aboutsummaryrefslogtreecommitdiff
path: root/forth/tests
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2015-02-24 09:16:20 -0600
committerJoel Martin <github@martintribe.org>2015-02-24 09:16:20 -0600
commitff26ebdb816da07b28b29073868994fc7eabf8d1 (patch)
treeee0e08f5226525cb4885512e07ae53c30f185990 /forth/tests
parent2a42d8274072c44dd2d83762cc27cd810f5b8452 (diff)
parenta631063f3fa2eaed473369b376a5499df92209bd (diff)
downloadmal-ff26ebdb816da07b28b29073868994fc7eabf8d1.tar.gz
mal-ff26ebdb816da07b28b29073868994fc7eabf8d1.zip
Merge pull request #8 from Chouser/forth3
Forth: Interop and perf updates
Diffstat (limited to 'forth/tests')
-rw-r--r--forth/tests/stepA_interop.mal41
1 files changed, 41 insertions, 0 deletions
diff --git a/forth/tests/stepA_interop.mal b/forth/tests/stepA_interop.mal
new file mode 100644
index 0000000..c4a0e75
--- /dev/null
+++ b/forth/tests/stepA_interop.mal
@@ -0,0 +1,41 @@
+;; Basic interop
+(. 5 'MalInt.)
+;=>5
+(. 11 31 '+ 'MalInt.)
+;=>42
+(. "greetings" 'MalString.)
+;=>"greetings"
+(. "hello" 'type 'cr 'mal-nil)
+; hello
+;=>nil
+
+;; Interop on non-literals
+(. (+ 15 27) 'MalInt.)
+;=>42
+(let* [a 17] (. a 25 '+ 'MalInt.))
+;=>42
+(let* [a "hello"] (. a 1 '- 'MalString.))
+;=>"hell"
+
+;; Use of annoyingly-named forth words
+(. 1 'MalInt. (symbol ",") 'here (symbol "@"))
+;=>1
+(let* (i 'MalInt.) (. 5 i))
+;=>5
+(let* (comma (symbol ",") fetch (symbol "@")) (. 'here 42 'MalInt. comma fetch))
+;=>42
+
+;; Multiple .-forms interacting via heap memory and mal locals
+(def! string-parts (fn* (s) (. s 'MalInt. 'swap 'MalInt. 'here '-rot (symbol ",") (symbol ",") 'here>MalList)))
+(first (rest (string-parts "sketchy")))
+;=>7
+(def! prn-chars (fn* (start count) (if (> count 0) (do (prn (. start 1 'MalString.)) (prn-chars (+ start 1) (- count 1))))))
+(let* (msg (string-parts "sketchy")) (prn-chars (first msg) (first (rest msg))))
+; "s"
+; "k"
+; "e"
+; "t"
+; "c"
+; "h"
+; "y"
+;=>nil