Allow linking to already compiled functions.

This commit is contained in:
Mike Pall 2010-02-18 19:37:30 +01:00
parent b11eeab906
commit bbe7d818d9
2 changed files with 24 additions and 8 deletions

View File

@ -1734,22 +1734,40 @@ static void check_call_unroll(jit_State *J)
} }
} }
static void rec_func_lua(jit_State *J) /* Record Lua function setup. */
static void rec_func_setup(jit_State *J)
{ {
GCproto *pt = J->pt; GCproto *pt = J->pt;
BCReg s, numparams = pt->numparams;
if ((pt->flags & PROTO_NO_JIT)) if ((pt->flags & PROTO_NO_JIT))
lj_trace_err(J, LJ_TRERR_CJITOFF); lj_trace_err(J, LJ_TRERR_CJITOFF);
lua_assert(!(pt->flags & PROTO_IS_VARARG)); lua_assert(!(pt->flags & PROTO_IS_VARARG));
if (J->baseslot + pt->framesize >= LJ_MAX_JSLOTS) if (J->baseslot + pt->framesize >= LJ_MAX_JSLOTS)
lj_trace_err(J, LJ_TRERR_STACKOV); lj_trace_err(J, LJ_TRERR_STACKOV);
/* Fill up missing args with nil. */ /* Fill up missing parameters with nil. */
while (J->maxslot < pt->numparams) for (s = J->maxslot; s < numparams; s++)
J->base[J->maxslot++] = TREF_NIL; J->base[s] = TREF_NIL;
/* The remaining slots should never be read before they are written. */ /* The remaining slots should never be read before they are written. */
J->maxslot = pt->numparams; J->maxslot = numparams;
}
/* Record entry to a Lua function. */
static void rec_func_lua(jit_State *J)
{
rec_func_setup(J);
check_call_unroll(J); check_call_unroll(J);
} }
/* Record entry to an already compiled function. */
static void rec_func_jit(jit_State *J, TraceNo lnk)
{
rec_func_setup(J);
J->instunroll = 0; /* Cannot continue across a compiled function. */
if (J->pc == J->startpc && J->framedepth + J->retdepth == 0)
lnk = J->curtrace; /* Can form an extra tail-recursive loop. */
rec_stop(J, lnk); /* Link to the function. */
}
/* -- Record allocations -------------------------------------------------- */ /* -- Record allocations -------------------------------------------------- */
static TRef rec_tnew(jit_State *J, uint32_t ah) static TRef rec_tnew(jit_State *J, uint32_t ah)
@ -2127,9 +2145,8 @@ void lj_record_ins(jit_State *J)
case BC_FUNCF: case BC_FUNCF:
rec_func_lua(J); rec_func_lua(J);
break; break;
case BC_JFUNCF: case BC_JFUNCF:
lj_trace_err(J, LJ_TRERR_NYILNKF); rec_func_jit(J, rc);
break; break;
case BC_FUNCV: case BC_FUNCV:

View File

@ -23,7 +23,6 @@ TREDEF(BADTYPE, "bad argument type")
TREDEF(CJITOFF, "call to JIT-disabled function") TREDEF(CJITOFF, "call to JIT-disabled function")
TREDEF(CUNROLL, "call unroll limit reached") TREDEF(CUNROLL, "call unroll limit reached")
TREDEF(NYIRECU, "NYI: recursive calls") TREDEF(NYIRECU, "NYI: recursive calls")
TREDEF(NYILNKF, "NYI: linking/patching function calls")
TREDEF(NYIVF, "NYI: vararg function") TREDEF(NYIVF, "NYI: vararg function")
TREDEF(NYICF, "NYI: C function %p") TREDEF(NYICF, "NYI: C function %p")
TREDEF(NYIFF, "NYI: FastFunc %s") TREDEF(NYIFF, "NYI: FastFunc %s")