From 1c14500ed698f1dc21b4b634a174af89b6318b07 Mon Sep 17 00:00:00 2001 From: JJ Date: Tue, 31 Oct 2023 02:49:41 -0700 Subject: compiler: restructure codebase --- src/ast.rs | 116 ------------------------------------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 src/ast.rs (limited to 'src/ast.rs') diff --git a/src/ast.rs b/src/ast.rs deleted file mode 100644 index 6c7963e..0000000 --- a/src/ast.rs +++ /dev/null @@ -1,116 +0,0 @@ -/// Representation of Tokens, function names, the like... -pub type Id = String; - -/// Puck's fundamental types. -pub enum Type { - Void, Never, - Integer, Float, String, // char et al are defined later - Func{from: Box, to: Box}, // todo: multiple params, effects - Struct(Vec<(Id, Box)>), - Tuple(Vec<(Option, Box)>), - Union(Vec<(Id, Box)>), - Interface { - funcs: Vec, - for_type: Option>, - }, - Array{size: usize, kind: Box}, - List(Box), - Slice(Box), // todo: plus ownership - Reference(Box), - Mutable(Box), // parameters only - Static(Box), // parameters only - Alias{ id: Id, params: Vec }, // todo: this is wrong -} - -/// Function signatures. -pub struct Sig { - effect: Option, - id: Id, - generics: Vec<(Id, Option)>, - params: Vec, - result: Option -} - -/// Patterns are recognizable given zero context. -/// This is why there is a generic Number term and no Bool term. -/// Also can be considered to be a Term/Value. -pub enum Pattern { - Ident(Id), // type aliases, union variants, calls... - Number(i64), Float(f64), - Char(char), String(String), - Struct(Vec), - Tuple(Vec), - List(Vec), // arrays, slices, lists -} - -pub struct StructPattern { field: Id, value: Expr } -pub struct TuplePattern { field: Option, value: Expr } - -/// Expressions introduce a new binding or bindings, in some regard. -pub enum Binding { - Let { - id: Pattern, // id: Pattern supports ex. `let (a, b) = ...` - kind: Option, - value: Box - }, - Var { - id: Pattern, - kind: Option, - value: Option> // variable bindings can be delayed - }, - Const { - public: bool, - id: Pattern, - kind: Option, - value: Box - }, - FuncDecl { - public: bool, - effect: Option, - id: Id, - generics: Vec, - params: Vec, - kind: Type, - body: Vec - }, - TypeDecl { id: Id, generics: Vec, alias: Type }, - Import { from: Option, imports: Vec, alias: Option }, - Module { id: Id, body: Vec }, -} - -pub struct GenericDecl { id: Id, kind: Option } -pub struct ParamDecl { id: Id, kind: Type } - -/// Expressions related to control flow. -pub enum Control { - Call { id: Id, params: Vec }, // function calls, macro invocations, field access... - If { - branches: Vec, - else_body: Option> - }, - Try { - body: Vec, - catches: Vec, - finally: Option> - }, - Match { - item: Pattern, - branches: Vec - }, - Block { id: Option, body: Vec }, - Static { body: Vec }, - For { binding: Pattern, range: Box, body: Vec }, - While { cond: Box, body: Vec }, - Loop { body: Vec }, -} - -pub struct CondBranch { cond: Expr, body: Vec } -pub struct CatchBranch { exceptions: Vec, binding: Option, body: Vec } -pub struct MatchBranch { pattern: Pattern, guard: Option, body: Vec } - -/// Expressions are either Patterns, Bindings, or Control flow constructs. -pub enum Expr { - Pattern(Pattern), - Binding(Binding), - Control(Control), -} -- cgit v1.2.3-70-g09d2