static void LJ_FASTCALL recff_table_remove(jit_State *J, RecordFFData *rd) { TRef tab = J->base[0]; rd->nres = 0; if (tref_istab(tab)) { if (!J->base[1] || tref_isnil(J->base[1])) { /* Simple pop: t[#t] = nil */ TRef trlen = lj_ir_call(J, IRCALL_lj_tab_len, tab); GCtab *t = tabV(&rd->argv[0]); MSize len = lj_tab_len(t); emitir(IRTGI(len ? IR_NE : IR_EQ), trlen, lj_ir_kint(J, 0)); if (len) { RecordIndex ix; ix.tab = tab; ix.key = trlen; settabV(J->L, &ix.tabv, t); setintV(&ix.keyv, len); ix.idxchain = 0; if (results_wanted(J) != 0) { /* Specialize load only if needed. */ ix.val = 0; J->base[0] = lj_record_idx(J, &ix); /* Load previous value. */ rd->nres = 1; /* Assumes ix.key/ix.tab is not modified for raw lj_record_idx(). */ } ix.val = TREF_NIL; lj_record_idx(J, &ix); /* Remove value. */ } } else { /* Complex case: remove in the middle. */ recff_nyiu(J); } } /* else: Interpreter will throw. */ }
static void LJ_FASTCALL recff_table_getn(jit_State *J, RecordFFData *rd) { if (tref_istab(J->base[0])) J->base[0] = lj_ir_call(J, IRCALL_lj_tab_len, J->base[0]); /* else: Interpreter will throw. */ UNUSED(rd); }
static void LJ_FASTCALL recff_math_random(jit_State *J, RecordFFData *rd) { GCudata *ud = udataV(&J->fn->c.upvalue[0]); TRef tr, one; lj_ir_kgc(J, obj2gco(ud), IRT_UDATA); /* Prevent collection. */ tr = lj_ir_call(J, IRCALL_lj_math_random_step, lj_ir_kptr(J, uddata(ud))); one = lj_ir_knum_one(J); tr = emitir(IRTN(IR_SUB), tr, one); if (J->base[0]) { TRef tr1 = lj_ir_tonum(J, J->base[0]); if (J->base[1]) { /* d = floor(d*(r2-r1+1.0)) + r1 */ TRef tr2 = lj_ir_tonum(J, J->base[1]); tr2 = emitir(IRTN(IR_SUB), tr2, tr1); tr2 = emitir(IRTN(IR_ADD), tr2, one); tr = emitir(IRTN(IR_MUL), tr, tr2); tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_FLOOR); tr = emitir(IRTN(IR_ADD), tr, tr1); } else { /* d = floor(d*r1) + 1.0 */ tr = emitir(IRTN(IR_MUL), tr, tr1); tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_FLOOR); tr = emitir(IRTN(IR_ADD), tr, one); } } J->base[0] = tr; UNUSED(rd); }
static void LJ_FASTCALL recff_io_flush(jit_State *J, RecordFFData *rd) { TRef fp = recff_io_fp(J, rd->data); TRef tr = lj_ir_call(J, IRCALL_fflush, fp); if (results_wanted(J) != 0) /* Check result only if not ignored. */ emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0)); J->base[0] = TREF_TRUE; }
static void LJ_FASTCALL recff_rawlen(jit_State *J, RecordFFData *rd) { TRef tr = J->base[0]; if (tref_isstr(tr)) J->base[0] = emitir(IRTI(IR_FLOAD), tr, IRFL_STR_LEN); else if (tref_istab(tr)) J->base[0] = lj_ir_call(J, IRCALL_lj_tab_len, tr); /* else: Interpreter will throw. */ UNUSED(rd); }
static void LJ_FASTCALL recff_io_write(jit_State *J, RecordFFData *rd) { TRef fp = recff_io_fp(J, rd->data); TRef zero = lj_ir_kint(J, 0); TRef one = lj_ir_kint(J, 1); ptrdiff_t i = rd->data == 0 ? 1 : 0; for (; J->base[i]; i++) { TRef str = lj_ir_tostr(J, J->base[i]); TRef buf = emitir(IRT(IR_STRREF, IRT_P32), str, zero); TRef len = emitir(IRTI(IR_FLOAD), str, IRFL_STR_LEN); if (tref_isk(len) && IR(tref_ref(len))->i == 1) { TRef tr = emitir(IRT(IR_XLOAD, IRT_U8), buf, IRXLOAD_READONLY); tr = lj_ir_call(J, IRCALL_fputc, tr, fp); if (results_wanted(J) != 0) /* Check result only if not ignored. */ emitir(IRTGI(IR_NE), tr, lj_ir_kint(J, -1)); } else { TRef tr = lj_ir_call(J, IRCALL_fwrite, buf, one, len, fp); if (results_wanted(J) != 0) /* Check result only if not ignored. */ emitir(IRTGI(IR_EQ), tr, len); } } J->base[0] = TREF_TRUE; }
static void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd) { RecordIndex ix; ix.tab = J->base[0]; ix.val = J->base[1]; rd->nres = 0; if (tref_istab(ix.tab) && ix.val) { if (!J->base[2]) { /* Simple push: t[#t+1] = v */ TRef trlen = lj_ir_call(J, IRCALL_lj_tab_len, ix.tab); GCtab *t = tabV(&rd->argv[0]); ix.key = emitir(IRTI(IR_ADD), trlen, lj_ir_kint(J, 1)); settabV(J->L, &ix.tabv, t); setintV(&ix.keyv, lj_tab_len(t) + 1); ix.idxchain = 0; lj_record_idx(J, &ix); /* Set new value. */ } else { /* Complex case: insert in the middle. */ recff_nyiu(J); } } /* else: Interpreter will throw. */ }
static void LJ_FASTCALL recff_math_htrig(jit_State *J, RecordFFData *rd) { TRef tr = lj_ir_tonum(J, J->base[0]); J->base[0] = lj_ir_call(J, rd->data, tr); }