add ivar/fvar/svar lookup funcs in codegen
parent
bac186a0c7
commit
51da22be06
|
@ -214,6 +214,31 @@ void gen_state::gen_val(
|
|||
}
|
||||
}
|
||||
|
||||
static inline int ret_code(int type, int def = 0) {
|
||||
if (type >= VAL_ANY) {
|
||||
return def;
|
||||
}
|
||||
return type << BC_INST_RET;
|
||||
}
|
||||
|
||||
void gen_state::gen_lookup_ivar(ident &id, int ltype) {
|
||||
code.push_back(
|
||||
BC_INST_IVAR | ret_code(ltype, BC_RET_INT) | (id.get_index() << 8)
|
||||
);
|
||||
}
|
||||
|
||||
void gen_state::gen_lookup_fvar(ident &id, int ltype) {
|
||||
code.push_back(
|
||||
BC_INST_FVAR | ret_code(ltype, BC_RET_FLOAT) | (id.get_index() << 8)
|
||||
);
|
||||
}
|
||||
|
||||
void gen_state::gen_lookup_svar(ident &id, int ltype) {
|
||||
code.push_back(
|
||||
BC_INST_SVAR | ret_code(ltype, BC_RET_STRING) | (id.get_index() << 8)
|
||||
);
|
||||
}
|
||||
|
||||
void gen_state::gen_main_null() {
|
||||
code.reserve(code.size() + 4);
|
||||
code.push_back(BC_INST_START);
|
||||
|
|
|
@ -45,6 +45,10 @@ 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_main_null();
|
||||
void gen_main_integer(integer_type v);
|
||||
void gen_main_float(float_type v);
|
||||
|
|
|
@ -434,35 +434,30 @@ lookupid:
|
|||
);
|
||||
switch (id.get_type()) {
|
||||
case ident_type::IVAR:
|
||||
gs.gs.code.push_back(
|
||||
BC_INST_IVAR | ret_code(ltype, BC_RET_INT) |
|
||||
(id.get_index() << 8)
|
||||
);
|
||||
gs.gs.gen_lookup_ivar(id, ltype);
|
||||
switch (ltype) {
|
||||
case VAL_POP:
|
||||
gs.gs.code.pop_back();
|
||||
break;
|
||||
case VAL_CODE:
|
||||
gs.gs.gen_lookup_ivar(id, ltype);
|
||||
gs.gs.code.push_back(BC_INST_COMPILE);
|
||||
break;
|
||||
case VAL_IDENT:
|
||||
gs.gs.gen_lookup_ivar(id, ltype);
|
||||
gs.gs.code.push_back(BC_INST_IDENT_U);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
case ident_type::FVAR:
|
||||
gs.gs.code.push_back(
|
||||
BC_INST_FVAR | ret_code(ltype, BC_RET_FLOAT) |
|
||||
(id.get_index() << 8)
|
||||
);
|
||||
switch (ltype) {
|
||||
case VAL_POP:
|
||||
gs.gs.code.pop_back();
|
||||
break;
|
||||
case VAL_CODE:
|
||||
gs.gs.gen_lookup_fvar(id, ltype);
|
||||
gs.gs.code.push_back(BC_INST_COMPILE);
|
||||
break;
|
||||
case VAL_IDENT:
|
||||
gs.gs.gen_lookup_fvar(id, ltype);
|
||||
gs.gs.code.push_back(BC_INST_IDENT_U);
|
||||
break;
|
||||
}
|
||||
|
@ -472,10 +467,7 @@ lookupid:
|
|||
case VAL_POP:
|
||||
return;
|
||||
default:
|
||||
gs.gs.code.push_back(
|
||||
BC_INST_SVAR | ret_code(ltype, BC_RET_STRING) |
|
||||
(id.get_index() << 8)
|
||||
);
|
||||
gs.gs.gen_lookup_svar(id, ltype);
|
||||
break;
|
||||
}
|
||||
goto done;
|
||||
|
|
Loading…
Reference in New Issue