duskos

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

commit 870b813930f7084ac4e41e5fb0afe536d5d4f4c1
parent e416cfb597c148dbb48a36190fa7cf5b391acb3d
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Sun, 19 Mar 2023 11:43:54 -0400

halcc: no no, this :?swap thing is stupid

Far from all binops can do swapping like that! but some can...

Diffstat:
Mfs/comp/c/egen.fs | 13+++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/fs/comp/c/egen.fs b/fs/comp/c/egen.fs @@ -40,11 +40,7 @@ struct[ Result CONST of = arg i) endof _err endcase ; : :isconst? ( self -- f ) type CONST = ; - \ Sort two result in "correct" order. If one of the ops is a W, it goes left. - \ If any of the results is a const, it goes right. After a :?swap, you can - \ check if both args are const by only checking the left one. - : :?swap ( left right -- left right ) - dup type W = if swap else over :isconst? if swap then then ; + : :isW? ( self -- f ) type W = ; ]struct alias noop parseExpression ( tok -- res ) \ forward declaration @@ -93,9 +89,10 @@ UOPSCNT wordtbl _tbl ( res -- res ) endcase ; current ' parseFactor realias -: binop doer ' , does> @ ( left right w ) >r - Result :?swap over Result :>W Result :hal# r> execute ; -binop _+, +, binop _*, *, +\ ops that can freely swap their operands +: swappable doer ' , does> @ ( left right w ) >r + dup Result :isW? if swap then over Result :>W Result :hal# r> execute ; +swappable _+, +, swappable _*, *, : _=, ( left right ) Result :>W Result :hal# !, Result :W ;