From 0d7cb228076354f893527bce2d426e21697832a9 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sat, 15 Jan 2022 22:40:01 -0800 Subject: 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. --- csc/macros-test.csc | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) (limited to 'csc/macros-test.csc') 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))) -- cgit v1.3.1