summaryrefslogtreecommitdiffstats
path: root/Syntax.sml
blob: 5d4513328b9540deff31390a59d39ccc2be19ed4 (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
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 list
  | 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 * (string * etype option) list
  | DType of string * etype
  | DStruct of string * structExpr

  and structExpr =
    SIdent of string list
  | SStruct of dec 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