X-Git-Url: http://git.lukelau.me/?a=blobdiff_plain;f=ast.scm;h=86d522560a8012546e6a754499b1216052d8ce70;hb=2d4831a551afbeec0680fa65c6d301853c8a975b;hp=b70317a70e6fd3a14aa9fab5c94be57991427f2e;hpb=8e106ca13666680051f91ab3f49ce2bd7e19ead7;p=scheme.git diff --git a/ast.scm b/ast.scm index b70317a..86d5225 100644 --- a/ast.scm +++ b/ast.scm @@ -17,6 +17,7 @@ ('if 'if) ('let 'let) ('lambda 'lambda) + ('case 'case) ('closure 'closure) ; only available in codegen ('static-string 'static-string) ; only available in codegen ('stack 'stack) ; only available in codegen (tag that value is passed via stack) @@ -35,6 +36,10 @@ ('app (map f x)) ('lambda `(lambda ,(lambda-args x) ,(f (lambda-body x)))) ('if `(if ,@(map f (cdr x)))) + ('case `(case ,(f (case-expr x)) + ,@(map (lambda (x) + (list (car x) (f (cadr x)))) + (case-cases x)))) ('stack `(stack ,(cadr x) ,(f (caddr x)))) (else x))) @@ -50,6 +55,9 @@ (inner (lambda-body x)))] ['if (append (f x) (flat-map inner (cdr x)))] + ['case (append (f x) + (inner (case-expr x)) + (flat-map inner (map cadr (case-cases x))))] ['stack (append (f x) (inner (caddr x)))] [else (f x)])) @@ -80,6 +88,9 @@ (define let-bindings cadr) (define let-body cddr) +(define case-expr cadr) +(define case-cases cddr) + ; (let ([(foo a b) (foo 123 345)]) a) ; | ; v @@ -178,10 +189,10 @@ ; | ; v ; (foo . ((A foo constructor) . (abs Int (abs Bool A)))) - ; (foo~0 . ((A foo 0) . (abs A Int))) - ; (foo~1 . ((A foo 1) . (abs A Bool))) + ; (foo~0 . ((A foo 0 Int) . (abs A Int))) + ; (foo~1 . ((A foo 1 Bool) . (abs A Bool))) ; (bar . ((A bar constructor) . (abs Bool A))) - ; (bar~0 . ((A bar 0) . (abs A Bool))) + ; (bar~0 . ((A bar 0 Bool) . (abs A Bool))) ; ------+------------------------------------- ; tor | info | type @@ -190,8 +201,9 @@ (fold-right (lambda (x acc) `(abs ,x ,acc)) t products)) (define (destructor ctor-name prod-type part-type index) - (let ([name (dtor-name ctor-name index)]) - (cons name (cons (list prod-type ctor-name index) `(abs ,prod-type ,part-type))))) + (let* ([name (dtor-name ctor-name index)] + [info (list prod-type ctor-name index part-type)]) + (cons name (cons info `(abs ,prod-type ,part-type))))) (let ([type-name (car data-layout)] [ctors (cdr data-layout)])