diff options
| author | Mike Pall <mike> | 2011-02-06 12:23:58 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2011-02-06 12:23:58 +0100 |
| commit | bf58160b7aa21d15b710f948d160da277a02a613 (patch) | |
| tree | 2db9391ef5c8d2ac401dfe3673de4c68af506290 | |
| parent | 4c74f704644c2f843cb304aba0c901723097ff14 (diff) | |
| download | luajit-bf58160b7aa21d15b710f948d160da277a02a613.tar.gz luajit-bf58160b7aa21d15b710f948d160da277a02a613.tar.bz2 luajit-bf58160b7aa21d15b710f948d160da277a02a613.zip | |
FFI: Simplify and fix tonumber() for cdata objects.
| -rw-r--r-- | src/lj_crecord.c | 39 | ||||
| -rw-r--r-- | src/lj_ffrecord.c | 12 |
2 files changed, 13 insertions, 38 deletions
diff --git a/src/lj_crecord.c b/src/lj_crecord.c index ae528881..b7b3855f 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c | |||
| @@ -404,8 +404,7 @@ static TRef crec_ct_tv(jit_State *J, CType *d, TRef dp, TRef sp, TValue *sval) | |||
| 404 | } else { | 404 | } else { |
| 405 | goto doconv; /* The pointer value was loaded, don't load number. */ | 405 | goto doconv; /* The pointer value was loaded, don't load number. */ |
| 406 | } | 406 | } |
| 407 | 407 | } else if (ctype_isinteger(s->info) && s->size == 8) { | |
| 408 | } else if (ctype_isnum(s->info) && s->size == 8) { | ||
| 409 | IRType t = (s->info & CTF_UNSIGNED) ? IRT_U64 : IRT_I64; | 408 | IRType t = (s->info & CTF_UNSIGNED) ? IRT_U64 : IRT_I64; |
| 410 | sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT64); | 409 | sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT64); |
| 411 | lj_needsplit(J); | 410 | lj_needsplit(J); |
| @@ -592,7 +591,7 @@ static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id) | |||
| 592 | lj_trace_err(J, LJ_TRERR_NYICONV); /* NYI: large/special allocations. */ | 591 | lj_trace_err(J, LJ_TRERR_NYICONV); /* NYI: large/special allocations. */ |
| 593 | trid = lj_ir_kint(J, id); | 592 | trid = lj_ir_kint(J, id); |
| 594 | /* Use special instruction to box pointer or 64 bit integer. */ | 593 | /* Use special instruction to box pointer or 64 bit integer. */ |
| 595 | if (ctype_isptr(info) || (ctype_isnum(info) && sz == 8)) { | 594 | if (ctype_isptr(info) || (ctype_isinteger(info) && sz == 8)) { |
| 596 | TRef sp = J->base[1] ? crec_ct_tv(J, d, 0, J->base[1], &rd->argv[1]) : | 595 | TRef sp = J->base[1] ? crec_ct_tv(J, d, 0, J->base[1], &rd->argv[1]) : |
| 597 | ctype_isptr(info) ? lj_ir_kptr(J, NULL) : | 596 | ctype_isptr(info) ? lj_ir_kptr(J, NULL) : |
| 598 | (lj_needsplit(J), lj_ir_kint64(J, 0)); | 597 | (lj_needsplit(J), lj_ir_kint64(J, 0)); |
| @@ -865,7 +864,7 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) | |||
| 865 | IRType t = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32; | 864 | IRType t = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32; |
| 866 | if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct); | 865 | if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct); |
| 867 | tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_PTR); | 866 | tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_PTR); |
| 868 | } else if (ctype_isnum(ct->info) && ct->size == 8) { | 867 | } else if (ctype_isinteger(ct->info) && ct->size == 8) { |
| 869 | IRType t = (ct->info & CTF_UNSIGNED) ? IRT_U64 : IRT_I64; | 868 | IRType t = (ct->info & CTF_UNSIGNED) ? IRT_U64 : IRT_I64; |
| 870 | tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_INT64); | 869 | tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_INT64); |
| 871 | lj_needsplit(J); | 870 | lj_needsplit(J); |
| @@ -974,35 +973,11 @@ void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd) | |||
| 974 | 973 | ||
| 975 | void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd) | 974 | void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd) |
| 976 | { | 975 | { |
| 977 | CTypeID sid = argv2cdata(J, J->base[0], &rd->argv[0])->typeid; | ||
| 978 | CTState *cts = ctype_ctsG(J2G(J)); | 976 | CTState *cts = ctype_ctsG(J2G(J)); |
| 979 | CType *s = ctype_raw(cts, sid); | 977 | IRType st = crec_ct2irt(ctype_raw(cts, cdataV(&rd->argv[0])->typeid)); |
| 980 | TRef sp = J->base[0]; | 978 | CTypeID did = (st >= IRT_I8 && st <= IRT_INT) ? CTID_INT32 : CTID_DOUBLE; |
| 981 | if (ctype_isref(s->info)) { | 979 | CType *d = ctype_get(cts, did); |
| 982 | sp = emitir(IRT(IR_FLOAD, IRT_PTR), sp, IRFL_CDATA_PTR); | 980 | J->base[0] = crec_ct_tv(J, d, 0, J->base[0], &rd->argv[0]); |
| 983 | s = ctype_rawchild(cts, s); | ||
| 984 | } else if (ctype_isnum(s->info) && s->size == 8) { | ||
| 985 | IRType t = (s->info & CTF_UNSIGNED) ? IRT_U64 : IRT_I64; | ||
| 986 | TRef tr = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT64); | ||
| 987 | J->base[0] = emitconv(tr, IRT_NUM, t, 0); | ||
| 988 | lj_needsplit(J); | ||
| 989 | return; | ||
| 990 | } else { | ||
| 991 | sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCcdata))); | ||
| 992 | } | ||
| 993 | if (ctype_isenum(s->info)) s = ctype_child(cts, s); | ||
| 994 | if (ctype_isnum(s->info) || ctype_iscomplex(s->info)) { | ||
| 995 | IRType t = crec_ct2irt(s); | ||
| 996 | if (t != IRT_CDATA) { | ||
| 997 | TRef tr = emitir(IRT(IR_XLOAD, t), sp, 0); /* Load number value. */ | ||
| 998 | if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J); | ||
| 999 | if (t == IRT_FLOAT || t == IRT_U32 || t == IRT_I64 || t == IRT_U64) | ||
| 1000 | tr = emitconv(tr, IRT_NUM, t, 0); | ||
| 1001 | J->base[0] = tr; | ||
| 1002 | return; | ||
| 1003 | } | ||
| 1004 | } | ||
| 1005 | lj_trace_err(J, LJ_TRERR_BADTYPE); | ||
| 1006 | } | 981 | } |
| 1007 | 982 | ||
| 1008 | #undef IR | 983 | #undef IR |
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 2296dac6..5b618a80 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
| @@ -253,13 +253,13 @@ static void LJ_FASTCALL recff_select(jit_State *J, RecordFFData *rd) | |||
| 253 | static void LJ_FASTCALL recff_tonumber(jit_State *J, RecordFFData *rd) | 253 | static void LJ_FASTCALL recff_tonumber(jit_State *J, RecordFFData *rd) |
| 254 | { | 254 | { |
| 255 | TRef tr = J->base[0]; | 255 | TRef tr = J->base[0]; |
| 256 | TRef base = J->base[1]; | ||
| 257 | if (tr && base) { | ||
| 258 | base = lj_ir_toint(J, base); | ||
| 259 | if (!tref_isk(base) || IR(tref_ref(base))->i != 10) | ||
| 260 | recff_nyiu(J); | ||
| 261 | } | ||
| 256 | if (tref_isnumber_str(tr)) { | 262 | if (tref_isnumber_str(tr)) { |
| 257 | TRef base = J->base[1]; | ||
| 258 | if (base) { | ||
| 259 | base = lj_ir_toint(J, base); | ||
| 260 | if (!tref_isk(base) || IR(tref_ref(base))->i != 10) | ||
| 261 | recff_nyiu(J); | ||
| 262 | } | ||
| 263 | if (tref_isstr(tr)) { | 263 | if (tref_isstr(tr)) { |
| 264 | TValue tmp; | 264 | TValue tmp; |
| 265 | if (!lj_str_tonum(strV(&rd->argv[0]), &tmp)) | 265 | if (!lj_str_tonum(strV(&rd->argv[0]), &tmp)) |
