diff options
| -rw-r--r-- | lcode.c | 12 | ||||
| -rw-r--r-- | ldebug.c | 12 | ||||
| -rw-r--r-- | lparser.c | 23 | ||||
| -rw-r--r-- | lvm.c | 103 |
4 files changed, 71 insertions, 79 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 1.70 2001/06/06 18:00:19 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 1.71 2001/06/07 15:01:21 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 | */ |
| @@ -144,6 +144,12 @@ static int need_value (FuncState *fs, int list, OpCode op) { | |||
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | 146 | ||
| 147 | static void patchtestreg (Instruction *i, int reg) { | ||
| 148 | if (reg == NO_REG) reg = GETARG_B(*i); | ||
| 149 | SETARG_A(*i, reg); | ||
| 150 | } | ||
| 151 | |||
| 152 | |||
| 147 | static void luaK_patchlistaux (FuncState *fs, int list, | 153 | static void luaK_patchlistaux (FuncState *fs, int list, |
| 148 | int ttarget, int treg, int ftarget, int freg, int dtarget) { | 154 | int ttarget, int treg, int ftarget, int freg, int dtarget) { |
| 149 | while (list != NO_JUMP) { | 155 | while (list != NO_JUMP) { |
| @@ -151,12 +157,12 @@ static void luaK_patchlistaux (FuncState *fs, int list, | |||
| 151 | Instruction *i = getjumpcontrol(fs, list); | 157 | Instruction *i = getjumpcontrol(fs, list); |
| 152 | switch (GET_OPCODE(*i)) { | 158 | switch (GET_OPCODE(*i)) { |
| 153 | case OP_TESTT: { | 159 | case OP_TESTT: { |
| 154 | SETARG_A(*i, treg); | 160 | patchtestreg(i, treg); |
| 155 | luaK_fixjump(fs, list, ttarget); | 161 | luaK_fixjump(fs, list, ttarget); |
| 156 | break; | 162 | break; |
| 157 | } | 163 | } |
| 158 | case OP_TESTF: { | 164 | case OP_TESTF: { |
| 159 | SETARG_A(*i, freg); | 165 | patchtestreg(i, freg); |
| 160 | luaK_fixjump(fs, list, ftarget); | 166 | luaK_fixjump(fs, list, ftarget); |
| 161 | break; | 167 | break; |
| 162 | } | 168 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 1.78 2001/06/06 17:50:36 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.79 2001/06/07 14:44:51 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 | */ |
| @@ -409,12 +409,6 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) { | |||
| 409 | pc += b; /* do the jump */ | 409 | pc += b; /* do the jump */ |
| 410 | break; | 410 | break; |
| 411 | } | 411 | } |
| 412 | case OP_TESTT: | ||
| 413 | case OP_TESTF: { | ||
| 414 | if (a != NO_REG) | ||
| 415 | checkreg(pt, a); | ||
| 416 | break; | ||
| 417 | } | ||
| 418 | case OP_NILJMP: { | 412 | case OP_NILJMP: { |
| 419 | check(pc+2 < pt->sizecode); /* check its jump */ | 413 | check(pc+2 < pt->sizecode); /* check its jump */ |
| 420 | break; | 414 | break; |
| @@ -605,8 +599,8 @@ const lu_byte luaG_opmodes[] = { | |||
| 605 | opmode(1,0,1,1, 0,0,iABC), /* OP_TESTLE */ | 599 | opmode(1,0,1,1, 0,0,iABC), /* OP_TESTLE */ |
| 606 | opmode(1,0,1,1, 0,0,iABC), /* OP_TESTGT */ | 600 | opmode(1,0,1,1, 0,0,iABC), /* OP_TESTGT */ |
| 607 | opmode(1,0,1,1, 0,0,iABC), /* OP_TESTGE */ | 601 | opmode(1,0,1,1, 0,0,iABC), /* OP_TESTGE */ |
| 608 | opmode(1,0,1,0, 1,0,iABC), /* OP_TESTT */ | 602 | opmode(1,1,1,0, 1,0,iABC), /* OP_TESTT */ |
| 609 | opmode(1,0,1,0, 1,0,iABC), /* OP_TESTF */ | 603 | opmode(1,1,1,0, 1,0,iABC), /* OP_TESTF */ |
| 610 | opmode(0,1,0,0, 1,0,iAsBc), /* OP_NILJMP */ | 604 | opmode(0,1,0,0, 1,0,iAsBc), /* OP_NILJMP */ |
| 611 | opmode(0,1,0,0, 0,0,iABC), /* OP_CALL */ | 605 | opmode(0,1,0,0, 0,0,iABC), /* OP_CALL */ |
| 612 | opmode(0,1,0,0, 0,0,iABC), /* OP_RETURN */ | 606 | opmode(0,1,0,0, 0,0,iABC), /* OP_RETURN */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.144 2001/06/05 19:27:32 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.145 2001/06/07 14:44:51 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 | */ |
| @@ -492,16 +492,20 @@ static void recfield (LexState *ls, expdesc *t) { | |||
| 492 | } | 492 | } |
| 493 | 493 | ||
| 494 | 494 | ||
| 495 | static int anotherfield (LexState *ls) { | ||
| 496 | if (ls->t.token != l_c(',')) return 0; | ||
| 497 | next(ls); /* skip the comma */ | ||
| 498 | return (ls->t.token != l_c(';') && ls->t.token != l_c('}')); | ||
| 499 | } | ||
| 500 | |||
| 501 | |||
| 495 | static int recfields (LexState *ls, expdesc *t) { | 502 | static int recfields (LexState *ls, expdesc *t) { |
| 496 | /* recfields -> recfield { `,' recfield } [`,'] */ | 503 | /* recfields -> recfield { `,' recfield } [`,'] */ |
| 497 | int n = 1; /* at least one element */ | 504 | int n = 0; |
| 498 | recfield(ls, t); | 505 | do { /* at least one element */ |
| 499 | while (ls->t.token == l_c(',')) { | ||
| 500 | next(ls); | ||
| 501 | if (ls->t.token == l_c(';') || ls->t.token == l_c('}')) break; | ||
| 502 | recfield(ls, t); | 506 | recfield(ls, t); |
| 503 | n++; | 507 | n++; |
| 504 | } | 508 | } while (anotherfield(ls)); |
| 505 | return n; | 509 | return n; |
| 506 | } | 510 | } |
| 507 | 511 | ||
| @@ -514,13 +518,12 @@ static int listfields (LexState *ls, expdesc *t) { | |||
| 514 | int reg; | 518 | int reg; |
| 515 | reg = fs->freereg; | 519 | reg = fs->freereg; |
| 516 | expr(ls, &v); | 520 | expr(ls, &v); |
| 517 | while (ls->t.token == l_c(',') && | 521 | while (anotherfield(ls)) { |
| 518 | (next(ls), (ls->t.token != l_c(';') && ls->t.token != l_c('}')))) { | ||
| 519 | luaK_exp2nextreg(fs, &v); | 522 | luaK_exp2nextreg(fs, &v); |
| 520 | luaX_checklimit(ls, n, MAXARG_Bc, | 523 | luaX_checklimit(ls, n, MAXARG_Bc, |
| 521 | l_s("`item groups' in a list initializer")); | 524 | l_s("`item groups' in a list initializer")); |
| 522 | if (n%LFIELDS_PER_FLUSH == 0) { | 525 | if (n%LFIELDS_PER_FLUSH == 0) { |
| 523 | luaK_codeABc(fs, OP_SETLIST, t->u.i.info, n-1); | 526 | luaK_codeABc(fs, OP_SETLIST, t->u.i.info, n-1); /* flush */ |
| 524 | fs->freereg = reg; /* free registers */ | 527 | fs->freereg = reg; /* free registers */ |
| 525 | } | 528 | } |
| 526 | expr(ls, &v); | 529 | expr(ls, &v); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.179 2001/06/05 18:17:01 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.180 2001/06/05 19:27:32 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 | */ |
| @@ -346,9 +346,9 @@ static void adjust_varargs (lua_State *L, StkId base, int nfixargs) { | |||
| 346 | TObject tempb, tempc; \ | 346 | TObject tempb, tempc; \ |
| 347 | if ((ttype(b) == LUA_TNUMBER || (b = luaV_tonumber(b, &tempb)) != NULL) && \ | 347 | if ((ttype(b) == LUA_TNUMBER || (b = luaV_tonumber(b, &tempb)) != NULL) && \ |
| 348 | (ttype(c) == LUA_TNUMBER || (c = luaV_tonumber(c, &tempc)) != NULL)) { \ | 348 | (ttype(c) == LUA_TNUMBER || (c = luaV_tonumber(c, &tempc)) != NULL)) { \ |
| 349 | setnvalue(RA(i), nvalue(b) op nvalue(c)); \ | 349 | setnvalue(ra, nvalue(b) op nvalue(c)); \ |
| 350 | } else \ | 350 | } else \ |
| 351 | call_arith(L, RB(i), RKC(i), RA(i), optm); \ | 351 | call_arith(L, RB(i), RKC(i), ra, optm); \ |
| 352 | } | 352 | } |
| 353 | 353 | ||
| 354 | 354 | ||
| @@ -375,59 +375,57 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 375 | /* main loop of interpreter */ | 375 | /* main loop of interpreter */ |
| 376 | for (;;) { | 376 | for (;;) { |
| 377 | const Instruction i = *pc++; | 377 | const Instruction i = *pc++; |
| 378 | const StkId ra = RA(i); | ||
| 378 | if (linehook) | 379 | if (linehook) |
| 379 | traceexec(L, linehook); | 380 | traceexec(L, linehook); |
| 380 | switch (GET_OPCODE(i)) { | 381 | switch (GET_OPCODE(i)) { |
| 381 | case OP_MOVE: { | 382 | case OP_MOVE: { |
| 382 | setobj(RA(i), RB(i)); | 383 | setobj(ra, RB(i)); |
| 383 | break; | 384 | break; |
| 384 | } | 385 | } |
| 385 | case OP_LOADK: { | 386 | case OP_LOADK: { |
| 386 | setobj(RA(i), KBc(i)); | 387 | setobj(ra, KBc(i)); |
| 387 | break; | 388 | break; |
| 388 | } | 389 | } |
| 389 | case OP_LOADINT: { | 390 | case OP_LOADINT: { |
| 390 | setnvalue(RA(i), (lua_Number)GETARG_sBc(i)); | 391 | setnvalue(ra, (lua_Number)GETARG_sBc(i)); |
| 391 | break; | 392 | break; |
| 392 | } | 393 | } |
| 393 | case OP_LOADUPVAL: { | 394 | case OP_LOADUPVAL: { |
| 394 | setobj(RA(i), cl->upvalue+GETARG_Bc(i)); | 395 | setobj(ra, cl->upvalue+GETARG_Bc(i)); |
| 395 | break; | 396 | break; |
| 396 | } | 397 | } |
| 397 | case OP_LOADNIL: { | 398 | case OP_LOADNIL: { |
| 398 | TObject *ra = RA(i); | ||
| 399 | TObject *rb = RB(i); | 399 | TObject *rb = RB(i); |
| 400 | do { | 400 | do { |
| 401 | setnilvalue(ra++); | 401 | setnilvalue(rb--); |
| 402 | } while (ra <= rb); | 402 | } while (rb >= ra); |
| 403 | break; | 403 | break; |
| 404 | } | 404 | } |
| 405 | case OP_GETGLOBAL: { | 405 | case OP_GETGLOBAL: { |
| 406 | lua_assert(ttype(KBc(i)) == LUA_TSTRING); | 406 | lua_assert(ttype(KBc(i)) == LUA_TSTRING); |
| 407 | luaV_getglobal(L, tsvalue(KBc(i)), RA(i)); | 407 | luaV_getglobal(L, tsvalue(KBc(i)), ra); |
| 408 | break; | 408 | break; |
| 409 | } | 409 | } |
| 410 | case OP_GETTABLE: { | 410 | case OP_GETTABLE: { |
| 411 | luaV_gettable(L, RB(i), RKC(i), RA(i)); | 411 | luaV_gettable(L, RB(i), RKC(i), ra); |
| 412 | break; | 412 | break; |
| 413 | } | 413 | } |
| 414 | case OP_SETGLOBAL: { | 414 | case OP_SETGLOBAL: { |
| 415 | lua_assert(ttype(KBc(i)) == LUA_TSTRING); | 415 | lua_assert(ttype(KBc(i)) == LUA_TSTRING); |
| 416 | luaV_setglobal(L, tsvalue(KBc(i)), RA(i)); | 416 | luaV_setglobal(L, tsvalue(KBc(i)), ra); |
| 417 | break; | 417 | break; |
| 418 | } | 418 | } |
| 419 | case OP_SETTABLE: { | 419 | case OP_SETTABLE: { |
| 420 | luaV_settable(L, RB(i), RKC(i), RA(i)); | 420 | luaV_settable(L, RB(i), RKC(i), ra); |
| 421 | break; | 421 | break; |
| 422 | } | 422 | } |
| 423 | case OP_NEWTABLE: { | 423 | case OP_NEWTABLE: { |
| 424 | StkId ra = RA(i); | ||
| 425 | sethvalue(ra, luaH_new(L, GETARG_Bc(i))); | 424 | sethvalue(ra, luaH_new(L, GETARG_Bc(i))); |
| 426 | luaV_checkGC(L, ra+1); | 425 | luaV_checkGC(L, ra+1); |
| 427 | break; | 426 | break; |
| 428 | } | 427 | } |
| 429 | case OP_SELF: { | 428 | case OP_SELF: { |
| 430 | StkId ra = RA(i); | ||
| 431 | StkId rb = RB(i); | 429 | StkId rb = RB(i); |
| 432 | setobj(ra+1, rb); | 430 | setobj(ra+1, rb); |
| 433 | luaV_gettable(L, rb, RKC(i), ra); | 431 | luaV_gettable(L, rb, RKC(i), ra); |
| @@ -450,12 +448,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 450 | break; | 448 | break; |
| 451 | } | 449 | } |
| 452 | case OP_POW: { | 450 | case OP_POW: { |
| 453 | call_arith(L, RB(i), RKC(i), RA(i), TM_POW); | 451 | call_arith(L, RB(i), RKC(i), ra, TM_POW); |
| 454 | break; | 452 | break; |
| 455 | } | 453 | } |
| 456 | case OP_UNM: { | 454 | case OP_UNM: { |
| 457 | const TObject *rb = RB(i); | 455 | const TObject *rb = RB(i); |
| 458 | StkId ra = RA(i); | ||
| 459 | if (ttype(rb) == LUA_TNUMBER || (rb=luaV_tonumber(rb, ra)) != NULL) { | 456 | if (ttype(rb) == LUA_TNUMBER || (rb=luaV_tonumber(rb, ra)) != NULL) { |
| 460 | setnvalue(ra, -nvalue(rb)); | 457 | setnvalue(ra, -nvalue(rb)); |
| 461 | } | 458 | } |
| @@ -468,9 +465,9 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 468 | } | 465 | } |
| 469 | case OP_NOT: { | 466 | case OP_NOT: { |
| 470 | if (ttype(RB(i)) == LUA_TNIL) { | 467 | if (ttype(RB(i)) == LUA_TNIL) { |
| 471 | setnvalue(RA(i), 1); | 468 | setnvalue(ra, 1); |
| 472 | } else { | 469 | } else { |
| 473 | setnilvalue(RA(i)); | 470 | setnilvalue(ra); |
| 474 | } | 471 | } |
| 475 | break; | 472 | break; |
| 476 | } | 473 | } |
| @@ -478,7 +475,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 478 | StkId top = RC(i)+1; | 475 | StkId top = RC(i)+1; |
| 479 | StkId rb = RB(i); | 476 | StkId rb = RB(i); |
| 480 | luaV_strconc(L, top-rb, top); | 477 | luaV_strconc(L, top-rb, top); |
| 481 | setobj(RA(i), rb); | 478 | setobj(ra, rb); |
| 482 | break; | 479 | break; |
| 483 | } | 480 | } |
| 484 | case OP_CJMP: | 481 | case OP_CJMP: |
| @@ -526,8 +523,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 526 | StkId rb = RB(i); | 523 | StkId rb = RB(i); |
| 527 | lua_assert(GET_OPCODE(*pc) == OP_CJMP); | 524 | lua_assert(GET_OPCODE(*pc) == OP_CJMP); |
| 528 | if (ttype(rb) != LUA_TNIL) { | 525 | if (ttype(rb) != LUA_TNIL) { |
| 529 | int a = GETARG_A(i); | 526 | setobj(ra, rb); |
| 530 | if (a != NO_REG) setobj(base+a, rb); | ||
| 531 | dojump(pc, *pc); | 527 | dojump(pc, *pc); |
| 532 | } | 528 | } |
| 533 | pc++; | 529 | pc++; |
| @@ -536,15 +532,14 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 536 | case OP_TESTF: { | 532 | case OP_TESTF: { |
| 537 | lua_assert(GET_OPCODE(*pc) == OP_CJMP); | 533 | lua_assert(GET_OPCODE(*pc) == OP_CJMP); |
| 538 | if (ttype(RB(i)) == LUA_TNIL) { | 534 | if (ttype(RB(i)) == LUA_TNIL) { |
| 539 | int a = GETARG_A(i); | 535 | setnilvalue(ra); |
| 540 | if (a != NO_REG) setnilvalue(base+a); | ||
| 541 | dojump(pc, *pc); | 536 | dojump(pc, *pc); |
| 542 | } | 537 | } |
| 543 | pc++; | 538 | pc++; |
| 544 | break; | 539 | break; |
| 545 | } | 540 | } |
| 546 | case OP_NILJMP: { | 541 | case OP_NILJMP: { |
| 547 | setnilvalue(RA(i)); | 542 | setnilvalue(ra); |
| 548 | pc++; | 543 | pc++; |
| 549 | break; | 544 | break; |
| 550 | } | 545 | } |
| @@ -555,9 +550,9 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 555 | L->top = base+b; | 550 | L->top = base+b; |
| 556 | nres = GETARG_C(i); | 551 | nres = GETARG_C(i); |
| 557 | if (nres == NO_REG) nres = LUA_MULTRET; | 552 | if (nres == NO_REG) nres = LUA_MULTRET; |
| 558 | luaD_call(L, RA(i), nres); | 553 | luaD_call(L, ra, nres); |
| 559 | if (nres != LUA_MULTRET) { | 554 | if (nres != LUA_MULTRET) { |
| 560 | lua_assert(L->top == RA(i)+nres); | 555 | lua_assert(L->top == ra+nres); |
| 561 | L->top = base+tf->maxstacksize; | 556 | L->top = base+tf->maxstacksize; |
| 562 | } | 557 | } |
| 563 | break; | 558 | break; |
| @@ -566,59 +561,55 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 566 | int b = GETARG_B(i); | 561 | int b = GETARG_B(i); |
| 567 | if (b != NO_REG) | 562 | if (b != NO_REG) |
| 568 | L->top = base+b; | 563 | L->top = base+b; |
| 569 | return RA(i); | 564 | return ra; |
| 570 | } | 565 | } |
| 571 | case OP_FORPREP: { | 566 | case OP_FORPREP: { |
| 572 | int jmp = GETARG_sBc(i); | 567 | int jmp = GETARG_sBc(i); |
| 573 | StkId breg = RA(i); | 568 | if (luaV_tonumber(ra, ra) == NULL) |
| 574 | if (luaV_tonumber(breg, breg) == NULL) | ||
| 575 | luaD_error(L, l_s("`for' initial value must be a number")); | 569 | luaD_error(L, l_s("`for' initial value must be a number")); |
| 576 | if (luaV_tonumber(breg+1, breg+1) == NULL) | 570 | if (luaV_tonumber(ra+1, ra+1) == NULL) |
| 577 | luaD_error(L, l_s("`for' limit must be a number")); | 571 | luaD_error(L, l_s("`for' limit must be a number")); |
| 578 | if (luaV_tonumber(breg+2, breg+2) == NULL) | 572 | if (luaV_tonumber(ra+2, ra+2) == NULL) |
| 579 | luaD_error(L, l_s("`for' step must be a number")); | 573 | luaD_error(L, l_s("`for' step must be a number")); |
| 580 | pc += -jmp; /* `jump' to loop end (delta is negated here) */ | 574 | pc += -jmp; /* `jump' to loop end (delta is negated here) */ |
| 581 | nvalue(breg) -= nvalue(breg+2);/* decrement index (to be incremented) */ | 575 | nvalue(ra) -= nvalue(ra+2);/* decrement index (to be incremented) */ |
| 582 | /* go through */ | 576 | /* go through */ |
| 583 | } | 577 | } |
| 584 | case OP_FORLOOP: { | 578 | case OP_FORLOOP: { |
| 585 | StkId breg = RA(i); | 579 | if (ttype(ra) != LUA_TNUMBER) |
| 586 | if (ttype(breg) != LUA_TNUMBER) | ||
| 587 | luaD_error(L, l_s("`for' index must be a number")); | 580 | luaD_error(L, l_s("`for' index must be a number")); |
| 588 | runtime_check(L, ttype(breg+1) == LUA_TNUMBER && | 581 | runtime_check(L, ttype(ra+1) == LUA_TNUMBER && |
| 589 | ttype(breg+2) == LUA_TNUMBER); | 582 | ttype(ra+2) == LUA_TNUMBER); |
| 590 | nvalue(breg) += nvalue(breg+2); /* increment index */ | 583 | nvalue(ra) += nvalue(ra+2); /* increment index */ |
| 591 | if (nvalue(breg+2) > 0 ? | 584 | if (nvalue(ra+2) > 0 ? |
| 592 | nvalue(breg) <= nvalue(breg+1) : | 585 | nvalue(ra) <= nvalue(ra+1) : |
| 593 | nvalue(breg) >= nvalue(breg+1)) | 586 | nvalue(ra) >= nvalue(ra+1)) |
| 594 | dojump(pc, i); /* repeat loop */ | 587 | dojump(pc, i); /* repeat loop */ |
| 595 | break; | 588 | break; |
| 596 | } | 589 | } |
| 597 | case OP_TFORPREP: { | 590 | case OP_TFORPREP: { |
| 598 | int jmp = GETARG_sBc(i); | 591 | int jmp = GETARG_sBc(i); |
| 599 | StkId breg = RA(i); | 592 | if (ttype(ra) != LUA_TTABLE) |
| 600 | if (ttype(breg) != LUA_TTABLE) | ||
| 601 | luaD_error(L, l_s("`for' table must be a table")); | 593 | luaD_error(L, l_s("`for' table must be a table")); |
| 602 | setnvalue(breg+1, -1); /* initial index */ | 594 | setnvalue(ra+1, -1); /* initial index */ |
| 603 | setnilvalue(breg+2); | 595 | setnilvalue(ra+2); |
| 604 | setnilvalue(breg+3); | 596 | setnilvalue(ra+3); |
| 605 | pc += -jmp; /* `jump' to loop end (delta is negated here) */ | 597 | pc += -jmp; /* `jump' to loop end (delta is negated here) */ |
| 606 | /* go through */ | 598 | /* go through */ |
| 607 | } | 599 | } |
| 608 | case OP_TFORLOOP: { | 600 | case OP_TFORLOOP: { |
| 609 | StkId breg = RA(i); | ||
| 610 | Hash *t; | 601 | Hash *t; |
| 611 | int n; | 602 | int n; |
| 612 | runtime_check(L, ttype(breg) == LUA_TTABLE); | 603 | runtime_check(L, ttype(ra) == LUA_TTABLE); |
| 613 | runtime_check(L, ttype(breg+1) == LUA_TNUMBER); | 604 | runtime_check(L, ttype(ra+1) == LUA_TNUMBER); |
| 614 | t = hvalue(breg); | 605 | t = hvalue(ra); |
| 615 | n = (int)nvalue(breg+1); | 606 | n = (int)nvalue(ra+1); |
| 616 | n = luaH_nexti(t, n); | 607 | n = luaH_nexti(t, n); |
| 617 | if (n != -1) { /* repeat loop? */ | 608 | if (n != -1) { /* repeat loop? */ |
| 618 | Node *node = node(t, n); | 609 | Node *node = node(t, n); |
| 619 | setnvalue(breg+1, n); /* index */ | 610 | setnvalue(ra+1, n); /* index */ |
| 620 | setkey2obj(breg+2, node); | 611 | setkey2obj(ra+2, node); |
| 621 | setobj(breg+3, val(node)); | 612 | setobj(ra+3, val(node)); |
| 622 | dojump(pc, i); /* repeat loop */ | 613 | dojump(pc, i); /* repeat loop */ |
| 623 | } | 614 | } |
| 624 | break; | 615 | break; |
| @@ -628,7 +619,6 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 628 | int bc; | 619 | int bc; |
| 629 | int n; | 620 | int n; |
| 630 | Hash *h; | 621 | Hash *h; |
| 631 | StkId ra = RA(i); | ||
| 632 | runtime_check(L, ttype(ra) == LUA_TTABLE); | 622 | runtime_check(L, ttype(ra) == LUA_TTABLE); |
| 633 | h = hvalue(ra); | 623 | h = hvalue(ra); |
| 634 | bc = GETARG_Bc(i); | 624 | bc = GETARG_Bc(i); |
| @@ -644,7 +634,6 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 644 | case OP_CLOSURE: { | 634 | case OP_CLOSURE: { |
| 645 | Proto *p = tf->kproto[GETARG_Bc(i)]; | 635 | Proto *p = tf->kproto[GETARG_Bc(i)]; |
| 646 | int nup = p->nupvalues; | 636 | int nup = p->nupvalues; |
| 647 | StkId ra = RA(i); | ||
| 648 | luaV_checkGC(L, ra+nup); | 637 | luaV_checkGC(L, ra+nup); |
| 649 | L->top = ra+nup; | 638 | L->top = ra+nup; |
| 650 | luaV_Lclosure(L, p, nup); | 639 | luaV_Lclosure(L, p, nup); |
