From bbe7d818d9d9d47c48f255104166a58e7f65d3ec Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 18 Feb 2010 19:37:30 +0100 Subject: [PATCH] Allow linking to already compiled functions. --- src/lj_record.c | 31 ++++++++++++++++++++++++------- src/lj_traceerr.h | 1 - 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/lj_record.c b/src/lj_record.c index 3f7c2bde..42f9a8ae 100644 --- a/src/lj_record.c +++ b/src/lj_record.c @@ -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; + BCReg s, numparams = pt->numparams; if ((pt->flags & PROTO_NO_JIT)) lj_trace_err(J, LJ_TRERR_CJITOFF); lua_assert(!(pt->flags & PROTO_IS_VARARG)); if (J->baseslot + pt->framesize >= LJ_MAX_JSLOTS) lj_trace_err(J, LJ_TRERR_STACKOV); - /* Fill up missing args with nil. */ - while (J->maxslot < pt->numparams) - J->base[J->maxslot++] = TREF_NIL; + /* Fill up missing parameters with nil. */ + for (s = J->maxslot; s < numparams; s++) + J->base[s] = TREF_NIL; /* 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); } +/* 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 -------------------------------------------------- */ static TRef rec_tnew(jit_State *J, uint32_t ah) @@ -2127,9 +2145,8 @@ void lj_record_ins(jit_State *J) case BC_FUNCF: rec_func_lua(J); break; - case BC_JFUNCF: - lj_trace_err(J, LJ_TRERR_NYILNKF); + rec_func_jit(J, rc); break; case BC_FUNCV: diff --git a/src/lj_traceerr.h b/src/lj_traceerr.h index 6e02a053..89ab04d1 100644 --- a/src/lj_traceerr.h +++ b/src/lj_traceerr.h @@ -23,7 +23,6 @@ TREDEF(BADTYPE, "bad argument type") TREDEF(CJITOFF, "call to JIT-disabled function") TREDEF(CUNROLL, "call unroll limit reached") TREDEF(NYIRECU, "NYI: recursive calls") -TREDEF(NYILNKF, "NYI: linking/patching function calls") TREDEF(NYIVF, "NYI: vararg function") TREDEF(NYICF, "NYI: C function %p") TREDEF(NYIFF, "NYI: FastFunc %s")