diff options
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 39 |
1 files changed, 18 insertions, 21 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.58 1999/06/22 20:37:23 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.59 1999/08/10 12:55:47 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 | */ |
@@ -114,7 +114,7 @@ void luaV_closure (int nelems) { | |||
114 | */ | 114 | */ |
115 | void luaV_gettable (void) { | 115 | void luaV_gettable (void) { |
116 | TObject *table = L->stack.top-2; | 116 | TObject *table = L->stack.top-2; |
117 | TObject *im; | 117 | const TObject *im; |
118 | if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */ | 118 | if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */ |
119 | im = luaT_getimbyObj(table, IM_GETTABLE); | 119 | im = luaT_getimbyObj(table, IM_GETTABLE); |
120 | if (ttype(im) == LUA_T_NIL) | 120 | if (ttype(im) == LUA_T_NIL) |
@@ -146,9 +146,9 @@ void luaV_gettable (void) { | |||
146 | /* | 146 | /* |
147 | ** Receives table at *t, index at *(t+1) and value at top. | 147 | ** Receives table at *t, index at *(t+1) and value at top. |
148 | */ | 148 | */ |
149 | void luaV_settable (TObject *t) { | 149 | void luaV_settable (const TObject *t) { |
150 | struct Stack *S = &L->stack; | 150 | struct Stack *S = &L->stack; |
151 | TObject *im; | 151 | const TObject *im; |
152 | if (ttype(t) != LUA_T_ARRAY) { /* not a table, get "settable" method */ | 152 | if (ttype(t) != LUA_T_ARRAY) { /* not a table, get "settable" method */ |
153 | im = luaT_getimbyObj(t, IM_SETTABLE); | 153 | im = luaT_getimbyObj(t, IM_SETTABLE); |
154 | if (ttype(im) == LUA_T_NIL) | 154 | if (ttype(im) == LUA_T_NIL) |
@@ -173,7 +173,7 @@ void luaV_settable (TObject *t) { | |||
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
176 | void luaV_rawsettable (TObject *t) { | 176 | void luaV_rawsettable (const TObject *t) { |
177 | if (ttype(t) != LUA_T_ARRAY) | 177 | if (ttype(t) != LUA_T_ARRAY) |
178 | lua_error("indexed expression not a table"); | 178 | lua_error("indexed expression not a table"); |
179 | else { | 179 | else { |
@@ -186,7 +186,7 @@ void luaV_rawsettable (TObject *t) { | |||
186 | 186 | ||
187 | void luaV_getglobal (TaggedString *ts) { | 187 | void luaV_getglobal (TaggedString *ts) { |
188 | /* WARNING: caller must assure stack space */ | 188 | /* WARNING: caller must assure stack space */ |
189 | TObject *value = &ts->u.s.globalval; | 189 | const TObject *value = &ts->u.s.globalval; |
190 | switch (ttype(value)) { | 190 | switch (ttype(value)) { |
191 | /* only userdata, tables and nil can have getglobal tag methods */ | 191 | /* only userdata, tables and nil can have getglobal tag methods */ |
192 | case LUA_T_USERDATA: case LUA_T_ARRAY: case LUA_T_NIL: { | 192 | case LUA_T_USERDATA: case LUA_T_ARRAY: case LUA_T_NIL: { |
@@ -208,8 +208,8 @@ void luaV_getglobal (TaggedString *ts) { | |||
208 | 208 | ||
209 | 209 | ||
210 | void luaV_setglobal (TaggedString *ts) { | 210 | void luaV_setglobal (TaggedString *ts) { |
211 | TObject *oldvalue = &ts->u.s.globalval; | 211 | const TObject *oldvalue = &ts->u.s.globalval; |
212 | TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL); | 212 | const TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL); |
213 | if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ | 213 | if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ |
214 | luaS_rawsetglobal(ts, --L->stack.top); | 214 | luaS_rawsetglobal(ts, --L->stack.top); |
215 | else { | 215 | else { |
@@ -226,9 +226,9 @@ void luaV_setglobal (TaggedString *ts) { | |||
226 | } | 226 | } |
227 | 227 | ||
228 | 228 | ||
229 | static void call_binTM (IMS event, char *msg) | 229 | static void call_binTM (IMS event, const char *msg) { |
230 | { | 230 | /* try first operand */ |
231 | TObject *im = luaT_getimbyObj(L->stack.top-2, event);/* try first operand */ | 231 | const TObject *im = luaT_getimbyObj(L->stack.top-2, event); |
232 | if (ttype(im) == LUA_T_NIL) { | 232 | if (ttype(im) == LUA_T_NIL) { |
233 | im = luaT_getimbyObj(L->stack.top-1, event); /* try second operand */ | 233 | im = luaT_getimbyObj(L->stack.top-1, event); /* try second operand */ |
234 | if (ttype(im) == LUA_T_NIL) { | 234 | if (ttype(im) == LUA_T_NIL) { |
@@ -242,14 +242,12 @@ static void call_binTM (IMS event, char *msg) | |||
242 | } | 242 | } |
243 | 243 | ||
244 | 244 | ||
245 | static void call_arith (IMS event) | 245 | static void call_arith (IMS event) { |
246 | { | ||
247 | call_binTM(event, "unexpected type in arithmetic operation"); | 246 | call_binTM(event, "unexpected type in arithmetic operation"); |
248 | } | 247 | } |
249 | 248 | ||
250 | 249 | ||
251 | static int luaV_strcomp (char *l, long ll, char *r, long lr) | 250 | static int luaV_strcomp (const char *l, long ll, const char *r, long lr) { |
252 | { | ||
253 | for (;;) { | 251 | for (;;) { |
254 | long temp = strcoll(l, r); | 252 | long temp = strcoll(l, r); |
255 | if (temp != 0) return temp; | 253 | if (temp != 0) return temp; |
@@ -268,8 +266,8 @@ static int luaV_strcomp (char *l, long ll, char *r, long lr) | |||
268 | void luaV_comparison (lua_Type ttype_less, lua_Type ttype_equal, | 266 | void luaV_comparison (lua_Type ttype_less, lua_Type ttype_equal, |
269 | lua_Type ttype_great, IMS op) { | 267 | lua_Type ttype_great, IMS op) { |
270 | struct Stack *S = &L->stack; | 268 | struct Stack *S = &L->stack; |
271 | TObject *l = S->top-2; | 269 | const TObject *l = S->top-2; |
272 | TObject *r = S->top-1; | 270 | const TObject *r = S->top-1; |
273 | real result; | 271 | real result; |
274 | if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) | 272 | if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) |
275 | result = nvalue(l)-nvalue(r); | 273 | result = nvalue(l)-nvalue(r); |
@@ -300,8 +298,7 @@ void luaV_pack (StkId firstel, int nvararg, TObject *tab) { | |||
300 | } | 298 | } |
301 | 299 | ||
302 | 300 | ||
303 | static void adjust_varargs (StkId first_extra_arg) | 301 | static void adjust_varargs (StkId first_extra_arg) { |
304 | { | ||
305 | TObject arg; | 302 | TObject arg; |
306 | luaV_pack(first_extra_arg, | 303 | luaV_pack(first_extra_arg, |
307 | (L->stack.top-L->stack.stack)-first_extra_arg, &arg); | 304 | (L->stack.top-L->stack.stack)-first_extra_arg, &arg); |
@@ -318,8 +315,8 @@ static void adjust_varargs (StkId first_extra_arg) | |||
318 | */ | 315 | */ |
319 | StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { | 316 | StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { |
320 | struct Stack *S = &L->stack; /* to optimize */ | 317 | struct Stack *S = &L->stack; /* to optimize */ |
321 | register Byte *pc = tf->code; | 318 | register const Byte *pc = tf->code; |
322 | TObject *consts = tf->consts; | 319 | const TObject *consts = tf->consts; |
323 | if (L->callhook) | 320 | if (L->callhook) |
324 | luaD_callHook(base, tf, 0); | 321 | luaD_callHook(base, tf, 0); |
325 | luaD_checkstack((*pc++)+EXTRA_STACK); | 322 | luaD_checkstack((*pc++)+EXTRA_STACK); |