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 | |
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.
-rw-r--r-- | func.h | 4 | ||||
-rw-r--r-- | inout.c | 109 | ||||
-rw-r--r-- | inout.h | 9 | ||||
-rw-r--r-- | lua.stx | 35 | ||||
-rw-r--r-- | opcode.c | 59 | ||||
-rw-r--r-- | opcode.h | 6 | ||||
-rw-r--r-- | table.c | 102 | ||||
-rw-r--r-- | table.h | 11 |
8 files changed, 121 insertions, 214 deletions
@@ -12,6 +12,10 @@ typedef struct TFunc | |||
12 | char marked; | 12 | char marked; |
13 | int size; | 13 | int size; |
14 | Byte *code; | 14 | Byte *code; |
15 | int lineDefined; | ||
16 | char *name1; /* function or method name (or null if main) */ | ||
17 | char *name2; /* object name (or null if not method) */ | ||
18 | char *fileName; | ||
15 | } TFunc; | 19 | } TFunc; |
16 | 20 | ||
17 | Long luaI_funccollector (void); | 21 | Long luaI_funccollector (void); |
@@ -5,7 +5,7 @@ | |||
5 | ** Also provides some predefined lua functions. | 5 | ** Also provides some predefined lua functions. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | char *rcs_inout="$Id: inout.c,v 2.21 1995/10/04 14:20:26 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.22 1995/10/09 13:06:20 roberto Exp roberto $"; |
9 | 9 | ||
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
@@ -31,20 +31,9 @@ char *rcs_inout="$Id: inout.c,v 2.21 1995/10/04 14:20:26 roberto Exp roberto $"; | |||
31 | Word lua_linenumber; | 31 | Word lua_linenumber; |
32 | Bool lua_debug; | 32 | Bool lua_debug; |
33 | Word lua_debugline = 0; | 33 | Word lua_debugline = 0; |
34 | char *lua_parsedfile; | ||
34 | 35 | ||
35 | 36 | ||
36 | /* Internal variables */ | ||
37 | |||
38 | typedef struct FuncStackNode { | ||
39 | struct FuncStackNode *next; | ||
40 | char *file; | ||
41 | Word function; | ||
42 | Word line; | ||
43 | } FuncStackNode; | ||
44 | |||
45 | static FuncStackNode *funcStack = NULL; | ||
46 | static Word nfuncstack=0; | ||
47 | |||
48 | static FILE *fp; | 37 | static FILE *fp; |
49 | static char *st; | 38 | static char *st; |
50 | 39 | ||
@@ -70,16 +59,17 @@ static int stringinput (void) | |||
70 | */ | 59 | */ |
71 | char *lua_openfile (char *fn) | 60 | char *lua_openfile (char *fn) |
72 | { | 61 | { |
73 | lua_linenumber = 1; | ||
74 | lua_setinput (fileinput); | 62 | lua_setinput (fileinput); |
75 | fp = fopen (fn, "r"); | 63 | fp = fopen (fn, "r"); |
76 | if (fp == NULL) | 64 | if (fp == NULL) |
77 | { | 65 | { |
78 | static char buff[255]; | 66 | static char buff[255]; |
79 | sprintf(buff, "unable to open file %.230s", fn); | 67 | sprintf(buff, "unable to open file `%.200s'", fn); |
80 | return buff; | 68 | return buff; |
81 | } | 69 | } |
82 | return lua_addfile (fn); | 70 | lua_linenumber = 1; |
71 | lua_parsedfile = lua_constcreate(fn)->ts.str; | ||
72 | return NULL; | ||
83 | } | 73 | } |
84 | 74 | ||
85 | /* | 75 | /* |
@@ -89,7 +79,6 @@ void lua_closefile (void) | |||
89 | { | 79 | { |
90 | if (fp != NULL) | 80 | if (fp != NULL) |
91 | { | 81 | { |
92 | lua_delfile(); | ||
93 | fclose (fp); | 82 | fclose (fp); |
94 | fp = NULL; | 83 | fp = NULL; |
95 | } | 84 | } |
@@ -98,16 +87,12 @@ void lua_closefile (void) | |||
98 | /* | 87 | /* |
99 | ** Function to open a string to be input unit | 88 | ** Function to open a string to be input unit |
100 | */ | 89 | */ |
101 | char *lua_openstring (char *s) | 90 | void lua_openstring (char *s) |
102 | { | 91 | { |
103 | lua_linenumber = 1; | ||
104 | lua_setinput (stringinput); | 92 | lua_setinput (stringinput); |
105 | st = s; | 93 | st = s; |
106 | { | 94 | lua_linenumber = 1; |
107 | char sn[64]; | 95 | lua_parsedfile = lua_constcreate("(string)")->ts.str; |
108 | sprintf (sn, "String: %10.10s...", s); | ||
109 | return lua_addfile (sn); | ||
110 | } | ||
111 | } | 96 | } |
112 | 97 | ||
113 | /* | 98 | /* |
@@ -115,75 +100,6 @@ char *lua_openstring (char *s) | |||
115 | */ | 100 | */ |
116 | void lua_closestring (void) | 101 | void lua_closestring (void) |
117 | { | 102 | { |
118 | lua_delfile(); | ||
119 | } | ||
120 | |||
121 | |||
122 | /* | ||
123 | ** Called to execute SETFUNCTION opcode, this function pushs a function into | ||
124 | ** function stack. | ||
125 | */ | ||
126 | void lua_pushfunction (char *file, Word function) | ||
127 | { | ||
128 | FuncStackNode *newNode; | ||
129 | if (nfuncstack++ >= MAXFUNCSTACK) | ||
130 | { | ||
131 | lua_error("function stack overflow"); | ||
132 | } | ||
133 | newNode = new(FuncStackNode); | ||
134 | newNode->function = function; | ||
135 | newNode->file = file; | ||
136 | newNode->line= lua_debugline; | ||
137 | newNode->next = funcStack; | ||
138 | funcStack = newNode; | ||
139 | } | ||
140 | |||
141 | /* | ||
142 | ** Called to execute RESET opcode, this function pops a function from | ||
143 | ** function stack. | ||
144 | */ | ||
145 | void lua_popfunction (void) | ||
146 | { | ||
147 | FuncStackNode *temp = funcStack; | ||
148 | if (temp == NULL) return; | ||
149 | --nfuncstack; | ||
150 | lua_debugline = temp->line; | ||
151 | funcStack = temp->next; | ||
152 | luaI_free(temp); | ||
153 | } | ||
154 | |||
155 | /* | ||
156 | ** Report bug building a message and pushing it on the stack. | ||
157 | */ | ||
158 | void luaI_reportbug (char *s, int err) | ||
159 | { | ||
160 | char msg[MAXMESSAGE]; | ||
161 | strcpy (msg, s); | ||
162 | if (lua_debugline != 0) | ||
163 | { | ||
164 | if (funcStack) | ||
165 | { | ||
166 | FuncStackNode *func = funcStack; | ||
167 | int line = lua_debugline; | ||
168 | sprintf (strchr(msg,0), "\n\tactive stack:\n"); | ||
169 | do | ||
170 | { | ||
171 | sprintf (strchr(msg,0), | ||
172 | "\t-> function \"%s\" at file \"%s\":%u\n", | ||
173 | lua_constant[func->function]->str, func->file, line); | ||
174 | line = func->line; | ||
175 | func = func->next; | ||
176 | if (err) lua_popfunction(); | ||
177 | } while (func); | ||
178 | } | ||
179 | else | ||
180 | { | ||
181 | sprintf (strchr(msg,0), | ||
182 | "\n\tin statement begining at line %u of file \"%s\"", | ||
183 | lua_debugline, lua_filename()); | ||
184 | } | ||
185 | } | ||
186 | lua_pushstring(msg); | ||
187 | } | 103 | } |
188 | 104 | ||
189 | 105 | ||
@@ -297,10 +213,3 @@ void luaI_error (void) | |||
297 | lua_error(s); | 213 | lua_error(s); |
298 | } | 214 | } |
299 | 215 | ||
300 | void luaI_getstack (void) | ||
301 | { | ||
302 | char *s = lua_getstring(lua_getparam(1)); | ||
303 | if (s == NULL) s = ""; | ||
304 | luaI_reportbug(s, 0); | ||
305 | } | ||
306 | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: inout.h,v 1.8 1995/05/02 18:43:03 roberto Exp roberto $ | 2 | ** $Id: inout.h,v 1.9 1995/05/16 17:23:58 roberto Exp roberto $ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | 5 | ||
@@ -12,21 +12,18 @@ | |||
12 | extern Word lua_linenumber; | 12 | extern Word lua_linenumber; |
13 | extern Bool lua_debug; | 13 | extern Bool lua_debug; |
14 | extern Word lua_debugline; | 14 | extern Word lua_debugline; |
15 | extern char *lua_parsedfile; | ||
15 | 16 | ||
16 | char *lua_openfile (char *fn); | 17 | char *lua_openfile (char *fn); |
17 | void lua_closefile (void); | 18 | void lua_closefile (void); |
18 | char *lua_openstring (char *s); | 19 | void lua_openstring (char *s); |
19 | void lua_closestring (void); | 20 | void lua_closestring (void); |
20 | void lua_pushfunction (char *file, Word function); | ||
21 | void lua_popfunction (void); | ||
22 | void luaI_reportbug (char *s, int err); | ||
23 | 21 | ||
24 | void lua_internaldofile (void); | 22 | void lua_internaldofile (void); |
25 | void lua_internaldostring (void); | 23 | void lua_internaldostring (void); |
26 | void lua_print (void); | 24 | void lua_print (void); |
27 | void luaI_type (void); | 25 | void luaI_type (void); |
28 | void lua_obj2number (void); | 26 | void lua_obj2number (void); |
29 | void luaI_getstack (void); | ||
30 | void luaI_error (void); | 27 | void luaI_error (void); |
31 | 28 | ||
32 | #endif | 29 | #endif |
@@ -1,6 +1,6 @@ | |||
1 | %{ | 1 | %{ |
2 | 2 | ||
3 | char *rcs_luastx = "$Id: lua.stx,v 3.19 1995/06/08 19:47:28 roberto Exp $"; | 3 | char *rcs_luastx = "$Id: lua.stx,v 3.20 1995/10/04 14:20:26 roberto Exp roberto $"; |
4 | 4 | ||
5 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
@@ -244,17 +244,10 @@ static void init_function (TreeNode *func) | |||
244 | } | 244 | } |
245 | pc=0; basepc=funcCode; maxcurr=maxcode; | 245 | pc=0; basepc=funcCode; maxcurr=maxcode; |
246 | nlocalvar=0; | 246 | nlocalvar=0; |
247 | if (lua_debug) | ||
248 | { | ||
249 | code_byte(SETFUNCTION); | ||
250 | code_code((TFunc *)luaI_strdup(lua_file[lua_nfile-1])); | ||
251 | code_word(luaI_findconstant(func)); | ||
252 | } | ||
253 | } | 247 | } |
254 | 248 | ||
255 | static void codereturn (void) | 249 | static void codereturn (void) |
256 | { | 250 | { |
257 | if (lua_debug) code_byte(RESET); | ||
258 | if (nlocalvar == 0) | 251 | if (nlocalvar == 0) |
259 | code_byte(RETCODE0); | 252 | code_byte(RETCODE0); |
260 | else | 253 | else |
@@ -345,8 +338,8 @@ static void codeIf (Long thenAdd, Long elseAdd) | |||
345 | static void yyerror (char *s) | 338 | static void yyerror (char *s) |
346 | { | 339 | { |
347 | static char msg[256]; | 340 | static char msg[256]; |
348 | sprintf (msg,"%s near \"%s\" at line %d in file \"%s\"", | 341 | sprintf (msg,"%s near \"%s\" at line %d in file `%s'", |
349 | s, lua_lasttext (), lua_linenumber, lua_filename()); | 342 | s, lua_lasttext (), lua_linenumber, lua_parsedfile); |
350 | lua_error (msg); | 343 | lua_error (msg); |
351 | } | 344 | } |
352 | 345 | ||
@@ -435,6 +428,7 @@ functionlist : /* empty */ | |||
435 | function : FUNCTION NAME | 428 | function : FUNCTION NAME |
436 | { | 429 | { |
437 | init_function($2); | 430 | init_function($2); |
431 | $<vInt>$ = lua_linenumber; | ||
438 | } | 432 | } |
439 | body | 433 | body |
440 | { | 434 | { |
@@ -442,6 +436,10 @@ function : FUNCTION NAME | |||
442 | luaI_insertfunction($4); /* may take part in GC */ | 436 | luaI_insertfunction($4); /* may take part in GC */ |
443 | s_tag(func) = LUA_T_FUNCTION; | 437 | s_tag(func) = LUA_T_FUNCTION; |
444 | lua_table[func].object.value.tf = $4; | 438 | lua_table[func].object.value.tf = $4; |
439 | $4->lineDefined = $<vInt>3; | ||
440 | $4->name1 = $2->ts.str; | ||
441 | $4->name2 = NULL; | ||
442 | $4->fileName = lua_parsedfile; | ||
445 | } | 443 | } |
446 | ; | 444 | ; |
447 | 445 | ||
@@ -449,6 +447,7 @@ method : FUNCTION NAME ':' NAME | |||
449 | { | 447 | { |
450 | init_function($4); | 448 | init_function($4); |
451 | add_localvar(luaI_findsymbolbyname("self")); | 449 | add_localvar(luaI_findsymbolbyname("self")); |
450 | $<vInt>$ = lua_linenumber; | ||
452 | } | 451 | } |
453 | body | 452 | body |
454 | { | 453 | { |
@@ -462,6 +461,10 @@ method : FUNCTION NAME ':' NAME | |||
462 | code_code($6); | 461 | code_code($6); |
463 | code_byte(STOREINDEXED0); | 462 | code_byte(STOREINDEXED0); |
464 | maincode=pc; *initcode=basepc; maxmain=maxcurr; | 463 | maincode=pc; *initcode=basepc; maxmain=maxcurr; |
464 | $6->lineDefined = $<vInt>5; | ||
465 | $6->name1 = $4->ts.str; | ||
466 | $6->name2 = $2->ts.str; | ||
467 | $6->fileName = lua_parsedfile; | ||
465 | } | 468 | } |
466 | ; | 469 | ; |
467 | 470 | ||
@@ -966,17 +969,6 @@ static void PrintCode (Byte *code, Byte *end) | |||
966 | printf ("%d RETCODE %d\n", p-code, *(++p)); | 969 | printf ("%d RETCODE %d\n", p-code, *(++p)); |
967 | p++; | 970 | p++; |
968 | break; | 971 | break; |
969 | case SETFUNCTION: | ||
970 | { | ||
971 | CodeCode c1; | ||
972 | CodeWord c2; | ||
973 | int n = p-code; | ||
974 | p++; | ||
975 | get_code(c1,p); | ||
976 | get_word(c2,p); | ||
977 | printf ("%d SETFUNCTION %s %d\n", n, (char *)c1.tf, c2.w); | ||
978 | } | ||
979 | break; | ||
980 | case SETLINE: | 972 | case SETLINE: |
981 | { | 973 | { |
982 | CodeWord c; | 974 | CodeWord c; |
@@ -987,7 +979,6 @@ static void PrintCode (Byte *code, Byte *end) | |||
987 | } | 979 | } |
988 | break; | 980 | break; |
989 | 981 | ||
990 | case RESET: printf ("%d RESET\n", (p++)-code); break; | ||
991 | default: printf ("%d Cannot happen: code %d\n", (p++)-code, *(p-1)); break; | 982 | default: printf ("%d Cannot happen: code %d\n", (p++)-code, *(p-1)); break; |
992 | } | 983 | } |
993 | } | 984 | } |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.42 1995/10/09 18:45:59 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.43 1995/10/13 15:16:25 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -248,9 +248,15 @@ static void do_call (StkId base, int nResults) | |||
248 | StkId firstResult; | 248 | StkId firstResult; |
249 | Object *func = stack+base-1; | 249 | Object *func = stack+base-1; |
250 | if (tag(func) == LUA_T_CFUNCTION) | 250 | if (tag(func) == LUA_T_CFUNCTION) |
251 | { | ||
252 | tag(func) = LUA_T_CMARK; | ||
251 | firstResult = callC(fvalue(func), base); | 253 | firstResult = callC(fvalue(func), base); |
254 | } | ||
252 | else if (tag(func) == LUA_T_FUNCTION) | 255 | else if (tag(func) == LUA_T_FUNCTION) |
256 | { | ||
257 | tag(func) = LUA_T_MARK; | ||
253 | firstResult = lua_execute(func->value.tf->code, base); | 258 | firstResult = lua_execute(func->value.tf->code, base); |
259 | } | ||
254 | else | 260 | else |
255 | { /* func is not a function */ | 261 | { /* func is not a function */ |
256 | call_funcFB(base, nResults); | 262 | call_funcFB(base, nResults); |
@@ -313,21 +319,21 @@ static void storesubscript (void) | |||
313 | /* | 319 | /* |
314 | ** Traverse all objects on stack | 320 | ** Traverse all objects on stack |
315 | */ | 321 | */ |
316 | void lua_travstack (void (*fn)(Object *)) | 322 | void lua_travstack (int (*fn)(Object *)) |
317 | { | 323 | { |
318 | Object *o; | 324 | Object *o; |
319 | for (o = top-1; o >= stack; o--) | 325 | for (o = top-1; o >= stack; o--) |
320 | fn (o); | 326 | fn (o); |
321 | } | 327 | } |
322 | 328 | ||
323 | 329 | ||
324 | /* | 330 | /* |
325 | ** Error messages | 331 | ** Error messages and debug functions |
326 | */ | 332 | */ |
327 | 333 | ||
328 | static void lua_message (char *s) | 334 | static void lua_message (char *s) |
329 | { | 335 | { |
330 | luaI_reportbug(s, 1); | 336 | lua_pushstring(s); |
331 | callFB(FB_ERROR); | 337 | callFB(FB_ERROR); |
332 | } | 338 | } |
333 | 339 | ||
@@ -347,6 +353,25 @@ void lua_error (char *s) | |||
347 | } | 353 | } |
348 | 354 | ||
349 | 355 | ||
356 | lua_Object luaD_stackedfunction (int level) | ||
357 | { | ||
358 | Object *p = top; | ||
359 | while (--p >= stack) | ||
360 | if (p->tag == LUA_T_MARK || p->tag == LUA_T_CMARK) | ||
361 | if (level-- == 0) | ||
362 | return Ref(p); | ||
363 | return LUA_NOOBJECT; | ||
364 | } | ||
365 | |||
366 | |||
367 | void luaD_funcInfo (lua_Object func, char **filename, char **funcname, | ||
368 | char **objname, int *linedefined) | ||
369 | { | ||
370 | return luaI_funcInfo(Address(func), filename, funcname, objname, linedefined); | ||
371 | } | ||
372 | |||
373 | |||
374 | |||
350 | /* | 375 | /* |
351 | ** Execute a protected call. Assumes that function is at CBase and | 376 | ** Execute a protected call. Assumes that function is at CBase and |
352 | ** parameters are on top of it. Leave nResults on the stack. | 377 | ** parameters are on top of it. Leave nResults on the stack. |
@@ -386,6 +411,9 @@ static int do_protectedmain (void) | |||
386 | adjustC(1); /* one slot for the pseudo-function */ | 411 | adjustC(1); /* one slot for the pseudo-function */ |
387 | stack[CBase].tag = LUA_T_FUNCTION; | 412 | stack[CBase].tag = LUA_T_FUNCTION; |
388 | stack[CBase].value.tf = &tf; | 413 | stack[CBase].value.tf = &tf; |
414 | tf.lineDefined = 0; | ||
415 | tf.name1 = tf.name2 = NULL; | ||
416 | tf.fileName = lua_parsedfile; | ||
389 | tf.code = NULL; | 417 | tf.code = NULL; |
390 | if (setjmp(myErrorJmp) == 0) | 418 | if (setjmp(myErrorJmp) == 0) |
391 | { | 419 | { |
@@ -454,12 +482,7 @@ int lua_dofile (char *filename) | |||
454 | int lua_dostring (char *string) | 482 | int lua_dostring (char *string) |
455 | { | 483 | { |
456 | int status; | 484 | int status; |
457 | char *message = lua_openstring(string); | 485 | lua_openstring(string); |
458 | if (message) | ||
459 | { | ||
460 | lua_message(message); | ||
461 | return 1; | ||
462 | } | ||
463 | status = do_protectedmain(); | 486 | status = do_protectedmain(); |
464 | lua_closestring(); | 487 | lua_closestring(); |
465 | return status; | 488 | return status; |
@@ -1138,16 +1161,6 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
1138 | case RETCODE: | 1161 | case RETCODE: |
1139 | return base+*pc; | 1162 | return base+*pc; |
1140 | 1163 | ||
1141 | case SETFUNCTION: | ||
1142 | { | ||
1143 | CodeCode file; | ||
1144 | CodeWord func; | ||
1145 | get_code(file,pc); | ||
1146 | get_word(func,pc); | ||
1147 | lua_pushfunction ((char *)file.tf, func.w); | ||
1148 | } | ||
1149 | break; | ||
1150 | |||
1151 | case SETLINE: | 1164 | case SETLINE: |
1152 | { | 1165 | { |
1153 | CodeWord code; | 1166 | CodeWord code; |
@@ -1156,10 +1169,6 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
1156 | } | 1169 | } |
1157 | break; | 1170 | break; |
1158 | 1171 | ||
1159 | case RESET: | ||
1160 | lua_popfunction (); | ||
1161 | break; | ||
1162 | |||
1163 | default: | 1172 | default: |
1164 | lua_error ("internal error - opcode doesn't match"); | 1173 | lua_error ("internal error - opcode doesn't match"); |
1165 | } | 1174 | } |
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | ** TeCGraf - PUC-Rio | 2 | ** TeCGraf - PUC-Rio |
3 | ** $Id: opcode.h,v 3.11 1995/04/11 17:56:30 celes Exp $ | 3 | ** $Id: opcode.h,v 3.12 1995/10/04 17:13:02 roberto Exp roberto $ |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef opcode_h | 6 | #ifndef opcode_h |
@@ -68,9 +68,7 @@ typedef enum | |||
68 | CALLFUNC, | 68 | CALLFUNC, |
69 | RETCODE0, | 69 | RETCODE0, |
70 | RETCODE, | 70 | RETCODE, |
71 | SETFUNCTION, | ||
72 | SETLINE, | 71 | SETLINE, |
73 | RESET | ||
74 | } OpCode; | 72 | } OpCode; |
75 | 73 | ||
76 | #define MULT_RET 255 | 74 | #define MULT_RET 255 |
@@ -149,7 +147,7 @@ void lua_setinput (Input fn); /* from "lex.c" module */ | |||
149 | char *lua_lasttext (void); /* from "lex.c" module */ | 147 | char *lua_lasttext (void); /* from "lex.c" module */ |
150 | int yylex (void); /* from "lex.c" module */ | 148 | int yylex (void); /* from "lex.c" module */ |
151 | void lua_parse (TFunc *tf); /* from "lua.stx" module */ | 149 | void lua_parse (TFunc *tf); /* from "lua.stx" module */ |
152 | void lua_travstack (void (*fn)(Object *)); | 150 | void lua_travstack (int (*fn)(Object *)); |
153 | Object *luaI_Address (lua_Object o); | 151 | Object *luaI_Address (lua_Object o); |
154 | void luaI_pushobject (Object *o); | 152 | void luaI_pushobject (Object *o); |
155 | void luaI_gcFB (Object *o); | 153 | void luaI_gcFB (Object *o); |
@@ -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 | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | ** Module to control static tables | 2 | ** Module to control static tables |
3 | ** TeCGraf - PUC-Rio | 3 | ** TeCGraf - PUC-Rio |
4 | ** $Id: table.h,v 2.10 1994/12/20 21:20:36 roberto Exp roberto $ | 4 | ** $Id: table.h,v 2.11 1995/10/13 15:16:25 roberto Exp roberto $ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef table_h | 7 | #ifndef table_h |
@@ -22,11 +22,10 @@ Word luaI_findsymbolbyname (char *name); | |||
22 | Word luaI_findsymbol (TreeNode *t); | 22 | Word luaI_findsymbol (TreeNode *t); |
23 | Word luaI_findconstant (TreeNode *t); | 23 | Word luaI_findconstant (TreeNode *t); |
24 | Word luaI_findconstantbyname (char *name); | 24 | Word luaI_findconstantbyname (char *name); |
25 | void lua_travsymbol (void (*fn)(Object *)); | 25 | int lua_markobject (Object *o); |
26 | void lua_markobject (Object *o); | ||
27 | void lua_pack (void); | 26 | void lua_pack (void); |
28 | char *lua_addfile (char *fn); | 27 | |
29 | int lua_delfile (void); | 28 | void luaI_funcInfo (Object *func, char **filename, char **funcname, |
30 | char *lua_filename (void); | 29 | char **objname, int *linedefined); |
31 | 30 | ||
32 | #endif | 31 | #endif |