Fix typechecking with bindings
authorLuke Lau <luke_lau@icloud.com>
Fri, 16 Aug 2019 00:12:54 +0000 (01:12 +0100)
committerLuke Lau <luke_lau@icloud.com>
Fri, 16 Aug 2019 00:12:54 +0000 (01:12 +0100)
codegen.scm
typecheck.scm

index 6203cfdef4f02d367c512517298ca890ce75f384..985ad44a41a24eeb32abd07a8740fa825518b9f7 100644 (file)
          (if (eqv? 'var (ast-type x))
              (list (cons x inner-offset))
              (begin
-               (emit "cmp $~a, ~a(%rbp)" x inner-offset)
+               (emit "cmpq $~a, ~a(%rbp)" x inner-offset)
                (emit "jne ~a" jne-label)
                '() )))))
   
index b3466751fdf7f4161963d3904c13f970b8798a76..f6d7c86465f4869043b3d2fcb9560e42603258d7 100644 (file)
     
     (define (get-bindings product-types pattern)
       (define (go product-type product)
-            (case (ast-type x)
+       (case (ast-type product)
          ['var (list (cons product product-type))]
                                        ; an inner pattern match
-              ['app (get-bindings product-type product)]))
+         ['app (let* ([inner-sum (car product)]
+                      [inner-sums (cdr (assoc product-type dls))]
+                      [inner-product-types (cdr (assoc inner-sum inner-sums))])
+                 (get-bindings inner-product-types product))]
+         [else '()]))
       (flat-map go product-types (cdr pattern)))
 
     
            (let* ([names (cdr pattern)]
                   [product-types (cdr sum)]
                   [new-env (append (get-bindings product-types pattern) env)])
+
              (check dls new-env expr)))]
                                        ; pattern match with binding and no constructor
        ['var (check dls (env-insert env pattern switch-type) expr)]