commit 60b55f40768128f35c55d5c0b18caa3f5de02386
parent 54a545208fc56d8d1aafe9b3dab2d5510749b132
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Wed, 15 Jun 2022 06:11:27 -0400
cc: add stackframe args to the vm
Diffstat:
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/fs/asm.fs b/fs/asm.fs
@@ -93,7 +93,7 @@ $00e9 op jmp, $0f84 op jz, $0f85 op jnz,
isimm? if
dup 1+ c@ ( immreg ) swap 2 + c@ ( immreg immop ) modrm<imm, else
c@ src swap ( reg regop ) modrm2, then ;
-$81 0 $01 op add, $81 7 $39 op cmp, $81 5 29 op sub, $f7 0 $85 op test,
+$81 0 $01 op add, $81 7 $39 op cmp, $81 5 $29 op sub, $f7 0 $85 op test,
\ tgt or-ed in
: op ( op -- ) doer c, does> ( a -- ) c@ tgtid or c, asm$ ;
diff --git a/fs/cc/vm.fs b/fs/cc/vm.fs
@@ -77,7 +77,9 @@ VM_NONE value operand
operand VM_CONSTANT = if
operandarg i32
else operand VM_REGISTER = if
- ebx else _err then then
+ ebx
+ else operand VM_STACKFRAME = if
+ operandarg [ebp]+ else _err then then then
VM_NONE to operand ;
: result! 1 to resultset? ;
@@ -91,6 +93,10 @@ VM_NONE value operand
VM_NONE operand = _assert
VM_CONSTANT to operand to operandarg ;
+: sf+>operand ( offset -- )
+ VM_NONE operand = _assert
+ VM_STACKFRAME to operand to operandarg ;
+
: operand>result ( -- )
resultset? not _assert
eax operandAsm mov, ;
@@ -98,12 +104,11 @@ VM_NONE value operand
\ generate function prelude code by allocating "locsz" bytes on PS.
: vmprelude, ( argsz locsz -- )
to locsz to argsz
- ebp locsz i32 sub, ;
+ locsz if ebp locsz i32 sub, then ;
\ deallocate locsz and argsz. If result is set, keep a 4b in here and push the
\ result there.
: vmret,
locsz argsz + resultset? if 4 - then
- ." foo " dup .x nl>
?dup if ebp i32 add, then
resultset? if [ebp] eax mov, then
ret, ;
diff --git a/fs/tests/cc/vm.fs b/fs/tests/cc/vm.fs
@@ -34,4 +34,15 @@ code test2
vmadd,
vmret,
test2 8 #eq
+
+vm$
+code test3 \ sub 2 args
+ 8 0 vmprelude,
+ 4 sf+>operand
+ operand>result
+ 0 sf+>operand
+ vmsub,
+ vmret,
+54 12 test3 42 #eq
+
testend