Add LJ_FR2 mode: Two-slot frame info.
This commit is contained in:
97
src/lj_api.c
97
src/lj_api.c
@@ -284,8 +284,8 @@ LUA_API int lua_equal(lua_State *L, int idx1, int idx2)
|
||||
} else {
|
||||
L->top = base+2;
|
||||
lj_vm_call(L, base, 1+1);
|
||||
L->top -= 2;
|
||||
return tvistruecond(L->top+1);
|
||||
L->top -= 2+LJ_FR2;
|
||||
return tvistruecond(L->top+1+LJ_FR2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -307,8 +307,8 @@ LUA_API int lua_lessthan(lua_State *L, int idx1, int idx2)
|
||||
} else {
|
||||
L->top = base+2;
|
||||
lj_vm_call(L, base, 1+1);
|
||||
L->top -= 2;
|
||||
return tvistruecond(L->top+1);
|
||||
L->top -= 2+LJ_FR2;
|
||||
return tvistruecond(L->top+1+LJ_FR2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -704,8 +704,8 @@ LUA_API void lua_concat(lua_State *L, int n)
|
||||
n -= (int)(L->top - top);
|
||||
L->top = top+2;
|
||||
lj_vm_call(L, top, 1+1);
|
||||
L->top--;
|
||||
copyTV(L, L->top-1, L->top);
|
||||
L->top -= 1+LJ_FR2;
|
||||
copyTV(L, L->top-1, L->top+LJ_FR2);
|
||||
} while (--n > 0);
|
||||
} else if (n == 0) { /* Push empty string. */
|
||||
setstrV(L, L->top, &G(L)->strempty);
|
||||
@@ -724,8 +724,8 @@ LUA_API void lua_gettable(lua_State *L, int idx)
|
||||
if (v == NULL) {
|
||||
L->top += 2;
|
||||
lj_vm_call(L, L->top-2, 1+1);
|
||||
L->top -= 2;
|
||||
v = L->top+1;
|
||||
L->top -= 2+LJ_FR2;
|
||||
v = L->top+1+LJ_FR2;
|
||||
}
|
||||
copyTV(L, L->top-1, v);
|
||||
}
|
||||
@@ -740,8 +740,8 @@ LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
|
||||
if (v == NULL) {
|
||||
L->top += 2;
|
||||
lj_vm_call(L, L->top-2, 1+1);
|
||||
L->top -= 2;
|
||||
v = L->top+1;
|
||||
L->top -= 2+LJ_FR2;
|
||||
v = L->top+1+LJ_FR2;
|
||||
}
|
||||
copyTV(L, L->top, v);
|
||||
incr_top(L);
|
||||
@@ -882,13 +882,14 @@ LUA_API void lua_settable(lua_State *L, int idx)
|
||||
o = lj_meta_tset(L, t, L->top-2);
|
||||
if (o) {
|
||||
/* NOBARRIER: lj_meta_tset ensures the table is not black. */
|
||||
copyTV(L, o, L->top-1);
|
||||
L->top -= 2;
|
||||
copyTV(L, o, L->top+1);
|
||||
} else {
|
||||
L->top += 3;
|
||||
copyTV(L, L->top-1, L->top-6);
|
||||
lj_vm_call(L, L->top-3, 0+1);
|
||||
L->top -= 3;
|
||||
TValue *base = L->top;
|
||||
copyTV(L, base+2, base-3-LJ_FR2);
|
||||
L->top = base+3;
|
||||
lj_vm_call(L, base, 0+1);
|
||||
L->top -= 3+LJ_FR2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -902,14 +903,14 @@ LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
|
||||
setstrV(L, &key, lj_str_newz(L, k));
|
||||
o = lj_meta_tset(L, t, &key);
|
||||
if (o) {
|
||||
L->top--;
|
||||
/* NOBARRIER: lj_meta_tset ensures the table is not black. */
|
||||
copyTV(L, o, L->top);
|
||||
copyTV(L, o, --L->top);
|
||||
} else {
|
||||
L->top += 3;
|
||||
copyTV(L, L->top-1, L->top-6);
|
||||
lj_vm_call(L, L->top-3, 0+1);
|
||||
L->top -= 2;
|
||||
TValue *base = L->top;
|
||||
copyTV(L, base+2, base-3-LJ_FR2);
|
||||
L->top = base+3;
|
||||
lj_vm_call(L, base, 0+1);
|
||||
L->top -= 2+LJ_FR2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1016,11 +1017,24 @@ LUA_API const char *lua_setupvalue(lua_State *L, int idx, int n)
|
||||
|
||||
/* -- Calls --------------------------------------------------------------- */
|
||||
|
||||
#if LJ_FR2
|
||||
static TValue *api_call_base(lua_State *L, int nargs)
|
||||
{
|
||||
TValue *o = L->top, *base = o - nargs;
|
||||
L->top = o+1;
|
||||
for (; o > base; o--) copyTV(L, o, o-1);
|
||||
setnilV(o);
|
||||
return o+1;
|
||||
}
|
||||
#else
|
||||
#define api_call_base(L, nargs) (L->top - (nargs))
|
||||
#endif
|
||||
|
||||
LUA_API void lua_call(lua_State *L, int nargs, int nresults)
|
||||
{
|
||||
api_check(L, L->status == 0 || L->status == LUA_ERRERR);
|
||||
api_checknelems(L, nargs+1);
|
||||
lj_vm_call(L, L->top - nargs, nresults+1);
|
||||
lj_vm_call(L, api_call_base(L, nargs), nresults+1);
|
||||
}
|
||||
|
||||
LUA_API int lua_pcall(lua_State *L, int nargs, int nresults, int errfunc)
|
||||
@@ -1038,7 +1052,7 @@ LUA_API int lua_pcall(lua_State *L, int nargs, int nresults, int errfunc)
|
||||
api_checkvalidindex(L, o);
|
||||
ef = savestack(L, o);
|
||||
}
|
||||
status = lj_vm_pcall(L, L->top - nargs, nresults+1, ef);
|
||||
status = lj_vm_pcall(L, api_call_base(L, nargs), nresults+1, ef);
|
||||
if (status) hook_restore(g, oldh);
|
||||
return status;
|
||||
}
|
||||
@@ -1046,12 +1060,14 @@ LUA_API int lua_pcall(lua_State *L, int nargs, int nresults, int errfunc)
|
||||
static TValue *cpcall(lua_State *L, lua_CFunction func, void *ud)
|
||||
{
|
||||
GCfunc *fn = lj_func_newC(L, 0, getcurrenv(L));
|
||||
TValue *top = L->top;
|
||||
fn->c.f = func;
|
||||
setfuncV(L, L->top, fn);
|
||||
setlightudV(L->top+1, checklightudptr(L, ud));
|
||||
setfuncV(L, top++, fn);
|
||||
if (LJ_FR2) setnilV(top++);
|
||||
setlightudV(top++, checklightudptr(L, ud));
|
||||
cframe_nres(L->cframe) = 1+0; /* Zero results. */
|
||||
L->top += 2;
|
||||
return L->top-1; /* Now call the newly allocated C function. */
|
||||
L->top = top;
|
||||
return top-1; /* Now call the newly allocated C function. */
|
||||
}
|
||||
|
||||
LUA_API int lua_cpcall(lua_State *L, lua_CFunction func, void *ud)
|
||||
@@ -1068,10 +1084,11 @@ LUA_API int lua_cpcall(lua_State *L, lua_CFunction func, void *ud)
|
||||
LUALIB_API int luaL_callmeta(lua_State *L, int idx, const char *field)
|
||||
{
|
||||
if (luaL_getmetafield(L, idx, field)) {
|
||||
TValue *base = L->top--;
|
||||
copyTV(L, base, index2adr(L, idx));
|
||||
L->top = base+1;
|
||||
lj_vm_call(L, base, 1+1);
|
||||
TValue *top = L->top--;
|
||||
if (LJ_FR2) setnilV(top++);
|
||||
copyTV(L, top++, index2adr(L, idx));
|
||||
L->top = top;
|
||||
lj_vm_call(L, top-1, 1+1);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -1098,12 +1115,14 @@ LUA_API int lua_yield(lua_State *L, int nresults)
|
||||
} else { /* Yield from hook: add a pseudo-frame. */
|
||||
TValue *top = L->top;
|
||||
hook_leave(g);
|
||||
top->u64 = cframe_multres(cf);
|
||||
setcont(top+1, lj_cont_hook);
|
||||
setframe_pc(top+1, cframe_pc(cf)-1);
|
||||
setframe_gc(top+2, obj2gco(L), LJ_TTHREAD);
|
||||
setframe_ftsz(top+2, ((char *)(top+3)-(char *)L->base)+FRAME_CONT);
|
||||
L->top = L->base = top+3;
|
||||
(top++)->u64 = cframe_multres(cf);
|
||||
setcont(top, lj_cont_hook);
|
||||
if (LJ_FR2) top++;
|
||||
setframe_pc(top, cframe_pc(cf)-1);
|
||||
if (LJ_FR2) top++;
|
||||
setframe_gc(top, obj2gco(L), LJ_TTHREAD);
|
||||
setframe_ftsz(top, ((char *)(top+1)-(char *)L->base)+FRAME_CONT);
|
||||
L->top = L->base = top+1;
|
||||
#if LJ_TARGET_X64
|
||||
lj_err_throw(L, LUA_YIELD);
|
||||
#else
|
||||
@@ -1120,7 +1139,9 @@ LUA_API int lua_yield(lua_State *L, int nresults)
|
||||
LUA_API int lua_resume(lua_State *L, int nargs)
|
||||
{
|
||||
if (L->cframe == NULL && L->status <= LUA_YIELD)
|
||||
return lj_vm_resume(L, L->top - nargs, 0, 0);
|
||||
return lj_vm_resume(L,
|
||||
L->status == 0 ? api_call_base(L, nargs) : L->top - nargs,
|
||||
0, 0);
|
||||
L->top = L->base;
|
||||
setstrV(L, L->top, lj_err_str(L, LJ_ERR_COSUSP));
|
||||
incr_top(L);
|
||||
|
||||
Reference in New Issue
Block a user