duskos

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

commit 819afcb88377511de71e57f2297dd600ea08a473
parent 5ffc1675e8879abb6adf38497b86c09a5b3adc7e
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Fri, 31 Mar 2023 13:40:09 -0400

halcc: consolidate

Diffstat:
Mfs/comp/c/expr.fs | 30+++++++++++-------------------
Mfs/tests/comp/c/cc.fs | 2+-
Mfs/tests/comp/c/test2.c | 5+++++
3 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/fs/comp/c/expr.fs b/fs/comp/c/expr.fs @@ -20,15 +20,14 @@ struct[ Result sfield arg \ numerical arg, for PS, CONST, ARRAY sfield target \ another Result. for REF, DEREF sfield cdecl - sfield lvl \ lvl changed applied within the expression - sfield blvl \ Bottom Level + sfield lvl \ Current indirection levels to the base type \ There can only be one result using W at once. Whenever a W result is \ created, it takes the lock. If it's already taken, there's an error. 0 value currentW \ link to Result : :Wfree# currentW if abort" W is already taken!" then ; - : :new ( arg type -- res ) SZ syspad :[ , , 0 , 0 , 0 , 0 , syspad :] ; + : :new ( arg type -- res ) SZ syspad :[ , , 0 , 0 , 0 , syspad :] ; : :none ( -- res ) 0 NONE :new ; : :const ( n -- res ) CONST :new ; : :W ( -- res ) :Wfree# 0 W :new dup to currentW ; @@ -46,30 +45,25 @@ struct[ Result dup arg .x spc> dup target ?dup if '{' emit _:. '}' emit spc> then dup cdecl ?dup if CDecl :. spc> then - dup lvl . spc> blvl . spc> - ." W=" currentW bool . ; + dup lvl . spc> ." W=" currentW bool . ; : :. _:. nl> ; : :W! ( self -- ) dup to currentW W swap to type ; - : :lvl lvl ; - \ Copy meta information (basesz, lvl, blvl from "other" result + \ Copy meta information (basesz, lvl from "other" result : :copymeta ( other self -- ) over cdecl over to cdecl - over lvl over to lvl - swap blvl swap to blvl ; + swap lvl swap to lvl ; : :& ( self -- res ) dup :iscdecl? _assert 0 REF :new 2dup :copymeta tuck to target ; : :* ( self -- res ) - 0 DEREF :new 2dup :copymeta tuck to target 1 over to+ lvl ; + 0 DEREF :new 2dup :copymeta tuck to target -1 over to+ lvl ; : :cdecl ( cdecl -- res ) 0 CDECL :new ( cdecl res ) - 2dup to cdecl - swap CDecl :lvl over to blvl ( cdecl res ) ; + over CDecl :lvl over to lvl tuck to cdecl ; : :basesz cdecl ?dup if CDecl type typesize else 4 then ; : :unsigned? cdecl ?dup if typeunsigned? else 1 then ; : :cdecl# dup :iscdecl? _assert cdecl ; - : :nb) ( halop self -- halop ) - bi+ :lvl | blvl = if :basesz nb) else drop then ; + : :nb) ( halop self -- halop ) dup lvl if drop else :basesz nb) then ; \ Never changes W, never pushes to PS : :hal# ( self -- halop ) dup type case ( self ) CONST of = arg i) endof @@ -86,9 +80,7 @@ struct[ Result : :hal$ dup :hal# swap :release ; : :>W ( self -- ) dup :isW? if drop else - dup :hal# :Wfree# @, - 0 over to@! lvl neg over to+ blvl - dup to currentW W swap to type then ; + dup :hal# :Wfree# @, dup to currentW W swap to type then ; : :>W$ ( self -- ) dup :>W :release ; : :isconst? ( self -- f ) type CONST = ; : :iszero? bi arg 0 = | :isconst? and ; @@ -108,11 +100,11 @@ struct[ Result \ lvl=blvl our arisz is "basesz" (we add and subtract by chunks of the \ base type), otherwise it's 4 (we deal with pointers). : :*arisz ( self -- n ) \ pointer arithmetics multiplier - dup bi blvl | :lvl - case + dup lvl case 0 of = drop 1 endof 1 of = :basesz endof drop 4 endcase ; - : :toint ( self -- ) 0 over to cdecl 0 over to lvl 0 swap to blvl ; + : :toint ( self -- ) 0 over to cdecl 0 swap to lvl ; ]struct BOPSCNT wordtbl _tbl ( a b -- n ) diff --git a/fs/tests/comp/c/cc.fs b/fs/tests/comp/c/cc.fs @@ -59,10 +59,10 @@ forempty \ no crash 42 boolnot 0 #eq S" foobar" 2 get8b 'o' #eq S" foobar" 4 get8b 'b' #eq -testend \s S" foobar" dup 2 'X' set8b S" fXobar" #s= S" foobar" dup 6 'X' set8b S" foobaX" #s= typecast 1 #eq +testend \s 5 whilesum 15 #eq 5 dowhilesum 15 #eq create mydata 42 , $12345678 , $23456789 , diff --git a/fs/tests/comp/c/test2.c b/fs/tests/comp/c/test2.c @@ -230,3 +230,8 @@ char get8b(char *s, int i) { void set8b(char *s, int i, char c) { s[i] = c; } +int typecast() { + char x = $ff; + int y = 1; + return x == (char)(y-2); +}