-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase-lang.rkt
67 lines (59 loc) · 1.85 KB
/
base-lang.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#lang racket
(require redex)
(provide base-syntax debug)
;; ---------------------------------------------------------------------------------------------------
;; Base Language
;;
;; This is a minimal base language, meant to be built upon to obtain a type-resugarable language.
;; e - expression
;; v - value
;; s - surface expression
;; t - type
;; a - pattern variable
;; x - variable
;;
;; The "*" variants represent sequences, and the "Rec" variants represent records.
;; These need to be built-in because they have unique behavior under inference/unification.
(define-language base-syntax
(v ::= unit) ; Redex requires this to be nonempty, so we include a 'unit' value.
(vRec ::= ϵ (field x v vRec))
(e ::= s x v
(calctype e as t in e)
(calctype* e* as t* in e))
(e* ::= ϵ a (cons e e*))
(eRec ::= ϵ a (field x e eRec))
(s ::= a) ; surface lang
(s* ::= ϵ a (cons s s*))
(sRec ::= ϵ a (field x s sRec))
(t ::= x)
(t* ::= ϵ x (cons t t*))
(tRec ::= ϵ x (field x t tRec))
(Γ ::= ϵ x (bind x t Γ) (bind* x* t* Γ))
(a ::= (variable-prefix ~))
(x ::= variable-not-otherwise-mentioned)
(x* ::= ϵ x (cons x x*))
(premise ::=
premise/judgement
premise/equation
premise/subtype
(assumption any))
(premise/judgement ::= (Γ ⊢ s : t) (Γ ⊢* s : t))
(premise/equation ::=
(t = t)
(t* = t*)
(Γ = Γ)
(tRec = tRec))
(premise/subtype ::=
(t ⋖ t)
(t* ⋖ t*)
(tRec ⋖ tRec)))
; Some of our judgements are stateful, so disable caching
(caching-enabled? #f)
;; Debugging ;;
(define-for-syntax debug-enabled? #f)
(define-syntax (debug stx)
(syntax-case stx ()
[(debug arg ...)
(if debug-enabled?
#'(printf arg ...)
#'(void))]))