-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2b9834
commit a7a5822
Showing
3 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
(syntax-spec | ||
(binding-class ml-var | ||
#:reference-compiler | ||
(make-variable-like-reference-compiler | ||
compile-RM)) | ||
|
||
(nonterminal ml-expr | ||
#:binding-space ml | ||
|
||
(~> x:ml-var | ||
(syntax/loc #'x (MR x))) | ||
|
||
x:ml-var | ||
n:number | ||
(app e1:ml-expr e2:ml-expr) | ||
(+ e1:ml-expr e2:ml-expr) | ||
(- e1:ml-expr e2:ml-expr) | ||
(if0 e1:ml-expr e2:ml-expr e3:ml-expr) | ||
(lambda ([x:ml-var t:ml-type]) e:ml-expr) | ||
#:binding (scope (bind x) e) | ||
|
||
(MR e:racket-expr) | ||
(: e:ml-expr t:ml-type) | ||
|
||
(~> (e1 e2) | ||
#'(app e1 e2))) | ||
|
||
(nonterminal ml-type | ||
#:binding-space ml | ||
Nat | ||
L | ||
(-> t1:ml-type t2:ml-type)) | ||
|
||
(host-interface/expression | ||
(RM e:ml-expr) | ||
(compile-RM #'e))) | ||
|
||
(struct ml-value [v t]) | ||
(struct racket-value [v]) | ||
|
||
;; MLVar is Identifier | ||
;; MLType is Syntax | ||
;; MLExpr is Syntax | ||
|
||
;; RM-translation : Any MLType -> Any | ||
(define (RM-translation v t) #| elided ... |#) | ||
|
||
;; MR-translation : Any MLType -> Any | ||
(define (MR-translation v t) #| elided ... |#) | ||
|
||
(begin-for-syntax | ||
;; compile-RM : MLExpr -> Syntax | ||
(define (compile-RM e) | ||
(define-values (e^ t) (infer-type e)) | ||
#`(RM-translation (ml->racket #,e^) #'#,t)) | ||
|
||
;; assert-type-equal! : MLType MLType MLExpr -> Void | ||
(define (assert-type-equal! actual expected term) #| elided ... |#) | ||
|
||
(define-local-symbol-table type-env) | ||
|
||
;; type-env-ref : MLVar -> MLType | ||
(define (type-env-ref x) | ||
(symbol-table-ref type-env x #'Nat)) | ||
|
||
;; type-env-extend! : MLVar MLType -> Void | ||
(define (type-env-extend! x t) | ||
(symbol-table-set! type-env x t)) | ||
|
||
;; infer-type : MLExpr -> (Values MLExpr MLType) | ||
(define (infer-type e) #| elided ... |#) | ||
|
||
;; check-type! : MLExpr MLType -> MLExpr | ||
(define (check-type! e t) #| elided ... |#)) | ||
|
||
(define-syntax ml->racket | ||
(syntax-parser | ||
#:datum-literals (app + - if0 lambda MR) | ||
#| elided cases ... |# | ||
[(_ (MR e t)) | ||
#'(MR-translation e #'t)])) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters