duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 54a545208fc56d8d1aafe9b3dab2d5510749b132
parent 6a575fc03fe19f55f8ffa9eadd4e1f5bb91b99b8
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Wed, 15 Jun 2022 05:50:36 -0400

cc: improve vm.fs

Add vmprelude, vmret, pushresult, popresult,

Diffstat:
Mfs/cc/vm.fs | 27++++++++++++++++++++++++---
Mfs/tests/cc/vm.fs | 23++++++++++++++++++++---
2 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/fs/cc/vm.fs b/fs/cc/vm.fs @@ -64,6 +64,8 @@ VM_NONE value operand \ For VM_CONSTANT, this contains the actual value \ For VM_STACKFRAME, this contains the SF offset 0 value operandarg +0 value argsz \ size of the argument portion of the SF. +0 value locsz \ size of the "local vars" portion of the SF. : vm$ 0 to resultset? VM_NONE to operand ; @@ -78,6 +80,8 @@ VM_NONE value operand ebx else _err then then VM_NONE to operand ; +: result! 1 to resultset? ; + \ Force current operand to be copied to the "alternate" register : operand>reg ( -- ) operand VM_REGISTER = not if @@ -91,6 +95,23 @@ VM_NONE value operand resultset? not _assert eax operandAsm mov, ; -: vmadd, eax operandAsm add, ; -: vmsub, eax operandAsm sub, ; -: vmmul, operand>reg operandAsm mul, ; +\ generate function prelude code by allocating "locsz" bytes on PS. +: vmprelude, ( argsz locsz -- ) + to locsz to argsz + ebp locsz i32 sub, ; +\ 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, ; +: pushresult, resultset? _assert eax push, 0 to resultset? ; +: popresult, + VM_NONE operand = _assert + VM_REGISTER to operand + ebx pop, ; +: vmadd, eax operandAsm add, result! ; +: vmsub, eax operandAsm sub, result! ; +: vmmul, operand>reg operandAsm mul, result! ; diff --git a/fs/tests/cc/vm.fs b/fs/tests/cc/vm.fs @@ -7,14 +7,31 @@ testbegin \ binop[+](binop[*](const[2],const[3]),const[1]) vm$ code test1 + 0 0 vmprelude, 2 const>operand operand>result 3 const>operand vmmul, 1 const>operand vmadd, - ebp 4 i32 sub, - [ebp] eax mov, - ret, + vmret, test1 7 #eq + +\ binop[+](binop[-](const[3], const[1]),binop[*](const[2],const[3])) +vm$ +code test2 + 0 0 vmprelude, + 3 const>operand + operand>result + 1 const>operand + vmsub, + pushresult, + 2 const>operand + operand>result + 3 const>operand + vmmul, + popresult, + vmadd, + vmret, +test2 8 #eq testend