projects
/
scheme.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0db4aa6
)
Fix typechecking with bindings
author
Luke Lau
<luke_lau@icloud.com>
Fri, 16 Aug 2019 00:12:54 +0000
(
01:12
+0100)
committer
Luke Lau
<luke_lau@icloud.com>
Fri, 16 Aug 2019 00:12:54 +0000
(
01:12
+0100)
codegen.scm
patch
|
blob
|
history
typecheck.scm
patch
|
blob
|
history
diff --git
a/codegen.scm
b/codegen.scm
index 6203cfdef4f02d367c512517298ca890ce75f384..985ad44a41a24eeb32abd07a8740fa825518b9f7 100644
(file)
--- a/
codegen.scm
+++ b/
codegen.scm
@@
-492,7
+492,7
@@
(if (eqv? 'var (ast-type x))
(list (cons x inner-offset))
(begin
(if (eqv? 'var (ast-type x))
(list (cons x inner-offset))
(begin
- (emit "cmp $~a, ~a(%rbp)" x inner-offset)
+ (emit "cmp
q
$~a, ~a(%rbp)" x inner-offset)
(emit "jne ~a" jne-label)
'() )))))
(emit "jne ~a" jne-label)
'() )))))
diff --git
a/typecheck.scm
b/typecheck.scm
index b3466751fdf7f4161963d3904c13f970b8798a76..f6d7c86465f4869043b3d2fcb9560e42603258d7 100644
(file)
--- a/
typecheck.scm
+++ b/
typecheck.scm
@@
-194,10
+194,14
@@
(define (get-bindings product-types pattern)
(define (go product-type product)
(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
['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)))
(flat-map go product-types (cdr pattern)))
@@
-211,6
+215,7
@@
(let* ([names (cdr pattern)]
[product-types (cdr sum)]
[new-env (append (get-bindings product-types pattern) env)])
(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)]
(check dls new-env expr)))]
; pattern match with binding and no constructor
['var (check dls (env-insert env pattern switch-type) expr)]