diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-25 14:47:14 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-25 14:47:14 -0300 |
commit | 801aaf37b14a1fad5bb49c9a4200d25680152471 (patch) | |
tree | e3cc5cdebac6d503091f4ba16444f8ecfa8dfdb2 /lvm.c | |
parent | 00af2faae71e6388ee61ef18b2c5902a42e9bc27 (diff) | |
download | lua-801aaf37b14a1fad5bb49c9a4200d25680152471.tar.gz lua-801aaf37b14a1fad5bb49c9a4200d25680152471.tar.bz2 lua-801aaf37b14a1fad5bb49c9a4200d25680152471.zip |
simpler implementation for line information
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 68 |
1 files changed, 21 insertions, 47 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.221 2002/03/20 12:52:32 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.222 2002/03/22 16:54:31 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -62,33 +62,17 @@ int luaV_tostring (lua_State *L, TObject *obj) { | |||
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
65 | static void traceexec (lua_State *L, lua_Hook linehook) { | 65 | static void traceexec (lua_State *L) { |
66 | CallInfo *ci = L->ci; | 66 | CallInfo *ci = L->ci; |
67 | int *lineinfo = ci_func(ci)->l.p->lineinfo; | 67 | int *lineinfo = ci_func(ci)->l.p->lineinfo; |
68 | int pc = cast(int, *ci->pc - ci_func(ci)->l.p->code) - 1; | 68 | int pc = cast(int, *ci->pc - ci_func(ci)->l.p->code) - 1; |
69 | int newline; | 69 | int newline = lineinfo[pc]; |
70 | if (testOpMode(GET_OPCODE(*(*ci->pc - 1)), OpModeNoTrace)) | 70 | if (pc == 0) /* tracing may be starting now? */ |
71 | return; | 71 | ci->lastpc = 0; /* initialize `lastpc' */ |
72 | if (ci->line == -1) return; /* no linehooks for this function */ | ||
73 | else if (ci->line == 0) { /* first linehook? */ | ||
74 | if (pc == 0) { /* function is starting now? */ | ||
75 | ci->line = 1; | ||
76 | ci->refi = 0; | ||
77 | ci->lastpc = pc+1; /* make sure it will call linehook */ | ||
78 | } | ||
79 | else { /* function started without hooks: */ | ||
80 | ci->line = -1; /* keep it that way */ | ||
81 | return; | ||
82 | } | ||
83 | } | ||
84 | newline = luaG_getline(lineinfo, pc, ci->line, &ci->refi); | ||
85 | /* calls linehook when enters a new line or jumps back (loop) */ | 72 | /* calls linehook when enters a new line or jumps back (loop) */ |
86 | if (newline != ci->line || pc <= ci->lastpc) { | 73 | if (pc <= ci->lastpc || newline != lineinfo[ci->lastpc]) |
87 | ci->line = newline; | 74 | luaD_lineHook(L, newline); |
88 | luaD_lineHook(L, newline, linehook); | 75 | L->ci->lastpc = pc; |
89 | ci = L->ci; /* previous call may realocate `ci' */ | ||
90 | } | ||
91 | ci->lastpc = pc; | ||
92 | } | 76 | } |
93 | 77 | ||
94 | 78 | ||
@@ -316,21 +300,17 @@ static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) { | |||
316 | 300 | ||
317 | #define dojump(pc, i) ((pc) += (i)) | 301 | #define dojump(pc, i) ((pc) += (i)) |
318 | 302 | ||
319 | /* | 303 | |
320 | ** Executes current Lua function. Parameters are between [base,top). | ||
321 | ** Returns n such that the results are between [n,top). | ||
322 | */ | ||
323 | StkId luaV_execute (lua_State *L) { | 304 | StkId luaV_execute (lua_State *L) { |
324 | StkId base; | 305 | StkId base; |
325 | LClosure *cl; | 306 | LClosure *cl; |
326 | TObject *k; | 307 | TObject *k; |
327 | const Instruction *pc; | 308 | const Instruction *pc; |
328 | lua_Hook linehook; | 309 | callentry: /* entry point when calling new functions */ |
329 | reinit: | ||
330 | linehook = L->linehook; | ||
331 | L->ci->pc = &pc; | 310 | L->ci->pc = &pc; |
332 | pc = L->ci->savedpc; | ||
333 | L->ci->pb = &base; | 311 | L->ci->pb = &base; |
312 | pc = L->ci->savedpc; | ||
313 | retentry: /* entry point when returning to old functions */ | ||
334 | base = L->ci->base; | 314 | base = L->ci->base; |
335 | cl = &clvalue(base - 1)->l; | 315 | cl = &clvalue(base - 1)->l; |
336 | k = cl->p->k; | 316 | k = cl->p->k; |
@@ -338,13 +318,13 @@ StkId luaV_execute (lua_State *L) { | |||
338 | for (;;) { | 318 | for (;;) { |
339 | const Instruction i = *pc++; | 319 | const Instruction i = *pc++; |
340 | StkId ra; | 320 | StkId ra; |
341 | if (linehook) | 321 | if (L->linehook) |
342 | traceexec(L, linehook); | 322 | traceexec(L); |
343 | ra = RA(i); | 323 | ra = RA(i); |
344 | lua_assert(L->top <= L->stack + L->stacksize && L->top >= L->ci->base); | 324 | lua_assert(L->top <= L->stack + L->stacksize && L->top >= L->ci->base); |
345 | lua_assert(L->top == L->ci->top || GET_OPCODE(i) == OP_CALL || | 325 | lua_assert(L->top == L->ci->top || |
346 | GET_OPCODE(i) == OP_TAILCALL || GET_OPCODE(i) == OP_RETURN || | 326 | GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || |
347 | GET_OPCODE(i) == OP_SETLISTO); | 327 | GET_OPCODE(i) == OP_RETURN || GET_OPCODE(i) == OP_SETLISTO); |
348 | switch (GET_OPCODE(i)) { | 328 | switch (GET_OPCODE(i)) { |
349 | case OP_MOVE: { | 329 | case OP_MOVE: { |
350 | setobj(ra, RB(i)); | 330 | setobj(ra, RB(i)); |
@@ -453,7 +433,6 @@ StkId luaV_execute (lua_State *L) { | |||
453 | break; | 433 | break; |
454 | } | 434 | } |
455 | case OP_JMP: { | 435 | case OP_JMP: { |
456 | linehook = L->linehook; | ||
457 | dojump(pc, GETARG_sBc(i)); | 436 | dojump(pc, GETARG_sBc(i)); |
458 | break; | 437 | break; |
459 | } | 438 | } |
@@ -511,7 +490,7 @@ StkId luaV_execute (lua_State *L) { | |||
511 | } | 490 | } |
512 | else { /* it is a Lua function: `call' it */ | 491 | else { /* it is a Lua function: `call' it */ |
513 | (L->ci-1)->savedpc = pc; | 492 | (L->ci-1)->savedpc = pc; |
514 | goto reinit; | 493 | goto callentry; |
515 | } | 494 | } |
516 | break; | 495 | break; |
517 | } | 496 | } |
@@ -521,7 +500,7 @@ StkId luaV_execute (lua_State *L) { | |||
521 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ | 500 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ |
522 | luaD_poscall(L, LUA_MULTRET, ra); /* move down function and args. */ | 501 | luaD_poscall(L, LUA_MULTRET, ra); /* move down function and args. */ |
523 | ra = luaD_precall(L, base-1); | 502 | ra = luaD_precall(L, base-1); |
524 | if (ra == NULL) goto reinit; /* it is a Lua function */ | 503 | if (ra == NULL) goto callentry; /* it is a Lua function */ |
525 | else if (ra > L->top) return NULL; /* yield??? */ | 504 | else if (ra > L->top) return NULL; /* yield??? */ |
526 | else goto ret; | 505 | else goto ret; |
527 | } | 506 | } |
@@ -540,14 +519,12 @@ StkId luaV_execute (lua_State *L) { | |||
540 | else { /* yes: continue its execution */ | 519 | else { /* yes: continue its execution */ |
541 | int nresults; | 520 | int nresults; |
542 | lua_assert(ttype(ci->base-1) == LUA_TFUNCTION); | 521 | lua_assert(ttype(ci->base-1) == LUA_TFUNCTION); |
543 | base = ci->base; /* restore previous values */ | ||
544 | cl = &clvalue(base - 1)->l; | ||
545 | k = cl->p->k; | ||
546 | pc = ci->savedpc; | 522 | pc = ci->savedpc; |
547 | lua_assert(GET_OPCODE(*(pc-1)) == OP_CALL); | 523 | lua_assert(GET_OPCODE(*(pc-1)) == OP_CALL); |
548 | nresults = GETARG_C(*(pc-1)) - 1; | 524 | nresults = GETARG_C(*(pc-1)) - 1; |
549 | luaD_poscall(L, nresults, ra); | 525 | luaD_poscall(L, nresults, ra); |
550 | if (nresults >= 0) L->top = L->ci->top; | 526 | if (nresults >= 0) L->top = L->ci->top; |
527 | goto retentry; | ||
551 | } | 528 | } |
552 | break; | 529 | break; |
553 | } | 530 | } |
@@ -556,7 +533,6 @@ StkId luaV_execute (lua_State *L) { | |||
556 | int j = GETARG_sBc(i); | 533 | int j = GETARG_sBc(i); |
557 | const TObject *plimit = ra+1; | 534 | const TObject *plimit = ra+1; |
558 | const TObject *pstep = ra+2; | 535 | const TObject *pstep = ra+2; |
559 | dojump(pc, j); /* jump back before tests (for error messages) */ | ||
560 | if (ttype(ra) != LUA_TNUMBER) | 536 | if (ttype(ra) != LUA_TNUMBER) |
561 | luaD_error(L, "`for' initial value must be a number"); | 537 | luaD_error(L, "`for' initial value must be a number"); |
562 | if (!tonumber(plimit, ra+1)) | 538 | if (!tonumber(plimit, ra+1)) |
@@ -567,11 +543,9 @@ StkId luaV_execute (lua_State *L) { | |||
567 | index = nvalue(ra) + step; /* increment index */ | 543 | index = nvalue(ra) + step; /* increment index */ |
568 | limit = nvalue(plimit); | 544 | limit = nvalue(plimit); |
569 | if (step > 0 ? index <= limit : index >= limit) { | 545 | if (step > 0 ? index <= limit : index >= limit) { |
546 | dojump(pc, j); /* jump back */ | ||
570 | chgnvalue(ra, index); /* update index */ | 547 | chgnvalue(ra, index); /* update index */ |
571 | linehook = L->linehook; | ||
572 | } | 548 | } |
573 | else | ||
574 | dojump(pc, -j); /* undo jump */ | ||
575 | break; | 549 | break; |
576 | } | 550 | } |
577 | case OP_TFORLOOP: { | 551 | case OP_TFORLOOP: { |