diff options
Diffstat (limited to 'lvm.c')
| -rw-r--r-- | lvm.c | 24 |
1 files changed, 17 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.140 2000/10/03 14:03:21 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.141 2000/10/03 14:27:44 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 | */ |
| @@ -69,7 +69,7 @@ static void traceexec (lua_State *L, StkId base, StkId top, lua_Hook linehook) { | |||
| 69 | int *lineinfo = ci->func->f.l->lineinfo; | 69 | int *lineinfo = ci->func->f.l->lineinfo; |
| 70 | int pc = (*ci->pc - 1) - ci->func->f.l->code; | 70 | int pc = (*ci->pc - 1) - ci->func->f.l->code; |
| 71 | int newline; | 71 | int newline; |
| 72 | if (ci->line == 0) { /* first time? */ | 72 | if (pc == 0) { /* may be first time? */ |
| 73 | ci->line = 1; | 73 | ci->line = 1; |
| 74 | ci->refi = 0; | 74 | ci->refi = 0; |
| 75 | ci->lastpc = pc+1; /* make sure it will call linehook */ | 75 | ci->lastpc = pc+1; /* make sure it will call linehook */ |
| @@ -348,14 +348,18 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 348 | StkId top; /* keep top local, for performance */ | 348 | StkId top; /* keep top local, for performance */ |
| 349 | const Instruction *pc = tf->code; | 349 | const Instruction *pc = tf->code; |
| 350 | TString **kstr = tf->kstr; | 350 | TString **kstr = tf->kstr; |
| 351 | lua_Hook linehook = L->linehook; | 351 | lua_Hook callhook = L->callhook; |
| 352 | lua_Hook linehook; /* set it only after calling eventual call hook */ | ||
| 352 | infovalue(base-1)->pc = &pc; | 353 | infovalue(base-1)->pc = &pc; |
| 353 | luaD_checkstack(L, tf->maxstacksize+EXTRA_STACK); | 354 | luaD_checkstack(L, tf->maxstacksize+EXTRA_STACK); |
| 354 | if (tf->is_vararg) /* varargs? */ | 355 | if (tf->is_vararg) /* varargs? */ |
| 355 | adjust_varargs(L, base, tf->numparams); | 356 | adjust_varargs(L, base, tf->numparams); |
| 356 | else | 357 | else |
| 357 | luaD_adjusttop(L, base, tf->numparams); | 358 | luaD_adjusttop(L, base, tf->numparams); |
| 359 | if (callhook) | ||
| 360 | luaD_callHook(L, base-1, callhook, "call"); | ||
| 358 | top = L->top; | 361 | top = L->top; |
| 362 | linehook = L->linehook; | ||
| 359 | /* main loop of interpreter */ | 363 | /* main loop of interpreter */ |
| 360 | for (;;) { | 364 | for (;;) { |
| 361 | const Instruction i = *pc++; | 365 | const Instruction i = *pc++; |
| @@ -363,11 +367,13 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 363 | traceexec(L, base, top, linehook); | 367 | traceexec(L, base, top, linehook); |
| 364 | switch (GET_OPCODE(i)) { | 368 | switch (GET_OPCODE(i)) { |
| 365 | case OP_END: { | 369 | case OP_END: { |
| 366 | return L->top; /* no results */ | 370 | L->top = top; |
| 371 | goto endloop; | ||
| 367 | } | 372 | } |
| 368 | case OP_RETURN: { | 373 | case OP_RETURN: { |
| 369 | L->top = top; | 374 | L->top = top; |
| 370 | return base+GETARG_U(i); | 375 | top = base+GETARG_U(i); |
| 376 | goto endloop; | ||
| 371 | } | 377 | } |
| 372 | case OP_CALL: { | 378 | case OP_CALL: { |
| 373 | int nres = GETARG_B(i); | 379 | int nres = GETARG_B(i); |
| @@ -380,7 +386,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 380 | case OP_TAILCALL: { | 386 | case OP_TAILCALL: { |
| 381 | L->top = top; | 387 | L->top = top; |
| 382 | luaD_call(L, base+GETARG_A(i), LUA_MULTRET); | 388 | luaD_call(L, base+GETARG_A(i), LUA_MULTRET); |
| 383 | return base+GETARG_B(i); | 389 | top = base+GETARG_B(i); |
| 390 | goto endloop; | ||
| 384 | } | 391 | } |
| 385 | case OP_PUSHNIL: { | 392 | case OP_PUSHNIL: { |
| 386 | int n = GETARG_U(i); | 393 | int n = GETARG_U(i); |
| @@ -700,5 +707,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 700 | break; | 707 | break; |
| 701 | } | 708 | } |
| 702 | } | 709 | } |
| 703 | } | 710 | } endloop: |
| 711 | if (callhook) /* same hook that was active at entry */ | ||
| 712 | luaD_callHook(L, base-1, callhook, "return"); | ||
| 713 | return top; | ||
| 704 | } | 714 | } |
