diff options
| -rw-r--r-- | ldo.c | 3 | ||||
| -rw-r--r-- | lfunc.c | 3 | ||||
| -rw-r--r-- | lgc.c | 4 | ||||
| -rw-r--r-- | lobject.c | 5 | ||||
| -rw-r--r-- | lobject.h | 27 | ||||
| -rw-r--r-- | lstring.c | 4 | ||||
| -rw-r--r-- | ltable.c | 3 |
7 files changed, 36 insertions, 13 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.117 2001/01/26 11:45:51 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.118 2001/01/29 15:35:17 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 | */ |
| @@ -172,6 +172,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
| 172 | setclvalue(func, tm); /* tag method is the new function to be called */ | 172 | setclvalue(func, tm); /* tag method is the new function to be called */ |
| 173 | } | 173 | } |
| 174 | cl = clvalue(func); | 174 | cl = clvalue(func); |
| 175 | ci.v.ttype = LUA_TMARK; | ||
| 175 | ci.func = cl; | 176 | ci.func = cl; |
| 176 | setivalue(func, &ci); | 177 | setivalue(func, &ci); |
| 177 | callhook = L->callhook; | 178 | callhook = L->callhook; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.c,v 1.36 2000/12/28 12:55:41 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 1.37 2001/01/19 13:20:30 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 | */ |
| @@ -19,6 +19,7 @@ | |||
| 19 | 19 | ||
| 20 | Closure *luaF_newclosure (lua_State *L, int nelems) { | 20 | Closure *luaF_newclosure (lua_State *L, int nelems) { |
| 21 | Closure *c = (Closure *)luaM_malloc(L, sizeclosure(nelems)); | 21 | Closure *c = (Closure *)luaM_malloc(L, sizeclosure(nelems)); |
| 22 | c->v.ttype = LUA_TFUNCTION; | ||
| 22 | c->next = G(L)->rootcl; | 23 | c->next = G(L)->rootcl; |
| 23 | G(L)->rootcl = c; | 24 | G(L)->rootcl = c; |
| 24 | c->mark = c; | 25 | c->mark = c; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 1.81 2001/01/26 14:16:24 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.82 2001/01/29 17:16:58 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 | */ |
| @@ -66,6 +66,8 @@ static void marktable (GCState *st, Hash *h) { | |||
| 66 | 66 | ||
| 67 | 67 | ||
| 68 | static void markobject (GCState *st, TObject *o) { | 68 | static void markobject (GCState *st, TObject *o) { |
| 69 | lua_assert(ttype(o) == LUA_TNUMBER || | ||
| 70 | ttype(o) == ((TValue *)(o->value.v))->ttype); | ||
| 69 | switch (ttype(o)) { | 71 | switch (ttype(o)) { |
| 70 | case LUA_TUSERDATA: case LUA_TSTRING: | 72 | case LUA_TUSERDATA: case LUA_TSTRING: |
| 71 | strmark(tsvalue(o)); | 73 | strmark(tsvalue(o)); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 1.61 2001/01/25 16:45:36 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.62 2001/01/26 14:16:35 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 | */ |
| @@ -19,7 +19,8 @@ | |||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | const TObject luaO_nilobject = {LUA_TNIL, {NULL}}; | 22 | const char luaO_ttnil = LUA_TNIL; |
| 23 | const TObject luaO_nilobject = {LUA_TNIL, {(void *)&luaO_ttnil}}; | ||
| 23 | 24 | ||
| 24 | 25 | ||
| 25 | /* | 26 | /* |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 1.89 2001/01/26 15:58:50 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.90 2001/01/29 17:16:58 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 | */ |
| @@ -29,7 +29,7 @@ | |||
| 29 | #endif | 29 | #endif |
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | /* mark for closures active in the stack */ | 32 | /* ttype for closures active in the stack */ |
| 33 | #define LUA_TMARK 6 | 33 | #define LUA_TMARK 6 |
| 34 | 34 | ||
| 35 | 35 | ||
| @@ -41,6 +41,14 @@ | |||
| 41 | #define is_T_MARK(t) (ttype(t) == LUA_TMARK) | 41 | #define is_T_MARK(t) (ttype(t) == LUA_TMARK) |
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | /* | ||
| 45 | ** tag at the start of all "boxed" Lua values | ||
| 46 | */ | ||
| 47 | typedef struct TValue { | ||
| 48 | char ttype; | ||
| 49 | } TValue; | ||
| 50 | |||
| 51 | |||
| 44 | typedef union { | 52 | typedef union { |
| 45 | void *v; | 53 | void *v; |
| 46 | lua_Number n; /* LUA_TNUMBER */ | 54 | lua_Number n; /* LUA_TNUMBER */ |
| @@ -87,7 +95,8 @@ typedef struct lua_TObject { | |||
| 87 | { TObject *_o=(obj); struct CallInfo *_v=(x); \ | 95 | { TObject *_o=(obj); struct CallInfo *_v=(x); \ |
| 88 | _o->tt=LUA_TMARK; _o->value.v=_v; } | 96 | _o->tt=LUA_TMARK; _o->value.v=_v; } |
| 89 | 97 | ||
| 90 | #define setnilvalue(obj) { (obj)->tt=LUA_TNIL; } | 98 | #define setnilvalue(obj) \ |
| 99 | { TObject *_o=(obj); _o->tt=LUA_TNIL; _o->value.v = (void *)&luaO_ttnil; } | ||
| 91 | 100 | ||
| 92 | #define setobj(obj1,obj2) \ | 101 | #define setobj(obj1,obj2) \ |
| 93 | { TObject *o1=(obj1); const TObject *o2=(obj2); \ | 102 | { TObject *o1=(obj1); const TObject *o2=(obj2); \ |
| @@ -107,6 +116,8 @@ typedef struct lua_TObject { | |||
| 107 | #define TSPACK ((int)sizeof(int)) | 116 | #define TSPACK ((int)sizeof(int)) |
| 108 | 117 | ||
| 109 | typedef struct TString { | 118 | typedef struct TString { |
| 119 | TValue v; | ||
| 120 | unsigned char marked; | ||
| 110 | union { | 121 | union { |
| 111 | struct { /* for strings */ | 122 | struct { /* for strings */ |
| 112 | luint32 hash; | 123 | luint32 hash; |
| @@ -119,7 +130,6 @@ typedef struct TString { | |||
| 119 | } u; | 130 | } u; |
| 120 | size_t len; | 131 | size_t len; |
| 121 | struct TString *nexthash; /* chain for hash table */ | 132 | struct TString *nexthash; /* chain for hash table */ |
| 122 | int marked; | ||
| 123 | char str[TSPACK]; /* variable length string!! must be the last field! */ | 133 | char str[TSPACK]; /* variable length string!! must be the last field! */ |
| 124 | } TString; | 134 | } TString; |
| 125 | 135 | ||
| @@ -128,6 +138,7 @@ typedef struct TString { | |||
| 128 | ** Function Prototypes | 138 | ** Function Prototypes |
| 129 | */ | 139 | */ |
| 130 | typedef struct Proto { | 140 | typedef struct Proto { |
| 141 | TValue v; | ||
| 131 | lua_Number *knum; /* numbers used by the function */ | 142 | lua_Number *knum; /* numbers used by the function */ |
| 132 | int sizeknum; /* size of `knum' */ | 143 | int sizeknum; /* size of `knum' */ |
| 133 | struct TString **kstr; /* strings used by the function */ | 144 | struct TString **kstr; /* strings used by the function */ |
| @@ -162,14 +173,15 @@ typedef struct LocVar { | |||
| 162 | ** Closures | 173 | ** Closures |
| 163 | */ | 174 | */ |
| 164 | typedef struct Closure { | 175 | typedef struct Closure { |
| 176 | TValue v; | ||
| 177 | char isC; /* 0 for Lua functions, 1 for C functions */ | ||
| 178 | short nupvalues; | ||
| 165 | union { | 179 | union { |
| 166 | lua_CFunction c; /* C functions */ | 180 | lua_CFunction c; /* C functions */ |
| 167 | struct Proto *l; /* Lua functions */ | 181 | struct Proto *l; /* Lua functions */ |
| 168 | } f; | 182 | } f; |
| 169 | struct Closure *next; | 183 | struct Closure *next; |
| 170 | struct Closure *mark; /* marked closures (point to itself when not marked) */ | 184 | struct Closure *mark; /* marked closures (point to itself when not marked) */ |
| 171 | short isC; /* 0 for Lua functions, 1 for C functions */ | ||
| 172 | short nupvalues; | ||
| 173 | TObject upvalue[1]; | 185 | TObject upvalue[1]; |
| 174 | } Closure; | 186 | } Closure; |
| 175 | 187 | ||
| @@ -186,6 +198,7 @@ typedef struct Node { | |||
| 186 | 198 | ||
| 187 | 199 | ||
| 188 | typedef struct Hash { | 200 | typedef struct Hash { |
| 201 | TValue v; | ||
| 189 | Node *node; | 202 | Node *node; |
| 190 | int htag; | 203 | int htag; |
| 191 | int size; | 204 | int size; |
| @@ -210,6 +223,7 @@ typedef struct Hash { | |||
| 210 | ** informations about a call (for debugging) | 223 | ** informations about a call (for debugging) |
| 211 | */ | 224 | */ |
| 212 | typedef struct CallInfo { | 225 | typedef struct CallInfo { |
| 226 | TValue v; | ||
| 213 | struct Closure *func; /* function being called */ | 227 | struct Closure *func; /* function being called */ |
| 214 | const Instruction **pc; /* current pc of called function */ | 228 | const Instruction **pc; /* current pc of called function */ |
| 215 | int lastpc; /* last pc traced */ | 229 | int lastpc; /* last pc traced */ |
| @@ -218,6 +232,7 @@ typedef struct CallInfo { | |||
| 218 | } CallInfo; | 232 | } CallInfo; |
| 219 | 233 | ||
| 220 | 234 | ||
| 235 | extern const char luaO_ttnil; /* "address" of the nil value */ | ||
| 221 | extern const TObject luaO_nilobject; | 236 | extern const TObject luaO_nilobject; |
| 222 | 237 | ||
| 223 | 238 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.51 2001/01/19 13:20:30 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.52 2001/01/26 15:58:50 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 | */ |
| @@ -76,6 +76,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
| 76 | } | 76 | } |
| 77 | /* not found */ | 77 | /* not found */ |
| 78 | ts = (TString *)luaM_malloc(L, sizestring(l)); | 78 | ts = (TString *)luaM_malloc(L, sizestring(l)); |
| 79 | ts->v.ttype = LUA_TSTRING; | ||
| 79 | ts->marked = 0; | 80 | ts->marked = 0; |
| 80 | ts->nexthash = NULL; | 81 | ts->nexthash = NULL; |
| 81 | ts->len = l; | 82 | ts->len = l; |
| @@ -91,6 +92,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
| 91 | TString *luaS_newudata (lua_State *L, size_t s, void *udata) { | 92 | TString *luaS_newudata (lua_State *L, size_t s, void *udata) { |
| 92 | union L_UTString *uts = (union L_UTString *)luaM_malloc(L, sizeudata(s)); | 93 | union L_UTString *uts = (union L_UTString *)luaM_malloc(L, sizeudata(s)); |
| 93 | TString *ts = &uts->ts; | 94 | TString *ts = &uts->ts; |
| 95 | ts->v.ttype = LUA_TUSERDATA; | ||
| 94 | ts->marked = 0; | 96 | ts->marked = 0; |
| 95 | ts->nexthash = NULL; | 97 | ts->nexthash = NULL; |
| 96 | ts->len = s; | 98 | ts->len = s; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 1.71 2001/01/29 13:02:20 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.72 2001/01/29 17:16:58 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 | */ |
| @@ -98,6 +98,7 @@ static void setnodevector (lua_State *L, Hash *t, luint32 size) { | |||
| 98 | 98 | ||
| 99 | Hash *luaH_new (lua_State *L, int size) { | 99 | Hash *luaH_new (lua_State *L, int size) { |
| 100 | Hash *t = luaM_new(L, Hash); | 100 | Hash *t = luaM_new(L, Hash); |
| 101 | t->v.ttype = LUA_TTABLE; | ||
| 101 | t->htag = TagDefault; | 102 | t->htag = TagDefault; |
| 102 | t->next = G(L)->roottable; | 103 | t->next = G(L)->roottable; |
| 103 | G(L)->roottable = t; | 104 | G(L)->roottable = t; |
