diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-11-22 11:12:07 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-11-22 11:12:07 -0200 |
commit | 29ede6aa13144ff7b69c57a87be1ee93f57ae896 (patch) | |
tree | adcfb5dcff7db55481cd675349e23dec0e63c939 /lvm.c | |
parent | 951897c09319ae5474a4b86bb7d615136577caa0 (diff) | |
download | lua-29ede6aa13144ff7b69c57a87be1ee93f57ae896.tar.gz lua-29ede6aa13144ff7b69c57a87be1ee93f57ae896.tar.bz2 lua-29ede6aa13144ff7b69c57a87be1ee93f57ae896.zip |
first implementation of multiple states (reentrant code).
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 224 |
1 files changed, 113 insertions, 111 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.64 1999/10/14 19:46:57 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.65 1999/11/04 17:22:26 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 | */ |
@@ -9,6 +9,8 @@ | |||
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
10 | #include <string.h> | 10 | #include <string.h> |
11 | 11 | ||
12 | #define LUA_REENTRANT | ||
13 | |||
12 | #include "lauxlib.h" | 14 | #include "lauxlib.h" |
13 | #include "ldo.h" | 15 | #include "ldo.h" |
14 | #include "lfunc.h" | 16 | #include "lfunc.h" |
@@ -27,7 +29,7 @@ | |||
27 | #endif | 29 | #endif |
28 | 30 | ||
29 | 31 | ||
30 | #define highbyte(x) ((x)<<8) | 32 | #define highbyte(L, x) ((x)<<8) |
31 | 33 | ||
32 | 34 | ||
33 | /* Extra stack size to run a function: LUA_T_LINE(1), TM calls(2), ... */ | 35 | /* Extra stack size to run a function: LUA_T_LINE(1), TM calls(2), ... */ |
@@ -35,13 +37,13 @@ | |||
35 | 37 | ||
36 | 38 | ||
37 | 39 | ||
38 | static TaggedString *strconc (const TaggedString *l, const TaggedString *r) { | 40 | static TaggedString *strconc (lua_State *L, const TaggedString *l, const TaggedString *r) { |
39 | long nl = l->u.s.len; | 41 | long nl = l->u.s.len; |
40 | long nr = r->u.s.len; | 42 | long nr = r->u.s.len; |
41 | char *buffer = luaL_openspace(nl+nr); | 43 | char *buffer = luaL_openspace(L, nl+nr); |
42 | memcpy(buffer, l->str, nl); | 44 | memcpy(buffer, l->str, nl); |
43 | memcpy(buffer+nl, r->str, nr); | 45 | memcpy(buffer+nl, r->str, nr); |
44 | return luaS_newlstr(buffer, nl+nr); | 46 | return luaS_newlstr(L, buffer, nl+nr); |
45 | } | 47 | } |
46 | 48 | ||
47 | 49 | ||
@@ -57,31 +59,31 @@ int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */ | |||
57 | } | 59 | } |
58 | 60 | ||
59 | 61 | ||
60 | int luaV_tostring (TObject *obj) { /* LUA_NUMBER */ | 62 | int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */ |
61 | if (ttype(obj) != LUA_T_NUMBER) | 63 | if (ttype(obj) != LUA_T_NUMBER) |
62 | return 1; | 64 | return 1; |
63 | else { | 65 | else { |
64 | char s[32]; /* 16 digits, signal, point and \0 (+ some extra...) */ | 66 | char s[32]; /* 16 digits, signal, point and \0 (+ some extra...) */ |
65 | sprintf(s, "%.16g", (double)nvalue(obj)); | 67 | sprintf(s, "%.16g", (double)nvalue(obj)); |
66 | tsvalue(obj) = luaS_new(s); | 68 | tsvalue(obj) = luaS_new(L, s); |
67 | ttype(obj) = LUA_T_STRING; | 69 | ttype(obj) = LUA_T_STRING; |
68 | return 0; | 70 | return 0; |
69 | } | 71 | } |
70 | } | 72 | } |
71 | 73 | ||
72 | 74 | ||
73 | void luaV_setn (Hash *t, int val) { | 75 | void luaV_setn (lua_State *L, Hash *t, int val) { |
74 | TObject index, value; | 76 | TObject index, value; |
75 | ttype(&index) = LUA_T_STRING; tsvalue(&index) = luaS_new("n"); | 77 | ttype(&index) = LUA_T_STRING; tsvalue(&index) = luaS_new(L, "n"); |
76 | ttype(&value) = LUA_T_NUMBER; nvalue(&value) = val; | 78 | ttype(&value) = LUA_T_NUMBER; nvalue(&value) = val; |
77 | luaH_set(t, &index, &value); | 79 | luaH_set(L, t, &index, &value); |
78 | } | 80 | } |
79 | 81 | ||
80 | 82 | ||
81 | void luaV_closure (int nelems) { | 83 | void luaV_closure (lua_State *L, int nelems) { |
82 | if (nelems > 0) { | 84 | if (nelems > 0) { |
83 | struct Stack *S = &L->stack; | 85 | struct Stack *S = &L->stack; |
84 | Closure *c = luaF_newclosure(nelems); | 86 | Closure *c = luaF_newclosure(L, nelems); |
85 | c->consts[0] = *(S->top-1); | 87 | c->consts[0] = *(S->top-1); |
86 | memcpy(&c->consts[1], S->top-(nelems+1), nelems*sizeof(TObject)); | 88 | memcpy(&c->consts[1], S->top-(nelems+1), nelems*sizeof(TObject)); |
87 | S->top -= nelems; | 89 | S->top -= nelems; |
@@ -95,23 +97,23 @@ void luaV_closure (int nelems) { | |||
95 | ** Function to index a table. | 97 | ** Function to index a table. |
96 | ** Receives the table at top-2 and the index at top-1. | 98 | ** Receives the table at top-2 and the index at top-1. |
97 | */ | 99 | */ |
98 | void luaV_gettable (void) { | 100 | void luaV_gettable (lua_State *L) { |
99 | TObject *table = L->stack.top-2; | 101 | TObject *table = L->stack.top-2; |
100 | const TObject *im; | 102 | const TObject *im; |
101 | if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */ | 103 | if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */ |
102 | im = luaT_getimbyObj(table, IM_GETTABLE); | 104 | im = luaT_getimbyObj(L, table, IM_GETTABLE); |
103 | if (ttype(im) == LUA_T_NIL) | 105 | if (ttype(im) == LUA_T_NIL) |
104 | lua_error("indexed expression not a table"); | 106 | lua_error(L, "indexed expression not a table"); |
105 | } | 107 | } |
106 | else { /* object is a table... */ | 108 | else { /* object is a table... */ |
107 | int tg = table->value.a->htag; | 109 | int tg = table->value.a->htag; |
108 | im = luaT_getim(tg, IM_GETTABLE); | 110 | im = luaT_getim(L, tg, IM_GETTABLE); |
109 | if (ttype(im) == LUA_T_NIL) { /* and does not have a "gettable" method */ | 111 | if (ttype(im) == LUA_T_NIL) { /* and does not have a "gettable" method */ |
110 | const TObject *h = luaH_get(avalue(table), table+1); | 112 | const TObject *h = luaH_get(L, avalue(table), table+1); |
111 | if (ttype(h) == LUA_T_NIL && | 113 | if (ttype(h) == LUA_T_NIL && |
112 | (ttype(im=luaT_getim(tg, IM_INDEX)) != LUA_T_NIL)) { | 114 | (ttype(im=luaT_getim(L, tg, IM_INDEX)) != LUA_T_NIL)) { |
113 | /* result is nil and there is an "index" tag method */ | 115 | /* result is nil and there is an "index" tag method */ |
114 | luaD_callTM(im, 2, 1); /* calls it */ | 116 | luaD_callTM(L, im, 2, 1); /* calls it */ |
115 | } | 117 | } |
116 | else { | 118 | else { |
117 | L->stack.top--; | 119 | L->stack.top--; |
@@ -122,25 +124,25 @@ void luaV_gettable (void) { | |||
122 | /* else it has a "gettable" method, go through to next command */ | 124 | /* else it has a "gettable" method, go through to next command */ |
123 | } | 125 | } |
124 | /* object is not a table, or it has a "gettable" method */ | 126 | /* object is not a table, or it has a "gettable" method */ |
125 | luaD_callTM(im, 2, 1); | 127 | luaD_callTM(L, im, 2, 1); |
126 | } | 128 | } |
127 | 129 | ||
128 | 130 | ||
129 | /* | 131 | /* |
130 | ** Receives table at *t, index at *(t+1) and value at top. | 132 | ** Receives table at *t, index at *(t+1) and value at top. |
131 | */ | 133 | */ |
132 | void luaV_settable (const TObject *t) { | 134 | void luaV_settable (lua_State *L, const TObject *t) { |
133 | struct Stack *S = &L->stack; | 135 | struct Stack *S = &L->stack; |
134 | const TObject *im; | 136 | const TObject *im; |
135 | if (ttype(t) != LUA_T_ARRAY) { /* not a table, get "settable" method */ | 137 | if (ttype(t) != LUA_T_ARRAY) { /* not a table, get "settable" method */ |
136 | im = luaT_getimbyObj(t, IM_SETTABLE); | 138 | im = luaT_getimbyObj(L, t, IM_SETTABLE); |
137 | if (ttype(im) == LUA_T_NIL) | 139 | if (ttype(im) == LUA_T_NIL) |
138 | lua_error("indexed expression not a table"); | 140 | lua_error(L, "indexed expression not a table"); |
139 | } | 141 | } |
140 | else { /* object is a table... */ | 142 | else { /* object is a table... */ |
141 | im = luaT_getim(avalue(t)->htag, IM_SETTABLE); | 143 | im = luaT_getim(L, avalue(t)->htag, IM_SETTABLE); |
142 | if (ttype(im) == LUA_T_NIL) { /* and does not have a "settable" method */ | 144 | if (ttype(im) == LUA_T_NIL) { /* and does not have a "settable" method */ |
143 | luaH_set(avalue(t), t+1, S->top-1); | 145 | luaH_set(L, avalue(t), t+1, S->top-1); |
144 | S->top--; /* pop value */ | 146 | S->top--; /* pop value */ |
145 | return; | 147 | return; |
146 | } | 148 | } |
@@ -152,35 +154,35 @@ void luaV_settable (const TObject *t) { | |||
152 | *(S->top) = *(t+1); | 154 | *(S->top) = *(t+1); |
153 | *(S->top-1) = *t; | 155 | *(S->top-1) = *t; |
154 | S->top += 2; /* WARNING: caller must assure stack space */ | 156 | S->top += 2; /* WARNING: caller must assure stack space */ |
155 | luaD_callTM(im, 3, 0); | 157 | luaD_callTM(L, im, 3, 0); |
156 | } | 158 | } |
157 | 159 | ||
158 | 160 | ||
159 | void luaV_rawsettable (const TObject *t) { | 161 | void luaV_rawsettable (lua_State *L, const TObject *t) { |
160 | if (ttype(t) != LUA_T_ARRAY) | 162 | if (ttype(t) != LUA_T_ARRAY) |
161 | lua_error("indexed expression not a table"); | 163 | lua_error(L, "indexed expression not a table"); |
162 | else { | 164 | else { |
163 | struct Stack *S = &L->stack; | 165 | struct Stack *S = &L->stack; |
164 | luaH_set(avalue(t), t+1, S->top-1); | 166 | luaH_set(L, avalue(t), t+1, S->top-1); |
165 | S->top -= 3; | 167 | S->top -= 3; |
166 | } | 168 | } |
167 | } | 169 | } |
168 | 170 | ||
169 | 171 | ||
170 | void luaV_getglobal (GlobalVar *gv) { | 172 | void luaV_getglobal (lua_State *L, GlobalVar *gv) { |
171 | /* WARNING: caller must assure stack space */ | 173 | /* WARNING: caller must assure stack space */ |
172 | const TObject *value = &gv->value; | 174 | const TObject *value = &gv->value; |
173 | switch (ttype(value)) { | 175 | switch (ttype(value)) { |
174 | /* only userdata, tables and nil can have getglobal tag methods */ | 176 | /* only userdata, tables and nil can have getglobal tag methods */ |
175 | case LUA_T_USERDATA: case LUA_T_ARRAY: case LUA_T_NIL: { | 177 | case LUA_T_USERDATA: case LUA_T_ARRAY: case LUA_T_NIL: { |
176 | TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL); | 178 | TObject *im = luaT_getimbyObj(L, value, IM_GETGLOBAL); |
177 | if (ttype(im) != LUA_T_NIL) { /* is there a tag method? */ | 179 | if (ttype(im) != LUA_T_NIL) { /* is there a tag method? */ |
178 | struct Stack *S = &L->stack; | 180 | struct Stack *S = &L->stack; |
179 | ttype(S->top) = LUA_T_STRING; | 181 | ttype(S->top) = LUA_T_STRING; |
180 | tsvalue(S->top) = gv->name; /* global name */ | 182 | tsvalue(S->top) = gv->name; /* global name */ |
181 | S->top++; | 183 | S->top++; |
182 | *S->top++ = *value; | 184 | *S->top++ = *value; |
183 | luaD_callTM(im, 2, 1); | 185 | luaD_callTM(L, im, 2, 1); |
184 | return; | 186 | return; |
185 | } | 187 | } |
186 | /* else no tag method: go through to default behavior */ | 188 | /* else no tag method: go through to default behavior */ |
@@ -190,9 +192,9 @@ void luaV_getglobal (GlobalVar *gv) { | |||
190 | } | 192 | } |
191 | 193 | ||
192 | 194 | ||
193 | void luaV_setglobal (GlobalVar *gv) { | 195 | void luaV_setglobal (lua_State *L, GlobalVar *gv) { |
194 | const TObject *oldvalue = &gv->value; | 196 | const TObject *oldvalue = &gv->value; |
195 | const TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL); | 197 | const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL); |
196 | if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ | 198 | if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ |
197 | gv->value = *(--L->stack.top); | 199 | gv->value = *(--L->stack.top); |
198 | else { | 200 | else { |
@@ -204,29 +206,29 @@ void luaV_setglobal (GlobalVar *gv) { | |||
204 | tsvalue(S->top-1) = gv->name; | 206 | tsvalue(S->top-1) = gv->name; |
205 | *S->top++ = *oldvalue; | 207 | *S->top++ = *oldvalue; |
206 | *S->top++ = newvalue; | 208 | *S->top++ = newvalue; |
207 | luaD_callTM(im, 3, 0); | 209 | luaD_callTM(L, im, 3, 0); |
208 | } | 210 | } |
209 | } | 211 | } |
210 | 212 | ||
211 | 213 | ||
212 | static void call_binTM (IMS event, const char *msg) { | 214 | static void call_binTM (lua_State *L, IMS event, const char *msg) { |
213 | /* try first operand */ | 215 | /* try first operand */ |
214 | const TObject *im = luaT_getimbyObj(L->stack.top-2, event); | 216 | const TObject *im = luaT_getimbyObj(L, L->stack.top-2, event); |
215 | if (ttype(im) == LUA_T_NIL) { | 217 | if (ttype(im) == LUA_T_NIL) { |
216 | im = luaT_getimbyObj(L->stack.top-1, event); /* try second operand */ | 218 | im = luaT_getimbyObj(L, L->stack.top-1, event); /* try second operand */ |
217 | if (ttype(im) == LUA_T_NIL) { | 219 | if (ttype(im) == LUA_T_NIL) { |
218 | im = luaT_getim(0, event); /* try a 'global' i.m. */ | 220 | im = luaT_getim(L, 0, event); /* try a 'global' i.m. */ |
219 | if (ttype(im) == LUA_T_NIL) | 221 | if (ttype(im) == LUA_T_NIL) |
220 | lua_error(msg); | 222 | lua_error(L, msg); |
221 | } | 223 | } |
222 | } | 224 | } |
223 | lua_pushstring(luaT_eventname[event]); | 225 | lua_pushstring(L, luaT_eventname[event]); |
224 | luaD_callTM(im, 3, 1); | 226 | luaD_callTM(L, im, 3, 1); |
225 | } | 227 | } |
226 | 228 | ||
227 | 229 | ||
228 | static void call_arith (IMS event) { | 230 | static void call_arith (lua_State *L, IMS event) { |
229 | call_binTM(event, "unexpected type in arithmetic operation"); | 231 | call_binTM(L, event, "unexpected type in arithmetic operation"); |
230 | } | 232 | } |
231 | 233 | ||
232 | 234 | ||
@@ -246,7 +248,7 @@ static int luaV_strcomp (const char *l, long ll, const char *r, long lr) { | |||
246 | } | 248 | } |
247 | } | 249 | } |
248 | 250 | ||
249 | void luaV_comparison (lua_Type ttype_less, lua_Type ttype_equal, | 251 | void luaV_comparison (lua_State *L, lua_Type ttype_less, lua_Type ttype_equal, |
250 | lua_Type ttype_great, IMS op) { | 252 | lua_Type ttype_great, IMS op) { |
251 | struct Stack *S = &L->stack; | 253 | struct Stack *S = &L->stack; |
252 | const TObject *l = S->top-2; | 254 | const TObject *l = S->top-2; |
@@ -258,7 +260,7 @@ void luaV_comparison (lua_Type ttype_less, lua_Type ttype_equal, | |||
258 | result = luaV_strcomp(svalue(l), tsvalue(l)->u.s.len, | 260 | result = luaV_strcomp(svalue(l), tsvalue(l)->u.s.len, |
259 | svalue(r), tsvalue(r)->u.s.len); | 261 | svalue(r), tsvalue(r)->u.s.len); |
260 | else { | 262 | else { |
261 | call_binTM(op, "unexpected type in comparison"); | 263 | call_binTM(L, op, "unexpected type in comparison"); |
262 | return; | 264 | return; |
263 | } | 265 | } |
264 | S->top--; | 266 | S->top--; |
@@ -268,24 +270,24 @@ void luaV_comparison (lua_Type ttype_less, lua_Type ttype_equal, | |||
268 | } | 270 | } |
269 | 271 | ||
270 | 272 | ||
271 | void luaV_pack (StkId firstel, int nvararg, TObject *tab) { | 273 | void luaV_pack (lua_State *L, StkId firstel, int nvararg, TObject *tab) { |
272 | TObject *firstelem = L->stack.stack+firstel; | 274 | TObject *firstelem = L->stack.stack+firstel; |
273 | int i; | 275 | int i; |
274 | Hash *htab; | 276 | Hash *htab; |
275 | if (nvararg < 0) nvararg = 0; | 277 | if (nvararg < 0) nvararg = 0; |
276 | htab = avalue(tab) = luaH_new(nvararg+1); /* +1 for field 'n' */ | 278 | htab = avalue(tab) = luaH_new(L, nvararg+1); /* +1 for field 'n' */ |
277 | ttype(tab) = LUA_T_ARRAY; | 279 | ttype(tab) = LUA_T_ARRAY; |
278 | for (i=0; i<nvararg; i++) | 280 | for (i=0; i<nvararg; i++) |
279 | luaH_setint(htab, i+1, firstelem+i); | 281 | luaH_setint(L, htab, i+1, firstelem+i); |
280 | luaV_setn(htab, nvararg); /* store counter in field "n" */ | 282 | luaV_setn(L, htab, nvararg); /* store counter in field "n" */ |
281 | } | 283 | } |
282 | 284 | ||
283 | 285 | ||
284 | static void adjust_varargs (StkId first_extra_arg) { | 286 | static void adjust_varargs (lua_State *L, StkId first_extra_arg) { |
285 | TObject arg; | 287 | TObject arg; |
286 | luaV_pack(first_extra_arg, | 288 | luaV_pack(L, first_extra_arg, |
287 | (L->stack.top-L->stack.stack)-first_extra_arg, &arg); | 289 | (L->stack.top-L->stack.stack)-first_extra_arg, &arg); |
288 | luaD_adjusttop(first_extra_arg); | 290 | luaD_adjusttop(L, first_extra_arg); |
289 | *L->stack.top++ = arg; | 291 | *L->stack.top++ = arg; |
290 | } | 292 | } |
291 | 293 | ||
@@ -296,18 +298,18 @@ static void adjust_varargs (StkId first_extra_arg) { | |||
296 | ** [stack+base,top). Returns n such that the the results are between | 298 | ** [stack+base,top). Returns n such that the the results are between |
297 | ** [stack+n,top). | 299 | ** [stack+n,top). |
298 | */ | 300 | */ |
299 | StkId luaV_execute (const Closure *cl, const TProtoFunc *tf, StkId base) { | 301 | StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, StkId base) { |
300 | struct Stack *S = &L->stack; /* to optimize */ | 302 | struct Stack *S = &L->stack; /* to optimize */ |
301 | register const Byte *pc = tf->code; | 303 | register const Byte *pc = tf->code; |
302 | const TObject *consts = tf->consts; | 304 | const TObject *consts = tf->consts; |
303 | if (L->callhook) | 305 | if (L->callhook) |
304 | luaD_callHook(base, tf, 0); | 306 | luaD_callHook(L, base, tf, 0); |
305 | luaD_checkstack((*pc++)+EXTRA_STACK); | 307 | luaD_checkstack(L, (*pc++)+EXTRA_STACK); |
306 | if (*pc < ZEROVARARG) | 308 | if (*pc < ZEROVARARG) |
307 | luaD_adjusttop(base+*(pc++)); | 309 | luaD_adjusttop(L, base+*(pc++)); |
308 | else { /* varargs */ | 310 | else { /* varargs */ |
309 | luaC_checkGC(); | 311 | luaC_checkGC(L); |
310 | adjust_varargs(base+(*pc++)-ZEROVARARG); | 312 | adjust_varargs(L, base+(*pc++)-ZEROVARARG); |
311 | } | 313 | } |
312 | for (;;) { | 314 | for (;;) { |
313 | register int aux = 0; | 315 | register int aux = 0; |
@@ -323,11 +325,11 @@ StkId luaV_execute (const Closure *cl, const TProtoFunc *tf, StkId base) { | |||
323 | goto ret; | 325 | goto ret; |
324 | 326 | ||
325 | case CALL: aux = *pc++; | 327 | case CALL: aux = *pc++; |
326 | luaD_calln(*pc++, aux); | 328 | luaD_calln(L, *pc++, aux); |
327 | break; | 329 | break; |
328 | 330 | ||
329 | case TAILCALL: aux = *pc++; | 331 | case TAILCALL: aux = *pc++; |
330 | luaD_calln(*pc++, MULT_RET); | 332 | luaD_calln(L, *pc++, MULT_RET); |
331 | base += aux; | 333 | base += aux; |
332 | goto ret; | 334 | goto ret; |
333 | 335 | ||
@@ -341,21 +343,21 @@ StkId luaV_execute (const Closure *cl, const TProtoFunc *tf, StkId base) { | |||
341 | S->top -= aux; | 343 | S->top -= aux; |
342 | break; | 344 | break; |
343 | 345 | ||
344 | case PUSHNUMBERW: aux += highbyte(*pc++); | 346 | case PUSHNUMBERW: aux += highbyte(L, *pc++); |
345 | case PUSHNUMBER: aux += *pc++; | 347 | case PUSHNUMBER: aux += *pc++; |
346 | ttype(S->top) = LUA_T_NUMBER; | 348 | ttype(S->top) = LUA_T_NUMBER; |
347 | nvalue(S->top) = aux; | 349 | nvalue(S->top) = aux; |
348 | S->top++; | 350 | S->top++; |
349 | break; | 351 | break; |
350 | 352 | ||
351 | case PUSHNUMBERNEGW: aux += highbyte(*pc++); | 353 | case PUSHNUMBERNEGW: aux += highbyte(L, *pc++); |
352 | case PUSHNUMBERNEG: aux += *pc++; | 354 | case PUSHNUMBERNEG: aux += *pc++; |
353 | ttype(S->top) = LUA_T_NUMBER; | 355 | ttype(S->top) = LUA_T_NUMBER; |
354 | nvalue(S->top) = -aux; | 356 | nvalue(S->top) = -aux; |
355 | S->top++; | 357 | S->top++; |
356 | break; | 358 | break; |
357 | 359 | ||
358 | case PUSHCONSTANTW: aux += highbyte(*pc++); | 360 | case PUSHCONSTANTW: aux += highbyte(L, *pc++); |
359 | case PUSHCONSTANT: aux += *pc++; | 361 | case PUSHCONSTANT: aux += *pc++; |
360 | *S->top++ = consts[aux]; | 362 | *S->top++ = consts[aux]; |
361 | break; | 363 | break; |
@@ -368,35 +370,35 @@ StkId luaV_execute (const Closure *cl, const TProtoFunc *tf, StkId base) { | |||
368 | *S->top++ = *((S->stack+base) + aux); | 370 | *S->top++ = *((S->stack+base) + aux); |
369 | break; | 371 | break; |
370 | 372 | ||
371 | case GETGLOBALW: aux += highbyte(*pc++); | 373 | case GETGLOBALW: aux += highbyte(L, *pc++); |
372 | case GETGLOBAL: aux += *pc++; | 374 | case GETGLOBAL: aux += *pc++; |
373 | luaV_getglobal(tsvalue(&consts[aux])->u.s.gv); | 375 | luaV_getglobal(L, tsvalue(&consts[aux])->u.s.gv); |
374 | break; | 376 | break; |
375 | 377 | ||
376 | case GETTABLE: | 378 | case GETTABLE: |
377 | luaV_gettable(); | 379 | luaV_gettable(L); |
378 | break; | 380 | break; |
379 | 381 | ||
380 | case GETDOTTEDW: aux += highbyte(*pc++); | 382 | case GETDOTTEDW: aux += highbyte(L, *pc++); |
381 | case GETDOTTED: aux += *pc++; | 383 | case GETDOTTED: aux += *pc++; |
382 | *S->top++ = consts[aux]; | 384 | *S->top++ = consts[aux]; |
383 | luaV_gettable(); | 385 | luaV_gettable(L); |
384 | break; | 386 | break; |
385 | 387 | ||
386 | case PUSHSELFW: aux += highbyte(*pc++); | 388 | case PUSHSELFW: aux += highbyte(L, *pc++); |
387 | case PUSHSELF: aux += *pc++; { | 389 | case PUSHSELF: aux += *pc++; { |
388 | TObject receiver; | 390 | TObject receiver; |
389 | receiver = *(S->top-1); | 391 | receiver = *(S->top-1); |
390 | *S->top++ = consts[aux]; | 392 | *S->top++ = consts[aux]; |
391 | luaV_gettable(); | 393 | luaV_gettable(L); |
392 | *S->top++ = receiver; | 394 | *S->top++ = receiver; |
393 | break; | 395 | break; |
394 | } | 396 | } |
395 | 397 | ||
396 | case CREATEARRAYW: aux += highbyte(*pc++); | 398 | case CREATEARRAYW: aux += highbyte(L, *pc++); |
397 | case CREATEARRAY: aux += *pc++; | 399 | case CREATEARRAY: aux += *pc++; |
398 | luaC_checkGC(); | 400 | luaC_checkGC(L); |
399 | avalue(S->top) = luaH_new(aux); | 401 | avalue(S->top) = luaH_new(L, aux); |
400 | ttype(S->top) = LUA_T_ARRAY; | 402 | ttype(S->top) = LUA_T_ARRAY; |
401 | S->top++; | 403 | S->top++; |
402 | break; | 404 | break; |
@@ -405,34 +407,34 @@ StkId luaV_execute (const Closure *cl, const TProtoFunc *tf, StkId base) { | |||
405 | *((S->stack+base) + aux) = *(--S->top); | 407 | *((S->stack+base) + aux) = *(--S->top); |
406 | break; | 408 | break; |
407 | 409 | ||
408 | case SETGLOBALW: aux += highbyte(*pc++); | 410 | case SETGLOBALW: aux += highbyte(L, *pc++); |
409 | case SETGLOBAL: aux += *pc++; | 411 | case SETGLOBAL: aux += *pc++; |
410 | luaV_setglobal(tsvalue(&consts[aux])->u.s.gv); | 412 | luaV_setglobal(L, tsvalue(&consts[aux])->u.s.gv); |
411 | break; | 413 | break; |
412 | 414 | ||
413 | case SETTABLEPOP: | 415 | case SETTABLEPOP: |
414 | luaV_settable(S->top-3); | 416 | luaV_settable(L, S->top-3); |
415 | S->top -= 2; /* pop table and index */ | 417 | S->top -= 2; /* pop table and index */ |
416 | break; | 418 | break; |
417 | 419 | ||
418 | case SETTABLE: | 420 | case SETTABLE: |
419 | luaV_settable(S->top-3-(*pc++)); | 421 | luaV_settable(L, S->top-3-(*pc++)); |
420 | break; | 422 | break; |
421 | 423 | ||
422 | case SETLISTW: aux += highbyte(*pc++); | 424 | case SETLISTW: aux += highbyte(L, *pc++); |
423 | case SETLIST: aux += *pc++; { | 425 | case SETLIST: aux += *pc++; { |
424 | int n = *(pc++); | 426 | int n = *(pc++); |
425 | Hash *arr = avalue(S->top-n-1); | 427 | Hash *arr = avalue(S->top-n-1); |
426 | aux *= LFIELDS_PER_FLUSH; | 428 | aux *= LFIELDS_PER_FLUSH; |
427 | for (; n; n--) | 429 | for (; n; n--) |
428 | luaH_setint(arr, n+aux, --S->top); | 430 | luaH_setint(L, arr, n+aux, --S->top); |
429 | break; | 431 | break; |
430 | } | 432 | } |
431 | 433 | ||
432 | case SETMAP: aux = *pc++; { | 434 | case SETMAP: aux = *pc++; { |
433 | Hash *arr = avalue(S->top-(2*aux)-3); | 435 | Hash *arr = avalue(S->top-(2*aux)-3); |
434 | do { | 436 | do { |
435 | luaH_set(arr, S->top-2, S->top-1); | 437 | luaH_set(L, arr, S->top-2, S->top-1); |
436 | S->top-=2; | 438 | S->top-=2; |
437 | } while (aux--); | 439 | } while (aux--); |
438 | break; | 440 | break; |
@@ -449,26 +451,26 @@ StkId luaV_execute (const Closure *cl, const TProtoFunc *tf, StkId base) { | |||
449 | } | 451 | } |
450 | 452 | ||
451 | case LTOP: | 453 | case LTOP: |
452 | luaV_comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT); | 454 | luaV_comparison(L, LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT); |
453 | break; | 455 | break; |
454 | 456 | ||
455 | case LEOP: | 457 | case LEOP: |
456 | luaV_comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE); | 458 | luaV_comparison(L, LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE); |
457 | break; | 459 | break; |
458 | 460 | ||
459 | case GTOP: | 461 | case GTOP: |
460 | luaV_comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT); | 462 | luaV_comparison(L, LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT); |
461 | break; | 463 | break; |
462 | 464 | ||
463 | case GEOP: | 465 | case GEOP: |
464 | luaV_comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE); | 466 | luaV_comparison(L, LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE); |
465 | break; | 467 | break; |
466 | 468 | ||
467 | case ADDOP: { | 469 | case ADDOP: { |
468 | TObject *l = S->top-2; | 470 | TObject *l = S->top-2; |
469 | TObject *r = S->top-1; | 471 | TObject *r = S->top-1; |
470 | if (tonumber(r) || tonumber(l)) | 472 | if (tonumber(r) || tonumber(l)) |
471 | call_arith(IM_ADD); | 473 | call_arith(L, IM_ADD); |
472 | else { | 474 | else { |
473 | nvalue(l) += nvalue(r); | 475 | nvalue(l) += nvalue(r); |
474 | --S->top; | 476 | --S->top; |
@@ -480,7 +482,7 @@ StkId luaV_execute (const Closure *cl, const TProtoFunc *tf, StkId base) { | |||
480 | TObject *l = S->top-2; | 482 | TObject *l = S->top-2; |
481 | TObject *r = S->top-1; | 483 | TObject *r = S->top-1; |
482 | if (tonumber(r) || tonumber(l)) | 484 | if (tonumber(r) || tonumber(l)) |
483 | call_arith(IM_SUB); | 485 | call_arith(L, IM_SUB); |
484 | else { | 486 | else { |
485 | nvalue(l) -= nvalue(r); | 487 | nvalue(l) -= nvalue(r); |
486 | --S->top; | 488 | --S->top; |
@@ -492,7 +494,7 @@ StkId luaV_execute (const Closure *cl, const TProtoFunc *tf, StkId base) { | |||
492 | TObject *l = S->top-2; | 494 | TObject *l = S->top-2; |
493 | TObject *r = S->top-1; | 495 | TObject *r = S->top-1; |
494 | if (tonumber(r) || tonumber(l)) | 496 | if (tonumber(r) || tonumber(l)) |
495 | call_arith(IM_MUL); | 497 | call_arith(L, IM_MUL); |
496 | else { | 498 | else { |
497 | nvalue(l) *= nvalue(r); | 499 | nvalue(l) *= nvalue(r); |
498 | --S->top; | 500 | --S->top; |
@@ -504,7 +506,7 @@ StkId luaV_execute (const Closure *cl, const TProtoFunc *tf, StkId base) { | |||
504 | TObject *l = S->top-2; | 506 | TObject *l = S->top-2; |
505 | TObject *r = S->top-1; | 507 | TObject *r = S->top-1; |
506 | if (tonumber(r) || tonumber(l)) | 508 | if (tonumber(r) || tonumber(l)) |
507 | call_arith(IM_DIV); | 509 | call_arith(L, IM_DIV); |
508 | else { | 510 | else { |
509 | nvalue(l) /= nvalue(r); | 511 | nvalue(l) /= nvalue(r); |
510 | --S->top; | 512 | --S->top; |
@@ -513,19 +515,19 @@ StkId luaV_execute (const Closure *cl, const TProtoFunc *tf, StkId base) { | |||
513 | } | 515 | } |
514 | 516 | ||
515 | case POWOP: | 517 | case POWOP: |
516 | call_binTM(IM_POW, "undefined operation"); | 518 | call_binTM(L, IM_POW, "undefined operation"); |
517 | break; | 519 | break; |
518 | 520 | ||
519 | case CONCOP: { | 521 | case CONCOP: { |
520 | TObject *l = S->top-2; | 522 | TObject *l = S->top-2; |
521 | TObject *r = S->top-1; | 523 | TObject *r = S->top-1; |
522 | if (tostring(l) || tostring(r)) | 524 | if (tostring(L, l) || tostring(L, r)) |
523 | call_binTM(IM_CONCAT, "unexpected type for concatenation"); | 525 | call_binTM(L, IM_CONCAT, "unexpected type for concatenation"); |
524 | else { | 526 | else { |
525 | tsvalue(l) = strconc(tsvalue(l), tsvalue(r)); | 527 | tsvalue(l) = strconc(L, tsvalue(l), tsvalue(r)); |
526 | --S->top; | 528 | --S->top; |
527 | } | 529 | } |
528 | luaC_checkGC(); | 530 | luaC_checkGC(L); |
529 | break; | 531 | break; |
530 | } | 532 | } |
531 | 533 | ||
@@ -533,7 +535,7 @@ StkId luaV_execute (const Closure *cl, const TProtoFunc *tf, StkId base) { | |||
533 | if (tonumber(S->top-1)) { | 535 | if (tonumber(S->top-1)) { |
534 | ttype(S->top) = LUA_T_NIL; | 536 | ttype(S->top) = LUA_T_NIL; |
535 | S->top++; | 537 | S->top++; |
536 | call_arith(IM_UNM); | 538 | call_arith(L, IM_UNM); |
537 | } | 539 | } |
538 | else | 540 | else |
539 | nvalue(S->top-1) = - nvalue(S->top-1); | 541 | nvalue(S->top-1) = - nvalue(S->top-1); |
@@ -545,72 +547,72 @@ StkId luaV_execute (const Closure *cl, const TProtoFunc *tf, StkId base) { | |||
545 | nvalue(S->top-1) = 1; | 547 | nvalue(S->top-1) = 1; |
546 | break; | 548 | break; |
547 | 549 | ||
548 | case ONTJMPW: aux += highbyte(*pc++); | 550 | case ONTJMPW: aux += highbyte(L, *pc++); |
549 | case ONTJMP: aux += *pc++; | 551 | case ONTJMP: aux += *pc++; |
550 | if (ttype(S->top-1) != LUA_T_NIL) pc += aux; | 552 | if (ttype(S->top-1) != LUA_T_NIL) pc += aux; |
551 | else S->top--; | 553 | else S->top--; |
552 | break; | 554 | break; |
553 | 555 | ||
554 | case ONFJMPW: aux += highbyte(*pc++); | 556 | case ONFJMPW: aux += highbyte(L, *pc++); |
555 | case ONFJMP: aux += *pc++; | 557 | case ONFJMP: aux += *pc++; |
556 | if (ttype(S->top-1) == LUA_T_NIL) pc += aux; | 558 | if (ttype(S->top-1) == LUA_T_NIL) pc += aux; |
557 | else S->top--; | 559 | else S->top--; |
558 | break; | 560 | break; |
559 | 561 | ||
560 | case JMPW: aux += highbyte(*pc++); | 562 | case JMPW: aux += highbyte(L, *pc++); |
561 | case JMP: aux += *pc++; | 563 | case JMP: aux += *pc++; |
562 | pc += aux; | 564 | pc += aux; |
563 | break; | 565 | break; |
564 | 566 | ||
565 | case IFFJMPW: aux += highbyte(*pc++); | 567 | case IFFJMPW: aux += highbyte(L, *pc++); |
566 | case IFFJMP: aux += *pc++; | 568 | case IFFJMP: aux += *pc++; |
567 | if (ttype(--S->top) == LUA_T_NIL) pc += aux; | 569 | if (ttype(--S->top) == LUA_T_NIL) pc += aux; |
568 | break; | 570 | break; |
569 | 571 | ||
570 | case IFTUPJMPW: aux += highbyte(*pc++); | 572 | case IFTUPJMPW: aux += highbyte(L, *pc++); |
571 | case IFTUPJMP: aux += *pc++; | 573 | case IFTUPJMP: aux += *pc++; |
572 | if (ttype(--S->top) != LUA_T_NIL) pc -= aux; | 574 | if (ttype(--S->top) != LUA_T_NIL) pc -= aux; |
573 | break; | 575 | break; |
574 | 576 | ||
575 | case IFFUPJMPW: aux += highbyte(*pc++); | 577 | case IFFUPJMPW: aux += highbyte(L, *pc++); |
576 | case IFFUPJMP: aux += *pc++; | 578 | case IFFUPJMP: aux += *pc++; |
577 | if (ttype(--S->top) == LUA_T_NIL) pc -= aux; | 579 | if (ttype(--S->top) == LUA_T_NIL) pc -= aux; |
578 | break; | 580 | break; |
579 | 581 | ||
580 | case CLOSUREW: aux += highbyte(*pc++); | 582 | case CLOSUREW: aux += highbyte(L, *pc++); |
581 | case CLOSURE: aux += *pc++; | 583 | case CLOSURE: aux += *pc++; |
582 | *S->top++ = consts[aux]; | 584 | *S->top++ = consts[aux]; |
583 | luaV_closure(*pc++); | 585 | luaV_closure(L, *pc++); |
584 | luaC_checkGC(); | 586 | luaC_checkGC(L); |
585 | break; | 587 | break; |
586 | 588 | ||
587 | case SETLINEW: aux += highbyte(*pc++); | 589 | case SETLINEW: aux += highbyte(L, *pc++); |
588 | case SETLINE: aux += *pc++; | 590 | case SETLINE: aux += *pc++; |
589 | if ((S->stack+base-1)->ttype != LUA_T_LINE) { | 591 | if ((S->stack+base-1)->ttype != LUA_T_LINE) { |
590 | /* open space for LINE value */ | 592 | /* open space for LINE value */ |
591 | luaD_openstack((S->top-S->stack)-base); | 593 | luaD_openstack(L, (S->top-S->stack)-base); |
592 | base++; | 594 | base++; |
593 | (S->stack+base-1)->ttype = LUA_T_LINE; | 595 | (S->stack+base-1)->ttype = LUA_T_LINE; |
594 | } | 596 | } |
595 | (S->stack+base-1)->value.i = aux; | 597 | (S->stack+base-1)->value.i = aux; |
596 | if (L->linehook) | 598 | if (L->linehook) |
597 | luaD_lineHook(aux); | 599 | luaD_lineHook(L, aux); |
598 | break; | 600 | break; |
599 | 601 | ||
600 | case LONGARGW: aux += highbyte(*pc++); | 602 | case LONGARGW: aux += highbyte(L, *pc++); |
601 | case LONGARG: aux += *pc++; | 603 | case LONGARG: aux += *pc++; |
602 | aux = highbyte(highbyte(aux)); | 604 | aux = highbyte(L, highbyte(L, aux)); |
603 | goto switchentry; /* do not reset "aux" */ | 605 | goto switchentry; /* do not reset "aux" */ |
604 | 606 | ||
605 | case CHECKSTACK: aux = *pc++; | 607 | case CHECKSTACK: aux = *pc++; |
606 | LUA_ASSERT((S->top-S->stack)-base == aux && S->last >= S->top, | 608 | LUA_ASSERT(L, (S->top-S->stack)-base == aux && S->last >= S->top, |
607 | "wrong stack size"); | 609 | "wrong stack size"); |
608 | break; | 610 | break; |
609 | 611 | ||
610 | } | 612 | } |
611 | } ret: | 613 | } ret: |
612 | if (L->callhook) | 614 | if (L->callhook) |
613 | luaD_callHook(0, NULL, 1); | 615 | luaD_callHook(L, 0, NULL, 1); |
614 | return base; | 616 | return base; |
615 | } | 617 | } |
616 | 618 | ||