LUA_API int lua_loadx(lua_State *L, lua_Reader reader, void *data, const char *chunkname, const char *mode) { LexState ls; int status; ls.rfunc = reader; ls.rdata = data; ls.chunkarg = chunkname ? chunkname : "?"; ls.mode = mode; lj_buf_init(L, &ls.sb); status = lj_vm_cpcall(L, NULL, &ls, cpparser); lj_lex_cleanup(L, &ls); lj_gc_check(L); return status; }
/* SPLIT pass. */ void lj_opt_split(jit_State *J) { #if LJ_SOFTFP if (!J->needsplit) J->needsplit = split_needsplit(J); #else lua_assert(J->needsplit >= split_needsplit(J)); /* Verify flag. */ #endif if (J->needsplit) { int errcode = lj_vm_cpcall(J->L, NULL, J, cpsplit); if (errcode) { /* Completely reset the trace to avoid inconsistent dump on abort. */ J->cur.nins = J->cur.nk = REF_BASE; J->cur.nsnap = 0; lj_err_throw(J->L, errcode); /* Propagate errors. */ } } }
static void LJ_FASTCALL recff_xpcall(jit_State *J, RecordFFData *rd) { if (J->maxslot >= 2) { TValue argv0, argv1; TRef tmp; int errcode; /* Swap function and traceback. */ tmp = J->base[0]; J->base[0] = J->base[1]; J->base[1] = tmp; copyTV(J->L, &argv0, &rd->argv[0]); copyTV(J->L, &argv1, &rd->argv[1]); copyTV(J->L, &rd->argv[0], &argv1); copyTV(J->L, &rd->argv[1], &argv0); /* Need to protect lj_record_call because it may throw. */ errcode = lj_vm_cpcall(J->L, NULL, J, recff_xpcall_cp); /* Always undo Lua stack swap to avoid confusing the interpreter. */ copyTV(J->L, &rd->argv[0], &argv0); copyTV(J->L, &rd->argv[1], &argv1); if (errcode) lj_err_throw(J->L, errcode); /* Propagate errors. */ rd->nres = -1; /* Pending call. */ } /* else: Interpreter will throw. */ }
static int recff_metacall(jit_State *J, RecordFFData *rd, MMS mm) { RecordIndex ix; ix.tab = J->base[0]; copyTV(J->L, &ix.tabv, &rd->argv[0]); if (lj_record_mm_lookup(J, &ix, mm)) { /* Has metamethod? */ int errcode; /* Temporarily insert metamethod below object. */ J->base[1] = J->base[0]; J->base[0] = ix.mobj; copyTV(J->L, &rd->argv[1], &rd->argv[0]); copyTV(J->L, &rd->argv[0], &ix.mobjv); /* Need to protect lj_record_tailcall because it may throw. */ errcode = lj_vm_cpcall(J->L, NULL, J, recff_metacall_cp); /* Always undo Lua stack changes to avoid confusing the interpreter. */ copyTV(J->L, &rd->argv[0], &rd->argv[1]); if (errcode) lj_err_throw(J->L, errcode); /* Propagate errors. */ rd->nres = -1; /* Pending call. */ return 1; /* Tailcalled to metamethod. */ } return 0; }