Skip to content

Commit

Permalink
issue #35 enhance the loadglobal/storeglobal opscodes to also include…
Browse files Browse the repository at this point in the history
… the _ENV symbol. Also fix the storeglobal opcode
  • Loading branch information
dibyendumajumdar committed Oct 3, 2020
1 parent 66d35a1 commit a1f6c49
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/linearizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -894,11 +894,14 @@ static struct pseudo *linearize_symbol_expression(struct proc *proc, struct ast_
{
struct lua_symbol *sym = expr->symbol_expr.var;
if (sym->symbol_type == SYM_GLOBAL) {
assert(sym->variable.env);
struct pseudo *target = allocate_temp_pseudo(proc, RAVI_TANY);
struct pseudo *operand = allocate_symbol_pseudo(proc, sym, 0); // no register actually
struct pseudo *operand_varname = allocate_symbol_pseudo(proc, sym, 0); // no register actually
struct pseudo* operand_env = allocate_symbol_pseudo(proc, sym->variable.env, 0); // no register
struct instruction *insn = allocate_instruction(proc, op_loadglobal);
target->insn = insn;
add_instruction_operand(proc, insn, operand);
add_instruction_operand(proc, insn, operand_env);
add_instruction_operand(proc, insn, operand_varname);
add_instruction_target(proc, insn, target);
add_instruction(proc, insn);
return target;
Expand Down Expand Up @@ -996,11 +999,19 @@ static void instruct_indexed_store(struct proc *proc, ravitype_t table_type, str
static void convert_loadglobal_to_store(struct proc *proc, struct instruction *insn, struct pseudo *value_pseudo,
ravitype_t value_type)
{
remove_instruction(insn->block, insn);
assert(insn->opcode == op_loadglobal);
remove_instruction(insn->block, insn); // remove the instruction from its original block
insn->opcode = op_storeglobal;
add_instruction_operand(proc, insn, value_pseudo);
// Remove the targets
struct pseudo *get_target = ptrlist_delete_last((struct ptr_list **)&insn->targets);
free_temp_pseudo(proc, get_target, false);
struct pseudo *pseudo;
// Move the loadglobal operands to target
FOR_EACH_PTR(insn->operands, pseudo) { add_instruction_target(proc, insn, pseudo); }
END_FOR_EACH_PTR(pseudo);
ptrlist_remove_all((struct ptr_list **)&insn->operands);
// Add new operand
add_instruction_operand(proc, insn, value_pseudo);
add_instruction(proc, insn);
}

Expand Down

0 comments on commit a1f6c49

Please sign in to comment.