mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-08 07:34:07 +00:00
FFI: Cleanup some type conversions.
Remove pointless conversions to booleans. Allow assigning functions to function pointers.
This commit is contained in:
parent
0ec7f5ed92
commit
6e702d703e
@ -129,10 +129,9 @@ void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,
|
|||||||
switch (cconv_idx2(dinfo, sinfo)) {
|
switch (cconv_idx2(dinfo, sinfo)) {
|
||||||
/* Destination is a bool. */
|
/* Destination is a bool. */
|
||||||
case CCX(B, B):
|
case CCX(B, B):
|
||||||
*dp = *sp; /* Source operand already normalized. */
|
*dp = *sp; /* Source operand is already normalized. */
|
||||||
break;
|
break;
|
||||||
case CCX(B, I):
|
case CCX(B, I): {
|
||||||
case CCX(B, P): {
|
|
||||||
MSize i;
|
MSize i;
|
||||||
uint8_t b = 0;
|
uint8_t b = 0;
|
||||||
for (i = 0; i < ssize; i++) b |= sp[i];
|
for (i = 0; i < ssize; i++) b |= sp[i];
|
||||||
@ -147,17 +146,6 @@ void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,
|
|||||||
*dp = b;
|
*dp = b;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CCX(B, C): {
|
|
||||||
CType *sc = ctype_child(cts, s);
|
|
||||||
uint8_t c;
|
|
||||||
lj_cconv_ct_ct(cts, d, sc, &c, sp, flags);
|
|
||||||
lj_cconv_ct_ct(cts, d, sc, dp, sp + sc->size, flags);
|
|
||||||
*dp = (*dp | c);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CCX(B, A):
|
|
||||||
*dp = (sp != (uint8_t *)0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Destination is an integer. */
|
/* Destination is an integer. */
|
||||||
case CCX(I, B):
|
case CCX(I, B):
|
||||||
@ -347,7 +335,7 @@ void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,
|
|||||||
|
|
||||||
/* Destination is an array. */
|
/* Destination is an array. */
|
||||||
case CCX(A, A):
|
case CCX(A, A):
|
||||||
if ((flags & CCF_CAST) || (d->info & CTF_VLA) || d->size != s->size ||
|
if ((flags & CCF_CAST) || (d->info & CTF_VLA) || dsize != ssize ||
|
||||||
d->size == CTSIZE_INVALID || !lj_cconv_compatptr(cts, d, s, flags))
|
d->size == CTSIZE_INVALID || !lj_cconv_compatptr(cts, d, s, flags))
|
||||||
goto err_conv;
|
goto err_conv;
|
||||||
goto copyval;
|
goto copyval;
|
||||||
@ -376,23 +364,15 @@ int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid,
|
|||||||
CTInfo sinfo = s->info;
|
CTInfo sinfo = s->info;
|
||||||
lua_assert(!ctype_isenum(sinfo));
|
lua_assert(!ctype_isenum(sinfo));
|
||||||
if (ctype_isnum(sinfo)) {
|
if (ctype_isnum(sinfo)) {
|
||||||
uint8_t tmpbool;
|
|
||||||
uint8_t *dp;
|
|
||||||
CTypeID did;
|
|
||||||
if (!ctype_isbool(sinfo)) {
|
if (!ctype_isbool(sinfo)) {
|
||||||
if (ctype_isinteger(sinfo) && s->size > 4) goto copyval;
|
if (ctype_isinteger(sinfo) && s->size > 4) goto copyval;
|
||||||
dp = (uint8_t *)&o->n;
|
lj_cconv_ct_ct(cts, ctype_get(cts, CTID_DOUBLE), s,
|
||||||
did = CTID_DOUBLE;
|
(uint8_t *)&o->n, sp, 0);
|
||||||
} else {
|
/* Numbers are NOT canonicalized here! Beware of uninitialized data. */
|
||||||
dp = &tmpbool;
|
|
||||||
did = CTID_BOOL;
|
|
||||||
}
|
|
||||||
lj_cconv_ct_ct(cts, ctype_get(cts, did), s, dp, sp, 0);
|
|
||||||
/* Numbers are NOT canonicalized here! Beware of uninitialized data. */
|
|
||||||
if (did == CTID_BOOL)
|
|
||||||
setboolV(o, tmpbool);
|
|
||||||
else
|
|
||||||
lua_assert(tvisnum(o));
|
lua_assert(tvisnum(o));
|
||||||
|
} else {
|
||||||
|
setboolV(o, (*sp & 1));
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) {
|
} else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) {
|
||||||
/* Create reference. */
|
/* Create reference. */
|
||||||
@ -542,8 +522,12 @@ void lj_cconv_ct_tv(CTState *cts, CType *d,
|
|||||||
sid = ctype_cid(s->info);
|
sid = ctype_cid(s->info);
|
||||||
}
|
}
|
||||||
s = ctype_raw(cts, sid);
|
s = ctype_raw(cts, sid);
|
||||||
if (ctype_isenum(s->info)) s = ctype_child(cts, s);
|
if (ctype_isfunc(s->info)) {
|
||||||
goto doconv;
|
sid = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|sid), CTSIZE_PTR);
|
||||||
|
} else {
|
||||||
|
if (ctype_isenum(s->info)) s = ctype_child(cts, s);
|
||||||
|
goto doconv;
|
||||||
|
}
|
||||||
} else if (tvisstr(o)) {
|
} else if (tvisstr(o)) {
|
||||||
GCstr *str = strV(o);
|
GCstr *str = strV(o);
|
||||||
if (ctype_isenum(d->info)) { /* Match string against enum constant. */
|
if (ctype_isenum(d->info)) { /* Match string against enum constant. */
|
||||||
|
@ -133,10 +133,7 @@ static void crec_ct_ct(jit_State *J, CType *d, CType *s, TRef dp, TRef sp)
|
|||||||
case CCX(B, B):
|
case CCX(B, B):
|
||||||
goto xstore; /* Source operand is already normalized. */
|
goto xstore; /* Source operand is already normalized. */
|
||||||
case CCX(B, I):
|
case CCX(B, I):
|
||||||
case CCX(B, P):
|
|
||||||
case CCX(B, F):
|
case CCX(B, F):
|
||||||
case CCX(B, C):
|
|
||||||
case CCX(B, A):
|
|
||||||
/* NYI: specialize to the result of a comparison against 0. */
|
/* NYI: specialize to the result of a comparison against 0. */
|
||||||
goto err_nyi;
|
goto err_nyi;
|
||||||
|
|
||||||
@ -683,6 +680,9 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd)
|
|||||||
} else if (!(ctype_isptr(ct->info) || ctype_isrefarray(ct->info))) {
|
} else if (!(ctype_isptr(ct->info) || ctype_isrefarray(ct->info))) {
|
||||||
goto err_type;
|
goto err_type;
|
||||||
}
|
}
|
||||||
|
} else if (tref_isnil(tr)) {
|
||||||
|
tr = lj_ir_kptr(J, NULL);
|
||||||
|
ct = ctype_get(cts, CTID_P_VOID);
|
||||||
} else if (tref_isinteger(tr)) {
|
} else if (tref_isinteger(tr)) {
|
||||||
ct = ctype_get(cts, CTID_INT32);
|
ct = ctype_get(cts, CTID_INT32);
|
||||||
} else if (!tref_isnum(tr)) {
|
} else if (!tref_isnum(tr)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user