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-12 12:56:31 -0500
committerelioat <elioat@tilde.institute>2025-01-12 12:56:31 -0500
commitdf1bbf51de157fdffd189a9df36544d0a1e1375f (patch)
treeeca0a8ed7a311c379d4a1dc1cdc44525cff0be8e /awk/forth/test.forth
parente5ca28ac779b9c4e9e981694853940f199b0e83d (diff)
downloadtour-df1bbf51de157fdffd189a9df36544d0a1e1375f.tar.gz
*
Diffstat (limited to 'awk/forth/test.forth')
-rw-r--r--awk/forth/test.forth34
1 files changed, 34 insertions, 0 deletions
diff --git a/awk/forth/test.forth b/awk/forth/test.forth
new file mode 100644
index 0000000..1beedaf
--- /dev/null
+++ b/awk/forth/test.forth
@@ -0,0 +1,34 @@
+\ Test arithmetic operations
+10 5 + .          \ Should print 15
+10 5 - .          \ Should print 5
+10 5 * .          \ Should print 50
+10 5 / .          \ Should print 2
+
+\ Test stack manipulation
+1 2 3 .s          \ Should show 3 values: 1 2 3
+dup .             \ Should print 3 again
+drop .            \ Should print 2
+swap .s           \ Should show 2 1
+over .s           \ Should show 2 1 2
+rot .s            \ Should show 1 2 3
+
+\ Test comparisons
+5 5 = .           \ Should print -1 (true)
+5 3 < .          \ Should print 0 (false)
+3 5 > .          \ Should print 0 (false)
+
+\ Test conditionals
+10 20 if .s then  \ Should print 1 2 (since the condition is true)
+10 5 if .s else 1 then  \ Should print 1 (since the condition is false)
+
+\ Test user-defined words
+: square dup * ;   \ Define a word to square a number
+4 square .         \ Should print 16
+
+: add_three 1 2 + + ;  \ Define a word to add three numbers
+1 2 add_three .    \ Should print 6
+
+\ List all words
+words              \ Should list all available words
+
+bye                \ Exit the interpreter 
\ No newline at end of file