diff options
Diffstat (limited to '')
-rw-r--r-- | src/lj_ffrecord.c | 560 |
1 files changed, 444 insertions, 116 deletions
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index c258aee1..d05dc5d7 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "lj_dispatch.h" | 27 | #include "lj_dispatch.h" |
28 | #include "lj_vm.h" | 28 | #include "lj_vm.h" |
29 | #include "lj_strscan.h" | 29 | #include "lj_strscan.h" |
30 | #include "lj_strfmt.h" | ||
30 | 31 | ||
31 | /* Some local macros to save typing. Undef'd at the end. */ | 32 | /* Some local macros to save typing. Undef'd at the end. */ |
32 | #define IR(ref) (&J->cur.ir[(ref)]) | 33 | #define IR(ref) (&J->cur.ir[(ref)]) |
@@ -79,10 +80,7 @@ static GCstr *argv2str(jit_State *J, TValue *o) | |||
79 | GCstr *s; | 80 | GCstr *s; |
80 | if (!tvisnumber(o)) | 81 | if (!tvisnumber(o)) |
81 | lj_trace_err(J, LJ_TRERR_BADTYPE); | 82 | lj_trace_err(J, LJ_TRERR_BADTYPE); |
82 | if (tvisint(o)) | 83 | s = lj_strfmt_number(J->L, o); |
83 | s = lj_str_fromint(J->L, intV(o)); | ||
84 | else | ||
85 | s = lj_str_fromnum(J->L, &o->n); | ||
86 | setstrV(J->L, o, s); | 84 | setstrV(J->L, o, s); |
87 | return s; | 85 | return s; |
88 | } | 86 | } |
@@ -98,27 +96,91 @@ static ptrdiff_t results_wanted(jit_State *J) | |||
98 | return -1; | 96 | return -1; |
99 | } | 97 | } |
100 | 98 | ||
101 | /* Throw error for unsupported variant of fast function. */ | 99 | /* Trace stitching: add continuation below frame to start a new trace. */ |
102 | LJ_NORET static void recff_nyiu(jit_State *J) | 100 | static void recff_stitch(jit_State *J) |
103 | { | 101 | { |
104 | setfuncV(J->L, &J->errinfo, J->fn); | 102 | ASMFunction cont = lj_cont_stitch; |
105 | lj_trace_err_info(J, LJ_TRERR_NYIFFU); | 103 | lua_State *L = J->L; |
104 | TValue *base = L->base; | ||
105 | const BCIns *pc = frame_pc(base-1); | ||
106 | TValue *pframe = frame_prevl(base-1); | ||
107 | TRef trcont; | ||
108 | |||
109 | lua_assert(!LJ_FR2); /* TODO_FR2: handle frame shift. */ | ||
110 | /* Move func + args up in Lua stack and insert continuation. */ | ||
111 | memmove(&base[1], &base[-1], sizeof(TValue)*(J->maxslot+1)); | ||
112 | setframe_ftsz(base+1, ((char *)(base+1) - (char *)pframe) + FRAME_CONT); | ||
113 | setcont(base, cont); | ||
114 | setframe_pc(base, pc); | ||
115 | setnilV(base-1); /* Incorrect, but rec_check_slots() won't run anymore. */ | ||
116 | L->base += 2; | ||
117 | L->top += 2; | ||
118 | |||
119 | /* Ditto for the IR. */ | ||
120 | memmove(&J->base[1], &J->base[-1], sizeof(TRef)*(J->maxslot+1)); | ||
121 | #if LJ_64 | ||
122 | trcont = lj_ir_kptr(J, (void *)((int64_t)cont-(int64_t)lj_vm_asm_begin)); | ||
123 | #else | ||
124 | trcont = lj_ir_kptr(J, (void *)cont); | ||
125 | #endif | ||
126 | J->base[0] = trcont | TREF_CONT; | ||
127 | J->ktracep = lj_ir_k64_reserve(J); | ||
128 | lua_assert(irt_toitype_(IRT_P64) == LJ_TTRACE); | ||
129 | J->base[-1] = emitir(IRT(IR_XLOAD, IRT_P64), lj_ir_kptr(J, &J->ktracep->gcr), 0); | ||
130 | J->base += 2; | ||
131 | J->baseslot += 2; | ||
132 | J->framedepth++; | ||
133 | |||
134 | lj_record_stop(J, LJ_TRLINK_STITCH, 0); | ||
135 | |||
136 | /* Undo Lua stack changes. */ | ||
137 | memmove(&base[-1], &base[1], sizeof(TValue)*(J->maxslot+1)); | ||
138 | setframe_pc(base-1, pc); | ||
139 | L->base -= 2; | ||
140 | L->top -= 2; | ||
106 | } | 141 | } |
107 | 142 | ||
108 | /* Fallback handler for all fast functions that are not recorded (yet). */ | 143 | /* Fallback handler for fast functions that are not recorded (yet). */ |
109 | static void LJ_FASTCALL recff_nyi(jit_State *J, RecordFFData *rd) | 144 | static void LJ_FASTCALL recff_nyi(jit_State *J, RecordFFData *rd) |
110 | { | 145 | { |
111 | setfuncV(J->L, &J->errinfo, J->fn); | 146 | if (J->cur.nins < (IRRef)J->param[JIT_P_minstitch] + REF_BASE) { |
112 | lj_trace_err_info(J, LJ_TRERR_NYIFF); | 147 | lj_trace_err_info(J, LJ_TRERR_TRACEUV); |
113 | UNUSED(rd); | 148 | } else { |
149 | /* Can only stitch from Lua call. */ | ||
150 | if (J->framedepth && frame_islua(J->L->base-1)) { | ||
151 | BCOp op = bc_op(*frame_pc(J->L->base-1)); | ||
152 | /* Stitched trace cannot start with *M op with variable # of args. */ | ||
153 | if (!(op == BC_CALLM || op == BC_CALLMT || | ||
154 | op == BC_RETM || op == BC_TSETM)) { | ||
155 | switch (J->fn->c.ffid) { | ||
156 | case FF_error: | ||
157 | case FF_debug_sethook: | ||
158 | case FF_jit_flush: | ||
159 | break; /* Don't stitch across special builtins. */ | ||
160 | default: | ||
161 | recff_stitch(J); /* Use trace stitching. */ | ||
162 | rd->nres = -1; | ||
163 | return; | ||
164 | } | ||
165 | } | ||
166 | } | ||
167 | /* Otherwise stop trace and return to interpreter. */ | ||
168 | lj_record_stop(J, LJ_TRLINK_RETURN, 0); | ||
169 | rd->nres = -1; | ||
170 | } | ||
114 | } | 171 | } |
115 | 172 | ||
116 | /* C functions can have arbitrary side-effects and are not recorded (yet). */ | 173 | /* Fallback handler for unsupported variants of fast functions. */ |
117 | static void LJ_FASTCALL recff_c(jit_State *J, RecordFFData *rd) | 174 | #define recff_nyiu recff_nyi |
175 | |||
176 | /* Must stop the trace for classic C functions with arbitrary side-effects. */ | ||
177 | #define recff_c recff_nyi | ||
178 | |||
179 | /* Emit BUFHDR for the global temporary buffer. */ | ||
180 | static TRef recff_bufhdr(jit_State *J) | ||
118 | { | 181 | { |
119 | setfuncV(J->L, &J->errinfo, J->fn); | 182 | return emitir(IRT(IR_BUFHDR, IRT_P32), |
120 | lj_trace_err_info(J, LJ_TRERR_NYICF); | 183 | lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET); |
121 | UNUSED(rd); | ||
122 | } | 184 | } |
123 | 185 | ||
124 | /* -- Base library fast functions ----------------------------------------- */ | 186 | /* -- Base library fast functions ----------------------------------------- */ |
@@ -135,7 +197,7 @@ static void LJ_FASTCALL recff_type(jit_State *J, RecordFFData *rd) | |||
135 | uint32_t t; | 197 | uint32_t t; |
136 | if (tvisnumber(&rd->argv[0])) | 198 | if (tvisnumber(&rd->argv[0])) |
137 | t = ~LJ_TNUMX; | 199 | t = ~LJ_TNUMX; |
138 | else if (LJ_64 && tvislightud(&rd->argv[0])) | 200 | else if (LJ_64 && !LJ_GC64 && tvislightud(&rd->argv[0])) |
139 | t = ~LJ_TLIGHTUD; | 201 | t = ~LJ_TLIGHTUD; |
140 | else | 202 | else |
141 | t = ~itype(&rd->argv[0]); | 203 | t = ~itype(&rd->argv[0]); |
@@ -263,7 +325,8 @@ static void LJ_FASTCALL recff_select(jit_State *J, RecordFFData *rd) | |||
263 | J->base[i] = J->base[start+i]; | 325 | J->base[i] = J->base[start+i]; |
264 | } /* else: Interpreter will throw. */ | 326 | } /* else: Interpreter will throw. */ |
265 | } else { | 327 | } else { |
266 | recff_nyiu(J); | 328 | recff_nyiu(J, rd); |
329 | return; | ||
267 | } | 330 | } |
268 | } /* else: Interpreter will throw. */ | 331 | } /* else: Interpreter will throw. */ |
269 | } | 332 | } |
@@ -274,14 +337,18 @@ static void LJ_FASTCALL recff_tonumber(jit_State *J, RecordFFData *rd) | |||
274 | TRef base = J->base[1]; | 337 | TRef base = J->base[1]; |
275 | if (tr && !tref_isnil(base)) { | 338 | if (tr && !tref_isnil(base)) { |
276 | base = lj_opt_narrow_toint(J, base); | 339 | base = lj_opt_narrow_toint(J, base); |
277 | if (!tref_isk(base) || IR(tref_ref(base))->i != 10) | 340 | if (!tref_isk(base) || IR(tref_ref(base))->i != 10) { |
278 | recff_nyiu(J); | 341 | recff_nyiu(J, rd); |
342 | return; | ||
343 | } | ||
279 | } | 344 | } |
280 | if (tref_isnumber_str(tr)) { | 345 | if (tref_isnumber_str(tr)) { |
281 | if (tref_isstr(tr)) { | 346 | if (tref_isstr(tr)) { |
282 | TValue tmp; | 347 | TValue tmp; |
283 | if (!lj_strscan_num(strV(&rd->argv[0]), &tmp)) | 348 | if (!lj_strscan_num(strV(&rd->argv[0]), &tmp)) { |
284 | recff_nyiu(J); /* Would need an inverted STRTO for this case. */ | 349 | recff_nyiu(J, rd); /* Would need an inverted STRTO for this case. */ |
350 | return; | ||
351 | } | ||
285 | tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0); | 352 | tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0); |
286 | } | 353 | } |
287 | #if LJ_HASFFI | 354 | #if LJ_HASFFI |
@@ -336,13 +403,15 @@ static void LJ_FASTCALL recff_tostring(jit_State *J, RecordFFData *rd) | |||
336 | if (tref_isstr(tr)) { | 403 | if (tref_isstr(tr)) { |
337 | /* Ignore __tostring in the string base metatable. */ | 404 | /* Ignore __tostring in the string base metatable. */ |
338 | /* Pass on result in J->base[0]. */ | 405 | /* Pass on result in J->base[0]. */ |
339 | } else if (!recff_metacall(J, rd, MM_tostring)) { | 406 | } else if (tr && !recff_metacall(J, rd, MM_tostring)) { |
340 | if (tref_isnumber(tr)) { | 407 | if (tref_isnumber(tr)) { |
341 | J->base[0] = emitir(IRT(IR_TOSTR, IRT_STR), tr, 0); | 408 | J->base[0] = emitir(IRT(IR_TOSTR, IRT_STR), tr, |
409 | tref_isnum(tr) ? IRTOSTR_NUM : IRTOSTR_INT); | ||
342 | } else if (tref_ispri(tr)) { | 410 | } else if (tref_ispri(tr)) { |
343 | J->base[0] = lj_ir_kstr(J, strV(&J->fn->c.upvalue[tref_type(tr)])); | 411 | J->base[0] = lj_ir_kstr(J, lj_strfmt_obj(J->L, &rd->argv[0])); |
344 | } else { | 412 | } else { |
345 | recff_nyiu(J); | 413 | recff_nyiu(J, rd); |
414 | return; | ||
346 | } | 415 | } |
347 | } | 416 | } |
348 | } | 417 | } |
@@ -364,15 +433,15 @@ static void LJ_FASTCALL recff_ipairs_aux(jit_State *J, RecordFFData *rd) | |||
364 | } /* else: Interpreter will throw. */ | 433 | } /* else: Interpreter will throw. */ |
365 | } | 434 | } |
366 | 435 | ||
367 | static void LJ_FASTCALL recff_ipairs(jit_State *J, RecordFFData *rd) | 436 | static void LJ_FASTCALL recff_xpairs(jit_State *J, RecordFFData *rd) |
368 | { | 437 | { |
369 | TRef tr = J->base[0]; | 438 | TRef tr = J->base[0]; |
370 | if (!((LJ_52 || (LJ_HASFFI && tref_iscdata(tr))) && | 439 | if (!((LJ_52 || (LJ_HASFFI && tref_iscdata(tr))) && |
371 | recff_metacall(J, rd, MM_ipairs))) { | 440 | recff_metacall(J, rd, MM_pairs + rd->data))) { |
372 | if (tref_istab(tr)) { | 441 | if (tref_istab(tr)) { |
373 | J->base[0] = lj_ir_kfunc(J, funcV(&J->fn->c.upvalue[0])); | 442 | J->base[0] = lj_ir_kfunc(J, funcV(&J->fn->c.upvalue[0])); |
374 | J->base[1] = tr; | 443 | J->base[1] = tr; |
375 | J->base[2] = lj_ir_kint(J, 0); | 444 | J->base[2] = rd->data ? lj_ir_kint(J, 0) : TREF_NIL; |
376 | rd->nres = 3; | 445 | rd->nres = 3; |
377 | } /* else: Interpreter will throw. */ | 446 | } /* else: Interpreter will throw. */ |
378 | } | 447 | } |
@@ -400,6 +469,7 @@ static void LJ_FASTCALL recff_xpcall(jit_State *J, RecordFFData *rd) | |||
400 | TValue argv0, argv1; | 469 | TValue argv0, argv1; |
401 | TRef tmp; | 470 | TRef tmp; |
402 | int errcode; | 471 | int errcode; |
472 | lua_assert(!LJ_FR2); /* TODO_FR2: handle different frame setup. */ | ||
403 | /* Swap function and traceback. */ | 473 | /* Swap function and traceback. */ |
404 | tmp = J->base[0]; J->base[0] = J->base[1]; J->base[1] = tmp; | 474 | tmp = J->base[0]; J->base[0] = J->base[1]; J->base[1] = tmp; |
405 | copyTV(J->L, &argv0, &rd->argv[0]); | 475 | copyTV(J->L, &argv0, &rd->argv[0]); |
@@ -417,6 +487,18 @@ static void LJ_FASTCALL recff_xpcall(jit_State *J, RecordFFData *rd) | |||
417 | } /* else: Interpreter will throw. */ | 487 | } /* else: Interpreter will throw. */ |
418 | } | 488 | } |
419 | 489 | ||
490 | static void LJ_FASTCALL recff_getfenv(jit_State *J, RecordFFData *rd) | ||
491 | { | ||
492 | TRef tr = J->base[0]; | ||
493 | /* Only support getfenv(0) for now. */ | ||
494 | if (tref_isint(tr) && tref_isk(tr) && IR(tref_ref(tr))->i == 0) { | ||
495 | TRef trl = emitir(IRT(IR_LREF, IRT_THREAD), 0, 0); | ||
496 | J->base[0] = emitir(IRT(IR_FLOAD, IRT_TAB), trl, IRFL_THREAD_ENV); | ||
497 | return; | ||
498 | } | ||
499 | recff_nyiu(J, rd); | ||
500 | } | ||
501 | |||
420 | /* -- Math library fast functions ----------------------------------------- */ | 502 | /* -- Math library fast functions ----------------------------------------- */ |
421 | 503 | ||
422 | static void LJ_FASTCALL recff_math_abs(jit_State *J, RecordFFData *rd) | 504 | static void LJ_FASTCALL recff_math_abs(jit_State *J, RecordFFData *rd) |
@@ -529,14 +611,6 @@ static void LJ_FASTCALL recff_math_modf(jit_State *J, RecordFFData *rd) | |||
529 | rd->nres = 2; | 611 | rd->nres = 2; |
530 | } | 612 | } |
531 | 613 | ||
532 | static void LJ_FASTCALL recff_math_degrad(jit_State *J, RecordFFData *rd) | ||
533 | { | ||
534 | TRef tr = lj_ir_tonum(J, J->base[0]); | ||
535 | TRef trm = lj_ir_knum(J, numV(&J->fn->c.upvalue[0])); | ||
536 | J->base[0] = emitir(IRTN(IR_MUL), tr, trm); | ||
537 | UNUSED(rd); | ||
538 | } | ||
539 | |||
540 | static void LJ_FASTCALL recff_math_pow(jit_State *J, RecordFFData *rd) | 614 | static void LJ_FASTCALL recff_math_pow(jit_State *J, RecordFFData *rd) |
541 | { | 615 | { |
542 | TRef tr = lj_ir_tonum(J, J->base[0]); | 616 | TRef tr = lj_ir_tonum(J, J->base[0]); |
@@ -593,48 +667,105 @@ static void LJ_FASTCALL recff_math_random(jit_State *J, RecordFFData *rd) | |||
593 | 667 | ||
594 | /* -- Bit library fast functions ------------------------------------------ */ | 668 | /* -- Bit library fast functions ------------------------------------------ */ |
595 | 669 | ||
596 | /* Record unary bit.tobit, bit.bnot, bit.bswap. */ | 670 | /* Record bit.tobit. */ |
671 | static void LJ_FASTCALL recff_bit_tobit(jit_State *J, RecordFFData *rd) | ||
672 | { | ||
673 | TRef tr = J->base[0]; | ||
674 | #if LJ_HASFFI | ||
675 | if (tref_iscdata(tr)) { recff_bit64_tobit(J, rd); return; } | ||
676 | #endif | ||
677 | J->base[0] = lj_opt_narrow_tobit(J, tr); | ||
678 | UNUSED(rd); | ||
679 | } | ||
680 | |||
681 | /* Record unary bit.bnot, bit.bswap. */ | ||
597 | static void LJ_FASTCALL recff_bit_unary(jit_State *J, RecordFFData *rd) | 682 | static void LJ_FASTCALL recff_bit_unary(jit_State *J, RecordFFData *rd) |
598 | { | 683 | { |
599 | TRef tr = lj_opt_narrow_tobit(J, J->base[0]); | 684 | #if LJ_HASFFI |
600 | J->base[0] = (rd->data == IR_TOBIT) ? tr : emitir(IRTI(rd->data), tr, 0); | 685 | if (recff_bit64_unary(J, rd)) |
686 | return; | ||
687 | #endif | ||
688 | J->base[0] = emitir(IRTI(rd->data), lj_opt_narrow_tobit(J, J->base[0]), 0); | ||
601 | } | 689 | } |
602 | 690 | ||
603 | /* Record N-ary bit.band, bit.bor, bit.bxor. */ | 691 | /* Record N-ary bit.band, bit.bor, bit.bxor. */ |
604 | static void LJ_FASTCALL recff_bit_nary(jit_State *J, RecordFFData *rd) | 692 | static void LJ_FASTCALL recff_bit_nary(jit_State *J, RecordFFData *rd) |
605 | { | 693 | { |
606 | TRef tr = lj_opt_narrow_tobit(J, J->base[0]); | 694 | #if LJ_HASFFI |
607 | uint32_t op = rd->data; | 695 | if (recff_bit64_nary(J, rd)) |
608 | BCReg i; | 696 | return; |
609 | for (i = 1; J->base[i] != 0; i++) | 697 | #endif |
610 | tr = emitir(IRTI(op), tr, lj_opt_narrow_tobit(J, J->base[i])); | 698 | { |
611 | J->base[0] = tr; | 699 | TRef tr = lj_opt_narrow_tobit(J, J->base[0]); |
700 | uint32_t ot = IRTI(rd->data); | ||
701 | BCReg i; | ||
702 | for (i = 1; J->base[i] != 0; i++) | ||
703 | tr = emitir(ot, tr, lj_opt_narrow_tobit(J, J->base[i])); | ||
704 | J->base[0] = tr; | ||
705 | } | ||
612 | } | 706 | } |
613 | 707 | ||
614 | /* Record bit shifts. */ | 708 | /* Record bit shifts. */ |
615 | static void LJ_FASTCALL recff_bit_shift(jit_State *J, RecordFFData *rd) | 709 | static void LJ_FASTCALL recff_bit_shift(jit_State *J, RecordFFData *rd) |
616 | { | 710 | { |
617 | TRef tr = lj_opt_narrow_tobit(J, J->base[0]); | 711 | #if LJ_HASFFI |
618 | TRef tsh = lj_opt_narrow_tobit(J, J->base[1]); | 712 | if (recff_bit64_shift(J, rd)) |
619 | IROp op = (IROp)rd->data; | 713 | return; |
620 | if (!(op < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) && | 714 | #endif |
621 | !tref_isk(tsh)) | 715 | { |
622 | tsh = emitir(IRTI(IR_BAND), tsh, lj_ir_kint(J, 31)); | 716 | TRef tr = lj_opt_narrow_tobit(J, J->base[0]); |
717 | TRef tsh = lj_opt_narrow_tobit(J, J->base[1]); | ||
718 | IROp op = (IROp)rd->data; | ||
719 | if (!(op < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) && | ||
720 | !tref_isk(tsh)) | ||
721 | tsh = emitir(IRTI(IR_BAND), tsh, lj_ir_kint(J, 31)); | ||
623 | #ifdef LJ_TARGET_UNIFYROT | 722 | #ifdef LJ_TARGET_UNIFYROT |
624 | if (op == (LJ_TARGET_UNIFYROT == 1 ? IR_BROR : IR_BROL)) { | 723 | if (op == (LJ_TARGET_UNIFYROT == 1 ? IR_BROR : IR_BROL)) { |
625 | op = LJ_TARGET_UNIFYROT == 1 ? IR_BROL : IR_BROR; | 724 | op = LJ_TARGET_UNIFYROT == 1 ? IR_BROL : IR_BROR; |
626 | tsh = emitir(IRTI(IR_NEG), tsh, tsh); | 725 | tsh = emitir(IRTI(IR_NEG), tsh, tsh); |
726 | } | ||
727 | #endif | ||
728 | J->base[0] = emitir(IRTI(op), tr, tsh); | ||
627 | } | 729 | } |
730 | } | ||
731 | |||
732 | static void LJ_FASTCALL recff_bit_tohex(jit_State *J, RecordFFData *rd) | ||
733 | { | ||
734 | #if LJ_HASFFI | ||
735 | TRef hdr = recff_bufhdr(J); | ||
736 | TRef tr = recff_bit64_tohex(J, rd, hdr); | ||
737 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); | ||
738 | #else | ||
739 | recff_nyiu(J, rd); /* Don't bother working around this NYI. */ | ||
628 | #endif | 740 | #endif |
629 | J->base[0] = emitir(IRTI(op), tr, tsh); | ||
630 | } | 741 | } |
631 | 742 | ||
632 | /* -- String library fast functions --------------------------------------- */ | 743 | /* -- String library fast functions --------------------------------------- */ |
633 | 744 | ||
634 | static void LJ_FASTCALL recff_string_len(jit_State *J, RecordFFData *rd) | 745 | /* Specialize to relative starting position for string. */ |
746 | static TRef recff_string_start(jit_State *J, GCstr *s, int32_t *st, TRef tr, | ||
747 | TRef trlen, TRef tr0) | ||
635 | { | 748 | { |
636 | J->base[0] = emitir(IRTI(IR_FLOAD), lj_ir_tostr(J, J->base[0]), IRFL_STR_LEN); | 749 | int32_t start = *st; |
637 | UNUSED(rd); | 750 | if (start < 0) { |
751 | emitir(IRTGI(IR_LT), tr, tr0); | ||
752 | tr = emitir(IRTI(IR_ADD), trlen, tr); | ||
753 | start = start + (int32_t)s->len; | ||
754 | emitir(start < 0 ? IRTGI(IR_LT) : IRTGI(IR_GE), tr, tr0); | ||
755 | if (start < 0) { | ||
756 | tr = tr0; | ||
757 | start = 0; | ||
758 | } | ||
759 | } else if (start == 0) { | ||
760 | emitir(IRTGI(IR_EQ), tr, tr0); | ||
761 | tr = tr0; | ||
762 | } else { | ||
763 | tr = emitir(IRTI(IR_ADD), tr, lj_ir_kint(J, -1)); | ||
764 | emitir(IRTGI(IR_GE), tr, tr0); | ||
765 | start--; | ||
766 | } | ||
767 | *st = start; | ||
768 | return tr; | ||
638 | } | 769 | } |
639 | 770 | ||
640 | /* Handle string.byte (rd->data = 0) and string.sub (rd->data = 1). */ | 771 | /* Handle string.byte (rd->data = 0) and string.sub (rd->data = 1). */ |
@@ -681,29 +812,11 @@ static void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd) | |||
681 | } else if ((MSize)end <= str->len) { | 812 | } else if ((MSize)end <= str->len) { |
682 | emitir(IRTGI(IR_ULE), trend, trlen); | 813 | emitir(IRTGI(IR_ULE), trend, trlen); |
683 | } else { | 814 | } else { |
684 | emitir(IRTGI(IR_GT), trend, trlen); | 815 | emitir(IRTGI(IR_UGT), trend, trlen); |
685 | end = (int32_t)str->len; | 816 | end = (int32_t)str->len; |
686 | trend = trlen; | 817 | trend = trlen; |
687 | } | 818 | } |
688 | if (start < 0) { | 819 | trstart = recff_string_start(J, str, &start, trstart, trlen, tr0); |
689 | emitir(IRTGI(IR_LT), trstart, tr0); | ||
690 | trstart = emitir(IRTI(IR_ADD), trlen, trstart); | ||
691 | start = start+(int32_t)str->len; | ||
692 | emitir(start < 0 ? IRTGI(IR_LT) : IRTGI(IR_GE), trstart, tr0); | ||
693 | if (start < 0) { | ||
694 | trstart = tr0; | ||
695 | start = 0; | ||
696 | } | ||
697 | } else { | ||
698 | if (start == 0) { | ||
699 | emitir(IRTGI(IR_EQ), trstart, tr0); | ||
700 | trstart = tr0; | ||
701 | } else { | ||
702 | trstart = emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, -1)); | ||
703 | emitir(IRTGI(IR_GE), trstart, tr0); | ||
704 | start--; | ||
705 | } | ||
706 | } | ||
707 | if (rd->data) { /* Return string.sub result. */ | 820 | if (rd->data) { /* Return string.sub result. */ |
708 | if (end - start >= 0) { | 821 | if (end - start >= 0) { |
709 | /* Also handle empty range here, to avoid extra traces. */ | 822 | /* Also handle empty range here, to avoid extra traces. */ |
@@ -713,7 +826,7 @@ static void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd) | |||
713 | J->base[0] = emitir(IRT(IR_SNEW, IRT_STR), trptr, trslen); | 826 | J->base[0] = emitir(IRT(IR_SNEW, IRT_STR), trptr, trslen); |
714 | } else { /* Range underflow: return empty string. */ | 827 | } else { /* Range underflow: return empty string. */ |
715 | emitir(IRTGI(IR_LT), trend, trstart); | 828 | emitir(IRTGI(IR_LT), trend, trstart); |
716 | J->base[0] = lj_ir_kstr(J, lj_str_new(J->L, strdata(str), 0)); | 829 | J->base[0] = lj_ir_kstr(J, &J2G(J)->strempty); |
717 | } | 830 | } |
718 | } else { /* Return string.byte result(s). */ | 831 | } else { /* Return string.byte result(s). */ |
719 | ptrdiff_t i, len = end - start; | 832 | ptrdiff_t i, len = end - start; |
@@ -735,48 +848,200 @@ static void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd) | |||
735 | } | 848 | } |
736 | } | 849 | } |
737 | 850 | ||
738 | /* -- Table library fast functions ---------------------------------------- */ | 851 | static void LJ_FASTCALL recff_string_char(jit_State *J, RecordFFData *rd) |
739 | |||
740 | static void LJ_FASTCALL recff_table_getn(jit_State *J, RecordFFData *rd) | ||
741 | { | 852 | { |
742 | if (tref_istab(J->base[0])) | 853 | TRef k255 = lj_ir_kint(J, 255); |
743 | J->base[0] = lj_ir_call(J, IRCALL_lj_tab_len, J->base[0]); | 854 | BCReg i; |
744 | /* else: Interpreter will throw. */ | 855 | for (i = 0; J->base[i] != 0; i++) { /* Convert char values to strings. */ |
856 | TRef tr = lj_opt_narrow_toint(J, J->base[i]); | ||
857 | emitir(IRTGI(IR_ULE), tr, k255); | ||
858 | J->base[i] = emitir(IRT(IR_TOSTR, IRT_STR), tr, IRTOSTR_CHAR); | ||
859 | } | ||
860 | if (i > 1) { /* Concatenate the strings, if there's more than one. */ | ||
861 | TRef hdr = recff_bufhdr(J), tr = hdr; | ||
862 | for (i = 0; J->base[i] != 0; i++) | ||
863 | tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, J->base[i]); | ||
864 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); | ||
865 | } | ||
745 | UNUSED(rd); | 866 | UNUSED(rd); |
746 | } | 867 | } |
747 | 868 | ||
748 | static void LJ_FASTCALL recff_table_remove(jit_State *J, RecordFFData *rd) | 869 | static void LJ_FASTCALL recff_string_rep(jit_State *J, RecordFFData *rd) |
749 | { | 870 | { |
750 | TRef tab = J->base[0]; | 871 | TRef str = lj_ir_tostr(J, J->base[0]); |
751 | rd->nres = 0; | 872 | TRef rep = lj_opt_narrow_toint(J, J->base[1]); |
752 | if (tref_istab(tab)) { | 873 | TRef hdr, tr, str2 = 0; |
753 | if (tref_isnil(J->base[1])) { /* Simple pop: t[#t] = nil */ | 874 | if (!tref_isnil(J->base[2])) { |
754 | TRef trlen = lj_ir_call(J, IRCALL_lj_tab_len, tab); | 875 | TRef sep = lj_ir_tostr(J, J->base[2]); |
755 | GCtab *t = tabV(&rd->argv[0]); | 876 | int32_t vrep = argv2int(J, &rd->argv[1]); |
756 | MSize len = lj_tab_len(t); | 877 | emitir(IRTGI(vrep > 1 ? IR_GT : IR_LE), rep, lj_ir_kint(J, 1)); |
757 | emitir(IRTGI(len ? IR_NE : IR_EQ), trlen, lj_ir_kint(J, 0)); | 878 | if (vrep > 1) { |
758 | if (len) { | 879 | TRef hdr2 = recff_bufhdr(J); |
759 | RecordIndex ix; | 880 | TRef tr2 = emitir(IRT(IR_BUFPUT, IRT_P32), hdr2, sep); |
760 | ix.tab = tab; | 881 | tr2 = emitir(IRT(IR_BUFPUT, IRT_P32), tr2, str); |
761 | ix.key = trlen; | 882 | str2 = emitir(IRT(IR_BUFSTR, IRT_STR), tr2, hdr2); |
762 | settabV(J->L, &ix.tabv, t); | 883 | } |
763 | setintV(&ix.keyv, len); | 884 | } |
764 | ix.idxchain = 0; | 885 | tr = hdr = recff_bufhdr(J); |
765 | if (results_wanted(J) != 0) { /* Specialize load only if needed. */ | 886 | if (str2) { |
766 | ix.val = 0; | 887 | tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, str); |
767 | J->base[0] = lj_record_idx(J, &ix); /* Load previous value. */ | 888 | str = str2; |
768 | rd->nres = 1; | 889 | rep = emitir(IRTI(IR_ADD), rep, lj_ir_kint(J, -1)); |
769 | /* Assumes ix.key/ix.tab is not modified for raw lj_record_idx(). */ | 890 | } |
770 | } | 891 | tr = lj_ir_call(J, IRCALL_lj_buf_putstr_rep, tr, str, rep); |
771 | ix.val = TREF_NIL; | 892 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); |
772 | lj_record_idx(J, &ix); /* Remove value. */ | 893 | } |
894 | |||
895 | static void LJ_FASTCALL recff_string_op(jit_State *J, RecordFFData *rd) | ||
896 | { | ||
897 | TRef str = lj_ir_tostr(J, J->base[0]); | ||
898 | TRef hdr = recff_bufhdr(J); | ||
899 | TRef tr = lj_ir_call(J, rd->data, hdr, str); | ||
900 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); | ||
901 | } | ||
902 | |||
903 | static void LJ_FASTCALL recff_string_find(jit_State *J, RecordFFData *rd) | ||
904 | { | ||
905 | TRef trstr = lj_ir_tostr(J, J->base[0]); | ||
906 | TRef trpat = lj_ir_tostr(J, J->base[1]); | ||
907 | TRef trlen = emitir(IRTI(IR_FLOAD), trstr, IRFL_STR_LEN); | ||
908 | TRef tr0 = lj_ir_kint(J, 0); | ||
909 | TRef trstart; | ||
910 | GCstr *str = argv2str(J, &rd->argv[0]); | ||
911 | GCstr *pat = argv2str(J, &rd->argv[1]); | ||
912 | int32_t start; | ||
913 | J->needsnap = 1; | ||
914 | if (tref_isnil(J->base[2])) { | ||
915 | trstart = lj_ir_kint(J, 1); | ||
916 | start = 1; | ||
917 | } else { | ||
918 | trstart = lj_opt_narrow_toint(J, J->base[2]); | ||
919 | start = argv2int(J, &rd->argv[2]); | ||
920 | } | ||
921 | trstart = recff_string_start(J, str, &start, trstart, trlen, tr0); | ||
922 | if ((MSize)start <= str->len) { | ||
923 | emitir(IRTGI(IR_ULE), trstart, trlen); | ||
924 | } else { | ||
925 | emitir(IRTGI(IR_UGT), trstart, trlen); | ||
926 | #if LJ_52 | ||
927 | J->base[0] = TREF_NIL; | ||
928 | return; | ||
929 | #else | ||
930 | trstart = trlen; | ||
931 | start = str->len; | ||
932 | #endif | ||
933 | } | ||
934 | /* Fixed arg or no pattern matching chars? (Specialized to pattern string.) */ | ||
935 | if ((J->base[2] && tref_istruecond(J->base[3])) || | ||
936 | (emitir(IRTG(IR_EQ, IRT_STR), trpat, lj_ir_kstr(J, pat)), | ||
937 | !lj_str_haspattern(pat))) { /* Search for fixed string. */ | ||
938 | TRef trsptr = emitir(IRT(IR_STRREF, IRT_P32), trstr, trstart); | ||
939 | TRef trpptr = emitir(IRT(IR_STRREF, IRT_P32), trpat, tr0); | ||
940 | TRef trslen = emitir(IRTI(IR_SUB), trlen, trstart); | ||
941 | TRef trplen = emitir(IRTI(IR_FLOAD), trpat, IRFL_STR_LEN); | ||
942 | TRef tr = lj_ir_call(J, IRCALL_lj_str_find, trsptr, trpptr, trslen, trplen); | ||
943 | TRef trp0 = lj_ir_kkptr(J, NULL); | ||
944 | if (lj_str_find(strdata(str)+(MSize)start, strdata(pat), | ||
945 | str->len-(MSize)start, pat->len)) { | ||
946 | TRef pos; | ||
947 | emitir(IRTG(IR_NE, IRT_P32), tr, trp0); | ||
948 | pos = emitir(IRTI(IR_SUB), tr, emitir(IRT(IR_STRREF, IRT_P32), trstr, tr0)); | ||
949 | J->base[0] = emitir(IRTI(IR_ADD), pos, lj_ir_kint(J, 1)); | ||
950 | J->base[1] = emitir(IRTI(IR_ADD), pos, trplen); | ||
951 | rd->nres = 2; | ||
952 | } else { | ||
953 | emitir(IRTG(IR_EQ, IRT_P32), tr, trp0); | ||
954 | J->base[0] = TREF_NIL; | ||
955 | } | ||
956 | } else { /* Search for pattern. */ | ||
957 | recff_nyiu(J, rd); | ||
958 | return; | ||
959 | } | ||
960 | } | ||
961 | |||
962 | static void LJ_FASTCALL recff_string_format(jit_State *J, RecordFFData *rd) | ||
963 | { | ||
964 | TRef trfmt = lj_ir_tostr(J, J->base[0]); | ||
965 | GCstr *fmt = argv2str(J, &rd->argv[0]); | ||
966 | int arg = 1; | ||
967 | TRef hdr, tr; | ||
968 | FormatState fs; | ||
969 | SFormat sf; | ||
970 | /* Specialize to the format string. */ | ||
971 | emitir(IRTG(IR_EQ, IRT_STR), trfmt, lj_ir_kstr(J, fmt)); | ||
972 | tr = hdr = recff_bufhdr(J); | ||
973 | lj_strfmt_init(&fs, strdata(fmt), fmt->len); | ||
974 | while ((sf = lj_strfmt_parse(&fs)) != STRFMT_EOF) { /* Parse format. */ | ||
975 | TRef tra = sf == STRFMT_LIT ? 0 : J->base[arg++]; | ||
976 | TRef trsf = lj_ir_kint(J, (int32_t)sf); | ||
977 | IRCallID id; | ||
978 | switch (STRFMT_TYPE(sf)) { | ||
979 | case STRFMT_LIT: | ||
980 | tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, | ||
981 | lj_ir_kstr(J, lj_str_new(J->L, fs.str, fs.len))); | ||
982 | break; | ||
983 | case STRFMT_INT: | ||
984 | id = IRCALL_lj_strfmt_putfnum_int; | ||
985 | handle_int: | ||
986 | if (!tref_isinteger(tra)) | ||
987 | goto handle_num; | ||
988 | if (sf == STRFMT_INT) { /* Shortcut for plain %d. */ | ||
989 | tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, | ||
990 | emitir(IRT(IR_TOSTR, IRT_STR), tra, IRTOSTR_INT)); | ||
991 | } else { | ||
992 | #if LJ_HASFFI | ||
993 | tra = emitir(IRT(IR_CONV, IRT_U64), tra, | ||
994 | (IRT_INT|(IRT_U64<<5)|IRCONV_SEXT)); | ||
995 | tr = lj_ir_call(J, IRCALL_lj_strfmt_putfxint, tr, trsf, tra); | ||
996 | lj_needsplit(J); | ||
997 | #else | ||
998 | recff_nyiu(J, rd); /* Don't bother working around this NYI. */ | ||
999 | return; | ||
1000 | #endif | ||
773 | } | 1001 | } |
774 | } else { /* Complex case: remove in the middle. */ | 1002 | break; |
775 | recff_nyiu(J); | 1003 | case STRFMT_UINT: |
1004 | id = IRCALL_lj_strfmt_putfnum_uint; | ||
1005 | goto handle_int; | ||
1006 | case STRFMT_NUM: | ||
1007 | id = IRCALL_lj_strfmt_putfnum; | ||
1008 | handle_num: | ||
1009 | tra = lj_ir_tonum(J, tra); | ||
1010 | tr = lj_ir_call(J, id, tr, trsf, tra); | ||
1011 | if (LJ_SOFTFP) lj_needsplit(J); | ||
1012 | break; | ||
1013 | case STRFMT_STR: | ||
1014 | if (!tref_isstr(tra)) { | ||
1015 | recff_nyiu(J, rd); /* NYI: __tostring and non-string types for %s. */ | ||
1016 | return; | ||
1017 | } | ||
1018 | if (sf == STRFMT_STR) /* Shortcut for plain %s. */ | ||
1019 | tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, tra); | ||
1020 | else if ((sf & STRFMT_T_QUOTED)) | ||
1021 | tr = lj_ir_call(J, IRCALL_lj_strfmt_putquoted, tr, tra); | ||
1022 | else | ||
1023 | tr = lj_ir_call(J, IRCALL_lj_strfmt_putfstr, tr, trsf, tra); | ||
1024 | break; | ||
1025 | case STRFMT_CHAR: | ||
1026 | tra = lj_opt_narrow_toint(J, tra); | ||
1027 | if (sf == STRFMT_CHAR) /* Shortcut for plain %c. */ | ||
1028 | tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, | ||
1029 | emitir(IRT(IR_TOSTR, IRT_STR), tra, IRTOSTR_CHAR)); | ||
1030 | else | ||
1031 | tr = lj_ir_call(J, IRCALL_lj_strfmt_putfchar, tr, trsf, tra); | ||
1032 | break; | ||
1033 | case STRFMT_PTR: /* NYI */ | ||
1034 | case STRFMT_ERR: | ||
1035 | default: | ||
1036 | recff_nyiu(J, rd); | ||
1037 | return; | ||
776 | } | 1038 | } |
777 | } /* else: Interpreter will throw. */ | 1039 | } |
1040 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); | ||
778 | } | 1041 | } |
779 | 1042 | ||
1043 | /* -- Table library fast functions ---------------------------------------- */ | ||
1044 | |||
780 | static void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd) | 1045 | static void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd) |
781 | { | 1046 | { |
782 | RecordIndex ix; | 1047 | RecordIndex ix; |
@@ -793,11 +1058,49 @@ static void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd) | |||
793 | ix.idxchain = 0; | 1058 | ix.idxchain = 0; |
794 | lj_record_idx(J, &ix); /* Set new value. */ | 1059 | lj_record_idx(J, &ix); /* Set new value. */ |
795 | } else { /* Complex case: insert in the middle. */ | 1060 | } else { /* Complex case: insert in the middle. */ |
796 | recff_nyiu(J); | 1061 | recff_nyiu(J, rd); |
1062 | return; | ||
797 | } | 1063 | } |
798 | } /* else: Interpreter will throw. */ | 1064 | } /* else: Interpreter will throw. */ |
799 | } | 1065 | } |
800 | 1066 | ||
1067 | static void LJ_FASTCALL recff_table_concat(jit_State *J, RecordFFData *rd) | ||
1068 | { | ||
1069 | TRef tab = J->base[0]; | ||
1070 | if (tref_istab(tab)) { | ||
1071 | TRef sep = !tref_isnil(J->base[1]) ? | ||
1072 | lj_ir_tostr(J, J->base[1]) : lj_ir_knull(J, IRT_STR); | ||
1073 | TRef tri = (J->base[1] && !tref_isnil(J->base[2])) ? | ||
1074 | lj_opt_narrow_toint(J, J->base[2]) : lj_ir_kint(J, 1); | ||
1075 | TRef tre = (J->base[1] && J->base[2] && !tref_isnil(J->base[3])) ? | ||
1076 | lj_opt_narrow_toint(J, J->base[3]) : | ||
1077 | lj_ir_call(J, IRCALL_lj_tab_len, tab); | ||
1078 | TRef hdr = recff_bufhdr(J); | ||
1079 | TRef tr = lj_ir_call(J, IRCALL_lj_buf_puttab, hdr, tab, sep, tri, tre); | ||
1080 | emitir(IRTG(IR_NE, IRT_PTR), tr, lj_ir_kptr(J, NULL)); | ||
1081 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); | ||
1082 | } /* else: Interpreter will throw. */ | ||
1083 | UNUSED(rd); | ||
1084 | } | ||
1085 | |||
1086 | static void LJ_FASTCALL recff_table_new(jit_State *J, RecordFFData *rd) | ||
1087 | { | ||
1088 | TRef tra = lj_opt_narrow_toint(J, J->base[0]); | ||
1089 | TRef trh = lj_opt_narrow_toint(J, J->base[1]); | ||
1090 | J->base[0] = lj_ir_call(J, IRCALL_lj_tab_new_ah, tra, trh); | ||
1091 | UNUSED(rd); | ||
1092 | } | ||
1093 | |||
1094 | static void LJ_FASTCALL recff_table_clear(jit_State *J, RecordFFData *rd) | ||
1095 | { | ||
1096 | TRef tr = J->base[0]; | ||
1097 | if (tref_istab(tr)) { | ||
1098 | rd->nres = 0; | ||
1099 | lj_ir_call(J, IRCALL_lj_tab_clear, tr); | ||
1100 | J->needsnap = 1; | ||
1101 | } /* else: Interpreter will throw. */ | ||
1102 | } | ||
1103 | |||
801 | /* -- I/O library fast functions ------------------------------------------ */ | 1104 | /* -- I/O library fast functions ------------------------------------------ */ |
802 | 1105 | ||
803 | /* Get FILE* for I/O function. Any I/O error aborts recording, so there's | 1106 | /* Get FILE* for I/O function. Any I/O error aborts recording, so there's |
@@ -833,7 +1136,10 @@ static void LJ_FASTCALL recff_io_write(jit_State *J, RecordFFData *rd) | |||
833 | TRef buf = emitir(IRT(IR_STRREF, IRT_P32), str, zero); | 1136 | TRef buf = emitir(IRT(IR_STRREF, IRT_P32), str, zero); |
834 | TRef len = emitir(IRTI(IR_FLOAD), str, IRFL_STR_LEN); | 1137 | TRef len = emitir(IRTI(IR_FLOAD), str, IRFL_STR_LEN); |
835 | if (tref_isk(len) && IR(tref_ref(len))->i == 1) { | 1138 | if (tref_isk(len) && IR(tref_ref(len))->i == 1) { |
836 | TRef tr = emitir(IRT(IR_XLOAD, IRT_U8), buf, IRXLOAD_READONLY); | 1139 | IRIns *irs = IR(tref_ref(str)); |
1140 | TRef tr = (irs->o == IR_TOSTR && irs->op2 == IRTOSTR_CHAR) ? | ||
1141 | irs->op1 : | ||
1142 | emitir(IRT(IR_XLOAD, IRT_U8), buf, IRXLOAD_READONLY); | ||
837 | tr = lj_ir_call(J, IRCALL_fputc, tr, fp); | 1143 | tr = lj_ir_call(J, IRCALL_fputc, tr, fp); |
838 | if (results_wanted(J) != 0) /* Check result only if not ignored. */ | 1144 | if (results_wanted(J) != 0) /* Check result only if not ignored. */ |
839 | emitir(IRTGI(IR_NE), tr, lj_ir_kint(J, -1)); | 1145 | emitir(IRTGI(IR_NE), tr, lj_ir_kint(J, -1)); |
@@ -855,6 +1161,28 @@ static void LJ_FASTCALL recff_io_flush(jit_State *J, RecordFFData *rd) | |||
855 | J->base[0] = TREF_TRUE; | 1161 | J->base[0] = TREF_TRUE; |
856 | } | 1162 | } |
857 | 1163 | ||
1164 | /* -- Debug library fast functions ---------------------------------------- */ | ||
1165 | |||
1166 | static void LJ_FASTCALL recff_debug_getmetatable(jit_State *J, RecordFFData *rd) | ||
1167 | { | ||
1168 | GCtab *mt; | ||
1169 | TRef mtref; | ||
1170 | TRef tr = J->base[0]; | ||
1171 | if (tref_istab(tr)) { | ||
1172 | mt = tabref(tabV(&rd->argv[0])->metatable); | ||
1173 | mtref = emitir(IRT(IR_FLOAD, IRT_TAB), tr, IRFL_TAB_META); | ||
1174 | } else if (tref_isudata(tr)) { | ||
1175 | mt = tabref(udataV(&rd->argv[0])->metatable); | ||
1176 | mtref = emitir(IRT(IR_FLOAD, IRT_TAB), tr, IRFL_UDATA_META); | ||
1177 | } else { | ||
1178 | mt = tabref(basemt_obj(J2G(J), &rd->argv[0])); | ||
1179 | J->base[0] = mt ? lj_ir_ktab(J, mt) : TREF_NIL; | ||
1180 | return; | ||
1181 | } | ||
1182 | emitir(IRTG(mt ? IR_NE : IR_EQ, IRT_TAB), mtref, lj_ir_knull(J, IRT_TAB)); | ||
1183 | J->base[0] = mt ? mtref : TREF_NIL; | ||
1184 | } | ||
1185 | |||
858 | /* -- Record calls to fast functions -------------------------------------- */ | 1186 | /* -- Record calls to fast functions -------------------------------------- */ |
859 | 1187 | ||
860 | #include "lj_recdef.h" | 1188 | #include "lj_recdef.h" |