diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-25 14:47:14 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-25 14:47:14 -0300 |
| commit | 801aaf37b14a1fad5bb49c9a4200d25680152471 (patch) | |
| tree | e3cc5cdebac6d503091f4ba16444f8ecfa8dfdb2 | |
| parent | 00af2faae71e6388ee61ef18b2c5902a42e9bc27 (diff) | |
| download | lua-801aaf37b14a1fad5bb49c9a4200d25680152471.tar.gz lua-801aaf37b14a1fad5bb49c9a4200d25680152471.tar.bz2 lua-801aaf37b14a1fad5bb49c9a4200d25680152471.zip | |
simpler implementation for line information
| -rw-r--r-- | lcode.c | 27 | ||||
| -rw-r--r-- | ldebug.c | 85 | ||||
| -rw-r--r-- | ldebug.h | 3 | ||||
| -rw-r--r-- | ldo.c | 9 | ||||
| -rw-r--r-- | ldo.h | 4 | ||||
| -rw-r--r-- | lfunc.c | 5 | ||||
| -rw-r--r-- | lobject.h | 3 | ||||
| -rw-r--r-- | lopcodes.c | 8 | ||||
| -rw-r--r-- | lopcodes.h | 5 | ||||
| -rw-r--r-- | lparser.c | 18 | ||||
| -rw-r--r-- | lparser.h | 4 | ||||
| -rw-r--r-- | lstate.h | 8 | ||||
| -rw-r--r-- | ltests.c | 4 | ||||
| -rw-r--r-- | lundump.c | 3 | ||||
| -rw-r--r-- | lvm.c | 68 |
15 files changed, 79 insertions, 175 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 1.91 2002/03/08 19:10:32 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 1.92 2002/03/21 20:31:43 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 | */ |
| @@ -737,31 +737,16 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { | |||
| 737 | } | 737 | } |
| 738 | 738 | ||
| 739 | 739 | ||
| 740 | static void codelineinfo (FuncState *fs) { | ||
| 741 | Proto *f = fs->f; | ||
| 742 | LexState *ls = fs->ls; | ||
| 743 | if (ls->lastline > fs->lastline) { | ||
| 744 | if (ls->lastline > fs->lastline+1) { | ||
| 745 | luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, | ||
| 746 | MAX_INT, "line info overflow"); | ||
| 747 | f->lineinfo[fs->nlineinfo++] = -(ls->lastline - (fs->lastline+1)); | ||
| 748 | } | ||
| 749 | luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, | ||
| 750 | MAX_INT, "line info overflow"); | ||
| 751 | f->lineinfo[fs->nlineinfo++] = fs->pc; | ||
| 752 | fs->lastline = ls->lastline; | ||
| 753 | } | ||
| 754 | } | ||
| 755 | |||
| 756 | |||
| 757 | static int luaK_code (FuncState *fs, Instruction i) { | 740 | static int luaK_code (FuncState *fs, Instruction i) { |
| 758 | Proto *f; | 741 | Proto *f = fs->f; |
| 759 | codelineinfo(fs); | 742 | int oldsize = f->sizecode; |
| 760 | f = fs->f; | ||
| 761 | /* put new instruction in code array */ | 743 | /* put new instruction in code array */ |
| 762 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, | 744 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, |
| 763 | MAX_INT, "code size overflow"); | 745 | MAX_INT, "code size overflow"); |
| 764 | f->code[fs->pc] = i; | 746 | f->code[fs->pc] = i; |
| 747 | if (f->sizecode != oldsize) | ||
| 748 | luaM_reallocvector(fs->L, f->lineinfo, oldsize, f->sizecode, int); | ||
| 749 | f->lineinfo[fs->pc] = fs->ls->lastline; | ||
| 765 | return fs->pc++; | 750 | return fs->pc++; |
| 766 | } | 751 | } |
| 767 | 752 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 1.103 2002/03/19 12:45:25 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.104 2002/03/22 16:54:31 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 | */ |
| @@ -34,6 +34,24 @@ static int isLmark (CallInfo *ci) { | |||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | static int currentpc (lua_State *L, CallInfo *ci) { | ||
| 38 | if (ci->pc == NULL) return -1; /* function is not an active Lua function */ | ||
| 39 | if (ci == L->ci || ci->pc != (ci+1)->pc) /* no other function using `pc'? */ | ||
| 40 | return (*ci->pc - ci_func(ci)->l.p->code) - 1; | ||
| 41 | else /* function's pc is saved */ | ||
| 42 | return (ci->savedpc - ci_func(ci)->l.p->code) - 1; | ||
| 43 | } | ||
| 44 | |||
| 45 | |||
| 46 | static int currentline (lua_State *L, CallInfo *ci) { | ||
| 47 | int pc = currentpc(L, ci); | ||
| 48 | if (pc < 0) | ||
| 49 | return -1; /* only active lua functions have current-line information */ | ||
| 50 | else | ||
| 51 | return ci_func(ci)->l.p->lineinfo[pc]; | ||
| 52 | } | ||
| 53 | |||
| 54 | |||
| 37 | LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) { | 55 | LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) { |
| 38 | lua_Hook oldhook; | 56 | lua_Hook oldhook; |
| 39 | lua_lock(L); | 57 | lua_lock(L); |
| @@ -45,10 +63,13 @@ LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) { | |||
| 45 | 63 | ||
| 46 | 64 | ||
| 47 | LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) { | 65 | LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) { |
| 66 | CallInfo *ci; | ||
| 48 | lua_Hook oldhook; | 67 | lua_Hook oldhook; |
| 49 | lua_lock(L); | 68 | lua_lock(L); |
| 50 | oldhook = L->linehook; | 69 | oldhook = L->linehook; |
| 51 | L->linehook = func; | 70 | L->linehook = func; |
| 71 | for (ci = L->base_ci; ci <= L->ci; ci++) | ||
| 72 | ci->lastpc = currentpc(L, ci); | ||
| 52 | lua_unlock(L); | 73 | lua_unlock(L); |
| 53 | return oldhook; | 74 | return oldhook; |
| 54 | } | 75 | } |
| @@ -67,57 +88,6 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { | |||
| 67 | } | 88 | } |
| 68 | 89 | ||
| 69 | 90 | ||
| 70 | int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) { | ||
| 71 | int refi; | ||
| 72 | if (lineinfo == NULL) return -1; /* no line info */ | ||
| 73 | refi = prefi ? *prefi : 0; | ||
| 74 | if (lineinfo[refi] < 0) | ||
| 75 | refline += -lineinfo[refi++]; | ||
| 76 | lua_assert(lineinfo[refi] >= 0); | ||
| 77 | while (lineinfo[refi] > pc) { | ||
| 78 | refline--; | ||
| 79 | refi--; | ||
| 80 | if (lineinfo[refi] < 0) | ||
| 81 | refline -= -lineinfo[refi--]; | ||
| 82 | lua_assert(lineinfo[refi] >= 0); | ||
| 83 | } | ||
| 84 | for (;;) { | ||
| 85 | int nextline = refline + 1; | ||
| 86 | int nextref = refi + 1; | ||
| 87 | if (lineinfo[nextref] < 0) | ||
| 88 | nextline += -lineinfo[nextref++]; | ||
| 89 | lua_assert(lineinfo[nextref] >= 0); | ||
| 90 | if (lineinfo[nextref] > pc) | ||
| 91 | break; | ||
| 92 | refline = nextline; | ||
| 93 | refi = nextref; | ||
| 94 | } | ||
| 95 | if (prefi) *prefi = refi; | ||
| 96 | return refline; | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | static int currentpc (lua_State *L, CallInfo *ci) { | ||
| 101 | lua_assert(isLmark(ci)); | ||
| 102 | if (ci->pc == NULL) return 0; /* function is not active */ | ||
| 103 | if (ci == L->ci || ci->pc != (ci+1)->pc) /* no other function using `pc'? */ | ||
| 104 | return (*ci->pc - ci_func(ci)->l.p->code) - 1; | ||
| 105 | else /* function's pc is saved */ | ||
| 106 | return (ci->savedpc - ci_func(ci)->l.p->code) - 1; | ||
| 107 | } | ||
| 108 | |||
| 109 | |||
| 110 | static int currentline (lua_State *L, CallInfo *ci) { | ||
| 111 | if (!isLmark(ci)) | ||
| 112 | return -1; /* only active lua functions have current-line information */ | ||
| 113 | else { | ||
| 114 | int *lineinfo = ci_func(ci)->l.p->lineinfo; | ||
| 115 | return luaG_getline(lineinfo, currentpc(L, ci), 1, NULL); | ||
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | |||
| 120 | |||
| 121 | static Proto *getluaproto (CallInfo *ci) { | 91 | static Proto *getluaproto (CallInfo *ci) { |
| 122 | return (isLmark(ci) ? ci_func(ci)->l.p : NULL); | 92 | return (isLmark(ci) ? ci_func(ci)->l.p : NULL); |
| 123 | } | 93 | } |
| @@ -272,19 +242,8 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
| 272 | #define checkreg(pt,reg) check((reg) < (pt)->maxstacksize) | 242 | #define checkreg(pt,reg) check((reg) < (pt)->maxstacksize) |
| 273 | 243 | ||
| 274 | 244 | ||
| 275 | static int checklineinfo (const Proto *pt) { | ||
| 276 | int *lineinfo = pt->lineinfo; | ||
| 277 | if (lineinfo == NULL) return 1; | ||
| 278 | check(pt->sizelineinfo >= 2 && lineinfo[pt->sizelineinfo-1] == MAX_INT); | ||
| 279 | lua_assert(luaG_getline(lineinfo, pt->sizecode-1, 1, NULL) < MAX_INT); | ||
| 280 | if (*lineinfo < 0) lineinfo++; | ||
| 281 | check(*lineinfo == 0); | ||
| 282 | return 1; | ||
| 283 | } | ||
| 284 | |||
| 285 | 245 | ||
| 286 | static int precheck (const Proto *pt) { | 246 | static int precheck (const Proto *pt) { |
| 287 | check(checklineinfo(pt)); | ||
| 288 | check(pt->maxstacksize <= MAXSTACK); | 247 | check(pt->maxstacksize <= MAXSTACK); |
| 289 | lua_assert(pt->numparams+pt->is_vararg <= pt->maxstacksize); | 248 | lua_assert(pt->numparams+pt->is_vararg <= pt->maxstacksize); |
| 290 | check(GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); | 249 | check(GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.h,v 1.16 2001/11/28 20:13:13 roberto Exp roberto $ | 2 | ** $Id: ldebug.h,v 1.17 2002/03/19 12:45:25 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 | */ |
| @@ -15,7 +15,6 @@ | |||
| 15 | void luaG_typeerror (lua_State *L, const TObject *o, const char *opname); | 15 | void luaG_typeerror (lua_State *L, const TObject *o, const char *opname); |
| 16 | void luaG_concaterror (lua_State *L, StkId p1, StkId p2); | 16 | void luaG_concaterror (lua_State *L, StkId p1, StkId p2); |
| 17 | void luaG_aritherror (lua_State *L, StkId p1, const TObject *p2); | 17 | void luaG_aritherror (lua_State *L, StkId p1, const TObject *p2); |
| 18 | int luaG_getline (int *lineinfo, int pc, int refline, int *refi); | ||
| 19 | void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2); | 18 | void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2); |
| 20 | int luaG_checkcode (const Proto *pt); | 19 | int luaG_checkcode (const Proto *pt); |
| 21 | 20 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.164 2002/03/15 17:17:16 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.165 2002/03/20 12:52:32 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -122,13 +122,13 @@ static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) { | |||
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | 124 | ||
| 125 | void luaD_lineHook (lua_State *L, int line, lua_Hook linehook) { | 125 | void luaD_lineHook (lua_State *L, int line) { |
| 126 | if (L->allowhooks) { | 126 | if (L->allowhooks) { |
| 127 | lua_Debug ar; | 127 | lua_Debug ar; |
| 128 | ar.event = "line"; | 128 | ar.event = "line"; |
| 129 | ar.i_ci = L->ci - L->base_ci; | 129 | ar.i_ci = L->ci - L->base_ci; |
| 130 | ar.currentline = line; | 130 | ar.currentline = line; |
| 131 | dohook(L, &ar, linehook); | 131 | dohook(L, &ar, L->linehook); |
| 132 | } | 132 | } |
| 133 | } | 133 | } |
| 134 | 134 | ||
| @@ -221,7 +221,6 @@ StkId luaD_precall (lua_State *L, StkId func) { | |||
| 221 | if (p->is_vararg) /* varargs? */ | 221 | if (p->is_vararg) /* varargs? */ |
| 222 | adjust_varargs(L, p->numparams); | 222 | adjust_varargs(L, p->numparams); |
| 223 | luaD_checkstack(L, p->maxstacksize); | 223 | luaD_checkstack(L, p->maxstacksize); |
| 224 | ci->line = 0; | ||
| 225 | ci->top = ci->base + p->maxstacksize; | 224 | ci->top = ci->base + p->maxstacksize; |
| 226 | while (L->top < ci->top) | 225 | while (L->top < ci->top) |
| 227 | setnilvalue(L->top++); | 226 | setnilvalue(L->top++); |
| @@ -250,7 +249,7 @@ void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { | |||
| 250 | luaD_callHook(L, L->callhook, "return"); | 249 | luaD_callHook(L, L->callhook, "return"); |
| 251 | firstResult = restorestack(L, fr); | 250 | firstResult = restorestack(L, fr); |
| 252 | } | 251 | } |
| 253 | res = L->ci->base - 1; /* func == final position of 1st result */ | 252 | res = L->ci->base - 1; /* res == final position of 1st result */ |
| 254 | L->ci--; | 253 | L->ci--; |
| 255 | /* move results to correct place */ | 254 | /* move results to correct place */ |
| 256 | while (wanted != 0 && firstResult < L->top) { | 255 | while (wanted != 0 && firstResult < L->top) { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.h,v 1.40 2002/01/30 17:27:53 roberto Exp roberto $ | 2 | ** $Id: ldo.h,v 1.41 2002/03/20 12:52:32 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -27,7 +27,7 @@ | |||
| 27 | #define restorestack(L,n) ((TObject *)((char *)L->stack + (n))) | 27 | #define restorestack(L,n) ((TObject *)((char *)L->stack + (n))) |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | void luaD_lineHook (lua_State *L, int line, lua_Hook linehook); | 30 | void luaD_lineHook (lua_State *L, int line); |
| 31 | StkId luaD_precall (lua_State *L, StkId func); | 31 | StkId luaD_precall (lua_State *L, StkId func); |
| 32 | void luaD_call (lua_State *L, StkId func, int nResults); | 32 | void luaD_call (lua_State *L, StkId func, int nResults); |
| 33 | void luaD_poscall (lua_State *L, int wanted, StkId firstResult); | 33 | void luaD_poscall (lua_State *L, int wanted, StkId firstResult); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.c,v 1.53 2001/12/21 17:31:35 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 1.54 2002/03/05 12:42:47 roberto Exp roberto $ |
| 3 | ** Auxiliary functions to manipulate prototypes and closures | 3 | ** Auxiliary functions to manipulate prototypes and closures |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -87,7 +87,6 @@ Proto *luaF_newproto (lua_State *L) { | |||
| 87 | f->marked = 0; | 87 | f->marked = 0; |
| 88 | f->lineinfo = NULL; | 88 | f->lineinfo = NULL; |
| 89 | f->sizelocvars = 0; | 89 | f->sizelocvars = 0; |
| 90 | f->sizelineinfo = 0; | ||
| 91 | f->locvars = NULL; | 90 | f->locvars = NULL; |
| 92 | f->lineDefined = 0; | 91 | f->lineDefined = 0; |
| 93 | f->source = NULL; | 92 | f->source = NULL; |
| @@ -99,10 +98,10 @@ Proto *luaF_newproto (lua_State *L) { | |||
| 99 | 98 | ||
| 100 | void luaF_freeproto (lua_State *L, Proto *f) { | 99 | void luaF_freeproto (lua_State *L, Proto *f) { |
| 101 | luaM_freearray(L, f->code, f->sizecode, Instruction); | 100 | luaM_freearray(L, f->code, f->sizecode, Instruction); |
| 101 | luaM_freearray(L, f->lineinfo, f->sizecode, int); | ||
| 102 | luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); | 102 | luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); |
| 103 | luaM_freearray(L, f->k, f->sizek, TObject); | 103 | luaM_freearray(L, f->k, f->sizek, TObject); |
| 104 | luaM_freearray(L, f->p, f->sizep, Proto *); | 104 | luaM_freearray(L, f->p, f->sizep, Proto *); |
| 105 | luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); | ||
| 106 | luaM_freelem(L, f); | 105 | luaM_freelem(L, f); |
| 107 | } | 106 | } |
| 108 | 107 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 1.126 2002/03/11 12:45:00 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.127 2002/03/18 18:16:16 roberto Exp roberto $ |
| 3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -129,7 +129,6 @@ typedef struct Proto { | |||
| 129 | int sizek; /* size of `k' */ | 129 | int sizek; /* size of `k' */ |
| 130 | int sizecode; | 130 | int sizecode; |
| 131 | int sizep; /* size of `p' */ | 131 | int sizep; /* size of `p' */ |
| 132 | int sizelineinfo; /* size of `lineinfo' */ | ||
| 133 | int sizelocvars; | 132 | int sizelocvars; |
| 134 | int lineDefined; | 133 | int lineDefined; |
| 135 | lu_byte nupvalues; | 134 | lu_byte nupvalues; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.c,v 1.12 2002/03/08 19:10:32 roberto Exp roberto $ | 2 | ** $Id: lopcodes.c,v 1.13 2002/03/21 20:32:22 roberto Exp roberto $ |
| 3 | ** extracted automatically from lopcodes.h by mkprint.lua | 3 | ** extracted automatically from lopcodes.h by mkprint.lua |
| 4 | ** DO NOT EDIT | 4 | ** DO NOT EDIT |
| 5 | ** See Copyright Notice in lua.h | 5 | ** See Copyright Notice in lua.h |
| @@ -59,11 +59,11 @@ const char *const luaP_opnames[] = { | |||
| 59 | 59 | ||
| 60 | #define opmode(t,x,b,c,sa,k,m) (((t)<<OpModeT) | \ | 60 | #define opmode(t,x,b,c,sa,k,m) (((t)<<OpModeT) | \ |
| 61 | ((b)<<OpModeBreg) | ((c)<<OpModeCreg) | \ | 61 | ((b)<<OpModeBreg) | ((c)<<OpModeCreg) | \ |
| 62 | ((sa)<<OpModesetA) | ((k)<<OpModeK) | (x)<<OpModeNoTrace | (m)) | 62 | ((sa)<<OpModesetA) | ((k)<<OpModeK) | (m)) |
| 63 | 63 | ||
| 64 | 64 | ||
| 65 | const lu_byte luaP_opmodes[NUM_OPCODES] = { | 65 | const lu_byte luaP_opmodes[NUM_OPCODES] = { |
| 66 | /* T n B C sA K mode opcode */ | 66 | /* T _ B C sA K mode opcode */ |
| 67 | opmode(0,0,1,0, 1,0,iABC) /* OP_MOVE */ | 67 | opmode(0,0,1,0, 1,0,iABC) /* OP_MOVE */ |
| 68 | ,opmode(0,0,0,0, 1,1,iABc) /* OP_LOADK */ | 68 | ,opmode(0,0,0,0, 1,1,iABc) /* OP_LOADK */ |
| 69 | ,opmode(0,0,0,0, 1,0,iABC) /* OP_LOADBOOL */ | 69 | ,opmode(0,0,0,0, 1,0,iABC) /* OP_LOADBOOL */ |
| @@ -96,7 +96,7 @@ const lu_byte luaP_opmodes[NUM_OPCODES] = { | |||
| 96 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_CALL */ | 96 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_CALL */ |
| 97 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_TAILCALL */ | 97 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_TAILCALL */ |
| 98 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_RETURN */ | 98 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_RETURN */ |
| 99 | ,opmode(0,1,0,0, 0,0,iAsBc) /* OP_FORLOOP */ | 99 | ,opmode(0,0,0,0, 0,0,iAsBc) /* OP_FORLOOP */ |
| 100 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_TFORLOOP */ | 100 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_TFORLOOP */ |
| 101 | ,opmode(0,0,0,0, 0,0,iABc) /* OP_SETLIST */ | 101 | ,opmode(0,0,0,0, 0,0,iABc) /* OP_SETLIST */ |
| 102 | ,opmode(0,0,0,0, 0,0,iABc) /* OP_SETLISTO */ | 102 | ,opmode(0,0,0,0, 0,0,iABc) /* OP_SETLISTO */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.h,v 1.91 2002/03/18 14:49:46 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.92 2002/03/21 20:32:22 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 | */ |
| @@ -207,8 +207,7 @@ enum OpModeMask { | |||
| 207 | OpModeCreg, /* C is a register/constant */ | 207 | OpModeCreg, /* C is a register/constant */ |
| 208 | OpModesetA, /* instruction set register A */ | 208 | OpModesetA, /* instruction set register A */ |
| 209 | OpModeK, /* Bc is a constant */ | 209 | OpModeK, /* Bc is a constant */ |
| 210 | OpModeT, /* operator is a test */ | 210 | OpModeT /* operator is a test */ |
| 211 | OpModeNoTrace /* operator should not be traced */ | ||
| 212 | }; | 211 | }; |
| 213 | 212 | ||
| 214 | extern const lu_byte luaP_opmodes[NUM_OPCODES]; | 213 | extern const lu_byte luaP_opmodes[NUM_OPCODES]; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.171 2002/03/18 14:49:46 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.172 2002/03/21 20:32:22 roberto Exp roberto $ |
| 3 | ** Lua Parser | 3 | ** Lua Parser |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -376,11 +376,9 @@ static void open_func (LexState *ls, FuncState *fs) { | |||
| 376 | fs->nk = 0; | 376 | fs->nk = 0; |
| 377 | fs->h = luaH_new(ls->L, 0, 0); | 377 | fs->h = luaH_new(ls->L, 0, 0); |
| 378 | fs->np = 0; | 378 | fs->np = 0; |
| 379 | fs->nlineinfo = 0; | ||
| 380 | fs->nlocvars = 0; | 379 | fs->nlocvars = 0; |
| 381 | fs->nactloc = 0; | 380 | fs->nactloc = 0; |
| 382 | fs->nactvar = 0; | 381 | fs->nactvar = 0; |
| 383 | fs->lastline = 0; | ||
| 384 | fs->defaultglob = NO_REG; /* default is free globals */ | 382 | fs->defaultglob = NO_REG; /* default is free globals */ |
| 385 | fs->bl = NULL; | 383 | fs->bl = NULL; |
| 386 | f->code = NULL; | 384 | f->code = NULL; |
| @@ -402,6 +400,7 @@ static void close_func (LexState *ls) { | |||
| 402 | G(L)->roottable = fs->h->next; | 400 | G(L)->roottable = fs->h->next; |
| 403 | luaH_free(L, fs->h); | 401 | luaH_free(L, fs->h); |
| 404 | luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); | 402 | luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); |
| 403 | luaM_reallocvector(L, f->lineinfo, f->sizecode, fs->pc, int); | ||
| 405 | f->sizecode = fs->pc; | 404 | f->sizecode = fs->pc; |
| 406 | luaM_reallocvector(L, f->k, f->sizek, fs->nk, TObject); | 405 | luaM_reallocvector(L, f->k, f->sizek, fs->nk, TObject); |
| 407 | f->sizek = fs->nk; | 406 | f->sizek = fs->nk; |
| @@ -409,9 +408,6 @@ static void close_func (LexState *ls) { | |||
| 409 | f->sizep = fs->np; | 408 | f->sizep = fs->np; |
| 410 | luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); | 409 | luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); |
| 411 | f->sizelocvars = fs->nlocvars; | 410 | f->sizelocvars = fs->nlocvars; |
| 412 | luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->nlineinfo+1, int); | ||
| 413 | f->lineinfo[fs->nlineinfo++] = MAX_INT; /* end flag */ | ||
| 414 | f->sizelineinfo = fs->nlineinfo; | ||
| 415 | lua_assert(luaG_checkcode(f)); | 411 | lua_assert(luaG_checkcode(f)); |
| 416 | lua_assert(fs->bl == NULL); | 412 | lua_assert(fs->bl == NULL); |
| 417 | ls->fs = fs->prev; | 413 | ls->fs = fs->prev; |
| @@ -999,10 +995,10 @@ static int exp1 (LexState *ls) { | |||
| 999 | } | 995 | } |
| 1000 | 996 | ||
| 1001 | 997 | ||
| 1002 | static void fornum (LexState *ls, TString *varname) { | 998 | static void fornum (LexState *ls, TString *varname, int line) { |
| 1003 | /* fornum -> NAME = exp1,exp1[,exp1] DO body */ | 999 | /* fornum -> NAME = exp1,exp1[,exp1] DO body */ |
| 1004 | FuncState *fs = ls->fs; | 1000 | FuncState *fs = ls->fs; |
| 1005 | int prep; | 1001 | int prep, endfor; |
| 1006 | int base = fs->freereg; | 1002 | int base = fs->freereg; |
| 1007 | new_localvar(ls, varname, 0); | 1003 | new_localvar(ls, varname, 0); |
| 1008 | new_localvarstr(ls, "(for limit)", 1); | 1004 | new_localvarstr(ls, "(for limit)", 1); |
| @@ -1024,7 +1020,9 @@ static void fornum (LexState *ls, TString *varname) { | |||
| 1024 | check(ls, TK_DO); | 1020 | check(ls, TK_DO); |
| 1025 | block(ls); | 1021 | block(ls); |
| 1026 | luaK_patchtohere(fs, prep-1); | 1022 | luaK_patchtohere(fs, prep-1); |
| 1027 | luaK_patchlist(fs, luaK_codeAsBc(fs, OP_FORLOOP, base, NO_JUMP), prep); | 1023 | endfor = luaK_codeAsBc(fs, OP_FORLOOP, base, NO_JUMP); |
| 1024 | luaK_patchlist(fs, endfor, prep); | ||
| 1025 | fs->f->lineinfo[endfor] = line; /* pretend that `OP_FOR' starts the loop */ | ||
| 1028 | } | 1026 | } |
| 1029 | 1027 | ||
| 1030 | 1028 | ||
| @@ -1065,7 +1063,7 @@ static void forstat (LexState *ls, int line) { | |||
| 1065 | varname = str_checkname(ls); /* first variable name */ | 1063 | varname = str_checkname(ls); /* first variable name */ |
| 1066 | next(ls); /* skip var name */ | 1064 | next(ls); /* skip var name */ |
| 1067 | switch (ls->t.token) { | 1065 | switch (ls->t.token) { |
| 1068 | case '=': fornum(ls, varname); break; | 1066 | case '=': fornum(ls, varname, line); break; |
| 1069 | case ',': case TK_IN: forlist(ls, varname); break; | 1067 | case ',': case TK_IN: forlist(ls, varname); break; |
| 1070 | default: luaK_error(ls, "`=' or `in' expected"); | 1068 | default: luaK_error(ls, "`=' or `in' expected"); |
| 1071 | } | 1069 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.h,v 1.39 2002/02/08 22:42:41 roberto Exp roberto $ | 2 | ** $Id: lparser.h,v 1.40 2002/03/14 18:01:52 roberto Exp roberto $ |
| 3 | ** Lua Parser | 3 | ** Lua Parser |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -68,11 +68,9 @@ typedef struct FuncState { | |||
| 68 | int defaultglob; /* where to look for non-declared globals */ | 68 | int defaultglob; /* where to look for non-declared globals */ |
| 69 | int nk; /* number of elements in `k' */ | 69 | int nk; /* number of elements in `k' */ |
| 70 | int np; /* number of elements in `p' */ | 70 | int np; /* number of elements in `p' */ |
| 71 | int nlineinfo; /* number of elements in `lineinfo' */ | ||
| 72 | int nlocvars; /* number of elements in `locvars' */ | 71 | int nlocvars; /* number of elements in `locvars' */ |
| 73 | int nactloc; /* number of active local variables */ | 72 | int nactloc; /* number of active local variables */ |
| 74 | int nactvar; /* number of elements in array `actvar' */ | 73 | int nactvar; /* number of elements in array `actvar' */ |
| 75 | int lastline; /* line where last `lineinfo' was generated */ | ||
| 76 | expdesc upvalues[MAXUPVALUES]; /* upvalues */ | 74 | expdesc upvalues[MAXUPVALUES]; /* upvalues */ |
| 77 | vardesc actvar[MAXVARS]; /* declared-variable stack */ | 75 | vardesc actvar[MAXVARS]; /* declared-variable stack */ |
| 78 | } FuncState; | 76 | } FuncState; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.h,v 1.78 2002/03/07 18:11:51 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 1.79 2002/03/11 12:45:00 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -91,16 +91,12 @@ typedef struct CallInfo { | |||
| 91 | StkId top; /* top for this function (when it's a Lua function) */ | 91 | StkId top; /* top for this function (when it's a Lua function) */ |
| 92 | const Instruction **pc; /* points to `pc' variable in `luaV_execute' */ | 92 | const Instruction **pc; /* points to `pc' variable in `luaV_execute' */ |
| 93 | StkId *pb; /* points to `base' variable in `luaV_execute' */ | 93 | StkId *pb; /* points to `base' variable in `luaV_execute' */ |
| 94 | /* extra information for line tracing */ | ||
| 95 | int lastpc; /* last pc traced */ | 94 | int lastpc; /* last pc traced */ |
| 96 | int line; /* current line */ | 95 | int yield_results; |
| 97 | int refi; /* current index in `lineinfo' */ | ||
| 98 | } CallInfo; | 96 | } CallInfo; |
| 99 | 97 | ||
| 100 | #define ci_func(ci) (clvalue((ci)->base - 1)) | 98 | #define ci_func(ci) (clvalue((ci)->base - 1)) |
| 101 | 99 | ||
| 102 | #define yield_results refi /* reuse this field */ | ||
| 103 | |||
| 104 | 100 | ||
| 105 | /* | 101 | /* |
| 106 | ** `global state', shared by all threads of this state | 102 | ** `global state', shared by all threads of this state |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 1.112 2002/03/14 18:01:52 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.113 2002/03/20 12:54:08 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -144,7 +144,7 @@ static char *buildop (Proto *p, int pc, char *buff) { | |||
| 144 | Instruction i = p->code[pc]; | 144 | Instruction i = p->code[pc]; |
| 145 | OpCode o = GET_OPCODE(i); | 145 | OpCode o = GET_OPCODE(i); |
| 146 | const char *name = luaP_opnames[o]; | 146 | const char *name = luaP_opnames[o]; |
| 147 | int line = luaG_getline(p->lineinfo, pc, 1, NULL); | 147 | int line = p->lineinfo[pc]; |
| 148 | sprintf(buff, "(%4d) %4d - ", line, pc); | 148 | sprintf(buff, "(%4d) %4d - ", line, pc); |
| 149 | switch (getOpMode(o)) { | 149 | switch (getOpMode(o)) { |
| 150 | case iABC: | 150 | case iABC: |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lundump.c,v 1.43 2001/07/24 21:57:19 roberto Exp $ | 2 | ** $Id: lundump.c,v 1.44 2001/11/28 20:13:13 roberto Exp roberto $ |
| 3 | ** load pre-compiled Lua chunks | 3 | ** load pre-compiled Lua chunks |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -133,7 +133,6 @@ static void LoadLines (lua_State* L, Proto* f, ZIO* Z, int swap) | |||
| 133 | int n; | 133 | int n; |
| 134 | n=LoadInt(L,Z,swap); | 134 | n=LoadInt(L,Z,swap); |
| 135 | f->lineinfo=luaM_newvector(L,n,int); | 135 | f->lineinfo=luaM_newvector(L,n,int); |
| 136 | f->sizelineinfo=n; | ||
| 137 | LoadVector(L,f->lineinfo,n,sizeof(*f->lineinfo),Z,swap); | 136 | LoadVector(L,f->lineinfo,n,sizeof(*f->lineinfo),Z,swap); |
| 138 | } | 137 | } |
| 139 | 138 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.221 2002/03/20 12:52:32 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.222 2002/03/22 16:54: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 | */ |
| @@ -62,33 +62,17 @@ int luaV_tostring (lua_State *L, TObject *obj) { | |||
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | 64 | ||
| 65 | static void traceexec (lua_State *L, lua_Hook linehook) { | 65 | static void traceexec (lua_State *L) { |
| 66 | CallInfo *ci = L->ci; | 66 | CallInfo *ci = L->ci; |
| 67 | int *lineinfo = ci_func(ci)->l.p->lineinfo; | 67 | int *lineinfo = ci_func(ci)->l.p->lineinfo; |
| 68 | int pc = cast(int, *ci->pc - ci_func(ci)->l.p->code) - 1; | 68 | int pc = cast(int, *ci->pc - ci_func(ci)->l.p->code) - 1; |
| 69 | int newline; | 69 | int newline = lineinfo[pc]; |
| 70 | if (testOpMode(GET_OPCODE(*(*ci->pc - 1)), OpModeNoTrace)) | 70 | if (pc == 0) /* tracing may be starting now? */ |
| 71 | return; | 71 | ci->lastpc = 0; /* initialize `lastpc' */ |
| 72 | if (ci->line == -1) return; /* no linehooks for this function */ | ||
| 73 | else if (ci->line == 0) { /* first linehook? */ | ||
| 74 | if (pc == 0) { /* function is starting now? */ | ||
| 75 | ci->line = 1; | ||
| 76 | ci->refi = 0; | ||
| 77 | ci->lastpc = pc+1; /* make sure it will call linehook */ | ||
| 78 | } | ||
| 79 | else { /* function started without hooks: */ | ||
| 80 | ci->line = -1; /* keep it that way */ | ||
| 81 | return; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | newline = luaG_getline(lineinfo, pc, ci->line, &ci->refi); | ||
| 85 | /* calls linehook when enters a new line or jumps back (loop) */ | 72 | /* calls linehook when enters a new line or jumps back (loop) */ |
| 86 | if (newline != ci->line || pc <= ci->lastpc) { | 73 | if (pc <= ci->lastpc || newline != lineinfo[ci->lastpc]) |
| 87 | ci->line = newline; | 74 | luaD_lineHook(L, newline); |
| 88 | luaD_lineHook(L, newline, linehook); | 75 | L->ci->lastpc = pc; |
| 89 | ci = L->ci; /* previous call may realocate `ci' */ | ||
| 90 | } | ||
| 91 | ci->lastpc = pc; | ||
| 92 | } | 76 | } |
| 93 | 77 | ||
| 94 | 78 | ||
| @@ -316,21 +300,17 @@ static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) { | |||
| 316 | 300 | ||
| 317 | #define dojump(pc, i) ((pc) += (i)) | 301 | #define dojump(pc, i) ((pc) += (i)) |
| 318 | 302 | ||
| 319 | /* | 303 | |
| 320 | ** Executes current Lua function. Parameters are between [base,top). | ||
| 321 | ** Returns n such that the results are between [n,top). | ||
| 322 | */ | ||
| 323 | StkId luaV_execute (lua_State *L) { | 304 | StkId luaV_execute (lua_State *L) { |
| 324 | StkId base; | 305 | StkId base; |
| 325 | LClosure *cl; | 306 | LClosure *cl; |
| 326 | TObject *k; | 307 | TObject *k; |
| 327 | const Instruction *pc; | 308 | const Instruction *pc; |
| 328 | lua_Hook linehook; | 309 | callentry: /* entry point when calling new functions */ |
| 329 | reinit: | ||
| 330 | linehook = L->linehook; | ||
| 331 | L->ci->pc = &pc; | 310 | L->ci->pc = &pc; |
| 332 | pc = L->ci->savedpc; | ||
| 333 | L->ci->pb = &base; | 311 | L->ci->pb = &base; |
| 312 | pc = L->ci->savedpc; | ||
| 313 | retentry: /* entry point when returning to old functions */ | ||
| 334 | base = L->ci->base; | 314 | base = L->ci->base; |
| 335 | cl = &clvalue(base - 1)->l; | 315 | cl = &clvalue(base - 1)->l; |
| 336 | k = cl->p->k; | 316 | k = cl->p->k; |
| @@ -338,13 +318,13 @@ StkId luaV_execute (lua_State *L) { | |||
| 338 | for (;;) { | 318 | for (;;) { |
| 339 | const Instruction i = *pc++; | 319 | const Instruction i = *pc++; |
| 340 | StkId ra; | 320 | StkId ra; |
| 341 | if (linehook) | 321 | if (L->linehook) |
| 342 | traceexec(L, linehook); | 322 | traceexec(L); |
| 343 | ra = RA(i); | 323 | ra = RA(i); |
| 344 | lua_assert(L->top <= L->stack + L->stacksize && L->top >= L->ci->base); | 324 | lua_assert(L->top <= L->stack + L->stacksize && L->top >= L->ci->base); |
| 345 | lua_assert(L->top == L->ci->top || GET_OPCODE(i) == OP_CALL || | 325 | lua_assert(L->top == L->ci->top || |
| 346 | GET_OPCODE(i) == OP_TAILCALL || GET_OPCODE(i) == OP_RETURN || | 326 | GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || |
| 347 | GET_OPCODE(i) == OP_SETLISTO); | 327 | GET_OPCODE(i) == OP_RETURN || GET_OPCODE(i) == OP_SETLISTO); |
| 348 | switch (GET_OPCODE(i)) { | 328 | switch (GET_OPCODE(i)) { |
| 349 | case OP_MOVE: { | 329 | case OP_MOVE: { |
| 350 | setobj(ra, RB(i)); | 330 | setobj(ra, RB(i)); |
| @@ -453,7 +433,6 @@ StkId luaV_execute (lua_State *L) { | |||
| 453 | break; | 433 | break; |
| 454 | } | 434 | } |
| 455 | case OP_JMP: { | 435 | case OP_JMP: { |
| 456 | linehook = L->linehook; | ||
| 457 | dojump(pc, GETARG_sBc(i)); | 436 | dojump(pc, GETARG_sBc(i)); |
| 458 | break; | 437 | break; |
| 459 | } | 438 | } |
| @@ -511,7 +490,7 @@ StkId luaV_execute (lua_State *L) { | |||
| 511 | } | 490 | } |
| 512 | else { /* it is a Lua function: `call' it */ | 491 | else { /* it is a Lua function: `call' it */ |
| 513 | (L->ci-1)->savedpc = pc; | 492 | (L->ci-1)->savedpc = pc; |
| 514 | goto reinit; | 493 | goto callentry; |
| 515 | } | 494 | } |
| 516 | break; | 495 | break; |
| 517 | } | 496 | } |
| @@ -521,7 +500,7 @@ StkId luaV_execute (lua_State *L) { | |||
| 521 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ | 500 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ |
| 522 | luaD_poscall(L, LUA_MULTRET, ra); /* move down function and args. */ | 501 | luaD_poscall(L, LUA_MULTRET, ra); /* move down function and args. */ |
| 523 | ra = luaD_precall(L, base-1); | 502 | ra = luaD_precall(L, base-1); |
| 524 | if (ra == NULL) goto reinit; /* it is a Lua function */ | 503 | if (ra == NULL) goto callentry; /* it is a Lua function */ |
| 525 | else if (ra > L->top) return NULL; /* yield??? */ | 504 | else if (ra > L->top) return NULL; /* yield??? */ |
| 526 | else goto ret; | 505 | else goto ret; |
| 527 | } | 506 | } |
| @@ -540,14 +519,12 @@ StkId luaV_execute (lua_State *L) { | |||
| 540 | else { /* yes: continue its execution */ | 519 | else { /* yes: continue its execution */ |
| 541 | int nresults; | 520 | int nresults; |
| 542 | lua_assert(ttype(ci->base-1) == LUA_TFUNCTION); | 521 | lua_assert(ttype(ci->base-1) == LUA_TFUNCTION); |
| 543 | base = ci->base; /* restore previous values */ | ||
| 544 | cl = &clvalue(base - 1)->l; | ||
| 545 | k = cl->p->k; | ||
| 546 | pc = ci->savedpc; | 522 | pc = ci->savedpc; |
| 547 | lua_assert(GET_OPCODE(*(pc-1)) == OP_CALL); | 523 | lua_assert(GET_OPCODE(*(pc-1)) == OP_CALL); |
| 548 | nresults = GETARG_C(*(pc-1)) - 1; | 524 | nresults = GETARG_C(*(pc-1)) - 1; |
| 549 | luaD_poscall(L, nresults, ra); | 525 | luaD_poscall(L, nresults, ra); |
| 550 | if (nresults >= 0) L->top = L->ci->top; | 526 | if (nresults >= 0) L->top = L->ci->top; |
| 527 | goto retentry; | ||
| 551 | } | 528 | } |
| 552 | break; | 529 | break; |
| 553 | } | 530 | } |
| @@ -556,7 +533,6 @@ StkId luaV_execute (lua_State *L) { | |||
| 556 | int j = GETARG_sBc(i); | 533 | int j = GETARG_sBc(i); |
| 557 | const TObject *plimit = ra+1; | 534 | const TObject *plimit = ra+1; |
| 558 | const TObject *pstep = ra+2; | 535 | const TObject *pstep = ra+2; |
| 559 | dojump(pc, j); /* jump back before tests (for error messages) */ | ||
| 560 | if (ttype(ra) != LUA_TNUMBER) | 536 | if (ttype(ra) != LUA_TNUMBER) |
| 561 | luaD_error(L, "`for' initial value must be a number"); | 537 | luaD_error(L, "`for' initial value must be a number"); |
| 562 | if (!tonumber(plimit, ra+1)) | 538 | if (!tonumber(plimit, ra+1)) |
| @@ -567,11 +543,9 @@ StkId luaV_execute (lua_State *L) { | |||
| 567 | index = nvalue(ra) + step; /* increment index */ | 543 | index = nvalue(ra) + step; /* increment index */ |
| 568 | limit = nvalue(plimit); | 544 | limit = nvalue(plimit); |
| 569 | if (step > 0 ? index <= limit : index >= limit) { | 545 | if (step > 0 ? index <= limit : index >= limit) { |
| 546 | dojump(pc, j); /* jump back */ | ||
| 570 | chgnvalue(ra, index); /* update index */ | 547 | chgnvalue(ra, index); /* update index */ |
| 571 | linehook = L->linehook; | ||
| 572 | } | 548 | } |
| 573 | else | ||
| 574 | dojump(pc, -j); /* undo jump */ | ||
| 575 | break; | 549 | break; |
| 576 | } | 550 | } |
| 577 | case OP_TFORLOOP: { | 551 | case OP_TFORLOOP: { |
