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 /opcode.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 'opcode.c')
| -rw-r--r-- | opcode.c | 59 |
1 files changed, 34 insertions, 25 deletions
| @@ -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 | } |
