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
|
## std/ast: Exposes the AST for building and operating on with macros.
pub type Ident = string
pub type Number = int
pub type Float = float
pub type Char = char
pub type String = str
pub type Struct = list[struct[field: str, value: Expr]]
pub type Tuple = list[struct[field: Option[string], value: Expr]]
pub type List = list[Expr]
pub type Let = struct
id: Pattern
kind: Option[Type]
value: ref Expr
pub type Var = struct
id: Pattern
kind: Option[Type]
value: Option[ref Expr] # variable bindings can be delayed
pub type Const = struct
id: Pattern
kind: Option[Type]
value = ref Expr
pub type FuncDecl = struct
public: bool
effect: Option[str]
id: str
generics: list[struct[id: str, kind: Option[Type]]]
params: list[struct[id: str, kind: Type]]
kind: Type
body: list[Expr]
pub type TypeDecl = struct
id: str
generics: list[str]
alias: Type
pub type Import = struct
mod_from: Option[string]
imports: list[str]
alias: Option[str]
pub type Module = struct
id: str
body: list[Expr]
pub type Call = struct
id: str
params: list[Expr]
pub type Cond = struct
branches: list[struct[cond: Expr, body: list[Expr]]]
else_body: Option[list[Expr]]
pub type Try = struct
body: list[Expr]
catches: list[struct[exceptions: list[str], body: list[Expr]]]
finally_body: Option[list[Expr]]
pub type Match = struct
item: ref Expr
branches: list[struct[pattern: Pattern, guard: Option[Expr], body: list[Expr]]]
pub type Block = struct
id: Option[str]
body: list[Expr]
pub type Static = struct
body: list[Expr]
pub type For = struct
binding: Pattern
range: ref Expr
body: list[Expr]
pub type While = struct
cond: ref Expr
body: list[Expr]
pub type Loop = struct
body: list[Expr]
# the first style of union. naming anonymous types.
pub type Type = union
Void, Never,
Integer, Float, String,
Func: struct[from, to: ref Type] # todo: multiple parameters
Struct: list[struct[id: str, kind: Type]]
Tuple: list[struct[id: Option[str], kind: Type]]
Union: list[struct[id: str, kind: Type]]
Interface: struct # todo: generics
funcs: list[Signature]
for_type: Option[ref Type]
Array: struct[size: uint, kind: ref Type]
List: ref Type
Slice: ref Type # todo: plus ownership
Alias: str # todo: params?? huh?
Static: ref Type
Mutable: ref Type
Reference: ref Type
pub type Signature = struct # todo: generics
id: str
effect: Option[str]
params: list[Type]
kind: Option[Type]
pub type Pattern = union
Ident: str
Number: int, Float: float, Char: char, String: str
Struct: struct[name: str, params: list[Pattern]]
Tuple: list[Pattern]
List: list[Pattern]
# the second style of union. A union of literal types, no names.
pub type Expr = union
Ident, Number, Float, Char, String, Struct, Tuple, List,
Let, Var, Const, FuncDecl, TypeDecl, Import, Module,
Call, Cond, Try, Match, Block, Static, For, While, Loop,
# todo: decide on a style of union
# anonymous struct objects can be constructed with {}
# anonymous tuple objects can be constructed with ()
# anonymous list objects can be constructed with []
# anonymous union *types* can be constructed with | (in parameters)
|