commit a5ad9b0bae39b077e5d32433f963d3f43edbd18c
parent b875ee51be39e376a4fd705fc3725f840bfe77a6
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Thu, 15 Sep 2022 07:56:46 -0400
cc/vm/forth: add missing "swap" compile in vmmov,
The test for it is coming in an upcoming commit. I'm doing the 8b/16b thing and
it's big.
Diffstat:
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fs/cc/vm/forth.fs b/fs/cc/vm/forth.fs
@@ -141,12 +141,14 @@ unop vm--op, 1-
postop vmop++, 1+
postop vmop--, 1-
+\ Just after having compiled an op, if the "other op" is TOS, we need to compile
+\ a "swap" to "unbury" it. We do it here.
+: swapifTOS optypelo VM_TOS = if compile swap then ;
+
\ 2 fields: signed op, unsigned op
: binop doer ' , ' , does> opsunsigned if CELLSZ + then @ ( w )
selop1 opCompile* opdeinit \ op1 is "lost" on PS
- selop2 hasop# optypelo VM_TOS = if
- \ if op2=TOS, we need to swap because our previous opCompile* buried it.
- compile swap then
+ selop2 hasop# swapifTOS
opCompile* opdeinit \ op2 is "lost" on PS
( w ) execute,
selop1 op>TOS ; \ result in op1 as VM_TOS
@@ -189,7 +191,7 @@ binop= vm>>=, rshift
: vmmov,
selop2 hasop# optype VM_CONSTARRAY = if _movarray, else
opCompile* opdeinit \ op2 is "lost" on PS
- selop1 &op>op opCompile* opdeinit compile ! then ;
+ selop1 swapifTOS &op>op opCompile* opdeinit compile ! then ;
\ Jumping
: ]vmjmp ( 'jump_addr -- ) here swap ! ;