commit e1b098643da1705e2bb0c4da64911432ded32325
parent 0bcc434a07e05ccb176a83d857d71de1fe648a30
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sun, 19 Mar 2023 18:01:14 -0400
halcc: add static tmp space to solve argument swapping problems
Diffstat:
3 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/fs/comp/c/egen.fs b/fs/comp/c/egen.fs
@@ -77,23 +77,18 @@ swappable _+, +, swappable _*, *,
swappable _&, and, swappable _^, xor, swappable _|, or,
: fixed doer ' , does> @ ( left right w ) >r
- over Result :>W Result :hal# r> execute ;
+ Result :?>tmp over Result :>W r> execute ;
fixed _-, -, fixed _/, /, fixed _%, %,
fixed _<<, <<, fixed _>>, >>,
: assign doer ' , does> @ ( left right w ) >r
- Result :>W W>A, dup Result :hal# lea, W<>A, \ A='left W=right
- Result :hal# r> execute A) !, Result :W ;
+ Result :?>tmp over Result :hal# lea, W>A, ( res-w rightop )
+ over Result :>W r> execute A) !, ;
assign _=, drop assign _+=, +,
assign _*=, *, assign _/=, /, assign _%=, %,
assign _&=, and, assign _^=, xor, assign _|=, or,
-
-\ TODO: deduplicate
-: rassign doer ' , does> @ ( left right w ) >r
- Result :>W W>A, dup Result :hal# lea, W<>A, \ A='left W=right
- Result :hal# dup @!, r> execute A) !, Result :W ;
-rassign _-=, -, rassign _/=, /, rassign _%=, %,
-rassign _<<=, <<, rassign _>>=, >>,
+assign _-=, -, assign _/=, /, assign _%=, %,
+assign _<<=, <<, assign _>>=, >>,
\ Our implementation of "x ? y : z" suffers a significant limitation because
\ we're single pass: by the time _? is called, it's possible that code
diff --git a/fs/comp/c/expr.fs b/fs/comp/c/expr.fs
@@ -34,6 +34,12 @@ struct[ Result
: :isW? ( self -- f ) type W = ;
: :const# dup :isconst? _assert arg ;
: :>PS :>W dup, PS+ ;
+ \ When we need semi-temporary space, PS is the way to go, but it's a bit less
+ \ efficient than static storage. Sometimes, we need very short term storage.
+ \ This temporary space if for that. But it has to be used immediately.
+ create _tmp 0 ,
+ \ Free up W by sending it to _tmp (if needed).
+ : :?>tmp ( self -- halop ) dup :isW? if drop _tmp m) dup !, else :hal# then ;
]struct
BOPSCNT wordtbl _tbl ( a b -- n )
diff --git a/fs/comp/c/gen.fs b/fs/comp/c/gen.fs
@@ -1,6 +1,6 @@
-\ C compiler parse+generate
+\ C compiler parse+generate main entry point
\ In this unit, we are fed with tokens, we parse it, then we generate native
-\ code through the HAL.
+\ code through the HAL. The "cparse" word is the main entry point.
require /sys/scratch.fs
?f<< /lib/str.fs
?f<< /lib/wordtbl.fs