fold BC_INST_IVAR/FVAR/SVAR into one instruction

master
Daniel Kolesa 2021-05-06 03:42:58 +02:00
parent a57072fb73
commit 139ead5d72
5 changed files with 13 additions and 70 deletions

View File

@ -142,14 +142,8 @@ enum {
BC_INST_CONC,
/* like above but without delimiter */
BC_INST_CONC_W,
/* push the value of svar with index D on the stack according to M */
BC_INST_SVAR,
/* push the value of ivar with index D on the stack according to M */
BC_INST_IVAR,
/* push the value of fvar with index D on the stack according to M */
BC_INST_FVAR,
/* pop a value off the stack and set vvar with index D to it */
BC_INST_FVAR1,
/* push the value of var with index D on the stack according to M */
BC_INST_VAR,
/* pop a value off the stack and set alias with index D to it */
BC_INST_ALIAS,
/* pop 2 values off the stack; top is value to set, below is alias name */

View File

@ -328,21 +328,9 @@ void gen_state::gen_val(
}
}
void gen_state::gen_lookup_ivar(ident &id, int ltype) {
void gen_state::gen_lookup_var(ident &id, int ltype) {
code.push_back(
BC_INST_IVAR | ret_code(ltype, BC_RET_INT) | (id.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.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.index() << 8)
BC_INST_VAR | ret_code(ltype) | (id.index() << 8)
);
}

View File

@ -60,9 +60,7 @@ struct gen_state {
std::size_t line = 0
);
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_var(ident &id, int ltype = 0);
void gen_lookup_alias(ident &id, int ltype = 0, int dtype = 0);
void gen_lookup_ident(int ltype = 0);

View File

@ -481,24 +481,11 @@ lookup_id:
);
switch (id.type()) {
case ident_type::IVAR:
if (ltype == VAL_POP) {
return;
}
gs.gen_lookup_ivar(id, ltype);
switch (ltype) {
case VAL_CODE:
case VAL_IDENT:
lookup_done(gs, ltype);
break;
default:
break;
}
return;
case ident_type::FVAR:
if (ltype == VAL_POP) {
return;
}
gs.gen_lookup_fvar(id, ltype);
gs.gen_lookup_var(id, ltype);
switch (ltype) {
case VAL_CODE:
case VAL_IDENT:
@ -513,7 +500,7 @@ lookup_id:
case VAL_POP:
return;
default:
gs.gen_lookup_svar(id, ltype);
gs.gen_lookup_var(id, ltype);
break;
}
lookup_done(gs, ltype);
@ -605,13 +592,9 @@ lookup_id:
);
switch (id.type()) {
case ident_type::IVAR:
gs.gen_lookup_ivar(id);
return true;
case ident_type::FVAR:
gs.gen_lookup_fvar(id);
return true;
case ident_type::SVAR:
gs.gen_lookup_svar(id);
gs.gen_lookup_var(id);
return true;
case ident_type::ALIAS:
gs.gen_lookup_alias(id);

View File

@ -716,31 +716,11 @@ std::uint32_t *vm_exec(
continue;
}
case BC_INST_SVAR | BC_RET_STRING:
case BC_INST_SVAR | BC_RET_NULL:
case BC_INST_SVAR | BC_RET_INT:
case BC_INST_SVAR | BC_RET_FLOAT:
args.emplace_back() = static_cast<string_var *>(
ts.istate->identmap[op >> 8]
)->value();
force_arg(cs, args.back(), op & BC_INST_RET_MASK);
continue;
case BC_INST_IVAR | BC_RET_INT:
case BC_INST_IVAR | BC_RET_NULL:
case BC_INST_IVAR | BC_RET_STRING:
case BC_INST_IVAR | BC_RET_FLOAT:
args.emplace_back() = static_cast<integer_var *>(
ts.istate->identmap[op >> 8]
)->value();
force_arg(cs, args.back(), op & BC_INST_RET_MASK);
continue;
case BC_INST_FVAR | BC_RET_FLOAT:
case BC_INST_FVAR | BC_RET_NULL:
case BC_INST_FVAR | BC_RET_STRING:
case BC_INST_FVAR | BC_RET_INT:
args.emplace_back() = static_cast<float_var *>(
case BC_INST_VAR | BC_RET_NULL:
case BC_INST_VAR | BC_RET_INT:
case BC_INST_VAR | BC_RET_FLOAT:
case BC_INST_VAR | BC_RET_STRING:
args.emplace_back() = static_cast<global_var *>(
ts.istate->identmap[op >> 8]
)->value();
force_arg(cs, args.back(), op & BC_INST_RET_MASK);