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) {
if (cond) {
code.push_back(BC_INST_COND);

View File

@ -47,9 +47,12 @@ struct gen_state {
std::size_t line = 0
);
void gen_lookup_ivar(ident &id, int ltype);
void gen_lookup_fvar(ident &id, int ltype);
void gen_lookup_svar(ident &id, int ltype);
void gen_lookup_ivar(ident &id, int ltype = 0);
void gen_lookup_fvar(ident &id, int ltype = 0);
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_ident_lookup();

View File

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