mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
Cleanup of frame handling. No functional changes.
This commit is contained in:
parent
b93b624ad8
commit
881f48f980
@ -97,7 +97,7 @@ lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
||||
lj_ccallback.h
|
||||
lj_debug.o: lj_debug.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
||||
lj_err.h lj_errmsg.h lj_debug.h lj_buf.h lj_gc.h lj_str.h lj_tab.h \
|
||||
lj_state.h lj_frame.h lj_bc.h lj_strfmt.h lj_vm.h lj_jit.h lj_ir.h
|
||||
lj_state.h lj_frame.h lj_bc.h lj_strfmt.h lj_jit.h lj_ir.h
|
||||
lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
||||
lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_func.h lj_tab.h \
|
||||
lj_meta.h lj_debug.h lj_state.h lj_frame.h lj_bc.h lj_ff.h lj_ffdef.h \
|
||||
|
@ -1102,7 +1102,7 @@ LUA_API int lua_yield(lua_State *L, int nresults)
|
||||
setcont(top+1, lj_cont_hook);
|
||||
setframe_pc(top+1, cframe_pc(cf)-1);
|
||||
setframe_gc(top+2, obj2gco(L));
|
||||
setframe_ftsz(top+2, (int)((char *)(top+3)-(char *)L->base)+FRAME_CONT);
|
||||
setframe_ftsz(top+2, ((char *)(top+3)-(char *)L->base)+FRAME_CONT);
|
||||
L->top = L->base = top+3;
|
||||
#if LJ_TARGET_X64
|
||||
lj_err_throw(L, LUA_YIELD);
|
||||
|
@ -432,7 +432,7 @@ static void callback_conv_args(CTState *cts, lua_State *L)
|
||||
o->u32.hi = rid; /* Return type. x86: +(spadj<<16). */
|
||||
o++;
|
||||
setframe_gc(o, obj2gco(fn));
|
||||
setframe_ftsz(o, (int)((char *)(o+1) - (char *)L->base) + FRAME_CONT);
|
||||
setframe_ftsz(o, ((char *)(o+1) - (char *)L->base) + FRAME_CONT);
|
||||
L->top = L->base = ++o;
|
||||
if (!ct)
|
||||
lj_err_caller(cts->L, LJ_ERR_FFI_BADCBACK);
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "lj_frame.h"
|
||||
#include "lj_bc.h"
|
||||
#include "lj_strfmt.h"
|
||||
#include "lj_vm.h"
|
||||
#if LJ_HASJIT
|
||||
#include "lj_jit.h"
|
||||
#endif
|
||||
@ -88,8 +87,7 @@ static BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe)
|
||||
if (frame_islua(f)) {
|
||||
f = frame_prevl(f);
|
||||
} else {
|
||||
if (frame_isc(f) || (LJ_HASFFI && frame_iscont(f) &&
|
||||
(f-1)->u32.lo == LJ_CONT_FFI_CALLBACK))
|
||||
if (frame_isc(f) || (frame_iscont(f) && frame_iscont_fficb(f)))
|
||||
cf = cframe_raw(cframe_prev(cf));
|
||||
f = frame_prevd(f);
|
||||
}
|
||||
|
17
src/lj_err.c
17
src/lj_err.c
@ -114,9 +114,7 @@ static void *err_unwind(lua_State *L, void *stopcf, int errcode)
|
||||
frame = frame_prevl(frame);
|
||||
break;
|
||||
case FRAME_C: /* C frame. */
|
||||
#if LJ_HASFFI
|
||||
unwind_c:
|
||||
#endif
|
||||
#if LJ_UNWIND_EXT
|
||||
if (errcode) {
|
||||
L->base = frame_prevd(frame) + 1;
|
||||
@ -150,10 +148,8 @@ static void *err_unwind(lua_State *L, void *stopcf, int errcode)
|
||||
}
|
||||
return cf;
|
||||
case FRAME_CONT: /* Continuation frame. */
|
||||
#if LJ_HASFFI
|
||||
if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK)
|
||||
if (frame_iscont_fficb(frame))
|
||||
goto unwind_c;
|
||||
#endif
|
||||
case FRAME_VARG: /* Vararg frame. */
|
||||
frame = frame_prevd(frame);
|
||||
break;
|
||||
@ -522,10 +518,8 @@ static ptrdiff_t finderrfunc(lua_State *L)
|
||||
frame = frame_prevd(frame);
|
||||
break;
|
||||
case FRAME_CONT:
|
||||
#if LJ_HASFFI
|
||||
if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK)
|
||||
if (frame_iscont_fficb(frame))
|
||||
cf = cframe_prev(cf);
|
||||
#endif
|
||||
frame = frame_prevd(frame);
|
||||
break;
|
||||
case FRAME_CP:
|
||||
@ -652,13 +646,10 @@ LJ_NOINLINE void lj_err_callermsg(lua_State *L, const char *msg)
|
||||
if (frame_islua(frame)) {
|
||||
pframe = frame_prevl(frame);
|
||||
} else if (frame_iscont(frame)) {
|
||||
#if LJ_HASFFI
|
||||
if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK) {
|
||||
if (frame_iscont_fficb(frame)) {
|
||||
pframe = frame;
|
||||
frame = NULL;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
} else {
|
||||
pframe = frame_prevd(frame);
|
||||
#if LJ_HASFFI
|
||||
/* Remove frame for FFI metamethods. */
|
||||
|
@ -109,7 +109,7 @@ static void recff_stitch(jit_State *J)
|
||||
|
||||
/* Move func + args up in Lua stack and insert continuation. */
|
||||
memmove(&base[1], &base[-1], sizeof(TValue)*(J->maxslot+1));
|
||||
setframe_ftsz(base+1, (int)((char *)(base+1) - (char *)pframe) + FRAME_CONT);
|
||||
setframe_ftsz(base+1, ((char *)(base+1) - (char *)pframe) + FRAME_CONT);
|
||||
setcont(base, cont);
|
||||
setframe_pc(base, pc);
|
||||
if (LJ_DUALNUM) setintV(base-1, traceno); else base[-1].u64 = traceno;
|
||||
|
@ -22,8 +22,11 @@ enum {
|
||||
|
||||
/* Macros to access and modify Lua frames. */
|
||||
#define frame_gc(f) (gcref((f)->fr.func))
|
||||
#define frame_func(f) (&frame_gc(f)->fn)
|
||||
#define frame_ftsz(f) ((f)->fr.tp.ftsz)
|
||||
#define frame_ftsz(f) ((ptrdiff_t)(f)->fr.tp.ftsz)
|
||||
#define frame_pc(f) (mref((f)->fr.tp.pcr, const BCIns))
|
||||
#define setframe_gc(f, p) (setgcref((f)->fr.func, (p)))
|
||||
#define setframe_ftsz(f, sz) ((f)->fr.tp.ftsz = (int32_t)(sz))
|
||||
#define setframe_pc(f, pc) (setmref((f)->fr.tp.pcr, (pc)))
|
||||
|
||||
#define frame_type(f) (frame_ftsz(f) & FRAME_TYPE)
|
||||
#define frame_typep(f) (frame_ftsz(f) & FRAME_TYPEP)
|
||||
@ -33,8 +36,14 @@ enum {
|
||||
#define frame_isvarg(f) (frame_typep(f) == FRAME_VARG)
|
||||
#define frame_ispcall(f) ((frame_ftsz(f) & 6) == FRAME_PCALL)
|
||||
|
||||
#define frame_pc(f) (mref((f)->fr.tp.pcr, const BCIns))
|
||||
#define frame_func(f) (&frame_gc(f)->fn)
|
||||
#define frame_delta(f) (frame_ftsz(f) >> 3)
|
||||
#define frame_sized(f) (frame_ftsz(f) & ~FRAME_TYPEP)
|
||||
|
||||
enum { LJ_CONT_TAILCALL, LJ_CONT_FFI_CALLBACK }; /* Special continuations. */
|
||||
|
||||
#define frame_contpc(f) (frame_pc((f)-1))
|
||||
#define frame_contv(f) (((f)-1)->u32.lo)
|
||||
#if LJ_64
|
||||
#define frame_contf(f) \
|
||||
((ASMFunction)(void *)((intptr_t)lj_vm_asm_begin + \
|
||||
@ -42,18 +51,14 @@ enum {
|
||||
#else
|
||||
#define frame_contf(f) ((ASMFunction)gcrefp(((f)-1)->gcr, void))
|
||||
#endif
|
||||
#define frame_delta(f) (frame_ftsz(f) >> 3)
|
||||
#define frame_sized(f) (frame_ftsz(f) & ~FRAME_TYPEP)
|
||||
#define frame_iscont_fficb(f) \
|
||||
(LJ_HASFFI && frame_contv(f) == LJ_CONT_FFI_CALLBACK)
|
||||
|
||||
#define frame_prevl(f) ((f) - (1+bc_a(frame_pc(f)[-1])))
|
||||
#define frame_prevd(f) ((TValue *)((char *)(f) - frame_sized(f)))
|
||||
#define frame_prev(f) (frame_islua(f)?frame_prevl(f):frame_prevd(f))
|
||||
/* Note: this macro does not skip over FRAME_VARG. */
|
||||
|
||||
#define setframe_pc(f, pc) (setmref((f)->fr.tp.pcr, (pc)))
|
||||
#define setframe_ftsz(f, sz) ((f)->fr.tp.ftsz = (sz))
|
||||
#define setframe_gc(f, p) (setgcref((f)->fr.func, (p)))
|
||||
|
||||
/* -- C stack frame ------------------------------------------------------- */
|
||||
|
||||
/* Macros to access and modify the C stack frame chain. */
|
||||
|
@ -84,7 +84,7 @@ int lj_meta_tailcall(lua_State *L, cTValue *tv)
|
||||
top->u32.lo = LJ_CONT_TAILCALL;
|
||||
setframe_pc(top, pc);
|
||||
setframe_gc(top+1, obj2gco(L)); /* Dummy frame object. */
|
||||
setframe_ftsz(top+1, (int)((char *)(top+2) - (char *)base) + FRAME_CONT);
|
||||
setframe_ftsz(top+1, ((char *)(top+2) - (char *)base) + FRAME_CONT);
|
||||
L->base = L->top = top+2;
|
||||
/*
|
||||
** before: [old_mo|PC] [... ...]
|
||||
|
@ -1627,7 +1627,8 @@ static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults)
|
||||
if (nvararg >= nresults)
|
||||
emitir(IRTGI(IR_GE), fr, lj_ir_kint(J, frofs+8*(int32_t)nresults));
|
||||
else
|
||||
emitir(IRTGI(IR_EQ), fr, lj_ir_kint(J, frame_ftsz(J->L->base-1)));
|
||||
emitir(IRTGI(IR_EQ), fr,
|
||||
lj_ir_kint(J, (int32_t)frame_ftsz(J->L->base-1)));
|
||||
vbase = emitir(IRTI(IR_SUB), REF_BASE, fr);
|
||||
vbase = emitir(IRT(IR_ADD, IRT_P32), vbase, lj_ir_kint(J, frofs-8));
|
||||
for (i = 0; i < nload; i++) {
|
||||
|
@ -796,7 +796,7 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr)
|
||||
MSize n, nent = snap->nent;
|
||||
SnapEntry *map = &T->snapmap[snap->mapofs];
|
||||
SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1];
|
||||
int32_t ftsz0;
|
||||
ptrdiff_t ftsz0;
|
||||
TValue *frame;
|
||||
BloomFilter rfilt = snap_renamefilter(T, snapno);
|
||||
const BCIns *pc = snap_pc(map[nent]);
|
||||
@ -838,7 +838,7 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr)
|
||||
o->u32.hi = tmp.u32.lo;
|
||||
} else if ((sn & (SNAP_CONT|SNAP_FRAME))) {
|
||||
/* Overwrite tag with frame link. */
|
||||
o->fr.tp.ftsz = snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0;
|
||||
setframe_ftsz(o, snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0);
|
||||
L->base = o+1;
|
||||
}
|
||||
}
|
||||
|
@ -105,8 +105,6 @@ LJ_ASMF void lj_cont_condf(void); /* Branch if result is false. */
|
||||
LJ_ASMF void lj_cont_hook(void); /* Continue from hook yield. */
|
||||
LJ_ASMF void lj_cont_stitch(void); /* Trace stitching. */
|
||||
|
||||
enum { LJ_CONT_TAILCALL, LJ_CONT_FFI_CALLBACK }; /* Special continuations. */
|
||||
|
||||
/* Start of the ASM code. */
|
||||
LJ_ASMF char lj_vm_asm_begin[];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user