aboutsummaryrefslogtreecommitdiff
path: root/std/ast.pk
diff options
context:
space:
mode:
Diffstat (limited to 'std/ast.pk')
-rw-r--r--std/ast.pk75
1 files changed, 35 insertions, 40 deletions
diff --git a/std/ast.pk b/std/ast.pk
index abc66ba..b069aa9 100644
--- a/std/ast.pk
+++ b/std/ast.pk
@@ -1,9 +1,13 @@
## std.ast: Exposes the AST for building and operating on with macros.
pub type Expr = union
- Ident(string), Number(int), Float(float), Char(chr), String(str)
- Struct(list[tuple[field: str, value: Expr]])
- Tuple(list[tuple[field: string?, value: Expr]])
+ Ident(string)
+ Number(int)
+ Float(float)
+ Char(chr)
+ String(str)
+ Struct(list[(field: str, value: Expr)])
+ Tuple(list[(field: str?, value: Expr)])
List(list[Expr])
Let(id: Pattern, kind: Type?, value: ref Expr)
Var(id: Pattern, kind: Type?, value: ref Expr?)
@@ -13,51 +17,41 @@ pub type Expr = union
generics: list[GenericParams],
params: list[FunctionParams],
kind: Type,
- body: list[Expr]
- )
+ body: list[Expr])
TypeDecl(id: str, generics: list[str], alias: Type)
Module(id: str, body: list[Expr])
Use(path: str)
Pub(Expr) # can easily generate incoherent statements. still desired?
Call(id: str, params: list[Expr])
- Cond(branches: list[CondBranch], else_body: list[Expr]?)
+ Cond(
+ branches: list[(cond: Expr, body: list[Expr])],
+ else_body: list[Expr]?)
Try(
try_body: list[Expr],
- catches: list[TryBranch]
- finally_body: list[Expr]?
- )
+ catches: list[(exceptions: list[str], body: list[Expr])],
+ finally_body: list[Expr]?)
Match(
item: ref Expr,
- branches: list[MatchBranch]
- )
+ branches: list[(pattern: Pattern, guard: Expr?, body: list[Expr])])
Block(id: str?, body: list[Expr])
ConstBlock(body: list[Expr]),
For(binding: Pattern, range: ref Expr, body: list[Expr])
While(cond: ref Expr, body: list[Expr])
Loop(body: list[Expr]),
-pub type CondBranch = tuple
- cond: Expr
- body: list[Expr]
-
-pub type TryBranch = tuple
- exceptions: list[str]
- body: list[Expr]
-
-pub type MatchBranch = tuple
- pattern: Pattern
- guard: Option[Expr]
- body: list[Expr]
-
pub type Type = ref union
- Void, Never,
- Integer, Float, String,
- Func(from: Type, to: Type) # todo: multiple parameters
- Struct(list[tuple[id: str, kind: Type]])
- Tuple(list[tuple[id: str?, kind: Type]])
- Union(list[tuple[id: str, kind: Type]])
- Interface( # todo: generics
- funcs: list[Signature]
+ Void
+ Never
+ Int(size: uint)
+ Dec(size: uint)
+ Float(size: uint)
+ String
+ Func(from: list[Type], to: Type)
+ Struct(list[(id: str, kind: Type)])
+ Tuple(list[(id: str?, kind: Type)])
+ Union(list[(id: str, kind: Type)])
+ Class( # todo: generics
+ funcs: list[(id: str, from: list[Type], to: Type?)]
for_type: Type?
)
Array(size: uint, kind: Type)
@@ -65,17 +59,18 @@ pub type Type = ref union
Slice(Type) # todo: plus ownership
Alias(str) # todo: params?? huh?
Static(Type)
- Mutable(Type)
- Reference(Type)
- Pointer(Type)
-pub type Signature = struct # todo: generics
- id: str
- effect: Option[str]
- params: list[Type]
- kind: Option[Type]
+ Lent(Type)
+ Mut(Type)
+ Ref(Type)
+ Refc(Type)
+ Ptr(Type)
+
pub type Pattern = union
Ident(str)
Number(int), Float(float), Char(chr), String(str)
Struct(name: str, params: list[Pattern])
Tuple(list[Pattern])
List(list[Pattern])
+
+@[magic]
+pub func quote(body): Expr