commit b1a35c900a35aa84b4238949f40a62aa07c8d3f4
parent 62bb24b80724a4e54bd419ee8cc3cdfd59bf5070
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sun, 18 Sep 2022 08:13:04 -0400
cc/gen: simplify VMOp selection
We are no longer tied to a specific op! by making all operations select operands
with "selop^", we can simplify the whole op selection logic. It doesn't matter
anymore whether op1 or op2 is selected.
Diffstat:
2 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/fs/cc/gen.fs b/fs/cc/gen.fs
@@ -195,8 +195,8 @@ ASTIDCNT wordtbl gentbl ( node -- )
dup rot to Function cursf ( cursf )
r@ to Declare address ( )
r@ Node firstchild ?dup if ( node )
- selop1 gennode ( value in op1 ) op1<>op2
- selop1 r@ decl>op vmmov,
+ gennode selop^ ( value in op^ )
+ r@ decl>op ( dst in op ) vmmov,
then rdrop
then ;
'w genchildren ( Unit )
@@ -239,19 +239,18 @@ ASTIDCNT wordtbl gentbl ( node -- )
\ See "Binary op resolution strategy" in opening comment
:w ( BinaryOp )
_debug if ." binop: " dup printast nl> then
- selectedop >r ( node ) >r
+ >r \ V1=node
r@ bopgentblpre r@ Op opid wexec ( node )
Node firstchild dup Node nextsibling swap ( n2 n1 )
over needs2ops? if \ n2 == 2ops
\ Resolve n2 before n1
swap gennode \ result in op1
dup needs2ops? if \ both need 2ops
- vmop :push rot gennode selop2 vmop :pop else
- selop2 gennode op1<>op2 then
+ vmop :push rot gennode vmop^ :pop else
+ selop^ gennode then
else \ nothing special needed, regular resolution
- selop1 gennode selop2 gennode then
- selop1 bopgentblpost r> Op opid wexec
- r> ( selectedop ) if op1<>op2 else selop1 then ;
+ gennode selop^ gennode selop^ then
+ bopgentblpost r> Op opid wexec ;
\ TODO: this doesn't work with lvalues yet
:w ( List )
dup Node :childcount dup 1+ 4 * syspad :allot dup >r ( node len a )
@@ -280,11 +279,11 @@ ASTIDCNT wordtbl gentbl ( node -- )
vmop loc VM_*CONSTANT = if vmop arg wordfunctype else TYPE_VOID then then
( node type ) swap vmop :push rot ( type oparg optype node )
\ pass arguments
- selop1 Node firstchild begin ( argnode )
+ Node firstchild begin ( argnode )
Node nextsibling ?dup while ( argnode )
dup gennode vmcallarg, repeat
\ call
- vmop :pop vmcall, ( type ) if selop1 vmpspop, then ;
+ vmop :pop vmcall, ( type ) if vmpspop, then ;
:w ( For )
Node firstchild dup _assert dup gennode ops$ ( exprnode ) \ initialization
here swap ( loop_addr node )
diff --git a/fs/cc/vm/commonlo.fs b/fs/cc/vm/commonlo.fs
@@ -37,7 +37,7 @@ struct[ VMOp
\ Initialize op to VM_NONE, "freeing" any resource it held.
: :init VM_NONE over to loc TYPE_INT swap to type ;
: :loclo loc $f and ;
- \ Is op a pointer?
+ \ Is loc a pointer?
: :pointer? loc $10 and bool ;
: :isconst? loc VM_CONSTANT = ;
: :noop# loc VM_NONE = _assert ;
@@ -61,12 +61,9 @@ vmop :self to vmop^ other
: _sel ['] vmop rebind vmop other ['] vmop^ rebind ;
: selop1 ( -- ) operands _sel ;
: selop2 ( -- ) operands VMOp SZ + _sel ;
-: selectedop ( -- n ) \ 0 == Op1 1 == Op2
- vmop :self operands <> ;
: selop^ vmop other _sel ;
: .ops
- selectedop .x1 spc>
vmop loc .x1 spc> vmop type printtype spc> vmop arg .x spc>
vmop^ loc .x1 spc> vmop^ type printtype spc> vmop^ arg .x nl> ;
@@ -81,7 +78,3 @@ vmop :self to vmop^ other
: sf+>op ( off -- ) noop# VM_*STACKFRAME to vmop loc to vmop arg ;
: ps+>op ( off -- ) noop# VM_*ARGSFRAME to vmop loc to vmop arg ;
: mem>op ( n -- ) noop# VM_*CONSTANT to vmop loc to vmop arg ;
-
-\ Swap op1 and op2 locs/args
-: op1<>op2
- vmop :push vmop^ :push vmop :pop vmop^ :pop ;