diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-12-23 16:19:57 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-12-23 16:19:57 -0200 |
| commit | b1b0c219f5255a0cd0921ebc0a77a81f99b72532 (patch) | |
| tree | 7cb4d9cbbdb1309b94794eb75694b02f2b08f75a | |
| parent | be3212de781786c0a68365dee1d3510407b5c325 (diff) | |
| download | lua-b1b0c219f5255a0cd0921ebc0a77a81f99b72532.tar.gz lua-b1b0c219f5255a0cd0921ebc0a77a81f99b72532.tar.bz2 lua-b1b0c219f5255a0cd0921ebc0a77a81f99b72532.zip | |
new ttypes to distinguish between C closures and Lua closures.
| -rw-r--r-- | lapi.c | 81 | ||||
| -rw-r--r-- | lapi.h | 8 | ||||
| -rw-r--r-- | lbuiltin.c | 6 | ||||
| -rw-r--r-- | ldebug.c | 23 | ||||
| -rw-r--r-- | ldo.c | 71 | ||||
| -rw-r--r-- | lgc.c | 7 | ||||
| -rw-r--r-- | lobject.c | 28 | ||||
| -rw-r--r-- | lobject.h | 28 | ||||
| -rw-r--r-- | lparser.c | 6 | ||||
| -rw-r--r-- | lref.c | 11 | ||||
| -rw-r--r-- | ltable.c | 6 | ||||
| -rw-r--r-- | ltests.c | 13 | ||||
| -rw-r--r-- | ltm.c | 26 | ||||
| -rw-r--r-- | lundump.c | 4 | ||||
| -rw-r--r-- | lvm.c | 9 |
15 files changed, 180 insertions, 147 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.63 1999/12/06 12:03:45 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.64 1999/12/14 18:31:20 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 | */ |
| @@ -30,19 +30,13 @@ const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" | |||
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | 32 | ||
| 33 | lua_Type luaA_normalizedtype (const TObject *o) { | 33 | const lua_Type luaA_normtype[] = { /* ORDER LUA_T */ |
| 34 | int t = ttype(o); | 34 | LUA_T_USERDATA, LUA_T_NUMBER, LUA_T_STRING, LUA_T_ARRAY, |
| 35 | switch (t) { | 35 | LUA_T_LPROTO, LUA_T_CPROTO, LUA_T_NIL, |
| 36 | case LUA_T_PMARK: | 36 | LUA_T_LCLOSURE, LUA_T_CCLOSURE, |
| 37 | return LUA_T_PROTO; | 37 | LUA_T_LCLOSURE, LUA_T_CCLOSURE, /* LUA_T_LCLMARK, LUA_T_CCLMARK */ |
| 38 | case LUA_T_CMARK: | 38 | LUA_T_LPROTO, LUA_T_CPROTO /* LUA_T_LMARK, LUA_T_CMARK */ |
| 39 | return LUA_T_CPROTO; | 39 | }; |
| 40 | case LUA_T_CLMARK: | ||
| 41 | return LUA_T_CLOSURE; | ||
| 42 | default: | ||
| 43 | return t; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | 40 | ||
| 47 | 41 | ||
| 48 | void luaA_setnormalized (TObject *d, const TObject *s) { | 42 | void luaA_setnormalized (TObject *d, const TObject *s) { |
| @@ -52,7 +46,15 @@ void luaA_setnormalized (TObject *d, const TObject *s) { | |||
| 52 | 46 | ||
| 53 | 47 | ||
| 54 | const TObject *luaA_protovalue (const TObject *o) { | 48 | const TObject *luaA_protovalue (const TObject *o) { |
| 55 | return (luaA_normalizedtype(o) == LUA_T_CLOSURE) ? protovalue(o) : o; | 49 | switch (luaA_normalizedtype(o)) { |
| 50 | case LUA_T_CCLOSURE: case LUA_T_LCLOSURE: | ||
| 51 | return protovalue(o); | ||
| 52 | default: | ||
| 53 | LUA_ASSERT(L, luaA_normalizedtype(o) == LUA_T_LPROTO || | ||
| 54 | luaA_normalizedtype(o) == LUA_T_CPROTO, | ||
| 55 | "invalid `function'"); | ||
| 56 | return o; | ||
| 57 | } | ||
| 56 | } | 58 | } |
| 57 | 59 | ||
| 58 | 60 | ||
| @@ -228,26 +230,32 @@ int lua_isnumber (lua_State *L, lua_Object o) { | |||
| 228 | } | 230 | } |
| 229 | 231 | ||
| 230 | int lua_isstring (lua_State *L, lua_Object o) { | 232 | int lua_isstring (lua_State *L, lua_Object o) { |
| 231 | int t = lua_tag(L, o); | 233 | UNUSED(L); |
| 232 | return (t == LUA_T_STRING) || (t == LUA_T_NUMBER); | 234 | return (o != LUA_NOOBJECT && (ttype(o) == LUA_T_STRING || |
| 235 | ttype(o) == LUA_T_NUMBER)); | ||
| 233 | } | 236 | } |
| 234 | 237 | ||
| 235 | int lua_isfunction (lua_State *L, lua_Object o) { | 238 | int lua_isfunction (lua_State *L, lua_Object o) { |
| 236 | int t = lua_tag(L, o); | 239 | return *lua_type(L, o) == 'f'; |
| 237 | return (t == LUA_T_PROTO) || (t == LUA_T_CPROTO); | ||
| 238 | } | 240 | } |
| 239 | 241 | ||
| 240 | int lua_equal(lua_State *L, lua_Object o1, lua_Object o2) { | 242 | int lua_equal(lua_State *L, lua_Object o1, lua_Object o2) { |
| 241 | UNUSED(L); | 243 | UNUSED(L); |
| 242 | if (o1 == LUA_NOOBJECT || o2 == LUA_NOOBJECT) return (o1 == o2); | 244 | if (o1 == LUA_NOOBJECT || o2 == LUA_NOOBJECT) |
| 243 | else return luaO_equalObj(o1, o2); | 245 | return (o1 == o2); |
| 246 | else { | ||
| 247 | TObject obj1, obj2; | ||
| 248 | luaA_setnormalized(&obj1, o1); | ||
| 249 | luaA_setnormalized(&obj2, o2); | ||
| 250 | return luaO_equalObj(&obj1, &obj2); | ||
| 251 | } | ||
| 244 | } | 252 | } |
| 245 | 253 | ||
| 246 | 254 | ||
| 247 | double lua_getnumber (lua_State *L, lua_Object obj) { | 255 | double lua_getnumber (lua_State *L, lua_Object obj) { |
| 248 | UNUSED(L); | 256 | UNUSED(L); |
| 249 | if (obj == LUA_NOOBJECT) return 0.0; | 257 | if (obj == LUA_NOOBJECT || tonumber(obj)) |
| 250 | if (tonumber(obj)) return 0.0; | 258 | return 0.0; |
| 251 | else return (nvalue(obj)); | 259 | else return (nvalue(obj)); |
| 252 | } | 260 | } |
| 253 | 261 | ||
| @@ -339,28 +347,11 @@ void lua_pushobject (lua_State *L, lua_Object o) { | |||
| 339 | int lua_tag (lua_State *L, lua_Object o) { | 347 | int lua_tag (lua_State *L, lua_Object o) { |
| 340 | UNUSED(L); | 348 | UNUSED(L); |
| 341 | if (o == LUA_NOOBJECT) | 349 | if (o == LUA_NOOBJECT) |
| 342 | return LUA_T_NIL; | 350 | return LUA_T_NIL; |
| 343 | else { | 351 | else if (ttype(o) == LUA_T_USERDATA) /* to allow `old' tags (deprecated) */ |
| 344 | int t; | 352 | return o->value.ts->u.d.tag; |
| 345 | switch (t = ttype(o)) { | 353 | else |
| 346 | case LUA_T_USERDATA: | 354 | return luaT_effectivetag(o); |
| 347 | return o->value.ts->u.d.tag; | ||
| 348 | case LUA_T_ARRAY: | ||
| 349 | return o->value.a->htag; | ||
| 350 | case LUA_T_PMARK: | ||
| 351 | return LUA_T_PROTO; | ||
| 352 | case LUA_T_CMARK: | ||
| 353 | return LUA_T_CPROTO; | ||
| 354 | case LUA_T_CLOSURE: case LUA_T_CLMARK: | ||
| 355 | return o->value.cl->consts[0].ttype; | ||
| 356 | #ifdef DEBUG | ||
| 357 | case LUA_T_LINE: | ||
| 358 | LUA_INTERNALERROR(L, "invalid type"); | ||
| 359 | #endif | ||
| 360 | default: | ||
| 361 | return t; | ||
| 362 | } | ||
| 363 | } | ||
| 364 | } | 355 | } |
| 365 | 356 | ||
| 366 | 357 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.h,v 1.10 1999/12/02 16:24:45 roberto Exp roberto $ | 2 | ** $Id: lapi.h,v 1.11 1999/12/14 18:33:29 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 | */ |
| @@ -11,7 +11,11 @@ | |||
| 11 | #include "lobject.h" | 11 | #include "lobject.h" |
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | lua_Type luaA_normalizedtype (const TObject *o); | 14 | extern const lua_Type luaA_normtype[]; |
| 15 | |||
| 16 | #define luaA_normalizedtype(o) (luaA_normtype[-ttype(o)]) | ||
| 17 | |||
| 18 | |||
| 15 | void luaA_setnormalized (TObject *d, const TObject *s); | 19 | void luaA_setnormalized (TObject *d, const TObject *s); |
| 16 | void luaA_checkCparams (lua_State *L, int nParams); | 20 | void luaA_checkCparams (lua_State *L, int nParams); |
| 17 | const TObject *luaA_protovalue (const TObject *o); | 21 | const TObject *luaA_protovalue (const TObject *o); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbuiltin.c,v 1.85 1999/12/14 18:42:57 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.86 1999/12/20 13:10:38 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 | */ |
| @@ -377,10 +377,10 @@ void luaB_tostring (lua_State *L) { | |||
| 377 | case LUA_T_ARRAY: | 377 | case LUA_T_ARRAY: |
| 378 | sprintf(buff, "table: %p", o->value.a); | 378 | sprintf(buff, "table: %p", o->value.a); |
| 379 | break; | 379 | break; |
| 380 | case LUA_T_CLOSURE: | 380 | case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: |
| 381 | sprintf(buff, "function: %p", o->value.cl); | 381 | sprintf(buff, "function: %p", o->value.cl); |
| 382 | break; | 382 | break; |
| 383 | case LUA_T_PROTO: | 383 | case LUA_T_LPROTO: |
| 384 | sprintf(buff, "function: %p", o->value.tf); | 384 | sprintf(buff, "function: %p", o->value.tf); |
| 385 | break; | 385 | break; |
| 386 | case LUA_T_CPROTO: | 386 | case LUA_T_CPROTO: |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: $ | 2 | ** $Id: ldebug.c,v 1.1 1999/12/14 18:31:20 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 | */ |
| @@ -42,10 +42,11 @@ int lua_setdebug (lua_State *L, int debug) { | |||
| 42 | lua_Function lua_stackedfunction (lua_State *L, int level) { | 42 | lua_Function lua_stackedfunction (lua_State *L, int level) { |
| 43 | int i; | 43 | int i; |
| 44 | for (i = (L->top-1)-L->stack; i>=0; i--) { | 44 | for (i = (L->top-1)-L->stack; i>=0; i--) { |
| 45 | int t = L->stack[i].ttype; | 45 | if (is_T_MARK(L->stack[i].ttype)) { |
| 46 | if (t == LUA_T_CLMARK || t == LUA_T_PMARK || t == LUA_T_CMARK) | 46 | if (level == 0) |
| 47 | if (level-- == 0) | ||
| 48 | return L->stack+i; | 47 | return L->stack+i; |
| 48 | level--; | ||
| 49 | } | ||
| 49 | } | 50 | } |
| 50 | return LUA_NOOBJECT; | 51 | return LUA_NOOBJECT; |
| 51 | } | 52 | } |
| @@ -53,8 +54,12 @@ lua_Function lua_stackedfunction (lua_State *L, int level) { | |||
| 53 | 54 | ||
| 54 | int lua_nups (lua_State *L, lua_Function f) { | 55 | int lua_nups (lua_State *L, lua_Function f) { |
| 55 | UNUSED(L); | 56 | UNUSED(L); |
| 56 | return (!f || luaA_normalizedtype(f) != LUA_T_CLOSURE) ? 0 : | 57 | switch (luaA_normalizedtype(f)) { |
| 57 | f->value.cl->nelems; | 58 | case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: |
| 59 | return f->value.cl->nelems; | ||
| 60 | default: | ||
| 61 | return 0; | ||
| 62 | } | ||
| 58 | } | 63 | } |
| 59 | 64 | ||
| 60 | 65 | ||
| @@ -66,7 +71,7 @@ int lua_currentline (lua_State *L, lua_Function f) { | |||
| 66 | lua_Object lua_getlocal (lua_State *L, lua_Function f, int local_number, | 71 | lua_Object lua_getlocal (lua_State *L, lua_Function f, int local_number, |
| 67 | const char **name) { | 72 | const char **name) { |
| 68 | /* check whether `f' is a Lua function */ | 73 | /* check whether `f' is a Lua function */ |
| 69 | if (lua_tag(L, f) != LUA_T_PROTO) | 74 | if (lua_tag(L, f) != LUA_T_LPROTO) |
| 70 | return LUA_NOOBJECT; | 75 | return LUA_NOOBJECT; |
| 71 | else { | 76 | else { |
| 72 | TProtoFunc *fp = luaA_protovalue(f)->value.tf; | 77 | TProtoFunc *fp = luaA_protovalue(f)->value.tf; |
| @@ -84,7 +89,7 @@ lua_Object lua_getlocal (lua_State *L, lua_Function f, int local_number, | |||
| 84 | 89 | ||
| 85 | int lua_setlocal (lua_State *L, lua_Function f, int local_number) { | 90 | int lua_setlocal (lua_State *L, lua_Function f, int local_number) { |
| 86 | /* check whether `f' is a Lua function */ | 91 | /* check whether `f' is a Lua function */ |
| 87 | if (lua_tag(L, f) != LUA_T_PROTO) | 92 | if (lua_tag(L, f) != LUA_T_LPROTO) |
| 88 | return 0; | 93 | return 0; |
| 89 | else { | 94 | else { |
| 90 | TProtoFunc *fp = luaA_protovalue(f)->value.tf; | 95 | TProtoFunc *fp = luaA_protovalue(f)->value.tf; |
| @@ -110,7 +115,7 @@ void lua_funcinfo (lua_State *L, lua_Object func, | |||
| 110 | lua_error(L, "API error - `funcinfo' called with a non-function value"); | 115 | lua_error(L, "API error - `funcinfo' called with a non-function value"); |
| 111 | else { | 116 | else { |
| 112 | const TObject *f = luaA_protovalue(func); | 117 | const TObject *f = luaA_protovalue(func); |
| 113 | if (luaA_normalizedtype(f) == LUA_T_PROTO) { | 118 | if (luaA_normalizedtype(f) == LUA_T_LPROTO) { |
| 114 | *source = tfvalue(f)->source->str; | 119 | *source = tfvalue(f)->source->str; |
| 115 | *linedefined = tfvalue(f)->lineDefined; | 120 | *linedefined = tfvalue(f)->lineDefined; |
| 116 | } | 121 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.58 1999/12/06 12:03:45 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.59 1999/12/21 18:04:41 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 | */ |
| @@ -93,7 +93,8 @@ void luaD_adjusttop (lua_State *L, StkId base, int extra) { | |||
| 93 | ** Open a hole inside the stack at `pos' | 93 | ** Open a hole inside the stack at `pos' |
| 94 | */ | 94 | */ |
| 95 | void luaD_openstack (lua_State *L, StkId pos) { | 95 | void luaD_openstack (lua_State *L, StkId pos) { |
| 96 | luaO_memup(pos+1, pos, (L->top-pos)*sizeof(TObject)); | 96 | int i = L->top-pos; |
| 97 | while (i--) pos[i+1] = pos[i]; | ||
| 97 | incr_top; | 98 | incr_top; |
| 98 | } | 99 | } |
| 99 | 100 | ||
| @@ -122,15 +123,18 @@ static void luaD_callHook (lua_State *L, StkId func, lua_CHFunction callhook, | |||
| 122 | if (isreturn) | 123 | if (isreturn) |
| 123 | callhook(L, LUA_NOOBJECT, "(return)", 0); | 124 | callhook(L, LUA_NOOBJECT, "(return)", 0); |
| 124 | else { | 125 | else { |
| 125 | if (ttype(func) == LUA_T_PROTO) | 126 | switch (ttype(func)) { |
| 126 | callhook(L, func, tfvalue(func)->source->str, | 127 | case LUA_T_LPROTO: |
| 127 | tfvalue(func)->lineDefined); | 128 | callhook(L, func, tfvalue(func)->source->str, |
| 128 | else if (ttype(func) == LUA_T_CLOSURE && | 129 | tfvalue(func)->lineDefined); |
| 129 | ttype(clvalue(func)->consts) == LUA_T_PROTO) | 130 | break; |
| 130 | callhook(L, func, tfvalue(protovalue(func))->source->str, | 131 | case LUA_T_LCLOSURE: |
| 131 | tfvalue(protovalue(func))->lineDefined); | 132 | callhook(L, func, tfvalue(protovalue(func))->source->str, |
| 132 | else | 133 | tfvalue(protovalue(func))->lineDefined); |
| 133 | callhook(L, func, "(C)", -1); | 134 | break; |
| 135 | default: | ||
| 136 | callhook(L, func, "(C)", -1); | ||
| 137 | } | ||
| 134 | } | 138 | } |
| 135 | L->allowhooks = 1; | 139 | L->allowhooks = 1; |
| 136 | L->top = old_top; | 140 | L->top = old_top; |
| @@ -158,16 +162,16 @@ static StkId callC (lua_State *L, lua_CFunction f, StkId base) { | |||
| 158 | } | 162 | } |
| 159 | 163 | ||
| 160 | 164 | ||
| 161 | static StkId callCclosure (lua_State *L, const struct Closure *cl, | 165 | static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) { |
| 162 | lua_CFunction f, StkId base) { | ||
| 163 | int nup = cl->nelems; /* number of upvalues */ | 166 | int nup = cl->nelems; /* number of upvalues */ |
| 167 | int n = L->top-base; /* number of arguments (to move up) */ | ||
| 164 | luaD_checkstack(L, nup); | 168 | luaD_checkstack(L, nup); |
| 165 | /* open space for upvalues as extra arguments */ | 169 | /* open space for upvalues as extra arguments */ |
| 166 | luaO_memup(base+nup, base, (L->top-base)*sizeof(TObject)); | 170 | while (n--) *(base+nup+n) = *(base+n); |
| 167 | /* copy upvalues into stack */ | ||
| 168 | memcpy(base, cl->consts+1, nup*sizeof(TObject)); | ||
| 169 | L->top += nup; | 171 | L->top += nup; |
| 170 | return callC(L, f, base); | 172 | /* copy upvalues into stack */ |
| 173 | while (nup--) *(base+nup) = cl->consts[nup+1]; | ||
| 174 | return callC(L, fvalue(cl->consts), base); | ||
| 171 | } | 175 | } |
| 172 | 176 | ||
| 173 | 177 | ||
| @@ -197,17 +201,20 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
| 197 | ttype(func) = LUA_T_CMARK; | 201 | ttype(func) = LUA_T_CMARK; |
| 198 | firstResult = callC(L, fvalue(func), func+1); | 202 | firstResult = callC(L, fvalue(func), func+1); |
| 199 | break; | 203 | break; |
| 200 | case LUA_T_PROTO: | 204 | case LUA_T_LPROTO: |
| 201 | ttype(func) = LUA_T_PMARK; | 205 | ttype(func) = LUA_T_LMARK; |
| 202 | firstResult = luaV_execute(L, NULL, tfvalue(func), func+1); | 206 | firstResult = luaV_execute(L, NULL, tfvalue(func), func+1); |
| 203 | break; | 207 | break; |
| 204 | case LUA_T_CLOSURE: { | 208 | case LUA_T_LCLOSURE: { |
| 205 | Closure *c = clvalue(func); | 209 | Closure *c = clvalue(func); |
| 206 | TObject *proto = c->consts; | 210 | ttype(func) = LUA_T_LCLMARK; |
| 207 | ttype(func) = LUA_T_CLMARK; | 211 | firstResult = luaV_execute(L, c, tfvalue(c->consts), func+1); |
| 208 | firstResult = (ttype(proto) == LUA_T_CPROTO) ? | 212 | break; |
| 209 | callCclosure(L, c, fvalue(proto), func+1) : | 213 | } |
| 210 | luaV_execute(L, c, tfvalue(proto), func+1); | 214 | case LUA_T_CCLOSURE: { |
| 215 | Closure *c = clvalue(func); | ||
| 216 | ttype(func) = LUA_T_CCLMARK; | ||
| 217 | firstResult = callCclosure(L, c, func+1); | ||
| 211 | break; | 218 | break; |
| 212 | } | 219 | } |
| 213 | default: { /* `func' is not a function; check the `function' tag method */ | 220 | default: { /* `func' is not a function; check the `function' tag method */ |
| @@ -226,16 +233,18 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
| 226 | nResults = L->top - firstResult; | 233 | nResults = L->top - firstResult; |
| 227 | else | 234 | else |
| 228 | luaD_adjusttop(L, firstResult, nResults); | 235 | luaD_adjusttop(L, firstResult, nResults); |
| 229 | /* move results to func (to erase parameters and function) */ | 236 | /* move results to `func' (to erase parameters and function) */ |
| 230 | luaO_memdown(func, firstResult, nResults*sizeof(TObject)); | 237 | while (nResults) { |
| 231 | L->top = func+nResults; | 238 | *func++ = *(L->top - nResults); |
| 239 | nResults--; | ||
| 240 | } | ||
| 241 | L->top = func; | ||
| 232 | } | 242 | } |
| 233 | 243 | ||
| 234 | 244 | ||
| 235 | static void message (lua_State *L, const char *s) { | 245 | static void message (lua_State *L, const char *s) { |
| 236 | const TObject *em = &(luaS_assertglobalbyname(L, "_ERRORMESSAGE")->value); | 246 | const TObject *em = &(luaS_assertglobalbyname(L, "_ERRORMESSAGE")->value); |
| 237 | if (ttype(em) == LUA_T_PROTO || ttype(em) == LUA_T_CPROTO || | 247 | if (*luaO_typename(em) == 'f') { |
| 238 | ttype(em) == LUA_T_CLOSURE) { | ||
| 239 | *L->top = *em; | 248 | *L->top = *em; |
| 240 | incr_top; | 249 | incr_top; |
| 241 | lua_pushstring(L, s); | 250 | lua_pushstring(L, s); |
| @@ -313,7 +322,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) { | |||
| 313 | L->errorJmp = oldErr; | 322 | L->errorJmp = oldErr; |
| 314 | if (status) return 1; /* error code */ | 323 | if (status) return 1; /* error code */ |
| 315 | if (tf == NULL) return 2; /* `natural' end */ | 324 | if (tf == NULL) return 2; /* `natural' end */ |
| 316 | L->top->ttype = LUA_T_PROTO; /* push new function on the stack */ | 325 | L->top->ttype = LUA_T_LPROTO; /* push new function on the stack */ |
| 317 | L->top->value.tf = tf; | 326 | L->top->value.tf = tf; |
| 318 | incr_top; | 327 | incr_top; |
| 319 | return 0; | 328 | return 0; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 1.36 1999/12/14 18:31:20 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.37 1999/12/21 18:04:41 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 | */ |
| @@ -100,10 +100,11 @@ static int markobject (lua_State *L, TObject *o) { | |||
| 100 | case LUA_T_ARRAY: | 100 | case LUA_T_ARRAY: |
| 101 | hashmark(L, avalue(o)); | 101 | hashmark(L, avalue(o)); |
| 102 | break; | 102 | break; |
| 103 | case LUA_T_CLOSURE: case LUA_T_CLMARK: | 103 | case LUA_T_LCLOSURE: case LUA_T_LCLMARK: |
| 104 | case LUA_T_CCLOSURE: case LUA_T_CCLMARK: | ||
| 104 | closuremark(L, o->value.cl); | 105 | closuremark(L, o->value.cl); |
| 105 | break; | 106 | break; |
| 106 | case LUA_T_PROTO: case LUA_T_PMARK: | 107 | case LUA_T_LPROTO: case LUA_T_LMARK: |
| 107 | protomark(L, o->value.tf); | 108 | protomark(L, o->value.tf); |
| 108 | break; | 109 | break; |
| 109 | default: break; /* numbers, cprotos, etc */ | 110 | default: break; /* numbers, cprotos, etc */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 1.26 1999/11/26 18:59:20 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.27 1999/12/14 18:31:20 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 | */ |
| @@ -14,8 +14,9 @@ | |||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | const char *const luaO_typenames[] = { /* ORDER LUA_T */ | 16 | const char *const luaO_typenames[] = { /* ORDER LUA_T */ |
| 17 | "userdata", "number", "string", "table", "function", "function", | 17 | "userdata", "number", "string", "table", "function", "function", "nil", |
| 18 | "nil", "function", "mark", "mark", "mark", "line", NULL | 18 | "function", "function", "function", "function", "function", "function", |
| 19 | "line", NULL | ||
| 19 | }; | 20 | }; |
| 20 | 21 | ||
| 21 | 22 | ||
| @@ -34,13 +35,20 @@ unsigned long luaO_power2 (unsigned long n) { | |||
| 34 | 35 | ||
| 35 | int luaO_equalval (const TObject *t1, const TObject *t2) { | 36 | int luaO_equalval (const TObject *t1, const TObject *t2) { |
| 36 | switch (ttype(t1)) { | 37 | switch (ttype(t1)) { |
| 37 | case LUA_T_NIL: return 1; | 38 | case LUA_T_NIL: |
| 38 | case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2); | 39 | return 1; |
| 39 | case LUA_T_STRING: case LUA_T_USERDATA: return svalue(t1) == svalue(t2); | 40 | case LUA_T_NUMBER: |
| 40 | case LUA_T_ARRAY: return avalue(t1) == avalue(t2); | 41 | return nvalue(t1) == nvalue(t2); |
| 41 | case LUA_T_PROTO: return tfvalue(t1) == tfvalue(t2); | 42 | case LUA_T_STRING: case LUA_T_USERDATA: |
| 42 | case LUA_T_CPROTO: return fvalue(t1) == fvalue(t2); | 43 | return svalue(t1) == svalue(t2); |
| 43 | case LUA_T_CLOSURE: return t1->value.cl == t2->value.cl; | 44 | case LUA_T_ARRAY: |
| 45 | return avalue(t1) == avalue(t2); | ||
| 46 | case LUA_T_LPROTO: | ||
| 47 | return tfvalue(t1) == tfvalue(t2); | ||
| 48 | case LUA_T_CPROTO: | ||
| 49 | return fvalue(t1) == fvalue(t2); | ||
| 50 | case LUA_T_CCLOSURE: case LUA_T_LCLOSURE: | ||
| 51 | return t1->value.cl == t2->value.cl; | ||
| 44 | default: | 52 | default: |
| 45 | LUA_INTERNALERROR(L, "invalid type"); | 53 | LUA_INTERNALERROR(L, "invalid type"); |
| 46 | return 0; /* UNREACHABLE */ | 54 | return 0; /* UNREACHABLE */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 1.39 1999/12/02 16:24:45 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.40 1999/12/14 18:33:29 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 | */ |
| @@ -69,25 +69,33 @@ typedef enum { | |||
| 69 | LUA_T_NUMBER = -1, /* fixed tag for numbers */ | 69 | LUA_T_NUMBER = -1, /* fixed tag for numbers */ |
| 70 | LUA_T_STRING = -2, /* fixed tag for strings */ | 70 | LUA_T_STRING = -2, /* fixed tag for strings */ |
| 71 | LUA_T_ARRAY = -3, /* tag default for tables (or arrays) */ | 71 | LUA_T_ARRAY = -3, /* tag default for tables (or arrays) */ |
| 72 | LUA_T_PROTO = -4, /* fixed tag for functions */ | 72 | LUA_T_LPROTO = -4, /* fixed tag for Lua functions */ |
| 73 | LUA_T_CPROTO = -5, /* fixed tag for Cfunctions */ | 73 | LUA_T_CPROTO = -5, /* fixed tag for C functions */ |
| 74 | LUA_T_NIL = -6, /* last "pre-defined" tag */ | 74 | LUA_T_NIL = -6, /* last "pre-defined" tag */ |
| 75 | LUA_T_CLOSURE = -7, | 75 | LUA_T_LCLOSURE = -7, /* Lua closure */ |
| 76 | LUA_T_CLMARK = -8, /* mark for closures */ | 76 | LUA_T_CCLOSURE = -8, /* C closure */ |
| 77 | LUA_T_PMARK = -9, /* mark for Lua prototypes */ | 77 | LUA_T_LCLMARK = -9 ,/* mark for Lua closures */ |
| 78 | LUA_T_CMARK = -10, /* mark for C prototypes */ | 78 | LUA_T_CCLMARK = -10,/* mark for C closures */ |
| 79 | LUA_T_LINE = -11 | 79 | LUA_T_LMARK = -11, /* mark for Lua prototypes */ |
| 80 | LUA_T_CMARK = -12, /* mark for C prototypes */ | ||
| 81 | LUA_T_LINE = -13 | ||
| 80 | } lua_Type; | 82 | } lua_Type; |
| 81 | 83 | ||
| 82 | #define NUM_TAGS 7 | 84 | #define NUM_TAGS 7 |
| 83 | 85 | ||
| 86 | /* | ||
| 87 | ** chech whether t is a mark; ttypes are negative numbers, so the | ||
| 88 | ** comparisons look reversed. (ORDER LUA_T) | ||
| 89 | */ | ||
| 90 | #define is_T_MARK(t) (LUA_T_CMARK <= (t) && (t) <= LUA_T_LCLMARK) | ||
| 91 | |||
| 84 | 92 | ||
| 85 | typedef union { | 93 | typedef union { |
| 86 | lua_CFunction f; /* LUA_T_CPROTO, LUA_T_CMARK */ | 94 | lua_CFunction f; /* LUA_T_CPROTO, LUA_T_CMARK */ |
| 87 | real n; /* LUA_T_NUMBER */ | 95 | real n; /* LUA_T_NUMBER */ |
| 88 | struct TaggedString *ts; /* LUA_T_STRING, LUA_T_USERDATA */ | 96 | struct TaggedString *ts; /* LUA_T_STRING, LUA_T_USERDATA */ |
| 89 | struct TProtoFunc *tf; /* LUA_T_PROTO, LUA_T_PMARK */ | 97 | struct TProtoFunc *tf; /* LUA_T_LPROTO, LUA_T_LMARK */ |
| 90 | struct Closure *cl; /* LUA_T_CLOSURE, LUA_T_CLMARK */ | 98 | struct Closure *cl; /* LUA_T_[CL]CLOSURE, LUA_T_[CL]CLMARK */ |
| 91 | struct Hash *a; /* LUA_T_ARRAY */ | 99 | struct Hash *a; /* LUA_T_ARRAY */ |
| 92 | int i; /* LUA_T_LINE */ | 100 | int i; /* LUA_T_LINE */ |
| 93 | } Value; | 101 | } Value; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.48 1999/12/21 17:31:28 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.49 1999/12/22 16:58:36 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 | */ |
| @@ -547,7 +547,7 @@ static void func_onstack (LexState *ls, FuncState *func) { | |||
| 547 | FuncState *fs = ls->fs; | 547 | FuncState *fs = ls->fs; |
| 548 | int i; | 548 | int i; |
| 549 | int c = next_constant(ls, fs->f); | 549 | int c = next_constant(ls, fs->f); |
| 550 | ttype(&fs->f->consts[c]) = LUA_T_PROTO; | 550 | ttype(&fs->f->consts[c]) = LUA_T_LPROTO; |
| 551 | fs->f->consts[c].value.tf = func->f; | 551 | fs->f->consts[c].value.tf = func->f; |
| 552 | if (func->nupvalues == 0) | 552 | if (func->nupvalues == 0) |
| 553 | code_constant(ls, c); | 553 | code_constant(ls, c); |
| @@ -580,7 +580,7 @@ static void init_state (LexState *ls, FuncState *fs, TaggedString *source) { | |||
| 580 | code_byte(ls, 0); /* to be filled with arg information */ | 580 | code_byte(ls, 0); /* to be filled with arg information */ |
| 581 | /* push function (to avoid GC) */ | 581 | /* push function (to avoid GC) */ |
| 582 | tfvalue(L->top) = f; | 582 | tfvalue(L->top) = f; |
| 583 | ttype(L->top) = LUA_T_PROTO; | 583 | ttype(L->top) = LUA_T_LPROTO; |
| 584 | incr_top; | 584 | incr_top; |
| 585 | } | 585 | } |
| 586 | 586 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lref.c,v 1.3 1999/11/22 13:12:07 roberto Exp roberto $ | 2 | ** $Id: lref.c,v 1.4 1999/12/14 18:31:20 roberto Exp roberto $ |
| 3 | ** REF mechanism | 3 | ** REF mechanism |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -85,15 +85,10 @@ static int ismarked (const TObject *o) { | |||
| 85 | return o->value.ts->marked; | 85 | return o->value.ts->marked; |
| 86 | case LUA_T_ARRAY: | 86 | case LUA_T_ARRAY: |
| 87 | return o->value.a->marked; | 87 | return o->value.a->marked; |
| 88 | case LUA_T_CLOSURE: | 88 | case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: |
| 89 | return o->value.cl->marked; | 89 | return o->value.cl->marked; |
| 90 | case LUA_T_PROTO: | 90 | case LUA_T_LPROTO: |
| 91 | return o->value.tf->marked; | 91 | return o->value.tf->marked; |
| 92 | #ifdef DEBUG | ||
| 93 | case LUA_T_LINE: case LUA_T_CLMARK: | ||
| 94 | case LUA_T_CMARK: case LUA_T_PMARK: | ||
| 95 | LUA_INTERNALERROR(L, "invalid type"); | ||
| 96 | #endif | ||
| 97 | default: /* number or cproto */ | 92 | default: /* number or cproto */ |
| 98 | return 1; | 93 | return 1; |
| 99 | } | 94 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 1.31 1999/11/26 18:59:20 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.32 1999/12/07 12:05:34 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 | */ |
| @@ -52,13 +52,13 @@ Node *luaH_mainposition (const Hash *t, const TObject *key) { | |||
| 52 | case LUA_T_ARRAY: | 52 | case LUA_T_ARRAY: |
| 53 | h = IntPoint(L, avalue(key)); | 53 | h = IntPoint(L, avalue(key)); |
| 54 | break; | 54 | break; |
| 55 | case LUA_T_PROTO: | 55 | case LUA_T_LPROTO: |
| 56 | h = IntPoint(L, tfvalue(key)); | 56 | h = IntPoint(L, tfvalue(key)); |
| 57 | break; | 57 | break; |
| 58 | case LUA_T_CPROTO: | 58 | case LUA_T_CPROTO: |
| 59 | h = IntPoint(L, fvalue(key)); | 59 | h = IntPoint(L, fvalue(key)); |
| 60 | break; | 60 | break; |
| 61 | case LUA_T_CLOSURE: | 61 | case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: |
| 62 | h = IntPoint(L, clvalue(key)); | 62 | h = IntPoint(L, clvalue(key)); |
| 63 | break; | 63 | break; |
| 64 | default: | 64 | default: |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbuiltin.c,v 1.83 1999/12/07 12:05:34 roberto Exp $ | 2 | ** $Id: ltests.c,v 1.1 1999/12/14 18:31:20 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 | */ |
| @@ -17,6 +17,7 @@ | |||
| 17 | #include "lstring.h" | 17 | #include "lstring.h" |
| 18 | #include "ltable.h" | 18 | #include "ltable.h" |
| 19 | #include "lua.h" | 19 | #include "lua.h" |
| 20 | #include "luadebug.h" | ||
| 20 | 21 | ||
| 21 | 22 | ||
| 22 | void luaB_opentests (lua_State *L); | 23 | void luaB_opentests (lua_State *L); |
| @@ -195,6 +196,12 @@ static void testC (lua_State *L) { | |||
| 195 | else if EQ("rawsettable") { | 196 | else if EQ("rawsettable") { |
| 196 | lua_rawsettable(L); | 197 | lua_rawsettable(L); |
| 197 | } | 198 | } |
| 199 | else if EQ("tag") { | ||
| 200 | lua_pushnumber(L, lua_tag(L, reg[getreg(L, &pc)])); | ||
| 201 | } | ||
| 202 | else if EQ("type") { | ||
| 203 | lua_pushstring(L, lua_type(L, reg[getreg(L, &pc)])); | ||
| 204 | } | ||
| 198 | else if EQ("nextvar") { | 205 | else if EQ("nextvar") { |
| 199 | lua_pushstring(L, lua_nextvar(L, lua_getstring(L, reg[getreg(L, &pc)]))); | 206 | lua_pushstring(L, lua_nextvar(L, lua_getstring(L, reg[getreg(L, &pc)]))); |
| 200 | } | 207 | } |
| @@ -223,6 +230,10 @@ static void testC (lua_State *L) { | |||
| 223 | int n = getreg(L, &pc); | 230 | int n = getreg(L, &pc); |
| 224 | lua_settagmethod(L, (int)lua_getnumber(L, reg[n]), getname(&pc)); | 231 | lua_settagmethod(L, (int)lua_getnumber(L, reg[n]), getname(&pc)); |
| 225 | } | 232 | } |
| 233 | else if EQ("getfunc") { | ||
| 234 | int n = getreg(L, &pc); | ||
| 235 | reg[n] = lua_stackedfunction(L, getnum(&pc)); | ||
| 236 | } | ||
| 226 | else if EQ("beginblock") { | 237 | else if EQ("beginblock") { |
| 227 | lua_beginblock(L); | 238 | lua_beginblock(L); |
| 228 | } | 239 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 1.28 1999/10/04 17:51:04 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.29 1999/11/22 13:12:07 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 | */ |
| @@ -42,7 +42,7 @@ static const char luaT_validevents[NUM_TAGS][IM_N] = { | |||
| 42 | {1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_NUMBER */ | 42 | {1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_NUMBER */ |
| 43 | {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */ | 43 | {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */ |
| 44 | {0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_ARRAY */ | 44 | {0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_ARRAY */ |
| 45 | {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_PROTO */ | 45 | {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_LPROTO */ |
| 46 | {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_CPROTO */ | 46 | {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_CPROTO */ |
| 47 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */ | 47 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */ |
| 48 | }; | 48 | }; |
| @@ -104,23 +104,21 @@ int lua_copytagmethods (lua_State *L, int tagto, int tagfrom) { | |||
| 104 | 104 | ||
| 105 | 105 | ||
| 106 | int luaT_effectivetag (const TObject *o) { | 106 | int luaT_effectivetag (const TObject *o) { |
| 107 | static const int realtag[] = { /* ORDER LUA_T */ | ||
| 108 | LUA_T_USERDATA, LUA_T_NUMBER, LUA_T_STRING, LUA_T_ARRAY, | ||
| 109 | LUA_T_LPROTO, LUA_T_CPROTO, LUA_T_NIL, | ||
| 110 | LUA_T_LPROTO, LUA_T_CPROTO, /* LUA_T_LCLOSURE, LUA_T_CCLOSURE */ | ||
| 111 | LUA_T_LPROTO, LUA_T_CPROTO, /* LUA_T_LCLMARK, LUA_T_CCLMARK */ | ||
| 112 | LUA_T_LPROTO, LUA_T_CPROTO /* LUA_T_LMARK, LUA_T_CMARK */ | ||
| 113 | }; | ||
| 107 | int t; | 114 | int t; |
| 108 | switch (t = ttype(o)) { | 115 | switch (t = ttype(o)) { |
| 109 | case LUA_T_ARRAY: | ||
| 110 | return o->value.a->htag; | ||
| 111 | case LUA_T_USERDATA: { | 116 | case LUA_T_USERDATA: { |
| 112 | int tag = o->value.ts->u.d.tag; | 117 | int tag = o->value.ts->u.d.tag; |
| 113 | return (tag >= 0) ? LUA_T_USERDATA : tag; | 118 | return (tag >= 0) ? LUA_T_USERDATA : tag; /* deprecated test */ |
| 114 | } | 119 | } |
| 115 | case LUA_T_CLOSURE: | 120 | case LUA_T_ARRAY: return o->value.a->htag; |
| 116 | return o->value.cl->consts[0].ttype; | 121 | default: return realtag[-t]; |
| 117 | #ifdef DEBUG | ||
| 118 | case LUA_T_PMARK: case LUA_T_CMARK: | ||
| 119 | case LUA_T_CLMARK: case LUA_T_LINE: | ||
| 120 | LUA_INTERNALERROR(L, "invalid type"); | ||
| 121 | #endif | ||
| 122 | default: | ||
| 123 | return t; | ||
| 124 | } | 122 | } |
| 125 | } | 123 | } |
| 126 | 124 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lundump.c,v 1.24 1999/12/02 18:45:03 lhf Exp $ | 2 | ** $Id: lundump.c,v 1.16 1999/12/02 19:11:51 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 | */ |
| @@ -135,7 +135,7 @@ static void LoadConstants (lua_State* L, TProtoFunc* tf, ZIO* Z, int native) | |||
| 135 | case LUA_T_STRING: | 135 | case LUA_T_STRING: |
| 136 | tsvalue(o)=LoadTString(L,Z); | 136 | tsvalue(o)=LoadTString(L,Z); |
| 137 | break; | 137 | break; |
| 138 | case LUA_T_PROTO: | 138 | case LUA_T_LPROTO: |
| 139 | tfvalue(o)=LoadFunction(L,Z,native); | 139 | tfvalue(o)=LoadFunction(L,Z,native); |
| 140 | break; | 140 | break; |
| 141 | case LUA_T_NIL: | 141 | case LUA_T_NIL: |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.73 1999/12/14 18:31:20 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.74 1999/12/21 18:04:41 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 | */ |
| @@ -86,8 +86,10 @@ void luaV_closure (lua_State *L, int nelems) { | |||
| 86 | Closure *c = luaF_newclosure(L, nelems); | 86 | Closure *c = luaF_newclosure(L, nelems); |
| 87 | c->consts[0] = *(L->top-1); | 87 | c->consts[0] = *(L->top-1); |
| 88 | L->top -= nelems; | 88 | L->top -= nelems; |
| 89 | memcpy(&c->consts[1], L->top-1, nelems*sizeof(TObject)); | 89 | while (nelems--) |
| 90 | ttype(L->top-1) = LUA_T_CLOSURE; | 90 | c->consts[nelems+1] = *(L->top-1+nelems); |
| 91 | ttype(L->top-1) = (ttype(&c->consts[0]) == LUA_T_CPROTO) ? | ||
| 92 | LUA_T_CCLOSURE : LUA_T_LCLOSURE; | ||
| 91 | (L->top-1)->value.cl = c; | 93 | (L->top-1)->value.cl = c; |
| 92 | } | 94 | } |
| 93 | } | 95 | } |
| @@ -577,6 +579,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, | |||
| 577 | *top++ = consts[aux]; | 579 | *top++ = consts[aux]; |
| 578 | L->top = top; | 580 | L->top = top; |
| 579 | aux = *pc++; /* number of upvalues */ | 581 | aux = *pc++; /* number of upvalues */ |
| 582 | LUA_ASSERT(L, aux>0, "closure with no upvalues"); | ||
| 580 | luaV_closure(L, aux); | 583 | luaV_closure(L, aux); |
| 581 | luaC_checkGC(L); | 584 | luaC_checkGC(L); |
| 582 | top -= aux; | 585 | top -= aux; |
