Flesh out stack values within ADTs
[scheme.git] / ast.scm
diff --git a/ast.scm b/ast.scm
index 342fe453a4d9276c36237e43e1a7069b5ec75670..52e06bcb24d3b4783eb301c8fb657ec7f7e06071 100644 (file)
--- 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)
                                        ;        |
                                        ;        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
 
     (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)])
           (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))))