Skip to content

Commit 0e911fa

Browse files
author
DigitalCodeCrafter
committed
changed types to be nodes in the AST
1 parent a1f38a6 commit 0e911fa

3 files changed

Lines changed: 135 additions & 130 deletions

File tree

src/compiler/ast.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,24 @@ pub enum NodeKind {
2222
IndexExpression { array: NodeId , index: NodeId },
2323
TupleIndexExpression { tuple: NodeId , index: i32 },
2424
PathExpression { segments: Vec<NodeId> },
25-
PathSegment { ident: String },
2625
ErrorExpr,
26+
27+
// Types
28+
TypePath { segments: Vec<NodeId> },
29+
TypeTuple { elements: Vec<NodeId> },
30+
TypeArray { ty: NodeId, len: NodeId },
31+
TypeSlice { ty: NodeId },
32+
ErrorType,
33+
34+
PathSegment { ident: String, args: Vec<NodeId> },
2735

2836
// Statements
29-
LetStmt { name: String, mutable: bool, ty: Option<TypeId>, value: Option<NodeId> },
37+
LetStmt { name: String, mutable: bool, ty: Option<NodeId>, value: Option<NodeId> },
3038
ExprStmt { expr: NodeId },
3139
EmptyStmt,
3240

3341
// Items
34-
Function { public: bool, name: String, params: Vec<(String, TypeId)>, return_type: Option<TypeId>, body: NodeId },
42+
Function { public: bool, name: String, params: Vec<(String, NodeId)>, return_type: Option<NodeId>, body: NodeId },
3543
Module { public: bool, name: String, items: Option<Vec<NodeId>> },
3644
UseDecl { public: bool, use_tree: NodeId },
3745

@@ -91,26 +99,3 @@ pub struct Pos {
9199
pub line: usize,
92100
pub col: usize,
93101
}
94-
95-
// --- Types ---
96-
97-
pub type TypeId = usize;
98-
99-
#[derive(Debug, Clone)]
100-
pub enum TypeKind {
101-
Simple(String),
102-
Generic {
103-
base: String,
104-
args: Vec<TypeId>,
105-
},
106-
Tuple(Vec<TypeId>),
107-
Array {
108-
ty: TypeId,
109-
len: Option<u32>,
110-
},
111-
Function {
112-
params: Vec<TypeId>,
113-
ret: Option<TypeId>,
114-
},
115-
ErrorType,
116-
}

0 commit comments

Comments
 (0)