duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit b6b1e0488543da7504572b269e5a41eac071ce16
parent dfbe66c22d323eaec177fec8414dfdb2bb83f714
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Fri, 31 Mar 2023 21:26:47 -0400

halcc: make && a boolean operator

Diffstat:
Mfs/comp/c/egen.fs | 2+-
Mfs/tests/comp/c/cc.fs | 2+-
Mfs/tests/comp/c/test2.c | 38++++++++++++++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/fs/comp/c/egen.fs b/fs/comp/c/egen.fs @@ -48,7 +48,7 @@ UOPSCNT wordtbl uoptbl ( res -- res ) : _prep ( left right -- left halop ) dup Result :hasW? if swap then over Result :?>W Result :hal$ ; : _*, _prep *, ; : _&, _prep and, ; : _^, _prep xor, ; : _|, _prep or, ; -: _&&, _prep and, ; +: _&&, _prep W=0>Z, 0 Z) branchC, swap @, W=0>Z, [compile] then NZ) C>W, ; : _||, _prep or, W=0>Z, NZ) C>W, ; \ TODO: generalize CDecl hamonization (:copymeta below) : _+, ( left right -- res ) diff --git a/fs/tests/comp/c/cc.fs b/fs/tests/comp/c/cc.fs @@ -76,7 +76,6 @@ globdata 4 + 16b @ 42 #eq 1234 switchstmt 3 #eq 'A' switchstmt 2 #eq 5678 switchstmt 2 #eq -testend \s 2 3 binop1 1 #eq '2' binop2 44 #eq @@ -84,6 +83,7 @@ binop3 $605 #eq binop5 1 #eq binop6 $1fe #eq binop7 0 #eq +testend \s binop8 $ffffffab #eq binop9 $1234 #eq 123 12 binop10 1 #eq diff --git a/fs/tests/comp/c/test2.c b/fs/tests/comp/c/test2.c @@ -301,3 +301,41 @@ int switchstmt(int x) { } return y; } + +// Below this comment are simple construct that were buggy before +int binop1(int a, int b) { + int c; + c = a ^ b; + return c; +} +int binop2(int n) { + int x = 42; + x = x + n - '0'; + return x; +} +/* There used to be a bug where this type of comment with "'" char in it would + cause a tokenization error. */ +int binop3() { + return global2[2] << 8 | global2[1]; +} +// assigning a pointer to another pointer doesn't trigger pointer arithmetics +void binop4() { + globfuncs[1] = negate; +} +// properly "boolify" arguments of logical operators +int binop5() { + int x = 2; + return x && 1; +} +// the i386 VM performed this add in 8b mode, not carrying the $100. +unsigned int binop6() { + unsigned int x = $ff; + unsigned char y = $ff; + return x + y; +} +// properly "boolify" arguments of logical operators, again... +int binop7() { + int x = 2; + int y = 0; + return x && y; +}