diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-04-09 16:47:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-04-09 16:47:44 -0300 |
commit | 7b65328c8e89ecc999e47d00288bfa4cf6692cdc (patch) | |
tree | 4bff202763e7389ca40a44003703376d32eeaf78 /lvm.c | |
parent | d2e05589d738c3a1b563879435d5cc0830719fd1 (diff) | |
download | lua-7b65328c8e89ecc999e47d00288bfa4cf6692cdc.tar.gz lua-7b65328c8e89ecc999e47d00288bfa4cf6692cdc.tar.bz2 lua-7b65328c8e89ecc999e47d00288bfa4cf6692cdc.zip |
new semantics for `generic for' (with state)
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.222 2002/03/22 16:54:31 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.223 2002/03/25 17:47:14 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 | */ |
@@ -549,21 +549,21 @@ StkId luaV_execute (lua_State *L) { | |||
549 | break; | 549 | break; |
550 | } | 550 | } |
551 | case OP_TFORLOOP: { | 551 | case OP_TFORLOOP: { |
552 | setobj(ra+4, ra+2); | ||
553 | setobj(ra+3, ra+1); | ||
554 | setobj(ra+2, ra); | ||
555 | L->top = ra+5; | ||
556 | luaD_call(L, ra+2, GETARG_C(i) + 1); | ||
557 | L->top = L->ci->top; | ||
558 | if (ttype(ra+2) != LUA_TNIL) pc++; /* skip jump (keep looping) */ | ||
559 | break; | ||
560 | } | ||
561 | case OP_TFORPREP: { | ||
552 | if (ttype(ra) == LUA_TTABLE) { | 562 | if (ttype(ra) == LUA_TTABLE) { |
553 | Table *t = hvalue(ra); | ||
554 | if (luaH_next(L, t, ra+1)) | ||
555 | pc++; /* skip jump (keep looping) */ | ||
556 | } | ||
557 | else if (ttype(ra) == LUA_TFUNCTION) { | ||
558 | setobj(ra+1, ra); | 563 | setobj(ra+1, ra); |
559 | L->top = ra+2; /* no arguments */ | 564 | setsvalue(ra, luaS_new(L, "next")); |
560 | luaD_call(L, ra+1, GETARG_C(i)); | 565 | luaV_gettable(L, gt(L), ra, ra); |
561 | L->top = L->ci->top; | ||
562 | if (ttype(ra+1) != LUA_TNIL) | ||
563 | pc++; /* skip jump (keep looping) */ | ||
564 | } | 566 | } |
565 | else | ||
566 | luaD_error(L, "`for' generator must be a table or function"); | ||
567 | break; | 567 | break; |
568 | } | 568 | } |
569 | case OP_SETLIST: | 569 | case OP_SETLIST: |