diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-05 09:14:08 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-05 09:14:08 -0300 |
commit | 001f2bdd0e2f8803889c1b5164b57a51e44aef5b (patch) | |
tree | d200cf4d708be3c61e64640c45b47050c9c6a375 /ldebug.c | |
parent | cd2ddaded97f7f2b2af02cecfd165cf70e6f83f4 (diff) | |
download | lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.gz lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.bz2 lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.zip |
new definition for types-tags
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 79 |
1 files changed, 40 insertions, 39 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.42 2000/09/18 19:39:49 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.43 2000/10/02 20:10:55 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,23 +23,21 @@ | |||
23 | #include "luadebug.h" | 23 | #include "luadebug.h" |
24 | 24 | ||
25 | 25 | ||
26 | |||
26 | static const char *getfuncname (lua_State *L, StkId f, const char **name); | 27 | static const char *getfuncname (lua_State *L, StkId f, const char **name); |
27 | 28 | ||
28 | 29 | ||
29 | static void setnormalized (TObject *d, const TObject *s) { | 30 | static void setnormalized (TObject *d, const TObject *s) { |
30 | switch (s->ttype) { | 31 | if (ttype(s) == LUA_TMARK) { |
31 | case TAG_CMARK: { | 32 | clvalue(d) = infovalue(s)->func; |
32 | clvalue(d) = clvalue(s); | 33 | ttype(d) = LUA_TFUNCTION; |
33 | ttype(d) = TAG_CCLOSURE; | ||
34 | break; | ||
35 | } | ||
36 | case TAG_LMARK: { | ||
37 | clvalue(d) = infovalue(s)->func; | ||
38 | ttype(d) = TAG_LCLOSURE; | ||
39 | break; | ||
40 | } | ||
41 | default: *d = *s; | ||
42 | } | 34 | } |
35 | else *d = *s; | ||
36 | } | ||
37 | |||
38 | |||
39 | static int isLmark (StkId o) { | ||
40 | return (o && ttype(o) == LUA_TMARK && !infovalue(o)->func->isC); | ||
43 | } | 41 | } |
44 | 42 | ||
45 | 43 | ||
@@ -82,9 +80,9 @@ int lua_getstack (lua_State *L, int level, lua_Debug *ar) { | |||
82 | 80 | ||
83 | static int lua_nups (StkId f) { | 81 | static int lua_nups (StkId f) { |
84 | switch (ttype(f)) { | 82 | switch (ttype(f)) { |
85 | case TAG_LCLOSURE: case TAG_CCLOSURE: case TAG_CMARK: | 83 | case LUA_TFUNCTION: |
86 | return clvalue(f)->nupvalues; | 84 | return clvalue(f)->nupvalues; |
87 | case TAG_LMARK: | 85 | case LUA_TMARK: |
88 | return infovalue(f)->func->nupvalues; | 86 | return infovalue(f)->func->nupvalues; |
89 | default: | 87 | default: |
90 | return 0; | 88 | return 0; |
@@ -125,13 +123,13 @@ int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) { | |||
125 | 123 | ||
126 | static int lua_currentpc (StkId f) { | 124 | static int lua_currentpc (StkId f) { |
127 | CallInfo *ci = infovalue(f); | 125 | CallInfo *ci = infovalue(f); |
128 | LUA_ASSERT(ttype(f) == TAG_LMARK, "function has no pc"); | 126 | LUA_ASSERT(isLmark(f), "function has no pc"); |
129 | return (*ci->pc - ci->func->f.l->code) - 1; | 127 | return (*ci->pc - ci->func->f.l->code) - 1; |
130 | } | 128 | } |
131 | 129 | ||
132 | 130 | ||
133 | static int lua_currentline (StkId f) { | 131 | static int lua_currentline (StkId f) { |
134 | if (ttype(f) != TAG_LMARK) | 132 | if (!isLmark(f)) |
135 | return -1; /* only active lua functions have current-line information */ | 133 | return -1; /* only active lua functions have current-line information */ |
136 | else { | 134 | else { |
137 | CallInfo *ci = infovalue(f); | 135 | CallInfo *ci = infovalue(f); |
@@ -143,7 +141,7 @@ static int lua_currentline (StkId f) { | |||
143 | 141 | ||
144 | 142 | ||
145 | static Proto *getluaproto (StkId f) { | 143 | static Proto *getluaproto (StkId f) { |
146 | return (ttype(f) == TAG_LMARK) ? infovalue(f)->func->f.l : NULL; | 144 | return (isLmark(f) ? infovalue(f)->func->f.l : NULL); |
147 | } | 145 | } |
148 | 146 | ||
149 | 147 | ||
@@ -179,22 +177,25 @@ static void infoLproto (lua_Debug *ar, Proto *f) { | |||
179 | } | 177 | } |
180 | 178 | ||
181 | 179 | ||
182 | static void lua_funcinfo (lua_Debug *ar, StkId func) { | 180 | static void lua_funcinfo (lua_State *L, lua_Debug *ar, StkId func) { |
181 | Closure *cl = NULL; | ||
183 | switch (ttype(func)) { | 182 | switch (ttype(func)) { |
184 | case TAG_LCLOSURE: | 183 | case LUA_TFUNCTION: |
185 | infoLproto(ar, clvalue(func)->f.l); | 184 | cl = clvalue(func); |
186 | break; | ||
187 | case TAG_LMARK: | ||
188 | infoLproto(ar, infovalue(func)->func->f.l); | ||
189 | break; | 185 | break; |
190 | case TAG_CCLOSURE: case TAG_CMARK: | 186 | case LUA_TMARK: |
191 | ar->source = "(C)"; | 187 | cl = infovalue(func)->func; |
192 | ar->linedefined = -1; | ||
193 | ar->what = "C"; | ||
194 | break; | 188 | break; |
195 | default: | 189 | default: |
196 | LUA_INTERNALERROR("invalid `func' value"); | 190 | lua_error(L, "value for `lua_getinfo' is not a function"); |
197 | } | 191 | } |
192 | if (cl->isC) { | ||
193 | ar->source = "(C)"; | ||
194 | ar->linedefined = -1; | ||
195 | ar->what = "C"; | ||
196 | } | ||
197 | else | ||
198 | infoLproto(ar, cl->f.l); | ||
198 | luaO_chunkid(ar->short_src, ar->source, sizeof(ar->short_src)); | 199 | luaO_chunkid(ar->short_src, ar->source, sizeof(ar->short_src)); |
199 | if (ar->linedefined == 0) | 200 | if (ar->linedefined == 0) |
200 | ar->what = "main"; | 201 | ar->what = "main"; |
@@ -218,7 +219,7 @@ static const char *travglobals (lua_State *L, const TObject *o) { | |||
218 | int i; | 219 | int i; |
219 | for (i=0; i<g->size; i++) { | 220 | for (i=0; i<g->size; i++) { |
220 | if (luaO_equalObj(o, val(node(g, i))) && | 221 | if (luaO_equalObj(o, val(node(g, i))) && |
221 | ttype(key(node(g, i))) == TAG_STRING) | 222 | ttype(key(node(g, i))) == LUA_TSTRING) |
222 | return tsvalue(key(node(g, i)))->str; | 223 | return tsvalue(key(node(g, i)))->str; |
223 | } | 224 | } |
224 | return NULL; | 225 | return NULL; |
@@ -250,7 +251,7 @@ int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
250 | for (; *what; what++) { | 251 | for (; *what; what++) { |
251 | switch (*what) { | 252 | switch (*what) { |
252 | case 'S': { | 253 | case 'S': { |
253 | lua_funcinfo(ar, func); | 254 | lua_funcinfo(L, ar, func); |
254 | break; | 255 | break; |
255 | } | 256 | } |
256 | case 'l': { | 257 | case 'l': { |
@@ -377,8 +378,8 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) { | |||
377 | 378 | ||
378 | static const char *getobjname (lua_State *L, StkId obj, const char **name) { | 379 | static const char *getobjname (lua_State *L, StkId obj, const char **name) { |
379 | StkId func = aux_stackedfunction(L, 0, obj); | 380 | StkId func = aux_stackedfunction(L, 0, obj); |
380 | if (func == NULL || ttype(func) != TAG_LMARK) | 381 | if (!isLmark(func)) |
381 | return NULL; /* not a Lua function */ | 382 | return NULL; /* not an active Lua function */ |
382 | else { | 383 | else { |
383 | Proto *p = infovalue(func)->func->f.l; | 384 | Proto *p = infovalue(func)->func->f.l; |
384 | int pc = lua_currentpc(func); | 385 | int pc = lua_currentpc(func); |
@@ -409,8 +410,8 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) { | |||
409 | 410 | ||
410 | static const char *getfuncname (lua_State *L, StkId f, const char **name) { | 411 | static const char *getfuncname (lua_State *L, StkId f, const char **name) { |
411 | StkId func = aux_stackedfunction(L, 0, f); /* calling function */ | 412 | StkId func = aux_stackedfunction(L, 0, f); /* calling function */ |
412 | if (func == NULL || ttype(func) != TAG_LMARK) | 413 | if (!isLmark(func)) |
413 | return NULL; /* not a Lua function */ | 414 | return NULL; /* not an active Lua function */ |
414 | else { | 415 | else { |
415 | Proto *p = infovalue(func)->func->f.l; | 416 | Proto *p = infovalue(func)->func->f.l; |
416 | int pc = lua_currentpc(func); | 417 | int pc = lua_currentpc(func); |
@@ -433,7 +434,7 @@ static const char *getfuncname (lua_State *L, StkId f, const char **name) { | |||
433 | void luaG_typeerror (lua_State *L, StkId o, const char *op) { | 434 | void luaG_typeerror (lua_State *L, StkId o, const char *op) { |
434 | const char *name; | 435 | const char *name; |
435 | const char *kind = getobjname(L, o, &name); | 436 | const char *kind = getobjname(L, o, &name); |
436 | const char *t = luaO_typename(L, o); | 437 | const char *t = luaO_typename(o); |
437 | if (kind) | 438 | if (kind) |
438 | luaO_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)", | 439 | luaO_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)", |
439 | op, kind, name, t); | 440 | op, kind, name, t); |
@@ -442,7 +443,7 @@ void luaG_typeerror (lua_State *L, StkId o, const char *op) { | |||
442 | } | 443 | } |
443 | 444 | ||
444 | 445 | ||
445 | void luaG_binerror (lua_State *L, StkId p1, lua_Tag t, const char *op) { | 446 | void luaG_binerror (lua_State *L, StkId p1, int t, const char *op) { |
446 | if (ttype(p1) == t) p1++; | 447 | if (ttype(p1) == t) p1++; |
447 | LUA_ASSERT(ttype(p1) != t, "must be an error"); | 448 | LUA_ASSERT(ttype(p1) != t, "must be an error"); |
448 | luaG_typeerror(L, p1, op); | 449 | luaG_typeerror(L, p1, op); |
@@ -450,8 +451,8 @@ void luaG_binerror (lua_State *L, StkId p1, lua_Tag t, const char *op) { | |||
450 | 451 | ||
451 | 452 | ||
452 | void luaG_ordererror (lua_State *L, StkId top) { | 453 | void luaG_ordererror (lua_State *L, StkId top) { |
453 | const char *t1 = luaO_typename(L, top-2); | 454 | const char *t1 = luaO_typename(top-2); |
454 | const char *t2 = luaO_typename(L, top-1); | 455 | const char *t2 = luaO_typename(top-1); |
455 | if (t1[2] == t2[2]) | 456 | if (t1[2] == t2[2]) |
456 | luaO_verror(L, "attempt to compare two %.10s values", t1); | 457 | luaO_verror(L, "attempt to compare two %.10s values", t1); |
457 | else | 458 | else |