blob: 0d10dd23a5122534607fc016958d65736ea9b16d (
plain) (
blame)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
structure Syntax =
struct
(* SML syntax *)
datatype etype =
Tyvar of string
| Tycon of etype list * string
| TyTuple of etype list
| Tyfun of etype * etype
datatype pat =
PWild
| PVar of string
| PInt of int
| PTuple of pat list
| PCon of string list * pat
datatype expr =
EIdent of string
| EDot of structExpr * string
| EBuiltin of string
| EInt of int
| EStr of string
| ETuple of expr list
| EList of expr list
| EApp of expr * expr
| ETyped of expr * etype
| EAndAlso of expr * expr
| EOrElse of expr * expr
| ELet of dec list * expr
| ELambda of pat * expr
| ECase of expr * (pat * expr) list
and dec =
DVal of pat * expr
| DValRec of pat * expr
| DFun of string * (pat list * expr) list
| DDatatype of string list * string * (string * etype option) list
| DType of string * etype
| DStruct of string * structExpr
and structExpr =
SIdent of string
| SDot of structExpr * string
| SStruct of dec list
datatype ty =
TInt
| TBool
| TString
| TVar of int
| TTuple of ty list
| TFun of ty * ty
| TList of ty
| TDatatype of string list
datatype structType =
TStruct of (string * structType) list * (string * ty) list
(*| TFunctor of structType * structType *)
datatype typedPat =
TPWild
| TPVar of string
| TPInt of int
| TPTuple of (typedPat * ty) list
| TPCon of string list * (typedPat * ty)
datatype typedExpr =
TEIdent of string
| TEDot of (typedStructExpr * structType) * string
| TEBuiltin of string
| TEInt of int
| TEStr of string
| TETuple of (typedExpr * ty) list
| TEList of (typedExpr * ty) list
| TEApp of (typedExpr * ty) * (typedExpr * ty)
| TEAndAlso of (typedExpr * ty) * (typedExpr * ty)
| TEOrElse of (typedExpr * ty) * (typedExpr * ty)
| TELet of typedDec list * (typedExpr * ty)
| TELambda of (typedPat * ty) * (typedExpr * ty)
| TECase of (typedExpr * ty) * ((typedPat * ty) * (typedExpr * ty)) list
and typedDec =
TDVal of (typedPat * ty) * (typedExpr * ty)
| TDValRec of (typedPat * ty) * (typedExpr * ty)
| TDFun of string * ((typedPat * ty) list * (typedExpr * ty)) list
| TDDatatype of string * (string * ty option) list
| TDStruct of string * (typedStructExpr * structType)
and typedStructExpr =
TSIdent of string
| TSDot of (typedStructExpr * structType) * string
| TSStruct of typedDec list
(* Lambda language *)
type var = int
datatype primop =
PExit
| PAdd
| PSub
| PMul
| PDiv
| PLess
| PEq
| PIf
| PRead
| PWrite
| PWriteErr
datatype lexp =
LVar of var
| LFn of var * lexp
| LFix of (var * var * lexp) list * lexp
| LApp of lexp * lexp
| LInt of int
| LString of string
| LRecord of lexp list
| LSelect of int * lexp
| LPrim of primop
| LSwitch of lexp * (int * lexp) list * lexp option
(* CPS *)
datatype value =
VVar of var
| VLabel of var
| VInt of int
datatype cexp =
CRecord of ((value * int list) list * var) list * cexp
| CSelect of int * value * var * cexp
| CApp of value * value list
| CFix of (var * var list * cexp) list * cexp
| CPrimop of primop * value list * var list * cexp list
datatype opcode =
OAlloc of var * value
| OCall
| OPoke of int * var * value
| OPeek of var * int * value
| OShuf of var * value
| OExit of value
| OAdd of var * value * value
| OSub of var * value * value
| OMul of var * value * value
| ODiv of var * value * value
| OLess of var * value * value
| OEq of var * value * value
| OIf of value * var
| OLabel of var
| ORead of var * var * value * value
| OWrite of var * value * value
| OWriteErr of var * value * value
end
|