diff options
Diffstat (limited to 'src/compiler/lex.zc')
| -rw-r--r-- | src/compiler/lex.zc | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/compiler/lex.zc b/src/compiler/lex.zc index 0348cae..712eff8 100644 --- a/src/compiler/lex.zc +++ b/src/compiler/lex.zc @@ -298,6 +298,12 @@ 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); } + if (compat(dst, xty)) xty = tbool; // (otherwise keep the type, so a type check after this still sees it) + return 0; + } if (!xfloat) { if (tbytes(dst) && !samesz(dst, xty)) tnorm(dst); return 0; @@ -423,6 +429,7 @@ int docblock(int nl) { doc_char(c); if (c == 10) bol = 1; } + if (ch < 0) { tline = line; serr("unterminated comment"); } while (dn && (dbuf[dn - 1] == 32 || dbuf[dn - 1] == 9 || dbuf[dn - 1] == 10 || dbuf[dn - 1] == 13)) dn--; doc_char(10); dlast = cl; docpending = 1; if (adj) dn = 0; @@ -484,6 +491,7 @@ int lex1() { if (docs_on) { docblock(nl); tglue = 0; continue; } nextch(); while (ch >= 0) { if (ch == '*') { nextch(); if (ch == '/') break; } else nextch(); } + if (ch < 0) { tline = line; serr("unterminated comment"); } // a /* with no */ (spec 1.2.2) nextch(); tglue = 0; continue; } tline = line; toff = cpos() - 1; tbuf[0] = '/'; oplex(1); return 0; |
