X-Git-Url: http://git.lukelau.me/?a=blobdiff_plain;f=ast.scm;h=52e06bcb24d3b4783eb301c8fb657ec7f7e06071;hb=1b7e2b53e68a39265fd7424910998d2607cc3815;hp=342fe453a4d9276c36237e43e1a7069b5ec75670;hpb=e4dc23d659849c88cec8c7e57d0d463f9493850e;p=scheme.git diff --git a/ast.scm b/ast.scm index 342fe45..52e06bc 100644 --- a/ast.scm +++ b/ast.scm @@ -1,3 +1,5 @@ +(load "utils.scm") + (define (ast-type x) (define (builtin? x) (case x @@ -33,7 +35,7 @@ ('app (map f x)) ('lambda `(lambda ,(lambda-args x) ,(f (lambda-body x)))) ('if `(if ,@(map f (cdr x)))) - ('stack `(stack ,(cadr x) ,(map f (caddr x)))) + ('stack `(stack ,(cadr x) ,(f (caddr x)))) (else x))) (define (ast-collect f x) @@ -176,10 +178,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 @@ -188,8 +190,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)]) @@ -329,26 +332,3 @@ (strong-connect v))) (car graph))) result)) - - - ; utils - -(define (range s n) - (if (= 0 n) '() - (append (range s (- n 1)) - (list (+ s (- n 1)))))) - -(define (flat-map f . xs) (fold-left append '() (apply map (cons f xs)))) -(define (repeat x n) (if (<= n 0) '() - (cons x (repeat x (- n 1))))) - - -(define-syntax push! - (syntax-rules () - ((_ s x) (set! s (cons x s))))) - -(define-syntax pop! - (syntax-rules () - ((_ s) (let ([x (car s)]) - (set! s (cdr s)) - x))))