diff options
| -rw-r--r-- | src/Makefile.dep | 6 | ||||
| -rw-r--r-- | src/lib_ffi.c | 2 | ||||
| -rw-r--r-- | src/lj_clib.c | 4 | ||||
| -rw-r--r-- | src/lj_clib.h | 3 | ||||
| -rw-r--r-- | src/lj_crecord.c | 34 | ||||
| -rw-r--r-- | src/lj_crecord.h | 2 | ||||
| -rw-r--r-- | src/lj_opt_fold.c | 12 | ||||
| -rw-r--r-- | src/lj_traceerr.h | 1 |
8 files changed, 53 insertions, 11 deletions
diff --git a/src/Makefile.dep b/src/Makefile.dep index cecaf403..b869fdff 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep | |||
| @@ -75,9 +75,9 @@ lj_cparse.o: lj_cparse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | |||
| 75 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_ctype.h lj_cparse.h lj_frame.h \ | 75 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_ctype.h lj_cparse.h lj_frame.h \ |
| 76 | lj_bc.h lj_vm.h lj_char.h | 76 | lj_bc.h lj_vm.h lj_char.h |
| 77 | lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 77 | lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 78 | lj_err.h lj_errmsg.h lj_str.h lj_ctype.h lj_gc.h lj_cparse.h lj_cconv.h \ | 78 | lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_gc.h lj_cparse.h \ |
| 79 | lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h \ | 79 | lj_cconv.h lj_clib.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h \ |
| 80 | lj_traceerr.h lj_ffrecord.h lj_crecord.h | 80 | lj_dispatch.h lj_bc.h lj_traceerr.h lj_ffrecord.h lj_crecord.h |
| 81 | lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 81 | lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 82 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h | 82 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h |
| 83 | lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 83 | lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 72128574..54d49f87 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
| @@ -239,7 +239,7 @@ static TValue *ffi_clib_index(lua_State *L) | |||
| 239 | return lj_clib_index(L, cl, strV(o+1)); | 239 | return lj_clib_index(L, cl, strV(o+1)); |
| 240 | } | 240 | } |
| 241 | 241 | ||
| 242 | LJLIB_CF(ffi_clib___index) | 242 | LJLIB_CF(ffi_clib___index) LJLIB_REC(clib_index) |
| 243 | { | 243 | { |
| 244 | TValue *tv = ffi_clib_index(L); | 244 | TValue *tv = ffi_clib_index(L); |
| 245 | if (tviscdata(tv)) { | 245 | if (tviscdata(tv)) { |
diff --git a/src/lj_clib.c b/src/lj_clib.c index e2d349fd..64d06dbc 100644 --- a/src/lj_clib.c +++ b/src/lj_clib.c | |||
| @@ -222,10 +222,6 @@ static void *clib_getsym(CLibrary *cl, const char *name) | |||
| 222 | 222 | ||
| 223 | /* -- C library indexing -------------------------------------------------- */ | 223 | /* -- C library indexing -------------------------------------------------- */ |
| 224 | 224 | ||
| 225 | /* Namespace for C library indexing. */ | ||
| 226 | #define CLNS_INDEX \ | ||
| 227 | ((1u<<CT_FUNC)|(1u<<CT_EXTERN)|(1u<<CT_CONSTVAL)) | ||
| 228 | |||
| 229 | #if LJ_TARGET_X86 && LJ_ABI_WIN | 225 | #if LJ_TARGET_X86 && LJ_ABI_WIN |
| 230 | /* Compute argument size for fastcall/stdcall functions. */ | 226 | /* Compute argument size for fastcall/stdcall functions. */ |
| 231 | static CTSize clib_func_argsize(CTState *cts, CType *ct) | 227 | static CTSize clib_func_argsize(CTState *cts, CType *ct) |
diff --git a/src/lj_clib.h b/src/lj_clib.h index 86045d24..51c32703 100644 --- a/src/lj_clib.h +++ b/src/lj_clib.h | |||
| @@ -10,6 +10,9 @@ | |||
| 10 | 10 | ||
| 11 | #if LJ_HASFFI | 11 | #if LJ_HASFFI |
| 12 | 12 | ||
| 13 | /* Namespace for C library indexing. */ | ||
| 14 | #define CLNS_INDEX ((1u<<CT_FUNC)|(1u<<CT_EXTERN)|(1u<<CT_CONSTVAL)) | ||
| 15 | |||
| 13 | /* C library namespace. */ | 16 | /* C library namespace. */ |
| 14 | typedef struct CLibrary { | 17 | typedef struct CLibrary { |
| 15 | void *handle; /* Opaque handle for dynamic library loader. */ | 18 | void *handle; /* Opaque handle for dynamic library loader. */ |
diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 80f00e18..e5413fb3 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c | |||
| @@ -12,9 +12,11 @@ | |||
| 12 | 12 | ||
| 13 | #include "lj_err.h" | 13 | #include "lj_err.h" |
| 14 | #include "lj_str.h" | 14 | #include "lj_str.h" |
| 15 | #include "lj_tab.h" | ||
| 15 | #include "lj_ctype.h" | 16 | #include "lj_ctype.h" |
| 16 | #include "lj_cparse.h" | 17 | #include "lj_cparse.h" |
| 17 | #include "lj_cconv.h" | 18 | #include "lj_cconv.h" |
| 19 | #include "lj_clib.h" | ||
| 18 | #include "lj_ir.h" | 20 | #include "lj_ir.h" |
| 19 | #include "lj_jit.h" | 21 | #include "lj_jit.h" |
| 20 | #include "lj_iropt.h" | 22 | #include "lj_iropt.h" |
| @@ -837,6 +839,38 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) | |||
| 837 | } | 839 | } |
| 838 | } | 840 | } |
| 839 | 841 | ||
| 842 | /* -- C library namespace metamethods ------------------------------------- */ | ||
| 843 | |||
| 844 | void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd) | ||
| 845 | { | ||
| 846 | CTState *cts = ctype_ctsG(J2G(J)); | ||
| 847 | if (tref_isudata(J->base[0]) && tref_isstr(J->base[1]) && | ||
| 848 | udataV(&rd->argv[0])->udtype == UDTYPE_FFI_CLIB) { | ||
| 849 | CLibrary *cl = (CLibrary *)uddata(udataV(&rd->argv[0])); | ||
| 850 | GCstr *name = strV(&rd->argv[1]); | ||
| 851 | CType *ct; | ||
| 852 | CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX); | ||
| 853 | cTValue *tv = lj_tab_getstr(cl->cache, name); | ||
| 854 | if (id && tv && tviscdata(tv)) { | ||
| 855 | /* Specialize to the symbol name and make the result a constant. */ | ||
| 856 | emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, name)); | ||
| 857 | if (ctype_isconstval(ct->info)) { | ||
| 858 | if (ct->size >= 0x80000000u && | ||
| 859 | (ctype_child(cts, ct)->info & CTF_UNSIGNED)) | ||
| 860 | J->base[0] = lj_ir_knum(J, (lua_Number)(uint32_t)ct->size); | ||
| 861 | else | ||
| 862 | J->base[0] = lj_ir_kint(J, (int32_t)ct->size); | ||
| 863 | } else if (ctype_isextern(ct->info)) { | ||
| 864 | lj_trace_err(J, LJ_TRERR_BADTYPE); /* NYI: access extern variables. */ | ||
| 865 | } else { | ||
| 866 | J->base[0] = lj_ir_kgc(J, obj2gco(cdataV(tv)), IRT_CDATA); | ||
| 867 | } | ||
| 868 | } else { | ||
| 869 | lj_trace_err(J, LJ_TRERR_NOCACHE); | ||
| 870 | } | ||
| 871 | } /* else: interpreter will throw. */ | ||
| 872 | } | ||
| 873 | |||
| 840 | /* -- FFI library functions ----------------------------------------------- */ | 874 | /* -- FFI library functions ----------------------------------------------- */ |
| 841 | 875 | ||
| 842 | void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd) | 876 | void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd) |
diff --git a/src/lj_crecord.h b/src/lj_crecord.h index 4ac5b3e2..2b6c3ec6 100644 --- a/src/lj_crecord.h +++ b/src/lj_crecord.h | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | LJ_FUNC void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd); | 14 | LJ_FUNC void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd); |
| 15 | LJ_FUNC void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd); | 15 | LJ_FUNC void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd); |
| 16 | LJ_FUNC void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd); | 16 | LJ_FUNC void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd); |
| 17 | LJ_FUNC void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd); | ||
| 17 | LJ_FUNC void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd); | 18 | LJ_FUNC void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd); |
| 18 | LJ_FUNC void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd); | 19 | LJ_FUNC void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd); |
| 19 | LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd); | 20 | LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd); |
| @@ -21,6 +22,7 @@ LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd); | |||
| 21 | #define recff_cdata_index recff_nyi | 22 | #define recff_cdata_index recff_nyi |
| 22 | #define recff_cdata_call recff_nyi | 23 | #define recff_cdata_call recff_nyi |
| 23 | #define recff_cdata_arith recff_nyi | 24 | #define recff_cdata_arith recff_nyi |
| 25 | #define recff_clib_index recff_nyi | ||
| 24 | #define recff_ffi_new recff_nyi | 26 | #define recff_ffi_new recff_nyi |
| 25 | #define recff_ffi_string recff_nyi | 27 | #define recff_ffi_string recff_nyi |
| 26 | #endif | 28 | #endif |
diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c index 9675fca2..ef397aea 100644 --- a/src/lj_opt_fold.c +++ b/src/lj_opt_fold.c | |||
| @@ -1768,12 +1768,18 @@ LJFOLDF(fload_cdata_typeid_kgc) | |||
| 1768 | return NEXTFOLD; | 1768 | return NEXTFOLD; |
| 1769 | } | 1769 | } |
| 1770 | 1770 | ||
| 1771 | /* The content of int64 cdata objects is immutable. */ | 1771 | /* Get the contents of immutable cdata objects. */ |
| 1772 | LJFOLD(FLOAD KGC IRFL_CDATA_PTR) | ||
| 1772 | LJFOLD(FLOAD KGC IRFL_CDATA_INT64) | 1773 | LJFOLD(FLOAD KGC IRFL_CDATA_INT64) |
| 1773 | LJFOLDF(fload_cdata_int64_kgc) | 1774 | LJFOLDF(fload_cdata_int64_kgc) |
| 1774 | { | 1775 | { |
| 1775 | if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) | 1776 | if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) { |
| 1776 | return INT64FOLD(*(uint64_t *)cdataptr(ir_kcdata(fleft))); | 1777 | void *p = cdataptr(ir_kcdata(fleft)); |
| 1778 | if (irt_is64(fins->t)) | ||
| 1779 | return INT64FOLD(*(uint64_t *)p); | ||
| 1780 | else | ||
| 1781 | return INTFOLD(*(int32_t *)p); | ||
| 1782 | } | ||
| 1777 | return NEXTFOLD; | 1783 | return NEXTFOLD; |
| 1778 | } | 1784 | } |
| 1779 | 1785 | ||
diff --git a/src/lj_traceerr.h b/src/lj_traceerr.h index e212dd4c..f0c45963 100644 --- a/src/lj_traceerr.h +++ b/src/lj_traceerr.h | |||
| @@ -35,6 +35,7 @@ TREDEF(IDXLOOP, "looping index lookup") | |||
| 35 | TREDEF(NYITMIX, "NYI: mixed sparse/dense table") | 35 | TREDEF(NYITMIX, "NYI: mixed sparse/dense table") |
| 36 | 36 | ||
| 37 | /* Recording C data operations. */ | 37 | /* Recording C data operations. */ |
| 38 | TREDEF(NOCACHE, "symbol not in cache") | ||
| 38 | TREDEF(NYICONV, "NYI: unsupported C type conversion") | 39 | TREDEF(NYICONV, "NYI: unsupported C type conversion") |
| 39 | 40 | ||
| 40 | /* Optimizations. */ | 41 | /* Optimizations. */ |
