diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-29 17:34:02 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-29 17:34:02 -0200 |
| commit | 63a822c8e199918c54e325cbc8696ed04071aba8 (patch) | |
| tree | 430e1b2fe1ffafb712bd712b5b625a18afaa953d /lobject.h | |
| parent | 09def5da4440a5a91c2721f495bd9c3df1081874 (diff) | |
| download | lua-63a822c8e199918c54e325cbc8696ed04071aba8.tar.gz lua-63a822c8e199918c54e325cbc8696ed04071aba8.tar.bz2 lua-63a822c8e199918c54e325cbc8696ed04071aba8.zip | |
all boxed types start with their tags
Diffstat (limited to 'lobject.h')
| -rw-r--r-- | lobject.h | 27 |
1 files changed, 21 insertions, 6 deletions
| @@ -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 | ||
