summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2023-01-07 09:08:19 -0500
committerDavid Thompson <dthompson2@worcester.edu>2023-06-08 08:14:41 -0400
commit75206940a98f7487da8a0398ab5de12fbafe3a71 (patch)
tree152db3ca5f097d5fee09323489f6f00649f9b3f1
parentc8d737284e631e626bc629469d77c2abb5d3847e (diff)
Add begin form.
-rw-r--r--infer2.scm12
1 files changed, 12 insertions, 0 deletions
diff --git a/infer2.scm b/infer2.scm
index 569792d..18f8ef2 100644
--- a/infer2.scm
+++ b/infer2.scm
@@ -147,6 +147,12 @@
(make-texp (texp-types body*)
`(let ,(map list vars vals*) ,body*)))
+(define-matcher (annotate:begin ('begin exps ... last) env)
+ (define last* (annotate-exp last env))
+ (make-texp (texp-types last*)
+ `(begin ,@(map (lambda (exp) (annotate-exp exp env)) exps)
+ ,last*)))
+
(define-matcher (annotate:lambda ('lambda ((? symbol? args) ...) body) env)
(define parameter-types (map (lambda (_name) (fresh-type-variable)) args))
(define env* (append (map cons args parameter-types) env))
@@ -171,6 +177,7 @@
annotate:if
annotate:values
annotate:let
+ annotate:begin
annotate:lambda
annotate:call))
@@ -218,6 +225,10 @@
(append (program-constraints body)
(append-map program-constraints vals)))
+(define-matcher (constrain:begin ((? type? types) ...)
+ ('begin (? texp? texps) ...))
+ (append-map program-constraints texps))
+
(define-matcher (constrain:lambda ((? procedure-type? type))
('lambda ((? symbol? args) ...)
(? texp? body)))
@@ -237,6 +248,7 @@
(compose-matchers constrain:if
constrain:values
constrain:let
+ constrain:begin
constrain:lambda
constrain:call
constrain:other))