LUA_API int lua_dump(lua_State *L, lua_Writer writer, void *data) { cTValue *o = L->top-1; api_check(L, L->top > L->base); if (tvisfunc(o) && isluafunc(funcV(o))) return lj_bcwrite(L, funcproto(funcV(o)), writer, data, 0); else return 1; }
/* Return prototype of first argument (Lua function or prototype object) */ static GCproto *check_Lproto(lua_State *L, int nolua) { TValue *o = L->base; if (L->top > o) { if (tvisproto(o)) { return protoV(o); } else if (tvisfunc(o)) { if (isluafunc(funcV(o))) return funcproto(funcV(o)); else if (nolua) return NULL; } } lj_err_argt(L, 1, LUA_TFUNCTION); return NULL; /* unreachable */ }
GCfunc *lj_lib_checkfunc(lua_State *L, int narg) { TValue *o = L->base + narg-1; if (!(o < L->top && tvisfunc(o))) lj_err_argt(L, narg, LUA_TFUNCTION); return funcV(o); }
void lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f, GCtab *env) { luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 4); lua_pushcfunction(L, f); /* NOBARRIER: The function is new (marked white). */ setgcref(funcV(L->top-1)->c.env, obj2gco(env)); lua_setfield(L, -2, name); L->top--; }
/* Push internal function on the stack. */ GCfunc *lj_lib_pushcc(lua_State *L, lua_CFunction f, int id, int n) { GCfunc *fn; lua_pushcclosure(L, f, n); fn = funcV(L->top-1); fn->c.ffid = (uint8_t)id; setmref(fn->c.pc, &G(L)->bc_cfunc_int); return fn; }
double ZeroMultipole::Potential:: pot (const double & rr) { if (rr > rc) return 0.; double tmp0 = funcV (alpha, rr); // double tmp0 = 0.; double tmp1 = coeff.back(); for (int ii = ll-1; ii >= 0; --ii){ tmp1 = tmp1 * rr * rr + coeff[ii]; } return tmp0 - tmp1; }
static void LJ_FASTCALL recff_ipairs(jit_State *J, RecordFFData *rd) { if (!(LJ_52 && recff_metacall(J, rd, MM_ipairs))) { TRef tab = J->base[0]; if (tref_istab(tab)) { J->base[0] = lj_ir_kfunc(J, funcV(&J->fn->c.upvalue[0])); J->base[1] = tab; J->base[2] = lj_ir_kint(J, 0); rd->nres = 3; } /* else: Interpreter will throw. */ } }
static void LJ_FASTCALL recff_ipairs(jit_State *J, RecordFFData *rd) { #ifdef LUAJIT_ENABLE_LUA52COMPAT if (!recff_metacall(J, rd, MM_ipairs)) #endif { TRef tab = J->base[0]; if (tref_istab(tab)) { J->base[0] = lj_ir_kfunc(J, funcV(&J->fn->c.upvalue[0])); J->base[1] = tab; J->base[2] = lj_ir_kint(J, 0); rd->nres = 3; } /* else: Interpreter will throw. */ } }
/* -- Luajittex needs this one because it overloads loadfile -- */ LUALIB_API int RESERVED_load_aux_JIT(lua_State *L, int status, int envarg) { if (status == 0) { if (tvistab(L->base+envarg-1)) { GCfunc *fn = funcV(L->top-1); GCtab *t = tabV(L->base+envarg-1); setgcref(fn->c.env, obj2gco(t)); lj_gc_objbarrier(L, fn, t); } return 1; } else { setnilV(L->top-2); return 2; } }
ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev) { global_State *g = G(L); GCstr *s = lj_str_newlit(L, LJ_VMEVENTS_REGKEY); cTValue *tv = lj_tab_getstr(tabV(registry(L)), s); if (tvistab(tv)) { int hash = VMEVENT_HASH(ev); tv = lj_tab_getint(tabV(tv), hash); if (tv && tvisfunc(tv)) { lj_state_checkstack(L, LUA_MINSTACK); setfuncV(L, L->top++, funcV(tv)); return savestack(L, L->top); } } g->vmevmask &= ~VMEVENT_MASK(ev); /* No handler: cache this fact. */ return 0; }
static void jit_profile_callback(lua_State *L2, lua_State *L, int samples, int vmstate) { TValue key; cTValue *tv; setlightudV(&key, (void *)&KEY_PROFILE_FUNC); tv = lj_tab_get(L, tabV(registry(L)), &key); if (tvisfunc(tv)) { char vmst = (char)vmstate; int status; setfuncV(L2, L2->top++, funcV(tv)); setthreadV(L2, L2->top++, L); setintV(L2->top++, samples); setstrV(L2, L2->top++, lj_str_new(L2, &vmst, 1)); status = lua_pcall(L2, 3, 0, 0); /* callback(thread, samples, vmstate) */ if (status) { if (G(L2)->panic) G(L2)->panic(L2); exit(EXIT_FAILURE); } lj_trace_abort(G(L2)); } }
static GCproto *get_proto(lua_State *L) { return funcproto(funcV(L->base)); }
void ZeroMultipole:: calCoefficients (const int & ll, const double & alpha, const double & rc, vector<double > & coeff) { coeff.clear (); coeff.resize (ll+1); double b0, b1, b2, b3, b4; double invrc, invrc2, invrc3, invrc4; double rc2; switch (ll) { case 0: b0 = funcV (alpha,rc); coeff[0] = b0; break; case 1: b0 = funcV (alpha,rc); b1 = funcD1V (alpha,rc); coeff[0] = b0 - M_inv2 * b1 * rc; coeff[1] = M_inv2 * b1 / rc; break; case 2: b0 = funcV (alpha,rc); b1 = funcD1V (alpha,rc); b2 = funcD2V (alpha,rc); invrc = 1./rc; coeff[0] = M_inv8 * b2 * rc * rc - 5.*M_inv8 * b1 * rc + b0; coeff[1] = 3.*M_inv4 * b1 * invrc - M_inv4 * b2; coeff[2] = M_inv8 * b2 * invrc * invrc - M_inv8 * b1 * invrc * invrc * invrc; break; case 3: b0 = funcV (alpha,rc); b1 = funcD1V (alpha,rc); b2 = funcD2V (alpha,rc); b3 = funcD3V (alpha,rc); invrc = 1./rc; invrc2 = invrc * invrc; coeff[0] = - M_inv48 * b3 * rc * rc * rc + 3.*M_inv16 * b2 * rc * rc - 11.*M_inv16 * b1 * rc + b0; coeff[1] = 15.*M_inv16 * b1 * invrc - 7.*M_inv16 * b2 + M_inv16 * b3 * rc; coeff[2] = 5.*M_inv16 * b2 * invrc2 - 5.*M_inv16 * b1 * invrc2 * invrc - M_inv16 * b3 * invrc; coeff[3] = M_inv16 * b1 * invrc2 * invrc2 * invrc - M_inv16 * b2 * invrc2 * invrc2 + M_inv48 * b3 * invrc2 * invrc; break; case 4: b0 = funcV (alpha,rc); b1 = funcD1V (alpha,rc); b2 = funcD2V (alpha,rc); b3 = funcD3V (alpha,rc); b4 = funcD4V (alpha,rc); rc2 = rc * rc; invrc = 1./rc; invrc2 = invrc * invrc; invrc3 = invrc2 * invrc; invrc4 = invrc2 * invrc2; coeff[0] = 1./384. * b4 * rc2 * rc2 - 7./192. * b3 * rc2 * rc + 29./128. * b2 * rc2 - 93./128. * b1 * rc + b0; coeff[1] = 35./32. * b1 * invrc - 19./32. * b2 - 1./96. * b4 * rc2 + M_inv8 * b3 * rc; coeff[2] = 1./64. * b4 - 35./64. * b1 * invrc3 + 35./64. * b2 * invrc2 - 5./32. * b3 * invrc; coeff[3] = 7./32. * b1 * invrc4 * invrc - 7./32. * b2 * invrc4 + 1./12. * b3 * invrc3 - 1./96. * b4 * invrc2; coeff[4] = 5./128. * b2 * invrc4 * invrc2 - 5./128. * b1 * invrc4 * invrc3 - 1./64. * b3 * invrc4 * invrc + 1./384 * b4 * invrc4; break; default: cerr << "ll larger than 4 is not implemented" << endl; break; } }