This repository has been archived on 2024-03-07. You can view files and clone it, but cannot push or open issues/pull-requests.
zarn/libstd/macro.cpp

40 lines
994 B
C++

#include "macro.hpp"
void assert_fail(Node const& node,
Compiler& compiler,
Program& program,
SymTable&)
{
try
{
compiler.compile(*node.child_at(1), program);
Loc loc = node.loc();
std::cerr << loc.file_path().string() << ":" << loc.line();
std::cerr << " ASSERTION FAILED" << std::endl;
exit(-1);
}
catch (std::exception const&)
{
}
size_t addr = program.add_constant(std::make_shared<Constant>
(TYPE_NIL, node.loc(), 0));
program.append(OPCODE_LOAD_CONST, addr);
}
void declare(Node const& node,
Compiler& compiler,
Program& program,
SymTable& sym)
{
std::string ident = node.child_at(1)->repr();
compiler.compile(*node.child_at(2), program);
auto entry = sym.find_any(ident);
assert(entry);
size_t addr = sym.gen_addr();
sym.declare(ident, addr);
program.append(OPCODE_STORE_LOCAL, addr);
}