aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-31 11:08:27 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-31 11:08:27 -0300
commit100bfec39a3de3029a97e645e7fe33877d7bbc2f (patch)
tree01c2c9bb63f71d3fb186b8f5be0b7577978f8a19 /lvm.c
parenta290b84c670bbf0770d76429e7282c555a80058e (diff)
downloadlua-100bfec39a3de3029a97e645e7fe33877d7bbc2f.tar.gz
lua-100bfec39a3de3029a97e645e7fe33877d7bbc2f.tar.bz2
lua-100bfec39a3de3029a97e645e7fe33877d7bbc2f.zip
new implementation for `next'
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/lvm.c b/lvm.c
index b9f5f74e..fb7998f4 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.130 2000/08/29 14:41:56 roberto Exp roberto $ 2** $Id: lvm.c,v 1.131 2000/08/29 14:48:16 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*/
@@ -656,34 +656,30 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
656 break; 656 break;
657 } 657 }
658 case OP_LFORPREP: { 658 case OP_LFORPREP: {
659 Node *node;
659 if (ttype(top-1) != TAG_TABLE) 660 if (ttype(top-1) != TAG_TABLE)
660 lua_error(L, "`for' table must be a table"); 661 lua_error(L, "`for' table must be a table");
661 top++; /* counter */ 662 node = luaH_next(L, hvalue(top-1), &luaO_nilobject);
662 L->top = top; 663 if (node == NULL) { /* `empty' loop? */
663 ttype(top-1) = TAG_NUMBER; 664 top--; /* remove table */
664 nvalue(top-1) = (Number)luaA_next(L, hvalue(top-2), 0); /* counter */
665 if (nvalue(top-1) == 0) { /* `empty' loop? */
666 top -= 2; /* remove table and counter */
667 pc += GETARG_S(i)+1; /* jump to loop end */ 665 pc += GETARG_S(i)+1; /* jump to loop end */
668 } 666 }
669 else { 667 else {
670 top += 2; /* index,value */ 668 top += 2; /* index,value */
671 LUA_ASSERT(top==L->top, "bad top"); 669 *(top-2) = *key(node);
670 *(top-1) = *val(node);
672 } 671 }
673 break; 672 break;
674 } 673 }
675 case OP_LFORLOOP: { 674 case OP_LFORLOOP: {
676 int n; 675 Node *node;
677 top -= 2; /* remove old index,value */ 676 LUA_ASSERT(ttype(top-3) == TAG_TABLE, "invalid table");
678 LUA_ASSERT(ttype(top-2) == TAG_TABLE, "invalid table"); 677 node = luaH_next(L, hvalue(top-3), top-2);
679 LUA_ASSERT(ttype(top-1) == TAG_NUMBER, "invalid counter"); 678 if (node == NULL) /* end loop? */
680 L->top = top; 679 top -= 3; /* remove table, key, and value */
681 n = luaA_next(L, hvalue(top-2), (int)nvalue(top-1));
682 if (n == 0) /* end loop? */
683 top -= 2; /* remove table and counter */
684 else { 680 else {
685 nvalue(top-1) = (Number)n; 681 *(top-2) = *key(node);
686 top += 2; /* new index,value */ 682 *(top-1) = *val(node);
687 pc += GETARG_S(i); /* repeat loop */ 683 pc += GETARG_S(i); /* repeat loop */
688 } 684 }
689 break; 685 break;