commit 51f8349d8654b45b3ba7f062180987d61ebafdf0
parent 026253cc36dcdd2a5995868ddc127e5665e57783
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sat, 18 Mar 2023 13:45:38 -0400
hal: transfer all relevant tests from CC vm to HAL
Diffstat:
2 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/fs/tests/asm/hal.fs b/fs/tests/asm/hal.fs
@@ -87,4 +87,69 @@ code test9 ( n -- n ) \ returns 42 if arg >= 10, 54 otherwise
54 LIT>W, exit,
5 test9 54 #eq
15 test9 42 #eq
+
+\ function calls
+code test10 ( n -- n-42 )
+ dup,
+ 42 LIT>W,
+ ' test1 execute,
+ exit,
+54 test10 12 #eq
+
+\ variable op width
+here ," hello" ( a )
+code test11 ( n -- c )
+ dup,
+ ( a ) LIT>W,
+ PSP) +, nip,
+ W) 8b) @,
+ exit,
+0 test11 'h' #eq
+1 test11 'e' #eq
+
+\ Testing that +, doesn't affect target memory location
+here 42 , here swap , ( pc of *int )
+code test12 ( -- n )
+ dup,
+ ( pc ) LIT>W,
+ W) @, W>A,
+ A) @,
+ 1 W+n, \ result in W, not in memory location
+ A) +, \ 42+43, not 43+43
+ exit,
+test12 85 #eq
+
+\ a rewrite of ptrset() from test.c for more precise testing
+code test13 ( -- n )
+ dup, -8 rs+,
+ 42 LIT>W, RSP) !,
+ RSP) lea, RSP) 4 +) !,
+ 54 LIT>W,
+ RSP) 4 +) [!],
+ RSP) @,
+ 8 rs+, exit,
+test13 54 #eq
+
+\ Branching with intermediate results. Check for PS leaks.
+create myarray 1 , 2 , 3 , 0 ,
+\ Equivalent: int i = 0; int *b = myarray; do ++i; while (*(b++)); return i;
+code test14 ( -- n )
+ dup, -4 rs+,
+ 0 LIT>W, RSP) !, \ i=0
+ myarray LIT>A,
+ begin
+ 1 RSP) [+n],
+ A) @,
+ 4 A+n,
+ W=0>Z, NZ) branchC, drop
+ RSP) @, 4 rs+, exit,
+test14 4 #eq
+scnt 0 #eq
+
+\ i386 didn't allow << and >> with non-const right operand
+code test15 ( n n -- n )
+ PSP) @!,
+ PSP) <<,
+ nip, exit,
+$42 4 test15 $420 #eq
testend
diff --git a/posix/hal.fs b/posix/hal.fs
@@ -8,3 +8,5 @@ create _tmp 0 ,
: tmp> _tmp m) @, ;
: -, ( operand -- ) >tmp @, dup, tmp> compile -^ ;
: *, ( operand -- ) >tmp @, dup, tmp> compile * ;
+: <<, ( operand -- ) >tmp @, dup, tmp> PSP) @!, compile lshift ;
+: >>, ( operand -- ) >tmp @, dup, tmp> PSP) @!, compile rshift ;