summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lcode.c19
-rw-r--r--ldebug.c96
-rw-r--r--ldebug.h5
-rw-r--r--lopcodes.h24
-rw-r--r--lparser.c22
-rw-r--r--lvm.c24
6 files changed, 94 insertions, 96 deletions
diff --git a/lcode.c b/lcode.c
index ad0c05d2..1c1517bf 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.72 2001/06/08 12:29:27 roberto Exp roberto $ 2** $Id: lcode.c,v 1.73 2001/06/08 19:00:57 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -69,8 +69,8 @@ int luaK_jump (FuncState *fs) {
69} 69}
70 70
71 71
72static int luaK_condjump (FuncState *fs, OpCode op, int B, int C) { 72static int luaK_condjump (FuncState *fs, OpCode op, int A, int B, int C) {
73 luaK_codeABC(fs, op, NO_REG, B, C); 73 luaK_codeABC(fs, op, A, B, C);
74 return luaK_codeAsBc(fs, OP_CJMP, 0, NO_JUMP); 74 return luaK_codeAsBc(fs, OP_CJMP, 0, NO_JUMP);
75} 75}
76 76
@@ -261,12 +261,11 @@ static int number_constant (FuncState *fs, lua_Number r) {
261 261
262void luaK_setcallreturns (FuncState *fs, expdesc *e, int nresults) { 262void luaK_setcallreturns (FuncState *fs, expdesc *e, int nresults) {
263 if (e->k == VCALL) { /* expression is an open function call? */ 263 if (e->k == VCALL) { /* expression is an open function call? */
264 int a = GETARG_A(getcode(fs, e)); 264 if (nresults == LUA_MULTRET) nresults = NO_REG;
265 int c = (nresults == LUA_MULTRET) ? NO_REG : a + nresults; 265 SETARG_C(getcode(fs, e), nresults);
266 SETARG_C(getcode(fs, e), c);
267 if (nresults == 1) { /* `regular' expression? */ 266 if (nresults == 1) { /* `regular' expression? */
268 e->k = VNONRELOC; 267 e->k = VNONRELOC;
269 e->u.i.info = a; 268 e->u.i.info = GETARG_A(getcode(fs, e));
270 } 269 }
271 } 270 }
272} 271}
@@ -499,13 +498,13 @@ static int jumponcond (FuncState *fs, expdesc *e, OpCode op) {
499 if (GET_OPCODE(ie) == OP_NOT) { 498 if (GET_OPCODE(ie) == OP_NOT) {
500 op = invertoperator(op); 499 op = invertoperator(op);
501 fs->pc--; /* remove previous OP_NOT */ 500 fs->pc--; /* remove previous OP_NOT */
502 return luaK_condjump(fs, op, GETARG_B(ie), 0); 501 return luaK_condjump(fs, op, NO_REG, GETARG_B(ie), 0);
503 } 502 }
504 /* else go through */ 503 /* else go through */
505 } 504 }
506 discharge2anyreg(fs, e); 505 discharge2anyreg(fs, e);
507 freeexp(fs, e); 506 freeexp(fs, e);
508 return luaK_condjump(fs, op, e->u.i.info, 0); 507 return luaK_condjump(fs, op, NO_REG, e->u.i.info, 0);
509} 508}
510 509
511 510
@@ -748,7 +747,7 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
748 e1->k = VRELOCABLE; 747 e1->k = VRELOCABLE;
749 } 748 }
750 else { /* jump */ 749 else { /* jump */
751 e1->u.i.info = luaK_condjump(fs, opc, o1, o2); 750 e1->u.i.info = luaK_condjump(fs, opc, o1, 0, o2);
752 e1->k = VJMP; 751 e1->k = VJMP;
753 } 752 }
754 } 753 }
diff --git a/ldebug.c b/ldebug.c
index 62372fca..27494a4e 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.80 2001/06/08 12:29:27 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.81 2001/06/08 19:00:57 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -349,6 +349,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) {
349 int a = GETARG_A(i); 349 int a = GETARG_A(i);
350 int b = 0; 350 int b = 0;
351 int c = 0; 351 int c = 0;
352 checkreg(pt, a);
352 switch (getOpMode(op)) { 353 switch (getOpMode(op)) {
353 case iABC: { 354 case iABC: {
354 b = GETARG_B(i); 355 b = GETARG_B(i);
@@ -370,7 +371,6 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) {
370 break; 371 break;
371 } 372 }
372 } 373 }
373 if (testOpMode(op, OpModeAreg)) checkreg(pt, a);
374 if (testOpMode(op, OpModesetA)) { 374 if (testOpMode(op, OpModesetA)) {
375 if (a == reg) last = pc; /* change register `a' */ 375 if (a == reg) last = pc; /* change register `a' */
376 } 376 }
@@ -414,20 +414,20 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) {
414 break; 414 break;
415 } 415 }
416 case OP_CALL: { 416 case OP_CALL: {
417 if (b == NO_REG) b = pt->maxstacksize; 417 if (b != NO_REG) {
418 checkreg(pt, a+b);
419 }
418 if (c == NO_REG) { 420 if (c == NO_REG) {
419 check(checkopenop(pt->code[pc+1])); 421 check(checkopenop(pt->code[pc+1]));
420 c = 1;
421 } 422 }
422 check(b > a); 423 else if (c != 0)
423 checkreg(pt, b-1); 424 checkreg(pt, a+c-1);
424 checkreg(pt, c-1);
425 if (reg >= a) last = pc; /* affect all registers above base */ 425 if (reg >= a) last = pc; /* affect all registers above base */
426 break; 426 break;
427 } 427 }
428 case OP_RETURN: { 428 case OP_RETURN: {
429 if (b == NO_REG) b = pt->maxstacksize; 429 if (b != NO_REG && b != 0)
430 checkreg(pt, b-1); 430 checkreg(pt, a+b-1);
431 break; 431 break;
432 } 432 }
433 case OP_FORPREP: 433 case OP_FORPREP:
@@ -566,49 +566,49 @@ void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) {
566 566
567 567
568#define opmode(t,a,b,c,sa,k,m) (((t)<<OpModeT) | \ 568#define opmode(t,a,b,c,sa,k,m) (((t)<<OpModeT) | \
569 ((a)<<OpModeAreg) | ((b)<<OpModeBreg) | ((c)<<OpModeCreg) | \ 569 ((b)<<OpModeBreg) | ((c)<<OpModeCreg) | \
570 ((sa)<<OpModesetA) | ((k)<<OpModeK) | (m)) 570 ((sa)<<OpModesetA) | ((k)<<OpModeK) | (m))
571 571
572 572
573const lu_byte luaG_opmodes[] = { 573const lu_byte luaG_opmodes[] = {
574/* T A B C sA K mode opcode */ 574/* T J B C sA K mode opcode */
575 opmode(0,1,1,0, 1,0,iABC), /* OP_MOVE */ 575 opmode(0,0,1,0, 1,0,iABC), /* OP_MOVE */
576 opmode(0,1,0,0, 1,1,iABc), /* OP_LOADK */ 576 opmode(0,0,0,0, 1,1,iABc), /* OP_LOADK */
577 opmode(0,1,0,0, 1,0,iAsBc), /* OP_LOADINT */ 577 opmode(0,0,0,0, 1,0,iAsBc), /* OP_LOADINT */
578 opmode(0,1,1,0, 1,0,iABC), /* OP_LOADNIL */ 578 opmode(0,0,1,0, 1,0,iABC), /* OP_LOADNIL */
579 opmode(0,1,0,0, 1,0,iABc), /* OP_LOADUPVAL */ 579 opmode(0,0,0,0, 1,0,iABc), /* OP_LOADUPVAL */
580 opmode(0,1,0,0, 1,1,iABc), /* OP_GETGLOBAL */ 580 opmode(0,0,0,0, 1,1,iABc), /* OP_GETGLOBAL */
581 opmode(0,1,1,1, 1,0,iABC), /* OP_GETTABLE */ 581 opmode(0,0,1,1, 1,0,iABC), /* OP_GETTABLE */
582 opmode(0,1,0,0, 0,1,iABc), /* OP_SETGLOBAL */ 582 opmode(0,0,0,0, 0,1,iABc), /* OP_SETGLOBAL */
583 opmode(0,1,1,1, 0,0,iABC), /* OP_SETTABLE */ 583 opmode(0,0,1,1, 0,0,iABC), /* OP_SETTABLE */
584 opmode(0,1,0,0, 1,0,iABc), /* OP_NEWTABLE */ 584 opmode(0,0,0,0, 1,0,iABc), /* OP_NEWTABLE */
585 opmode(0,1,1,1, 1,0,iABC), /* OP_SELF */ 585 opmode(0,0,1,1, 1,0,iABC), /* OP_SELF */
586 opmode(0,1,1,1, 1,0,iABC), /* OP_ADD */ 586 opmode(0,0,1,1, 1,0,iABC), /* OP_ADD */
587 opmode(0,1,1,1, 1,0,iABC), /* OP_SUB */ 587 opmode(0,0,1,1, 1,0,iABC), /* OP_SUB */
588 opmode(0,1,1,1, 1,0,iABC), /* OP_MUL */ 588 opmode(0,0,1,1, 1,0,iABC), /* OP_MUL */
589 opmode(0,1,1,1, 1,0,iABC), /* OP_DIV */ 589 opmode(0,0,1,1, 1,0,iABC), /* OP_DIV */
590 opmode(0,1,1,1, 1,0,iABC), /* OP_POW */ 590 opmode(0,0,1,1, 1,0,iABC), /* OP_POW */
591 opmode(0,1,1,0, 1,0,iABC), /* OP_UNM */ 591 opmode(0,0,1,0, 1,0,iABC), /* OP_UNM */
592 opmode(0,1,1,0, 1,0,iABC), /* OP_NOT */ 592 opmode(0,0,1,0, 1,0,iABC), /* OP_NOT */
593 opmode(0,1,1,1, 1,0,iABC), /* OP_CONCAT */ 593 opmode(0,0,1,1, 1,0,iABC), /* OP_CONCAT */
594 opmode(0,0,0,0, 0,0,iAsBc), /* OP_JMP */ 594 opmode(0,1,0,0, 0,0,iAsBc), /* OP_JMP */
595 opmode(0,0,0,0, 0,0,iAsBc), /* OP_CJMP */ 595 opmode(0,1,0,0, 0,0,iAsBc), /* OP_CJMP */
596 opmode(1,0,1,1, 0,0,iABC), /* OP_TESTEQ */ 596 opmode(1,0,0,1, 0,0,iABC), /* OP_TESTEQ */
597 opmode(1,0,1,1, 0,0,iABC), /* OP_TESTNE */ 597 opmode(1,0,0,1, 0,0,iABC), /* OP_TESTNE */
598 opmode(1,0,1,1, 0,0,iABC), /* OP_TESTLT */ 598 opmode(1,0,0,1, 0,0,iABC), /* OP_TESTLT */
599 opmode(1,0,1,1, 0,0,iABC), /* OP_TESTLE */ 599 opmode(1,0,0,1, 0,0,iABC), /* OP_TESTLE */
600 opmode(1,0,1,1, 0,0,iABC), /* OP_TESTGT */ 600 opmode(1,0,0,1, 0,0,iABC), /* OP_TESTGT */
601 opmode(1,0,1,1, 0,0,iABC), /* OP_TESTGE */ 601 opmode(1,0,0,1, 0,0,iABC), /* OP_TESTGE */
602 opmode(1,1,1,0, 1,0,iABC), /* OP_TESTT */ 602 opmode(1,0,1,0, 1,0,iABC), /* OP_TESTT */
603 opmode(1,1,1,0, 1,0,iABC), /* OP_TESTF */ 603 opmode(1,0,1,0, 1,0,iABC), /* OP_TESTF */
604 opmode(0,1,0,0, 1,0,iAsBc), /* OP_NILJMP */ 604 opmode(0,0,0,0, 1,0,iAsBc), /* OP_NILJMP */
605 opmode(0,1,0,0, 0,0,iABC), /* OP_CALL */ 605 opmode(0,0,0,0, 0,0,iABC), /* OP_CALL */
606 opmode(0,1,0,0, 0,0,iABC), /* OP_RETURN */ 606 opmode(0,0,0,0, 0,0,iABC), /* OP_RETURN */
607 opmode(0,1,0,0, 0,0,iAsBc), /* OP_FORPREP */ 607 opmode(0,0,0,0, 0,0,iAsBc), /* OP_FORPREP */
608 opmode(0,1,0,0, 0,0,iAsBc), /* OP_FORLOOP */ 608 opmode(0,0,0,0, 0,0,iAsBc), /* OP_FORLOOP */
609 opmode(0,1,0,0, 0,0,iAsBc), /* OP_TFORPREP */ 609 opmode(0,1,0,0, 0,0,iAsBc), /* OP_TFORPREP */
610 opmode(0,1,0,0, 0,0,iAsBc), /* OP_TFORLOOP */ 610 opmode(0,1,0,0, 0,0,iAsBc), /* OP_TFORLOOP */
611 opmode(0,1,0,0, 0,0,iABc), /* OP_SETLIST */ 611 opmode(0,0,0,0, 0,0,iABc), /* OP_SETLIST */
612 opmode(0,1,0,0, 0,0,iABc), /* OP_SETLIST0 */ 612 opmode(0,0,0,0, 0,0,iABc), /* OP_SETLIST0 */
613 opmode(0,1,0,0, 0,0,iABc) /* OP_CLOSURE */ 613 opmode(0,0,0,0, 0,0,iABc) /* OP_CLOSURE */
614}; 614};
diff --git a/ldebug.h b/ldebug.h
index c48681f1..678ef1ce 100644
--- a/ldebug.h
+++ b/ldebug.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.h,v 1.12 2001/06/05 18:17:01 roberto Exp roberto $ 2** $Id: ldebug.h,v 1.13 2001/06/06 17:50:36 roberto Exp roberto $
3** Auxiliary functions from Debug Interface module 3** Auxiliary functions from Debug Interface module
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -18,8 +18,7 @@ enum OpMode {iABC, iABc, iAsBc}; /* basic instruction format */
18** masks for instruction properties 18** masks for instruction properties
19*/ 19*/
20enum OpModeMask { 20enum OpModeMask {
21 OpModeAreg = 2, /* A is a register */ 21 OpModeBreg = 2, /* B is a register */
22 OpModeBreg, /* B is a register */
23 OpModeCreg, /* C is a register/constant */ 22 OpModeCreg, /* C is a register/constant */
24 OpModesetA, /* instruction set register A */ 23 OpModesetA, /* instruction set register A */
25 OpModeK, /* Bc is a constant */ 24 OpModeK, /* Bc is a constant */
diff --git a/lopcodes.h b/lopcodes.h
index bbca12d9..45674257 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.73 2001/06/05 18:17:01 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.74 2001/06/08 19:00:57 roberto Exp roberto $
3** Opcodes for Lua virtual machine 3** Opcodes for Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -153,20 +153,20 @@ OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */
153OP_JMP,/* sBc PC += sBc */ 153OP_JMP,/* sBc PC += sBc */
154OP_CJMP,/* sBc if test then PC += sBc (see (1)) */ 154OP_CJMP,/* sBc if test then PC += sBc (see (1)) */
155 155
156OP_TESTEQ,/* B C test := (R(B) == R/K(C)) */ 156OP_TESTEQ,/* A C test := (R(A) == R/K(C)) */
157OP_TESTNE,/* B C test := (R(B) ~= R/K(C)) */ 157OP_TESTNE,/* A C test := (R(A) ~= R/K(C)) */
158OP_TESTLT,/* B C test := (R(B) < R/K(C)) */ 158OP_TESTLT,/* A C test := (R(A) < R/K(C)) */
159OP_TESTLE,/* B C test := (R(B) <= R/K(C)) */ 159OP_TESTLE,/* A C test := (R(A) <= R/K(C)) */
160OP_TESTGT,/* B C test := (R(B) > R/K(C)) */ 160OP_TESTGT,/* A C test := (R(A) > R/K(C)) */
161OP_TESTGE,/* B C test := (R(B) >= R/K(C)) */ 161OP_TESTGE,/* A C test := (R(A) >= R/K(C)) */
162 162
163OP_TESTT,/* A B test := R(B); if (test) R(A) := R(B) */ 163OP_TESTT,/* A B test := R(B); if (test) R(A) := R(B) */
164OP_TESTF,/* A B test := not R(B); if (test) R(A) := nil */ 164OP_TESTF,/* A B test := not R(B); if (test) R(A) := nil */
165 165
166OP_NILJMP,/* A R(A) := nil; PC++; */ 166OP_NILJMP,/* A R(A) := nil; PC++; */
167 167
168OP_CALL,/* A B C R(A), ... ,R(C-1) := R(A)(R(A+1), ... ,R(B-1)) */ 168OP_CALL,/* A B C R(A), ... ,R(A+C-1) := R(A)(R(A+1), ... ,R(A+B))*/
169OP_RETURN,/* A B return R(A), ... ,R(B-1) (see (3)) */ 169OP_RETURN,/* A B return R(A), ... ,R(A+B-1) (see (3)) */
170 170
171OP_FORPREP,/* A sBc */ 171OP_FORPREP,/* A sBc */
172OP_FORLOOP,/* A sBc */ 172OP_FORLOOP,/* A sBc */
@@ -191,10 +191,10 @@ OP_CLOSURE /* A Bc R(A) := closure(KPROTO[Bc], R(A), ... ,R(A+n)) */
191 instructions OP_TEST* and OP_CJMP must always occur together. 191 instructions OP_TEST* and OP_CJMP must always occur together.
192 192
193 (2) In OP_CALL, if (B == NO_REG) then B = top. C is the number of returns, 193 (2) In OP_CALL, if (B == NO_REG) then B = top. C is the number of returns,
194 and can be NO_REG. OP_CALL always set "top" to last_result+1, so 194 and can be NO_REG. OP_CALL can set `top' to last_result+1, so
195 next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use "top". 195 next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'.
196 196
197 (3) In OP_RETURN, if (B == NO_REG) then B = top. 197 (3) In OP_RETURN, if (B == NO_REG) then return up to `top'
198===========================================================================*/ 198===========================================================================*/
199 199
200 200
diff --git a/lparser.c b/lparser.c
index 8dff5638..b077c324 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.146 2001/06/08 12:29:27 roberto Exp roberto $ 2** $Id: lparser.c,v 1.147 2001/06/08 19:00:57 roberto Exp roberto $
3** LL(1) Parser and code generator for Lua 3** LL(1) Parser and code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -415,7 +415,7 @@ static int explist1 (LexState *ls, expdesc *v) {
415static void funcargs (LexState *ls, expdesc *f) { 415static void funcargs (LexState *ls, expdesc *f) {
416 FuncState *fs = ls->fs; 416 FuncState *fs = ls->fs;
417 expdesc args; 417 expdesc args;
418 int base, top; 418 int base, nparams;
419 switch (ls->t.token) { 419 switch (ls->t.token) {
420 case l_c('('): { /* funcargs -> `(' [ explist1 ] `)' */ 420 case l_c('('): { /* funcargs -> `(' [ explist1 ] `)' */
421 int line = ls->linenumber; 421 int line = ls->linenumber;
@@ -446,13 +446,13 @@ static void funcargs (LexState *ls, expdesc *f) {
446 lua_assert(f->k == VNONRELOC); 446 lua_assert(f->k == VNONRELOC);
447 base = f->u.i.info; /* base register for call */ 447 base = f->u.i.info; /* base register for call */
448 if (args.k == VCALL) 448 if (args.k == VCALL)
449 top = NO_REG; /* open call */ 449 nparams = NO_REG; /* open call */
450 else { 450 else {
451 if (args.k != VVOID) 451 if (args.k != VVOID)
452 luaK_exp2nextreg(fs, &args); /* close last argument */ 452 luaK_exp2nextreg(fs, &args); /* close last argument */
453 top = fs->freereg; 453 nparams = fs->freereg - (base+1);
454 } 454 }
455 init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, top, base+1)); 455 init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams, 1));
456 fs->freereg = base+1; /* call remove function and arguments and leaves 456 fs->freereg = base+1; /* call remove function and arguments and leaves
457 (unless changed) one result */ 457 (unless changed) one result */
458} 458}
@@ -1091,31 +1091,31 @@ static void retstat (LexState *ls) {
1091 /* stat -> RETURN explist */ 1091 /* stat -> RETURN explist */
1092 FuncState *fs = ls->fs; 1092 FuncState *fs = ls->fs;
1093 expdesc e; 1093 expdesc e;
1094 int first, last1; /* registers with returned values */ 1094 int first, nret; /* registers with returned values */
1095 next(ls); /* skip RETURN */ 1095 next(ls); /* skip RETURN */
1096 if (block_follow(ls->t.token) || ls->t.token == l_c(';')) 1096 if (block_follow(ls->t.token) || ls->t.token == l_c(';'))
1097 first = last1 = 0; /* return no values */ 1097 first = nret = 0; /* return no values */
1098 else { 1098 else {
1099 int n = explist1(ls, &e); /* optional return values */ 1099 int n = explist1(ls, &e); /* optional return values */
1100 if (e.k == VCALL) { 1100 if (e.k == VCALL) {
1101 luaK_setcallreturns(fs, &e, LUA_MULTRET); 1101 luaK_setcallreturns(fs, &e, LUA_MULTRET);
1102 first = fs->nactloc; 1102 first = fs->nactloc;
1103 last1 = NO_REG; /* return all values */ 1103 nret = NO_REG; /* return all values */
1104 } 1104 }
1105 else { 1105 else {
1106 if (n == 1) { /* only one value? */ 1106 if (n == 1) { /* only one value? */
1107 luaK_exp2anyreg(fs, &e); 1107 luaK_exp2anyreg(fs, &e);
1108 first = e.u.i.info; 1108 first = e.u.i.info;
1109 last1 = first+1; /* return only this value */ 1109 nret = 1; /* return only this value */
1110 } 1110 }
1111 else { 1111 else {
1112 luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ 1112 luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */
1113 first = fs->nactloc; 1113 first = fs->nactloc;
1114 last1 = fs->freereg; /* return all `active' values */ 1114 nret = fs->freereg - first; /* return all `active' values */
1115 } 1115 }
1116 } 1116 }
1117 } 1117 }
1118 luaK_codeABC(fs, OP_RETURN, first, last1, 0); 1118 luaK_codeABC(fs, OP_RETURN, first, nret, 0);
1119 fs->freereg = fs->nactloc; /* removes all temp values */ 1119 fs->freereg = fs->nactloc; /* removes all temp values */
1120} 1120}
1121 1121
diff --git a/lvm.c b/lvm.c
index 64df3762..5cadb252 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.182 2001/06/08 19:00:57 roberto Exp roberto $ 2** $Id: lvm.c,v 1.183 2001/06/08 19:20:02 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -488,37 +488,37 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
488 } 488 }
489 case OP_TESTEQ: { 489 case OP_TESTEQ: {
490 lua_assert(GET_OPCODE(*pc) == OP_CJMP); 490 lua_assert(GET_OPCODE(*pc) == OP_CJMP);
491 if (luaO_equalObj(RB(i), RKC(i))) dojump(pc, *pc); 491 if (luaO_equalObj(ra, RKC(i))) dojump(pc, *pc);
492 pc++; 492 pc++;
493 break; 493 break;
494 } 494 }
495 case OP_TESTNE: { 495 case OP_TESTNE: {
496 lua_assert(GET_OPCODE(*pc) == OP_CJMP); 496 lua_assert(GET_OPCODE(*pc) == OP_CJMP);
497 if (!luaO_equalObj(RB(i), RKC(i))) dojump(pc, *pc); 497 if (!luaO_equalObj(ra, RKC(i))) dojump(pc, *pc);
498 pc++; 498 pc++;
499 break; 499 break;
500 } 500 }
501 case OP_TESTLT: { 501 case OP_TESTLT: {
502 lua_assert(GET_OPCODE(*pc) == OP_CJMP); 502 lua_assert(GET_OPCODE(*pc) == OP_CJMP);
503 if (luaV_lessthan(L, RB(i), RKC(i))) dojump(pc, *pc); 503 if (luaV_lessthan(L, ra, RKC(i))) dojump(pc, *pc);
504 pc++; 504 pc++;
505 break; 505 break;
506 } 506 }
507 case OP_TESTLE: { /* b <= c === !(c<b) */ 507 case OP_TESTLE: { /* b <= c === !(c<b) */
508 lua_assert(GET_OPCODE(*pc) == OP_CJMP); 508 lua_assert(GET_OPCODE(*pc) == OP_CJMP);
509 if (!luaV_lessthan(L, RKC(i), RB(i))) dojump(pc, *pc); 509 if (!luaV_lessthan(L, RKC(i), ra)) dojump(pc, *pc);
510 pc++; 510 pc++;
511 break; 511 break;
512 } 512 }
513 case OP_TESTGT: { /* b > c === (c<b) */ 513 case OP_TESTGT: { /* b > c === (c<b) */
514 lua_assert(GET_OPCODE(*pc) == OP_CJMP); 514 lua_assert(GET_OPCODE(*pc) == OP_CJMP);
515 if (luaV_lessthan(L, RKC(i), RB(i))) dojump(pc, *pc); 515 if (luaV_lessthan(L, RKC(i), ra)) dojump(pc, *pc);
516 pc++; 516 pc++;
517 break; 517 break;
518 } 518 }
519 case OP_TESTGE: { /* b >= c === !(b<c) */ 519 case OP_TESTGE: { /* b >= c === !(b<c) */
520 lua_assert(GET_OPCODE(*pc) == OP_CJMP); 520 lua_assert(GET_OPCODE(*pc) == OP_CJMP);
521 if (!luaV_lessthan(L, RB(i), RKC(i))) dojump(pc, *pc); 521 if (!luaV_lessthan(L, ra, RKC(i))) dojump(pc, *pc);
522 pc++; 522 pc++;
523 break; 523 break;
524 } 524 }
@@ -550,11 +550,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
550 int c; 550 int c;
551 int b = GETARG_B(i); 551 int b = GETARG_B(i);
552 if (b != NO_REG) 552 if (b != NO_REG)
553 L->top = base+b; 553 L->top = ra+b+1;
554 luaD_call(L, ra); 554 luaD_call(L, ra);
555 c = GETARG_C(i); 555 c = GETARG_C(i);
556 if (c != NO_REG) { 556 if (c != NO_REG) {
557 while (L->top < base+c) setnilvalue(L->top++); 557 while (L->top < ra+c) setnilvalue(L->top++);
558 L->top = base + tf->maxstacksize; 558 L->top = base + tf->maxstacksize;
559 } 559 }
560 break; 560 break;
@@ -562,7 +562,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
562 case OP_RETURN: { 562 case OP_RETURN: {
563 int b = GETARG_B(i); 563 int b = GETARG_B(i);
564 if (b != NO_REG) 564 if (b != NO_REG)
565 L->top = base+b; 565 L->top = ra+b;
566 return ra; 566 return ra;
567 } 567 }
568 case OP_FORPREP: { 568 case OP_FORPREP: {
@@ -578,10 +578,10 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
578 /* go through */ 578 /* go through */
579 } 579 }
580 case OP_FORLOOP: { 580 case OP_FORLOOP: {
581 if (ttype(ra) != LUA_TNUMBER)
582 luaD_error(L, l_s("`for' index must be a number"));
583 runtime_check(L, ttype(ra+1) == LUA_TNUMBER && 581 runtime_check(L, ttype(ra+1) == LUA_TNUMBER &&
584 ttype(ra+2) == LUA_TNUMBER); 582 ttype(ra+2) == LUA_TNUMBER);
583 if (ttype(ra) != LUA_TNUMBER)
584 luaD_error(L, l_s("`for' index must be a number"));
585 nvalue(ra) += nvalue(ra+2); /* increment index */ 585 nvalue(ra) += nvalue(ra+2); /* increment index */
586 if (nvalue(ra+2) > 0 ? 586 if (nvalue(ra+2) > 0 ?
587 nvalue(ra) <= nvalue(ra+1) : 587 nvalue(ra) <= nvalue(ra+1) :