aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c54
-rw-r--r--lapi.h4
-rw-r--r--lbuiltin.c64
-rw-r--r--lcode.c172
-rw-r--r--lcode.h4
-rw-r--r--ldebug.c38
-rw-r--r--ldo.c28
-rw-r--r--lfunc.c12
-rw-r--r--lfunc.h8
-rw-r--r--lgc.c30
-rw-r--r--llex.c42
-rw-r--r--llex.h17
-rw-r--r--lmathlib.c4
-rw-r--r--lmem.c4
-rw-r--r--lobject.c20
-rw-r--r--lobject.h88
-rw-r--r--lopcodes.h98
-rw-r--r--lparser.c158
-rw-r--r--lparser.h8
-rw-r--r--lref.c12
-rw-r--r--lstate.h6
-rw-r--r--lstring.c52
-rw-r--r--lstring.h14
-rw-r--r--ltable.c30
-rw-r--r--ltests.c6
-rw-r--r--ltm.c40
-rw-r--r--lundump.c36
-rw-r--r--lundump.h6
-rw-r--r--lvm.c206
-rw-r--r--lvm.h8
30 files changed, 635 insertions, 634 deletions
diff --git a/lapi.c b/lapi.c
index d915696b..1391511f 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.72 2000/02/22 17:54:16 roberto Exp roberto $ 2** $Id: lapi.c,v 1.73 2000/03/03 14:58:26 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -33,7 +33,7 @@ const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
33 33
34const TObject *luaA_protovalue (const TObject *o) { 34const TObject *luaA_protovalue (const TObject *o) {
35 switch (ttype(o)) { 35 switch (ttype(o)) {
36 case LUA_T_CCLOSURE: case LUA_T_LCLOSURE: 36 case TAG_CCLOSURE: case TAG_LCLOSURE:
37 return protovalue(o); 37 return protovalue(o);
38 default: 38 default:
39 return o; 39 return o;
@@ -106,7 +106,7 @@ lua_Object lua_settagmethod (lua_State *L, int tag, const char *event) {
106 TObject *method; 106 TObject *method;
107 luaA_checkCargs(L, 1); 107 luaA_checkCargs(L, 1);
108 method = L->top-1; 108 method = L->top-1;
109 if ((ttype(method) != LUA_T_NIL) && (*lua_type(L, method) != 'f')) 109 if ((ttype(method) != TAG_NIL) && (*lua_type(L, method) != 'f'))
110 lua_error(L, "Lua API error - tag method must be a function or nil"); 110 lua_error(L, "Lua API error - tag method must be a function or nil");
111 luaT_settagmethod(L, tag, event, method); 111 luaT_settagmethod(L, tag, event, method);
112 return luaA_putObjectOnTop(L); 112 return luaA_putObjectOnTop(L);
@@ -132,7 +132,7 @@ lua_Object lua_gettable (lua_State *L) {
132lua_Object lua_rawgettable (lua_State *L) { 132lua_Object lua_rawgettable (lua_State *L) {
133 lua_Object res; 133 lua_Object res;
134 luaA_checkCargs(L, 2); 134 luaA_checkCargs(L, 2);
135 if (ttype(L->top-2) != LUA_T_ARRAY) 135 if (ttype(L->top-2) != TAG_ARRAY)
136 lua_error(L, "indexed expression not a table in rawgettable"); 136 lua_error(L, "indexed expression not a table in rawgettable");
137 res = luaA_putluaObject(L, luaH_get(L, avalue(L->top-2), L->top-1)); 137 res = luaA_putluaObject(L, luaH_get(L, avalue(L->top-2), L->top-1));
138 L->top -= 2; 138 L->top -= 2;
@@ -159,7 +159,7 @@ lua_Object lua_createtable (lua_State *L) {
159 TObject o; 159 TObject o;
160 luaC_checkGC(L); 160 luaC_checkGC(L);
161 avalue(&o) = luaH_new(L, 0); 161 avalue(&o) = luaH_new(L, 0);
162 ttype(&o) = LUA_T_ARRAY; 162 ttype(&o) = TAG_ARRAY;
163 return luaA_putluaObject(L, &o); 163 return luaA_putluaObject(L, &o);
164} 164}
165 165
@@ -196,21 +196,21 @@ const char *lua_type (lua_State *L, lua_Object o) {
196 196
197int lua_isnil (lua_State *L, lua_Object o) { 197int lua_isnil (lua_State *L, lua_Object o) {
198 UNUSED(L); 198 UNUSED(L);
199 return (o != LUA_NOOBJECT) && (ttype(o) == LUA_T_NIL); 199 return (o != LUA_NOOBJECT) && (ttype(o) == TAG_NIL);
200} 200}
201 201
202int lua_istable (lua_State *L, lua_Object o) { 202int lua_istable (lua_State *L, lua_Object o) {
203 UNUSED(L); 203 UNUSED(L);
204 return (o != LUA_NOOBJECT) && (ttype(o) == LUA_T_ARRAY); 204 return (o != LUA_NOOBJECT) && (ttype(o) == TAG_ARRAY);
205} 205}
206 206
207int lua_isuserdata (lua_State *L, lua_Object o) { 207int lua_isuserdata (lua_State *L, lua_Object o) {
208 UNUSED(L); 208 UNUSED(L);
209 return (o != LUA_NOOBJECT) && (ttype(o) == LUA_T_USERDATA); 209 return (o != LUA_NOOBJECT) && (ttype(o) == TAG_USERDATA);
210} 210}
211 211
212int lua_iscfunction (lua_State *L, lua_Object o) { 212int lua_iscfunction (lua_State *L, lua_Object o) {
213 return (lua_tag(L, o) == LUA_T_CPROTO); 213 return (lua_tag(L, o) == TAG_CPROTO);
214} 214}
215 215
216int lua_isnumber (lua_State *L, lua_Object o) { 216int lua_isnumber (lua_State *L, lua_Object o) {
@@ -220,8 +220,8 @@ int lua_isnumber (lua_State *L, lua_Object o) {
220 220
221int lua_isstring (lua_State *L, lua_Object o) { 221int lua_isstring (lua_State *L, lua_Object o) {
222 UNUSED(L); 222 UNUSED(L);
223 return (o != LUA_NOOBJECT && (ttype(o) == LUA_T_STRING || 223 return (o != LUA_NOOBJECT && (ttype(o) == TAG_STRING ||
224 ttype(o) == LUA_T_NUMBER)); 224 ttype(o) == TAG_NUMBER));
225} 225}
226 226
227int lua_isfunction (lua_State *L, lua_Object o) { 227int lua_isfunction (lua_State *L, lua_Object o) {
@@ -258,7 +258,7 @@ long lua_strlen (lua_State *L, lua_Object obj) {
258 258
259void *lua_getuserdata (lua_State *L, lua_Object obj) { 259void *lua_getuserdata (lua_State *L, lua_Object obj) {
260 UNUSED(L); 260 UNUSED(L);
261 if (obj == LUA_NOOBJECT || ttype(obj) != LUA_T_USERDATA) 261 if (obj == LUA_NOOBJECT || ttype(obj) != TAG_USERDATA)
262 return NULL; 262 return NULL;
263 else return tsvalue(obj)->u.d.value; 263 else return tsvalue(obj)->u.d.value;
264} 264}
@@ -271,19 +271,19 @@ lua_CFunction lua_getcfunction (lua_State *L, lua_Object obj) {
271 271
272 272
273void lua_pushnil (lua_State *L) { 273void lua_pushnil (lua_State *L) {
274 ttype(L->top) = LUA_T_NIL; 274 ttype(L->top) = TAG_NIL;
275 incr_top; 275 incr_top;
276} 276}
277 277
278void lua_pushnumber (lua_State *L, double n) { 278void lua_pushnumber (lua_State *L, double n) {
279 ttype(L->top) = LUA_T_NUMBER; 279 ttype(L->top) = TAG_NUMBER;
280 nvalue(L->top) = n; 280 nvalue(L->top) = n;
281 incr_top; 281 incr_top;
282} 282}
283 283
284void lua_pushlstring (lua_State *L, const char *s, long len) { 284void lua_pushlstring (lua_State *L, const char *s, long len) {
285 tsvalue(L->top) = luaS_newlstr(L, s, len); 285 tsvalue(L->top) = luaS_newlstr(L, s, len);
286 ttype(L->top) = LUA_T_STRING; 286 ttype(L->top) = TAG_STRING;
287 incr_top; 287 incr_top;
288 luaC_checkGC(L); 288 luaC_checkGC(L);
289} 289}
@@ -299,7 +299,7 @@ void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
299 if (fn == NULL) 299 if (fn == NULL)
300 lua_error(L, "Lua API error - attempt to push a NULL Cfunction"); 300 lua_error(L, "Lua API error - attempt to push a NULL Cfunction");
301 luaA_checkCargs(L, n); 301 luaA_checkCargs(L, n);
302 ttype(L->top) = LUA_T_CPROTO; 302 ttype(L->top) = TAG_CPROTO;
303 fvalue(L->top) = fn; 303 fvalue(L->top) = fn;
304 incr_top; 304 incr_top;
305 luaV_closure(L, n); 305 luaV_closure(L, n);
@@ -310,7 +310,7 @@ void lua_pushusertag (lua_State *L, void *u, int tag) {
310 if (tag < 0 && tag != LUA_ANYTAG) 310 if (tag < 0 && tag != LUA_ANYTAG)
311 luaT_realtag(L, tag); /* error if tag is not valid */ 311 luaT_realtag(L, tag); /* error if tag is not valid */
312 tsvalue(L->top) = luaS_createudata(L, u, tag); 312 tsvalue(L->top) = luaS_createudata(L, u, tag);
313 ttype(L->top) = LUA_T_USERDATA; 313 ttype(L->top) = TAG_USERDATA;
314 incr_top; 314 incr_top;
315 luaC_checkGC(L); 315 luaC_checkGC(L);
316} 316}
@@ -331,8 +331,8 @@ void lua_pushobject (lua_State *L, lua_Object o) {
331int lua_tag (lua_State *L, lua_Object o) { 331int lua_tag (lua_State *L, lua_Object o) {
332 UNUSED(L); 332 UNUSED(L);
333 if (o == LUA_NOOBJECT) 333 if (o == LUA_NOOBJECT)
334 return LUA_T_NIL; 334 return TAG_NIL;
335 else if (ttype(o) == LUA_T_USERDATA) /* to allow `old' tags (deprecated) */ 335 else if (ttype(o) == TAG_USERDATA) /* to allow `old' tags (deprecated) */
336 return o->value.ts->u.d.tag; 336 return o->value.ts->u.d.tag;
337 else 337 else
338 return luaT_effectivetag(o); 338 return luaT_effectivetag(o);
@@ -343,10 +343,10 @@ void lua_settag (lua_State *L, int tag) {
343 luaA_checkCargs(L, 1); 343 luaA_checkCargs(L, 1);
344 luaT_realtag(L, tag); 344 luaT_realtag(L, tag);
345 switch (ttype(L->top-1)) { 345 switch (ttype(L->top-1)) {
346 case LUA_T_ARRAY: 346 case TAG_ARRAY:
347 (L->top-1)->value.a->htag = tag; 347 (L->top-1)->value.a->htag = tag;
348 break; 348 break;
349 case LUA_T_USERDATA: 349 case TAG_USERDATA:
350 (L->top-1)->value.ts->u.d.tag = tag; 350 (L->top-1)->value.ts->u.d.tag = tag;
351 break; 351 break;
352 default: 352 default:
@@ -357,7 +357,7 @@ void lua_settag (lua_State *L, int tag) {
357} 357}
358 358
359 359
360GlobalVar *luaA_nextvar (lua_State *L, TaggedString *ts) { 360GlobalVar *luaA_nextvar (lua_State *L, TString *ts) {
361 GlobalVar *gv; 361 GlobalVar *gv;
362 if (ts == NULL) 362 if (ts == NULL)
363 gv = L->rootglobal; /* first variable */ 363 gv = L->rootglobal; /* first variable */
@@ -366,10 +366,10 @@ GlobalVar *luaA_nextvar (lua_State *L, TaggedString *ts) {
366 luaL_arg_check(L, ts->u.s.gv, 1, "variable name expected"); 366 luaL_arg_check(L, ts->u.s.gv, 1, "variable name expected");
367 gv = ts->u.s.gv->next; /* get next */ 367 gv = ts->u.s.gv->next; /* get next */
368 } 368 }
369 while (gv && gv->value.ttype == LUA_T_NIL) /* skip globals with nil */ 369 while (gv && gv->value.ttype == TAG_NIL) /* skip globals with nil */
370 gv = gv->next; 370 gv = gv->next;
371 if (gv) { 371 if (gv) {
372 ttype(L->top) = LUA_T_STRING; tsvalue(L->top) = gv->name; 372 ttype(L->top) = TAG_STRING; tsvalue(L->top) = gv->name;
373 incr_top; 373 incr_top;
374 luaA_pushobject(L, &gv->value); 374 luaA_pushobject(L, &gv->value);
375 } 375 }
@@ -378,7 +378,7 @@ GlobalVar *luaA_nextvar (lua_State *L, TaggedString *ts) {
378 378
379 379
380const char *lua_nextvar (lua_State *L, const char *varname) { 380const char *lua_nextvar (lua_State *L, const char *varname) {
381 TaggedString *ts = (varname == NULL) ? NULL : luaS_new(L, varname); 381 TString *ts = (varname == NULL) ? NULL : luaS_new(L, varname);
382 GlobalVar *gv = luaA_nextvar(L, ts); 382 GlobalVar *gv = luaA_nextvar(L, ts);
383 if (gv) { 383 if (gv) {
384 top2LC(L, 2); 384 top2LC(L, 2);
@@ -395,7 +395,7 @@ int luaA_next (lua_State *L, const Hash *t, int i) {
395 int tsize = t->size; 395 int tsize = t->size;
396 for (; i<tsize; i++) { 396 for (; i<tsize; i++) {
397 Node *n = node(t, i); 397 Node *n = node(t, i);
398 if (ttype(val(n)) != LUA_T_NIL) { 398 if (ttype(val(n)) != TAG_NIL) {
399 luaA_pushobject(L, key(n)); 399 luaA_pushobject(L, key(n));
400 luaA_pushobject(L, val(n)); 400 luaA_pushobject(L, val(n));
401 return i+1; /* index to be used next time */ 401 return i+1; /* index to be used next time */
@@ -406,7 +406,7 @@ int luaA_next (lua_State *L, const Hash *t, int i) {
406 406
407 407
408int lua_next (lua_State *L, lua_Object t, int i) { 408int lua_next (lua_State *L, lua_Object t, int i) {
409 if (ttype(t) != LUA_T_ARRAY) 409 if (ttype(t) != TAG_ARRAY)
410 lua_error(L, "Lua API error - object is not a table in `lua_next'"); 410 lua_error(L, "Lua API error - object is not a table in `lua_next'");
411 i = luaA_next(L, avalue(t), i); 411 i = luaA_next(L, avalue(t), i);
412 top2LC(L, (i==0) ? 0 : 2); 412 top2LC(L, (i==0) ? 0 : 2);
diff --git a/lapi.h b/lapi.h
index 5fb3e90d..835009d7 100644
--- a/lapi.h
+++ b/lapi.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.h,v 1.13 2000/01/19 12:00:45 roberto Exp roberto $ 2** $Id: lapi.h,v 1.14 2000/03/03 14:58:26 roberto Exp roberto $
3** Auxiliary functions from Lua API 3** Auxiliary functions from Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -14,7 +14,7 @@
14void luaA_checkCargs (lua_State *L, int nargs); 14void luaA_checkCargs (lua_State *L, int nargs);
15const TObject *luaA_protovalue (const TObject *o); 15const TObject *luaA_protovalue (const TObject *o);
16void luaA_pushobject (lua_State *L, const TObject *o); 16void luaA_pushobject (lua_State *L, const TObject *o);
17GlobalVar *luaA_nextvar (lua_State *L, TaggedString *g); 17GlobalVar *luaA_nextvar (lua_State *L, TString *g);
18int luaA_next (lua_State *L, const Hash *t, int i); 18int luaA_next (lua_State *L, const Hash *t, int i);
19lua_Object luaA_putluaObject (lua_State *L, const TObject *o); 19lua_Object luaA_putluaObject (lua_State *L, const TObject *o);
20lua_Object luaA_putObjectOnTop (lua_State *L); 20lua_Object luaA_putObjectOnTop (lua_State *L);
diff --git a/lbuiltin.c b/lbuiltin.c
index 3c558886..41787bcc 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuiltin.c,v 1.94 2000/03/03 14:58:26 roberto Exp $ 2** $Id: lbuiltin.c,v 1.95 2000/03/09 00:19:22 roberto Exp roberto $
3** Built-in functions 3** Built-in functions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -52,20 +52,20 @@ void luaB_opentests (lua_State *L);
52*/ 52*/
53 53
54 54
55static void pushtagstring (lua_State *L, TaggedString *s) { 55static void pushtagstring (lua_State *L, TString *s) {
56 ttype(L->top) = LUA_T_STRING; 56 ttype(L->top) = TAG_STRING;
57 tsvalue(L->top) = s; 57 tsvalue(L->top) = s;
58 incr_top; 58 incr_top;
59} 59}
60 60
61 61
62static real getsize (const Hash *h) { 62static Number getsize (const Hash *h) {
63 real max = 0; 63 Number max = 0;
64 int i = h->size; 64 int i = h->size;
65 Node *n = h->node; 65 Node *n = h->node;
66 while (i--) { 66 while (i--) {
67 if (ttype(key(n)) == LUA_T_NUMBER && 67 if (ttype(key(n)) == TAG_NUMBER &&
68 ttype(val(n)) != LUA_T_NIL && 68 ttype(val(n)) != TAG_NIL &&
69 nvalue(key(n)) > max) 69 nvalue(key(n)) > max)
70 max = nvalue(key(n)); 70 max = nvalue(key(n));
71 n++; 71 n++;
@@ -74,14 +74,14 @@ static real getsize (const Hash *h) {
74} 74}
75 75
76 76
77static real getnarg (lua_State *L, const Hash *a) { 77static Number getnarg (lua_State *L, const Hash *a) {
78 TObject index; 78 TObject index;
79 const TObject *value; 79 const TObject *value;
80 /* value = table.n */ 80 /* value = table.n */
81 ttype(&index) = LUA_T_STRING; 81 ttype(&index) = TAG_STRING;
82 tsvalue(&index) = luaS_new(L, "n"); 82 tsvalue(&index) = luaS_new(L, "n");
83 value = luaH_get(L, a, &index); 83 value = luaH_get(L, a, &index);
84 return (ttype(value) == LUA_T_NUMBER) ? nvalue(value) : getsize(a); 84 return (ttype(value) == TAG_NUMBER) ? nvalue(value) : getsize(a);
85} 85}
86 86
87 87
@@ -167,7 +167,7 @@ void luaB_tonumber (lua_State *L) {
167 else { 167 else {
168 const char *s1 = luaL_check_string(L, 1); 168 const char *s1 = luaL_check_string(L, 1);
169 char *s2; 169 char *s2;
170 real n; 170 Number n;
171 luaL_arg_check(L, 0 <= base && base <= 36, 2, "base out of range"); 171 luaL_arg_check(L, 0 <= base && base <= 36, 2, "base out of range");
172 n = strtoul(s1, &s2, base); 172 n = strtoul(s1, &s2, base);
173 if (s1 == s2) return; /* no valid digits: return nil */ 173 if (s1 == s2) return; /* no valid digits: return nil */
@@ -244,7 +244,7 @@ void luaB_settagmethod (lua_State *L) {
244 luaL_arg_check(L, lua_isnil(L, nf) || lua_isfunction(L, nf), 3, 244 luaL_arg_check(L, lua_isnil(L, nf) || lua_isfunction(L, nf), 3,
245 "function or nil expected"); 245 "function or nil expected");
246#ifndef LUA_COMPAT_GC 246#ifndef LUA_COMPAT_GC
247 if (strcmp(event, "gc") == 0 && tag != LUA_T_NIL) 247 if (strcmp(event, "gc") == 0 && tag != TAG_NIL)
248 lua_error(L, "cannot set this `gc' tag method from Lua"); 248 lua_error(L, "cannot set this `gc' tag method from Lua");
249#endif 249#endif
250 lua_pushobject(L, nf); 250 lua_pushobject(L, nf);
@@ -349,11 +349,11 @@ void luaB_call (lua_State *L) {
349 349
350void luaB_nextvar (lua_State *L) { 350void luaB_nextvar (lua_State *L) {
351 lua_Object o = luaL_nonnullarg(L, 1); 351 lua_Object o = luaL_nonnullarg(L, 1);
352 TaggedString *name; 352 TString *name;
353 if (ttype(o) == LUA_T_NIL) 353 if (ttype(o) == TAG_NIL)
354 name = NULL; 354 name = NULL;
355 else { 355 else {
356 luaL_arg_check(L, ttype(o) == LUA_T_STRING, 1, "variable name expected"); 356 luaL_arg_check(L, ttype(o) == TAG_STRING, 1, "variable name expected");
357 name = tsvalue(o); 357 name = tsvalue(o);
358 } 358 }
359 if (!luaA_nextvar(L, name)) 359 if (!luaA_nextvar(L, name))
@@ -365,7 +365,7 @@ void luaB_next (lua_State *L) {
365 const Hash *a = gettable(L, 1); 365 const Hash *a = gettable(L, 1);
366 lua_Object k = luaL_nonnullarg(L, 2); 366 lua_Object k = luaL_nonnullarg(L, 2);
367 int i; /* `luaA_next' gets first element after `i' */ 367 int i; /* `luaA_next' gets first element after `i' */
368 if (ttype(k) == LUA_T_NIL) 368 if (ttype(k) == TAG_NIL)
369 i = 0; /* get first */ 369 i = 0; /* get first */
370 else { 370 else {
371 i = luaH_pos(L, a, k)+1; 371 i = luaH_pos(L, a, k)+1;
@@ -380,29 +380,29 @@ void luaB_tostring (lua_State *L) {
380 lua_Object o = lua_getparam(L, 1); 380 lua_Object o = lua_getparam(L, 1);
381 char buff[64]; 381 char buff[64];
382 switch (ttype(o)) { 382 switch (ttype(o)) {
383 case LUA_T_NUMBER: 383 case TAG_NUMBER:
384 lua_pushstring(L, lua_getstring(L, o)); 384 lua_pushstring(L, lua_getstring(L, o));
385 return; 385 return;
386 case LUA_T_STRING: 386 case TAG_STRING:
387 lua_pushobject(L, o); 387 lua_pushobject(L, o);
388 return; 388 return;
389 case LUA_T_ARRAY: 389 case TAG_ARRAY:
390 sprintf(buff, "table: %p", o->value.a); 390 sprintf(buff, "table: %p", o->value.a);
391 break; 391 break;
392 case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: 392 case TAG_LCLOSURE: case TAG_CCLOSURE:
393 sprintf(buff, "function: %p", o->value.cl); 393 sprintf(buff, "function: %p", o->value.cl);
394 break; 394 break;
395 case LUA_T_LPROTO: 395 case TAG_LPROTO:
396 sprintf(buff, "function: %p", o->value.tf); 396 sprintf(buff, "function: %p", o->value.tf);
397 break; 397 break;
398 case LUA_T_CPROTO: 398 case TAG_CPROTO:
399 sprintf(buff, "function: %p", o->value.f); 399 sprintf(buff, "function: %p", o->value.f);
400 break; 400 break;
401 case LUA_T_USERDATA: 401 case TAG_USERDATA:
402 sprintf(buff, "userdata: %p(%d)", o->value.ts->u.d.value, 402 sprintf(buff, "userdata: %p(%d)", o->value.ts->u.d.value,
403 o->value.ts->u.d.tag); 403 o->value.ts->u.d.tag);
404 break; 404 break;
405 case LUA_T_NIL: 405 case TAG_NIL:
406 lua_pushstring(L, "nil"); 406 lua_pushstring(L, "nil");
407 return; 407 return;
408 default: 408 default:
@@ -440,10 +440,10 @@ void luaB_foreachi (lua_State *L) {
440 luaD_checkstack(L, 3); /* for f, key, and val */ 440 luaD_checkstack(L, 3); /* for f, key, and val */
441 for (i=1; i<=n; i++) { 441 for (i=1; i<=n; i++) {
442 *(L->top++) = *f; 442 *(L->top++) = *f;
443 ttype(L->top) = LUA_T_NUMBER; nvalue(L->top++) = i; 443 ttype(L->top) = TAG_NUMBER; nvalue(L->top++) = i;
444 *(L->top++) = *luaH_getint(L, t, i); 444 *(L->top++) = *luaH_getint(L, t, i);
445 luaD_call(L, L->top-3, 1); 445 luaD_call(L, L->top-3, 1);
446 if (ttype(L->top-1) != LUA_T_NIL) 446 if (ttype(L->top-1) != TAG_NIL)
447 return; 447 return;
448 L->top--; /* remove nil result */ 448 L->top--; /* remove nil result */
449 } 449 }
@@ -457,12 +457,12 @@ void luaB_foreach (lua_State *L) {
457 luaD_checkstack(L, 3); /* for f, key, and val */ 457 luaD_checkstack(L, 3); /* for f, key, and val */
458 for (i=0; i<a->size; i++) { 458 for (i=0; i<a->size; i++) {
459 const Node *nd = &(a->node[i]); 459 const Node *nd = &(a->node[i]);
460 if (ttype(val(nd)) != LUA_T_NIL) { 460 if (ttype(val(nd)) != TAG_NIL) {
461 *(L->top++) = *f; 461 *(L->top++) = *f;
462 *(L->top++) = *key(nd); 462 *(L->top++) = *key(nd);
463 *(L->top++) = *val(nd); 463 *(L->top++) = *val(nd);
464 luaD_call(L, L->top-3, 1); 464 luaD_call(L, L->top-3, 1);
465 if (ttype(L->top-1) != LUA_T_NIL) 465 if (ttype(L->top-1) != TAG_NIL)
466 return; 466 return;
467 L->top--; /* remove result */ 467 L->top--; /* remove result */
468 } 468 }
@@ -475,13 +475,13 @@ void luaB_foreachvar (lua_State *L) {
475 GlobalVar *gv; 475 GlobalVar *gv;
476 luaD_checkstack(L, 4); /* for extra var name, f, var name, and globalval */ 476 luaD_checkstack(L, 4); /* for extra var name, f, var name, and globalval */
477 for (gv = L->rootglobal; gv; gv = gv->next) { 477 for (gv = L->rootglobal; gv; gv = gv->next) {
478 if (gv->value.ttype != LUA_T_NIL) { 478 if (gv->value.ttype != TAG_NIL) {
479 pushtagstring(L, gv->name); /* keep (extra) name on stack to avoid GC */ 479 pushtagstring(L, gv->name); /* keep (extra) name on stack to avoid GC */
480 *(L->top++) = *f; 480 *(L->top++) = *f;
481 pushtagstring(L, gv->name); 481 pushtagstring(L, gv->name);
482 *(L->top++) = gv->value; 482 *(L->top++) = gv->value;
483 luaD_call(L, L->top-3, 1); 483 luaD_call(L, L->top-3, 1);
484 if (ttype(L->top-1) != LUA_T_NIL) { 484 if (ttype(L->top-1) != TAG_NIL) {
485 *(L->top-2) = *(L->top-1); /* remove extra name */ 485 *(L->top-2) = *(L->top-1); /* remove extra name */
486 L->top--; 486 L->top--;
487 return; 487 return;
@@ -551,7 +551,7 @@ static int sort_comp (lua_State *L, lua_Object f, const TObject *a,
551 L->top += 3; 551 L->top += 3;
552 luaD_call(L, L->top-3, 1); 552 luaD_call(L, L->top-3, 1);
553 L->top--; 553 L->top--;
554 return (ttype(L->top) != LUA_T_NIL); 554 return (ttype(L->top) != TAG_NIL);
555 } 555 }
556 else /* a < b? */ 556 else /* a < b? */
557 return luaV_lessthan(L, a, b, L->top); 557 return luaV_lessthan(L, a, b, L->top);
@@ -559,7 +559,7 @@ static int sort_comp (lua_State *L, lua_Object f, const TObject *a,
559 559
560static void auxsort (lua_State *L, Hash *a, int l, int u, lua_Object f) { 560static void auxsort (lua_State *L, Hash *a, int l, int u, lua_Object f) {
561 StkId P = L->top++; /* temporary place for pivot */ 561 StkId P = L->top++; /* temporary place for pivot */
562 ttype(P) = LUA_T_NIL; 562 ttype(P) = TAG_NIL;
563 while (l < u) { /* for tail recursion */ 563 while (l < u) { /* for tail recursion */
564 int i, j; 564 int i, j;
565 /* sort elements a[l], a[(l+u)/2] and a[u] */ 565 /* sort elements a[l], a[(l+u)/2] and a[u] */
diff --git a/lcode.c b/lcode.c
index 1a5c23f7..de78c52f 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.8 2000/03/09 13:57:37 roberto Exp roberto $ 2** $Id: lcode.c,v 1.9 2000/03/10 14:38:10 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*/
@@ -32,8 +32,8 @@ static Instruction *previous_instruction (LexState *ls) {
32 if (fs->pc > fs->lasttarget) /* no jumps to current position? */ 32 if (fs->pc > fs->lasttarget) /* no jumps to current position? */
33 return &fs->f->code[fs->pc-1]; /* returns previous instruction */ 33 return &fs->f->code[fs->pc-1]; /* returns previous instruction */
34 else { 34 else {
35 static Instruction dummy = CREATE_0(ENDCODE); 35 static Instruction dummy = CREATE_0(OP_END);
36 return &dummy; /* no optimizations after an `ENDCODE' */ 36 return &dummy; /* no optimizations after an `END' */
37 } 37 }
38} 38}
39 39
@@ -49,10 +49,10 @@ int luaK_primitivecode (LexState *ls, Instruction i) {
49static void luaK_minus (LexState *ls) { 49static void luaK_minus (LexState *ls) {
50 Instruction *previous = previous_instruction(ls); 50 Instruction *previous = previous_instruction(ls);
51 switch(GET_OPCODE(*previous)) { 51 switch(GET_OPCODE(*previous)) {
52 case PUSHINT: SETARG_S(*previous, -GETARG_S(*previous)); return; 52 case OP_PUSHINT: SETARG_S(*previous, -GETARG_S(*previous)); return;
53 case PUSHNUM: SET_OPCODE(*previous, PUSHNEGNUM); return; 53 case OP_PUSHNUM: SET_OPCODE(*previous, OP_PUSHNEGNUM); return;
54 case PUSHNEGNUM: SET_OPCODE(*previous, PUSHNUM); return; 54 case OP_PUSHNEGNUM: SET_OPCODE(*previous, OP_PUSHNUM); return;
55 default: luaK_primitivecode(ls, CREATE_0(MINUSOP)); 55 default: luaK_primitivecode(ls, CREATE_0(OP_MINUS));
56 } 56 }
57} 57}
58 58
@@ -61,8 +61,8 @@ static void luaK_gettable (LexState *ls) {
61 Instruction *previous = previous_instruction(ls); 61 Instruction *previous = previous_instruction(ls);
62 luaK_deltastack(ls, -1); 62 luaK_deltastack(ls, -1);
63 switch(GET_OPCODE(*previous)) { 63 switch(GET_OPCODE(*previous)) {
64 case PUSHSTRING: SET_OPCODE(*previous, GETDOTTED); break; 64 case OP_PUSHSTRING: SET_OPCODE(*previous, OP_GETDOTTED); break;
65 default: luaK_primitivecode(ls, CREATE_0(GETTABLE)); 65 default: luaK_primitivecode(ls, CREATE_0(OP_GETTABLE));
66 } 66 }
67} 67}
68 68
@@ -71,8 +71,8 @@ static void luaK_add (LexState *ls) {
71 Instruction *previous = previous_instruction(ls); 71 Instruction *previous = previous_instruction(ls);
72 luaK_deltastack(ls, -1); 72 luaK_deltastack(ls, -1);
73 switch(GET_OPCODE(*previous)) { 73 switch(GET_OPCODE(*previous)) {
74 case PUSHINT: SET_OPCODE(*previous, ADDI); break; 74 case OP_PUSHINT: SET_OPCODE(*previous, OP_ADDI); break;
75 default: luaK_primitivecode(ls, CREATE_0(ADDOP)); 75 default: luaK_primitivecode(ls, CREATE_0(OP_ADD));
76 } 76 }
77} 77}
78 78
@@ -81,11 +81,11 @@ static void luaK_sub (LexState *ls) {
81 Instruction *previous = previous_instruction(ls); 81 Instruction *previous = previous_instruction(ls);
82 luaK_deltastack(ls, -1); 82 luaK_deltastack(ls, -1);
83 switch(GET_OPCODE(*previous)) { 83 switch(GET_OPCODE(*previous)) {
84 case PUSHINT: 84 case OP_PUSHINT:
85 SET_OPCODE(*previous, ADDI); 85 SET_OPCODE(*previous, OP_ADDI);
86 SETARG_S(*previous, -GETARG_S(*previous)); 86 SETARG_S(*previous, -GETARG_S(*previous));
87 break; 87 break;
88 default: luaK_primitivecode(ls, CREATE_0(SUBOP)); 88 default: luaK_primitivecode(ls, CREATE_0(OP_SUB));
89 } 89 }
90} 90}
91 91
@@ -94,43 +94,43 @@ static void luaK_conc (LexState *ls) {
94 Instruction *previous = previous_instruction(ls); 94 Instruction *previous = previous_instruction(ls);
95 luaK_deltastack(ls, -1); 95 luaK_deltastack(ls, -1);
96 switch(GET_OPCODE(*previous)) { 96 switch(GET_OPCODE(*previous)) {
97 case CONCOP: SETARG_U(*previous, GETARG_U(*previous)+1); break; 97 case OP_CONC: SETARG_U(*previous, GETARG_U(*previous)+1); break;
98 default: luaK_primitivecode(ls, CREATE_U(CONCOP, 2)); 98 default: luaK_primitivecode(ls, CREATE_U(OP_CONC, 2));
99 } 99 }
100} 100}
101 101
102 102
103static void luaK_eq (LexState *ls) { 103static void luaK_eq (LexState *ls) {
104 Instruction *previous = previous_instruction(ls); 104 Instruction *previous = previous_instruction(ls);
105 if (*previous == CREATE_U(PUSHNIL, 1)) { 105 if (*previous == CREATE_U(OP_PUSHNIL, 1)) {
106 *previous = CREATE_0(NOTOP); 106 *previous = CREATE_0(OP_NOT);
107 luaK_deltastack(ls, -1); /* undo effect of PUSHNIL */ 107 luaK_deltastack(ls, -1); /* undo effect of PUSHNIL */
108 } 108 }
109 else 109 else
110 luaK_S(ls, IFEQJMP, 0, -2); 110 luaK_S(ls, OP_IFEQJMP, 0, -2);
111} 111}
112 112
113 113
114static void luaK_neq (LexState *ls) { 114static void luaK_neq (LexState *ls) {
115 Instruction *previous = previous_instruction(ls); 115 Instruction *previous = previous_instruction(ls);
116 if (*previous == CREATE_U(PUSHNIL, 1)) { 116 if (*previous == CREATE_U(OP_PUSHNIL, 1)) {
117 ls->fs->pc--; /* remove PUSHNIL */ 117 ls->fs->pc--; /* remove PUSHNIL */
118 luaK_deltastack(ls, -1); /* undo effect of PUSHNIL */ 118 luaK_deltastack(ls, -1); /* undo effect of PUSHNIL */
119 } 119 }
120 else 120 else
121 luaK_S(ls, IFNEQJMP, 0, -2); 121 luaK_S(ls, OP_IFNEQJMP, 0, -2);
122} 122}
123 123
124 124
125void luaK_retcode (LexState *ls, int nlocals, int nexps) { 125void luaK_retcode (LexState *ls, int nlocals, int nexps) {
126 Instruction *previous = previous_instruction(ls); 126 Instruction *previous = previous_instruction(ls);
127 if (nexps > 0 && GET_OPCODE(*previous) == CALL) { 127 if (nexps > 0 && GET_OPCODE(*previous) == OP_CALL) {
128 LUA_ASSERT(ls->L, GETARG_B(*previous) == MULT_RET, "call should be open"); 128 LUA_ASSERT(ls->L, GETARG_B(*previous) == MULT_RET, "call should be open");
129 SET_OPCODE(*previous, TAILCALL); 129 SET_OPCODE(*previous, OP_TAILCALL);
130 SETARG_B(*previous, nlocals); 130 SETARG_B(*previous, nlocals);
131 } 131 }
132 else 132 else
133 luaK_primitivecode(ls, CREATE_U(RETCODE, nlocals)); 133 luaK_primitivecode(ls, CREATE_U(OP_RETURN, nlocals));
134} 134}
135 135
136 136
@@ -138,8 +138,8 @@ static void luaK_pushnil (LexState *ls, int n) {
138 Instruction *previous = previous_instruction(ls); 138 Instruction *previous = previous_instruction(ls);
139 luaK_deltastack(ls, n); 139 luaK_deltastack(ls, n);
140 switch(GET_OPCODE(*previous)) { 140 switch(GET_OPCODE(*previous)) {
141 case PUSHNIL: SETARG_U(*previous, GETARG_U(*previous)+n); break; 141 case OP_PUSHNIL: SETARG_U(*previous, GETARG_U(*previous)+n); break;
142 default: luaK_primitivecode(ls, CREATE_U(PUSHNIL, n)); 142 default: luaK_primitivecode(ls, CREATE_U(OP_PUSHNIL, n));
143 } 143 }
144} 144}
145 145
@@ -181,7 +181,7 @@ void luaK_deltastack (LexState *ls, int delta) {
181 181
182 182
183void luaK_kstr (LexState *ls, int c) { 183void luaK_kstr (LexState *ls, int c) {
184 luaK_U(ls, PUSHSTRING, c, 1); 184 luaK_U(ls, OP_PUSHSTRING, c, 1);
185} 185}
186 186
187 187
@@ -189,32 +189,32 @@ void luaK_kstr (LexState *ls, int c) {
189#define LOOKBACKNUMS 20 /* arbitrary limit */ 189#define LOOKBACKNUMS 20 /* arbitrary limit */
190#endif 190#endif
191 191
192static int real_constant (LexState *ls, real r) { 192static int real_constant (LexState *ls, Number r) {
193 /* check whether `r' has appeared within the last LOOKBACKNUMS entries */ 193 /* check whether `r' has appeared within the last LOOKBACKNUMS entries */
194 TProtoFunc *f = ls->fs->f; 194 Proto *f = ls->fs->f;
195 int c = f->nknum; 195 int c = f->nknum;
196 int lim = c < LOOKBACKNUMS ? 0 : c-LOOKBACKNUMS; 196 int lim = c < LOOKBACKNUMS ? 0 : c-LOOKBACKNUMS;
197 while (--c >= lim) 197 while (--c >= lim)
198 if (f->knum[c] == r) return c; 198 if (f->knum[c] == r) return c;
199 /* not found; create a new entry */ 199 /* not found; create a new entry */
200 luaM_growvector(ls->L, f->knum, f->nknum, 1, real, constantEM, MAXARG_U); 200 luaM_growvector(ls->L, f->knum, f->nknum, 1, Number, constantEM, MAXARG_U);
201 c = f->nknum++; 201 c = f->nknum++;
202 f->knum[c] = r; 202 f->knum[c] = r;
203 return c; 203 return c;
204} 204}
205 205
206 206
207void luaK_number (LexState *ls, real f) { 207void luaK_number (LexState *ls, Number f) {
208 if (f <= (real)MAXARG_S && (int)f == f) 208 if (f <= (Number)MAXARG_S && (int)f == f)
209 luaK_S(ls, PUSHINT, (int)f, 1); /* f has a short integer value */ 209 luaK_S(ls, OP_PUSHINT, (int)f, 1); /* f has a short integer value */
210 else 210 else
211 luaK_U(ls, PUSHNUM, real_constant(ls, f), 1); 211 luaK_U(ls, OP_PUSHNUM, real_constant(ls, f), 1);
212} 212}
213 213
214 214
215void luaK_adjuststack (LexState *ls, int n) { 215void luaK_adjuststack (LexState *ls, int n) {
216 if (n > 0) 216 if (n > 0)
217 luaK_U(ls, POP, n, -n); 217 luaK_U(ls, OP_POP, n, -n);
218 else if (n < 0) 218 else if (n < 0)
219 luaK_pushnil(ls, -n); 219 luaK_pushnil(ls, -n);
220} 220}
@@ -223,7 +223,7 @@ void luaK_adjuststack (LexState *ls, int n) {
223int luaK_lastisopen (LexState *ls) { 223int luaK_lastisopen (LexState *ls) {
224 /* check whether last instruction is an (open) function call */ 224 /* check whether last instruction is an (open) function call */
225 Instruction *i = previous_instruction(ls); 225 Instruction *i = previous_instruction(ls);
226 if (GET_OPCODE(*i) == CALL) { 226 if (GET_OPCODE(*i) == OP_CALL) {
227 LUA_ASSERT(ls->L, GETARG_B(*i) == MULT_RET, "call should be open"); 227 LUA_ASSERT(ls->L, GETARG_B(*i) == MULT_RET, "call should be open");
228 return 1; 228 return 1;
229 } 229 }
@@ -233,7 +233,7 @@ int luaK_lastisopen (LexState *ls) {
233 233
234void luaK_setcallreturns (LexState *ls, int nresults) { 234void luaK_setcallreturns (LexState *ls, int nresults) {
235 Instruction *i = previous_instruction(ls); 235 Instruction *i = previous_instruction(ls);
236 if (GET_OPCODE(*i) == CALL) { /* expression is a function call? */ 236 if (GET_OPCODE(*i) == OP_CALL) { /* expression is a function call? */
237 LUA_ASSERT(ls->L, GETARG_B(*i) == MULT_RET, "call should be open"); 237 LUA_ASSERT(ls->L, GETARG_B(*i) == MULT_RET, "call should be open");
238 SETARG_B(*i, nresults); /* set nresults */ 238 SETARG_B(*i, nresults); /* set nresults */
239 luaK_deltastack(ls, nresults); /* push results */ 239 luaK_deltastack(ls, nresults); /* push results */
@@ -249,10 +249,10 @@ static void assertglobal (LexState *ls, int index) {
249static int discharge (LexState *ls, expdesc *var) { 249static int discharge (LexState *ls, expdesc *var) {
250 switch (var->k) { 250 switch (var->k) {
251 case VLOCAL: 251 case VLOCAL:
252 luaK_U(ls, PUSHLOCAL, var->u.index, 1); 252 luaK_U(ls, OP_PUSHLOCAL, var->u.index, 1);
253 break; 253 break;
254 case VGLOBAL: 254 case VGLOBAL:
255 luaK_U(ls, GETGLOBAL, var->u.index, 1); 255 luaK_U(ls, OP_GETGLOBAL, var->u.index, 1);
256 assertglobal(ls, var->u.index); /* make sure that there is a global */ 256 assertglobal(ls, var->u.index); /* make sure that there is a global */
257 break; 257 break;
258 case VINDEXED: 258 case VINDEXED:
@@ -278,14 +278,14 @@ static void discharge1 (LexState *ls, expdesc *var) {
278void luaK_storevar (LexState *ls, const expdesc *var) { 278void luaK_storevar (LexState *ls, const expdesc *var) {
279 switch (var->k) { 279 switch (var->k) {
280 case VLOCAL: 280 case VLOCAL:
281 luaK_U(ls, SETLOCAL, var->u.index, -1); 281 luaK_U(ls, OP_SETLOCAL, var->u.index, -1);
282 break; 282 break;
283 case VGLOBAL: 283 case VGLOBAL:
284 luaK_U(ls, SETGLOBAL, var->u.index, -1); 284 luaK_U(ls, OP_SETGLOBAL, var->u.index, -1);
285 assertglobal(ls, var->u.index); /* make sure that there is a global */ 285 assertglobal(ls, var->u.index); /* make sure that there is a global */
286 break; 286 break;
287 case VINDEXED: 287 case VINDEXED:
288 luaK_0(ls, SETTABLEPOP, -3); 288 luaK_0(ls, OP_SETTABLEPOP, -3);
289 break; 289 break;
290 default: 290 default:
291 LUA_INTERNALERROR(ls->L, "invalid var kind to store"); 291 LUA_INTERNALERROR(ls->L, "invalid var kind to store");
@@ -295,17 +295,17 @@ void luaK_storevar (LexState *ls, const expdesc *var) {
295 295
296static OpCode invertjump (OpCode op) { 296static OpCode invertjump (OpCode op) {
297 switch (op) { 297 switch (op) {
298 case IFNEQJMP: return IFEQJMP; 298 case OP_IFNEQJMP: return OP_IFEQJMP;
299 case IFEQJMP: return IFNEQJMP; 299 case OP_IFEQJMP: return OP_IFNEQJMP;
300 case IFLTJMP: return IFGEJMP; 300 case OP_IFLTJMP: return OP_IFGEJMP;
301 case IFLEJMP: return IFGTJMP; 301 case OP_IFLEJMP: return OP_IFGTJMP;
302 case IFGTJMP: return IFLEJMP; 302 case OP_IFGTJMP: return OP_IFLEJMP;
303 case IFGEJMP: return IFLTJMP; 303 case OP_IFGEJMP: return OP_IFLTJMP;
304 case IFTJMP: case ONTJMP: return IFFJMP; 304 case OP_IFTJMP: case OP_ONTJMP: return OP_IFFJMP;
305 case IFFJMP: case ONFJMP: return IFTJMP; 305 case OP_IFFJMP: case OP_ONFJMP: return OP_IFTJMP;
306 default: 306 default:
307 LUA_INTERNALERROR(NULL, "invalid jump instruction"); 307 LUA_INTERNALERROR(NULL, "invalid jump instruction");
308 return ENDCODE; /* to avoid warnings */ 308 return OP_END; /* to avoid warnings */
309 } 309 }
310} 310}
311 311
@@ -313,7 +313,7 @@ static OpCode invertjump (OpCode op) {
313static void luaK_jump (LexState *ls, OpCode jump) { 313static void luaK_jump (LexState *ls, OpCode jump) {
314 Instruction *previous = previous_instruction(ls); 314 Instruction *previous = previous_instruction(ls);
315 luaK_deltastack(ls, -1); 315 luaK_deltastack(ls, -1);
316 if (*previous == CREATE_0(NOTOP)) 316 if (*previous == CREATE_0(OP_NOT))
317 *previous = CREATE_S(invertjump(jump), 0); 317 *previous = CREATE_S(invertjump(jump), 0);
318 else 318 else
319 luaK_primitivecode(ls, CREATE_S(jump, 0)); 319 luaK_primitivecode(ls, CREATE_S(jump, 0));
@@ -342,10 +342,10 @@ static void luaK_patchlistaux (LexState *ls, int list, int target,
342 SETARG_S(*i, special_target-(list+1)); 342 SETARG_S(*i, special_target-(list+1));
343 else { 343 else {
344 SETARG_S(*i, target-(list+1)); /* do the patch */ 344 SETARG_S(*i, target-(list+1)); /* do the patch */
345 if (op == ONTJMP) /* remove eventual values */ 345 if (op == OP_ONTJMP) /* remove eventual values */
346 SET_OPCODE(*i, IFTJMP); 346 SET_OPCODE(*i, OP_IFTJMP);
347 else if (op == ONFJMP) 347 else if (op == OP_ONFJMP)
348 SET_OPCODE(*i, IFFJMP); 348 SET_OPCODE(*i, OP_IFFJMP);
349 } 349 }
350 if (next == 0) return; 350 if (next == 0) return;
351 list += next+1; 351 list += next+1;
@@ -355,7 +355,7 @@ static void luaK_patchlistaux (LexState *ls, int list, int target,
355 355
356 356
357void luaK_patchlist (LexState *ls, int list, int target) { 357void luaK_patchlist (LexState *ls, int list, int target) {
358 luaK_patchlistaux(ls, list, target, ENDCODE, 0); 358 luaK_patchlistaux(ls, list, target, OP_END, 0);
359} 359}
360 360
361 361
@@ -399,7 +399,7 @@ void luaK_goiftrue (LexState *ls, expdesc *v, int keepvalue) {
399 if (ISJUMP(GET_OPCODE(*previous))) 399 if (ISJUMP(GET_OPCODE(*previous)))
400 SET_OPCODE(*previous, invertjump(GET_OPCODE(*previous))); 400 SET_OPCODE(*previous, invertjump(GET_OPCODE(*previous)));
401 else { 401 else {
402 OpCode jump = keepvalue ? ONFJMP : IFFJMP; 402 OpCode jump = keepvalue ? OP_ONFJMP : OP_IFFJMP;
403 luaK_jump(ls, jump); 403 luaK_jump(ls, jump);
404 } 404 }
405 insert_last(fs, &v->u.l.f); 405 insert_last(fs, &v->u.l.f);
@@ -414,7 +414,7 @@ void luaK_goiffalse (LexState *ls, expdesc *v, int keepvalue) {
414 discharge1(ls, v); 414 discharge1(ls, v);
415 previous = fs->f->code[fs->pc-1]; 415 previous = fs->f->code[fs->pc-1];
416 if (!ISJUMP(GET_OPCODE(previous))) { 416 if (!ISJUMP(GET_OPCODE(previous))) {
417 OpCode jump = keepvalue ? ONTJMP : IFTJMP; 417 OpCode jump = keepvalue ? OP_ONTJMP : OP_IFTJMP;
418 luaK_jump(ls, jump); 418 luaK_jump(ls, jump);
419 } 419 }
420 insert_last(fs, &v->u.l.t); 420 insert_last(fs, &v->u.l.t);
@@ -440,28 +440,28 @@ void luaK_tostack (LexState *ls, expdesc *v, int onlyone) {
440 int final; /* position after whole expression */ 440 int final; /* position after whole expression */
441 if (ISJUMP(previous)) { 441 if (ISJUMP(previous)) {
442 insert_last(fs, &v->u.l.t); /* put `previous' in true list */ 442 insert_last(fs, &v->u.l.t); /* put `previous' in true list */
443 p_nil = luaK_0(ls, PUSHNILJMP, 0); 443 p_nil = luaK_0(ls, OP_PUSHNILJMP, 0);
444 p_1 = luaK_S(ls, PUSHINT, 1, 1); 444 p_1 = luaK_S(ls, OP_PUSHINT, 1, 1);
445 } 445 }
446 else { /* still may need a PUSHNIL or a PUSHINT */ 446 else { /* still may need a PUSHNIL or a PUSHINT */
447 int need_nil = need_value(fs, v->u.l.f, ONFJMP); 447 int need_nil = need_value(fs, v->u.l.f, OP_ONFJMP);
448 int need_1 = need_value(fs, v->u.l.t, ONTJMP); 448 int need_1 = need_value(fs, v->u.l.t, OP_ONTJMP);
449 if (need_nil && need_1) { 449 if (need_nil && need_1) {
450 luaK_S(ls, JMP, 2, 0); /* skip both pushes */ 450 luaK_S(ls, OP_JMP, 2, 0); /* skip both pushes */
451 p_nil = luaK_0(ls, PUSHNILJMP, 0); 451 p_nil = luaK_0(ls, OP_PUSHNILJMP, 0);
452 p_1 = luaK_S(ls, PUSHINT, 1, 0); 452 p_1 = luaK_S(ls, OP_PUSHINT, 1, 0);
453 } 453 }
454 else if (need_nil || need_1) { 454 else if (need_nil || need_1) {
455 luaK_S(ls, JMP, 1, 0); /* skip one push */ 455 luaK_S(ls, OP_JMP, 1, 0); /* skip one push */
456 if (need_nil) 456 if (need_nil)
457 p_nil = luaK_U(ls, PUSHNIL, 1, 0); 457 p_nil = luaK_U(ls, OP_PUSHNIL, 1, 0);
458 else /* need_1 */ 458 else /* need_1 */
459 p_1 = luaK_S(ls, PUSHINT, 1, 0); 459 p_1 = luaK_S(ls, OP_PUSHINT, 1, 0);
460 } 460 }
461 } 461 }
462 final = luaK_getlabel(ls); 462 final = luaK_getlabel(ls);
463 luaK_patchlistaux(ls, v->u.l.f, p_nil, ONFJMP, final); 463 luaK_patchlistaux(ls, v->u.l.f, p_nil, OP_ONFJMP, final);
464 luaK_patchlistaux(ls, v->u.l.t, p_1, ONTJMP, final); 464 luaK_patchlistaux(ls, v->u.l.t, p_1, OP_ONTJMP, final);
465 v->u.l.f = v->u.l.t = 0; 465 v->u.l.f = v->u.l.t = 0;
466 } 466 }
467 } 467 }
@@ -481,7 +481,7 @@ void luaK_prefix (LexState *ls, int op, expdesc *v) {
481 if (ISJUMP(GET_OPCODE(*previous))) 481 if (ISJUMP(GET_OPCODE(*previous)))
482 SET_OPCODE(*previous, invertjump(GET_OPCODE(*previous))); 482 SET_OPCODE(*previous, invertjump(GET_OPCODE(*previous)));
483 else 483 else
484 luaK_0(ls, NOTOP, 0); 484 luaK_0(ls, OP_NOT, 0);
485 /* interchange true and false lists */ 485 /* interchange true and false lists */
486 { int temp = v->u.l.f; v->u.l.f = v->u.l.t; v->u.l.t = temp; } 486 { int temp = v->u.l.f; v->u.l.f = v->u.l.t; v->u.l.t = temp; }
487 } 487 }
@@ -489,9 +489,9 @@ void luaK_prefix (LexState *ls, int op, expdesc *v) {
489 489
490 490
491void luaK_infix (LexState *ls, int op, expdesc *v) { 491void luaK_infix (LexState *ls, int op, expdesc *v) {
492 if (op == AND) 492 if (op == TK_AND)
493 luaK_goiftrue(ls, v, 1); 493 luaK_goiftrue(ls, v, 1);
494 else if (op == OR) 494 else if (op == TK_OR)
495 luaK_goiffalse(ls, v, 1); 495 luaK_goiffalse(ls, v, 1);
496 else 496 else
497 luaK_tostack(ls, v, 1); /* all other binary operators need a value */ 497 luaK_tostack(ls, v, 1); /* all other binary operators need a value */
@@ -499,13 +499,13 @@ void luaK_infix (LexState *ls, int op, expdesc *v) {
499 499
500 500
501void luaK_posfix (LexState *ls, int op, expdesc *v1, expdesc *v2) { 501void luaK_posfix (LexState *ls, int op, expdesc *v1, expdesc *v2) {
502 if (op == AND) { 502 if (op == TK_AND) {
503 LUA_ASSERT(ls->L, v1->u.l.t == 0, "list must be closed"); 503 LUA_ASSERT(ls->L, v1->u.l.t == 0, "list must be closed");
504 discharge1(ls, v2); 504 discharge1(ls, v2);
505 v1->u.l.t = v2->u.l.t; 505 v1->u.l.t = v2->u.l.t;
506 concatlists(ls, &v1->u.l.f, v2->u.l.f); 506 concatlists(ls, &v1->u.l.f, v2->u.l.f);
507 } 507 }
508 else if (op == OR) { 508 else if (op == TK_OR) {
509 LUA_ASSERT(ls->L, v1->u.l.f == 0, "list must be closed"); 509 LUA_ASSERT(ls->L, v1->u.l.f == 0, "list must be closed");
510 discharge1(ls, v2); 510 discharge1(ls, v2);
511 v1->u.l.f = v2->u.l.f; 511 v1->u.l.f = v2->u.l.f;
@@ -516,16 +516,16 @@ void luaK_posfix (LexState *ls, int op, expdesc *v1, expdesc *v2) {
516 switch (op) { 516 switch (op) {
517 case '+': luaK_add(ls); break; 517 case '+': luaK_add(ls); break;
518 case '-': luaK_sub(ls); break; 518 case '-': luaK_sub(ls); break;
519 case '*': luaK_0(ls, MULTOP, -1); break; 519 case '*': luaK_0(ls, OP_MULT, -1); break;
520 case '/': luaK_0(ls, DIVOP, -1); break; 520 case '/': luaK_0(ls, OP_DIV, -1); break;
521 case '^': luaK_0(ls, POWOP, -1); break; 521 case '^': luaK_0(ls, OP_POW, -1); break;
522 case CONC: luaK_conc(ls); break; 522 case TK_CONC: luaK_conc(ls); break;
523 case EQ: luaK_eq(ls); break; 523 case TK_EQ: luaK_eq(ls); break;
524 case NE: luaK_neq(ls); break; 524 case TK_NE: luaK_neq(ls); break;
525 case '>': luaK_S(ls, IFGTJMP, 0, -2); break; 525 case '>': luaK_S(ls, OP_IFGTJMP, 0, -2); break;
526 case '<': luaK_S(ls, IFLTJMP, 0, -2); break; 526 case '<': luaK_S(ls, OP_IFLTJMP, 0, -2); break;
527 case GE: luaK_S(ls, IFGEJMP, 0, -2); break; 527 case TK_GE: luaK_S(ls, OP_IFGEJMP, 0, -2); break;
528 case LE: luaK_S(ls, IFLEJMP, 0, -2); break; 528 case TK_LE: luaK_S(ls, OP_IFLEJMP, 0, -2); break;
529 } 529 }
530 } 530 }
531} 531}
diff --git a/lcode.h b/lcode.h
index 91674ad3..994ff499 100644
--- a/lcode.h
+++ b/lcode.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.h,v 1.3 2000/03/03 18:53:17 roberto Exp roberto $ 2** $Id: lcode.h,v 1.5 2000/03/09 13:57:37 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*/
@@ -30,7 +30,7 @@ void luaK_goiffalse (LexState *ls, expdesc *v, int keepvalue);
30int luaK_getlabel (LexState *ls); 30int luaK_getlabel (LexState *ls);
31void luaK_deltastack (LexState *ls, int delta); 31void luaK_deltastack (LexState *ls, int delta);
32void luaK_kstr (LexState *ls, int c); 32void luaK_kstr (LexState *ls, int c);
33void luaK_number (LexState *ls, real f); 33void luaK_number (LexState *ls, Number f);
34void luaK_adjuststack (LexState *ls, int n); 34void luaK_adjuststack (LexState *ls, int n);
35int luaK_lastisopen (LexState *ls); 35int luaK_lastisopen (LexState *ls);
36void luaK_setcallreturns (LexState *ls, int nresults); 36void luaK_setcallreturns (LexState *ls, int nresults);
diff --git a/ldebug.c b/ldebug.c
index 45214b8f..1353dfc7 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.9 2000/02/17 18:30:36 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.10 2000/03/03 14:58:26 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*/
@@ -23,11 +23,11 @@
23 23
24 24
25static const lua_Type normtype[] = { /* ORDER LUA_T */ 25static const lua_Type normtype[] = { /* ORDER LUA_T */
26 LUA_T_USERDATA, LUA_T_NUMBER, LUA_T_STRING, LUA_T_ARRAY, 26 TAG_USERDATA, TAG_NUMBER, TAG_STRING, TAG_ARRAY,
27 LUA_T_LPROTO, LUA_T_CPROTO, LUA_T_NIL, 27 TAG_LPROTO, TAG_CPROTO, TAG_NIL,
28 LUA_T_LCLOSURE, LUA_T_CCLOSURE, 28 TAG_LCLOSURE, TAG_CCLOSURE,
29 LUA_T_LCLOSURE, LUA_T_CCLOSURE, /* LUA_T_LCLMARK, LUA_T_CCLMARK */ 29 TAG_LCLOSURE, TAG_CCLOSURE, /* TAG_LCLMARK, TAG_CCLMARK */
30 LUA_T_LPROTO, LUA_T_CPROTO /* LUA_T_LMARK, LUA_T_CMARK */ 30 TAG_LPROTO, TAG_CPROTO /* TAG_LMARK, TAG_CMARK */
31}; 31};
32 32
33 33
@@ -39,7 +39,7 @@ static void setnormalized (TObject *d, const TObject *s) {
39 39
40 40
41static int hasdebuginfo (lua_State *L, StkId f) { 41static int hasdebuginfo (lua_State *L, StkId f) {
42 return (f+1 < L->top && (f+1)->ttype == LUA_T_LINE); 42 return (f+1 < L->top && (f+1)->ttype == TAG_LINE);
43} 43}
44 44
45 45
@@ -89,8 +89,8 @@ int lua_getstack (lua_State *L, int level, lua_Dbgactreg *ar) {
89 89
90static int lua_nups (StkId f) { 90static int lua_nups (StkId f) {
91 switch (ttype(f)) { 91 switch (ttype(f)) {
92 case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: 92 case TAG_LCLOSURE: case TAG_CCLOSURE:
93 case LUA_T_LCLMARK: case LUA_T_CCLMARK: 93 case TAG_LCLMARK: case TAG_CCLMARK:
94 return f->value.cl->nelems; 94 return f->value.cl->nelems;
95 default: 95 default:
96 return 0; 96 return 0;
@@ -103,10 +103,10 @@ static int lua_currentline (lua_State *L, StkId f) {
103} 103}
104 104
105 105
106static TProtoFunc *getluaproto (StkId f) { 106static Proto *getluaproto (StkId f) {
107 if (ttype(f) == LUA_T_LMARK) 107 if (ttype(f) == TAG_LMARK)
108 return f->value.tf; 108 return f->value.tf;
109 else if (ttype(f) == LUA_T_LCLMARK) 109 else if (ttype(f) == TAG_LCLMARK)
110 return protovalue(f)->value.tf; 110 return protovalue(f)->value.tf;
111 else return NULL; 111 else return NULL;
112} 112}
@@ -114,13 +114,13 @@ static TProtoFunc *getluaproto (StkId f) {
114 114
115int lua_getlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) { 115int lua_getlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) {
116 StkId f = ar->_func; 116 StkId f = ar->_func;
117 TProtoFunc *fp = getluaproto(f); 117 Proto *fp = getluaproto(f);
118 if (!fp) return 0; /* `f' is not a Lua function? */ 118 if (!fp) return 0; /* `f' is not a Lua function? */
119 v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); 119 v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f));
120 if (!v->name) return 0; 120 if (!v->name) return 0;
121 /* if `name', there must be a LUA_T_LINE */ 121 /* if `name', there must be a TAG_LINE */
122 /* therefore, f+2 points to function base */ 122 /* therefore, f+2 points to function base */
123 LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); 123 LUA_ASSERT(L, ttype(f+1) == TAG_LINE, "");
124 v->value = luaA_putluaObject(L, (f+2)+(v->index-1)); 124 v->value = luaA_putluaObject(L, (f+2)+(v->index-1));
125 return 1; 125 return 1;
126} 126}
@@ -128,11 +128,11 @@ int lua_getlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) {
128 128
129int lua_setlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) { 129int lua_setlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) {
130 StkId f = ar->_func; 130 StkId f = ar->_func;
131 TProtoFunc *fp = getluaproto(f); 131 Proto *fp = getluaproto(f);
132 if (!fp) return 0; /* `f' is not a Lua function? */ 132 if (!fp) return 0; /* `f' is not a Lua function? */
133 v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); 133 v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f));
134 if (!v->name) return 0; 134 if (!v->name) return 0;
135 LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); 135 LUA_ASSERT(L, ttype(f+1) == TAG_LINE, "");
136 *((f+2)+(v->index-1)) = *v->value; 136 *((f+2)+(v->index-1)) = *v->value;
137 return 1; 137 return 1;
138} 138}
@@ -141,12 +141,12 @@ int lua_setlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) {
141static void lua_funcinfo (lua_Dbgactreg *ar) { 141static void lua_funcinfo (lua_Dbgactreg *ar) {
142 StkId func = ar->_func; 142 StkId func = ar->_func;
143 switch (ttype(func)) { 143 switch (ttype(func)) {
144 case LUA_T_LPROTO: case LUA_T_LMARK: 144 case TAG_LPROTO: case TAG_LMARK:
145 ar->source = tfvalue(func)->source->str; 145 ar->source = tfvalue(func)->source->str;
146 ar->linedefined = tfvalue(func)->lineDefined; 146 ar->linedefined = tfvalue(func)->lineDefined;
147 ar->what = "Lua"; 147 ar->what = "Lua";
148 break; 148 break;
149 case LUA_T_LCLOSURE: case LUA_T_LCLMARK: 149 case TAG_LCLOSURE: case TAG_LCLMARK:
150 ar->source = tfvalue(protovalue(func))->source->str; 150 ar->source = tfvalue(protovalue(func))->source->str;
151 ar->linedefined = tfvalue(protovalue(func))->lineDefined; 151 ar->linedefined = tfvalue(protovalue(func))->lineDefined;
152 ar->what = "Lua"; 152 ar->what = "Lua";
diff --git a/ldo.c b/ldo.c
index be7a4266..cde94514 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.67 2000/02/08 16:34:31 roberto Exp roberto $ 2** $Id: ldo.c,v 1.68 2000/03/03 14:58:26 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*/
@@ -86,7 +86,7 @@ void luaD_adjusttop (lua_State *L, StkId base, int extra) {
86 else { 86 else {
87 luaD_checkstack(L, diff); 87 luaD_checkstack(L, diff);
88 while (diff--) 88 while (diff--)
89 ttype(L->top++) = LUA_T_NIL; 89 ttype(L->top++) = TAG_NIL;
90 } 90 }
91} 91}
92 92
@@ -191,29 +191,29 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
191 lua_Dbghook callhook = L->callhook; 191 lua_Dbghook callhook = L->callhook;
192 retry: /* for `function' tag method */ 192 retry: /* for `function' tag method */
193 switch (ttype(func)) { 193 switch (ttype(func)) {
194 case LUA_T_CPROTO: 194 case TAG_CPROTO:
195 ttype(func) = LUA_T_CMARK; 195 ttype(func) = TAG_CMARK;
196 firstResult = callC(L, fvalue(func), func+1); 196 firstResult = callC(L, fvalue(func), func+1);
197 break; 197 break;
198 case LUA_T_LPROTO: 198 case TAG_LPROTO:
199 ttype(func) = LUA_T_LMARK; 199 ttype(func) = TAG_LMARK;
200 firstResult = luaV_execute(L, NULL, tfvalue(func), func+1); 200 firstResult = luaV_execute(L, NULL, tfvalue(func), func+1);
201 break; 201 break;
202 case LUA_T_LCLOSURE: { 202 case TAG_LCLOSURE: {
203 Closure *c = clvalue(func); 203 Closure *c = clvalue(func);
204 ttype(func) = LUA_T_LCLMARK; 204 ttype(func) = TAG_LCLMARK;
205 firstResult = luaV_execute(L, c, tfvalue(c->consts), func+1); 205 firstResult = luaV_execute(L, c, tfvalue(c->consts), func+1);
206 break; 206 break;
207 } 207 }
208 case LUA_T_CCLOSURE: { 208 case TAG_CCLOSURE: {
209 Closure *c = clvalue(func); 209 Closure *c = clvalue(func);
210 ttype(func) = LUA_T_CCLMARK; 210 ttype(func) = TAG_CCLMARK;
211 firstResult = callCclosure(L, c, func+1); 211 firstResult = callCclosure(L, c, func+1);
212 break; 212 break;
213 } 213 }
214 default: { /* `func' is not a function; check the `function' tag method */ 214 default: { /* `func' is not a function; check the `function' tag method */
215 const TObject *im = luaT_getimbyObj(L, func, IM_FUNCTION); 215 const TObject *im = luaT_getimbyObj(L, func, IM_FUNCTION);
216 if (ttype(im) == LUA_T_NIL) 216 if (ttype(im) == TAG_NIL)
217 luaG_callerror(L, func); 217 luaG_callerror(L, func);
218 luaD_openstack(L, func); 218 luaD_openstack(L, func);
219 *func = *im; /* tag method is the new function to be called */ 219 *func = *im; /* tag method is the new function to be called */
@@ -298,7 +298,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
298 StkId base = L->Cstack.base; 298 StkId base = L->Cstack.base;
299 int numCblocks = L->numCblocks; 299 int numCblocks = L->numCblocks;
300 int status; 300 int status;
301 TProtoFunc *volatile tf; 301 Proto *volatile tf;
302 struct lua_longjmp *volatile oldErr = L->errorJmp; 302 struct lua_longjmp *volatile oldErr = L->errorJmp;
303 L->errorJmp = &myErrorJmp; 303 L->errorJmp = &myErrorJmp;
304 L->top = base; /* clear C2Lua */ 304 L->top = base; /* clear C2Lua */
@@ -316,7 +316,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
316 L->errorJmp = oldErr; 316 L->errorJmp = oldErr;
317 if (status) return 1; /* error code */ 317 if (status) return 1; /* error code */
318 if (tf == NULL) return 2; /* `natural' end */ 318 if (tf == NULL) return 2; /* `natural' end */
319 L->top->ttype = LUA_T_LPROTO; /* push new function on the stack */ 319 L->top->ttype = TAG_LPROTO; /* push new function on the stack */
320 L->top->value.tf = tf; 320 L->top->value.tf = tf;
321 incr_top; 321 incr_top;
322 return 0; 322 return 0;
@@ -345,7 +345,7 @@ static int do_main (lua_State *L, ZIO *z, int bin) {
345 345
346void luaD_gcIM (lua_State *L, const TObject *o) { 346void luaD_gcIM (lua_State *L, const TObject *o) {
347 const TObject *im = luaT_getimbyObj(L, o, IM_GC); 347 const TObject *im = luaT_getimbyObj(L, o, IM_GC);
348 if (ttype(im) != LUA_T_NIL) { 348 if (ttype(im) != TAG_NIL) {
349 luaD_checkstack(L, 2); 349 luaD_checkstack(L, 2);
350 *(L->top++) = *im; 350 *(L->top++) = *im;
351 *(L->top++) = *o; 351 *(L->top++) = *o;
diff --git a/lfunc.c b/lfunc.c
index fad91ace..18ca5ca2 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 1.18 2000/01/28 16:53:00 roberto Exp roberto $ 2** $Id: lfunc.c,v 1.19 2000/03/03 14:58:26 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*/
@@ -13,7 +13,7 @@
13#include "lmem.h" 13#include "lmem.h"
14#include "lstate.h" 14#include "lstate.h"
15 15
16#define gcsizeproto(L, p) numblocks(L, 0, sizeof(TProtoFunc)) 16#define gcsizeproto(L, p) numblocks(L, 0, sizeof(Proto))
17#define gcsizeclosure(L, c) numblocks(L, c->nelems, sizeof(Closure)) 17#define gcsizeclosure(L, c) numblocks(L, c->nelems, sizeof(Closure))
18 18
19 19
@@ -29,8 +29,8 @@ Closure *luaF_newclosure (lua_State *L, int nelems) {
29} 29}
30 30
31 31
32TProtoFunc *luaF_newproto (lua_State *L) { 32Proto *luaF_newproto (lua_State *L) {
33 TProtoFunc *f = luaM_new(L, TProtoFunc); 33 Proto *f = luaM_new(L, Proto);
34 f->code = NULL; 34 f->code = NULL;
35 f->lineDefined = 0; 35 f->lineDefined = 0;
36 f->source = NULL; 36 f->source = NULL;
@@ -49,7 +49,7 @@ TProtoFunc *luaF_newproto (lua_State *L) {
49} 49}
50 50
51 51
52void luaF_freeproto (lua_State *L, TProtoFunc *f) { 52void luaF_freeproto (lua_State *L, Proto *f) {
53 L->nblocks -= gcsizeproto(L, f); 53 L->nblocks -= gcsizeproto(L, f);
54 luaM_free(L, f->code); 54 luaM_free(L, f->code);
55 luaM_free(L, f->locvars); 55 luaM_free(L, f->locvars);
@@ -70,7 +70,7 @@ void luaF_freeclosure (lua_State *L, Closure *c) {
70** Look for n-th local variable at line `line' in function `func'. 70** Look for n-th local variable at line `line' in function `func'.
71** Returns NULL if not found. 71** Returns NULL if not found.
72*/ 72*/
73const char *luaF_getlocalname (const TProtoFunc *func, 73const char *luaF_getlocalname (const Proto *func,
74 int local_number, int line) { 74 int local_number, int line) {
75 int count = 0; 75 int count = 0;
76 const char *varname = NULL; 76 const char *varname = NULL;
diff --git a/lfunc.h b/lfunc.h
index 9b862b14..a0dc7817 100644
--- a/lfunc.h
+++ b/lfunc.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.h,v 1.9 1999/11/22 13:12:07 roberto Exp roberto $ 2** $Id: lfunc.h,v 1.10 1999/12/27 17:33:22 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*/
@@ -12,12 +12,12 @@
12 12
13 13
14 14
15TProtoFunc *luaF_newproto (lua_State *L); 15Proto *luaF_newproto (lua_State *L);
16Closure *luaF_newclosure (lua_State *L, int nelems); 16Closure *luaF_newclosure (lua_State *L, int nelems);
17void luaF_freeproto (lua_State *L, TProtoFunc *f); 17void luaF_freeproto (lua_State *L, Proto *f);
18void luaF_freeclosure (lua_State *L, Closure *c); 18void luaF_freeclosure (lua_State *L, Closure *c);
19 19
20const char *luaF_getlocalname (const TProtoFunc *func, 20const char *luaF_getlocalname (const Proto *func,
21 int local_number, int line); 21 int local_number, int line);
22 22
23 23
diff --git a/lgc.c b/lgc.c
index 4fbe7230..87aa7d25 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.40 2000/01/25 13:57:18 roberto Exp roberto $ 2** $Id: lgc.c,v 1.41 2000/01/28 16:53:00 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -28,7 +28,7 @@ static int markobject (lua_State *L, TObject *o);
28 28
29 29
30 30
31static void protomark (lua_State *L, TProtoFunc *f) { 31static void protomark (lua_State *L, Proto *f) {
32 if (!f->marked) { 32 if (!f->marked) {
33 int i; 33 int i;
34 f->marked = 1; 34 f->marked = 1;
@@ -57,7 +57,7 @@ static void hashmark (lua_State *L, Hash *h) {
57 h->marked = 1; 57 h->marked = 1;
58 for (i=h->size-1; i>=0; i--) { 58 for (i=h->size-1; i>=0; i--) {
59 Node *n = node(h,i); 59 Node *n = node(h,i);
60 if (ttype(key(n)) != LUA_T_NIL) { 60 if (ttype(key(n)) != TAG_NIL) {
61 markobject(L, &n->key); 61 markobject(L, &n->key);
62 markobject(L, &n->val); 62 markobject(L, &n->val);
63 } 63 }
@@ -70,7 +70,7 @@ static void travglobal (lua_State *L) {
70 GlobalVar *gv; 70 GlobalVar *gv;
71 for (gv=L->rootglobal; gv; gv=gv->next) { 71 for (gv=L->rootglobal; gv; gv=gv->next) {
72 LUA_ASSERT(L, gv->name->u.s.gv == gv, "inconsistent global name"); 72 LUA_ASSERT(L, gv->name->u.s.gv == gv, "inconsistent global name");
73 if (gv->value.ttype != LUA_T_NIL) { 73 if (gv->value.ttype != TAG_NIL) {
74 strmark(L, gv->name); /* cannot collect non nil global variables */ 74 strmark(L, gv->name); /* cannot collect non nil global variables */
75 markobject(L, &gv->value); 75 markobject(L, &gv->value);
76 } 76 }
@@ -96,17 +96,17 @@ static void travlock (lua_State *L) {
96 96
97static int markobject (lua_State *L, TObject *o) { 97static int markobject (lua_State *L, TObject *o) {
98 switch (ttype(o)) { 98 switch (ttype(o)) {
99 case LUA_T_USERDATA: case LUA_T_STRING: 99 case TAG_USERDATA: case TAG_STRING:
100 strmark(L, tsvalue(o)); 100 strmark(L, tsvalue(o));
101 break; 101 break;
102 case LUA_T_ARRAY: 102 case TAG_ARRAY:
103 hashmark(L, avalue(o)); 103 hashmark(L, avalue(o));
104 break; 104 break;
105 case LUA_T_LCLOSURE: case LUA_T_LCLMARK: 105 case TAG_LCLOSURE: case TAG_LCLMARK:
106 case LUA_T_CCLOSURE: case LUA_T_CCLMARK: 106 case TAG_CCLOSURE: case TAG_CCLMARK:
107 closuremark(L, o->value.cl); 107 closuremark(L, o->value.cl);
108 break; 108 break;
109 case LUA_T_LPROTO: case LUA_T_LMARK: 109 case TAG_LPROTO: case TAG_LMARK:
110 protomark(L, o->value.tf); 110 protomark(L, o->value.tf);
111 break; 111 break;
112 default: break; /* numbers, cprotos, etc */ 112 default: break; /* numbers, cprotos, etc */
@@ -116,8 +116,8 @@ static int markobject (lua_State *L, TObject *o) {
116 116
117 117
118static void collectproto (lua_State *L) { 118static void collectproto (lua_State *L) {
119 TProtoFunc **p = &L->rootproto; 119 Proto **p = &L->rootproto;
120 TProtoFunc *next; 120 Proto *next;
121 while ((next = *p) != NULL) { 121 while ((next = *p) != NULL) {
122 if (next->marked) { 122 if (next->marked) {
123 next->marked = 0; 123 next->marked = 0;
@@ -185,14 +185,14 @@ static void clear_global_list (lua_State *L, int limit) {
185static void collectstring (lua_State *L, int limit) { 185static void collectstring (lua_State *L, int limit) {
186 TObject o; /* to call userdata `gc' tag method */ 186 TObject o; /* to call userdata `gc' tag method */
187 int i; 187 int i;
188 ttype(&o) = LUA_T_USERDATA; 188 ttype(&o) = TAG_USERDATA;
189 clear_global_list(L, limit); 189 clear_global_list(L, limit);
190 for (i=0; i<NUM_HASHS; i++) { /* for each hash table */ 190 for (i=0; i<NUM_HASHS; i++) { /* for each hash table */
191 stringtable *tb = &L->string_root[i]; 191 stringtable *tb = &L->string_root[i];
192 int j; 192 int j;
193 for (j=0; j<tb->size; j++) { /* for each list */ 193 for (j=0; j<tb->size; j++) { /* for each list */
194 TaggedString **p = &tb->hash[j]; 194 TString **p = &tb->hash[j];
195 TaggedString *next; 195 TString *next;
196 while ((next = *p) != NULL) { 196 while ((next = *p) != NULL) {
197 if (next->marked >= limit) { 197 if (next->marked >= limit) {
198 if (next->marked < FIXMARK) /* does not change FIXMARKs */ 198 if (next->marked < FIXMARK) /* does not change FIXMARKs */
@@ -220,7 +220,7 @@ static void collectstring (lua_State *L, int limit) {
220static void tableTM (lua_State *L) { 220static void tableTM (lua_State *L) {
221 Hash *p; 221 Hash *p;
222 TObject o; 222 TObject o;
223 ttype(&o) = LUA_T_ARRAY; 223 ttype(&o) = TAG_ARRAY;
224 for (p = L->roottable; p; p = p->next) { 224 for (p = L->roottable; p; p = p->next) {
225 if (!p->marked) { 225 if (!p->marked) {
226 avalue(&o) = p; 226 avalue(&o) = p;
diff --git a/llex.c b/llex.c
index 6745fbbc..a3d2cab3 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 1.51 2000/02/08 16:34:31 roberto Exp roberto $ 2** $Id: llex.c,v 1.52 2000/03/03 14:58:26 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -39,7 +39,7 @@ static const char *const token2string [] = {"and", "do", "else", "elseif", "end"
39void luaX_init (lua_State *L) { 39void luaX_init (lua_State *L) {
40 int i; 40 int i;
41 for (i=0; i<NUM_RESERVED; i++) { 41 for (i=0; i<NUM_RESERVED; i++) {
42 TaggedString *ts = luaS_new(L, token2string[i]); 42 TString *ts = luaS_new(L, token2string[i]);
43 ts->marked = (unsigned char)(RESERVEDMARK+i); /* reserved word */ 43 ts->marked = (unsigned char)(RESERVEDMARK+i); /* reserved word */
44 } 44 }
45} 45}
@@ -160,7 +160,7 @@ static void ifskip (lua_State *L, LexState *LS) {
160 if (LS->current == '\n') 160 if (LS->current == '\n')
161 inclinenumber(L, LS); 161 inclinenumber(L, LS);
162 else if (LS->current == EOZ) 162 else if (LS->current == EOZ)
163 luaX_error(LS, "input ends inside a $if", EOS); 163 luaX_error(LS, "input ends inside a $if", TK_EOS);
164 else next(LS); 164 else next(LS);
165 } 165 }
166} 166}
@@ -240,7 +240,7 @@ static void read_long_string (lua_State *L, LexState *LS) {
240 for (;;) { 240 for (;;) {
241 switch (LS->current) { 241 switch (LS->current) {
242 case EOZ: 242 case EOZ:
243 luaX_error(LS, "unfinished long string", STRING); 243 luaX_error(LS, "unfinished long string", TK_STRING);
244 break; /* to avoid warnings */ 244 break; /* to avoid warnings */
245 case '[': 245 case '[':
246 save_and_next(L, LS); 246 save_and_next(L, LS);
@@ -276,7 +276,7 @@ static void read_string (lua_State *L, LexState *LS, int del) {
276 while (LS->current != del) { 276 while (LS->current != del) {
277 switch (LS->current) { 277 switch (LS->current) {
278 case EOZ: case '\n': 278 case EOZ: case '\n':
279 luaX_error(LS, "unfinished string", STRING); 279 luaX_error(LS, "unfinished string", TK_STRING);
280 break; /* to avoid warnings */ 280 break; /* to avoid warnings */
281 case '\\': 281 case '\\':
282 next(LS); /* do not save the '\' */ 282 next(LS); /* do not save the '\' */
@@ -298,7 +298,7 @@ static void read_string (lua_State *L, LexState *LS, int del) {
298 next(LS); 298 next(LS);
299 } while (++i<3 && isdigit(LS->current)); 299 } while (++i<3 && isdigit(LS->current));
300 if (c != (unsigned char)c) 300 if (c != (unsigned char)c)
301 luaX_error(LS, "escape sequence too large", STRING); 301 luaX_error(LS, "escape sequence too large", TK_STRING);
302 save(L, c); 302 save(L, c);
303 break; 303 break;
304 } 304 }
@@ -343,34 +343,34 @@ int luaX_lex (LexState *LS) {
343 else { 343 else {
344 save_and_next(L, LS); /* pass the second '[' */ 344 save_and_next(L, LS); /* pass the second '[' */
345 read_long_string(L, LS); 345 read_long_string(L, LS);
346 return STRING; 346 return TK_STRING;
347 } 347 }
348 348
349 case '=': 349 case '=':
350 next(LS); 350 next(LS);
351 if (LS->current != '=') return '='; 351 if (LS->current != '=') return '=';
352 else { next(LS); return EQ; } 352 else { next(LS); return TK_EQ; }
353 353
354 case '<': 354 case '<':
355 next(LS); 355 next(LS);
356 if (LS->current != '=') return '<'; 356 if (LS->current != '=') return '<';
357 else { next(LS); return LE; } 357 else { next(LS); return TK_LE; }
358 358
359 case '>': 359 case '>':
360 next(LS); 360 next(LS);
361 if (LS->current != '=') return '>'; 361 if (LS->current != '=') return '>';
362 else { next(LS); return GE; } 362 else { next(LS); return TK_GE; }
363 363
364 case '~': 364 case '~':
365 next(LS); 365 next(LS);
366 if (LS->current != '=') return '~'; 366 if (LS->current != '=') return '~';
367 else { next(LS); return NE; } 367 else { next(LS); return TK_NE; }
368 368
369 case '"': 369 case '"':
370 case '\'': 370 case '\'':
371 luaL_resetbuffer(L); 371 luaL_resetbuffer(L);
372 read_string(L, LS, LS->current); 372 read_string(L, LS, LS->current);
373 return STRING; 373 return TK_STRING;
374 374
375 case '.': 375 case '.':
376 luaL_resetbuffer(L); 376 luaL_resetbuffer(L);
@@ -379,9 +379,9 @@ int luaX_lex (LexState *LS) {
379 next(LS); 379 next(LS);
380 if (LS->current == '.') { 380 if (LS->current == '.') {
381 next(LS); 381 next(LS);
382 return DOTS; /* ... */ 382 return TK_DOTS; /* ... */
383 } 383 }
384 else return CONC; /* .. */ 384 else return TK_CONC; /* .. */
385 } 385 }
386 else if (!isdigit(LS->current)) return '.'; 386 else if (!isdigit(LS->current)) return '.';
387 else goto fraction; /* LS->current is a digit */ 387 else goto fraction; /* LS->current is a digit */
@@ -397,7 +397,7 @@ int luaX_lex (LexState *LS) {
397 if (LS->current == '.') { 397 if (LS->current == '.') {
398 save(L, '.'); 398 save(L, '.');
399 luaX_error(LS, "ambiguous syntax" 399 luaX_error(LS, "ambiguous syntax"
400 " (decimal point x string concatenation)", NUMBER); 400 " (decimal point x string concatenation)", TK_NUMBER);
401 } 401 }
402 } 402 }
403 fraction: /* LUA_NUMBER */ 403 fraction: /* LUA_NUMBER */
@@ -412,13 +412,13 @@ int luaX_lex (LexState *LS) {
412 } 412 }
413 save(L, '\0'); 413 save(L, '\0');
414 if (!luaO_str2d(L->Mbuffer+L->Mbuffbase, &LS->seminfo.r)) 414 if (!luaO_str2d(L->Mbuffer+L->Mbuffbase, &LS->seminfo.r))
415 luaX_error(LS, "malformed number", NUMBER); 415 luaX_error(LS, "malformed number", TK_NUMBER);
416 return NUMBER; 416 return TK_NUMBER;
417 417
418 case EOZ: 418 case EOZ:
419 if (LS->iflevel > 0) 419 if (LS->iflevel > 0)
420 luaX_error(LS, "input ends inside a $if", EOS); 420 luaX_error(LS, "input ends inside a $if", TK_EOS);
421 return EOS; 421 return TK_EOS;
422 422
423 case '_': goto tname; 423 case '_': goto tname;
424 424
@@ -431,7 +431,7 @@ int luaX_lex (LexState *LS) {
431 return c; 431 return c;
432 } 432 }
433 tname: { /* identifier or reserved word */ 433 tname: { /* identifier or reserved word */
434 TaggedString *ts; 434 TString *ts;
435 luaL_resetbuffer(L); 435 luaL_resetbuffer(L);
436 do { 436 do {
437 save_and_next(L, LS); 437 save_and_next(L, LS);
@@ -441,7 +441,7 @@ int luaX_lex (LexState *LS) {
441 if (ts->marked >= RESERVEDMARK) /* reserved word? */ 441 if (ts->marked >= RESERVEDMARK) /* reserved word? */
442 return ts->marked-RESERVEDMARK+FIRST_RESERVED; 442 return ts->marked-RESERVEDMARK+FIRST_RESERVED;
443 LS->seminfo.ts = ts; 443 LS->seminfo.ts = ts;
444 return NAME; 444 return TK_NAME;
445 } 445 }
446 } 446 }
447 } 447 }
diff --git a/llex.h b/llex.h
index 93097010..26ab95dd 100644
--- a/llex.h
+++ b/llex.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.h,v 1.18 2000/02/08 16:34:31 roberto Exp roberto $ 2** $Id: llex.h,v 1.19 2000/03/03 14:58:26 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -23,15 +23,16 @@
23*/ 23*/
24enum RESERVED { 24enum RESERVED {
25 /* terminal symbols denoted by reserved words */ 25 /* terminal symbols denoted by reserved words */
26 AND = FIRST_RESERVED, 26 TK_AND = FIRST_RESERVED,
27 DO, ELSE, ELSEIF, END, FUNCTION, IF, LOCAL, NIL, NOT, OR, 27 TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FUNCTION, TK_IF, TK_LOCAL,
28 REPEAT, RETURN, THEN, UNTIL, WHILE, 28 TK_NIL, TK_NOT, TK_OR, TK_REPEAT, TK_RETURN, TK_THEN, TK_UNTIL, TK_WHILE,
29 /* other terminal symbols */ 29 /* other terminal symbols */
30 NAME, CONC, DOTS, EQ, GE, LE, NE, NUMBER, STRING, EOS 30 TK_NAME, TK_CONC, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
31 TK_STRING, TK_EOS
31}; 32};
32 33
33/* number of reserved words */ 34/* number of reserved words */
34#define NUM_RESERVED ((int)(WHILE-FIRST_RESERVED+1)) 35#define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1))
35 36
36 37
37#ifndef MAX_IFS 38#ifndef MAX_IFS
@@ -53,8 +54,8 @@ typedef struct LexState {
53 struct FuncState *fs; /* `FuncState' is private to the parser */ 54 struct FuncState *fs; /* `FuncState' is private to the parser */
54 struct lua_State *L; 55 struct lua_State *L;
55 union { 56 union {
56 real r; 57 Number r;
57 TaggedString *ts; 58 TString *ts;
58 } seminfo; /* semantics information */ 59 } seminfo; /* semantics information */
59 struct zio *z; /* input stream */ 60 struct zio *z; /* input stream */
60 int linenumber; /* input line counter */ 61 int linenumber; /* input line counter */
diff --git a/lmathlib.c b/lmathlib.c
index ee53f52e..8ed5deae 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.22 1999/12/14 18:31:20 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.23 1999/12/27 17:33:22 roberto Exp roberto $
3** Standard mathematical library 3** Standard mathematical library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -147,7 +147,7 @@ static void math_random (lua_State *L) {
147 some systems (SunOS!) "rand()" may return a value larger than RAND_MAX */ 147 some systems (SunOS!) "rand()" may return a value larger than RAND_MAX */
148 double r = (double)(rand()%RAND_MAX) / (double)RAND_MAX; 148 double r = (double)(rand()%RAND_MAX) / (double)RAND_MAX;
149 if (lua_getparam(L, 1) == LUA_NOOBJECT) /* no arguments? */ 149 if (lua_getparam(L, 1) == LUA_NOOBJECT) /* no arguments? */
150 lua_pushnumber(L, r); /* real between 0 and 1 */ 150 lua_pushnumber(L, r); /* Number between 0 and 1 */
151 else { 151 else {
152 int l, u; /* lower & upper limits */ 152 int l, u; /* lower & upper limits */
153 if (lua_getparam(L, 2) == LUA_NOOBJECT) { /* only one argument? */ 153 if (lua_getparam(L, 2) == LUA_NOOBJECT) { /* only one argument? */
diff --git a/lmem.c b/lmem.c
index 24f56db1..00e45f6f 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.c,v 1.26 2000/03/03 14:58:26 roberto Exp roberto $ 2** $Id: lmem.c,v 1.27 2000/03/10 14:01:05 roberto Exp roberto $
3** Interface to Memory Manager 3** Interface to Memory Manager
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -16,7 +16,7 @@
16 16
17 17
18/* 18/*
19** real ANSI systems do not need these tests; 19** Number ANSI systems do not need these tests;
20** but some systems (Sun OS) are not that ANSI... 20** but some systems (Sun OS) are not that ANSI...
21*/ 21*/
22#ifdef OLD_ANSI 22#ifdef OLD_ANSI
diff --git a/lobject.c b/lobject.c
index 617815d8..1fdb7c80 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.31 2000/02/17 18:30:36 roberto Exp roberto $ 2** $Id: lobject.c,v 1.32 2000/03/03 14:58:26 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -20,7 +20,7 @@ const char *const luaO_typenames[] = { /* ORDER LUA_T */
20}; 20};
21 21
22 22
23const TObject luaO_nilobject = {LUA_T_NIL, {NULL}}; 23const TObject luaO_nilobject = {TAG_NIL, {NULL}};
24 24
25 25
26/* 26/*
@@ -35,19 +35,19 @@ unsigned long luaO_power2 (unsigned long n) {
35 35
36int luaO_equalval (const TObject *t1, const TObject *t2) { 36int luaO_equalval (const TObject *t1, const TObject *t2) {
37 switch (ttype(t1)) { 37 switch (ttype(t1)) {
38 case LUA_T_NIL: 38 case TAG_NIL:
39 return 1; 39 return 1;
40 case LUA_T_NUMBER: 40 case TAG_NUMBER:
41 return nvalue(t1) == nvalue(t2); 41 return nvalue(t1) == nvalue(t2);
42 case LUA_T_STRING: case LUA_T_USERDATA: 42 case TAG_STRING: case TAG_USERDATA:
43 return svalue(t1) == svalue(t2); 43 return svalue(t1) == svalue(t2);
44 case LUA_T_ARRAY: 44 case TAG_ARRAY:
45 return avalue(t1) == avalue(t2); 45 return avalue(t1) == avalue(t2);
46 case LUA_T_LPROTO: 46 case TAG_LPROTO:
47 return tfvalue(t1) == tfvalue(t2); 47 return tfvalue(t1) == tfvalue(t2);
48 case LUA_T_CPROTO: 48 case TAG_CPROTO:
49 return fvalue(t1) == fvalue(t2); 49 return fvalue(t1) == fvalue(t2);
50 case LUA_T_CCLOSURE: case LUA_T_LCLOSURE: 50 case TAG_CCLOSURE: case TAG_LCLOSURE:
51 return t1->value.cl == t2->value.cl; 51 return t1->value.cl == t2->value.cl;
52 default: 52 default:
53 LUA_INTERNALERROR(L, "invalid type"); 53 LUA_INTERNALERROR(L, "invalid type");
@@ -67,7 +67,7 @@ static double expten (unsigned int e) {
67} 67}
68 68
69 69
70int luaO_str2d (const char *s, real *result) { /* LUA_NUMBER */ 70int luaO_str2d (const char *s, Number *result) { /* LUA_NUMBER */
71 double a = 0.0; 71 double a = 0.0;
72 int point = 0; /* number of decimal digits */ 72 int point = 0; /* number of decimal digits */
73 int sig; 73 int sig;
diff --git a/lobject.h b/lobject.h
index 20368bdf..685124f9 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.49 2000/02/21 18:33:26 roberto Exp roberto $ 2** $Id: lobject.h,v 1.50 2000/03/03 14:58:26 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*/
@@ -27,14 +27,14 @@
27#define UNUSED(x) (void)x /* to avoid warnings */ 27#define UNUSED(x) (void)x /* to avoid warnings */
28 28
29/* 29/*
30** "real" is the type "number" of Lua 30** Define the type `number' of Lua
31** GREP LUA_NUMBER to change that 31** GREP LUA_NUMBER to change that
32*/ 32*/
33#ifndef LUA_NUM_TYPE 33#ifndef LUA_NUM_TYPE
34#define LUA_NUM_TYPE double 34#define LUA_NUM_TYPE double
35#endif 35#endif
36 36
37typedef LUA_NUM_TYPE real; 37typedef LUA_NUM_TYPE Number;
38 38
39 39
40/* 40/*
@@ -66,45 +66,45 @@ typedef unsigned long Instruction;
66** grep "ORDER LUA_T" 66** grep "ORDER LUA_T"
67*/ 67*/
68typedef enum { 68typedef enum {
69 LUA_T_USERDATA = 0, /* default tag for userdata */ 69 TAG_USERDATA = 0, /* default tag for userdata */
70 LUA_T_NUMBER = -1, /* fixed tag for numbers */ 70 TAG_NUMBER = -1, /* fixed tag for numbers */
71 LUA_T_STRING = -2, /* fixed tag for strings */ 71 TAG_STRING = -2, /* fixed tag for strings */
72 LUA_T_ARRAY = -3, /* default tag for tables (or arrays) */ 72 TAG_ARRAY = -3, /* default tag for tables (or arrays) */
73 LUA_T_LPROTO = -4, /* fixed tag for Lua functions */ 73 TAG_LPROTO = -4, /* fixed tag for Lua functions */
74 LUA_T_CPROTO = -5, /* fixed tag for C functions */ 74 TAG_CPROTO = -5, /* fixed tag for C functions */
75 LUA_T_NIL = -6, /* last "pre-defined" tag */ 75 TAG_NIL = -6, /* last "pre-defined" tag */
76 76
77 LUA_T_LCLOSURE = -7, /* Lua closure */ 77 TAG_LCLOSURE = -7, /* Lua closure */
78 LUA_T_CCLOSURE = -8, /* C closure */ 78 TAG_CCLOSURE = -8, /* C closure */
79 79
80 LUA_T_LCLMARK = -9 ,/* mark for Lua closures */ 80 TAG_LCLMARK = -9 ,/* mark for Lua closures */
81 LUA_T_CCLMARK = -10,/* mark for C closures */ 81 TAG_CCLMARK = -10,/* mark for C closures */
82 LUA_T_LMARK = -11,/* mark for Lua prototypes */ 82 TAG_LMARK = -11,/* mark for Lua prototypes */
83 LUA_T_CMARK = -12,/* mark for C prototypes */ 83 TAG_CMARK = -12,/* mark for C prototypes */
84 84
85 LUA_T_LINE = -13 85 TAG_LINE = -13
86} lua_Type; 86} lua_Type;
87 87
88#define NUM_TAGS 7 /* tags for values visible from Lua */ 88#define NUM_TAGS 7 /* tags for values visible from Lua */
89 89
90 90
91#define LAST_REGULAR_TAG LUA_T_CCLOSURE /* after that, are all marks */ 91#define LAST_REGULAR_TAG TAG_CCLOSURE /* after that, are all marks */
92 92
93/* 93/*
94** check whether `t' is a mark; ttypes are negative numbers, so the 94** check whether `t' is a mark; ttypes are negative numbers, so the
95** comparisons look reversed. (ORDER LUA_T) 95** comparisons look reversed. (ORDER LUA_T)
96*/ 96*/
97#define is_T_MARK(t) (LUA_T_CMARK <= (t) && (t) <= LUA_T_LCLMARK) 97#define is_T_MARK(t) (TAG_CMARK <= (t) && (t) <= TAG_LCLMARK)
98 98
99 99
100typedef union { 100typedef union {
101 lua_CFunction f; /* LUA_T_CPROTO, LUA_T_CMARK */ 101 lua_CFunction f; /* TAG_CPROTO, TAG_CMARK */
102 real n; /* LUA_T_NUMBER */ 102 Number n; /* TAG_NUMBER */
103 struct TaggedString *ts; /* LUA_T_STRING, LUA_T_USERDATA */ 103 struct TString *ts; /* TAG_STRING, TAG_USERDATA */
104 struct TProtoFunc *tf; /* LUA_T_LPROTO, LUA_T_LMARK */ 104 struct Proto *tf; /* TAG_LPROTO, TAG_LMARK */
105 struct Closure *cl; /* LUA_T_[CL]CLOSURE, LUA_T_[CL]CLMARK */ 105 struct Closure *cl; /* TAG_[CL]CLOSURE, TAG_[CL]CLMARK */
106 struct Hash *a; /* LUA_T_ARRAY */ 106 struct Hash *a; /* TAG_ARRAY */
107 int i; /* LUA_T_LINE */ 107 int i; /* TAG_LINE */
108} Value; 108} Value;
109 109
110 110
@@ -118,14 +118,14 @@ typedef struct TObject {
118typedef struct GlobalVar { 118typedef struct GlobalVar {
119 TObject value; 119 TObject value;
120 struct GlobalVar *next; 120 struct GlobalVar *next;
121 struct TaggedString *name; 121 struct TString *name;
122} GlobalVar; 122} GlobalVar;
123 123
124 124
125/* 125/*
126** String headers for string table 126** String headers for string table
127*/ 127*/
128typedef struct TaggedString { 128typedef struct TString {
129 union { 129 union {
130 struct { /* for strings */ 130 struct { /* for strings */
131 GlobalVar *gv; /* eventual global value with this name */ 131 GlobalVar *gv; /* eventual global value with this name */
@@ -136,12 +136,12 @@ typedef struct TaggedString {
136 void *value; 136 void *value;
137 } d; 137 } d;
138 } u; 138 } u;
139 struct TaggedString *nexthash; /* chain for hash table */ 139 struct TString *nexthash; /* chain for hash table */
140 unsigned long hash; 140 unsigned long hash;
141 int constindex; /* hint to reuse constants (= -1 if this is a userdata) */ 141 int constindex; /* hint to reuse constants (= -1 if this is a userdata) */
142 unsigned char marked; 142 unsigned char marked;
143 char str[1]; /* \0 byte already reserved */ 143 char str[1]; /* \0 byte already reserved */
144} TaggedString; 144} TString;
145 145
146 146
147 147
@@ -149,27 +149,27 @@ typedef struct TaggedString {
149/* 149/*
150** Function Prototypes 150** Function Prototypes
151*/ 151*/
152typedef struct TProtoFunc { 152typedef struct Proto {
153 struct TProtoFunc *next; 153 struct Proto *next;
154 int marked; 154 int marked;
155 struct TaggedString **kstr; /* strings used by the function */ 155 struct TString **kstr; /* strings used by the function */
156 int nkstr; /* size of `kstr' */ 156 int nkstr; /* size of `kstr' */
157 real *knum; /* real numbers used by the function */ 157 Number *knum; /* Number numbers used by the function */
158 int nknum; /* size of `knum' */ 158 int nknum; /* size of `knum' */
159 struct TProtoFunc **kproto; /* functions defined inside the function */ 159 struct Proto **kproto; /* functions defined inside the function */
160 int nkproto; /* size of `kproto' */ 160 int nkproto; /* size of `kproto' */
161 Instruction *code; /* ends with opcode ENDCODE */ 161 Instruction *code; /* ends with opcode ENDCODE */
162 int lineDefined; 162 int lineDefined;
163 TaggedString *source; 163 TString *source;
164 int numparams; 164 int numparams;
165 int is_vararg; 165 int is_vararg;
166 int maxstacksize; 166 int maxstacksize;
167 struct LocVar *locvars; /* ends with line = -1 */ 167 struct LocVar *locvars; /* ends with line = -1 */
168} TProtoFunc; 168} Proto;
169 169
170 170
171typedef struct LocVar { 171typedef struct LocVar {
172 TaggedString *varname; /* NULL signals end of scope */ 172 TString *varname; /* NULL signals end of scope */
173 int line; 173 int line;
174} LocVar; 174} LocVar;
175 175
@@ -202,10 +202,10 @@ typedef struct Closure {
202 202
203 203
204 204
205typedef struct node { 205typedef struct Node {
206 TObject key; 206 TObject key;
207 TObject val; 207 TObject val;
208 struct node *next; /* for chaining */ 208 struct Node *next; /* for chaining */
209} Node; 209} Node;
210 210
211typedef struct Hash { 211typedef struct Hash {
@@ -230,7 +230,7 @@ unsigned long luaO_power2 (unsigned long n);
230#define luaO_equalObj(t1,t2) (ttype(t1) == ttype(t2) && luaO_equalval(t1,t2)) 230#define luaO_equalObj(t1,t2) (ttype(t1) == ttype(t2) && luaO_equalval(t1,t2))
231int luaO_equalval (const TObject *t1, const TObject *t2); 231int luaO_equalval (const TObject *t1, const TObject *t2);
232int luaO_redimension (lua_State *L, int oldsize); 232int luaO_redimension (lua_State *L, int oldsize);
233int luaO_str2d (const char *s, real *result); 233int luaO_str2d (const char *s, Number *result);
234 234
235 235
236#endif 236#endif
diff --git a/lopcodes.h b/lopcodes.h
index cd19ff3d..a155956d 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.44 2000/03/03 18:53:17 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.47 2000/03/09 13:57:37 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*/
@@ -20,7 +20,7 @@
20 type 3: 1st unsigned argument in the higher 16 bits (`A') 20 type 3: 1st unsigned argument in the higher 16 bits (`A')
21 2nd unsigned argument in the middle 8 bits (`B') 21 2nd unsigned argument in the middle 8 bits (`B')
22 22
23 The signed argument is represented in excess 2^23; that is, the real value 23 The signed argument is represented in excess 2^23; that is, the Number value
24 is the usigned value minus 2^23. 24 is the usigned value minus 2^23.
25===========================================================================*/ 25===========================================================================*/
26 26
@@ -88,73 +88,73 @@ typedef enum {
88/*---------------------------------------------------------------------- 88/*----------------------------------------------------------------------
89name args stack before stack after side effects 89name args stack before stack after side effects
90------------------------------------------------------------------------*/ 90------------------------------------------------------------------------*/
91ENDCODE,/* - - (return) */ 91OP_END,/* - - (return) */
92RETCODE,/* U - (return) */ 92OP_RETURN,/* U - (return) */
93 93
94CALL,/* A B v_n-v_1 f(at a) r_b-r_1 f(v1,...,v_n) */ 94OP_CALL,/* A B v_n-v_1 f(at a) r_b-r_1 f(v1,...,v_n) */
95TAILCALL,/* A B v_a-v_1 f (return) f(v1,...,v_a) */ 95OP_TAILCALL,/* A B v_a-v_1 f (return) f(v1,...,v_a) */
96 96
97PUSHNIL,/* U - nil_1-nil_u */ 97OP_PUSHNIL,/* U - nil_1-nil_u */
98POP,/* U a_u-a_1 - */ 98OP_POP,/* U a_u-a_1 - */
99 99
100PUSHINT,/* S - (real)s */ 100OP_PUSHINT,/* S - (Number)s */
101PUSHSTRING,/* K - KSTR[k] */ 101OP_PUSHSTRING,/* K - KSTR[k] */
102PUSHNUM,/* N - KNUM[u] */ 102OP_PUSHNUM,/* N - KNUM[u] */
103PUSHNEGNUM,/* N - -KNUM[u] */ 103OP_PUSHNEGNUM,/* N - -KNUM[u] */
104 104
105PUSHUPVALUE,/* U - Closure[u] */ 105OP_PUSHUPVALUE,/* U - Closure[u] */
106 106
107PUSHLOCAL,/* L - LOC[u] */ 107OP_PUSHLOCAL,/* L - LOC[u] */
108GETGLOBAL,/* K - VAR[KSTR[k]] */ 108OP_GETGLOBAL,/* K - VAR[KSTR[k]] */
109 109
110GETTABLE,/* - i t t[i] */ 110OP_GETTABLE,/* - i t t[i] */
111GETDOTTED,/* K t t[KSTR[k]] */ 111OP_GETDOTTED,/* K t t[KSTR[k]] */
112PUSHSELF,/* K t t t[KSTR[k]] */ 112OP_PUSHSELF,/* K t t t[KSTR[k]] */
113 113
114CREATETABLE,/* U - newarray(size = u) */ 114OP_CREATETABLE,/* U - newarray(size = u) */
115 115
116SETLOCAL,/* L x - LOC[u]=x */ 116OP_SETLOCAL,/* L x - LOC[u]=x */
117SETGLOBAL,/* K x - VAR[KSTR[k]]=x */ 117OP_SETGLOBAL,/* K x - VAR[KSTR[k]]=x */
118SETTABLEPOP,/* - v i t - t[i]=v */ 118OP_SETTABLEPOP,/* - v i t - t[i]=v */
119SETTABLE,/* U v a_u-a_1 i t a_u-a_1 i t t[i]=v */ 119OP_SETTABLE,/* U v a_u-a_1 i t a_u-a_1 i t t[i]=v */
120 120
121SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */ 121OP_SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */
122SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */ 122OP_SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */
123 123
124ADDOP,/* - y x x+y */ 124OP_ADD,/* - y x x+y */
125ADDI,/* S x x+s */ 125OP_ADDI,/* S x x+s */
126SUBOP,/* - y x x-y */ 126OP_SUB,/* - y x x-y */
127MULTOP,/* - y x x*y */ 127OP_MULT,/* - y x x*y */
128DIVOP,/* - y x x/y */ 128OP_DIV,/* - y x x/y */
129POWOP,/* - y x x^y */ 129OP_POW,/* - y x x^y */
130CONCOP,/* U v_u-v_1 v1..-..v_u */ 130OP_CONC,/* U v_u-v_1 v1..-..v_u */
131MINUSOP,/* - x -x */ 131OP_MINUS,/* - x -x */
132NOTOP,/* - x (x==nil)? 1 : nil */ 132OP_NOT,/* - x (x==nil)? 1 : nil */
133 133
134IFNEQJMP,/* J y x - (x~=y)? PC+=s */ 134OP_IFNEQJMP,/* J y x - (x~=y)? PC+=s */
135IFEQJMP,/* J y x - (x==y)? PC+=s */ 135OP_IFEQJMP,/* J y x - (x==y)? PC+=s */
136IFLTJMP,/* J y x - (x<y)? PC+=s */ 136OP_IFLTJMP,/* J y x - (x<y)? PC+=s */
137IFLEJMP,/* J y x - (x<y)? PC+=s */ 137OP_IFLEJMP,/* J y x - (x<y)? PC+=s */
138IFGTJMP,/* J y x - (x>y)? PC+=s */ 138OP_IFGTJMP,/* J y x - (x>y)? PC+=s */
139IFGEJMP,/* J y x - (x>=y)? PC+=s */ 139OP_IFGEJMP,/* J y x - (x>=y)? PC+=s */
140 140
141IFTJMP,/* J x - (x!=nil)? PC+=s */ 141OP_IFTJMP,/* J x - (x!=nil)? PC+=s */
142IFFJMP,/* J x - (x==nil)? PC+=s */ 142OP_IFFJMP,/* J x - (x==nil)? PC+=s */
143ONTJMP,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */ 143OP_ONTJMP,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */
144ONFJMP,/* J x (x==nil)? x : - (x==nil)? PC+=s */ 144OP_ONFJMP,/* J x (x==nil)? x : - (x==nil)? PC+=s */
145JMP,/* J - - PC+=s */ 145OP_JMP,/* J - - PC+=s */
146 146
147PUSHNILJMP,/* - - nil PC++; */ 147OP_PUSHNILJMP,/* - - nil PC++; */
148 148
149CLOSURE,/* A B v_b-v_1 closure(CNST[a], v_1-v_b) */ 149OP_CLOSURE,/* A B v_b-v_1 closure(CNST[a], v_1-v_b) */
150 150
151SETLINE/* U - - LINE=u */ 151OP_SETLINE/* U - - LINE=u */
152 152
153} OpCode; 153} OpCode;
154 154
155 155
156 156
157#define ISJUMP(o) (IFNEQJMP <= (o) && (o) <= JMP) 157#define ISJUMP(o) (OP_IFNEQJMP <= (o) && (o) <= OP_JMP)
158 158
159 159
160#define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */ 160#define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */
diff --git a/lparser.c b/lparser.c
index a8198190..c875f784 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.64 2000/03/03 20:29:25 roberto Exp roberto $ 2** $Id: lparser.c,v 1.67 2000/03/09 13:57:37 roberto Exp roberto $
3** LL(1) Parser and code generator for Lua 3** LL(1) Parser and code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -116,7 +116,7 @@ static void checklimit (LexState *ls, int val, int limit, const char *msg) {
116 116
117static void check_debugline (LexState *ls) { 117static void check_debugline (LexState *ls) {
118 if (ls->L->debug && ls->linenumber != ls->fs->lastsetline) { 118 if (ls->L->debug && ls->linenumber != ls->fs->lastsetline) {
119 luaK_U(ls, SETLINE, ls->linenumber, 0); 119 luaK_U(ls, OP_SETLINE, ls->linenumber, 0);
120 ls->fs->lastsetline = ls->linenumber; 120 ls->fs->lastsetline = ls->linenumber;
121 } 121 }
122} 122}
@@ -130,11 +130,11 @@ static void check_match (LexState *ls, int what, int who, int where) {
130} 130}
131 131
132 132
133static int string_constant (LexState *ls, FuncState *fs, TaggedString *s) { 133static int string_constant (LexState *ls, FuncState *fs, TString *s) {
134 TProtoFunc *f = fs->f; 134 Proto *f = fs->f;
135 int c = s->constindex; 135 int c = s->constindex;
136 if (c >= f->nkstr || f->kstr[c] != s) { 136 if (c >= f->nkstr || f->kstr[c] != s) {
137 luaM_growvector(ls->L, f->kstr, f->nkstr, 1, TaggedString *, 137 luaM_growvector(ls->L, f->kstr, f->nkstr, 1, TString *,
138 constantEM, MAXARG_U); 138 constantEM, MAXARG_U);
139 c = f->nkstr++; 139 c = f->nkstr++;
140 f->kstr[c] = s; 140 f->kstr[c] = s;
@@ -144,14 +144,14 @@ static int string_constant (LexState *ls, FuncState *fs, TaggedString *s) {
144} 144}
145 145
146 146
147static void code_string (LexState *ls, TaggedString *s) { 147static void code_string (LexState *ls, TString *s) {
148 luaK_kstr(ls, string_constant(ls, ls->fs, s)); 148 luaK_kstr(ls, string_constant(ls, ls->fs, s));
149} 149}
150 150
151 151
152static int checkname (LexState *ls) { 152static int checkname (LexState *ls) {
153 int sc; 153 int sc;
154 if (ls->token != NAME) 154 if (ls->token != TK_NAME)
155 luaK_error(ls, "<name> expected"); 155 luaK_error(ls, "<name> expected");
156 sc = string_constant(ls, ls->fs, ls->seminfo.ts); 156 sc = string_constant(ls, ls->fs, ls->seminfo.ts);
157 next(ls); 157 next(ls);
@@ -159,17 +159,17 @@ static int checkname (LexState *ls) {
159} 159}
160 160
161 161
162static TaggedString *str_checkname (LexState *ls) { 162static TString *str_checkname (LexState *ls) {
163 int i = checkname(ls); /* this call may realloc `f->consts' */ 163 int i = checkname(ls); /* this call may realloc `f->consts' */
164 return ls->fs->f->kstr[i]; 164 return ls->fs->f->kstr[i];
165} 165}
166 166
167 167
168static void luaI_registerlocalvar (LexState *ls, TaggedString *varname, 168static void luaI_registerlocalvar (LexState *ls, TString *varname,
169 int line) { 169 int line) {
170 FuncState *fs = ls->fs; 170 FuncState *fs = ls->fs;
171 if (fs->nvars != -1) { /* debug information? */ 171 if (fs->nvars != -1) { /* debug information? */
172 TProtoFunc *f = fs->f; 172 Proto *f = fs->f;
173 luaM_growvector(ls->L, f->locvars, fs->nvars, 1, LocVar, "", MAX_INT); 173 luaM_growvector(ls->L, f->locvars, fs->nvars, 1, LocVar, "", MAX_INT);
174 f->locvars[fs->nvars].varname = varname; 174 f->locvars[fs->nvars].varname = varname;
175 f->locvars[fs->nvars].line = line; 175 f->locvars[fs->nvars].line = line;
@@ -183,7 +183,7 @@ static void luaI_unregisterlocalvar (LexState *ls, int line) {
183} 183}
184 184
185 185
186static void store_localvar (LexState *ls, TaggedString *name, int n) { 186static void store_localvar (LexState *ls, TString *name, int n) {
187 FuncState *fs = ls->fs; 187 FuncState *fs = ls->fs;
188 checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables"); 188 checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables");
189 fs->localvar[fs->nlocalvar+n] = name; 189 fs->localvar[fs->nlocalvar+n] = name;
@@ -199,13 +199,13 @@ static void adjustlocalvars (LexState *ls, int nvars, int line) {
199} 199}
200 200
201 201
202static void add_localvar (LexState *ls, TaggedString *name) { 202static void add_localvar (LexState *ls, TString *name) {
203 store_localvar(ls, name, 0); 203 store_localvar(ls, name, 0);
204 adjustlocalvars(ls, 1, 0); 204 adjustlocalvars(ls, 1, 0);
205} 205}
206 206
207 207
208static int aux_localname (FuncState *fs, TaggedString *n) { 208static int aux_localname (FuncState *fs, TString *n) {
209 int i; 209 int i;
210 for (i=fs->nlocalvar-1; i >= 0; i--) 210 for (i=fs->nlocalvar-1; i >= 0; i--)
211 if (n == fs->localvar[i]) return i; /* local var index */ 211 if (n == fs->localvar[i]) return i; /* local var index */
@@ -213,7 +213,7 @@ static int aux_localname (FuncState *fs, TaggedString *n) {
213} 213}
214 214
215 215
216static void singlevar (LexState *ls, TaggedString *n, expdesc *var, int prev) { 216static void singlevar (LexState *ls, TString *n, expdesc *var, int prev) {
217 FuncState *fs = prev ? ls->fs->prev : ls->fs; 217 FuncState *fs = prev ? ls->fs->prev : ls->fs;
218 int i = aux_localname(fs, n); 218 int i = aux_localname(fs, n);
219 if (i >= 0) { /* local value? */ 219 if (i >= 0) { /* local value? */
@@ -231,7 +231,7 @@ static void singlevar (LexState *ls, TaggedString *n, expdesc *var, int prev) {
231} 231}
232 232
233 233
234static int indexupvalue (LexState *ls, TaggedString *n) { 234static int indexupvalue (LexState *ls, TString *n) {
235 FuncState *fs = ls->fs; 235 FuncState *fs = ls->fs;
236 expdesc v; 236 expdesc v;
237 int i; 237 int i;
@@ -248,12 +248,12 @@ static int indexupvalue (LexState *ls, TaggedString *n) {
248} 248}
249 249
250 250
251static void pushupvalue (LexState *ls, TaggedString *n) { 251static void pushupvalue (LexState *ls, TString *n) {
252 if (ls->fs->prev == NULL) 252 if (ls->fs->prev == NULL)
253 luaX_syntaxerror(ls, "cannot access upvalue in main", n->str); 253 luaX_syntaxerror(ls, "cannot access upvalue in main", n->str);
254 if (aux_localname(ls->fs, n) >= 0) 254 if (aux_localname(ls->fs, n) >= 0)
255 luaX_syntaxerror(ls, "cannot access an upvalue in current scope", n->str); 255 luaX_syntaxerror(ls, "cannot access an upvalue in current scope", n->str);
256 luaK_U(ls, PUSHUPVALUE, indexupvalue(ls, n), 1); 256 luaK_U(ls, OP_PUSHUPVALUE, indexupvalue(ls, n), 1);
257} 257}
258 258
259 259
@@ -308,21 +308,21 @@ static int getvarname (LexState *ls, expdesc *var) {
308 308
309 309
310static void func_onstack (LexState *ls, FuncState *func) { 310static void func_onstack (LexState *ls, FuncState *func) {
311 TProtoFunc *f = ls->fs->f; 311 Proto *f = ls->fs->f;
312 int i; 312 int i;
313 for (i=0; i<func->nupvalues; i++) 313 for (i=0; i<func->nupvalues; i++)
314 luaK_tostack(ls, &func->upvalues[i], 1); 314 luaK_tostack(ls, &func->upvalues[i], 1);
315 luaM_growvector(ls->L, f->kproto, f->nkproto, 1, TProtoFunc *, 315 luaM_growvector(ls->L, f->kproto, f->nkproto, 1, Proto *,
316 constantEM, MAXARG_A); 316 constantEM, MAXARG_A);
317 f->kproto[f->nkproto++] = func->f; 317 f->kproto[f->nkproto++] = func->f;
318 luaK_deltastack(ls, 1); /* CLOSURE puts one extra element before popping */ 318 luaK_deltastack(ls, 1); /* CLOSURE puts one extra element before popping */
319 luaK_AB(ls, CLOSURE, f->nkproto-1, func->nupvalues, -func->nupvalues); 319 luaK_AB(ls, OP_CLOSURE, f->nkproto-1, func->nupvalues, -func->nupvalues);
320} 320}
321 321
322 322
323static void init_state (LexState *ls, FuncState *fs, TaggedString *source) { 323static void init_state (LexState *ls, FuncState *fs, TString *source) {
324 lua_State *L = ls->L; 324 lua_State *L = ls->L;
325 TProtoFunc *f = luaF_newproto(ls->L); 325 Proto *f = luaF_newproto(ls->L);
326 fs->prev = ls->fs; /* linked list of funcstates */ 326 fs->prev = ls->fs; /* linked list of funcstates */
327 ls->fs = fs; 327 ls->fs = fs;
328 fs->stacksize = 0; 328 fs->stacksize = 0;
@@ -340,19 +340,19 @@ static void init_state (LexState *ls, FuncState *fs, TaggedString *source) {
340 fs->nvars = (L->debug) ? 0 : -1; /* flag no debug information? */ 340 fs->nvars = (L->debug) ? 0 : -1; /* flag no debug information? */
341 /* push function (to avoid GC) */ 341 /* push function (to avoid GC) */
342 tfvalue(L->top) = f; 342 tfvalue(L->top) = f;
343 ttype(L->top) = LUA_T_LPROTO; 343 ttype(L->top) = TAG_LPROTO;
344 incr_top; 344 incr_top;
345} 345}
346 346
347 347
348static void close_func (LexState *ls) { 348static void close_func (LexState *ls) {
349 FuncState *fs = ls->fs; 349 FuncState *fs = ls->fs;
350 TProtoFunc *f = fs->f; 350 Proto *f = fs->f;
351 luaK_0(ls, ENDCODE, 0); 351 luaK_0(ls, OP_END, 0);
352 luaM_reallocvector(ls->L, f->code, fs->pc, Instruction); 352 luaM_reallocvector(ls->L, f->code, fs->pc, Instruction);
353 luaM_reallocvector(ls->L, f->kstr, f->nkstr, TaggedString *); 353 luaM_reallocvector(ls->L, f->kstr, f->nkstr, TString *);
354 luaM_reallocvector(ls->L, f->knum, f->nknum, real); 354 luaM_reallocvector(ls->L, f->knum, f->nknum, Number);
355 luaM_reallocvector(ls->L, f->kproto, f->nkproto, TProtoFunc *); 355 luaM_reallocvector(ls->L, f->kproto, f->nkproto, Proto *);
356 if (fs->nvars != -1) { /* debug information? */ 356 if (fs->nvars != -1) { /* debug information? */
357 luaI_registerlocalvar(ls, NULL, -1); /* flag end of vector */ 357 luaI_registerlocalvar(ls, NULL, -1); /* flag end of vector */
358 luaM_reallocvector(ls->L, f->locvars, fs->nvars, LocVar); 358 luaM_reallocvector(ls->L, f->locvars, fs->nvars, LocVar);
@@ -362,14 +362,14 @@ static void close_func (LexState *ls) {
362} 362}
363 363
364 364
365TProtoFunc *luaY_parser (lua_State *L, ZIO *z) { 365Proto *luaY_parser (lua_State *L, ZIO *z) {
366 struct LexState lexstate; 366 struct LexState lexstate;
367 struct FuncState funcstate; 367 struct FuncState funcstate;
368 luaX_setinput(L, &lexstate, z); 368 luaX_setinput(L, &lexstate, z);
369 init_state(&lexstate, &funcstate, luaS_new(L, zname(z))); 369 init_state(&lexstate, &funcstate, luaS_new(L, zname(z)));
370 next(&lexstate); /* read first token */ 370 next(&lexstate); /* read first token */
371 chunk(&lexstate); 371 chunk(&lexstate);
372 if (lexstate.token != EOS) 372 if (lexstate.token != TK_EOS)
373 luaK_error(&lexstate, "<eof> expected"); 373 luaK_error(&lexstate, "<eof> expected");
374 close_func(&lexstate); 374 close_func(&lexstate);
375 return funcstate.f; 375 return funcstate.f;
@@ -401,8 +401,8 @@ static int explist1 (LexState *ls) {
401static int explist (LexState *ls) { 401static int explist (LexState *ls) {
402 /* explist -> [ explist1 ] */ 402 /* explist -> [ explist1 ] */
403 switch (ls->token) { 403 switch (ls->token) {
404 case ELSE: case ELSEIF: case END: case UNTIL: 404 case TK_ELSE: case TK_ELSEIF: case TK_END: case TK_UNTIL:
405 case EOS: case ';': case ')': 405 case TK_EOS: case ';': case ')':
406 return 0; /* empty list */ 406 return 0; /* empty list */
407 407
408 default: 408 default:
@@ -432,7 +432,7 @@ static void funcargs (LexState *ls, int slf) {
432 constructor(ls); 432 constructor(ls);
433 break; 433 break;
434 434
435 case STRING: /* funcargs -> STRING */ 435 case TK_STRING: /* funcargs -> STRING */
436 code_string(ls, ls->seminfo.ts); /* must use `seminfo' before `next' */ 436 code_string(ls, ls->seminfo.ts); /* must use `seminfo' before `next' */
437 next(ls); 437 next(ls);
438 break; 438 break;
@@ -442,7 +442,7 @@ static void funcargs (LexState *ls, int slf) {
442 break; 442 break;
443 } 443 }
444 fs->stacksize = slevel; /* call will remove function and arguments */ 444 fs->stacksize = slevel; /* call will remove function and arguments */
445 luaK_AB(ls, CALL, slevel, MULT_RET, 0); 445 luaK_AB(ls, OP_CALL, slevel, MULT_RET, 0);
446} 446}
447 447
448 448
@@ -469,14 +469,14 @@ static void var_or_func_tail (LexState *ls, expdesc *v) {
469 next(ls); 469 next(ls);
470 name = checkname(ls); 470 name = checkname(ls);
471 luaK_tostack(ls, v, 1); /* `v' must be on stack */ 471 luaK_tostack(ls, v, 1); /* `v' must be on stack */
472 luaK_U(ls, PUSHSELF, name, 1); 472 luaK_U(ls, OP_PUSHSELF, name, 1);
473 funcargs(ls, 1); 473 funcargs(ls, 1);
474 v->k = VEXP; 474 v->k = VEXP;
475 v->u.l.t = v->u.l.f = 0; 475 v->u.l.t = v->u.l.f = 0;
476 break; 476 break;
477 } 477 }
478 478
479 case '(': case STRING: case '{': /* var_or_func_tail -> funcargs */ 479 case '(': case TK_STRING: case '{': /* var_or_func_tail -> funcargs */
480 luaK_tostack(ls, v, 1); /* `v' must be on stack */ 480 luaK_tostack(ls, v, 1); /* `v' must be on stack */
481 funcargs(ls, 0); 481 funcargs(ls, 0);
482 v->k = VEXP; 482 v->k = VEXP;
@@ -513,7 +513,7 @@ static void var_or_func (LexState *ls, expdesc *v) {
513static void recfield (LexState *ls) { 513static void recfield (LexState *ls) {
514 /* recfield -> (NAME | '['exp1']') = exp1 */ 514 /* recfield -> (NAME | '['exp1']') = exp1 */
515 switch (ls->token) { 515 switch (ls->token) {
516 case NAME: 516 case TK_NAME:
517 luaK_kstr(ls, checkname(ls)); 517 luaK_kstr(ls, checkname(ls));
518 break; 518 break;
519 519
@@ -541,12 +541,12 @@ static int recfields (LexState *ls) {
541 recfield(ls); 541 recfield(ls);
542 n++; 542 n++;
543 if (++mod_n == RFIELDS_PER_FLUSH) { 543 if (++mod_n == RFIELDS_PER_FLUSH) {
544 luaK_U(ls, SETMAP, RFIELDS_PER_FLUSH-1, -2*RFIELDS_PER_FLUSH); 544 luaK_U(ls, OP_SETMAP, RFIELDS_PER_FLUSH-1, -2*RFIELDS_PER_FLUSH);
545 mod_n = 0; 545 mod_n = 0;
546 } 546 }
547 } 547 }
548 if (mod_n) 548 if (mod_n)
549 luaK_U(ls, SETMAP, mod_n-1, -2*mod_n); 549 luaK_U(ls, OP_SETMAP, mod_n-1, -2*mod_n);
550 return n; 550 return n;
551} 551}
552 552
@@ -564,13 +564,13 @@ static int listfields (LexState *ls) {
564 checklimit(ls, n, MAXARG_A*LFIELDS_PER_FLUSH, 564 checklimit(ls, n, MAXARG_A*LFIELDS_PER_FLUSH,
565 "items in a list initializer"); 565 "items in a list initializer");
566 if (++mod_n == LFIELDS_PER_FLUSH) { 566 if (++mod_n == LFIELDS_PER_FLUSH) {
567 luaK_AB(ls, SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH-1, 567 luaK_AB(ls, OP_SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH-1,
568 -LFIELDS_PER_FLUSH); 568 -LFIELDS_PER_FLUSH);
569 mod_n = 0; 569 mod_n = 0;
570 } 570 }
571 } 571 }
572 if (mod_n > 0) 572 if (mod_n > 0)
573 luaK_AB(ls, SETLIST, n/LFIELDS_PER_FLUSH, mod_n-1, -mod_n); 573 luaK_AB(ls, OP_SETLIST, n/LFIELDS_PER_FLUSH, mod_n-1, -mod_n);
574 return n; 574 return n;
575} 575}
576 576
@@ -583,7 +583,7 @@ static void constructor_part (LexState *ls, constdesc *cd) {
583 cd->k = ls->token; 583 cd->k = ls->token;
584 return; 584 return;
585 585
586 case NAME: { 586 case TK_NAME: {
587 expdesc v; 587 expdesc v;
588 expr(ls, &v); 588 expr(ls, &v);
589 if (ls->token == '=') { 589 if (ls->token == '=') {
@@ -619,7 +619,7 @@ static void constructor_part (LexState *ls, constdesc *cd) {
619static void constructor (LexState *ls) { 619static void constructor (LexState *ls) {
620 /* constructor -> '{' constructor_part [';' constructor_part] '}' */ 620 /* constructor -> '{' constructor_part [';' constructor_part] '}' */
621 int line = ls->linenumber; 621 int line = ls->linenumber;
622 int pc = luaK_U(ls, CREATETABLE, 0, 1); 622 int pc = luaK_U(ls, OP_CREATETABLE, 0, 1);
623 int nelems; 623 int nelems;
624 constdesc cd; 624 constdesc cd;
625 check(ls, '{'); 625 check(ls, '{');
@@ -653,19 +653,19 @@ static void constructor (LexState *ls) {
653static void simpleexp (LexState *ls, expdesc *v) { 653static void simpleexp (LexState *ls, expdesc *v) {
654 check_debugline(ls); 654 check_debugline(ls);
655 switch (ls->token) { 655 switch (ls->token) {
656 case NUMBER: { /* simpleexp -> NUMBER */ 656 case TK_NUMBER: { /* simpleexp -> NUMBER */
657 real r = ls->seminfo.r; 657 Number r = ls->seminfo.r;
658 next(ls); 658 next(ls);
659 luaK_number(ls, r); 659 luaK_number(ls, r);
660 break; 660 break;
661 } 661 }
662 662
663 case STRING: /* simpleexp -> STRING */ 663 case TK_STRING: /* simpleexp -> STRING */
664 code_string(ls, ls->seminfo.ts); /* must use `seminfo' before `next' */ 664 code_string(ls, ls->seminfo.ts); /* must use `seminfo' before `next' */
665 next(ls); 665 next(ls);
666 break; 666 break;
667 667
668 case NIL: /* simpleexp -> NIL */ 668 case TK_NIL: /* simpleexp -> NIL */
669 luaK_adjuststack(ls, -1); 669 luaK_adjuststack(ls, -1);
670 next(ls); 670 next(ls);
671 break; 671 break;
@@ -674,7 +674,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
674 constructor(ls); 674 constructor(ls);
675 break; 675 break;
676 676
677 case FUNCTION: /* simpleexp -> FUNCTION body */ 677 case TK_FUNCTION: /* simpleexp -> FUNCTION body */
678 next(ls); 678 next(ls);
679 body(ls, 0, ls->linenumber); 679 body(ls, 0, ls->linenumber);
680 break; 680 break;
@@ -685,7 +685,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
685 check(ls, ')'); 685 check(ls, ')');
686 return; 686 return;
687 687
688 case NAME: case '%': 688 case TK_NAME: case '%':
689 var_or_func(ls, v); 689 var_or_func(ls, v);
690 return; 690 return;
691 691
@@ -720,12 +720,12 @@ static int get_priority (int op, int *rp) {
720 720
721 case '+': case '-': *rp = 5; return 5; 721 case '+': case '-': *rp = 5; return 5;
722 722
723 case CONC: *rp = 3; return 4; /* right associative (?) */ 723 case TK_CONC: *rp = 3; return 4; /* right associative (?) */
724 724
725 case EQ: case NE: case '>': case '<': case LE: case GE: 725 case TK_EQ: case TK_NE: case '>': case '<': case TK_LE: case TK_GE:
726 *rp = 2; return 2; 726 *rp = 2; return 2;
727 727
728 case AND: case OR: *rp = 1; return 1; 728 case TK_AND: case TK_OR: *rp = 1; return 1;
729 729
730 default: *rp = -1; return -1; 730 default: *rp = -1; return -1;
731 } 731 }
@@ -738,7 +738,7 @@ static int get_priority (int op, int *rp) {
738*/ 738*/
739static void subexpr (LexState *ls, expdesc *v, int limit) { 739static void subexpr (LexState *ls, expdesc *v, int limit) {
740 int rp; 740 int rp;
741 if (ls->token == '-' || ls->token == NOT) { 741 if (ls->token == '-' || ls->token == TK_NOT) {
742 int op = ls->token; /* operator */ 742 int op = ls->token; /* operator */
743 next(ls); 743 next(ls);
744 subexpr(ls, v, UNARY_PRIORITY); 744 subexpr(ls, v, UNARY_PRIORITY);
@@ -806,7 +806,7 @@ static int assignment (LexState *ls, expdesc *v, int nvars) {
806 luaK_storevar(ls, v); 806 luaK_storevar(ls, v);
807 } 807 }
808 else { /* indexed var with values in between*/ 808 else { /* indexed var with values in between*/
809 luaK_U(ls, SETTABLE, left+(nvars-1), -1); 809 luaK_U(ls, OP_SETTABLE, left+(nvars-1), -1);
810 left += 2; /* table&index are not popped, because they aren't on top */ 810 left += 2; /* table&index are not popped, because they aren't on top */
811 } 811 }
812 return left; 812 return left;
@@ -838,11 +838,11 @@ static void whilestat (LexState *ls, int line) {
838 for (i=0; i<cond_size; i++) buffer[i] = fs->f->code[while_init+i]; 838 for (i=0; i<cond_size; i++) buffer[i] = fs->f->code[while_init+i];
839 /* go back to state prior condition */ 839 /* go back to state prior condition */
840 fs->pc = while_init; 840 fs->pc = while_init;
841 luaK_S(ls, JMP, 0, 0); /* initial jump to condition */ 841 luaK_S(ls, OP_JMP, 0, 0); /* initial jump to condition */
842 check(ls, DO); 842 check(ls, TK_DO);
843 loopentry = luaK_getlabel(ls); 843 loopentry = luaK_getlabel(ls);
844 block(ls); 844 block(ls);
845 check_match(ls, END, WHILE, line); 845 check_match(ls, TK_END, TK_WHILE, line);
846 cond_init = luaK_getlabel(ls); 846 cond_init = luaK_getlabel(ls);
847 luaK_fixjump(ls, while_init, cond_init); 847 luaK_fixjump(ls, while_init, cond_init);
848 /* correct `v' and copy condition to new position */ 848 /* correct `v' and copy condition to new position */
@@ -859,7 +859,7 @@ static void repeatstat (LexState *ls, int line) {
859 expdesc v; 859 expdesc v;
860 next(ls); 860 next(ls);
861 block(ls); 861 block(ls);
862 check_match(ls, UNTIL, REPEAT, line); 862 check_match(ls, TK_UNTIL, TK_REPEAT, line);
863 expr(ls, &v); 863 expr(ls, &v);
864 luaK_goiftrue(ls, &v, 0); 864 luaK_goiftrue(ls, &v, 0);
865 luaK_patchlist(ls, v.u.l.f, repeat_init); 865 luaK_patchlist(ls, v.u.l.f, repeat_init);
@@ -958,16 +958,16 @@ static void ifpart (LexState *ls, int line) {
958 next(ls); /* skip IF or ELSEIF */ 958 next(ls); /* skip IF or ELSEIF */
959 expr(ls, &v); /* cond */ 959 expr(ls, &v); /* cond */
960 luaK_goiftrue(ls, &v, 0); 960 luaK_goiftrue(ls, &v, 0);
961 check(ls, THEN); 961 check(ls, TK_THEN);
962 block(ls); /* `then' part */ 962 block(ls); /* `then' part */
963 luaK_S(ls, JMP, 0, 0); /* 2nd jump: over `else' part */ 963 luaK_S(ls, OP_JMP, 0, 0); /* 2nd jump: over `else' part */
964 elseinit = luaK_getlabel(ls); /* address of 2nd jump == elseinit-1 */ 964 elseinit = luaK_getlabel(ls); /* address of 2nd jump == elseinit-1 */
965 if (ls->token == ELSEIF) 965 if (ls->token == TK_ELSEIF)
966 ifpart(ls, line); 966 ifpart(ls, line);
967 else { 967 else {
968 if (optional(ls, ELSE)) 968 if (optional(ls, TK_ELSE))
969 block(ls); /* `else' part */ 969 block(ls); /* `else' part */
970 check_match(ls, END, IF, line); 970 check_match(ls, TK_END, TK_IF, line);
971 } 971 }
972 if (fs->pc > elseinit) { /* is there an `else' part? */ 972 if (fs->pc > elseinit) { /* is there an `else' part? */
973 luaK_fixjump(ls, elseinit-1, luaK_getlabel(ls)); /* fix 2nd jump */ 973 luaK_fixjump(ls, elseinit-1, luaK_getlabel(ls)); /* fix 2nd jump */
@@ -983,38 +983,38 @@ static void ifpart (LexState *ls, int line) {
983static int stat (LexState *ls) { 983static int stat (LexState *ls) {
984 int line = ls->linenumber; /* may be needed for error messages */ 984 int line = ls->linenumber; /* may be needed for error messages */
985 switch (ls->token) { 985 switch (ls->token) {
986 case IF: /* stat -> IF ifpart END */ 986 case TK_IF: /* stat -> IF ifpart END */
987 ifpart(ls, line); 987 ifpart(ls, line);
988 return 1; 988 return 1;
989 989
990 case WHILE: /* stat -> whilestat */ 990 case TK_WHILE: /* stat -> whilestat */
991 whilestat(ls, line); 991 whilestat(ls, line);
992 return 1; 992 return 1;
993 993
994 case DO: { /* stat -> DO block END */ 994 case TK_DO: { /* stat -> DO block END */
995 next(ls); 995 next(ls);
996 block(ls); 996 block(ls);
997 check_match(ls, END, DO, line); 997 check_match(ls, TK_END, TK_DO, line);
998 return 1; 998 return 1;
999 } 999 }
1000 1000
1001 case REPEAT: /* stat -> repeatstat */ 1001 case TK_REPEAT: /* stat -> repeatstat */
1002 repeatstat(ls, line); 1002 repeatstat(ls, line);
1003 return 1; 1003 return 1;
1004 1004
1005 case FUNCTION: /* stat -> funcstat */ 1005 case TK_FUNCTION: /* stat -> funcstat */
1006 return funcstat(ls, line); 1006 return funcstat(ls, line);
1007 1007
1008 case LOCAL: /* stat -> localstat */ 1008 case TK_LOCAL: /* stat -> localstat */
1009 localstat(ls); 1009 localstat(ls);
1010 return 1; 1010 return 1;
1011 1011
1012 case NAME: case '%': /* stat -> namestat */ 1012 case TK_NAME: case '%': /* stat -> namestat */
1013 namestat(ls); 1013 namestat(ls);
1014 return 1; 1014 return 1;
1015 1015
1016 case RETURN: case ';': case ELSE: case ELSEIF: 1016 case TK_RETURN: case ';': case TK_ELSE: case TK_ELSEIF:
1017 case END: case UNTIL: case EOS: /* `stat' follow */ 1017 case TK_END: case TK_UNTIL: case TK_EOS: /* `stat' follow */
1018 return 0; 1018 return 0;
1019 1019
1020 default: 1020 default:
@@ -1028,23 +1028,23 @@ static void parlist (LexState *ls) {
1028 int nparams = 0; 1028 int nparams = 0;
1029 int dots = 0; 1029 int dots = 0;
1030 switch (ls->token) { 1030 switch (ls->token) {
1031 case DOTS: /* parlist -> DOTS */ 1031 case TK_DOTS: /* parlist -> DOTS */
1032 next(ls); 1032 next(ls);
1033 dots = 1; 1033 dots = 1;
1034 break; 1034 break;
1035 1035
1036 case NAME: /* parlist, tailparlist -> NAME [',' tailparlist] */ 1036 case TK_NAME: /* parlist, tailparlist -> NAME [',' tailparlist] */
1037 init: 1037 init:
1038 store_localvar(ls, str_checkname(ls), nparams++); 1038 store_localvar(ls, str_checkname(ls), nparams++);
1039 if (ls->token == ',') { 1039 if (ls->token == ',') {
1040 next(ls); 1040 next(ls);
1041 switch (ls->token) { 1041 switch (ls->token) {
1042 case DOTS: /* tailparlist -> DOTS */ 1042 case TK_DOTS: /* tailparlist -> DOTS */
1043 next(ls); 1043 next(ls);
1044 dots = 1; 1044 dots = 1;
1045 break; 1045 break;
1046 1046
1047 case NAME: /* tailparlist -> NAME [',' tailparlist] */ 1047 case TK_NAME: /* tailparlist -> NAME [',' tailparlist] */
1048 goto init; 1048 goto init;
1049 1049
1050 default: luaK_error(ls, "<name> or `...' expected"); 1050 default: luaK_error(ls, "<name> or `...' expected");
@@ -1071,7 +1071,7 @@ static void body (LexState *ls, int needself, int line) {
1071 parlist(ls); 1071 parlist(ls);
1072 check(ls, ')'); 1072 check(ls, ')');
1073 chunk(ls); 1073 chunk(ls);
1074 check_match(ls, END, FUNCTION, line); 1074 check_match(ls, TK_END, TK_FUNCTION, line);
1075 close_func(ls); 1075 close_func(ls);
1076 func_onstack(ls, &new_fs); 1076 func_onstack(ls, &new_fs);
1077} 1077}
@@ -1079,7 +1079,7 @@ static void body (LexState *ls, int needself, int line) {
1079 1079
1080static void ret (LexState *ls) { 1080static void ret (LexState *ls) {
1081 /* ret -> [RETURN explist sc] */ 1081 /* ret -> [RETURN explist sc] */
1082 if (ls->token == RETURN) { 1082 if (ls->token == TK_RETURN) {
1083 int nexps; /* number of expressions returned */ 1083 int nexps; /* number of expressions returned */
1084 check_debugline(ls); 1084 check_debugline(ls);
1085 next(ls); 1085 next(ls);
diff --git a/lparser.h b/lparser.h
index 01332478..36b76c97 100644
--- a/lparser.h
+++ b/lparser.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.h,v 1.9 2000/03/03 18:53:17 roberto Exp roberto $ 2** $Id: lparser.h,v 1.11 2000/03/09 13:57:37 roberto Exp roberto $
3** LL(1) Parser and code generator for Lua 3** LL(1) Parser and code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -68,7 +68,7 @@ typedef struct expdesc {
68 68
69/* state needed to generate code for a given function */ 69/* state needed to generate code for a given function */
70typedef struct FuncState { 70typedef struct FuncState {
71 TProtoFunc *f; /* current function header */ 71 Proto *f; /* current function header */
72 struct FuncState *prev; /* enclosing function */ 72 struct FuncState *prev; /* enclosing function */
73 int pc; /* next position to code */ 73 int pc; /* next position to code */
74 int lasttarget; /* `pc' of last `jump target' */ 74 int lasttarget; /* `pc' of last `jump target' */
@@ -78,11 +78,11 @@ typedef struct FuncState {
78 int nvars; /* number of entries in f->locvars (-1 if no debug information) */ 78 int nvars; /* number of entries in f->locvars (-1 if no debug information) */
79 int lastsetline; /* line where last SETLINE was issued */ 79 int lastsetline; /* line where last SETLINE was issued */
80 expdesc upvalues[MAXUPVALUES]; /* upvalues */ 80 expdesc upvalues[MAXUPVALUES]; /* upvalues */
81 TaggedString *localvar[MAXLOCALS]; /* store local variable names */ 81 TString *localvar[MAXLOCALS]; /* store local variable names */
82} FuncState; 82} FuncState;
83 83
84 84
85TProtoFunc *luaY_parser (lua_State *L, ZIO *z); 85Proto *luaY_parser (lua_State *L, ZIO *z);
86 86
87 87
88#endif 88#endif
diff --git a/lref.c b/lref.c
index eeb720a2..b401a1b5 100644
--- a/lref.c
+++ b/lref.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lref.c,v 1.7 2000/02/08 16:34:31 roberto Exp roberto $ 2** $Id: lref.c,v 1.8 2000/03/03 14:58:26 roberto Exp roberto $
3** reference mechanism 3** reference mechanism
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -17,7 +17,7 @@
17int lua_ref (lua_State *L, int lock) { 17int lua_ref (lua_State *L, int lock) {
18 int ref; 18 int ref;
19 luaA_checkCargs(L, 1); 19 luaA_checkCargs(L, 1);
20 if (ttype(L->top-1) == LUA_T_NIL) 20 if (ttype(L->top-1) == TAG_NIL)
21 ref = LUA_REFNIL; 21 ref = LUA_REFNIL;
22 else { 22 else {
23 if (L->refFree != NONEXT) { /* is there a free place? */ 23 if (L->refFree != NONEXT) { /* is there a free place? */
@@ -82,13 +82,13 @@ void lua_endblock (lua_State *L) {
82static int ismarked (const TObject *o) { 82static int ismarked (const TObject *o) {
83 /* valid only for locked objects */ 83 /* valid only for locked objects */
84 switch (o->ttype) { 84 switch (o->ttype) {
85 case LUA_T_STRING: case LUA_T_USERDATA: 85 case TAG_STRING: case TAG_USERDATA:
86 return o->value.ts->marked; 86 return o->value.ts->marked;
87 case LUA_T_ARRAY: 87 case TAG_ARRAY:
88 return o->value.a->marked; 88 return o->value.a->marked;
89 case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: 89 case TAG_LCLOSURE: case TAG_CCLOSURE:
90 return o->value.cl->marked; 90 return o->value.cl->marked;
91 case LUA_T_LPROTO: 91 case TAG_LPROTO:
92 return o->value.tf->marked; 92 return o->value.tf->marked;
93 default: /* number or cproto */ 93 default: /* number or cproto */
94 return 1; 94 return 1;
diff --git a/lstate.h b/lstate.h
index da0f1681..bda30bb9 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 1.28 2000/01/19 12:00:45 roberto Exp roberto $ 2** $Id: lstate.h,v 1.29 2000/02/08 16:34:31 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*/
@@ -43,7 +43,7 @@ struct C_Lua_Stack {
43typedef struct stringtable { 43typedef struct stringtable {
44 int size; 44 int size;
45 int nuse; /* number of elements (including EMPTYs) */ 45 int nuse; /* number of elements (including EMPTYs) */
46 TaggedString **hash; 46 TString **hash;
47} stringtable; 47} stringtable;
48 48
49 49
@@ -63,7 +63,7 @@ struct lua_State {
63 struct C_Lua_Stack *Cblocks; 63 struct C_Lua_Stack *Cblocks;
64 int numCblocks; /* number of nested Cblocks */ 64 int numCblocks; /* number of nested Cblocks */
65 /* global state */ 65 /* global state */
66 TProtoFunc *rootproto; /* list of all prototypes */ 66 Proto *rootproto; /* list of all prototypes */
67 Closure *rootcl; /* list of all closures */ 67 Closure *rootcl; /* list of all closures */
68 Hash *roottable; /* list of all tables */ 68 Hash *roottable; /* list of all tables */
69 GlobalVar *rootglobal; /* list of global variables */ 69 GlobalVar *rootglobal; /* list of global variables */
diff --git a/lstring.c b/lstring.c
index 7e10da33..1dd4c9b9 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.c,v 1.32 2000/03/03 14:58:26 roberto Exp roberto $ 2** $Id: lstring.c,v 1.33 2000/03/10 14:38:10 roberto Exp roberto $
3** String table (keeps all strings handled by Lua) 3** String table (keeps all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -17,7 +17,7 @@
17 17
18 18
19 19
20#define gcsizestring(L, l) numblocks(L, 0, sizeof(TaggedString)+l) 20#define gcsizestring(L, l) numblocks(L, 0, sizeof(TString)+l)
21#define gcsizeudata gcsizestring(L, 0) 21#define gcsizeudata gcsizestring(L, 0)
22 22
23 23
@@ -28,7 +28,7 @@ void luaS_init (lua_State *L) {
28 for (i=0; i<NUM_HASHS; i++) { 28 for (i=0; i<NUM_HASHS; i++) {
29 L->string_root[i].size = 1; 29 L->string_root[i].size = 1;
30 L->string_root[i].nuse = 0; 30 L->string_root[i].nuse = 0;
31 L->string_root[i].hash = luaM_newvector(L, 1, TaggedString *);; 31 L->string_root[i].hash = luaM_newvector(L, 1, TString *);;
32 L->string_root[i].hash[0] = NULL; 32 L->string_root[i].hash[0] = NULL;
33 } 33 }
34} 34}
@@ -54,14 +54,14 @@ static unsigned long hash_s (const char *s, long l) {
54 54
55 55
56void luaS_resize (lua_State *L, stringtable *tb, int newsize) { 56void luaS_resize (lua_State *L, stringtable *tb, int newsize) {
57 TaggedString **newhash = luaM_newvector(L, newsize, TaggedString *); 57 TString **newhash = luaM_newvector(L, newsize, TString *);
58 int i; 58 int i;
59 for (i=0; i<newsize; i++) newhash[i] = NULL; 59 for (i=0; i<newsize; i++) newhash[i] = NULL;
60 /* rehash */ 60 /* rehash */
61 for (i=0; i<tb->size; i++) { 61 for (i=0; i<tb->size; i++) {
62 TaggedString *p = tb->hash[i]; 62 TString *p = tb->hash[i];
63 while (p) { /* for each node in the list */ 63 while (p) { /* for each node in the list */
64 TaggedString *next = p->nexthash; /* save next */ 64 TString *next = p->nexthash; /* save next */
65 int h = p->hash&(newsize-1); /* new position */ 65 int h = p->hash&(newsize-1); /* new position */
66 LUA_ASSERT(L, p->hash%newsize == (p->hash&(newsize-1)), 66 LUA_ASSERT(L, p->hash%newsize == (p->hash&(newsize-1)),
67 "a&(x-1) == a%x, for x power of 2"); 67 "a&(x-1) == a%x, for x power of 2");
@@ -76,9 +76,9 @@ void luaS_resize (lua_State *L, stringtable *tb, int newsize) {
76} 76}
77 77
78 78
79static TaggedString *newone (lua_State *L, long l, unsigned long h) { 79static TString *newone (lua_State *L, long l, unsigned long h) {
80 TaggedString *ts = (TaggedString *)luaM_malloc(L, 80 TString *ts = (TString *)luaM_malloc(L,
81 sizeof(TaggedString)+l*sizeof(char)); 81 sizeof(TString)+l*sizeof(char));
82 ts->marked = 0; 82 ts->marked = 0;
83 ts->nexthash = NULL; 83 ts->nexthash = NULL;
84 ts->hash = h; 84 ts->hash = h;
@@ -86,9 +86,9 @@ static TaggedString *newone (lua_State *L, long l, unsigned long h) {
86} 86}
87 87
88 88
89static TaggedString *newone_s (lua_State *L, const char *str, 89static TString *newone_s (lua_State *L, const char *str,
90 long l, unsigned long h) { 90 long l, unsigned long h) {
91 TaggedString *ts = newone(L, l, h); 91 TString *ts = newone(L, l, h);
92 memcpy(ts->str, str, l); 92 memcpy(ts->str, str, l);
93 ts->str[l] = 0; /* ending 0 */ 93 ts->str[l] = 0; /* ending 0 */
94 ts->u.s.gv = NULL; /* no global value */ 94 ts->u.s.gv = NULL; /* no global value */
@@ -99,9 +99,9 @@ static TaggedString *newone_s (lua_State *L, const char *str,
99} 99}
100 100
101 101
102static TaggedString *newone_u (lua_State *L, void *buff, 102static TString *newone_u (lua_State *L, void *buff,
103 int tag, unsigned long h) { 103 int tag, unsigned long h) {
104 TaggedString *ts = newone(L, 0, h); 104 TString *ts = newone(L, 0, h);
105 ts->u.d.value = buff; 105 ts->u.d.value = buff;
106 ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag; 106 ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag;
107 ts->constindex = -1; /* tag -> this is a userdata */ 107 ts->constindex = -1; /* tag -> this is a userdata */
@@ -110,7 +110,7 @@ static TaggedString *newone_u (lua_State *L, void *buff,
110} 110}
111 111
112 112
113static void newentry (lua_State *L, stringtable *tb, TaggedString *ts, int h) { 113static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) {
114 ts->nexthash = tb->hash[h]; /* chain new entry */ 114 ts->nexthash = tb->hash[h]; /* chain new entry */
115 tb->hash[h] = ts; 115 tb->hash[h] = ts;
116 tb->nuse++; 116 tb->nuse++;
@@ -119,12 +119,12 @@ static void newentry (lua_State *L, stringtable *tb, TaggedString *ts, int h) {
119} 119}
120 120
121 121
122TaggedString *luaS_newlstr (lua_State *L, const char *str, long l) { 122TString *luaS_newlstr (lua_State *L, const char *str, long l) {
123 unsigned long h = hash_s(str, l); 123 unsigned long h = hash_s(str, l);
124 stringtable *tb = &L->string_root[(l==0) ? 0 : 124 stringtable *tb = &L->string_root[(l==0) ? 0 :
125 ((unsigned int)(str[0]+str[l-1]))&(NUM_HASHSTR-1)]; 125 ((unsigned int)(str[0]+str[l-1]))&(NUM_HASHSTR-1)];
126 int h1 = h&(tb->size-1); 126 int h1 = h&(tb->size-1);
127 TaggedString *ts; 127 TString *ts;
128 for (ts = tb->hash[h1]; ts; ts = ts->nexthash) { 128 for (ts = tb->hash[h1]; ts; ts = ts->nexthash) {
129 if (ts->u.s.len == l && (memcmp(str, ts->str, l) == 0)) 129 if (ts->u.s.len == l && (memcmp(str, ts->str, l) == 0))
130 return ts; 130 return ts;
@@ -140,11 +140,11 @@ TaggedString *luaS_newlstr (lua_State *L, const char *str, long l) {
140** uses '%' for one hashing with userdata because addresses are too regular, 140** uses '%' for one hashing with userdata because addresses are too regular,
141** so two '&' operations would be highly correlated 141** so two '&' operations would be highly correlated
142*/ 142*/
143TaggedString *luaS_createudata (lua_State *L, void *udata, int tag) { 143TString *luaS_createudata (lua_State *L, void *udata, int tag) {
144 unsigned long h = IntPoint(L, udata); 144 unsigned long h = IntPoint(L, udata);
145 stringtable *tb = &L->string_root[(h%NUM_HASHUDATA)+NUM_HASHSTR]; 145 stringtable *tb = &L->string_root[(h%NUM_HASHUDATA)+NUM_HASHSTR];
146 int h1 = h&(tb->size-1); 146 int h1 = h&(tb->size-1);
147 TaggedString *ts; 147 TString *ts;
148 for (ts = tb->hash[h1]; ts; ts = ts->nexthash) { 148 for (ts = tb->hash[h1]; ts; ts = ts->nexthash) {
149 if (udata == ts->u.d.value && (tag == ts->u.d.tag || tag == LUA_ANYTAG)) 149 if (udata == ts->u.d.value && (tag == ts->u.d.tag || tag == LUA_ANYTAG))
150 return ts; 150 return ts;
@@ -156,18 +156,18 @@ TaggedString *luaS_createudata (lua_State *L, void *udata, int tag) {
156} 156}
157 157
158 158
159TaggedString *luaS_new (lua_State *L, const char *str) { 159TString *luaS_new (lua_State *L, const char *str) {
160 return luaS_newlstr(L, str, strlen(str)); 160 return luaS_newlstr(L, str, strlen(str));
161} 161}
162 162
163TaggedString *luaS_newfixed (lua_State *L, const char *str) { 163TString *luaS_newfixed (lua_State *L, const char *str) {
164 TaggedString *ts = luaS_new(L, str); 164 TString *ts = luaS_new(L, str);
165 if (ts->marked == 0) ts->marked = FIXMARK; /* avoid GC */ 165 if (ts->marked == 0) ts->marked = FIXMARK; /* avoid GC */
166 return ts; 166 return ts;
167} 167}
168 168
169 169
170void luaS_free (lua_State *L, TaggedString *t) { 170void luaS_free (lua_State *L, TString *t) {
171 if (t->constindex == -1) /* is userdata? */ 171 if (t->constindex == -1) /* is userdata? */
172 L->nblocks -= gcsizeudata; 172 L->nblocks -= gcsizeudata;
173 else { /* is string */ 173 else { /* is string */
@@ -178,11 +178,11 @@ void luaS_free (lua_State *L, TaggedString *t) {
178} 178}
179 179
180 180
181GlobalVar *luaS_assertglobal (lua_State *L, TaggedString *ts) { 181GlobalVar *luaS_assertglobal (lua_State *L, TString *ts) {
182 GlobalVar *gv = ts->u.s.gv; 182 GlobalVar *gv = ts->u.s.gv;
183 if (!gv) { /* no global value yet? */ 183 if (!gv) { /* no global value yet? */
184 gv = luaM_new(L, GlobalVar); 184 gv = luaM_new(L, GlobalVar);
185 gv->value.ttype = LUA_T_NIL; /* initial value */ 185 gv->value.ttype = TAG_NIL; /* initial value */
186 gv->name = ts; 186 gv->name = ts;
187 gv->next = L->rootglobal; /* chain in global list */ 187 gv->next = L->rootglobal; /* chain in global list */
188 L->rootglobal = gv; 188 L->rootglobal = gv;
@@ -198,8 +198,8 @@ GlobalVar *luaS_assertglobalbyname (lua_State *L, const char *name) {
198 198
199 199
200int luaS_globaldefined (lua_State *L, const char *name) { 200int luaS_globaldefined (lua_State *L, const char *name) {
201 TaggedString *ts = luaS_new(L, name); 201 TString *ts = luaS_new(L, name);
202 return ts->u.s.gv && ts->u.s.gv->value.ttype != LUA_T_NIL; 202 return ts->u.s.gv && ts->u.s.gv->value.ttype != TAG_NIL;
203} 203}
204 204
205 205
diff --git a/lstring.h b/lstring.h
index 226c02eb..80aa0b8f 100644
--- a/lstring.h
+++ b/lstring.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.h,v 1.16 2000/03/03 14:58:26 roberto Exp roberto $ 2** $Id: lstring.h,v 1.17 2000/03/10 14:38:10 roberto Exp roberto $
3** String table (keep all strings handled by Lua) 3** String table (keep all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -27,13 +27,13 @@
27 27
28void luaS_init (lua_State *L); 28void luaS_init (lua_State *L);
29void luaS_resize (lua_State *L, stringtable *tb, int newsize); 29void luaS_resize (lua_State *L, stringtable *tb, int newsize);
30TaggedString *luaS_createudata (lua_State *L, void *udata, int tag); 30TString *luaS_createudata (lua_State *L, void *udata, int tag);
31void luaS_freeall (lua_State *L); 31void luaS_freeall (lua_State *L);
32void luaS_free (lua_State *L, TaggedString *ts); 32void luaS_free (lua_State *L, TString *ts);
33TaggedString *luaS_newlstr (lua_State *L, const char *str, long l); 33TString *luaS_newlstr (lua_State *L, const char *str, long l);
34TaggedString *luaS_new (lua_State *L, const char *str); 34TString *luaS_new (lua_State *L, const char *str);
35TaggedString *luaS_newfixed (lua_State *L, const char *str); 35TString *luaS_newfixed (lua_State *L, const char *str);
36GlobalVar *luaS_assertglobal (lua_State *L, TaggedString *ts); 36GlobalVar *luaS_assertglobal (lua_State *L, TString *ts);
37GlobalVar *luaS_assertglobalbyname (lua_State *L, const char *name); 37GlobalVar *luaS_assertglobalbyname (lua_State *L, const char *name);
38int luaS_globaldefined (lua_State *L, const char *name); 38int luaS_globaldefined (lua_State *L, const char *name);
39 39
diff --git a/ltable.c b/ltable.c
index be45da44..d13002c9 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.34 2000/02/08 16:34:31 roberto Exp roberto $ 2** $Id: ltable.c,v 1.35 2000/03/03 14:58:26 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -32,7 +32,7 @@
32 32
33 33
34 34
35#define TagDefault LUA_T_ARRAY 35#define TagDefault TAG_ARRAY
36 36
37 37
38 38
@@ -43,22 +43,22 @@
43Node *luaH_mainposition (const Hash *t, const TObject *key) { 43Node *luaH_mainposition (const Hash *t, const TObject *key) {
44 unsigned long h; 44 unsigned long h;
45 switch (ttype(key)) { 45 switch (ttype(key)) {
46 case LUA_T_NUMBER: 46 case TAG_NUMBER:
47 h = (unsigned long)(long)nvalue(key); 47 h = (unsigned long)(long)nvalue(key);
48 break; 48 break;
49 case LUA_T_STRING: case LUA_T_USERDATA: 49 case TAG_STRING: case TAG_USERDATA:
50 h = tsvalue(key)->hash; 50 h = tsvalue(key)->hash;
51 break; 51 break;
52 case LUA_T_ARRAY: 52 case TAG_ARRAY:
53 h = IntPoint(L, avalue(key)); 53 h = IntPoint(L, avalue(key));
54 break; 54 break;
55 case LUA_T_LPROTO: 55 case TAG_LPROTO:
56 h = IntPoint(L, tfvalue(key)); 56 h = IntPoint(L, tfvalue(key));
57 break; 57 break;
58 case LUA_T_CPROTO: 58 case TAG_CPROTO:
59 h = IntPoint(L, fvalue(key)); 59 h = IntPoint(L, fvalue(key));
60 break; 60 break;
61 case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: 61 case TAG_LCLOSURE: case TAG_CCLOSURE:
62 h = IntPoint(L, clvalue(key)); 62 h = IntPoint(L, clvalue(key));
63 break; 63 break;
64 default: 64 default:
@@ -95,7 +95,7 @@ static Node *hashnodecreate (lua_State *L, int nhash) {
95 Node *v = luaM_newvector(L, nhash, Node); 95 Node *v = luaM_newvector(L, nhash, Node);
96 int i; 96 int i;
97 for (i=0; i<nhash; i++) { 97 for (i=0; i<nhash; i++) {
98 ttype(&v[i].key) = ttype(&v[i].val) = LUA_T_NIL; 98 ttype(&v[i].key) = ttype(&v[i].val) = TAG_NIL;
99 v[i].next = NULL; 99 v[i].next = NULL;
100 } 100 }
101 return v; 101 return v;
@@ -134,7 +134,7 @@ static int newsize (const Hash *t) {
134 int realuse = 0; 134 int realuse = 0;
135 int i; 135 int i;
136 for (i=0; i<size; i++) { 136 for (i=0; i<size; i++) {
137 if (ttype(&v[i].val) != LUA_T_NIL) 137 if (ttype(&v[i].val) != TAG_NIL)
138 realuse++; 138 realuse++;
139 } 139 }
140 return luaO_power2(realuse+realuse/4+1); 140 return luaO_power2(realuse+realuse/4+1);
@@ -149,7 +149,7 @@ static void rehash (lua_State *L, Hash *t) {
149 setnodevector(L, t, newsize(t)); /* create new array of nodes */ 149 setnodevector(L, t, newsize(t)); /* create new array of nodes */
150 for (i=0; i<oldsize; i++) { 150 for (i=0; i<oldsize; i++) {
151 Node *old = nold+i; 151 Node *old = nold+i;
152 if (ttype(&old->val) != LUA_T_NIL) 152 if (ttype(&old->val) != TAG_NIL)
153 luaH_set(L, t, &old->key, &old->val); 153 luaH_set(L, t, &old->key, &old->val);
154 } 154 }
155 luaM_free(L, nold); /* free old array */ 155 luaM_free(L, nold); /* free old array */
@@ -182,7 +182,7 @@ void luaH_set (lua_State *L, Hash *t, const TObject *key, const TObject *val) {
182 else n = n->next; 182 else n = n->next;
183 } while (n); 183 } while (n);
184 /* `key' not found; must insert it */ 184 /* `key' not found; must insert it */
185 if (ttype(&mp->key) != LUA_T_NIL) { /* main position is not free? */ 185 if (ttype(&mp->key) != TAG_NIL) { /* main position is not free? */
186 Node *othern; /* main position of colliding node */ 186 Node *othern; /* main position of colliding node */
187 n = t->firstfree; /* get a free place */ 187 n = t->firstfree; /* get a free place */
188 /* is colliding node out of its main position? (can only happens if 188 /* is colliding node out of its main position? (can only happens if
@@ -204,7 +204,7 @@ void luaH_set (lua_State *L, Hash *t, const TObject *key, const TObject *val) {
204 mp->key = *key; 204 mp->key = *key;
205 mp->val = *val; 205 mp->val = *val;
206 for (;;) { /* check free places */ 206 for (;;) { /* check free places */
207 if (ttype(&(t->firstfree)->key) == LUA_T_NIL) 207 if (ttype(&(t->firstfree)->key) == TAG_NIL)
208 return; /* OK; table still has a free place */ 208 return; /* OK; table still has a free place */
209 else if (t->firstfree == t->node) break; /* cannot decrement from here */ 209 else if (t->firstfree == t->node) break; /* cannot decrement from here */
210 else (t->firstfree)--; 210 else (t->firstfree)--;
@@ -215,7 +215,7 @@ void luaH_set (lua_State *L, Hash *t, const TObject *key, const TObject *val) {
215 215
216void luaH_setint (lua_State *L, Hash *t, int key, const TObject *val) { 216void luaH_setint (lua_State *L, Hash *t, int key, const TObject *val) {
217 TObject index; 217 TObject index;
218 ttype(&index) = LUA_T_NUMBER; 218 ttype(&index) = TAG_NUMBER;
219 nvalue(&index) = key; 219 nvalue(&index) = key;
220 luaH_set(L, t, &index, val); 220 luaH_set(L, t, &index, val);
221} 221}
@@ -223,7 +223,7 @@ void luaH_setint (lua_State *L, Hash *t, int key, const TObject *val) {
223 223
224const TObject *luaH_getint (lua_State *L, const Hash *t, int key) { 224const TObject *luaH_getint (lua_State *L, const Hash *t, int key) {
225 TObject index; 225 TObject index;
226 ttype(&index) = LUA_T_NUMBER; 226 ttype(&index) = TAG_NUMBER;
227 nvalue(&index) = key; 227 nvalue(&index) = key;
228 return luaH_get(L, t, &index); 228 return luaH_get(L, t, &index);
229} 229}
diff --git a/ltests.c b/ltests.c
index 90480097..8d712796 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 1.7 2000/02/08 16:34:31 roberto Exp roberto $ 2** $Id: ltests.c,v 1.8 2000/02/21 18:30:06 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*/
@@ -39,7 +39,7 @@ static void mem_query (lua_State *L) {
39static void hash_query (lua_State *L) { 39static void hash_query (lua_State *L) {
40 lua_Object o = luaL_nonnullarg(L, 1); 40 lua_Object o = luaL_nonnullarg(L, 1);
41 if (lua_getparam(L, 2) == LUA_NOOBJECT) { 41 if (lua_getparam(L, 2) == LUA_NOOBJECT) {
42 luaL_arg_check(L, ttype(o) == LUA_T_STRING, 1, "string expected"); 42 luaL_arg_check(L, ttype(o) == TAG_STRING, 1, "string expected");
43 lua_pushnumber(L, tsvalue(o)->hash); 43 lua_pushnumber(L, tsvalue(o)->hash);
44 } 44 }
45 else { 45 else {
@@ -75,7 +75,7 @@ static void query_strings (lua_State *L) {
75 } 75 }
76 } 76 }
77 else { 77 else {
78 TaggedString *ts = L->string_root[h].hash[s]; 78 TString *ts = L->string_root[h].hash[s];
79 for (ts = L->string_root[h].hash[s]; ts; ts = ts->nexthash) { 79 for (ts = L->string_root[h].hash[s]; ts; ts = ts->nexthash) {
80 if (ts->constindex == -1) lua_pushstring(L, "<USERDATA>"); 80 if (ts->constindex == -1) lua_pushstring(L, "<USERDATA>");
81 else lua_pushstring(L, ts->str); 81 else lua_pushstring(L, ts->str);
diff --git a/ltm.c b/ltm.c
index 3a79d48b..6a73006e 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.32 2000/02/22 18:12:46 roberto Exp roberto $ 2** $Id: ltm.c,v 1.33 2000/03/03 14:58:26 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -32,33 +32,33 @@ static int luaI_checkevent (lua_State *L, const char *name, const char *const li
32 32
33 33
34 34
35/* events in LUA_T_NIL are all allowed, since this is used as a 35/* events in TAG_NIL are all allowed, since this is used as a
36* 'placeholder' for "default" fallbacks 36* 'placeholder' for "default" fallbacks
37*/ 37*/
38/* ORDER LUA_T, ORDER IM */ 38/* ORDER LUA_T, ORDER IM */
39static const char luaT_validevents[NUM_TAGS][IM_N] = { 39static const char luaT_validevents[NUM_TAGS][IM_N] = {
40{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_USERDATA */ 40{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* TAG_USERDATA */
41{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* LUA_T_NUMBER */ 41{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* TAG_NUMBER */
42{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */ 42{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* TAG_STRING */
43{0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_ARRAY */ 43{0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* TAG_ARRAY */
44{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_LPROTO */ 44{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* TAG_LPROTO */
45{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_CPROTO */ 45{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* TAG_CPROTO */
46{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */ 46{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* TAG_NIL */
47}; 47};
48 48
49int luaT_validevent (int t, int e) { /* ORDER LUA_T */ 49int luaT_validevent (int t, int e) { /* ORDER LUA_T */
50#ifdef LUA_COMPAT_GC 50#ifdef LUA_COMPAT_GC
51 if (t == LUA_T_ARRAY && e == IM_GC) 51 if (t == TAG_ARRAY && e == IM_GC)
52 return 1; /* old versions allowed gc tag method for tables */ 52 return 1; /* old versions allowed gc tag method for tables */
53#endif 53#endif
54 return (t < LUA_T_NIL) ? 1 : luaT_validevents[-t][e]; 54 return (t < TAG_NIL) ? 1 : luaT_validevents[-t][e];
55} 55}
56 56
57 57
58static void init_entry (lua_State *L, int tag) { 58static void init_entry (lua_State *L, int tag) {
59 int i; 59 int i;
60 for (i=0; i<IM_N; i++) 60 for (i=0; i<IM_N; i++)
61 ttype(luaT_getim(L, tag, i)) = LUA_T_NIL; 61 ttype(luaT_getim(L, tag, i)) = TAG_NIL;
62} 62}
63 63
64 64
@@ -85,7 +85,7 @@ static void checktag (lua_State *L, int tag) {
85} 85}
86 86
87void luaT_realtag (lua_State *L, int tag) { 87void luaT_realtag (lua_State *L, int tag) {
88 if (!(L->last_tag <= tag && tag < LUA_T_NIL)) 88 if (!(L->last_tag <= tag && tag < TAG_NIL))
89 luaL_verror(L, "tag %d was not created by `newtag'", tag); 89 luaL_verror(L, "tag %d was not created by `newtag'", tag);
90} 90}
91 91
@@ -104,17 +104,17 @@ int lua_copytagmethods (lua_State *L, int tagto, int tagfrom) {
104 104
105int luaT_effectivetag (const TObject *o) { 105int luaT_effectivetag (const TObject *o) {
106 static const int realtag[] = { /* ORDER LUA_T */ 106 static const int realtag[] = { /* ORDER LUA_T */
107 LUA_T_USERDATA, LUA_T_NUMBER, LUA_T_STRING, LUA_T_ARRAY, 107 TAG_USERDATA, TAG_NUMBER, TAG_STRING, TAG_ARRAY,
108 LUA_T_LPROTO, LUA_T_CPROTO, LUA_T_NIL, 108 TAG_LPROTO, TAG_CPROTO, TAG_NIL,
109 LUA_T_LPROTO, LUA_T_CPROTO, /* LUA_T_LCLOSURE, LUA_T_CCLOSURE */ 109 TAG_LPROTO, TAG_CPROTO, /* TAG_LCLOSURE, TAG_CCLOSURE */
110 }; 110 };
111 int t; 111 int t;
112 switch (t = ttype(o)) { 112 switch (t = ttype(o)) {
113 case LUA_T_USERDATA: { 113 case TAG_USERDATA: {
114 int tag = o->value.ts->u.d.tag; 114 int tag = o->value.ts->u.d.tag;
115 return (tag >= 0) ? LUA_T_USERDATA : tag; /* deprecated test */ 115 return (tag >= 0) ? TAG_USERDATA : tag; /* deprecated test */
116 } 116 }
117 case LUA_T_ARRAY: return o->value.a->htag; 117 case TAG_ARRAY: return o->value.a->htag;
118 default: return realtag[-t]; 118 default: return realtag[-t];
119 } 119 }
120} 120}
@@ -149,7 +149,7 @@ void luaT_settagmethod (lua_State *L, int t, const char *event, TObject *func) {
149 if (!luaT_validevent(t, e)) 149 if (!luaT_validevent(t, e))
150 luaL_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s", 150 luaL_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s",
151 luaT_eventname[e], luaO_typenames[-t], 151 luaT_eventname[e], luaO_typenames[-t],
152 (t == LUA_T_ARRAY || t == LUA_T_USERDATA) ? " with default tag" 152 (t == TAG_ARRAY || t == TAG_USERDATA) ? " with default tag"
153 : ""); 153 : "");
154 temp = *func; 154 temp = *func;
155 *func = *luaT_getim(L, t,e); 155 *func = *luaT_getim(L, t,e);
diff --git a/lundump.c b/lundump.c
index 7aa0a93d..3dd01ba4 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.26 2000/02/17 19:17:44 lhf Exp lhf $ 2** $Id: lundump.c,v 1.18 2000/03/03 14:58:26 roberto Exp roberto $
3** load bytecodes from files 3** load bytecodes from files
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -50,7 +50,7 @@ static unsigned long LoadLong (lua_State* L, ZIO* Z)
50 return (hi<<16)|lo; 50 return (hi<<16)|lo;
51} 51}
52 52
53static real LoadNumber (lua_State* L, ZIO* Z) 53static Number LoadNumber (lua_State* L, ZIO* Z)
54{ 54{
55 char b[256]; 55 char b[256];
56 int size=ezgetc(L,Z); 56 int size=ezgetc(L,Z);
@@ -67,15 +67,15 @@ static int LoadInt (lua_State* L, ZIO* Z, const char* message)
67 return i; 67 return i;
68} 68}
69 69
70static void LoadCode (lua_State* L, TProtoFunc* tf, ZIO* Z) 70static void LoadCode (lua_State* L, Proto* tf, ZIO* Z)
71{ 71{
72 int size=LoadInt(L,Z,"code too long (%lu bytes) in %.255s"); 72 int size=LoadInt(L,Z,"code too long (%lu bytes) in %.255s");
73 tf->code=luaM_newvector(L,size,Instruction); 73 tf->code=luaM_newvector(L,size,Instruction);
74 LoadBlock(L,tf->code,size*sizeof(tf->code[0]),Z); 74 LoadBlock(L,tf->code,size*sizeof(tf->code[0]),Z);
75 if (tf->code[size-1]!=ENDCODE) luaL_verror(L,"bad code in %.255s",zname(Z)); 75 if (tf->code[size-1]!=OP_END) luaL_verror(L,"bad code in %.255s",zname(Z));
76} 76}
77 77
78static TaggedString* LoadString (lua_State* L, ZIO* Z) 78static TString* LoadString (lua_State* L, ZIO* Z)
79{ 79{
80 long size=LoadLong(L,Z); 80 long size=LoadLong(L,Z);
81 if (size==0) 81 if (size==0)
@@ -88,7 +88,7 @@ static TaggedString* LoadString (lua_State* L, ZIO* Z)
88 } 88 }
89} 89}
90 90
91static void LoadLocals (lua_State* L, TProtoFunc* tf, ZIO* Z) 91static void LoadLocals (lua_State* L, Proto* tf, ZIO* Z)
92{ 92{
93 int i,n=LoadInt(L,Z,"too many locals (%lu) in %.255s"); 93 int i,n=LoadInt(L,Z,"too many locals (%lu) in %.255s");
94 if (n==0) return; 94 if (n==0) return;
@@ -102,21 +102,21 @@ static void LoadLocals (lua_State* L, TProtoFunc* tf, ZIO* Z)
102 tf->locvars[i].varname=NULL; 102 tf->locvars[i].varname=NULL;
103} 103}
104 104
105static TProtoFunc* LoadFunction (lua_State* L, ZIO* Z, int native); 105static Proto* LoadFunction (lua_State* L, ZIO* Z, int native);
106 106
107static void LoadConstants (lua_State* L, TProtoFunc* tf, ZIO* Z, int native) 107static void LoadConstants (lua_State* L, Proto* tf, ZIO* Z, int native)
108{ 108{
109 int i,n; 109 int i,n;
110 tf->nkstr=n=LoadInt(L,Z,"too many strings (%lu) in %.255s"); 110 tf->nkstr=n=LoadInt(L,Z,"too many strings (%lu) in %.255s");
111 if (n>0) 111 if (n>0)
112 { 112 {
113 tf->kstr=luaM_newvector(L,n,TaggedString*); 113 tf->kstr=luaM_newvector(L,n,TString*);
114 for (i=0; i<n; i++) tf->kstr[i]=LoadString(L,Z); 114 for (i=0; i<n; i++) tf->kstr[i]=LoadString(L,Z);
115 } 115 }
116 tf->nknum=n=LoadInt(L,Z,"too many numbers (%lu) in %.255s"); 116 tf->nknum=n=LoadInt(L,Z,"too many numbers (%lu) in %.255s");
117 if (n>0) 117 if (n>0)
118 { 118 {
119 tf->knum=luaM_newvector(L,n,real); 119 tf->knum=luaM_newvector(L,n,Number);
120 if (native) 120 if (native)
121 LoadBlock(L,tf->knum,n*sizeof(tf->knum[0]),Z); 121 LoadBlock(L,tf->knum,n*sizeof(tf->knum[0]),Z);
122 else 122 else
@@ -125,14 +125,14 @@ static void LoadConstants (lua_State* L, TProtoFunc* tf, ZIO* Z, int native)
125 tf->nkproto=n=LoadInt(L,Z,"too many functions (%lu) in %.255s"); 125 tf->nkproto=n=LoadInt(L,Z,"too many functions (%lu) in %.255s");
126 if (n>0) 126 if (n>0)
127 { 127 {
128 tf->kproto=luaM_newvector(L,n,TProtoFunc*); 128 tf->kproto=luaM_newvector(L,n,Proto*);
129 for (i=0; i<n; i++) tf->kproto[i]=LoadFunction(L,Z,native); 129 for (i=0; i<n; i++) tf->kproto[i]=LoadFunction(L,Z,native);
130 } 130 }
131} 131}
132 132
133static TProtoFunc* LoadFunction (lua_State* L, ZIO* Z, int native) 133static Proto* LoadFunction (lua_State* L, ZIO* Z, int native)
134{ 134{
135 TProtoFunc* tf=luaF_newproto(L); 135 Proto* tf=luaF_newproto(L);
136 tf->lineDefined=LoadInt(L,Z,"lineDefined too large (%lu) in %.255s"); 136 tf->lineDefined=LoadInt(L,Z,"lineDefined too large (%lu) in %.255s");
137 tf->source=LoadString(L,Z); 137 tf->source=LoadString(L,Z);
138 if (tf->source==NULL) tf->source=luaS_new(L,zname(Z)); 138 if (tf->source==NULL) tf->source=luaS_new(L,zname(Z));
@@ -172,12 +172,12 @@ static int LoadHeader (lua_State* L, ZIO* Z)
172 native=(sizeofR!=0); 172 native=(sizeofR!=0);
173 if (native) /* test number representation */ 173 if (native) /* test number representation */
174 { 174 {
175 if (sizeofR!=sizeof(real)) 175 if (sizeofR!=sizeof(Number))
176 luaL_verror(L,"unknown number size in %.255s: read %d; expected %d", 176 luaL_verror(L,"unknown number size in %.255s: read %d; expected %d",
177 zname(Z),sizeofR,(int)sizeof(real)); 177 zname(Z),sizeofR,(int)sizeof(Number));
178 else 178 else
179 { 179 {
180 real f=0,tf=TEST_NUMBER; 180 Number f=0,tf=TEST_NUMBER;
181 LoadBlock(L,&f,sizeof(f),Z); 181 LoadBlock(L,&f,sizeof(f),Z);
182 if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */ 182 if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */
183 luaL_verror(L,"unknown number format in %.255s: " 183 luaL_verror(L,"unknown number format in %.255s: "
@@ -188,7 +188,7 @@ static int LoadHeader (lua_State* L, ZIO* Z)
188 return native; 188 return native;
189} 189}
190 190
191static TProtoFunc* LoadChunk (lua_State* L, ZIO* Z) 191static Proto* LoadChunk (lua_State* L, ZIO* Z)
192{ 192{
193 return LoadFunction(L,Z,LoadHeader(L,Z)); 193 return LoadFunction(L,Z,LoadHeader(L,Z));
194} 194}
@@ -197,7 +197,7 @@ static TProtoFunc* LoadChunk (lua_State* L, ZIO* Z)
197** load one chunk from a file or buffer 197** load one chunk from a file or buffer
198** return main if ok and NULL at EOF 198** return main if ok and NULL at EOF
199*/ 199*/
200TProtoFunc* luaU_undump1 (lua_State* L, ZIO* Z) 200Proto* luaU_undump1 (lua_State* L, ZIO* Z)
201{ 201{
202 int c=zgetc(Z); 202 int c=zgetc(Z);
203 if (c==ID_CHUNK) 203 if (c==ID_CHUNK)
diff --git a/lundump.h b/lundump.h
index 4c582ad5..b3171a80 100644
--- a/lundump.h
+++ b/lundump.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.h,v 1.18 2000/01/28 17:51:09 lhf Exp $ 2** $Id: lundump.h,v 1.13 2000/03/03 14:58:26 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*/
@@ -11,11 +11,11 @@
11#include "lzio.h" 11#include "lzio.h"
12 12
13/* load one chunk */ 13/* load one chunk */
14TProtoFunc* luaU_undump1 (lua_State* L, ZIO* Z); 14Proto* luaU_undump1 (lua_State* L, ZIO* Z);
15 15
16/* handle cases that cannot happen */ 16/* handle cases that cannot happen */
17void luaU_badconstant (lua_State* L, const char* s, int i, 17void luaU_badconstant (lua_State* L, const char* s, int i,
18 const TObject* o, const TProtoFunc* tf); 18 const TObject* o, const Proto* tf);
19 19
20/* convert number from text */ 20/* convert number from text */
21double luaU_str2d (lua_State* L, const char* b, const char* where); 21double luaU_str2d (lua_State* L, const char* b, const char* where);
diff --git a/lvm.c b/lvm.c
index 71a97d83..62a24064 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.93 2000/03/09 13:57:37 roberto Exp roberto $ 2** $Id: lvm.c,v 1.94 2000/03/10 14:38:10 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*/
@@ -33,32 +33,32 @@
33 33
34/* 34/*
35** Extra stack size to run a function: 35** Extra stack size to run a function:
36** LUA_T_LINE(1), NAME(1), TM calls(3) (plus some extra...) 36** TAG_LINE(1), NAME(1), TM calls(3) (plus some extra...)
37*/ 37*/
38#define EXTRA_STACK 8 38#define EXTRA_STACK 8
39 39
40 40
41 41
42int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */ 42int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */
43 if (ttype(obj) != LUA_T_STRING) 43 if (ttype(obj) != TAG_STRING)
44 return 1; 44 return 1;
45 else { 45 else {
46 if (!luaO_str2d(svalue(obj), &nvalue(obj))) 46 if (!luaO_str2d(svalue(obj), &nvalue(obj)))
47 return 2; 47 return 2;
48 ttype(obj) = LUA_T_NUMBER; 48 ttype(obj) = TAG_NUMBER;
49 return 0; 49 return 0;
50 } 50 }
51} 51}
52 52
53 53
54int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */ 54int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */
55 if (ttype(obj) != LUA_T_NUMBER) 55 if (ttype(obj) != TAG_NUMBER)
56 return 1; 56 return 1;
57 else { 57 else {
58 char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ 58 char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */
59 sprintf(s, "%.16g", (double)nvalue(obj)); 59 sprintf(s, "%.16g", (double)nvalue(obj));
60 tsvalue(obj) = luaS_new(L, s); 60 tsvalue(obj) = luaS_new(L, s);
61 ttype(obj) = LUA_T_STRING; 61 ttype(obj) = TAG_STRING;
62 return 0; 62 return 0;
63 } 63 }
64} 64}
@@ -66,8 +66,8 @@ int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */
66 66
67void luaV_setn (lua_State *L, Hash *t, int val) { 67void luaV_setn (lua_State *L, Hash *t, int val) {
68 TObject index, value; 68 TObject index, value;
69 ttype(&index) = LUA_T_STRING; tsvalue(&index) = luaS_new(L, "n"); 69 ttype(&index) = TAG_STRING; tsvalue(&index) = luaS_new(L, "n");
70 ttype(&value) = LUA_T_NUMBER; nvalue(&value) = val; 70 ttype(&value) = TAG_NUMBER; nvalue(&value) = val;
71 luaH_set(L, t, &index, &value); 71 luaH_set(L, t, &index, &value);
72} 72}
73 73
@@ -79,8 +79,8 @@ void luaV_closure (lua_State *L, int nelems) {
79 L->top -= nelems; 79 L->top -= nelems;
80 while (nelems--) 80 while (nelems--)
81 c->consts[nelems+1] = *(L->top-1+nelems); 81 c->consts[nelems+1] = *(L->top-1+nelems);
82 ttype(L->top-1) = (ttype(&c->consts[0]) == LUA_T_CPROTO) ? 82 ttype(L->top-1) = (ttype(&c->consts[0]) == TAG_CPROTO) ?
83 LUA_T_CCLOSURE : LUA_T_LCLOSURE; 83 TAG_CCLOSURE : TAG_LCLOSURE;
84 (L->top-1)->value.cl = c; 84 (L->top-1)->value.cl = c;
85 } 85 }
86} 86}
@@ -93,9 +93,9 @@ void luaV_closure (lua_State *L, int nelems) {
93void luaV_gettable (lua_State *L, StkId top) { 93void luaV_gettable (lua_State *L, StkId top) {
94 TObject *table = top-2; 94 TObject *table = top-2;
95 const TObject *im; 95 const TObject *im;
96 if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable TM */ 96 if (ttype(table) != TAG_ARRAY) { /* not a table, get gettable TM */
97 im = luaT_getimbyObj(L, table, IM_GETTABLE); 97 im = luaT_getimbyObj(L, table, IM_GETTABLE);
98 if (ttype(im) == LUA_T_NIL) { 98 if (ttype(im) == TAG_NIL) {
99 L->top = top; 99 L->top = top;
100 luaG_indexerror(L, table); 100 luaG_indexerror(L, table);
101 } 101 }
@@ -103,10 +103,10 @@ void luaV_gettable (lua_State *L, StkId top) {
103 else { /* object is a table... */ 103 else { /* object is a table... */
104 int tg = table->value.a->htag; 104 int tg = table->value.a->htag;
105 im = luaT_getim(L, tg, IM_GETTABLE); 105 im = luaT_getim(L, tg, IM_GETTABLE);
106 if (ttype(im) == LUA_T_NIL) { /* and does not have a `gettable' TM */ 106 if (ttype(im) == TAG_NIL) { /* and does not have a `gettable' TM */
107 const TObject *h = luaH_get(L, avalue(table), table+1); 107 const TObject *h = luaH_get(L, avalue(table), table+1);
108 if (ttype(h) == LUA_T_NIL && 108 if (ttype(h) == TAG_NIL &&
109 (ttype(im=luaT_getim(L, tg, IM_INDEX)) != LUA_T_NIL)) { 109 (ttype(im=luaT_getim(L, tg, IM_INDEX)) != TAG_NIL)) {
110 /* result is nil and there is an `index' tag method */ 110 /* result is nil and there is an `index' tag method */
111 L->top = top; 111 L->top = top;
112 luaD_callTM(L, im, 2, 1); /* calls it */ 112 luaD_callTM(L, im, 2, 1); /* calls it */
@@ -128,15 +128,15 @@ void luaV_gettable (lua_State *L, StkId top) {
128*/ 128*/
129void luaV_settable (lua_State *L, StkId t, StkId top) { 129void luaV_settable (lua_State *L, StkId t, StkId top) {
130 const TObject *im; 130 const TObject *im;
131 if (ttype(t) != LUA_T_ARRAY) { /* not a table, get `settable' method */ 131 if (ttype(t) != TAG_ARRAY) { /* not a table, get `settable' method */
132 L->top = top; 132 L->top = top;
133 im = luaT_getimbyObj(L, t, IM_SETTABLE); 133 im = luaT_getimbyObj(L, t, IM_SETTABLE);
134 if (ttype(im) == LUA_T_NIL) 134 if (ttype(im) == TAG_NIL)
135 luaG_indexerror(L, t); 135 luaG_indexerror(L, t);
136 } 136 }
137 else { /* object is a table... */ 137 else { /* object is a table... */
138 im = luaT_getim(L, avalue(t)->htag, IM_SETTABLE); 138 im = luaT_getim(L, avalue(t)->htag, IM_SETTABLE);
139 if (ttype(im) == LUA_T_NIL) { /* and does not have a `settable' method */ 139 if (ttype(im) == TAG_NIL) { /* and does not have a `settable' method */
140 luaH_set(L, avalue(t), t+1, top-1); 140 luaH_set(L, avalue(t), t+1, top-1);
141 return; 141 return;
142 } 142 }
@@ -155,7 +155,7 @@ void luaV_settable (lua_State *L, StkId t, StkId top) {
155 155
156 156
157void luaV_rawsettable (lua_State *L, StkId t) { 157void luaV_rawsettable (lua_State *L, StkId t) {
158 if (ttype(t) != LUA_T_ARRAY) 158 if (ttype(t) != TAG_ARRAY)
159 lua_error(L, "indexed expression not a table"); 159 lua_error(L, "indexed expression not a table");
160 else { 160 else {
161 luaH_set(L, avalue(t), t+1, L->top-1); 161 luaH_set(L, avalue(t), t+1, L->top-1);
@@ -167,12 +167,12 @@ void luaV_rawsettable (lua_State *L, StkId t) {
167void luaV_getglobal (lua_State *L, GlobalVar *gv, StkId top) { 167void luaV_getglobal (lua_State *L, GlobalVar *gv, StkId top) {
168 const TObject *value = &gv->value; 168 const TObject *value = &gv->value;
169 TObject *im = luaT_getimbyObj(L, value, IM_GETGLOBAL); 169 TObject *im = luaT_getimbyObj(L, value, IM_GETGLOBAL);
170 if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ 170 if (ttype(im) == TAG_NIL) /* is there a tag method? */
171 *top = *value; /* default behavior */ 171 *top = *value; /* default behavior */
172 else { /* tag method */ 172 else { /* tag method */
173 luaD_checkstack(L, 3); 173 luaD_checkstack(L, 3);
174 *top = *im; 174 *top = *im;
175 ttype(top+1) = LUA_T_STRING; 175 ttype(top+1) = TAG_STRING;
176 tsvalue(top+1) = gv->name; /* global name */ 176 tsvalue(top+1) = gv->name; /* global name */
177 *(top+2) = *value; 177 *(top+2) = *value;
178 L->top = top+3; 178 L->top = top+3;
@@ -184,13 +184,13 @@ void luaV_getglobal (lua_State *L, GlobalVar *gv, StkId top) {
184void luaV_setglobal (lua_State *L, GlobalVar *gv, StkId top) { 184void luaV_setglobal (lua_State *L, GlobalVar *gv, StkId top) {
185 const TObject *oldvalue = &gv->value; 185 const TObject *oldvalue = &gv->value;
186 const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL); 186 const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL);
187 if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ 187 if (ttype(im) == TAG_NIL) /* is there a tag method? */
188 gv->value = *(top-1); 188 gv->value = *(top-1);
189 else { 189 else {
190 luaD_checkstack(L, 3); 190 luaD_checkstack(L, 3);
191 *(top+2) = *(top-1); /* new value */ 191 *(top+2) = *(top-1); /* new value */
192 *(top+1) = *oldvalue; 192 *(top+1) = *oldvalue;
193 ttype(top) = LUA_T_STRING; 193 ttype(top) = TAG_STRING;
194 tsvalue(top) = gv->name; 194 tsvalue(top) = gv->name;
195 *(top-1) = *im; 195 *(top-1) = *im;
196 L->top = top+3; 196 L->top = top+3;
@@ -203,11 +203,11 @@ static void call_binTM (lua_State *L, StkId top, IMS event, const char *msg) {
203 /* try first operand */ 203 /* try first operand */
204 const TObject *im = luaT_getimbyObj(L, top-2, event); 204 const TObject *im = luaT_getimbyObj(L, top-2, event);
205 L->top = top; 205 L->top = top;
206 if (ttype(im) == LUA_T_NIL) { 206 if (ttype(im) == TAG_NIL) {
207 im = luaT_getimbyObj(L, top-1, event); /* try second operand */ 207 im = luaT_getimbyObj(L, top-1, event); /* try second operand */
208 if (ttype(im) == LUA_T_NIL) { 208 if (ttype(im) == TAG_NIL) {
209 im = luaT_getim(L, 0, event); /* try a `global' method */ 209 im = luaT_getim(L, 0, event); /* try a `global' method */
210 if (ttype(im) == LUA_T_NIL) 210 if (ttype(im) == TAG_NIL)
211 lua_error(L, msg); 211 lua_error(L, msg);
212 } 212 }
213 } 213 }
@@ -221,7 +221,7 @@ static void call_arith (lua_State *L, StkId top, IMS event) {
221} 221}
222 222
223 223
224static int luaV_strcomp (const TaggedString *ls, const TaggedString *rs) { 224static int luaV_strcomp (const TString *ls, const TString *rs) {
225 const char *l = ls->str; 225 const char *l = ls->str;
226 long ll = ls->u.s.len; 226 long ll = ls->u.s.len;
227 const char *r = rs->str; 227 const char *r = rs->str;
@@ -243,9 +243,9 @@ static int luaV_strcomp (const TaggedString *ls, const TaggedString *rs) {
243 243
244 244
245int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top) { 245int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top) {
246 if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) 246 if (ttype(l) == TAG_NUMBER && ttype(r) == TAG_NUMBER)
247 return (nvalue(l) < nvalue(r)); 247 return (nvalue(l) < nvalue(r));
248 else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING) 248 else if (ttype(l) == TAG_STRING && ttype(r) == TAG_STRING)
249 return (luaV_strcomp(tsvalue(l), tsvalue(r)) < 0); 249 return (luaV_strcomp(tsvalue(l), tsvalue(r)) < 0);
250 else { /* call TM */ 250 else { /* call TM */
251 luaD_checkstack(L, 2); 251 luaD_checkstack(L, 2);
@@ -253,14 +253,14 @@ int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top)
253 *top++ = *r; 253 *top++ = *r;
254 call_binTM(L, top, IM_LT, "unexpected type in comparison"); 254 call_binTM(L, top, IM_LT, "unexpected type in comparison");
255 L->top--; 255 L->top--;
256 return (ttype(L->top) != LUA_T_NIL); 256 return (ttype(L->top) != TAG_NIL);
257 } 257 }
258} 258}
259 259
260 260
261#define setbool(o,cond) if (cond) { \ 261#define setbool(o,cond) if (cond) { \
262 ttype(o) = LUA_T_NUMBER; nvalue(o) = 1.0; } \ 262 ttype(o) = TAG_NUMBER; nvalue(o) = 1.0; } \
263 else ttype(o) = LUA_T_NIL 263 else ttype(o) = TAG_NIL
264 264
265 265
266static void strconc (lua_State *L, int total, StkId top) { 266static void strconc (lua_State *L, int total, StkId top) {
@@ -295,7 +295,7 @@ void luaV_pack (lua_State *L, StkId firstelem, int nvararg, TObject *tab) {
295 int i; 295 int i;
296 Hash *htab; 296 Hash *htab;
297 htab = avalue(tab) = luaH_new(L, nvararg+1); /* +1 for field `n' */ 297 htab = avalue(tab) = luaH_new(L, nvararg+1); /* +1 for field `n' */
298 ttype(tab) = LUA_T_ARRAY; 298 ttype(tab) = TAG_ARRAY;
299 for (i=0; i<nvararg; i++) 299 for (i=0; i<nvararg; i++)
300 luaH_setint(L, htab, i+1, firstelem+i); 300 luaH_setint(L, htab, i+1, firstelem+i);
301 luaV_setn(L, htab, nvararg); /* store counter in field `n' */ 301 luaV_setn(L, htab, nvararg); /* store counter in field `n' */
@@ -321,11 +321,11 @@ static void adjust_varargs (lua_State *L, StkId base, int nfixargs) {
321** Executes the given Lua function. Parameters are between [base,top). 321** Executes the given Lua function. Parameters are between [base,top).
322** Returns n such that the the results are between [n,top). 322** Returns n such that the the results are between [n,top).
323*/ 323*/
324StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, 324StkId luaV_execute (lua_State *L, const Closure *cl, const Proto *tf,
325 register StkId base) { 325 register StkId base) {
326 register StkId top; /* keep top local, for performance */ 326 register StkId top; /* keep top local, for performance */
327 register const Instruction *pc = tf->code; 327 register const Instruction *pc = tf->code;
328 TaggedString **kstr = tf->kstr; 328 TString **kstr = tf->kstr;
329 if (L->callhook) 329 if (L->callhook)
330 luaD_callHook(L, base-1, L->callhook, "call"); 330 luaD_callHook(L, base-1, L->callhook, "call");
331 luaD_checkstack(L, tf->maxstacksize+EXTRA_STACK); 331 luaD_checkstack(L, tf->maxstacksize+EXTRA_STACK);
@@ -340,124 +340,124 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
340 register Instruction i = *pc++; 340 register Instruction i = *pc++;
341 switch (GET_OPCODE(i)) { 341 switch (GET_OPCODE(i)) {
342 342
343 case ENDCODE: 343 case OP_END:
344 return L->top; /* no results */ 344 return L->top; /* no results */
345 345
346 case RETCODE: 346 case OP_RETURN:
347 L->top = top; 347 L->top = top;
348 return base+GETARG_U(i); 348 return base+GETARG_U(i);
349 349
350 case CALL: 350 case OP_CALL:
351 L->top = top; 351 L->top = top;
352 luaD_call(L, base+GETARG_A(i), GETARG_B(i)); 352 luaD_call(L, base+GETARG_A(i), GETARG_B(i));
353 top = L->top; 353 top = L->top;
354 break; 354 break;
355 355
356 case TAILCALL: 356 case OP_TAILCALL:
357 L->top = top; 357 L->top = top;
358 luaD_call(L, base+GETARG_A(i), MULT_RET); 358 luaD_call(L, base+GETARG_A(i), MULT_RET);
359 return base+GETARG_B(i); 359 return base+GETARG_B(i);
360 360
361 case PUSHNIL: { 361 case OP_PUSHNIL: {
362 int n = GETARG_U(i); 362 int n = GETARG_U(i);
363 LUA_ASSERT(L, n>0, "invalid argument"); 363 LUA_ASSERT(L, n>0, "invalid argument");
364 do { 364 do {
365 ttype(top++) = LUA_T_NIL; 365 ttype(top++) = TAG_NIL;
366 } while (--n > 0); 366 } while (--n > 0);
367 break; 367 break;
368 } 368 }
369 369
370 case POP: 370 case OP_POP:
371 top -= GETARG_U(i); 371 top -= GETARG_U(i);
372 break; 372 break;
373 373
374 case PUSHINT: 374 case OP_PUSHINT:
375 ttype(top) = LUA_T_NUMBER; 375 ttype(top) = TAG_NUMBER;
376 nvalue(top) = (real)GETARG_S(i); 376 nvalue(top) = (Number)GETARG_S(i);
377 top++; 377 top++;
378 break; 378 break;
379 379
380 case PUSHSTRING: 380 case OP_PUSHSTRING:
381 ttype(top) = LUA_T_STRING; 381 ttype(top) = TAG_STRING;
382 tsvalue(top) = kstr[GETARG_U(i)]; 382 tsvalue(top) = kstr[GETARG_U(i)];
383 top++; 383 top++;
384 break; 384 break;
385 385
386 case PUSHNUM: 386 case OP_PUSHNUM:
387 ttype(top) = LUA_T_NUMBER; 387 ttype(top) = TAG_NUMBER;
388 nvalue(top) = tf->knum[GETARG_U(i)]; 388 nvalue(top) = tf->knum[GETARG_U(i)];
389 top++; 389 top++;
390 break; 390 break;
391 391
392 case PUSHNEGNUM: 392 case OP_PUSHNEGNUM:
393 ttype(top) = LUA_T_NUMBER; 393 ttype(top) = TAG_NUMBER;
394 nvalue(top) = -tf->knum[GETARG_U(i)]; 394 nvalue(top) = -tf->knum[GETARG_U(i)];
395 top++; 395 top++;
396 break; 396 break;
397 397
398 case PUSHUPVALUE: 398 case OP_PUSHUPVALUE:
399 *top++ = cl->consts[GETARG_U(i)+1]; 399 *top++ = cl->consts[GETARG_U(i)+1];
400 break; 400 break;
401 401
402 case PUSHLOCAL: 402 case OP_PUSHLOCAL:
403 *top++ = *(base+GETARG_U(i)); 403 *top++ = *(base+GETARG_U(i));
404 break; 404 break;
405 405
406 case GETGLOBAL: 406 case OP_GETGLOBAL:
407 luaV_getglobal(L, kstr[GETARG_U(i)]->u.s.gv, top); 407 luaV_getglobal(L, kstr[GETARG_U(i)]->u.s.gv, top);
408 top++; 408 top++;
409 break; 409 break;
410 410
411 case GETTABLE: 411 case OP_GETTABLE:
412 luaV_gettable(L, top); 412 luaV_gettable(L, top);
413 top--; 413 top--;
414 break; 414 break;
415 415
416 case GETDOTTED: 416 case OP_GETDOTTED:
417 ttype(top) = LUA_T_STRING; 417 ttype(top) = TAG_STRING;
418 tsvalue(top++) = kstr[GETARG_U(i)]; 418 tsvalue(top++) = kstr[GETARG_U(i)];
419 luaV_gettable(L, top); 419 luaV_gettable(L, top);
420 top--; 420 top--;
421 break; 421 break;
422 422
423 case PUSHSELF: { 423 case OP_PUSHSELF: {
424 TObject receiver; 424 TObject receiver;
425 receiver = *(top-1); 425 receiver = *(top-1);
426 ttype(top) = LUA_T_STRING; 426 ttype(top) = TAG_STRING;
427 tsvalue(top++) = kstr[GETARG_U(i)]; 427 tsvalue(top++) = kstr[GETARG_U(i)];
428 luaV_gettable(L, top); 428 luaV_gettable(L, top);
429 *(top-1) = receiver; 429 *(top-1) = receiver;
430 break; 430 break;
431 } 431 }
432 432
433 case CREATETABLE: 433 case OP_CREATETABLE:
434 L->top = top; 434 L->top = top;
435 luaC_checkGC(L); 435 luaC_checkGC(L);
436 avalue(top) = luaH_new(L, GETARG_U(i)); 436 avalue(top) = luaH_new(L, GETARG_U(i));
437 ttype(top) = LUA_T_ARRAY; 437 ttype(top) = TAG_ARRAY;
438 top++; 438 top++;
439 break; 439 break;
440 440
441 case SETLOCAL: 441 case OP_SETLOCAL:
442 *(base+GETARG_U(i)) = *(--top); 442 *(base+GETARG_U(i)) = *(--top);
443 break; 443 break;
444 444
445 case SETGLOBAL: 445 case OP_SETGLOBAL:
446 luaV_setglobal(L, kstr[GETARG_U(i)]->u.s.gv, top); 446 luaV_setglobal(L, kstr[GETARG_U(i)]->u.s.gv, top);
447 top--; 447 top--;
448 break; 448 break;
449 449
450 case SETTABLEPOP: 450 case OP_SETTABLEPOP:
451 luaV_settable(L, top-3, top); 451 luaV_settable(L, top-3, top);
452 top -= 3; /* pop table, index, and value */ 452 top -= 3; /* pop table, index, and value */
453 break; 453 break;
454 454
455 case SETTABLE: 455 case OP_SETTABLE:
456 luaV_settable(L, top-3-GETARG_U(i), top); 456 luaV_settable(L, top-3-GETARG_U(i), top);
457 top--; /* pop value */ 457 top--; /* pop value */
458 break; 458 break;
459 459
460 case SETLIST: { 460 case OP_SETLIST: {
461 int aux = GETARG_A(i) * LFIELDS_PER_FLUSH; 461 int aux = GETARG_A(i) * LFIELDS_PER_FLUSH;
462 int n = GETARG_B(i)+1; 462 int n = GETARG_B(i)+1;
463 Hash *arr = avalue(top-n-1); 463 Hash *arr = avalue(top-n-1);
@@ -467,7 +467,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
467 break; 467 break;
468 } 468 }
469 469
470 case SETMAP: { 470 case OP_SETMAP: {
471 int n = GETARG_U(i); 471 int n = GETARG_U(i);
472 StkId finaltop = top-2*(n+1); 472 StkId finaltop = top-2*(n+1);
473 Hash *arr = avalue(finaltop-1); 473 Hash *arr = avalue(finaltop-1);
@@ -479,7 +479,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
479 break; 479 break;
480 } 480 }
481 481
482 case ADDOP: 482 case OP_ADD:
483 if (tonumber(top-1) || tonumber(top-2)) 483 if (tonumber(top-1) || tonumber(top-2))
484 call_arith(L, top, IM_ADD); 484 call_arith(L, top, IM_ADD);
485 else 485 else
@@ -487,17 +487,17 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
487 top--; 487 top--;
488 break; 488 break;
489 489
490 case ADDI: 490 case OP_ADDI:
491 if (tonumber(top-1)) { 491 if (tonumber(top-1)) {
492 ttype(top) = LUA_T_NUMBER; 492 ttype(top) = TAG_NUMBER;
493 nvalue(top) = (real)GETARG_S(i); 493 nvalue(top) = (Number)GETARG_S(i);
494 call_arith(L, top+1, IM_ADD); 494 call_arith(L, top+1, IM_ADD);
495 } 495 }
496 else 496 else
497 nvalue(top-1) += (real)GETARG_S(i); 497 nvalue(top-1) += (Number)GETARG_S(i);
498 break; 498 break;
499 499
500 case SUBOP: 500 case OP_SUB:
501 if (tonumber(top-1) || tonumber(top-2)) 501 if (tonumber(top-1) || tonumber(top-2))
502 call_arith(L, top, IM_SUB); 502 call_arith(L, top, IM_SUB);
503 else 503 else
@@ -505,7 +505,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
505 top--; 505 top--;
506 break; 506 break;
507 507
508 case MULTOP: 508 case OP_MULT:
509 if (tonumber(top-1) || tonumber(top-2)) 509 if (tonumber(top-1) || tonumber(top-2))
510 call_arith(L, top, IM_MUL); 510 call_arith(L, top, IM_MUL);
511 else 511 else
@@ -513,7 +513,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
513 top--; 513 top--;
514 break; 514 break;
515 515
516 case DIVOP: 516 case OP_DIV:
517 if (tonumber(top-1) || tonumber(top-2)) 517 if (tonumber(top-1) || tonumber(top-2))
518 call_arith(L, top, IM_DIV); 518 call_arith(L, top, IM_DIV);
519 else 519 else
@@ -521,12 +521,12 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
521 top--; 521 top--;
522 break; 522 break;
523 523
524 case POWOP: 524 case OP_POW:
525 call_binTM(L, top, IM_POW, "undefined operation"); 525 call_binTM(L, top, IM_POW, "undefined operation");
526 top--; 526 top--;
527 break; 527 break;
528 528
529 case CONCOP: { 529 case OP_CONC: {
530 int n = GETARG_U(i); 530 int n = GETARG_U(i);
531 strconc(L, n, top); 531 strconc(L, n, top);
532 top -= n-1; 532 top -= n-1;
@@ -535,80 +535,80 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
535 break; 535 break;
536 } 536 }
537 537
538 case MINUSOP: 538 case OP_MINUS:
539 if (tonumber(top-1)) { 539 if (tonumber(top-1)) {
540 ttype(top) = LUA_T_NIL; 540 ttype(top) = TAG_NIL;
541 call_arith(L, top+1, IM_UNM); 541 call_arith(L, top+1, IM_UNM);
542 } 542 }
543 else 543 else
544 nvalue(top-1) = -nvalue(top-1); 544 nvalue(top-1) = -nvalue(top-1);
545 break; 545 break;
546 546
547 case NOTOP: 547 case OP_NOT:
548 ttype(top-1) = 548 ttype(top-1) =
549 (ttype(top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL; 549 (ttype(top-1) == TAG_NIL) ? TAG_NUMBER : TAG_NIL;
550 nvalue(top-1) = 1; 550 nvalue(top-1) = 1;
551 break; 551 break;
552 552
553 case IFNEQJMP: 553 case OP_IFNEQJMP:
554 top -= 2; 554 top -= 2;
555 if (!luaO_equalObj(top, top+1)) pc += GETARG_S(i); 555 if (!luaO_equalObj(top, top+1)) pc += GETARG_S(i);
556 break; 556 break;
557 557
558 case IFEQJMP: 558 case OP_IFEQJMP:
559 top -= 2; 559 top -= 2;
560 if (luaO_equalObj(top, top+1)) pc += GETARG_S(i); 560 if (luaO_equalObj(top, top+1)) pc += GETARG_S(i);
561 break; 561 break;
562 562
563 case IFLTJMP: 563 case OP_IFLTJMP:
564 top -= 2; 564 top -= 2;
565 if (luaV_lessthan(L, top, top+1, top+2)) pc += GETARG_S(i); 565 if (luaV_lessthan(L, top, top+1, top+2)) pc += GETARG_S(i);
566 break; 566 break;
567 567
568 case IFLEJMP: /* a <= b === !(b<a) */ 568 case OP_IFLEJMP: /* a <= b === !(b<a) */
569 top -= 2; 569 top -= 2;
570 if (!luaV_lessthan(L, top+1, top, top+2)) pc += GETARG_S(i); 570 if (!luaV_lessthan(L, top+1, top, top+2)) pc += GETARG_S(i);
571 break; 571 break;
572 572
573 case IFGTJMP: /* a > b === (b<a) */ 573 case OP_IFGTJMP: /* a > b === (b<a) */
574 top -= 2; 574 top -= 2;
575 if (luaV_lessthan(L, top+1, top, top+2)) pc += GETARG_S(i); 575 if (luaV_lessthan(L, top+1, top, top+2)) pc += GETARG_S(i);
576 break; 576 break;
577 577
578 case IFGEJMP: /* a >= b === !(a<b) */ 578 case OP_IFGEJMP: /* a >= b === !(a<b) */
579 top -= 2; 579 top -= 2;
580 if (!luaV_lessthan(L, top, top+1, top+2)) pc += GETARG_S(i); 580 if (!luaV_lessthan(L, top, top+1, top+2)) pc += GETARG_S(i);
581 break; 581 break;
582 582
583 case IFTJMP: 583 case OP_IFTJMP:
584 if (ttype(--top) != LUA_T_NIL) pc += GETARG_S(i); 584 if (ttype(--top) != TAG_NIL) pc += GETARG_S(i);
585 break; 585 break;
586 586
587 case IFFJMP: 587 case OP_IFFJMP:
588 if (ttype(--top) == LUA_T_NIL) pc += GETARG_S(i); 588 if (ttype(--top) == TAG_NIL) pc += GETARG_S(i);
589 break; 589 break;
590 590
591 case ONTJMP: 591 case OP_ONTJMP:
592 if (ttype(top-1) != LUA_T_NIL) pc += GETARG_S(i); 592 if (ttype(top-1) != TAG_NIL) pc += GETARG_S(i);
593 else top--; 593 else top--;
594 break; 594 break;
595 595
596 case ONFJMP: 596 case OP_ONFJMP:
597 if (ttype(top-1) == LUA_T_NIL) pc += GETARG_S(i); 597 if (ttype(top-1) == TAG_NIL) pc += GETARG_S(i);
598 else top--; 598 else top--;
599 break; 599 break;
600 600
601 case JMP: 601 case OP_JMP:
602 pc += GETARG_S(i); 602 pc += GETARG_S(i);
603 break; 603 break;
604 604
605 case PUSHNILJMP: 605 case OP_PUSHNILJMP:
606 ttype(top++) = LUA_T_NIL; 606 ttype(top++) = TAG_NIL;
607 pc++; 607 pc++;
608 break; 608 break;
609 609
610 case CLOSURE: 610 case OP_CLOSURE:
611 ttype(top) = LUA_T_LPROTO; 611 ttype(top) = TAG_LPROTO;
612 tfvalue(top) = tf->kproto[GETARG_A(i)]; 612 tfvalue(top) = tf->kproto[GETARG_A(i)];
613 L->top = ++top; 613 L->top = ++top;
614 luaV_closure(L, GETARG_B(i)); 614 luaV_closure(L, GETARG_B(i));
@@ -616,14 +616,14 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
616 luaC_checkGC(L); 616 luaC_checkGC(L);
617 break; 617 break;
618 618
619 case SETLINE: 619 case OP_SETLINE:
620 if ((base-1)->ttype != LUA_T_LINE) { 620 if ((base-1)->ttype != TAG_LINE) {
621 /* open space for LINE value */ 621 /* open space for LINE value */
622 int n = top-base; 622 int n = top-base;
623 while (n--) base[n+1] = base[n]; 623 while (n--) base[n+1] = base[n];
624 base++; 624 base++;
625 top++; 625 top++;
626 (base-1)->ttype = LUA_T_LINE; 626 (base-1)->ttype = TAG_LINE;
627 } 627 }
628 (base-1)->value.i = GETARG_U(i); 628 (base-1)->value.i = GETARG_U(i);
629 if (L->linehook) { 629 if (L->linehook) {
diff --git a/lvm.h b/lvm.h
index b3033200..1a733a44 100644
--- a/lvm.h
+++ b/lvm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.h,v 1.17 2000/03/03 14:58:26 roberto Exp $ 2** $Id: lvm.h,v 1.18 2000/03/09 00:19:22 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*/
@@ -13,8 +13,8 @@
13#include "ltm.h" 13#include "ltm.h"
14 14
15 15
16#define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (luaV_tonumber(o) != 0)) 16#define tonumber(o) ((ttype(o) != TAG_NUMBER) && (luaV_tonumber(o) != 0))
17#define tostring(L,o) ((ttype(o) != LUA_T_STRING) && (luaV_tostring(L, o) != 0)) 17#define tostring(L,o) ((ttype(o) != TAG_STRING) && (luaV_tostring(L, o) != 0))
18 18
19 19
20void luaV_pack (lua_State *L, StkId firstel, int nvararg, TObject *tab); 20void luaV_pack (lua_State *L, StkId firstel, int nvararg, TObject *tab);
@@ -26,7 +26,7 @@ void luaV_settable (lua_State *L, StkId t, StkId top);
26void luaV_rawsettable (lua_State *L, StkId t); 26void luaV_rawsettable (lua_State *L, StkId t);
27void luaV_getglobal (lua_State *L, GlobalVar *gv, StkId top); 27void luaV_getglobal (lua_State *L, GlobalVar *gv, StkId top);
28void luaV_setglobal (lua_State *L, GlobalVar *gv, StkId top); 28void luaV_setglobal (lua_State *L, GlobalVar *gv, StkId top);
29StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, StkId base); 29StkId luaV_execute (lua_State *L, const Closure *cl, const Proto *tf, StkId base);
30void luaV_closure (lua_State *L, int nelems); 30void luaV_closure (lua_State *L, int nelems);
31int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top); 31int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top);
32 32