diff options
| author | Mike Pall <mike> | 2011-02-05 01:05:56 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2011-02-05 01:05:56 +0100 |
| commit | c29ed4dbbf9089c6a7ba22c785e342c12862cbd8 (patch) | |
| tree | 7c0d7e32739ad77d95a9e5d34f6cd23bac98cb85 | |
| parent | 618b4516488a4fec332bb1ff29ece18821767917 (diff) | |
| download | luajit-c29ed4dbbf9089c6a7ba22c785e342c12862cbd8.tar.gz luajit-c29ed4dbbf9089c6a7ba22c785e342c12862cbd8.tar.bz2 luajit-c29ed4dbbf9089c6a7ba22c785e342c12862cbd8.zip | |
FFI: Record ffi.string().
| -rw-r--r-- | src/lib_ffi.c | 16 | ||||
| -rw-r--r-- | src/lj_crecord.c | 17 | ||||
| -rw-r--r-- | src/lj_crecord.h | 2 | ||||
| -rw-r--r-- | src/lj_ir.h | 3 |
4 files changed, 31 insertions, 7 deletions
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 85a4e9c1..72128574 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
| @@ -425,17 +425,21 @@ LJLIB_CF(ffi_cast) | |||
| 425 | return 1; | 425 | return 1; |
| 426 | } | 426 | } |
| 427 | 427 | ||
| 428 | LJLIB_CF(ffi_string) | 428 | LJLIB_CF(ffi_string) LJLIB_REC(.) |
| 429 | { | 429 | { |
| 430 | CTState *cts = ctype_cts(L); | 430 | CTState *cts = ctype_cts(L); |
| 431 | TValue *o = lj_lib_checkany(L, 1); | 431 | TValue *o = lj_lib_checkany(L, 1); |
| 432 | size_t sz = (size_t)(CTSize)lj_lib_optint(L, 2, (int32_t)CTSIZE_INVALID); | ||
| 433 | CType *ct = ctype_get(cts, sz==CTSIZE_INVALID ? CTID_P_CVOID : CTID_P_CCHAR); | ||
| 434 | const char *p; | 432 | const char *p; |
| 433 | size_t len; | ||
| 434 | if (o+1 < L->top) { | ||
| 435 | len = (size_t)lj_lib_checkint(L, 2); | ||
| 436 | lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CVOID), (uint8_t *)&p, o, 0); | ||
| 437 | } else { | ||
| 438 | lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CCHAR), (uint8_t *)&p, o, 0); | ||
| 439 | len = strlen(p); | ||
| 440 | } | ||
| 435 | L->top = o+1; /* Make sure this is the last item on the stack. */ | 441 | L->top = o+1; /* Make sure this is the last item on the stack. */ |
| 436 | lj_cconv_ct_tv(cts, ct, (uint8_t *)&p, o, 0); | 442 | setstrV(L, o, lj_str_new(L, p, len)); |
| 437 | if (sz == CTSIZE_INVALID) sz = strlen(p); | ||
| 438 | setstrV(L, o, lj_str_new(L, p, sz)); | ||
| 439 | lj_gc_check(L); | 443 | lj_gc_check(L); |
| 440 | return 1; | 444 | return 1; |
| 441 | } | 445 | } |
diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 1223eb8e..80f00e18 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c | |||
| @@ -844,6 +844,23 @@ void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd) | |||
| 844 | crec_alloc(J, rd, argv2ctype(J, J->base[0], &rd->argv[0])); | 844 | crec_alloc(J, rd, argv2ctype(J, J->base[0], &rd->argv[0])); |
| 845 | } | 845 | } |
| 846 | 846 | ||
| 847 | void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd) | ||
| 848 | { | ||
| 849 | CTState *cts = ctype_ctsG(J2G(J)); | ||
| 850 | TRef tr = J->base[0]; | ||
| 851 | if (tr) { | ||
| 852 | TRef trlen = J->base[1]; | ||
| 853 | if (trlen) { | ||
| 854 | trlen = lj_ir_toint(J, trlen); | ||
| 855 | tr = crec_ct_tv(J, ctype_get(cts, CTID_P_CVOID), 0, tr, &rd->argv[0]); | ||
| 856 | } else { | ||
| 857 | tr = crec_ct_tv(J, ctype_get(cts, CTID_P_CCHAR), 0, tr, &rd->argv[0]); | ||
| 858 | trlen = lj_ir_call(J, IRCALL_strlen, tr); | ||
| 859 | } | ||
| 860 | J->base[0] = emitir(IRT(IR_SNEW, IRT_STR), tr, trlen); | ||
| 861 | } /* else: interpreter will throw. */ | ||
| 862 | } | ||
| 863 | |||
| 847 | /* -- Miscellaneous library functions ------------------------------------- */ | 864 | /* -- Miscellaneous library functions ------------------------------------- */ |
| 848 | 865 | ||
| 849 | void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd) | 866 | void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd) |
diff --git a/src/lj_crecord.h b/src/lj_crecord.h index 3b2249c5..4ac5b3e2 100644 --- a/src/lj_crecord.h +++ b/src/lj_crecord.h | |||
| @@ -15,12 +15,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_ffi_new(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_string(jit_State *J, RecordFFData *rd); | ||
| 18 | LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd); | 19 | LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd); |
| 19 | #else | 20 | #else |
| 20 | #define recff_cdata_index recff_nyi | 21 | #define recff_cdata_index recff_nyi |
| 21 | #define recff_cdata_call recff_nyi | 22 | #define recff_cdata_call recff_nyi |
| 22 | #define recff_cdata_arith recff_nyi | 23 | #define recff_cdata_arith recff_nyi |
| 23 | #define recff_ffi_new recff_nyi | 24 | #define recff_ffi_new recff_nyi |
| 25 | #define recff_ffi_string recff_nyi | ||
| 24 | #endif | 26 | #endif |
| 25 | 27 | ||
| 26 | #endif | 28 | #endif |
diff --git a/src/lj_ir.h b/src/lj_ir.h index bde0ac04..bedb4c2b 100644 --- a/src/lj_ir.h +++ b/src/lj_ir.h | |||
| @@ -273,7 +273,8 @@ typedef struct CCallInfo { | |||
| 273 | _(lj_carith_modi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ | 273 | _(lj_carith_modi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ |
| 274 | _(lj_carith_modu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \ | 274 | _(lj_carith_modu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \ |
| 275 | _(lj_carith_powi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ | 275 | _(lj_carith_powi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ |
| 276 | _(lj_carith_powu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) | 276 | _(lj_carith_powu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \ |
| 277 | _(strlen, 1, N, INT, 0) | ||
| 277 | #else | 278 | #else |
| 278 | #define IRCALLDEF_FFI(_) | 279 | #define IRCALLDEF_FFI(_) |
| 279 | #endif | 280 | #endif |
