diff options
Diffstat (limited to 'src/lj_cconv.c')
-rw-r--r-- | src/lj_cconv.c | 44 |
1 files changed, 14 insertions, 30 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. */ |