lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Duncan Cross wrote:
> What happens for me is
> the final assertion fails, and reading back the pairs of values, in a lot of
> cases towards the end, the first number is not zero or nil but the second
> value *is* zero (which shouldn't be possible):

Thank you for the report and the test case! It's a bug in the
bytecode generation for some conditionals, which shows only in
compiled code. Patch attached.

BTW: You'll get better performance if you don't fill the rd[]
array backwards. It degrades into a hash table in this case.
You could just do a quick forward fill before the loop:
  for j=start,finish do rd[j] = 0 end

--- a/src/lj_parse.c
+++ b/src/lj_parse.c
@@ -636,6 +636,7 @@ static void invertjump(FuncState *fs, ExpDesc *e)
 static BCPos jumponcond(FuncState *fs, ExpDesc *e, int cond)
+  BCPos pc;
   if (e->k == VRELOCABLE) {
     BCIns *i = bcptr(fs, e);
     if (bc_op(*i) == BC_NOT) {
@@ -648,9 +649,10 @@ static BCPos jumponcond(FuncState *fs, ExpDesc *e, int cond)
     reserveregs(fs, 1);
     discharge2reg(fs, e, fs->freereg-1);
-  freeexp(fs, e);
   emitAD(fs, cond ? BC_ISTC : BC_ISFC, NO_REG, e->;
-  return emit_jump(fs);
+  pc = emit_jump(fs);
+  freeexp(fs, e);
+  return pc;
 static void goiftrue(FuncState *fs, ExpDesc *e)