Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
11ea127
chore: added new examples of syntax
Zffu May 5, 2026
b1e0635
chore: removed unused lay
Zffu May 5, 2026
19a835e
feat: replaced shadowfunc token with externfunc
Zffu May 5, 2026
fbf026e
feat: renamed shadow functions to extern functions for clarity
Zffu May 5, 2026
d696c32
feat: added range parsing
Zffu May 5, 2026
0721c5f
feat: added AST ranged for block
Zffu May 5, 2026
12beacc
feat: added ranged for loop AST parsing
Zffu May 5, 2026
85b29bd
fix: fixed some errors with the AST of ranged for loops
Zffu May 5, 2026
87bdaff
feat: added HIR ranged for block + hinting on return of return type
Zffu May 5, 2026
263151f
fix: temporarily fixed an error with structs
Zffu May 5, 2026
4f8c1f6
feat: added better return type syntax
Zffu May 5, 2026
cc13da3
feat: changed use statements in order to be example compliant
Zffu May 5, 2026
58012fe
feat: added semicollon in lexer
Zffu May 6, 2026
93cfdfe
chore: removed unused stock system
Zffu May 6, 2026
47e32c4
feat: added semicollon allowing in node body parsing
Zffu May 6, 2026
9c14c01
feat: added ranged for loop lowering
Zffu May 6, 2026
6981a98
feat: added type enforcing for range
Zffu May 6, 2026
b3aecd3
feat: added variable type enforcment in ranged for loops
Zffu May 6, 2026
8834cdf
fix: fixed something with the MIR ranged loop lowering
Zffu May 6, 2026
0b42ded
feat: staticstr -> pointer casting on MIR
Zffu May 7, 2026
7975a6a
fix: fixed a bug with for loops & ranged for loops where the iterated…
Zffu May 7, 2026
ccc7025
feat: added llvm IR build
Zffu May 7, 2026
23895c4
fix: fixed a LLVM bridge bug where function IDs from the global scope…
Zffu May 7, 2026
82e55cb
fix: fixed a bug with for loops
Zffu May 7, 2026
146b5b7
feat: added new pointer stuff in AST
Zffu May 7, 2026
cdd840d
feat: added pointer deref in MIR
Zffu May 7, 2026
6981211
feat: added deref modify AST parsing
Zffu May 7, 2026
e1367dc
feat: added deref modify (not working)
Zffu May 7, 2026
aa29e4c
feat: v1.0.0 experimental release pre commit
Zffu May 10, 2026
5f394d8
fix: fixed pointer -> generic lowered (pointer) bug
Zffu May 10, 2026
7f0fd89
chore: removed eligible for SSA message
Zffu May 10, 2026
e2e32b2
feat: made stack alloc use more precise tyÃpes
Zffu May 10, 2026
ebb6262
feat: added errors
Zffu May 10, 2026
1c2f11d
feat: added ending point enforcment
Zffu May 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ out
out.*

*.qf
*.qfmir
*.llvm
*.air

!examples/**.qf
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions compiler/ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

pub mod ctx;
pub mod operators;
pub mod ranges;
pub mod tree;
pub mod types;
14 changes: 12 additions & 2 deletions compiler/ast/src/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,23 @@ pub fn parse_compare_operator(
_ => false,
};

if eq {
*ind += 1;
}

let op = match tokens[*ind].tok_type {
LexerTokenType::EqualSign => {
tokens[*ind + 1].expects(LexerTokenType::EqualSign)?;
if !eq {
tokens[*ind + 1].expects(LexerTokenType::EqualSign)?;
}

ComparingOperator::Equal
}

LexerTokenType::ExclamationMark => {
tokens[*ind + 1].expects(LexerTokenType::EqualSign)?;
if !eq {
tokens[*ind + 1].expects(LexerTokenType::EqualSign)?;
}

ComparingOperator::NotEqual
}
Expand All @@ -106,5 +114,7 @@ pub fn parse_compare_operator(
}
};

*ind += 1;

return Ok(op);
}
7 changes: 7 additions & 0 deletions compiler/ast/src/ranges.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::tree::ASTTreeNode;

#[derive(Debug, PartialEq, Clone)]
pub struct ASTRange {
pub min: Box<ASTTreeNode>,
pub max: Box<ASTTreeNode>,
}
30 changes: 22 additions & 8 deletions compiler/ast/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use diagnostics::{
diagnostic::{Diagnostic, Span, SpanKind, SpanPosition},
};

use crate::types::ASTType;
use crate::{ranges::ASTRange, types::ASTType};

#[derive(Debug, PartialEq, Clone)]
pub struct FunctionDeclarationArgument {
Expand Down Expand Up @@ -78,7 +78,13 @@ pub enum ASTTreeNodeKind {

VariableReference(HashedString),

PointerGrab(Box<ASTTreeNode>),
Dereference(Box<ASTTreeNode>),

DereferenceModify {
pointer: Box<ASTTreeNode>,
val: Box<ASTTreeNode>,
},

ReferenceGrab(Box<ASTTreeNode>),

StructInitializer {
Expand Down Expand Up @@ -166,13 +172,20 @@ pub enum ASTTreeNodeKind {
cond: Box<ASTTreeNode>,
body: Vec<Box<ASTTreeNode>>,
},

ForBlock {
initial_state: Box<ASTTreeNode>,
cond: Box<ASTTreeNode>,
increment: Box<ASTTreeNode>,
body: Vec<Box<ASTTreeNode>>,
},

RangedForBlock {
var: Box<ASTTreeNode>,
range: ASTRange,
body: Vec<Box<ASTTreeNode>>,
},

FunctionCall {
func: HashedString,
args: Vec<Box<ASTTreeNode>>,
Expand All @@ -185,7 +198,7 @@ pub enum ASTTreeNodeKind {
requires_this: bool,
},

ShadowFunctionDeclaration {
ExternFunctionDeclaration {
func_name: HashedString,
args: Vec<FunctionDeclarationArgument>,
return_type: Option<ASTType>,
Expand Down Expand Up @@ -222,7 +235,7 @@ impl ASTTreeNodeKind {
ASTTreeNodeKind::FunctionDeclaration { .. }
| ASTTreeNodeKind::EnumDeclaration { .. }
| ASTTreeNodeKind::StaticVariableDeclaration { .. }
| ASTTreeNodeKind::ShadowFunctionDeclaration { .. }
| ASTTreeNodeKind::ExternFunctionDeclaration { .. }
| ASTTreeNodeKind::StructLayoutDeclaration { .. }
);
}
Expand All @@ -239,7 +252,7 @@ impl ASTTreeNodeKind {
return Some(HashedString::new(func_name.val.to_string()));
}

ASTTreeNodeKind::ShadowFunctionDeclaration {
ASTTreeNodeKind::ExternFunctionDeclaration {
func_name,
args: _,
return_type: _,
Expand Down Expand Up @@ -349,7 +362,8 @@ impl Display for ASTTreeNodeKind {
Self::BooleanBasedConditionMember { .. } => "boolean condition",
Self::MathResult { .. } => "math operation",
Self::VariableReference(_) => "variable reference",
Self::PointerGrab(_) => "pointer grabbing",
Self::DereferenceModify { .. } => "modifying dereference",
Self::Dereference(_) => "dereference",
Self::ReferenceGrab(_) => "reference",
Self::StructInitializer { .. } => "struct value initializer",
Self::ArrayVariableInitializerValue { .. }
Expand All @@ -364,10 +378,10 @@ impl Display for ASTTreeNodeKind {
Self::ReturnStatement { .. } => "return statement",
Self::StaticVariableDeclaration { .. } => "static variable declaration",
Self::WhileBlock { .. } => "while block",
Self::ForBlock { .. } => "for block",
Self::ForBlock { .. } | Self::RangedForBlock { .. } => "for block",
Self::FunctionCall { .. } => "function call",
Self::FunctionDeclaration { .. } => "function declaration",
Self::ShadowFunctionDeclaration { .. } => "shadow function declaration",
Self::ExternFunctionDeclaration { .. } => "extern function declaration",
Self::StructLRFunction { .. } => "struct LRU function usage",
Self::StructLRVariable { .. } => "struct LRU variable usage",
Self::StructLayoutDeclaration { .. } => "struct / layout declaration",
Expand Down
42 changes: 39 additions & 3 deletions compiler/ast_parser/src/control/for_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use lexer::token::{LexerToken, LexerTokenType};
use ast::tree::{ASTTreeNode, ASTTreeNodeKind};

use crate::{
functions::parse_node_body, parser::parse_ast_node_in_body, value::parse_ast_value,
variables::decl::parse_variable_declaration,
functions::parse_node_body, parser::parse_ast_node_in_body, ranges::parse_value_range,
value::parse_ast_value, variables::decl::parse_variable_declaration,
};

pub fn parse_for_loop(
Expand All @@ -14,11 +14,18 @@ pub fn parse_for_loop(
) -> DiagnosticResult<Box<ASTTreeNode>> {
let start = tokens[*ind].pos.clone();

if tokens[*ind + 1].tok_type != LexerTokenType::ParenOpen {
return parse_for_ranged_loop(tokens, ind);
}

*ind += 1;

tokens[*ind].expects(LexerTokenType::ParenOpen)?;
*ind += 1;

tokens[*ind].expects(LexerTokenType::Var)?;

let initial = parse_variable_declaration(tokens, ind)?;
let initial = parse_variable_declaration(tokens, ind, true)?;

tokens[*ind].expects(LexerTokenType::Comma)?;

Expand Down Expand Up @@ -50,3 +57,32 @@ pub fn parse_for_loop(
end,
)));
}

pub fn parse_for_ranged_loop(
tokens: &Vec<LexerToken>,
ind: &mut usize,
) -> DiagnosticResult<Box<ASTTreeNode>> {
let start = tokens[*ind].pos.clone();

let var = parse_variable_declaration(tokens, ind, false)?;

tokens[*ind].expects(LexerTokenType::EqualSign)?;
*ind += 1;

tokens[*ind].expects(LexerTokenType::AngelBracketClose)?;
*ind += 1;

let range = parse_value_range(tokens, ind)?;

tokens[*ind].expects(LexerTokenType::BracketOpen)?;

let body = parse_node_body(tokens, ind)?;

let end: compiler_utils::Position = tokens[*ind - 1].get_end_pos();

Ok(Box::new(ASTTreeNode::new(
ASTTreeNodeKind::RangedForBlock { var, range, body },
start,
end,
)))
}
40 changes: 23 additions & 17 deletions compiler/ast_parser/src/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ pub mod arguments;
pub mod returns;
pub mod shadow;

pub fn parse_function_return_type(
tokens: &Vec<LexerToken>,
ind: &mut usize,
) -> DiagnosticResult<Option<ASTType>> {
if tokens[*ind].tok_type == LexerTokenType::Minus {
*ind += 1;

tokens[*ind].expects(LexerTokenType::AngelBracketClose)?;
*ind += 1;

let ty = parse_type(tokens, ind)?;

return Ok(Some(ty));
} else {
return Ok(None);
}
}

pub fn parse_function_declaraction(
tokens: &Vec<LexerToken>,
ind: &mut usize,
Expand All @@ -34,12 +52,7 @@ pub fn parse_function_declaraction(

*ind += 1;

let mut ret_type = None;

if tokens[*ind].is_keyword() {
ret_type = Some(parse_type(tokens, ind)?);
//*ind += 1;
}
let ret_type = parse_function_return_type(tokens, ind)?;

tokens[*ind].expects(LexerTokenType::BracketOpen)?;

Expand Down Expand Up @@ -108,20 +121,13 @@ pub fn parse_node_body(
let mut tok: &LexerToken = &tokens[*ind];
let mut body: Vec<Box<ASTTreeNode>> = Vec::new();

let mut stock = 1;

while tok.tok_type != LexerTokenType::EndOfFile && tok.tok_type != LexerTokenType::BracketClose
{
if tok.tok_type == LexerTokenType::BracketClose {
stock -= 1;
}

if stock == 0 {
break;
}
if tok.tok_type == LexerTokenType::SemiCollon {
*ind += 1;
tok = &tokens[*ind];

if tok.tok_type == LexerTokenType::BracketOpen {
stock += 1;
continue;
}

let n = parse_ast_node_in_body(tokens, ind)?;
Expand Down
18 changes: 5 additions & 13 deletions compiler/ast_parser/src/functions/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use compiler_utils::hash::HashedString;
use diagnostics::DiagnosticResult;
use lexer::token::{LexerToken, LexerTokenType};

use crate::{functions::arguments::parse_function_arguments, types::parse_type};
use crate::functions::{arguments::parse_function_arguments, parse_function_return_type};

pub fn parse_shadow_function_declaration(
pub fn parse_extern_function_definition(
tokens: &Vec<LexerToken>,
ind: &mut usize,
) -> DiagnosticResult<Box<ASTTreeNode>> {
Expand All @@ -23,19 +23,11 @@ pub fn parse_shadow_function_declaration(

*ind += 1;

let mut ret_type = None;
let end;

if tokens[*ind].is_keyword() {
ret_type = Some(parse_type(tokens, ind)?);

end = tokens[*ind].get_end_pos().clone();
} else {
end = tokens[*ind - 1].get_end_pos().clone();
}
let ret_type = parse_function_return_type(tokens, ind)?;
let end = tokens[*ind].get_end_pos();

return Ok(Box::new(ASTTreeNode::new(
ASTTreeNodeKind::ShadowFunctionDeclaration {
ASTTreeNodeKind::ExternFunctionDeclaration {
func_name: HashedString::new(function_name.0),
args: args.0,
return_type: ret_type,
Expand Down
2 changes: 2 additions & 0 deletions compiler/ast_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub mod functions;
pub mod literals;
pub mod math;
pub mod parser;
pub mod pointers;
pub mod ranges;
pub mod structs;
pub mod types;
pub mod unwraps;
Expand Down
2 changes: 0 additions & 2 deletions compiler/ast_parser/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ pub fn parse_math_operation(
.into());
}

println!("{:#?}", tokens[*ind].tok_type);

let right_member = parse_ast_value(tokens, ind)?;

let start = original.start.clone();
Expand Down
12 changes: 8 additions & 4 deletions compiler/ast_parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use crate::{
},
functions::{
parse_function_call, parse_function_declaraction, returns::parse_function_return_statement,
shadow::parse_shadow_function_declaration,
shadow::parse_extern_function_definition,
},
pointers::parse_deref_modify,
structs::{enums::parse_enum_declaration, parse_type_declaration},
use_statements::parse_use_statement,
value::parse_ast_value_post_l,
Expand All @@ -39,8 +40,8 @@ pub fn parse_ast_node(
return parse_function_declaraction(tokens, ind, None);
}

LexerTokenType::ShadowFunction => {
return parse_shadow_function_declaration(tokens, ind);
LexerTokenType::ExternFunc => {
return parse_extern_function_definition(tokens, ind);
}

LexerTokenType::Struct => {
Expand Down Expand Up @@ -76,7 +77,7 @@ pub fn parse_ast_node_in_body(
) -> DiagnosticResult<Box<ASTTreeNode>> {
match &tokens[*ind].tok_type {
LexerTokenType::Var => {
return parse_variable_declaration(tokens, ind);
return parse_variable_declaration(tokens, ind, true);
}

LexerTokenType::If => {
Expand All @@ -91,13 +92,16 @@ pub fn parse_ast_node_in_body(
return parse_for_loop(tokens, ind);
}

LexerTokenType::Asterisk => return parse_deref_modify(tokens, ind),

LexerTokenType::Return => {
return parse_function_return_statement(tokens, ind);
}

LexerTokenType::Keyword(str, _) => {
if tokens[*ind + 1].tok_type == LexerTokenType::ParenOpen {
let call = parse_function_call(tokens, ind);

return parse_ast_value_post_l(tokens, ind, call, true);
}

Expand Down
Loading
Loading