diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-06-05 11:56:18 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-06-05 11:56:18 -0300 |
commit | dbfb810267d8fd7ecf546ea1e1edc8892547e664 (patch) | |
tree | ca5906c0238233c903f2c9427646e67c74bc7806 /lvm.c | |
parent | 9c14b5e416e1ca3ebed37c4ceb860579124ac29f (diff) | |
download | lua-dbfb810267d8fd7ecf546ea1e1edc8892547e664.tar.gz lua-dbfb810267d8fd7ecf546ea1e1edc8892547e664.tar.bz2 lua-dbfb810267d8fd7ecf546ea1e1edc8892547e664.zip |
cleansing of lparser.c
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 25 |
1 files changed, 12 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.109 2000/05/25 19:02:21 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.110 2000/05/30 19:00:31 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 | */ |
@@ -483,13 +483,13 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
483 | 483 | ||
484 | case OP_SETMAP: { | 484 | case OP_SETMAP: { |
485 | int n = GETARG_U(i); | 485 | int n = GETARG_U(i); |
486 | StkId finaltop = top-2*(n+1); | 486 | StkId finaltop = top-2*n; |
487 | Hash *arr = avalue(finaltop-1); | 487 | Hash *arr = avalue(finaltop-1); |
488 | L->top = finaltop; /* final value of `top' (in case of errors) */ | 488 | L->top = finaltop; /* final value of `top' (in case of errors) */ |
489 | do { | 489 | for (; n; n--) { |
490 | luaH_set(L, arr, top-2, top-1); | 490 | luaH_set(L, arr, top-2, top-1); |
491 | top-=2; | 491 | top-=2; |
492 | } while (n--); | 492 | } |
493 | break; | 493 | break; |
494 | } | 494 | } |
495 | 495 | ||
@@ -625,23 +625,22 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
625 | lua_error(L, "`for' limit must be a number"); | 625 | lua_error(L, "`for' limit must be a number"); |
626 | if (tonumber(top-3)) | 626 | if (tonumber(top-3)) |
627 | lua_error(L, "`for' initial value must be a number"); | 627 | lua_error(L, "`for' initial value must be a number"); |
628 | /* number of steps */ | ||
629 | nvalue(top-2) = (nvalue(top-2)-nvalue(top-3))/nvalue(top-1); | ||
628 | nvalue(top-3) -= nvalue(top-1); /* to be undone by first FORLOOP */ | 630 | nvalue(top-3) -= nvalue(top-1); /* to be undone by first FORLOOP */ |
629 | pc += GETARG_S(i); | 631 | pc += GETARG_S(i); |
630 | break; | 632 | break; |
631 | 633 | ||
632 | case OP_FORLOOP: { | 634 | case OP_FORLOOP: { |
633 | Number step = nvalue(top-1); | ||
634 | Number limit = nvalue(top-2); | ||
635 | Number index; | ||
636 | LUA_ASSERT(L, ttype(top-1) == TAG_NUMBER, "invalid step"); | 635 | LUA_ASSERT(L, ttype(top-1) == TAG_NUMBER, "invalid step"); |
637 | LUA_ASSERT(L, ttype(top-2) == TAG_NUMBER, "invalid limit"); | 636 | LUA_ASSERT(L, ttype(top-2) == TAG_NUMBER, "invalid count"); |
638 | if (ttype(top-3) != TAG_NUMBER) | 637 | if (nvalue(top-2) < 0) |
639 | lua_error(L, "`for' index must be a number"); | ||
640 | index = nvalue(top-3)+step; | ||
641 | if ((step>0) ? index>limit : index<limit) | ||
642 | top -= 3; /* end loop: remove control variables */ | 638 | top -= 3; /* end loop: remove control variables */ |
643 | else { | 639 | else { |
644 | nvalue(top-3) = index; | 640 | nvalue(top-2)--; /* decrement count */ |
641 | if (ttype(top-3) != TAG_NUMBER) | ||
642 | lua_error(L, "`for' index must be a number"); | ||
643 | nvalue(top-3) += nvalue(top-1); /* increment index */ | ||
645 | pc += GETARG_S(i); | 644 | pc += GETARG_S(i); |
646 | } | 645 | } |
647 | break; | 646 | break; |