more codegen utils

master
Daniel Kolesa 2021-04-09 03:34:48 +02:00
parent 3790435c34
commit 295c905c32
3 changed files with 26 additions and 21 deletions

View File

@ -243,6 +243,16 @@ void gen_state::gen_lookup_svar(ident &id, int ltype) {
); );
} }
void gen_state::gen_lookup_alias(ident &id, int ltype, int dtype) {
code.push_back(
BC_INST_LOOKUP | ret_code(ltype, dtype) | (id.get_index() << 8)
);
}
void gen_state::gen_lookup_ident(int ltype) {
code.push_back(BC_INST_LOOKUP_U | ret_code(ltype));
}
void gen_state::gen_compile(bool cond) { void gen_state::gen_compile(bool cond) {
if (cond) { if (cond) {
code.push_back(BC_INST_COND); code.push_back(BC_INST_COND);

View File

@ -47,9 +47,12 @@ struct gen_state {
std::size_t line = 0 std::size_t line = 0
); );
void gen_lookup_ivar(ident &id, int ltype); void gen_lookup_ivar(ident &id, int ltype = 0);
void gen_lookup_fvar(ident &id, int ltype); void gen_lookup_fvar(ident &id, int ltype = 0);
void gen_lookup_svar(ident &id, int ltype); void gen_lookup_svar(ident &id, int ltype = 0);
void gen_lookup_alias(ident &id, int ltype = 0, int dtype = 0);
void gen_lookup_ident(int ltype = 0);
void gen_compile(bool cond = false); void gen_compile(bool cond = false);
void gen_ident_lookup(); void gen_ident_lookup();

View File

@ -476,16 +476,10 @@ lookupid:
case VAL_POP: case VAL_POP:
return; return;
case VAL_COND: case VAL_COND:
gs.gs.code.push_back( gs.gs.gen_lookup_alias(id);
BC_INST_LOOKUP | (id.get_index() << 8)
);
break; break;
default: default:
gs.gs.code.push_back( gs.gs.gen_lookup_alias(id, ltype, BC_RET_STRING);
BC_INST_LOOKUP |
ret_code(ltype, BC_RET_STRING) |
(id.get_index() << 8)
);
break; break;
} }
goto done; goto done;
@ -574,10 +568,10 @@ lookupid:
} }
switch (ltype) { switch (ltype) {
case VAL_COND: case VAL_COND:
gs.gs.code.push_back(BC_INST_LOOKUP_U); gs.gs.gen_lookup_ident();
break; break;
default: default:
gs.gs.code.push_back(BC_INST_LOOKUP_U | ret_code(ltype)); gs.gs.gen_lookup_ident(ltype);
break; break;
} }
done: done:
@ -624,7 +618,7 @@ static bool compileblocksub(parser_state &gs) {
if (!compilearg(gs, VAL_STRING)) { if (!compilearg(gs, VAL_STRING)) {
return false; return false;
} }
gs.gs.code.push_back(BC_INST_LOOKUP_U); gs.gs.gen_lookup_ident();
break; break;
case '\"': case '\"':
lookup = gs.get_str_dup(); lookup = gs.get_str_dup();
@ -642,24 +636,22 @@ lookupid:
); );
switch (id.get_type()) { switch (id.get_type()) {
case ident_type::IVAR: case ident_type::IVAR:
gs.gs.code.push_back(BC_INST_IVAR | (id.get_index() << 8)); gs.gs.gen_lookup_ivar(id);
goto done; goto done;
case ident_type::FVAR: case ident_type::FVAR:
gs.gs.code.push_back(BC_INST_FVAR | (id.get_index() << 8)); gs.gs.gen_lookup_fvar(id);
goto done; goto done;
case ident_type::SVAR: case ident_type::SVAR:
gs.gs.code.push_back(BC_INST_SVAR | (id.get_index() << 8)); gs.gs.gen_lookup_svar(id);
goto done; goto done;
case ident_type::ALIAS: case ident_type::ALIAS:
gs.gs.code.push_back( gs.gs.gen_lookup_alias(id);
BC_INST_LOOKUP | (id.get_index() << 8)
);
goto done; goto done;
default: default:
break; break;
} }
gs.gs.gen_val_string(lookup.str_term()); gs.gs.gen_val_string(lookup.str_term());
gs.gs.code.push_back(BC_INST_LOOKUP_U); gs.gs.gen_lookup_ident();
done: done:
break; break;
} }