Skip to content

Commit fc8a6b4

Browse files
authored
Merge pull request #90 from Quickfall/feat/better-func-storage
[feat] Global Scope
2 parents 64b5052 + 0e92465 commit fc8a6b4

143 files changed

Lines changed: 13559 additions & 7890 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[workspace]
2-
members = ["compiler/ast", "compiler/ast_parser", "compiler/astoir", "compiler/astoir_hir", "compiler/astoir_hir_lowering", "compiler/astoir_mir", "compiler/compiler_typing", "compiler/astoir_mir_lowering", "compiler/compiler_main", "compiler/compiler_utils", "compiler/llvm_ir_bridge", "compiler/diagnostics"]
2+
members = ["compiler/ast", "compiler/ast_parser", "compiler/astoir", "compiler/astoir_hir", "compiler/astoir_hir_lowering", "compiler/astoir_mir", "compiler/compiler_typing", "compiler/astoir_mir_lowering", "compiler/compiler_main", "compiler/compiler_utils", "compiler/llvm_ir_bridge", "compiler/diagnostics", "compiler/prelude", "compiler/compiler_global_scope"]

compiler/ast/src/ctx.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
use std::{collections::HashMap};
1+
use std::collections::HashMap;
22

33
use crate::tree::ASTTreeNode;
44

55
#[derive(Debug)]
66
pub struct ParserCtx {
7-
pub map: HashMap<String, Box<ASTTreeNode>>,
8-
pub uses: Vec<Box<ASTTreeNode>>,
9-
pub iter_order: Vec<String>
7+
pub map: HashMap<String, Box<ASTTreeNode>>,
8+
pub uses: Vec<Box<ASTTreeNode>>,
9+
pub iter_order: Vec<String>,
1010
}
1111

1212
impl ParserCtx {
13-
pub fn new() -> Self {
14-
return ParserCtx { map: HashMap::new(), iter_order: Vec::new(), uses: vec![] }
15-
}
13+
pub fn new() -> Self {
14+
return ParserCtx {
15+
map: HashMap::new(),
16+
iter_order: Vec::new(),
17+
uses: vec![],
18+
};
19+
}
1620

17-
pub fn insert(&mut self, name: String, node: Box<ASTTreeNode>) -> bool {
18-
if !node.kind.is_tree_permissible() {
19-
return false;
20-
}
21+
pub fn insert(&mut self, name: String, node: Box<ASTTreeNode>) -> bool {
22+
if !node.kind.is_tree_permissible() {
23+
return false;
24+
}
2125

22-
self.iter_order.push(name.clone());
26+
self.iter_order.push(name.clone());
2327

24-
self.map.insert(name, node);
25-
return true;
26-
}
27-
28-
}
28+
self.map.insert(name, node);
29+
return true;
30+
}
31+
}

compiler/ast/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//!
22
//! The AST module of Quickfall. Contains all of the AST code required for the Quickfall language.
3-
//!
3+
//!
44
5-
pub mod tree;
65
pub mod ctx;
6+
pub mod operators;
7+
pub mod tree;
78
pub mod types;
8-
pub mod operators;

compiler/ast/src/operators.rs

Lines changed: 102 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -4,95 +4,107 @@ use compiler_utils::operators::{ComparingOperator, MathOperator, MathOperatorTyp
44
use diagnostics::{DiagnosticResult, builders::make_unexpected_simple_error};
55
use lexer::token::{LexerToken, LexerTokenType};
66

7-
pub fn parse_math_operator(tokens: &Vec<LexerToken>, ind: &mut usize) -> DiagnosticResult<MathOperator> {
8-
let op = match tokens[*ind].tok_type {
9-
LexerTokenType::Plus => MathOperatorType::Add,
10-
LexerTokenType::PercentSign => MathOperatorType::Modulo,
11-
LexerTokenType::Minus => MathOperatorType::Subtract,
12-
LexerTokenType::Asterisk => {
13-
if tokens[*ind + 1].tok_type == LexerTokenType::Asterisk {
14-
*ind += 1;
15-
16-
MathOperatorType::ShiftLeft
17-
} else {
18-
MathOperatorType::Multiply
19-
}
20-
}
21-
LexerTokenType::Divide => {
22-
if tokens[*ind + 1].tok_type == LexerTokenType::Divide {
23-
*ind += 1;
24-
25-
MathOperatorType::ShiftRight
26-
} else {
27-
MathOperatorType::Divide
28-
}
29-
}
30-
31-
_ => return Err(make_unexpected_simple_error(&tokens[*ind], &tokens[*ind].tok_type).into())
32-
};
33-
34-
*ind += 1;
35-
36-
let assigns = match tokens[*ind].tok_type {
37-
LexerTokenType::EqualSign => true,
38-
_ => false
39-
};
40-
41-
if assigns {
42-
*ind += 1;
43-
}
44-
45-
let fast = match tokens[*ind].tok_type {
46-
LexerTokenType::Tidle => true,
47-
_ => false
48-
};
49-
50-
if fast {
51-
*ind += 1;
52-
}
53-
54-
return Ok(MathOperator { operator: op, assigns, fast });
7+
pub fn parse_math_operator(
8+
tokens: &Vec<LexerToken>,
9+
ind: &mut usize,
10+
) -> DiagnosticResult<MathOperator> {
11+
let op = match tokens[*ind].tok_type {
12+
LexerTokenType::Plus => MathOperatorType::Add,
13+
LexerTokenType::PercentSign => MathOperatorType::Modulo,
14+
LexerTokenType::Minus => MathOperatorType::Subtract,
15+
LexerTokenType::Asterisk => {
16+
if tokens[*ind + 1].tok_type == LexerTokenType::Asterisk {
17+
*ind += 1;
18+
19+
MathOperatorType::ShiftLeft
20+
} else {
21+
MathOperatorType::Multiply
22+
}
23+
}
24+
LexerTokenType::Divide => {
25+
if tokens[*ind + 1].tok_type == LexerTokenType::Divide {
26+
*ind += 1;
27+
28+
MathOperatorType::ShiftRight
29+
} else {
30+
MathOperatorType::Divide
31+
}
32+
}
33+
34+
_ => {
35+
return Err(make_unexpected_simple_error(&tokens[*ind], &tokens[*ind].tok_type).into());
36+
}
37+
};
38+
39+
*ind += 1;
40+
41+
let assigns = match tokens[*ind].tok_type {
42+
LexerTokenType::EqualSign => true,
43+
_ => false,
44+
};
45+
46+
if assigns {
47+
*ind += 1;
48+
}
49+
50+
let fast = match tokens[*ind].tok_type {
51+
LexerTokenType::Tidle => true,
52+
_ => false,
53+
};
54+
55+
if fast {
56+
*ind += 1;
57+
}
58+
59+
return Ok(MathOperator {
60+
operator: op,
61+
assigns,
62+
fast,
63+
});
5564
}
5665

57-
pub fn parse_compare_operator(tokens: &Vec<LexerToken>, ind: &mut usize) -> DiagnosticResult<ComparingOperator> {
58-
let eq = match tokens[*ind + 1].tok_type {
59-
LexerTokenType::EqualSign => true,
60-
_ => false
61-
};
62-
63-
let op = match tokens[*ind].tok_type {
64-
LexerTokenType::EqualSign => {
65-
tokens[*ind + 1].expects(LexerTokenType::EqualSign)?;
66-
67-
ComparingOperator::Equal
68-
},
69-
70-
LexerTokenType::ExclamationMark => {
71-
tokens[*ind + 1].expects(LexerTokenType::EqualSign)?;
72-
73-
ComparingOperator::NotEqual
74-
},
75-
76-
LexerTokenType::AngelBracketOpen => {
77-
if eq {
78-
ComparingOperator::LowerEqual
79-
} else {
80-
ComparingOperator::Lower
81-
}
82-
},
83-
84-
LexerTokenType::AngelBracketClose => {
85-
if eq {
86-
ComparingOperator::HigherEqual
87-
} else {
88-
ComparingOperator::Higher
89-
}
90-
},
91-
92-
_ => {
93-
return Err(make_unexpected_simple_error(&tokens[*ind], &tokens[*ind].tok_type).into())
94-
}
95-
};
96-
97-
return Ok(op);
98-
}
66+
pub fn parse_compare_operator(
67+
tokens: &Vec<LexerToken>,
68+
ind: &mut usize,
69+
) -> DiagnosticResult<ComparingOperator> {
70+
let eq = match tokens[*ind + 1].tok_type {
71+
LexerTokenType::EqualSign => true,
72+
_ => false,
73+
};
74+
75+
let op = match tokens[*ind].tok_type {
76+
LexerTokenType::EqualSign => {
77+
tokens[*ind + 1].expects(LexerTokenType::EqualSign)?;
78+
79+
ComparingOperator::Equal
80+
}
81+
82+
LexerTokenType::ExclamationMark => {
83+
tokens[*ind + 1].expects(LexerTokenType::EqualSign)?;
84+
85+
ComparingOperator::NotEqual
86+
}
87+
88+
LexerTokenType::AngelBracketOpen => {
89+
if eq {
90+
ComparingOperator::LowerEqual
91+
} else {
92+
ComparingOperator::Lower
93+
}
94+
}
95+
96+
LexerTokenType::AngelBracketClose => {
97+
if eq {
98+
ComparingOperator::HigherEqual
99+
} else {
100+
ComparingOperator::Higher
101+
}
102+
}
103+
104+
_ => {
105+
return Err(make_unexpected_simple_error(&tokens[*ind], &tokens[*ind].tok_type).into());
106+
}
107+
};
108+
109+
return Ok(op);
110+
}

0 commit comments

Comments
 (0)