Skip to content

Commit

Permalink
#245 move function around
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed Jun 25, 2022
1 parent 4119bba commit 0f36fa5
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions ravicomp/src/linearizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1205,49 +1205,6 @@ static Pseudo *linearize_symbol_expression(Proc *proc, AstNode *expr)
}
}

static Pseudo *instruct_indexed_load(Proc *proc, ravitype_t container_type,
Pseudo *container_pseudo, ravitype_t key_type,
Pseudo *key_pseudo, ravitype_t target_type, unsigned line_number)
{
int op = op_get;
switch (container_type) {
case RAVI_TTABLE:
op = op_tget;
break;
case RAVI_TARRAYINT:
op = op_iaget;
break;
case RAVI_TARRAYFLT:
op = op_faget;
break;
default:
break;
}
/* Note we rely upon ordering of enums here */
switch (key_type) {
case RAVI_TNUMINT:
op++;
break;
case RAVI_TSTRING:
assert(container_type != RAVI_TARRAYINT && container_type != RAVI_TARRAYFLT);
op += 2;
break;
default:
break;
}
Pseudo *target_pseudo = allocate_temp_pseudo(proc, target_type, false);
Instruction *insn = allocate_instruction(proc, (enum opcode)op, line_number);
Pseudo *tofree1 = add_instruction_operand(proc, insn, container_pseudo);
Pseudo *tofree2 = add_instruction_operand(proc, insn, key_pseudo);
add_instruction_target(proc, insn, target_pseudo);
add_instruction(proc, insn);
if (tofree1)
free_temp_pseudo(proc, tofree1, false);
if (tofree2)
free_temp_pseudo(proc, tofree2, false);
return target_pseudo;
}

static Pseudo *indexed_load_from_global(Proc *proc, Pseudo *index_pseudo)
{
Pseudo *container_pseudo = index_pseudo->index_info.container;
Expand Down Expand Up @@ -1431,6 +1388,49 @@ static void indexed_store(Proc *proc, Pseudo *index_pseudo, Pseudo *value_pseudo
free_temp_pseudo(proc, tofree, false);
}

static Pseudo *instruct_indexed_load(Proc *proc, ravitype_t container_type,
Pseudo *container_pseudo, ravitype_t key_type,
Pseudo *key_pseudo, ravitype_t target_type, unsigned line_number)
{
int op = op_get;
switch (container_type) {
case RAVI_TTABLE:
op = op_tget;
break;
case RAVI_TARRAYINT:
op = op_iaget;
break;
case RAVI_TARRAYFLT:
op = op_faget;
break;
default:
break;
}
/* Note we rely upon ordering of enums here */
switch (key_type) {
case RAVI_TNUMINT:
op++;
break;
case RAVI_TSTRING:
assert(container_type != RAVI_TARRAYINT && container_type != RAVI_TARRAYFLT);
op += 2;
break;
default:
break;
}
Pseudo *target_pseudo = allocate_temp_pseudo(proc, target_type, false);
Instruction *insn = allocate_instruction(proc, (enum opcode)op, line_number);
Pseudo *tofree1 = add_instruction_operand(proc, insn, container_pseudo);
Pseudo *tofree2 = add_instruction_operand(proc, insn, key_pseudo);
add_instruction_target(proc, insn, target_pseudo);
add_instruction(proc, insn);
if (tofree1)
free_temp_pseudo(proc, tofree1, false);
if (tofree2)
free_temp_pseudo(proc, tofree2, false);
return target_pseudo;
}

/**
* Lua function calls can return multiple values, and the caller decides how many values to accept.
* We indicate multiple values using a PSEUDO_RANGE.
Expand Down

0 comments on commit 0f36fa5

Please sign in to comment.