diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-10-17 09:58:41 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-10-17 09:58:41 -0200 |
| commit | 2cffb08a5c770678999a313a83c76652a3d02d4c (patch) | |
| tree | 2a638e6dc4e4682863aadcff0073fa7af0c6198e /table.c | |
| parent | 15f40fddca66301a53f8b0adf41958c7e9add945 (diff) | |
| download | lua-2cffb08a5c770678999a313a83c76652a3d02d4c.tar.gz lua-2cffb08a5c770678999a313a83c76652a3d02d4c.tar.bz2 lua-2cffb08a5c770678999a313a83c76652a3d02d4c.zip | |
new style for debug information about functions: no more SETFUNCTION
opcodes. When a function is called, its entry in the stack is marked with
LUA_T_(C)MARK, so function 'luaD_stackedfunction' can find it if
needed.
Functions now have their file names in the headers, so there is no need
of 'addfile' and the like.
Diffstat (limited to '')
| -rw-r--r-- | table.c | 102 |
1 files changed, 51 insertions, 51 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Module to control static tables | 3 | ** Module to control static tables |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_table="$Id: table.c,v 2.33 1995/10/04 14:20:26 roberto Exp roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.34 1995/10/13 15:16:25 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | 9 | ||
| @@ -28,11 +28,6 @@ static Word lua_nconstant = 0; | |||
| 28 | static Long lua_maxconstant = 0; | 28 | static Long lua_maxconstant = 0; |
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | |||
| 32 | #define MAXFILE 20 | ||
| 33 | char *lua_file[MAXFILE]; | ||
| 34 | int lua_nfile; | ||
| 35 | |||
| 36 | #define GARBAGE_BLOCK 1024 | 31 | #define GARBAGE_BLOCK 1024 |
| 37 | #define MIN_GARBAGE_BLOCK (GARBAGE_BLOCK/2) | 32 | #define MIN_GARBAGE_BLOCK (GARBAGE_BLOCK/2) |
| 38 | 33 | ||
| @@ -68,8 +63,6 @@ static void lua_initsymbol (void) | |||
| 68 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring; | 63 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring; |
| 69 | n = luaI_findsymbolbyname("setfallback"); | 64 | n = luaI_findsymbolbyname("setfallback"); |
| 70 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_setfallback; | 65 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_setfallback; |
| 71 | n = luaI_findsymbolbyname("getstack"); | ||
| 72 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_getstack; | ||
| 73 | n = luaI_findsymbolbyname("error"); | 66 | n = luaI_findsymbolbyname("error"); |
| 74 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_error; | 67 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_error; |
| 75 | } | 68 | } |
| @@ -154,25 +147,29 @@ Word luaI_findconstantbyname (char *name) | |||
| 154 | /* | 147 | /* |
| 155 | ** Traverse symbol table objects | 148 | ** Traverse symbol table objects |
| 156 | */ | 149 | */ |
| 157 | void lua_travsymbol (void (*fn)(Object *)) | 150 | static char *lua_travsymbol (int (*fn)(Object *)) |
| 158 | { | 151 | { |
| 159 | Word i; | 152 | Word i; |
| 160 | for (i=0; i<lua_ntable; i++) | 153 | for (i=0; i<lua_ntable; i++) |
| 161 | fn(&s_object(i)); | 154 | if (fn(&s_object(i))) |
| 155 | return luaI_nodebysymbol(i)->ts.str; | ||
| 156 | return NULL; | ||
| 162 | } | 157 | } |
| 163 | 158 | ||
| 164 | 159 | ||
| 165 | /* | 160 | /* |
| 166 | ** Mark an object if it is a string or a unmarked array. | 161 | ** Mark an object if it is a string or a unmarked array. |
| 167 | */ | 162 | */ |
| 168 | void lua_markobject (Object *o) | 163 | int lua_markobject (Object *o) |
| 169 | { | 164 | { |
| 170 | if (tag(o) == LUA_T_STRING && !tsvalue(o)->marked) | 165 | if (tag(o) == LUA_T_STRING && !tsvalue(o)->marked) |
| 171 | tsvalue(o)->marked = 1; | 166 | tsvalue(o)->marked = 1; |
| 172 | else if (tag(o) == LUA_T_ARRAY) | 167 | else if (tag(o) == LUA_T_ARRAY) |
| 173 | lua_hashmark (avalue(o)); | 168 | lua_hashmark (avalue(o)); |
| 174 | else if (o->tag == LUA_T_FUNCTION && !o->value.tf->marked) | 169 | else if ((o->tag == LUA_T_FUNCTION || o->tag == LUA_T_MARK) |
| 170 | && !o->value.tf->marked) | ||
| 175 | o->value.tf->marked = 1; | 171 | o->value.tf->marked = 1; |
| 172 | return 0; | ||
| 176 | } | 173 | } |
| 177 | 174 | ||
| 178 | 175 | ||
| @@ -200,70 +197,39 @@ void lua_pack (void) | |||
| 200 | 197 | ||
| 201 | 198 | ||
| 202 | /* | 199 | /* |
| 203 | ** Add a file name at file table, checking overflow. This function also set | ||
| 204 | ** the external variable "lua_filename" with the function filename set. | ||
| 205 | ** Return 0 on success or error message on error. | ||
| 206 | */ | ||
| 207 | char *lua_addfile (char *fn) | ||
| 208 | { | ||
| 209 | if (lua_nfile >= MAXFILE) | ||
| 210 | return "too many files"; | ||
| 211 | if ((lua_file[lua_nfile++] = luaI_strdup (fn)) == NULL) | ||
| 212 | return "not enough memory"; | ||
| 213 | return NULL; | ||
| 214 | } | ||
| 215 | |||
| 216 | /* | ||
| 217 | ** Delete a file from file stack | ||
| 218 | */ | ||
| 219 | int lua_delfile (void) | ||
| 220 | { | ||
| 221 | luaI_free(lua_file[--lua_nfile]); | ||
| 222 | return 1; | ||
| 223 | } | ||
| 224 | |||
| 225 | /* | ||
| 226 | ** Return the last file name set. | ||
| 227 | */ | ||
| 228 | char *lua_filename (void) | ||
| 229 | { | ||
| 230 | return lua_file[lua_nfile-1]; | ||
| 231 | } | ||
| 232 | |||
| 233 | /* | ||
| 234 | ** Internal function: return next global variable | 200 | ** Internal function: return next global variable |
| 235 | */ | 201 | */ |
| 236 | static void lua_nextvar (void) | 202 | static void lua_nextvar (void) |
| 237 | { | 203 | { |
| 238 | char *varname; | 204 | Word next; |
| 239 | TreeNode *next; | ||
| 240 | lua_Object o = lua_getparam(1); | 205 | lua_Object o = lua_getparam(1); |
| 241 | if (o == LUA_NOOBJECT) | 206 | if (o == LUA_NOOBJECT) |
| 242 | lua_error("too few arguments to function `nextvar'"); | 207 | lua_error("too few arguments to function `nextvar'"); |
| 243 | if (lua_getparam(2) != LUA_NOOBJECT) | 208 | if (lua_getparam(2) != LUA_NOOBJECT) |
| 244 | lua_error("too many arguments to function `nextvar'"); | 209 | lua_error("too many arguments to function `nextvar'"); |
| 245 | if (lua_isnil(o)) | 210 | if (lua_isnil(o)) |
| 246 | varname = NULL; | 211 | next = 0; |
| 247 | else if (!lua_isstring(o)) | 212 | else if (!lua_isstring(o)) |
| 248 | { | 213 | { |
| 249 | lua_error("incorrect argument to function `nextvar'"); | 214 | lua_error("incorrect argument to function `nextvar'"); |
| 250 | return; /* to avoid warnings */ | 215 | return; /* to avoid warnings */ |
| 251 | } | 216 | } |
| 252 | else | 217 | else |
| 253 | varname = lua_getstring(o); | 218 | next = luaI_findsymbolbyname(lua_getstring(o)) + 1; |
| 254 | next = lua_varnext(varname); | 219 | while (next < lua_ntable && s_tag(next) == LUA_T_NIL) next++; |
| 255 | if (next == NULL) | 220 | if (next >= lua_ntable) |
| 256 | { | 221 | { |
| 257 | lua_pushnil(); | 222 | lua_pushnil(); |
| 258 | lua_pushnil(); | 223 | lua_pushnil(); |
| 259 | } | 224 | } |
| 260 | else | 225 | else |
| 261 | { | 226 | { |
| 227 | TreeNode *t = luaI_nodebysymbol(next); | ||
| 262 | Object name; | 228 | Object name; |
| 263 | tag(&name) = LUA_T_STRING; | 229 | tag(&name) = LUA_T_STRING; |
| 264 | tsvalue(&name) = &(next->ts); | 230 | tsvalue(&name) = &(t->ts); |
| 265 | luaI_pushobject(&name); | 231 | luaI_pushobject(&name); |
| 266 | luaI_pushobject(&s_object(next->varindex)); | 232 | luaI_pushobject(&s_object(next)); |
| 267 | } | 233 | } |
| 268 | } | 234 | } |
| 269 | 235 | ||
| @@ -286,3 +252,37 @@ static void getglobal (void) | |||
| 286 | lua_error("incorrect argument to function `getglobal'"); | 252 | lua_error("incorrect argument to function `getglobal'"); |
| 287 | lua_pushobject(lua_getglobal(lua_getstring(name))); | 253 | lua_pushobject(lua_getglobal(lua_getstring(name))); |
| 288 | } | 254 | } |
| 255 | |||
| 256 | |||
| 257 | static lua_CFunction cfunc = NULL; | ||
| 258 | static int checkfunc (Object *o) | ||
| 259 | { | ||
| 260 | return ((o->tag == LUA_T_CMARK || o->tag == LUA_T_CFUNCTION) && | ||
| 261 | o->value.f == cfunc); | ||
| 262 | } | ||
| 263 | |||
| 264 | |||
| 265 | void luaI_funcInfo (struct Object *func, char **filename, char **funcname, | ||
| 266 | char **objname, int *linedefined) | ||
| 267 | { | ||
| 268 | if (func->tag == LUA_T_MARK || func->tag == LUA_T_FUNCTION) | ||
| 269 | { | ||
| 270 | TFunc *f = func->value.tf; | ||
| 271 | *filename = f->fileName; | ||
| 272 | *funcname = f->name1; | ||
| 273 | *objname = f->name2; | ||
| 274 | *linedefined = f->lineDefined; | ||
| 275 | } | ||
| 276 | else if (func->tag == LUA_T_CMARK || func->tag == LUA_T_CFUNCTION) | ||
| 277 | { | ||
| 278 | /* temporario: */ | ||
| 279 | cfunc = func->value.f; | ||
| 280 | *filename = "(?)"; | ||
| 281 | *objname = 0; | ||
| 282 | *linedefined = 0; | ||
| 283 | *funcname = lua_travsymbol(checkfunc); | ||
| 284 | if (*funcname == NULL) | ||
| 285 | *funcname = luaI_travfallbacks(checkfunc); | ||
| 286 | } | ||
| 287 | } | ||
| 288 | |||
