aboutsummaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 16:49:25 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 16:49:40 +0330
commitaadfdb87fdb42b42434358e643da8c98dd4647b2 (patch)
tree27b8eb749b600c44fb8f1159cfcce15cdad30c5e /src/compiler
parentenum: a member is defined as soon as it is declared, so later values can name... (diff)
bool: a value stored into a bool is normalised to 0 or 1 (appendix b.2.6)
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/lex.zc5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/compiler/lex.zc b/src/compiler/lex.zc
index 0348cae..d06b81b 100644
--- a/src/compiler/lex.zc
+++ b/src/compiler/lex.zc
@@ -298,6 +298,11 @@ int fcoerce(word dst) {
if (dst == tf32 && xty != tf32 && !ispk(xty)) { xenh("zf2s"); xenh("zs2f"); xty = tf32; }
return 0;
}
+ if (dst[0] == TY_BOOL && xty[0] != TY_BOOL) { // bool holds 0 or 1: any nonzero value is 1 (spec 2.1)
+ if (xfloat) { op(OP_FLIT); emit(0); op(OP_FEQ); lit(1); op(18); xfloat = 0; }
+ else { lit(0); op(O_PICK); lit(0); op(O_SWAP); op(O_SUB); op(17); lit(63); op(19); lit(0); op(O_SWAP); op(O_SUB); }
+ xty = tbool; return 0;
+ }
if (!xfloat) {
if (tbytes(dst) && !samesz(dst, xty)) tnorm(dst);
return 0;