aboutsummaryrefslogtreecommitdiff
path: root/std/fundamental
diff options
context:
space:
mode:
Diffstat (limited to 'std/fundamental')
-rw-r--r--std/fundamental/ast.pk119
-rw-r--r--std/fundamental/logs.pk1
-rw-r--r--std/fundamental/tests.pk5
3 files changed, 125 insertions, 0 deletions
diff --git a/std/fundamental/ast.pk b/std/fundamental/ast.pk
new file mode 100644
index 0000000..25bdc02
--- /dev/null
+++ b/std/fundamental/ast.pk
@@ -0,0 +1,119 @@
+## 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[name: str, kind: Option[Type]]]
+ params: list[struct[name: 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
+ name: str
+ body: list[ref Expr]
+
+pub type Call = struct
+ id: str
+ params: list[Expr]
+pub type Cond = struct
+ branches: list[CondBranch]
+ else_body: Option[list[Expr]]
+pub type Try = struct
+ body: ref Expr
+ catches: list[struct[exceptions: list[str], body: list[Expr]]]
+ finally_body: Option[list[Expr]]
+pub type Match = struct
+ item: ref Expr
+ branches: list[MatchBranch]
+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
+ Struct: struct[name: str, params: list[]]
+ Tuple: list[Pattern]
+ List
+pub type CondBranch = struct
+ cond: Expr
+ body: list[Expr]
+pub type MatchBranch = struct
+ pattern: Pattern
+ guard: Option[Expr]
+ body: Expr
+
+# 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)
diff --git a/std/fundamental/logs.pk b/std/fundamental/logs.pk
new file mode 100644
index 0000000..7a0060f
--- /dev/null
+++ b/std/fundamental/logs.pk
@@ -0,0 +1 @@
+## std/logs: Utility macros and functions for logging.
diff --git a/std/fundamental/tests.pk b/std/fundamental/tests.pk
new file mode 100644
index 0000000..7eb00a8
--- /dev/null
+++ b/std/fundamental/tests.pk
@@ -0,0 +1,5 @@
+## std/tests: Utility macros and functions for testing.
+
+## A macro for runnable examples. Runs them on compilation.
+pub macro examples(body) =
+ ...