Start work on ADTs
[scheme.git] / codegen.scm
index 7a12fc2228795b588cfbf117d3f1e7712f282be6..fb856a54a7da63314890bc6c739ce9cc03c69a01 100644 (file)
            (set! bound (append (lambda-args e) bound))
            (collect (lambda-body e))))
 
-      ('app (fold-map collect e))
-      ('if (fold-map collect (cdr e)))
+      ('app (flat-map collect e))
+      ('if (flat-map collect (cdr e)))
       ('let
-         (let ([bind-fvs (fold-map (lambda (a)
+         (let ([bind-fvs (flat-map (lambda (a)
                                      (begin
                                        (set! bound (cons (car a) bound))
                                        (collect (cdr a))))
                                    (let-bindings e))])
-           (append bind-fvs (fold-map collect (let-body e)))))
+           (append bind-fvs (flat-map collect (let-body e)))))
       (else '())))
   (collect prog))
 
 (define (codegen program)
   (set! cur-label 0)
   (set! cur-lambda 0)
-  (let* ((extract-res-0 (extract-strings program))
+  (let* ([body (program-body program)] 
+        
+        (extract-res-0 (extract-strings body))
         (strings (car extract-res-0))
         (extract-res-1 (extract-lambdas (cdr extract-res-0)))
         (lambdas (car extract-res-1))
 
 (define (compile-to-binary program output t)
   (set! target t)
-  (when (not (eq? (typecheck program) 'int)) (error #f "not an int"))
+  (when (not (eq? (typecheck program) 'Int)) (error #f "not an Int"))
   (let ([tmp-path "/tmp/a.s"])
     (when (file-exists? tmp-path) (delete-file tmp-path))
     (with-output-to-file tmp-path