diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-06 09:45:25 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-06 09:45:25 -0300 |
commit | ad3816d0d15b9e681a39dfe90b78ecd8e68aaec7 (patch) | |
tree | b79618aaceaa71a89f2dfe4a571d34ed55d78c83 /lvm.c | |
parent | 046a3d6173792b7d4d4d26a4e063e2fe383c10a7 (diff) | |
download | lua-ad3816d0d15b9e681a39dfe90b78ecd8e68aaec7.tar.gz lua-ad3816d0d15b9e681a39dfe90b78ecd8e68aaec7.tar.bz2 lua-ad3816d0d15b9e681a39dfe90b78ecd8e68aaec7.zip |
luaD_call is more uniform
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 27 |
1 files changed, 9 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.143 2000/10/05 12:14:08 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.144 2000/10/05 13:00:17 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 | */ |
@@ -67,7 +67,7 @@ int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */ | |||
67 | static void traceexec (lua_State *L, StkId base, StkId top, lua_Hook linehook) { | 67 | static void traceexec (lua_State *L, StkId base, StkId top, lua_Hook linehook) { |
68 | CallInfo *ci = infovalue(base-1); | 68 | CallInfo *ci = infovalue(base-1); |
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 - ci->func->f.l->code) - 1; |
71 | int newline; | 71 | int newline; |
72 | if (pc == 0) { /* may be first time? */ | 72 | if (pc == 0) { /* may be first time? */ |
73 | ci->line = 1; | 73 | ci->line = 1; |
@@ -349,22 +349,18 @@ static void adjust_varargs (lua_State *L, StkId base, int nfixargs) { | |||
349 | ** Returns n such that the the results are between [n,top). | 349 | ** Returns n such that the the results are between [n,top). |
350 | */ | 350 | */ |
351 | StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | 351 | StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { |
352 | const Proto *tf = cl->f.l; | 352 | const Proto *const tf = cl->f.l; |
353 | StkId top; /* keep top local, for performance */ | 353 | StkId top; /* keep top local, for performance */ |
354 | const Instruction *pc = tf->code; | 354 | const Instruction *pc = tf->code; |
355 | TString **kstr = tf->kstr; | 355 | TString **const kstr = tf->kstr; |
356 | lua_Hook callhook = L->callhook; | 356 | const lua_Hook linehook = L->linehook; |
357 | lua_Hook linehook; /* set it only after calling eventual call hook */ | ||
358 | infovalue(base-1)->pc = &pc; | 357 | infovalue(base-1)->pc = &pc; |
359 | luaD_checkstack(L, tf->maxstacksize+EXTRA_STACK); | 358 | luaD_checkstack(L, tf->maxstacksize+EXTRA_STACK); |
360 | if (tf->is_vararg) /* varargs? */ | 359 | if (tf->is_vararg) /* varargs? */ |
361 | adjust_varargs(L, base, tf->numparams); | 360 | adjust_varargs(L, base, tf->numparams); |
362 | else | 361 | else |
363 | luaD_adjusttop(L, base, tf->numparams); | 362 | luaD_adjusttop(L, base, tf->numparams); |
364 | if (callhook) | ||
365 | luaD_callHook(L, base-1, callhook, "call"); | ||
366 | top = L->top; | 363 | top = L->top; |
367 | linehook = L->linehook; | ||
368 | /* main loop of interpreter */ | 364 | /* main loop of interpreter */ |
369 | for (;;) { | 365 | for (;;) { |
370 | const Instruction i = *pc++; | 366 | const Instruction i = *pc++; |
@@ -373,12 +369,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
373 | switch (GET_OPCODE(i)) { | 369 | switch (GET_OPCODE(i)) { |
374 | case OP_END: { | 370 | case OP_END: { |
375 | L->top = top; | 371 | L->top = top; |
376 | goto endloop; | 372 | return top; |
377 | } | 373 | } |
378 | case OP_RETURN: { | 374 | case OP_RETURN: { |
379 | L->top = top; | 375 | L->top = top; |
380 | top = base+GETARG_U(i); | 376 | return base+GETARG_U(i); |
381 | goto endloop; | ||
382 | } | 377 | } |
383 | case OP_CALL: { | 378 | case OP_CALL: { |
384 | int nres = GETARG_B(i); | 379 | int nres = GETARG_B(i); |
@@ -391,8 +386,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
391 | case OP_TAILCALL: { | 386 | case OP_TAILCALL: { |
392 | L->top = top; | 387 | L->top = top; |
393 | luaD_call(L, base+GETARG_A(i), LUA_MULTRET); | 388 | luaD_call(L, base+GETARG_A(i), LUA_MULTRET); |
394 | top = base+GETARG_B(i); | 389 | return base+GETARG_B(i); |
395 | goto endloop; | ||
396 | } | 390 | } |
397 | case OP_PUSHNIL: { | 391 | case OP_PUSHNIL: { |
398 | int n = GETARG_U(i); | 392 | int n = GETARG_U(i); |
@@ -712,8 +706,5 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
712 | break; | 706 | break; |
713 | } | 707 | } |
714 | } | 708 | } |
715 | } endloop: | 709 | } |
716 | if (callhook) /* same hook that was active at entry */ | ||
717 | luaD_callHook(L, base-1, callhook, "return"); | ||
718 | return top; | ||
719 | } | 710 | } |