diff options
Diffstat (limited to 'std/ast.pk')
-rw-r--r-- | std/ast.pk | 29 |
1 files changed, 19 insertions, 10 deletions
@@ -1,5 +1,8 @@ ## std.ast: Exposes the AST for building and operating on with macros. +## The `Expr` type represents the abstract syntax tree of Puck itself. +## It notably lacks type information. +## It is, however, syntactically correct-by-construction. pub type Expr = union Ident(string) Number(int) @@ -11,17 +14,24 @@ pub type Expr = union List(list[Expr]) Let(id: Pattern, kind: Type?, value: ref Expr) Var(id: Pattern, kind: Type?, value: ref Expr?) - Const(id: Pattern, kind: Type?, value: ref Expr) + ConstDecl(public: bool, id: Pattern, kind: Type?, value: ref Expr) FuncDecl( # effects? + public: bool, id: str, - generics: list[GenericParams], - params: list[FunctionParams], - kind: Type, + generics: list[(id: Pattern, kind: Type?)], + params: list[(id: Pattern, kind: Type)], + kind: Type?, body: list[Expr]) - TypeDecl(id: str, generics: list[str], alias: Type) - Module(id: str, body: list[Expr]) + MacroDecl( + public: bool, + id: str, + generics: list[(id: Pattern, kind: Type?)], + params: list[(id: Pattern, kind: Type?)], + kind: Type?, + body: list[Expr]) + TypeDecl(public: bool, id: str, generics: list[str], alias: Type) + Module(public: bool, 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[(cond: Expr, body: list[Expr])], @@ -34,13 +44,12 @@ pub type Expr = union item: ref Expr, branches: list[(pattern: Pattern, guard: Expr?, body: list[Expr])]) Block(id: str?, body: list[Expr]) - ConstBlock(body: list[Expr]), + ConstExpr(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 Type = ref union - Void Never Int(size: uint) Dec(size: uint) @@ -58,7 +67,7 @@ pub type Type = ref union List(Type) Slice(Type) # todo: plus ownership Alias(str) # todo: params?? huh? - Static(Type) + Const(Type) Lent(Type) Mut(Type) Ref(Type) |