about summary refs log tree commit diff stats
path: root/awk/forth/test.forth
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2025-01-02 07:31:09 -0500
committerelioat <elioat@tilde.institute>2025-01-02 07:31:09 -0500
commite170508a1a6ab735b97d79369c1d6fc624ff57b9 (patch)
tree6e148475ad824d408f4373b4602c55aa4a5ecf00 /awk/forth/test.forth
parent9c4bde6f5e44454a6c1db0a53cb4b94732711272 (diff)
downloadtour-e170508a1a6ab735b97d79369c1d6fc624ff57b9.tar.gz
*
Diffstat (limited to 'awk/forth/test.forth')
-rw-r--r--awk/forth/test.forth70
1 files changed, 70 insertions, 0 deletions
diff --git a/awk/forth/test.forth b/awk/forth/test.forth
new file mode 100644
index 0000000..c743478
--- /dev/null
+++ b/awk/forth/test.forth
@@ -0,0 +1,70 @@
+( Basic Forth test suite )
+
+testing Basic stack operations
+5 dup . . test 5 test 5
+
+testing Addition
+3 4 + test 7
+
+testing Subtraction
+10 3 - test 7
+
+testing Multiplication
+6 7 * test 42
+
+testing Division
+20 4 / test 5
+
+testing Stack manipulation - rot
+1 2 3 rot test 1
+
+testing Stack manipulation - drop
+1 2 3 drop test 2
+
+testing Stack manipulation - nip
+1 2 3 nip test 3
+
+testing Stack manipulation - tuck
+1 2 tuck test 2
+
+testing Stack manipulation - over
+1 2 over test 1
+
+testing Variables
+variable x
+5 x !
+x @ test 5
+10 x !
+x ? ( should print 10 )
+
+testing Negate
+5 negate test -5
+
+testing Absolute value
+-7 abs test 7
+
+testing Maximum
+3 8 max test 8
+
+testing Minimum
+3 8 min test 3
+
+testing Modulo
+17 5 mod test 2
+
+testing Equality
+5 5 = test 1
+5 6 = test 0
+
+testing Word definition
+: square dup * ;
+5 square test 25
+
+testing Complex word definition
+variable counter
+: increment-counter counter @ 1 + counter ! ;
+5 counter !
+increment-counter
+counter @ test 6
+
+bye 
\ No newline at end of file