Skip to content

Commit

Permalink
#77 mark variables referenced in upvalues when they are modified
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed Mar 19, 2022
1 parent 0d7e3ae commit 991aa35
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/linearizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,20 @@ static inline void set_current_proc(LinearizerState *linearizer, Proc *proc)
linearizer->current_proc = proc;
}

static void set_local_modified_flag(Pseudo *target) {
if (target->type != PSEUDO_SYMBOL)
return;
LuaSymbol *symbol = target->symbol;
if (symbol->symbol_type == SYM_UPVALUE)
symbol = symbol->upvalue.target_variable;
if (symbol->symbol_type != SYM_LOCAL)
return;
if (!symbol->variable.literal_initializer)
return;
assert(symbol->variable.literal_initializer->type == EXPR_LITERAL);
symbol->variable.modified = 1;
}

static void instruct_totype(Proc *proc, Pseudo *target, const VariableType *vtype, unsigned line_number)
{
enum opcode targetop = op_nop;
Expand Down Expand Up @@ -780,6 +794,8 @@ static Pseudo *instruct_move(Proc *proc, enum opcode op, Pseudo *target, Pseudo
add_instruction_operand(proc, mov, src);
add_instruction_target(proc, mov, target);
add_instruction(proc, mov);
if (!is_intializer)
set_local_modified_flag(target);
return target;
}

Expand Down Expand Up @@ -1173,6 +1189,7 @@ static Pseudo *instruct_indexed_load(Proc *proc, ravitype_t container_type,
add_instruction_operand(proc, insn, key_pseudo);
add_instruction_target(proc, insn, target_pseudo);
add_instruction(proc, insn);
set_local_modified_flag(target_pseudo);
return target_pseudo;
}

Expand All @@ -1194,6 +1211,7 @@ static Pseudo *indexed_load_from_global(Proc *proc, Pseudo *index_pseudo)
free_temp_pseudo(proc, container_pseudo, false);
free_temp_pseudo(proc, key_pseudo, false);
index_pseudo->index_info.used = 1;
set_local_modified_flag(target);
return target;
}

Expand Down Expand Up @@ -1249,6 +1267,7 @@ static Pseudo *indexed_load(Proc *proc, Pseudo *index_pseudo)
free_temp_pseudo(proc, container_pseudo, false);
free_temp_pseudo(proc, key_pseudo, false);
index_pseudo->index_info.used = 1;
set_local_modified_flag(target_pseudo);
return target_pseudo;
}

Expand Down

0 comments on commit 991aa35

Please sign in to comment.