66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
#include "macro.hpp"
|
|
|
|
namespace fkstd
|
|
{
|
|
void assert_static_fail(Compiler& compiler,
|
|
std::shared_ptr<Node> node,
|
|
std::shared_ptr<Program> program)
|
|
{
|
|
try
|
|
{
|
|
compiler.compile_prog(node->child(1), program);
|
|
}
|
|
catch(std::exception const&)
|
|
{
|
|
program->load_const(std::make_shared<Constant>(TYPE_BOOL,
|
|
true,
|
|
node->loc()));
|
|
return;
|
|
}
|
|
|
|
std::stringstream ss;
|
|
ss << "assertion failed";
|
|
node->loc().error<assert_error>(LOG_ERROR, ss.str());
|
|
}
|
|
|
|
void decl(Compiler& compiler,
|
|
std::shared_ptr<Node> node,
|
|
std::shared_ptr<Program> program)
|
|
{
|
|
static addr_t addr = 0;
|
|
addr++;
|
|
|
|
std::string ident = node->child(1)->repr();
|
|
auto rhs = node->child(2);
|
|
|
|
compiler.compile_prog(rhs, program);
|
|
|
|
compiler.sym()->declare_local(ident,
|
|
addr,
|
|
node->loc());
|
|
|
|
program->add(OP_STORE_LOCAL, addr);
|
|
}
|
|
|
|
void block(Compiler& compiler,
|
|
std::shared_ptr<Node> node,
|
|
std::shared_ptr<Program> program)
|
|
{
|
|
compiler.sym()->enter_scope();
|
|
|
|
for (size_t i=1; i<node->size(); i++)
|
|
{
|
|
compiler.compile_prog(node->child(i), program);
|
|
|
|
if (i != node->size() - 1)
|
|
{
|
|
program->add(OP_POP);
|
|
}
|
|
}
|
|
|
|
compiler.sym()->leave_scope();
|
|
|
|
// std::cout << compiler.sym()->string() << std::endl;
|
|
}
|
|
}
|