~vdupras/duskos

870b813930f7084ac4e41e5fb0afe536d5d4f4c1 — Virgil Dupras 1 year, 1 month ago e416cfb
halcc: no no, this :?swap thing is stupid

Far from all binops can do swapping like that! but some can...
1 files changed, 5 insertions(+), 8 deletions(-)

M fs/comp/c/egen.fs
M fs/comp/c/egen.fs => fs/comp/c/egen.fs +5 -8
@@ 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 ;