Skip to content

Commit b48e175

Browse files
committed
πŸ“ chore: Add types to AST
1 parent d50c7c6 commit b48e175

File tree

8 files changed

+47
-7
lines changed

8 files changed

+47
-7
lines changed

β€Žsrc/compiler/typesharp_ast/ast.rsβ€Ž

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// use crate::{ typesharp_parser::Module };
33
use super::position::{ Position };
44
use super::op::*;
5+
use super::types;
56
use crate::{ compiler::typesharp_lexer::token::Token };
67

78
pub struct AST {
@@ -53,14 +54,20 @@ pub struct ASTStatement {
5354
#[derive(Clone, PartialEq, Debug)]
5455
pub enum ASTStateBody {
5556
// expressions, function calls, returns etc should be here.
56-
FuncCall(Signature)
57+
FuncCall(Signature),
58+
Expression(Expression),
59+
StackVar(Var),
60+
Constant(HeapVar),
61+
AnyConstant(AnyVar),
62+
If(Conditional)
5763
}
5864

5965
// Context and definitions
6066
/// A variable, const, class, etc.
6167
#[derive(Clone, PartialEq, Debug)]
6268
pub struct Var {
6369
pub op: Option<AnyOp>,
70+
pub typ: Option<types::Type>,
6471
pub val: Token,
6572
pub pos: Position,
6673
pub dies: bool,
@@ -93,7 +100,9 @@ pub struct Expression {
93100
pub v: Vec<AnyVar>
94101
}
95102

103+
#[derive(Clone, PartialEq, Debug)]
96104
pub struct Conditional {
97105
pub condition: Expression,
98-
pub body: Vec<ASTStatement>
106+
pub body: Vec<ASTStatement>,
107+
pub fin: Option<Vec<ASTStatement>>
99108
}

β€Žsrc/compiler/typesharp_ast/mod.rsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod position;
33
pub mod keyword;
44
pub mod cursor;
55
pub mod op;
6+
pub mod types;
67

78
pub use self::{
89
position::{ Position, Span },
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// this is used by the parser
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// this is used by the parser
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
// This is a module that handles internal classes and types.
2+
pub mod builtin;
3+
pub mod compiler;
4+
use super::{ ast };
5+
26
#[derive(Clone, PartialEq, Debug)]
37
pub struct Type {
48
pub name: String,
@@ -7,10 +11,12 @@ pub struct Type {
711

812
#[derive(Clone, PartialEq, Debug)]
913
pub struct TypeDefinition {
10-
pub func: TypeSignature
14+
/// Used for linting and more descriptive errors
15+
pub calculated_defs: Option<Vec<ast::Conditional>>,
16+
pub defs: Option<Vec<ast::AnyVar>>
1117
}
1218

13-
#[derive(Clone, PartialEq, Debug)]
14-
pub struct TypeSignature {
15-
16-
}
19+
pub use self::{
20+
builtin::*,
21+
compiler::*
22+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod parser;

β€Žsrc/lib.rsβ€Ž

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![allow(non_snake_case)]
2+
pub mod compiler;
3+
pub mod error;
4+
//pub mod parser_h::{ parser, compile };
5+
6+
fn main() {
7+
let code = "use std.math;
8+
/*const mychild: string = 10;
9+
const newval = (int) mychild;
10+
debug!(newval); // Number<u8, 10>
11+
*/";
12+
let lexed = compiler::typesharp_lexer::tokenize(&code);
13+
let val = lexed.len();
14+
15+
for token in lexed {
16+
println!("Found: {:?}", token);
17+
}
18+
19+
println!("There are: {} tokens.", val);
20+
//compile(parser::parse(lexed));
21+
}

0 commit comments

Comments
Β (0)