diff options
| author | Mike Pall <mike> | 2010-12-24 01:31:39 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2010-12-24 01:31:39 +0100 |
| commit | 461bf7733164c1c02f3e3001faef6eb028cd6e9e (patch) | |
| tree | a4d51e369da8906c5151cd8c43b4424ec56e1404 | |
| parent | 4850865c57996897df61f60631fa064f4adbb088 (diff) | |
| download | luajit-461bf7733164c1c02f3e3001faef6eb028cd6e9e.tar.gz luajit-461bf7733164c1c02f3e3001faef6eb028cd6e9e.tar.bz2 luajit-461bf7733164c1c02f3e3001faef6eb028cd6e9e.zip | |
FFI: Parse complex and 64 bit integer literals.
| -rw-r--r-- | src/Makefile.dep | 19 | ||||
| -rw-r--r-- | src/buildvm.c | 8 | ||||
| -rw-r--r-- | src/buildvm_ppc.dasc | 13 | ||||
| -rw-r--r-- | src/buildvm_ppcspe.h | 188 | ||||
| -rw-r--r-- | src/buildvm_x64.h | 5 | ||||
| -rw-r--r-- | src/buildvm_x64win.h | 5 | ||||
| -rw-r--r-- | src/buildvm_x86.dasc | 9 | ||||
| -rw-r--r-- | src/buildvm_x86.h | 5 | ||||
| -rw-r--r-- | src/lib_ffi.c | 3 | ||||
| -rw-r--r-- | src/lj_bc.h | 3 | ||||
| -rw-r--r-- | src/lj_cdata.h | 9 | ||||
| -rw-r--r-- | src/lj_lex.c | 95 | ||||
| -rw-r--r-- | src/lj_parse.c | 48 | ||||
| -rw-r--r-- | src/lj_parse.h | 3 |
14 files changed, 303 insertions, 110 deletions
diff --git a/src/Makefile.dep b/src/Makefile.dep index 6a5d208a..3e202537 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep | |||
| @@ -93,7 +93,8 @@ lj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ | |||
| 93 | lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \ | 93 | lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \ |
| 94 | lj_bc.h lj_traceerr.h lj_lib.h | 94 | lj_bc.h lj_traceerr.h lj_lib.h |
| 95 | lj_lex.o: lj_lex.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ | 95 | lj_lex.o: lj_lex.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ |
| 96 | lj_err.h lj_errmsg.h lj_str.h lj_lex.h lj_parse.h lj_char.h | 96 | lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_cdata.h lualib.h \ |
| 97 | lj_lex.h lj_parse.h lj_char.h | ||
| 97 | lj_lib.o: lj_lib.c lauxlib.h lua.h luaconf.h lj_obj.h lj_def.h lj_arch.h \ | 98 | lj_lib.o: lj_lib.c lauxlib.h lua.h luaconf.h lj_obj.h lj_def.h lj_arch.h \ |
| 98 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_bc.h \ | 99 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_bc.h \ |
| 99 | lj_dispatch.h lj_jit.h lj_ir.h lj_vm.h lj_lib.h | 100 | lj_dispatch.h lj_jit.h lj_ir.h lj_vm.h lj_lib.h |
| @@ -118,7 +119,7 @@ lj_opt_narrow.o: lj_opt_narrow.c lj_obj.h lua.h luaconf.h lj_def.h \ | |||
| 118 | lj_dispatch.h lj_traceerr.h | 119 | lj_dispatch.h lj_traceerr.h |
| 119 | lj_parse.o: lj_parse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 120 | lj_parse.o: lj_parse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 120 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_state.h \ | 121 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_state.h \ |
| 121 | lj_bc.h lj_lex.h lj_parse.h lj_vm.h lj_vmevent.h | 122 | lj_bc.h lj_ctype.h lj_lex.h lj_parse.h lj_vm.h lj_vmevent.h |
| 122 | lj_record.o: lj_record.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 123 | lj_record.o: lj_record.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 123 | lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ff.h \ | 124 | lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ff.h \ |
| 124 | lj_ffdef.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \ | 125 | lj_ffdef.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \ |
| @@ -151,13 +152,13 @@ ljamalg.o: ljamalg.c lua.h luaconf.h lauxlib.h lj_gc.c lj_obj.h lj_def.h \ | |||
| 151 | lj_char.c lj_char.h lj_bc.c lj_bcdef.h lj_obj.c lj_str.c lj_tab.c \ | 152 | lj_char.c lj_char.h lj_bc.c lj_bcdef.h lj_obj.c lj_str.c lj_tab.c \ |
| 152 | lj_func.c lj_udata.c lj_meta.c lj_state.c lj_lex.h lj_alloc.h \ | 153 | lj_func.c lj_udata.c lj_meta.c lj_state.c lj_lex.h lj_alloc.h \ |
| 153 | lj_dispatch.c lj_ff.h lj_ffdef.h luajit.h lj_vmevent.c lj_vmevent.h \ | 154 | lj_dispatch.c lj_ff.h lj_ffdef.h luajit.h lj_vmevent.c lj_vmevent.h \ |
| 154 | lj_api.c lj_parse.h lj_lex.c lj_parse.c lj_ctype.c lj_cdata.c lj_cconv.h \ | 155 | lj_api.c lj_parse.h lj_lex.c lualib.h lj_parse.c lj_ctype.c lj_cdata.c \ |
| 155 | lj_cconv.c lj_cparse.c lj_cparse.h lj_lib.c lj_lib.h lj_ir.c lj_iropt.h \ | 156 | lj_cconv.h lj_cconv.c lj_cparse.c lj_cparse.h lj_lib.c lj_lib.h lj_ir.c \ |
| 156 | lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c lj_opt_dce.c \ | 157 | lj_iropt.h lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c \ |
| 157 | lj_opt_loop.c lj_snap.h lj_mcode.c lj_mcode.h lj_snap.c lj_target.h \ | 158 | lj_opt_dce.c lj_opt_loop.c lj_snap.h lj_mcode.c lj_mcode.h lj_snap.c \ |
| 158 | lj_target_*.h lj_record.c lj_record.h lj_ffrecord.h lj_crecord.c \ | 159 | lj_target.h lj_target_*.h lj_record.c lj_record.h lj_ffrecord.h \ |
| 159 | lj_crecord.h lj_ffrecord.c lj_recdef.h lj_asm.c lj_asm.h lj_trace.c \ | 160 | lj_crecord.c lj_crecord.h lj_ffrecord.c lj_recdef.h lj_asm.c lj_asm.h \ |
| 160 | lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c lib_base.c lualib.h \ | 161 | lj_trace.c lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c lib_base.c \ |
| 161 | lj_libdef.h lib_math.c lib_string.c lib_table.c lib_io.c lib_os.c \ | 162 | lj_libdef.h lib_math.c lib_string.c lib_table.c lib_io.c lib_os.c \ |
| 162 | lib_package.c lib_debug.c lib_bit.c lib_jit.c lib_ffi.c lib_init.c | 163 | lib_package.c lib_debug.c lib_bit.c lib_jit.c lib_ffi.c lib_init.c |
| 163 | luajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h lj_arch.h | 164 | luajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h lj_arch.h |
diff --git a/src/buildvm.c b/src/buildvm.c index 72e612c1..1681b592 100644 --- a/src/buildvm.c +++ b/src/buildvm.c | |||
| @@ -207,10 +207,10 @@ static int build_code(BuildCtx *ctx) | |||
| 207 | int32_t ofs = dasm_getpclabel(Dst, i); | 207 | int32_t ofs = dasm_getpclabel(Dst, i); |
| 208 | if (ofs < 0) return 0x22000000|i; | 208 | if (ofs < 0) return 0x22000000|i; |
| 209 | ctx->bc_ofs[i] = ofs; | 209 | ctx->bc_ofs[i] = ofs; |
| 210 | #if !LJ_HASJIT | 210 | if ((LJ_HASJIT || |
| 211 | if (!(i == BC_JFORI || i == BC_JFORL || i == BC_JITERL || i == BC_JLOOP || | 211 | !(i == BC_JFORI || i == BC_JFORL || i == BC_JITERL || i == BC_JLOOP || |
| 212 | i == BC_IFORL || i == BC_IITERL || i == BC_ILOOP)) | 212 | i == BC_IFORL || i == BC_IITERL || i == BC_ILOOP)) && |
| 213 | #endif | 213 | (LJ_HASFFI || i != BC_KCDATA)) |
| 214 | sym_insert(ctx, ofs, LABEL_PREFIX_BC, bc_names[i]); | 214 | sym_insert(ctx, ofs, LABEL_PREFIX_BC, bc_names[i]); |
| 215 | } | 215 | } |
| 216 | 216 | ||
diff --git a/src/buildvm_ppc.dasc b/src/buildvm_ppc.dasc index 108363e5..a81335db 100644 --- a/src/buildvm_ppc.dasc +++ b/src/buildvm_ppc.dasc | |||
| @@ -2430,6 +2430,19 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
| 2430 | | evstddx TMP0, BASE, RA | 2430 | | evstddx TMP0, BASE, RA |
| 2431 | | ins_next2 | 2431 | | ins_next2 |
| 2432 | break; | 2432 | break; |
| 2433 | case BC_KCDATA: | ||
| 2434 | #if LJ_HASFFI | ||
| 2435 | | // RA = dst*8, RD = cdata_const*8 (~) | ||
| 2436 | | ins_next1 | ||
| 2437 | | srwi TMP1, RD, 1 | ||
| 2438 | | subfic TMP1, TMP1, -4 | ||
| 2439 | | lwzx TMP0, KBASE, TMP1 // KBASE-4-cdata_const*4 | ||
| 2440 | | li TMP2, LJ_TCDATA | ||
| 2441 | | evmergelo TMP0, TMP2, TMP0 | ||
| 2442 | | evstddx TMP0, BASE, RA | ||
| 2443 | | ins_next2 | ||
| 2444 | #endif | ||
| 2445 | break; | ||
| 2433 | case BC_KSHORT: | 2446 | case BC_KSHORT: |
| 2434 | | // RA = dst*8, RD = int16_literal*8 | 2447 | | // RA = dst*8, RD = int16_literal*8 |
| 2435 | | srwi TMP1, RD, 3 | 2448 | | srwi TMP1, RD, 3 |
diff --git a/src/buildvm_ppcspe.h b/src/buildvm_ppcspe.h index 0855fda8..8a10c24a 100644 --- a/src/buildvm_ppcspe.h +++ b/src/buildvm_ppcspe.h | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | #define DASM_SECTION_CODE_OP 0 | 12 | #define DASM_SECTION_CODE_OP 0 |
| 13 | #define DASM_SECTION_CODE_SUB 1 | 13 | #define DASM_SECTION_CODE_SUB 1 |
| 14 | #define DASM_MAXSECTION 2 | 14 | #define DASM_MAXSECTION 2 |
| 15 | static const unsigned int build_actionlist[4928] = { | 15 | static const unsigned int build_actionlist[4947] = { |
| 16 | 0x00010001, | 16 | 0x00010001, |
| 17 | 0x00060014, | 17 | 0x00060014, |
| 18 | 0x72000000, | 18 | 0x72000000, |
| @@ -3372,6 +3372,25 @@ static const unsigned int build_actionlist[4928] = { | |||
| 3372 | 0x7c0903a6, | 3372 | 0x7c0903a6, |
| 3373 | 0x4e800420, | 3373 | 0x4e800420, |
| 3374 | 0x00000000, | 3374 | 0x00000000, |
| 3375 | 0x80f00000, | ||
| 3376 | 0x3a100004, | ||
| 3377 | 0x5588007e, | ||
| 3378 | 0x000900ab, | ||
| 3379 | 0x2108fffc, | ||
| 3380 | 0x7c0f402e, | ||
| 3381 | 0x39200000, | ||
| 3382 | 0x00098200, | ||
| 3383 | 0x1009022d, | ||
| 3384 | 0x100ea320, | ||
| 3385 | 0x54e815ba, | ||
| 3386 | 0x54ea5d78, | ||
| 3387 | 0x54ec9b78, | ||
| 3388 | 0x7c11402e, | ||
| 3389 | 0x54f4dd78, | ||
| 3390 | 0x54eb9d78, | ||
| 3391 | 0x7c0903a6, | ||
| 3392 | 0x4e800420, | ||
| 3393 | 0x00000000, | ||
| 3375 | 0x558800fe, | 3394 | 0x558800fe, |
| 3376 | 0x000900ab, | 3395 | 0x000900ab, |
| 3377 | 0x7d080734, | 3396 | 0x7d080734, |
| @@ -5619,158 +5638,163 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
| 5619 | case BC_KSTR: | 5638 | case BC_KSTR: |
| 5620 | dasm_put(Dst, 3342, 32-1); | 5639 | dasm_put(Dst, 3342, 32-1); |
| 5621 | break; | 5640 | break; |
| 5641 | case BC_KCDATA: | ||
| 5642 | #if LJ_HASFFI | ||
| 5643 | dasm_put(Dst, 3359, 32-1, LJ_TCDATA); | ||
| 5644 | #endif | ||
| 5645 | break; | ||
| 5622 | case BC_KSHORT: | 5646 | case BC_KSHORT: |
| 5623 | dasm_put(Dst, 3359, 32-3); | 5647 | dasm_put(Dst, 3378, 32-3); |
| 5624 | break; | 5648 | break; |
| 5625 | case BC_KNUM: | 5649 | case BC_KNUM: |
| 5626 | dasm_put(Dst, 3375); | 5650 | dasm_put(Dst, 3394); |
| 5627 | break; | 5651 | break; |
| 5628 | case BC_KPRI: | 5652 | case BC_KPRI: |
| 5629 | dasm_put(Dst, 3388, 32-3); | 5653 | dasm_put(Dst, 3407, 32-3); |
| 5630 | break; | 5654 | break; |
| 5631 | case BC_KNIL: | 5655 | case BC_KNIL: |
| 5632 | dasm_put(Dst, 3403); | 5656 | dasm_put(Dst, 3422); |
| 5633 | break; | 5657 | break; |
| 5634 | 5658 | ||
| 5635 | /* -- Upvalue and function ops ------------------------------------------ */ | 5659 | /* -- Upvalue and function ops ------------------------------------------ */ |
| 5636 | 5660 | ||
| 5637 | case BC_UGET: | 5661 | case BC_UGET: |
| 5638 | dasm_put(Dst, 3422, 32-1, offsetof(GCfuncL, uvptr), DtA(->v)); | 5662 | dasm_put(Dst, 3441, 32-1, offsetof(GCfuncL, uvptr), DtA(->v)); |
| 5639 | break; | 5663 | break; |
| 5640 | case BC_USETV: | 5664 | case BC_USETV: |
| 5641 | dasm_put(Dst, 3443, 32-1, offsetof(GCfuncL, uvptr), DtA(->marked), DtA(->v), LJ_GC_BLACK, DtA(->closed), -LJ_TISNUM, LJ_TISGCV - LJ_TISNUM, Dt4(->gch.marked), LJ_GC_WHITES, GG_DISP2G); | 5665 | dasm_put(Dst, 3462, 32-1, offsetof(GCfuncL, uvptr), DtA(->marked), DtA(->v), LJ_GC_BLACK, DtA(->closed), -LJ_TISNUM, LJ_TISGCV - LJ_TISNUM, Dt4(->gch.marked), LJ_GC_WHITES, GG_DISP2G); |
| 5642 | break; | 5666 | break; |
| 5643 | case BC_USETS: | 5667 | case BC_USETS: |
| 5644 | dasm_put(Dst, 3495, 32-1, 32-1, offsetof(GCfuncL, uvptr), DtA(->marked), DtA(->v), LJ_GC_BLACK, Dt5(->marked), DtA(->closed), LJ_GC_WHITES, GG_DISP2G); | 5668 | dasm_put(Dst, 3514, 32-1, 32-1, offsetof(GCfuncL, uvptr), DtA(->marked), DtA(->v), LJ_GC_BLACK, Dt5(->marked), DtA(->closed), LJ_GC_WHITES, GG_DISP2G); |
| 5645 | break; | 5669 | break; |
| 5646 | case BC_USETN: | 5670 | case BC_USETN: |
| 5647 | dasm_put(Dst, 3544, 32-1, offsetof(GCfuncL, uvptr), DtA(->v)); | 5671 | dasm_put(Dst, 3563, 32-1, offsetof(GCfuncL, uvptr), DtA(->v)); |
| 5648 | break; | 5672 | break; |
| 5649 | case BC_USETP: | 5673 | case BC_USETP: |
| 5650 | dasm_put(Dst, 3565, 32-1, offsetof(GCfuncL, uvptr), 32-3, DtA(->v)); | 5674 | dasm_put(Dst, 3584, 32-1, offsetof(GCfuncL, uvptr), 32-3, DtA(->v)); |
| 5651 | break; | 5675 | break; |
| 5652 | 5676 | ||
| 5653 | case BC_UCLO: | 5677 | case BC_UCLO: |
| 5654 | dasm_put(Dst, 3588, Dt1(->openupval), 32-1, -(BCBIAS_J*4 >> 16), Dt1(->base), Dt1(->base)); | 5678 | dasm_put(Dst, 3607, Dt1(->openupval), 32-1, -(BCBIAS_J*4 >> 16), Dt1(->base), Dt1(->base)); |
| 5655 | break; | 5679 | break; |
| 5656 | 5680 | ||
| 5657 | case BC_FNEW: | 5681 | case BC_FNEW: |
| 5658 | dasm_put(Dst, 3618, 32-1, Dt1(->base), Dt1(->base)); | 5682 | dasm_put(Dst, 3637, 32-1, Dt1(->base), Dt1(->base)); |
| 5659 | break; | 5683 | break; |
| 5660 | 5684 | ||
| 5661 | /* -- Table ops --------------------------------------------------------- */ | 5685 | /* -- Table ops --------------------------------------------------------- */ |
| 5662 | 5686 | ||
| 5663 | case BC_TNEW: | 5687 | case BC_TNEW: |
| 5664 | case BC_TDUP: | 5688 | case BC_TDUP: |
| 5665 | dasm_put(Dst, 3644, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), Dt1(->base)); | 5689 | dasm_put(Dst, 3663, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), Dt1(->base)); |
| 5666 | if (op == BC_TNEW) { | 5690 | if (op == BC_TNEW) { |
| 5667 | dasm_put(Dst, 3657); | 5691 | dasm_put(Dst, 3676); |
| 5668 | } else { | 5692 | } else { |
| 5669 | dasm_put(Dst, 3665, 32-1); | 5693 | dasm_put(Dst, 3684, 32-1); |
| 5670 | } | 5694 | } |
| 5671 | dasm_put(Dst, 3672, Dt1(->base)); | 5695 | dasm_put(Dst, 3691, Dt1(->base)); |
| 5672 | break; | 5696 | break; |
| 5673 | 5697 | ||
| 5674 | case BC_GGET: | 5698 | case BC_GGET: |
| 5675 | case BC_GSET: | 5699 | case BC_GSET: |
| 5676 | dasm_put(Dst, 3695, 32-1, Dt7(->env)); | 5700 | dasm_put(Dst, 3714, 32-1, Dt7(->env)); |
| 5677 | if (op == BC_GGET) { | 5701 | if (op == BC_GGET) { |
| 5678 | dasm_put(Dst, 3703); | 5702 | dasm_put(Dst, 3722); |
| 5679 | } else { | 5703 | } else { |
| 5680 | dasm_put(Dst, 3706); | 5704 | dasm_put(Dst, 3725); |
| 5681 | } | 5705 | } |
| 5682 | break; | 5706 | break; |
| 5683 | 5707 | ||
| 5684 | case BC_TGETV: | 5708 | case BC_TGETV: |
| 5685 | dasm_put(Dst, 3709, Dt6(->asize), Dt6(->array), 31-3, Dt6(->metatable), Dt6(->nomm), 1<<MM_index); | 5709 | dasm_put(Dst, 3728, Dt6(->asize), Dt6(->array), 31-3, Dt6(->metatable), Dt6(->nomm), 1<<MM_index); |
| 5686 | break; | 5710 | break; |
| 5687 | case BC_TGETS: | 5711 | case BC_TGETS: |
| 5688 | dasm_put(Dst, 3767, 32-1, Dt6(->hmask), Dt5(->hash), Dt6(->node), 31-5, 31-3, DtB(->key), DtB(->val), DtB(->next), Dt6(->metatable), Dt6(->nomm), 1<<MM_index); | 5712 | dasm_put(Dst, 3786, 32-1, Dt6(->hmask), Dt5(->hash), Dt6(->node), 31-5, 31-3, DtB(->key), DtB(->val), DtB(->next), Dt6(->metatable), Dt6(->nomm), 1<<MM_index); |
| 5689 | dasm_put(Dst, 3831); | 5713 | dasm_put(Dst, 3850); |
| 5690 | break; | 5714 | break; |
| 5691 | case BC_TGETB: | 5715 | case BC_TGETB: |
| 5692 | dasm_put(Dst, 3836, 32-3, Dt6(->asize), Dt6(->array), Dt6(->metatable), Dt6(->nomm), 1<<MM_index); | 5716 | dasm_put(Dst, 3855, 32-3, Dt6(->asize), Dt6(->array), Dt6(->metatable), Dt6(->nomm), 1<<MM_index); |
| 5693 | break; | 5717 | break; |
| 5694 | 5718 | ||
| 5695 | case BC_TSETV: | 5719 | case BC_TSETV: |
| 5696 | dasm_put(Dst, 3880, Dt6(->asize), Dt6(->array), 31-3, Dt6(->marked), LJ_GC_BLACK, Dt6(->metatable), Dt6(->nomm), 1<<MM_newindex); | 5720 | dasm_put(Dst, 3899, Dt6(->asize), Dt6(->array), 31-3, Dt6(->marked), LJ_GC_BLACK, Dt6(->metatable), Dt6(->nomm), 1<<MM_newindex); |
| 5697 | dasm_put(Dst, 3947, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->marked), Dt6(->gclist)); | 5721 | dasm_put(Dst, 3966, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->marked), Dt6(->gclist)); |
| 5698 | break; | 5722 | break; |
| 5699 | case BC_TSETS: | 5723 | case BC_TSETS: |
| 5700 | dasm_put(Dst, 3959, 32-1, Dt6(->hmask), Dt5(->hash), Dt6(->node), Dt6(->nomm), 31-5, 31-3, Dt6(->marked), DtB(->key), DtB(->val), LJ_GC_BLACK, DtB(->val), Dt6(->metatable)); | 5724 | dasm_put(Dst, 3978, 32-1, Dt6(->hmask), Dt5(->hash), Dt6(->node), Dt6(->nomm), 31-5, 31-3, Dt6(->marked), DtB(->key), DtB(->val), LJ_GC_BLACK, DtB(->val), Dt6(->metatable)); |
| 5701 | dasm_put(Dst, 4020, Dt6(->nomm), 1<<MM_newindex, DtB(->next), Dt6(->metatable), DISPATCH_GL(tmptv), Dt1(->base), Dt6(->nomm), 1<<MM_newindex, Dt1(->base), DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain)); | 5725 | dasm_put(Dst, 4039, Dt6(->nomm), 1<<MM_newindex, DtB(->next), Dt6(->metatable), DISPATCH_GL(tmptv), Dt1(->base), Dt6(->nomm), 1<<MM_newindex, Dt1(->base), DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain)); |
| 5702 | dasm_put(Dst, 4071, Dt6(->marked), Dt6(->gclist)); | 5726 | dasm_put(Dst, 4090, Dt6(->marked), Dt6(->gclist)); |
| 5703 | break; | 5727 | break; |
| 5704 | case BC_TSETB: | 5728 | case BC_TSETB: |
| 5705 | dasm_put(Dst, 4078, 32-3, Dt6(->asize), Dt6(->array), Dt6(->marked), LJ_GC_BLACK, Dt6(->metatable), Dt6(->nomm), 1<<MM_newindex, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->marked)); | 5729 | dasm_put(Dst, 4097, 32-3, Dt6(->asize), Dt6(->array), Dt6(->marked), LJ_GC_BLACK, Dt6(->metatable), Dt6(->nomm), 1<<MM_newindex, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->marked)); |
| 5706 | dasm_put(Dst, 4138, Dt6(->gclist)); | 5730 | dasm_put(Dst, 4157, Dt6(->gclist)); |
| 5707 | break; | 5731 | break; |
| 5708 | 5732 | ||
| 5709 | case BC_TSETM: | 5733 | case BC_TSETM: |
| 5710 | dasm_put(Dst, 4143, 32-3, Dt6(->asize), 31-3, Dt6(->marked), Dt6(->array), LJ_GC_BLACK, Dt1(->base), DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->marked), Dt6(->gclist)); | 5734 | dasm_put(Dst, 4162, 32-3, Dt6(->asize), 31-3, Dt6(->marked), Dt6(->array), LJ_GC_BLACK, Dt1(->base), DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->marked), Dt6(->gclist)); |
| 5711 | dasm_put(Dst, 4212); | 5735 | dasm_put(Dst, 4231); |
| 5712 | break; | 5736 | break; |
| 5713 | 5737 | ||
| 5714 | /* -- Calls and vararg handling ----------------------------------------- */ | 5738 | /* -- Calls and vararg handling ----------------------------------------- */ |
| 5715 | 5739 | ||
| 5716 | case BC_CALLM: | 5740 | case BC_CALLM: |
| 5717 | dasm_put(Dst, 4215); | 5741 | dasm_put(Dst, 4234); |
| 5718 | break; | 5742 | break; |
| 5719 | case BC_CALL: | 5743 | case BC_CALL: |
| 5720 | dasm_put(Dst, 4217, Dt7(->pc)); | 5744 | dasm_put(Dst, 4236, Dt7(->pc)); |
| 5721 | break; | 5745 | break; |
| 5722 | 5746 | ||
| 5723 | case BC_CALLMT: | 5747 | case BC_CALLMT: |
| 5724 | dasm_put(Dst, 4237); | 5748 | dasm_put(Dst, 4256); |
| 5725 | break; | 5749 | break; |
| 5726 | case BC_CALLT: | 5750 | case BC_CALLT: |
| 5727 | dasm_put(Dst, 4239, FRAME_TYPE, Dt7(->ffid), FRAME_VARG, Dt7(->pc), -4-8, Dt7(->pc), PC2PROTO(k), FRAME_TYPEP); | 5751 | dasm_put(Dst, 4258, FRAME_TYPE, Dt7(->ffid), FRAME_VARG, Dt7(->pc), -4-8, Dt7(->pc), PC2PROTO(k), FRAME_TYPEP); |
| 5728 | dasm_put(Dst, 4304, FRAME_TYPE); | 5752 | dasm_put(Dst, 4323, FRAME_TYPE); |
| 5729 | break; | 5753 | break; |
| 5730 | 5754 | ||
| 5731 | case BC_ITERC: | 5755 | case BC_ITERC: |
| 5732 | dasm_put(Dst, 4311, Dt7(->pc)); | 5756 | dasm_put(Dst, 4330, Dt7(->pc)); |
| 5733 | break; | 5757 | break; |
| 5734 | 5758 | ||
| 5735 | case BC_ITERN: | 5759 | case BC_ITERN: |
| 5736 | #if LJ_HASJIT | 5760 | #if LJ_HASJIT |
| 5737 | #endif | 5761 | #endif |
| 5738 | dasm_put(Dst, 4337, Dt6(->asize), Dt6(->array), 31-3, -(BCBIAS_J*4 >> 16), Dt6(->hmask), Dt6(->node), 31-5, 31-3, DtB(->key), -(BCBIAS_J*4 >> 16)); | 5762 | dasm_put(Dst, 4356, Dt6(->asize), Dt6(->array), 31-3, -(BCBIAS_J*4 >> 16), Dt6(->hmask), Dt6(->node), 31-5, 31-3, DtB(->key), -(BCBIAS_J*4 >> 16)); |
| 5739 | dasm_put(Dst, 4416); | 5763 | dasm_put(Dst, 4435); |
| 5740 | break; | 5764 | break; |
| 5741 | 5765 | ||
| 5742 | case BC_ISNEXT: | 5766 | case BC_ISNEXT: |
| 5743 | dasm_put(Dst, 4420, LJ_TTAB, LJ_TFUNC, LJ_TNIL, Dt8(->ffid), FF_next_N, 32-1, -(BCBIAS_J*4 >> 16), BC_JMP, BC_ITERC, -(BCBIAS_J*4 >> 16)); | 5767 | dasm_put(Dst, 4439, LJ_TTAB, LJ_TFUNC, LJ_TNIL, Dt8(->ffid), FF_next_N, 32-1, -(BCBIAS_J*4 >> 16), BC_JMP, BC_ITERC, -(BCBIAS_J*4 >> 16)); |
| 5744 | break; | 5768 | break; |
| 5745 | 5769 | ||
| 5746 | case BC_VARG: | 5770 | case BC_VARG: |
| 5747 | dasm_put(Dst, 4471, FRAME_VARG, Dt1(->maxstack), Dt1(->top), Dt1(->base), 32-3, Dt1(->base)); | 5771 | dasm_put(Dst, 4490, FRAME_VARG, Dt1(->maxstack), Dt1(->top), Dt1(->base), 32-3, Dt1(->base)); |
| 5748 | dasm_put(Dst, 4551); | 5772 | dasm_put(Dst, 4570); |
| 5749 | break; | 5773 | break; |
| 5750 | 5774 | ||
| 5751 | /* -- Returns ----------------------------------------------------------- */ | 5775 | /* -- Returns ----------------------------------------------------------- */ |
| 5752 | 5776 | ||
| 5753 | case BC_RETM: | 5777 | case BC_RETM: |
| 5754 | dasm_put(Dst, 4557); | 5778 | dasm_put(Dst, 4576); |
| 5755 | break; | 5779 | break; |
| 5756 | 5780 | ||
| 5757 | case BC_RET: | 5781 | case BC_RET: |
| 5758 | dasm_put(Dst, 4559, FRAME_TYPE, FRAME_VARG, Dt7(->pc), PC2PROTO(k), FRAME_TYPEP); | 5782 | dasm_put(Dst, 4578, FRAME_TYPE, FRAME_VARG, Dt7(->pc), PC2PROTO(k), FRAME_TYPEP); |
| 5759 | break; | 5783 | break; |
| 5760 | 5784 | ||
| 5761 | case BC_RET0: case BC_RET1: | 5785 | case BC_RET0: case BC_RET1: |
| 5762 | dasm_put(Dst, 4629, FRAME_TYPE, FRAME_VARG); | 5786 | dasm_put(Dst, 4648, FRAME_TYPE, FRAME_VARG); |
| 5763 | if (op == BC_RET1) { | 5787 | if (op == BC_RET1) { |
| 5764 | dasm_put(Dst, 4642); | 5788 | dasm_put(Dst, 4661); |
| 5765 | } | 5789 | } |
| 5766 | dasm_put(Dst, 4645, Dt7(->pc), PC2PROTO(k)); | 5790 | dasm_put(Dst, 4664, Dt7(->pc), PC2PROTO(k)); |
| 5767 | break; | 5791 | break; |
| 5768 | 5792 | ||
| 5769 | /* -- Loops and branches ------------------------------------------------ */ | 5793 | /* -- Loops and branches ------------------------------------------------ */ |
| 5770 | 5794 | ||
| 5771 | case BC_FORL: | 5795 | case BC_FORL: |
| 5772 | #if LJ_HASJIT | 5796 | #if LJ_HASJIT |
| 5773 | dasm_put(Dst, 4673); | 5797 | dasm_put(Dst, 4692); |
| 5774 | #endif | 5798 | #endif |
| 5775 | break; | 5799 | break; |
| 5776 | 5800 | ||
| @@ -5782,35 +5806,35 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
| 5782 | case BC_FORI: | 5806 | case BC_FORI: |
| 5783 | case BC_IFORL: | 5807 | case BC_IFORL: |
| 5784 | vk = (op == BC_IFORL || op == BC_JFORL); | 5808 | vk = (op == BC_IFORL || op == BC_JFORL); |
| 5785 | dasm_put(Dst, 4675, FORL_IDX*8, FORL_STEP*8, FORL_STOP*8); | 5809 | dasm_put(Dst, 4694, FORL_IDX*8, FORL_STEP*8, FORL_STOP*8); |
| 5786 | if (!vk) { | 5810 | if (!vk) { |
| 5787 | dasm_put(Dst, 4683); | 5811 | dasm_put(Dst, 4702); |
| 5788 | } | 5812 | } |
| 5789 | if (vk) { | 5813 | if (vk) { |
| 5790 | dasm_put(Dst, 4691, FORL_IDX*8); | 5814 | dasm_put(Dst, 4710, FORL_IDX*8); |
| 5791 | } | 5815 | } |
| 5792 | dasm_put(Dst, 4695, FORL_EXT*8); | 5816 | dasm_put(Dst, 4714, FORL_EXT*8); |
| 5793 | if (op != BC_JFORL) { | 5817 | if (op != BC_JFORL) { |
| 5794 | dasm_put(Dst, 4703, 32-1); | 5818 | dasm_put(Dst, 4722, 32-1); |
| 5795 | if (op == BC_JFORI) { | 5819 | if (op == BC_JFORI) { |
| 5796 | dasm_put(Dst, 4707, -(BCBIAS_J*4 >> 16)); | 5820 | dasm_put(Dst, 4726, -(BCBIAS_J*4 >> 16)); |
| 5797 | } else { | 5821 | } else { |
| 5798 | dasm_put(Dst, 4710, -(BCBIAS_J*4 >> 16)); | 5822 | dasm_put(Dst, 4729, -(BCBIAS_J*4 >> 16)); |
| 5799 | } | 5823 | } |
| 5800 | } | 5824 | } |
| 5801 | if (op == BC_FORI) { | 5825 | if (op == BC_FORI) { |
| 5802 | dasm_put(Dst, 4713); | 5826 | dasm_put(Dst, 4732); |
| 5803 | } else if (op == BC_IFORL) { | 5827 | } else if (op == BC_IFORL) { |
| 5804 | dasm_put(Dst, 4715); | 5828 | dasm_put(Dst, 4734); |
| 5805 | } else { | 5829 | } else { |
| 5806 | dasm_put(Dst, 4717, BC_JLOOP); | 5830 | dasm_put(Dst, 4736, BC_JLOOP); |
| 5807 | } | 5831 | } |
| 5808 | dasm_put(Dst, 4720); | 5832 | dasm_put(Dst, 4739); |
| 5809 | break; | 5833 | break; |
| 5810 | 5834 | ||
| 5811 | case BC_ITERL: | 5835 | case BC_ITERL: |
| 5812 | #if LJ_HASJIT | 5836 | #if LJ_HASJIT |
| 5813 | dasm_put(Dst, 4735); | 5837 | dasm_put(Dst, 4754); |
| 5814 | #endif | 5838 | #endif |
| 5815 | break; | 5839 | break; |
| 5816 | 5840 | ||
| @@ -5819,40 +5843,40 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
| 5819 | break; | 5843 | break; |
| 5820 | #endif | 5844 | #endif |
| 5821 | case BC_IITERL: | 5845 | case BC_IITERL: |
| 5822 | dasm_put(Dst, 4737); | 5846 | dasm_put(Dst, 4756); |
| 5823 | if (op == BC_JITERL) { | 5847 | if (op == BC_JITERL) { |
| 5824 | dasm_put(Dst, 4743); | 5848 | dasm_put(Dst, 4762); |
| 5825 | } else { | 5849 | } else { |
| 5826 | dasm_put(Dst, 4745, 32-1, -(BCBIAS_J*4 >> 16)); | 5850 | dasm_put(Dst, 4764, 32-1, -(BCBIAS_J*4 >> 16)); |
| 5827 | } | 5851 | } |
| 5828 | dasm_put(Dst, 4752); | 5852 | dasm_put(Dst, 4771); |
| 5829 | break; | 5853 | break; |
| 5830 | 5854 | ||
| 5831 | case BC_LOOP: | 5855 | case BC_LOOP: |
| 5832 | #if LJ_HASJIT | 5856 | #if LJ_HASJIT |
| 5833 | dasm_put(Dst, 4764); | 5857 | dasm_put(Dst, 4783); |
| 5834 | #endif | 5858 | #endif |
| 5835 | break; | 5859 | break; |
| 5836 | 5860 | ||
| 5837 | case BC_ILOOP: | 5861 | case BC_ILOOP: |
| 5838 | dasm_put(Dst, 4766); | 5862 | dasm_put(Dst, 4785); |
| 5839 | break; | 5863 | break; |
| 5840 | 5864 | ||
| 5841 | case BC_JLOOP: | 5865 | case BC_JLOOP: |
| 5842 | #if LJ_HASJIT | 5866 | #if LJ_HASJIT |
| 5843 | dasm_put(Dst, 4777); | 5867 | dasm_put(Dst, 4796); |
| 5844 | #endif | 5868 | #endif |
| 5845 | break; | 5869 | break; |
| 5846 | 5870 | ||
| 5847 | case BC_JMP: | 5871 | case BC_JMP: |
| 5848 | dasm_put(Dst, 4779, 32-1, -(BCBIAS_J*4 >> 16)); | 5872 | dasm_put(Dst, 4798, 32-1, -(BCBIAS_J*4 >> 16)); |
| 5849 | break; | 5873 | break; |
| 5850 | 5874 | ||
| 5851 | /* -- Function headers -------------------------------------------------- */ | 5875 | /* -- Function headers -------------------------------------------------- */ |
| 5852 | 5876 | ||
| 5853 | case BC_FUNCF: | 5877 | case BC_FUNCF: |
| 5854 | #if LJ_HASJIT | 5878 | #if LJ_HASJIT |
| 5855 | dasm_put(Dst, 4795); | 5879 | dasm_put(Dst, 4814); |
| 5856 | #endif | 5880 | #endif |
| 5857 | case BC_FUNCV: /* NYI: compiled vararg functions. */ | 5881 | case BC_FUNCV: /* NYI: compiled vararg functions. */ |
| 5858 | break; | 5882 | break; |
| @@ -5862,38 +5886,38 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
| 5862 | break; | 5886 | break; |
| 5863 | #endif | 5887 | #endif |
| 5864 | case BC_IFUNCF: | 5888 | case BC_IFUNCF: |
| 5865 | dasm_put(Dst, 4797, Dt1(->maxstack), -4+PC2PROTO(numparams), -4+PC2PROTO(k), 31-3); | 5889 | dasm_put(Dst, 4816, Dt1(->maxstack), -4+PC2PROTO(numparams), -4+PC2PROTO(k), 31-3); |
| 5866 | if (op == BC_JFUNCF) { | 5890 | if (op == BC_JFUNCF) { |
| 5867 | dasm_put(Dst, 4815); | 5891 | dasm_put(Dst, 4834); |
| 5868 | } else { | 5892 | } else { |
| 5869 | dasm_put(Dst, 4817); | 5893 | dasm_put(Dst, 4836); |
| 5870 | } | 5894 | } |
| 5871 | dasm_put(Dst, 4826); | 5895 | dasm_put(Dst, 4845); |
| 5872 | break; | 5896 | break; |
| 5873 | 5897 | ||
| 5874 | case BC_JFUNCV: | 5898 | case BC_JFUNCV: |
| 5875 | #if !LJ_HASJIT | 5899 | #if !LJ_HASJIT |
| 5876 | break; | 5900 | break; |
| 5877 | #endif | 5901 | #endif |
| 5878 | dasm_put(Dst, 4832); | 5902 | dasm_put(Dst, 4851); |
| 5879 | break; /* NYI: compiled vararg functions. */ | 5903 | break; /* NYI: compiled vararg functions. */ |
| 5880 | 5904 | ||
| 5881 | case BC_IFUNCV: | 5905 | case BC_IFUNCV: |
| 5882 | dasm_put(Dst, 4834, Dt1(->maxstack), 8+FRAME_VARG, -4+PC2PROTO(k), -4+PC2PROTO(numparams)); | 5906 | dasm_put(Dst, 4853, Dt1(->maxstack), 8+FRAME_VARG, -4+PC2PROTO(k), -4+PC2PROTO(numparams)); |
| 5883 | break; | 5907 | break; |
| 5884 | 5908 | ||
| 5885 | case BC_FUNCC: | 5909 | case BC_FUNCC: |
| 5886 | case BC_FUNCCW: | 5910 | case BC_FUNCCW: |
| 5887 | if (op == BC_FUNCC) { | 5911 | if (op == BC_FUNCC) { |
| 5888 | dasm_put(Dst, 4884, Dt8(->f)); | 5912 | dasm_put(Dst, 4903, Dt8(->f)); |
| 5889 | } else { | 5913 | } else { |
| 5890 | dasm_put(Dst, 4887, DISPATCH_GL(wrapf)); | 5914 | dasm_put(Dst, 4906, DISPATCH_GL(wrapf)); |
| 5891 | } | 5915 | } |
| 5892 | dasm_put(Dst, 4890, Dt1(->maxstack), Dt1(->base), Dt1(->top), ~LJ_VMST_C); | 5916 | dasm_put(Dst, 4909, Dt1(->maxstack), Dt1(->base), Dt1(->top), ~LJ_VMST_C); |
| 5893 | if (op == BC_FUNCCW) { | 5917 | if (op == BC_FUNCCW) { |
| 5894 | dasm_put(Dst, 4903, Dt8(->f)); | 5918 | dasm_put(Dst, 4922, Dt8(->f)); |
| 5895 | } | 5919 | } |
| 5896 | dasm_put(Dst, 4906, DISPATCH_GL(vmstate), Dt1(->top), 31-3, Dt1(->base), ~LJ_VMST_INTERP, DISPATCH_GL(vmstate)); | 5920 | dasm_put(Dst, 4925, DISPATCH_GL(vmstate), Dt1(->top), 31-3, Dt1(->base), ~LJ_VMST_INTERP, DISPATCH_GL(vmstate)); |
| 5897 | break; | 5921 | break; |
| 5898 | 5922 | ||
| 5899 | /* ---------------------------------------------------------------------- */ | 5923 | /* ---------------------------------------------------------------------- */ |
| @@ -5913,7 +5937,7 @@ static int build_backend(BuildCtx *ctx) | |||
| 5913 | 5937 | ||
| 5914 | build_subroutines(ctx); | 5938 | build_subroutines(ctx); |
| 5915 | 5939 | ||
| 5916 | dasm_put(Dst, 4927); | 5940 | dasm_put(Dst, 4946); |
| 5917 | for (op = 0; op < BC__MAX; op++) | 5941 | for (op = 0; op < BC__MAX; op++) |
| 5918 | build_ins(ctx, (BCOp)op, op); | 5942 | build_ins(ctx, (BCOp)op, op); |
| 5919 | 5943 | ||
diff --git a/src/buildvm_x64.h b/src/buildvm_x64.h index c40abbd8..73cbbb6d 100644 --- a/src/buildvm_x64.h +++ b/src/buildvm_x64.h | |||
| @@ -1862,6 +1862,11 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse) | |||
| 1862 | case BC_KSTR: | 1862 | case BC_KSTR: |
| 1863 | dasm_put(Dst, 10553, LJ_TSTR); | 1863 | dasm_put(Dst, 10553, LJ_TSTR); |
| 1864 | break; | 1864 | break; |
| 1865 | case BC_KCDATA: | ||
| 1866 | #if LJ_HASFFI | ||
| 1867 | dasm_put(Dst, 10553, LJ_TCDATA); | ||
| 1868 | #endif | ||
| 1869 | break; | ||
| 1865 | case BC_KSHORT: | 1870 | case BC_KSHORT: |
| 1866 | if (sse) { | 1871 | if (sse) { |
| 1867 | dasm_put(Dst, 10590); | 1872 | dasm_put(Dst, 10590); |
diff --git a/src/buildvm_x64win.h b/src/buildvm_x64win.h index e855ca8b..94dbe50f 100644 --- a/src/buildvm_x64win.h +++ b/src/buildvm_x64win.h | |||
| @@ -1863,6 +1863,11 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse) | |||
| 1863 | case BC_KSTR: | 1863 | case BC_KSTR: |
| 1864 | dasm_put(Dst, 10534, LJ_TSTR); | 1864 | dasm_put(Dst, 10534, LJ_TSTR); |
| 1865 | break; | 1865 | break; |
| 1866 | case BC_KCDATA: | ||
| 1867 | #if LJ_HASFFI | ||
| 1868 | dasm_put(Dst, 10534, LJ_TCDATA); | ||
| 1869 | #endif | ||
| 1870 | break; | ||
| 1866 | case BC_KSHORT: | 1871 | case BC_KSHORT: |
| 1867 | if (sse) { | 1872 | if (sse) { |
| 1868 | dasm_put(Dst, 10569); | 1873 | dasm_put(Dst, 10569); |
diff --git a/src/buildvm_x86.dasc b/src/buildvm_x86.dasc index 0bd8f304..b4f34782 100644 --- a/src/buildvm_x86.dasc +++ b/src/buildvm_x86.dasc | |||
| @@ -3795,6 +3795,15 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse) | |||
| 3795 | | mov [BASE+RA*8], RD | 3795 | | mov [BASE+RA*8], RD |
| 3796 | | ins_next | 3796 | | ins_next |
| 3797 | break; | 3797 | break; |
| 3798 | case BC_KCDATA: | ||
| 3799 | #if LJ_HASFFI | ||
| 3800 | | ins_AND // RA = dst, RD = cdata const (~) | ||
| 3801 | | mov RD, [KBASE+RD*4] | ||
| 3802 | | mov dword [BASE+RA*8+4], LJ_TCDATA | ||
| 3803 | | mov [BASE+RA*8], RD | ||
| 3804 | | ins_next | ||
| 3805 | #endif | ||
| 3806 | break; | ||
| 3798 | case BC_KSHORT: | 3807 | case BC_KSHORT: |
| 3799 | | ins_AD // RA = dst, RD = signed int16 literal | 3808 | | ins_AD // RA = dst, RD = signed int16 literal |
| 3800 | if (sse) { | 3809 | if (sse) { |
diff --git a/src/buildvm_x86.h b/src/buildvm_x86.h index 25e4cc8e..555fe67a 100644 --- a/src/buildvm_x86.h +++ b/src/buildvm_x86.h | |||
| @@ -1982,6 +1982,11 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse) | |||
| 1982 | case BC_KSTR: | 1982 | case BC_KSTR: |
| 1983 | dasm_put(Dst, 11907, LJ_TSTR); | 1983 | dasm_put(Dst, 11907, LJ_TSTR); |
| 1984 | break; | 1984 | break; |
| 1985 | case BC_KCDATA: | ||
| 1986 | #if LJ_HASFFI | ||
| 1987 | dasm_put(Dst, 11907, LJ_TCDATA); | ||
| 1988 | #endif | ||
| 1989 | break; | ||
| 1985 | case BC_KSHORT: | 1990 | case BC_KSHORT: |
| 1986 | if (sse) { | 1991 | if (sse) { |
| 1987 | dasm_put(Dst, 11940); | 1992 | dasm_put(Dst, 11940); |
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index ed73a5fe..3ea19dd5 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
| @@ -474,7 +474,8 @@ LUALIB_API int luaopen_ffi(lua_State *L) | |||
| 474 | lj_ctype_init(L); | 474 | lj_ctype_init(L); |
| 475 | LJ_LIB_REG_(L, NULL, ffi_meta); | 475 | LJ_LIB_REG_(L, NULL, ffi_meta); |
| 476 | /* NOBARRIER: basemt is a GC root. */ | 476 | /* NOBARRIER: basemt is a GC root. */ |
| 477 | setgcref(basemt_it(G(L), LJ_TCDATA), obj2gco(tabV(L->top-1))); | 477 | L->top--; |
| 478 | setgcref(basemt_it(G(L), LJ_TCDATA), obj2gco(tabV(L->top))); | ||
| 478 | lua_pushliteral(L, LJ_OS_NAME); | 479 | lua_pushliteral(L, LJ_OS_NAME); |
| 479 | lua_pushliteral(L, LJ_ARCH_NAME); | 480 | lua_pushliteral(L, LJ_ARCH_NAME); |
| 480 | LJ_LIB_REG_(L, NULL, ffi); /* Note: no global "ffi" created! */ | 481 | LJ_LIB_REG_(L, NULL, ffi); /* Note: no global "ffi" created! */ |
diff --git a/src/lj_bc.h b/src/lj_bc.h index 837316d5..101e2c15 100644 --- a/src/lj_bc.h +++ b/src/lj_bc.h | |||
| @@ -121,6 +121,7 @@ | |||
| 121 | \ | 121 | \ |
| 122 | /* Constant ops. */ \ | 122 | /* Constant ops. */ \ |
| 123 | _(KSTR, dst, ___, str, ___) \ | 123 | _(KSTR, dst, ___, str, ___) \ |
| 124 | _(KCDATA, dst, ___, cdata, ___) \ | ||
| 124 | _(KSHORT, dst, ___, lits, ___) \ | 125 | _(KSHORT, dst, ___, lits, ___) \ |
| 125 | _(KNUM, dst, ___, num, ___) \ | 126 | _(KNUM, dst, ___, num, ___) \ |
| 126 | _(KPRI, dst, ___, pri, ___) \ | 127 | _(KPRI, dst, ___, pri, ___) \ |
| @@ -234,7 +235,7 @@ enum { | |||
| 234 | /* Bytecode operand modes. ORDER BCMode */ | 235 | /* Bytecode operand modes. ORDER BCMode */ |
| 235 | typedef enum { | 236 | typedef enum { |
| 236 | BCMnone, BCMdst, BCMbase, BCMvar, BCMrbase, BCMuv, /* Mode A must be <= 7 */ | 237 | BCMnone, BCMdst, BCMbase, BCMvar, BCMrbase, BCMuv, /* Mode A must be <= 7 */ |
| 237 | BCMlit, BCMlits, BCMpri, BCMnum, BCMstr, BCMtab, BCMfunc, BCMjump, | 238 | BCMlit, BCMlits, BCMpri, BCMnum, BCMstr, BCMtab, BCMfunc, BCMjump, BCMcdata, |
| 238 | BCM_max | 239 | BCM_max |
| 239 | } BCMode; | 240 | } BCMode; |
| 240 | #define BCM___ BCMnone | 241 | #define BCM___ BCMnone |
diff --git a/src/lj_cdata.h b/src/lj_cdata.h index 38b6ce16..27b0bf15 100644 --- a/src/lj_cdata.h +++ b/src/lj_cdata.h | |||
| @@ -45,6 +45,15 @@ static LJ_AINLINE GCcdata *lj_cdata_new(CTState *cts, CTypeID id, CTSize sz) | |||
| 45 | return cd; | 45 | return cd; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | /* Variant which works without a valid CTState. */ | ||
| 49 | static LJ_AINLINE GCcdata *lj_cdata_new_(lua_State *L, CTypeID id, CTSize sz) | ||
| 50 | { | ||
| 51 | GCcdata *cd = (GCcdata *)lj_mem_newgco(L, sizeof(GCcdata) + sz); | ||
| 52 | cd->gct = ~LJ_TCDATA; | ||
| 53 | cd->typeid = id; | ||
| 54 | return cd; | ||
| 55 | } | ||
| 56 | |||
| 48 | LJ_FUNC GCcdata *lj_cdata_newref(CTState *cts, const void *pp, CTypeID id); | 57 | LJ_FUNC GCcdata *lj_cdata_newref(CTState *cts, const void *pp, CTypeID id); |
| 49 | LJ_FUNC GCcdata *lj_cdata_newv(CTState *cts, CTypeID id, CTSize sz, | 58 | LJ_FUNC GCcdata *lj_cdata_newv(CTState *cts, CTypeID id, CTSize sz, |
| 50 | CTSize align); | 59 | CTSize align); |
diff --git a/src/lj_lex.c b/src/lj_lex.c index a115b79a..01e5ce57 100644 --- a/src/lj_lex.c +++ b/src/lj_lex.c | |||
| @@ -13,6 +13,12 @@ | |||
| 13 | #include "lj_gc.h" | 13 | #include "lj_gc.h" |
| 14 | #include "lj_err.h" | 14 | #include "lj_err.h" |
| 15 | #include "lj_str.h" | 15 | #include "lj_str.h" |
| 16 | #if LJ_HASFFI | ||
| 17 | #include "lj_tab.h" | ||
| 18 | #include "lj_ctype.h" | ||
| 19 | #include "lj_cdata.h" | ||
| 20 | #include "lualib.h" | ||
| 21 | #endif | ||
| 16 | #include "lj_lex.h" | 22 | #include "lj_lex.h" |
| 17 | #include "lj_parse.h" | 23 | #include "lj_parse.h" |
| 18 | #include "lj_char.h" | 24 | #include "lj_char.h" |
| @@ -77,7 +83,64 @@ static void inclinenumber(LexState *ls) | |||
| 77 | 83 | ||
| 78 | /* -- Scanner for terminals ----------------------------------------------- */ | 84 | /* -- Scanner for terminals ----------------------------------------------- */ |
| 79 | 85 | ||
| 80 | static void read_numeral(LexState *ls, TValue *tv) | 86 | #if LJ_HASFFI |
| 87 | /* Load FFI library on-demand. Needed if we create cdata objects. */ | ||
| 88 | static void lex_loadffi(lua_State *L) | ||
| 89 | { | ||
| 90 | cTValue *tmp; | ||
| 91 | luaopen_ffi(L); | ||
| 92 | tmp = lj_tab_getstr(tabV(registry(L)), lj_str_newlit(L, "_LOADED")); | ||
| 93 | if (tmp && tvistab(tmp)) { | ||
| 94 | GCtab *t = tabV(tmp); | ||
| 95 | copyTV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "ffi")), L->top-1); | ||
| 96 | lj_gc_anybarriert(L, t); | ||
| 97 | } | ||
| 98 | L->top--; | ||
| 99 | } | ||
| 100 | |||
| 101 | /* Parse 64 bit integer. */ | ||
| 102 | static int lex_number64(LexState *ls, TValue *tv) | ||
| 103 | { | ||
| 104 | uint64_t n = 0; | ||
| 105 | uint8_t *p = (uint8_t *)ls->sb.buf; | ||
| 106 | CTypeID id = CTID_INT64; | ||
| 107 | GCcdata *cd; | ||
| 108 | int numl = 0; | ||
| 109 | if (p[0] == '0' && (p[1] & ~0x20) == 'X') { /* Hexadecimal. */ | ||
| 110 | p += 2; | ||
| 111 | if (!lj_char_isxdigit(*p)) return 0; | ||
| 112 | do { | ||
| 113 | n = n*16 + (*p & 15); | ||
| 114 | if (!lj_char_isdigit(*p)) n += 9; | ||
| 115 | p++; | ||
| 116 | } while (lj_char_isxdigit(*p)); | ||
| 117 | } else { /* Decimal. */ | ||
| 118 | if (!lj_char_isdigit(*p)) return 0; | ||
| 119 | do { | ||
| 120 | n = n*10 + (*p - '0'); | ||
| 121 | p++; | ||
| 122 | } while (lj_char_isdigit(*p)); | ||
| 123 | } | ||
| 124 | for (;;) { /* Parse suffixes. */ | ||
| 125 | if ((*p & ~0x20) == 'U') | ||
| 126 | id = CTID_UINT64; | ||
| 127 | else if ((*p & ~0x20) == 'L') | ||
| 128 | numl++; | ||
| 129 | else | ||
| 130 | break; | ||
| 131 | p++; | ||
| 132 | } | ||
| 133 | if (numl != 2 || *p != '\0') return 0; | ||
| 134 | /* Return cdata holding a 64 bit integer. */ | ||
| 135 | cd = lj_cdata_new_(ls->L, id, 8); | ||
| 136 | *(uint64_t *)cdataptr(cd) = n; | ||
| 137 | lj_parse_keepcdata(ls, tv, cd); | ||
| 138 | return 1; /* Ok. */ | ||
| 139 | } | ||
| 140 | #endif | ||
| 141 | |||
| 142 | /* Parse a number literal. */ | ||
| 143 | static void lex_number(LexState *ls, TValue *tv) | ||
| 81 | { | 144 | { |
| 82 | int c; | 145 | int c; |
| 83 | lua_assert(lj_char_isdigit(ls->current)); | 146 | lua_assert(lj_char_isdigit(ls->current)); |
| @@ -87,9 +150,31 @@ static void read_numeral(LexState *ls, TValue *tv) | |||
| 87 | } while (lj_char_isident(ls->current) || ls->current == '.' || | 150 | } while (lj_char_isident(ls->current) || ls->current == '.' || |
| 88 | ((ls->current == '-' || ls->current == '+') && | 151 | ((ls->current == '-' || ls->current == '+') && |
| 89 | ((c & ~0x20) == 'E' || (c & ~0x20) == 'P'))); | 152 | ((c & ~0x20) == 'E' || (c & ~0x20) == 'P'))); |
| 153 | #if LJ_HASFFI | ||
| 154 | c &= ~0x20; | ||
| 155 | if ((c == 'I' || c == 'L' || c == 'U') && !ctype_ctsG(G(ls->L))) | ||
| 156 | lex_loadffi(ls->L); | ||
| 157 | if (c == 'I') /* Parse imaginary part of complex number. */ | ||
| 158 | ls->sb.n--; | ||
| 159 | #endif | ||
| 90 | save(ls, '\0'); | 160 | save(ls, '\0'); |
| 91 | if (!lj_str_numconv(ls->sb.buf, tv)) | 161 | #if LJ_HASFFI |
| 92 | lj_lex_error(ls, TK_number, LJ_ERR_XNUMBER); | 162 | if ((c == 'L' || c == 'U') && lex_number64(ls, tv)) { /* Parse 64 bit int. */ |
| 163 | return; | ||
| 164 | } else | ||
| 165 | #endif | ||
| 166 | if (lj_str_numconv(ls->sb.buf, tv)) { | ||
| 167 | #if LJ_HASFFI | ||
| 168 | if (c == 'I') { /* Return cdata holding a complex number. */ | ||
| 169 | GCcdata *cd = lj_cdata_new_(ls->L, CTID_COMPLEX_DOUBLE, 2*sizeof(double)); | ||
| 170 | ((double *)cdataptr(cd))[0] = 0; | ||
| 171 | ((double *)cdataptr(cd))[1] = tv->n; | ||
| 172 | lj_parse_keepcdata(ls, tv, cd); | ||
| 173 | } | ||
| 174 | #endif | ||
| 175 | return; | ||
| 176 | } | ||
| 177 | lj_lex_error(ls, TK_number, LJ_ERR_XNUMBER); | ||
| 93 | } | 178 | } |
| 94 | 179 | ||
| 95 | static int skip_sep(LexState *ls) | 180 | static int skip_sep(LexState *ls) |
| @@ -224,7 +309,7 @@ static int llex(LexState *ls, TValue *tv) | |||
| 224 | if (lj_char_isident(ls->current)) { | 309 | if (lj_char_isident(ls->current)) { |
| 225 | GCstr *s; | 310 | GCstr *s; |
| 226 | if (lj_char_isdigit(ls->current)) { /* Numeric literal. */ | 311 | if (lj_char_isdigit(ls->current)) { /* Numeric literal. */ |
| 227 | read_numeral(ls, tv); | 312 | lex_number(ls, tv); |
| 228 | return TK_number; | 313 | return TK_number; |
| 229 | } | 314 | } |
| 230 | /* Identifier or reserved word. */ | 315 | /* Identifier or reserved word. */ |
| @@ -306,7 +391,7 @@ static int llex(LexState *ls, TValue *tv) | |||
| 306 | } else if (!lj_char_isdigit(ls->current)) { | 391 | } else if (!lj_char_isdigit(ls->current)) { |
| 307 | return '.'; | 392 | return '.'; |
| 308 | } else { | 393 | } else { |
| 309 | read_numeral(ls, tv); | 394 | lex_number(ls, tv); |
| 310 | return TK_number; | 395 | return TK_number; |
| 311 | } | 396 | } |
| 312 | case END_OF_STREAM: | 397 | case END_OF_STREAM: |
diff --git a/src/lj_parse.c b/src/lj_parse.c index d93ed990..22241b24 100644 --- a/src/lj_parse.c +++ b/src/lj_parse.c | |||
| @@ -17,6 +17,9 @@ | |||
| 17 | #include "lj_func.h" | 17 | #include "lj_func.h" |
| 18 | #include "lj_state.h" | 18 | #include "lj_state.h" |
| 19 | #include "lj_bc.h" | 19 | #include "lj_bc.h" |
| 20 | #if LJ_HASFFI | ||
| 21 | #include "lj_ctype.h" | ||
| 22 | #endif | ||
| 20 | #include "lj_lex.h" | 23 | #include "lj_lex.h" |
| 21 | #include "lj_parse.h" | 24 | #include "lj_parse.h" |
| 22 | #include "lj_vm.h" | 25 | #include "lj_vm.h" |
| @@ -33,6 +36,7 @@ typedef enum { | |||
| 33 | VKSTR, /* sval = string value */ | 36 | VKSTR, /* sval = string value */ |
| 34 | VKNUM, /* nval = number value */ | 37 | VKNUM, /* nval = number value */ |
| 35 | VKLAST = VKNUM, | 38 | VKLAST = VKNUM, |
| 39 | VKCDATA, /* nval = cdata value, not treated as a constant expression */ | ||
| 36 | /* Non-constant expressions follow: */ | 40 | /* Non-constant expressions follow: */ |
| 37 | VLOCAL, /* info = local register */ | 41 | VLOCAL, /* info = local register */ |
| 38 | VUPVAL, /* info = upvalue index */ | 42 | VUPVAL, /* info = upvalue index */ |
| @@ -61,7 +65,7 @@ typedef struct ExpDesc { | |||
| 61 | } ExpDesc; | 65 | } ExpDesc; |
| 62 | 66 | ||
| 63 | /* Macros for expressions. */ | 67 | /* Macros for expressions. */ |
| 64 | #define expr_hasjump(e) ((e)->t != (e)->f) | 68 | #define expr_hasjump(e) ((e)->t != (e)->f) |
| 65 | 69 | ||
| 66 | #define expr_isk(e) ((e)->k <= VKLAST) | 70 | #define expr_isk(e) ((e)->k <= VKLAST) |
| 67 | #define expr_isk_nojump(e) (expr_isk(e) && !expr_hasjump(e)) | 71 | #define expr_isk_nojump(e) (expr_isk(e) && !expr_hasjump(e)) |
| @@ -216,6 +220,17 @@ GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t len) | |||
| 216 | return s; | 220 | return s; |
| 217 | } | 221 | } |
| 218 | 222 | ||
| 223 | #if LJ_HASFFI | ||
| 224 | /* Anchor cdata to avoid GC. */ | ||
| 225 | void lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd) | ||
| 226 | { | ||
| 227 | /* NOBARRIER: the key is new or kept alive. */ | ||
| 228 | lua_State *L = ls->L; | ||
| 229 | setcdataV(L, tv, cd); | ||
| 230 | setboolV(lj_tab_set(L, ls->fs->kt, tv), 1); | ||
| 231 | } | ||
| 232 | #endif | ||
| 233 | |||
| 219 | /* -- Jump list handling -------------------------------------------------- */ | 234 | /* -- Jump list handling -------------------------------------------------- */ |
| 220 | 235 | ||
| 221 | /* Get next element in jump list. */ | 236 | /* Get next element in jump list. */ |
| @@ -469,6 +484,11 @@ static void expr_toreg_nobranch(FuncState *fs, ExpDesc *e, BCReg reg) | |||
| 469 | ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)k); | 484 | ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)k); |
| 470 | else | 485 | else |
| 471 | ins = BCINS_AD(BC_KNUM, reg, const_num(fs, e)); | 486 | ins = BCINS_AD(BC_KNUM, reg, const_num(fs, e)); |
| 487 | #if LJ_HASFFI | ||
| 488 | } else if (e->k == VKCDATA) { | ||
| 489 | ins = BCINS_AD(BC_KCDATA, reg, | ||
| 490 | const_gc(fs, obj2gco(cdataV(&e->u.nval)), LJ_TCDATA)); | ||
| 491 | #endif | ||
| 472 | } else if (e->k == VRELOCABLE) { | 492 | } else if (e->k == VRELOCABLE) { |
| 473 | setbc_a(bcptr(fs, e), reg); | 493 | setbc_a(bcptr(fs, e), reg); |
| 474 | goto noins; | 494 | goto noins; |
| @@ -856,7 +876,7 @@ static void bcemit_unop(FuncState *fs, BCOp op, ExpDesc *e) | |||
| 856 | if (e->k == VKNIL || e->k == VKFALSE) { | 876 | if (e->k == VKNIL || e->k == VKFALSE) { |
| 857 | e->k = VKTRUE; | 877 | e->k = VKTRUE; |
| 858 | return; | 878 | return; |
| 859 | } else if (expr_isk(e)) { | 879 | } else if (expr_isk(e) || (LJ_HASFFI && e->k == VKCDATA)) { |
| 860 | e->k = VKFALSE; | 880 | e->k = VKFALSE; |
| 861 | return; | 881 | return; |
| 862 | } else if (e->k == VJMP) { | 882 | } else if (e->k == VJMP) { |
| @@ -872,10 +892,22 @@ static void bcemit_unop(FuncState *fs, BCOp op, ExpDesc *e) | |||
| 872 | } | 892 | } |
| 873 | } else { | 893 | } else { |
| 874 | lua_assert(op == BC_UNM || op == BC_LEN); | 894 | lua_assert(op == BC_UNM || op == BC_LEN); |
| 875 | /* Constant-fold negations. But avoid folding to -0. */ | 895 | if (op == BC_UNM && !expr_hasjump(e)) { /* Constant-fold negations. */ |
| 876 | if (op == BC_UNM && expr_isnumk_nojump(e) && expr_numV(e) != 0) { | 896 | #if LJ_HASFFI |
| 877 | setnumV(&e->u.nval, -expr_numV(e)); | 897 | if (e->k == VKCDATA) { /* Fold in-place since cdata is not interned. */ |
| 878 | return; | 898 | GCcdata *cd = cdataV(&e->u.nval); |
| 899 | int64_t *p = (int64_t *)cdataptr(cd); | ||
| 900 | if (cd->typeid == CTID_COMPLEX_DOUBLE) | ||
| 901 | p[1] ^= (int64_t)U64x(80000000,00000000); | ||
| 902 | else | ||
| 903 | *p = -*p; | ||
| 904 | return; | ||
| 905 | } else | ||
| 906 | #endif | ||
| 907 | if (expr_isnumk(e) && expr_numV(e) != 0) { /* Avoid folding to -0. */ | ||
| 908 | e->u.nval.u64 ^= U64x(80000000,00000000); | ||
| 909 | return; | ||
| 910 | } | ||
| 879 | } | 911 | } |
| 880 | expr_toanyreg(fs, e); | 912 | expr_toanyreg(fs, e); |
| 881 | } | 913 | } |
| @@ -1554,8 +1586,8 @@ static void expr_simple(LexState *ls, ExpDesc *v) | |||
| 1554 | { | 1586 | { |
| 1555 | switch (ls->token) { | 1587 | switch (ls->token) { |
| 1556 | case TK_number: | 1588 | case TK_number: |
| 1557 | expr_init(v, VKNUM, 0); | 1589 | expr_init(v, (LJ_HASFFI && tviscdata(&ls->tokenval)) ? VKCDATA : VKNUM, 0); |
| 1558 | setnumV(&v->u.nval, numV(&ls->tokenval)); | 1590 | copyTV(ls->L, &v->u.nval, &ls->tokenval); |
| 1559 | break; | 1591 | break; |
| 1560 | case TK_string: | 1592 | case TK_string: |
| 1561 | expr_init(v, VKSTR, 0); | 1593 | expr_init(v, VKSTR, 0); |
diff --git a/src/lj_parse.h b/src/lj_parse.h index 2031eeed..a05cb4ce 100644 --- a/src/lj_parse.h +++ b/src/lj_parse.h | |||
| @@ -11,5 +11,8 @@ | |||
| 11 | 11 | ||
| 12 | LJ_FUNC GCproto *lj_parse(LexState *ls); | 12 | LJ_FUNC GCproto *lj_parse(LexState *ls); |
| 13 | LJ_FUNC GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t l); | 13 | LJ_FUNC GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t l); |
| 14 | #if LJ_HASFFI | ||
| 15 | LJ_FUNC void lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd); | ||
| 16 | #endif | ||
| 14 | 17 | ||
| 15 | #endif | 18 | #endif |
