Skip to content

Commit

Permalink
use new approach to locate OP_NEWTABLE when checking types of assignm…
Browse files Browse the repository at this point in the history
…ents to local variables
  • Loading branch information
Dibyendu Majumdar committed Dec 21, 2015
1 parent c61c7f8 commit c47f132
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ static void ravi_typecheck(LexState *ls, expdesc *v, int *vars, int nvars,
if (v->ravi_type != vartype &&
(vartype == RAVI_TARRAYFLT || vartype == RAVI_TARRAYINT) &&
v->k == VNONRELOC) {
#if 0
/* as the bytecode for generating a table is already emitted by this stage
* we have to amend the generated byte code - not sure if there is a
* better approach. We look for the last bytecode that is OP_NEWTABLE
Expand Down Expand Up @@ -1274,6 +1275,25 @@ static void ravi_typecheck(LexState *ls, expdesc *v, int *vars, int nvars,
}
if (i < 0)
luaX_syntaxerror(ls, "expecting array initializer");
#else
int ok = 0;
if (v->pc >= 0) {
Instruction *pc = &ls->fs->f->code[v->pc];
OpCode op = GET_OPCODE(*pc);
if (op == OP_NEWTABLE) {
int reg = GETARG_A(*pc);
if (reg == v->u.info) {
op = (vartype == RAVI_TARRAYINT) ? OP_RAVI_NEWARRAYI : OP_RAVI_NEWARRAYF;
SET_OPCODE(*pc, op); /* modify opcode */
DEBUG_CODEGEN(
raviY_printf(ls->fs, "[%d]* %o ; modify opcode\n", v->pc, *pc));
ok = 1;
}
}
}
if (!ok)
luaX_syntaxerror(ls, "expecting array initializer");
#endif
}
/* if we are calling a function then convert return types */
else if (v->ravi_type != vartype &&
Expand Down

0 comments on commit c47f132

Please sign in to comment.