diff options
Diffstat (limited to 'lib/csc/macros-test.csc')
| -rw-r--r-- | lib/csc/macros-test.csc | 115 |
1 files changed, 78 insertions, 37 deletions
diff --git a/lib/csc/macros-test.csc b/lib/csc/macros-test.csc index def474f..2af86b7 100644 --- a/lib/csc/macros-test.csc +++ b/lib/csc/macros-test.csc @@ -68,7 +68,19 @@ (test builtin-quote (assert-equal - (make-constant '(test 1 2 3)) + (make-call-builtin 'cons + (list + (make-constant 'test) + (make-call-builtin 'cons + (list + (make-constant 1) + (make-call-builtin 'cons + (list + (make-constant 2) + (make-call-builtin 'cons + (list + (make-constant 3) + (make-constant '()))))))))) (expand-body 'main '((quote (test 1 2 3))) builtins-environment) @@ -80,12 +92,12 @@ (make-constant 1) (expand-body 'main '((let-syntax - (foo + ((foo (syntax-rules (a b) ((foo a) 0) ((foo b) - 1))) + 1)))) (foo b))) builtins-environment) transform-ir1)) @@ -96,9 +108,9 @@ (make-constant 0) (expand-body 'main '((let-syntax - (foo + ((foo (syntax-rules () - ((foo _) 0))) + ((foo _) 0)))) (foo ignored))) builtins-environment) transform-ir1)) @@ -109,9 +121,9 @@ (make-constant 5) (expand-body 'main '((let-syntax - (foo - (syntax-rules () - ((foo x) x))) + ((foo + (syntax-rules () + ((foo x) x)))) (foo 5))) builtins-environment) transform-ir1)) @@ -122,10 +134,10 @@ (make-constant 1) (expand-body 'main '((let-syntax - (foo + ((foo (syntax-rules () ((foo x) 0) - ((foo) 1))) + ((foo) 1)))) (foo))) builtins-environment) transform-ir1)) @@ -136,9 +148,9 @@ (make-constant 1) (expand-body 'main '((let-syntax - (foo + ((foo (syntax-rules () - ((foo a . b) a))) + ((foo a . b) a)))) (foo 1 2 3))) builtins-environment) transform-ir1)) @@ -149,9 +161,9 @@ (make-constant 'a) (expand-body 'main '((let-syntax - (foo + ((foo (syntax-rules () - ((foo x) (quote x)))) + ((foo x) (quote x))))) (foo a))) builtins-environment) transform-ir1)) @@ -162,11 +174,11 @@ (make-constant 2) (expand-body 'main '((let-syntax - (foo + ((foo (syntax-rules () ((foo "abc") 0) ((foo "def") 1) - ((foo "ghi") 2))) + ((foo "ghi") 2)))) (foo "ghi"))) builtins-environment) transform-ir1)) @@ -177,9 +189,9 @@ (make-constant 5) (expand-body 'main '((let-syntax - (foo + ((foo (syntax-rules () - ((foo x ...) (x ...)))) + ((foo x ...) (x ...))))) (foo quote 5))) builtins-environment) transform-ir1)) @@ -190,9 +202,9 @@ (make-constant 5) (expand-body 'main '((let-syntax - (foo + ((foo (syntax-rules () - ((foo x ... . y) (x ... y)))) + ((foo x ... . y) (x ... y))))) (foo quote . 5))) builtins-environment) transform-ir1)) @@ -200,13 +212,19 @@ (test builtin-syntax-rules-ellipsis-zip (assert-equal - (make-constant '((1 . 3) (2 . 4))) + (make-call-builtin 'cons + (list + (make-call-builtin 'cons (list (make-constant 1) (make-constant 3))) + (make-call-builtin 'cons + (list + (make-call-builtin 'cons (list (make-constant 2) (make-constant 4))) + (make-constant '()))))) (expand-body 'main '((let-syntax - (zip + ((zip (syntax-rules () ((zip (x ...) (y ...)) - (quote ((x . y) ...))))) + (quote ((x . y) ...)))))) (zip (1 2) (3 4)))) builtins-environment) transform-ir1)) @@ -214,13 +232,28 @@ (test builtin-syntax-rules-ellipsis-nested (assert-equal - (make-constant '(1 2 3 4 5)) + (make-call-builtin 'cons + (list + (make-constant 1) + (make-call-builtin 'cons + (list + (make-constant 2) + (make-call-builtin 'cons + (list + (make-constant 3) + (make-call-builtin 'cons + (list + (make-constant 4) + (make-call-builtin 'cons + (list + (make-constant 5) + (make-constant '()))))))))))) (expand-body 'main '((let-syntax - (append + ((append (syntax-rules () ((append (x ...) ...) - (quote (x ... ...))))) + (quote (x ... ...)))))) (append (1 2) (3 4) () (5)))) builtins-environment) transform-ir1)) @@ -231,9 +264,9 @@ (make-constant 5) (expand-body 'main '((let-syntax - (foo + ((foo (syntax-rules ::: () - ((foo x :::) (x :::)))) + ((foo x :::) (x :::))))) (foo quote 5))) builtins-environment) transform-ir1)) @@ -242,13 +275,13 @@ (test builtin-syntax-rules-define (assert-equal (make-library-define (make-library-ref 'exit 'main) - (make-lambda (test-ref 'args) (make-sequence (make-constant #f) (make-call-builtin 'exit (list (make-library-ref 'code 'main)))))) + (make-lambda (test-ref 'args) (make-call-builtin 'exit (list (make-library-ref 'code 'main))))) (expand-body 'main '((let-syntax - (define + ((define (syntax-rules () ((define (f) body ...) - (builtin-define f (builtin-lambda args body ...))))) + (builtin-define f (builtin-lambda args body ...)))))) (define (exit) (call-builtin exit code)))) builtins-environment) @@ -262,20 +295,20 @@ (test builtin-lambda-ref (assert-equal (make-lambda (test-ref 'args) - (make-sequence (make-constant #f) (test-ref 'args))) + (test-ref 'args)) (expand-body 'main '((builtin-lambda args args)) builtins-environment) transform-ir1)) - (test builtin-case-lambda-defines + (test builtin-lambda-defines (assert-equal (make-lambda (test-ref 'args) (make-letrec #t '(a b) (list (gensym) (gensym)) (list (make-constant 6) (test-ref 'a)) - (make-sequence (make-constant #f) (make-constant 7)))) + (make-constant 7))) (expand-body 'main '((builtin-lambda args (builtin-define a (quote 6)) @@ -285,6 +318,16 @@ transform-ir1)) + (test builtin-lambda-empty + (assert-equal + (make-lambda (test-ref 'args) + (make-constant #f)) + (expand-body 'main + '((builtin-lambda args)) + builtins-environment) + transform-ir1)) + + (test builtin-define-syntax (assert-equal (make-sequence @@ -311,9 +354,7 @@ (test builtin-lexical-set (assert-equal (make-lambda (test-ref 'args) - (make-sequence - (make-constant #f) - (make-lexical-set (test-ref 'args) (make-constant 5)))) + (make-lexical-set (test-ref 'args) (make-constant 5))) (expand-body 'main '((builtin-lambda args (set! args 5))) |
