diff options
author | Mike Pall <mike> | 2011-01-13 16:39:42 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2011-01-13 16:39:42 +0100 |
commit | 6e702d703efc1aee4e0f4dfa749a4ce51d7b97f8 (patch) | |
tree | 8855c5874ae9acd090ab860673c661bce7df5f1f /src | |
parent | 0ec7f5ed92b6b9720c80669b2de3aa3c40967153 (diff) | |
download | luajit-6e702d703efc1aee4e0f4dfa749a4ce51d7b97f8.tar.gz luajit-6e702d703efc1aee4e0f4dfa749a4ce51d7b97f8.tar.bz2 luajit-6e702d703efc1aee4e0f4dfa749a4ce51d7b97f8.zip |
FFI: Cleanup some type conversions.
Remove pointless conversions to booleans.
Allow assigning functions to function pointers.
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_cconv.c | 44 | ||||
-rw-r--r-- | src/lj_crecord.c | 6 |
2 files changed, 17 insertions, 33 deletions
diff --git a/src/lj_cconv.c b/src/lj_cconv.c index be45b256..1f14adad 100644 --- a/src/lj_cconv.c +++ b/src/lj_cconv.c | |||
@@ -129,10 +129,9 @@ void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s, | |||
129 | switch (cconv_idx2(dinfo, sinfo)) { | 129 | switch (cconv_idx2(dinfo, sinfo)) { |
130 | /* Destination is a bool. */ | 130 | /* Destination is a bool. */ |
131 | case CCX(B, B): | 131 | case CCX(B, B): |
132 | *dp = *sp; /* Source operand already normalized. */ | 132 | *dp = *sp; /* Source operand is already normalized. */ |
133 | break; | 133 | break; |
134 | case CCX(B, I): | 134 | case CCX(B, I): { |
135 | case CCX(B, P): { | ||
136 | MSize i; | 135 | MSize i; |
137 | uint8_t b = 0; | 136 | uint8_t b = 0; |
138 | for (i = 0; i < ssize; i++) b |= sp[i]; | 137 | for (i = 0; i < ssize; i++) b |= sp[i]; |
@@ -147,17 +146,6 @@ void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s, | |||
147 | *dp = b; | 146 | *dp = b; |
148 | break; | 147 | break; |
149 | } | 148 | } |
150 | case CCX(B, C): { | ||
151 | CType *sc = ctype_child(cts, s); | ||
152 | uint8_t c; | ||
153 | lj_cconv_ct_ct(cts, d, sc, &c, sp, flags); | ||
154 | lj_cconv_ct_ct(cts, d, sc, dp, sp + sc->size, flags); | ||
155 | *dp = (*dp | c); | ||
156 | break; | ||
157 | } | ||
158 | case CCX(B, A): | ||
159 | *dp = (sp != (uint8_t *)0); | ||
160 | break; | ||
161 | 149 | ||
162 | /* Destination is an integer. */ | 150 | /* Destination is an integer. */ |
163 | case CCX(I, B): | 151 | case CCX(I, B): |
@@ -347,7 +335,7 @@ void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s, | |||
347 | 335 | ||
348 | /* Destination is an array. */ | 336 | /* Destination is an array. */ |
349 | case CCX(A, A): | 337 | case CCX(A, A): |
350 | if ((flags & CCF_CAST) || (d->info & CTF_VLA) || d->size != s->size || | 338 | if ((flags & CCF_CAST) || (d->info & CTF_VLA) || dsize != ssize || |
351 | d->size == CTSIZE_INVALID || !lj_cconv_compatptr(cts, d, s, flags)) | 339 | d->size == CTSIZE_INVALID || !lj_cconv_compatptr(cts, d, s, flags)) |
352 | goto err_conv; | 340 | goto err_conv; |
353 | goto copyval; | 341 | goto copyval; |
@@ -376,23 +364,15 @@ int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid, | |||
376 | CTInfo sinfo = s->info; | 364 | CTInfo sinfo = s->info; |
377 | lua_assert(!ctype_isenum(sinfo)); | 365 | lua_assert(!ctype_isenum(sinfo)); |
378 | if (ctype_isnum(sinfo)) { | 366 | if (ctype_isnum(sinfo)) { |
379 | uint8_t tmpbool; | ||
380 | uint8_t *dp; | ||
381 | CTypeID did; | ||
382 | if (!ctype_isbool(sinfo)) { | 367 | if (!ctype_isbool(sinfo)) { |
383 | if (ctype_isinteger(sinfo) && s->size > 4) goto copyval; | 368 | if (ctype_isinteger(sinfo) && s->size > 4) goto copyval; |
384 | dp = (uint8_t *)&o->n; | 369 | lj_cconv_ct_ct(cts, ctype_get(cts, CTID_DOUBLE), s, |
385 | did = CTID_DOUBLE; | 370 | (uint8_t *)&o->n, sp, 0); |
371 | /* Numbers are NOT canonicalized here! Beware of uninitialized data. */ | ||
372 | lua_assert(tvisnum(o)); | ||
386 | } else { | 373 | } else { |
387 | dp = &tmpbool; | 374 | setboolV(o, (*sp & 1)); |
388 | did = CTID_BOOL; | ||
389 | } | 375 | } |
390 | lj_cconv_ct_ct(cts, ctype_get(cts, did), s, dp, sp, 0); | ||
391 | /* Numbers are NOT canonicalized here! Beware of uninitialized data. */ | ||
392 | if (did == CTID_BOOL) | ||
393 | setboolV(o, tmpbool); | ||
394 | else | ||
395 | lua_assert(tvisnum(o)); | ||
396 | return 0; | 376 | return 0; |
397 | } else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) { | 377 | } else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) { |
398 | /* Create reference. */ | 378 | /* Create reference. */ |
@@ -542,8 +522,12 @@ void lj_cconv_ct_tv(CTState *cts, CType *d, | |||
542 | sid = ctype_cid(s->info); | 522 | sid = ctype_cid(s->info); |
543 | } | 523 | } |
544 | s = ctype_raw(cts, sid); | 524 | s = ctype_raw(cts, sid); |
545 | if (ctype_isenum(s->info)) s = ctype_child(cts, s); | 525 | if (ctype_isfunc(s->info)) { |
546 | goto doconv; | 526 | sid = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|sid), CTSIZE_PTR); |
527 | } else { | ||
528 | if (ctype_isenum(s->info)) s = ctype_child(cts, s); | ||
529 | goto doconv; | ||
530 | } | ||
547 | } else if (tvisstr(o)) { | 531 | } else if (tvisstr(o)) { |
548 | GCstr *str = strV(o); | 532 | GCstr *str = strV(o); |
549 | if (ctype_isenum(d->info)) { /* Match string against enum constant. */ | 533 | if (ctype_isenum(d->info)) { /* Match string against enum constant. */ |
diff --git a/src/lj_crecord.c b/src/lj_crecord.c index eb26bd0f..0f48f213 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c | |||
@@ -133,10 +133,7 @@ static void crec_ct_ct(jit_State *J, CType *d, CType *s, TRef dp, TRef sp) | |||
133 | case CCX(B, B): | 133 | case CCX(B, B): |
134 | goto xstore; /* Source operand is already normalized. */ | 134 | goto xstore; /* Source operand is already normalized. */ |
135 | case CCX(B, I): | 135 | case CCX(B, I): |
136 | case CCX(B, P): | ||
137 | case CCX(B, F): | 136 | case CCX(B, F): |
138 | case CCX(B, C): | ||
139 | case CCX(B, A): | ||
140 | /* NYI: specialize to the result of a comparison against 0. */ | 137 | /* NYI: specialize to the result of a comparison against 0. */ |
141 | goto err_nyi; | 138 | goto err_nyi; |
142 | 139 | ||
@@ -683,6 +680,9 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) | |||
683 | } else if (!(ctype_isptr(ct->info) || ctype_isrefarray(ct->info))) { | 680 | } else if (!(ctype_isptr(ct->info) || ctype_isrefarray(ct->info))) { |
684 | goto err_type; | 681 | goto err_type; |
685 | } | 682 | } |
683 | } else if (tref_isnil(tr)) { | ||
684 | tr = lj_ir_kptr(J, NULL); | ||
685 | ct = ctype_get(cts, CTID_P_VOID); | ||
686 | } else if (tref_isinteger(tr)) { | 686 | } else if (tref_isinteger(tr)) { |
687 | ct = ctype_get(cts, CTID_INT32); | 687 | ct = ctype_get(cts, CTID_INT32); |
688 | } else if (!tref_isnum(tr)) { | 688 | } else if (!tref_isnum(tr)) { |