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

35 lines
940 B
C++
Raw Normal View History

#include "macro.hpp"
2023-09-19 09:29:23 +00:00
void assert_fail(Node const& node, Module& mod)
{
try
{
2023-09-19 09:29:23 +00:00
mod.static_pass().execute(*node.child_at(1));
mod.compiler().compile(*node.child_at(1), mod.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&)
{
}
2023-09-19 09:29:23 +00:00
size_t addr = mod.program().add_constant(std::make_shared<Constant>
2023-09-18 17:32:16 +00:00
(TYPE_NIL, node.loc(), 0));
2023-09-19 09:29:23 +00:00
mod.program().append(OPCODE_LOAD_CONST, addr);
}
2023-09-19 04:38:14 +00:00
2023-09-19 09:29:23 +00:00
void declare(Node const& node, Module &mod)
2023-09-19 04:38:14 +00:00
{
std::string ident = node.child_at(1)->repr();
2023-09-19 09:29:23 +00:00
mod.compiler().compile(*node.child_at(2), mod.program());
auto entry = mod.sym().find_any(ident);
2023-09-19 04:38:14 +00:00
assert(entry);
2023-09-19 09:29:23 +00:00
size_t addr = mod.sym().gen_addr();
2023-09-19 04:38:14 +00:00
2023-09-19 09:29:23 +00:00
mod.sym().declare(ident, addr);
mod.program().append(OPCODE_STORE_LOCAL, addr);
2023-09-19 04:38:14 +00:00
}