void compiler::compile_literal(const std::string& token) { if ( islabel_ref(token) ) { compile_label(token.substr(1)); return; } int32_t literal = to_literal(token); // Literals are pushed on to the stack if ( literal != -1 ) { m.load(PUSH); m.load(literal); return; } // Unknown literals are treated as forward function calls compile_function_call(token); }
// Main compiler dispatch system void compile(compiler_wrapper *cw, ast_node *root) { switch(root->type) { case ABINARY_EXPRESSION: compile_binary(cw, root); break; case AUNARY_EXPRESSION: compile_unary(cw, root); break; case AVALUE: compile_value(cw, root); break; case AUNIT: compile_unit_value(cw, root); break; case ACOND_CHAIN: compile_cond(cw, root); break; case AIF: compile_if(cw, root); break; case ALOOP: compile_loop(cw, root); break; case AITERLOOP: compile_iter_loop(cw, root); break; case AFUNC_DECL: compile_function(cw, root); break; case AFUNC_CALL: compile_function_call(cw, root); break; case ACLASS_DECL: compile_class_decl(cw, root); break; case ATERNARY: compile_ternary(cw, root); break; case AMEMBER_ACCESS: compile_member_access(cw, root); break; case AARRAY: compile_array(cw, root); break; case ATABLE: compile_table(cw, root); break; case AOBJDECL: compile_object(cw, root); break; case AINDEX: compile_indx(cw, root); break; case ATRIPLESET: compile_triple_set(cw, root); break; case ATRYCATCH: compile_try_catch(cw, root); break; case AONEOFF: compile_one_off(cw, root); break; case ALOAD: compile_load(cw, root); break; case AREGEX: compile_regex(cw, root); break; default: break; } }