aboutsummaryrefslogtreecommitdiffstats
path: root/csc/macros-test.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-01-15 22:40:01 -0800
committerRose Hogenson <rhogenson@posteo.net>2022-01-15 22:40:01 -0800
commit0d7cb228076354f893527bce2d426e21697832a9 (patch)
treefa12d1afff4cdb077437b11544c9ef8f299cd88e /csc/macros-test.csc
parentWrite a first draft macro expander. (diff)
downloadchromatopelma-0d7cb228076354f893527bce2d426e21697832a9.tar.zst
Finish the macro expander.
It works!! At least it passes all the test cases. Next I will: 1. finish the builtins, 2. add a conversion to IR2 in continuation passing style, 3. add a compiler from IR2 to bytecode, 4. and add an option to the frontend compiler to generate a standalone executable.
Diffstat (limited to 'csc/macros-test.csc')
-rw-r--r--csc/macros-test.csc152
1 files changed, 152 insertions, 0 deletions
diff --git a/csc/macros-test.csc b/csc/macros-test.csc
index 007b881..4cc8efa 100644
--- a/csc/macros-test.csc
+++ b/csc/macros-test.csc
@@ -10,3 +10,155 @@
(assert-equal
(make-constant '(test 1 2 3))
(expand '(quote (test 1 2 3)) test-environment)))
+
+
+(test builtin-syntax-rules-literal
+ (assert-equal
+ (make-constant 1)
+ (expand
+ '(builtin-let-syntax
+ (foo
+ (syntax-rules (a b)
+ ((foo a)
+ 0)
+ ((foo b)
+ 1)))
+ (foo b))
+ test-environment)))
+
+
+(test builtin-syntax-rules-underscore
+ (assert-equal
+ (make-constant 0)
+ (expand
+ '(builtin-let-syntax
+ (foo
+ (syntax-rules ()
+ ((foo _) 0)))
+ (foo ignored))
+ test-environment)))
+
+
+(test builtin-syntax-rules-substitution
+ (assert-equal
+ (make-constant 5)
+ (expand
+ '(builtin-let-syntax
+ (foo
+ (syntax-rules ()
+ ((foo x) x)))
+ (foo 5))
+ test-environment)))
+
+
+(test builtin-syntax-rules-nil
+ (assert-equal
+ (make-constant 1)
+ (expand
+ '(builtin-let-syntax
+ (foo
+ (syntax-rules ()
+ ((foo x) 0)
+ ((foo) 1)))
+ (foo))
+ test-environment)))
+
+
+(test builtin-syntax-rules-improper-list
+ (assert-equal
+ (make-constant 1)
+ (expand
+ '(builtin-let-syntax
+ (foo
+ (syntax-rules ()
+ ((foo a . b) a)))
+ (foo 1 2 3))
+ test-environment)))
+
+
+(test builtin-syntax-rules-quoted
+ (assert-equal
+ (make-constant 'a)
+ (expand
+ '(builtin-let-syntax
+ (foo
+ (syntax-rules ()
+ ((foo x) (quote x))))
+ (foo a))
+ test-environment)))
+
+
+(test builtin-syntax-rules-constant
+ (assert-equal
+ (make-constant 2)
+ (expand
+ '(builtin-let-syntax
+ (foo
+ (syntax-rules ()
+ ((foo "abc") 0)
+ ((foo "def") 1)
+ ((foo "ghi") 2)))
+ (foo "ghi"))
+ test-environment)))
+
+
+(test builtin-syntax-rules-ellipsis
+ (assert-equal
+ (make-constant 5)
+ (expand
+ '(builtin-let-syntax
+ (foo
+ (syntax-rules ()
+ ((foo x ...) (x ...))))
+ (foo quote 5))
+ test-environment)))
+
+
+(test builtin-syntax-rules-ellipsis-improper
+ (assert-equal
+ (make-constant 5)
+ (expand
+ '(builtin-let-syntax
+ (foo
+ (syntax-rules ()
+ ((foo x ... . y) (x ... y))))
+ (foo quote . 5))
+ test-environment)))
+
+
+(test builtin-syntax-rules-ellipsis-zip
+ (assert-equal
+ (make-constant '((1 . 3) (2 . 4)))
+ (expand
+ '(builtin-let-syntax
+ (zip
+ (syntax-rules ()
+ ((zip (x ...) (y ...))
+ (quote ((x . y) ...)))))
+ (zip (1 2) (3 4)))
+ test-environment)))
+
+
+(test builtin-syntax-rules-ellipsis-nested
+ (assert-equal
+ (make-constant '(1 2 3 4 5))
+ (expand
+ '(builtin-let-syntax
+ (append
+ (syntax-rules ()
+ ((append (x ...) ...)
+ (quote (x ... ...)))))
+ (append (1 2) (3 4) () (5)))
+ test-environment)))
+
+
+(test builtin-syntax-rules-ellipsis-custom
+ (assert-equal
+ (make-constant 5)
+ (expand
+ '(builtin-let-syntax
+ (foo
+ (syntax-rules ::: ()
+ ((foo x :::) (x :::))))
+ (foo quote 5))
+ test-environment)))