Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
faa445a
chore: added astoirÃ_mir crate
Zffu Mar 10, 2026
3a51773
chore: added astoir_mir crate
Zffu Mar 10, 2026
e8328f7
feat: added basic MIRInstruction struct
Zffu Mar 10, 2026
2b1a136
feat: added base values
Zffu Mar 10, 2026
1911f17
feat: added most HIR instructions
Zffu Mar 10, 2026
4d69950
feat: added pointer & neg instructions
Zffu Mar 10, 2026
0c224bc
feat: added more needed instructions
Zffu Mar 10, 2026
402bcf2
feat: added int value
Zffu Mar 10, 2026
a8be3c6
feat: added float value
Zffu Mar 10, 2026
0afd11d
feat: started working on blocks
Zffu Mar 10, 2026
039fc51
feat: added instruction return types
Zffu Mar 10, 2026
294fd8b
feat: added instruction append to MIRBlock
Zffu Mar 10, 2026
d40f56a
feat: added helper build functions
Zffu Mar 10, 2026
5754c3a
feat: added constant values
Zffu Mar 10, 2026
8b20134
feat: added block value hints
Zffu Mar 10, 2026
da0cbb3
feat: added stack_alloc hint
Zffu Mar 10, 2026
898c992
feat: added hint in build_store check
Zffu Mar 10, 2026
905d022
fix: fixed an error
Zffu Mar 10, 2026
73aef97
feat: added MIR function struct
Zffu Mar 11, 2026
6f9b8e9
feat: changed MIRBlockReference to usize
Zffu Mar 11, 2026
5a4c947
feat: changed instructions to use MIRBlockReference
Zffu Mar 11, 2026
5247a9e
feat: added missing builder functions
Zffu Mar 11, 2026
8678bd5
feat: added constant builder functions
Zffu Mar 11, 2026
2cde60c
chore: removed done TODOs
Zffu Mar 11, 2026
de3fdac
fix :fixed BaseValueType::eq returning true when it shouldn't
Zffu Mar 11, 2026
01647ee
feat: added context for variables in MIR blocks
Zffu Mar 11, 2026
f633fdd
chore: added astoir_mir_lowering crate
Zffu Mar 11, 2026
96ebbd9
feat: added variable declaration lowering
Zffu Mar 11, 2026
4d514a4
feat: added variable reference lowering
Zffu Mar 11, 2026
6f02466
feat: added lower hir variable reference value
Zffu Mar 11, 2026
a06c13a
feat: added const lowering
Zffu Mar 11, 2026
1cb94fe
fix: missing ref
Zffu Mar 11, 2026
fbe7d72
feat: added static string constant instruction
Zffu Mar 11, 2026
499971b
feat: added builder func
Zffu Mar 11, 2026
02b7add
feat: added lowering support for string statics
Zffu Mar 11, 2026
e047147
feat: added basic mir lowering for values
Zffu Mar 11, 2026
3d3bffb
feat: added default value store for variable declarations
Zffu Mar 11, 2026
fe7b4a2
feat: lowered var assign
Zffu Mar 11, 2026
c6aae2a
feat: added boolean lowering
Zffu Mar 11, 2026
3170190
feat: marked MIR independant types as deprecated
Zffu Mar 12, 2026
31f5f92
feat: Ãadded compacted types
Zffu Mar 12, 2026
c6366b0
feat: migrated raw value objects
Zffu Mar 12, 2026
8c44d6d
feat: started migrating the instruction return types
Zffu Mar 12, 2026
cfeeab3
feat: added Ãis_equal to BaseType
Zffu Mar 13, 2026
a84a6ae
feat: migrated builder functions
Zffu Mar 13, 2026
f322894
feat: added assignment support for math operations
Zffu Mar 13, 2026
0339b74
feat: added signed operations support
Zffu Mar 13, 2026
bc72dd0
feat: added float operation support
Zffu Mar 13, 2026
d98b9c7
chore: added Math operation lowering in lower_hir_value
Zffu Mar 13, 2026
0179cff
chore: removed old MIR type
Zffu Mar 13, 2026
15c46c9
feat: added is_from_struct field to MIRFunction
Zffu Mar 13, 2026
7c3a407
feat: added global MIR context
Zffu Mar 13, 2026
1d89606
chore: removed the need for AnyType as it was unstable
Zffu Mar 13, 2026
3377c4f
feat: added comp functions for CompactedType
Zffu Mar 13, 2026
3724291
feat: added build_call
Zffu Mar 13, 2026
a44a477
feat: added return type for load
Zffu Mar 14, 2026
ef68181
feat: added ctx passing everywhere
Zffu Mar 14, 2026
f4d678d
feat: added default val tracking & era tracker for value assignments
Zffu Mar 14, 2026
e5fef72
feat: added helper functions in HIRBranchedContext to know if a varia…
Zffu Mar 14, 2026
0f51e1e
feat: added var value change lowering
Zffu Mar 14, 2026
dd963cf
feat: added variable value enforcing everywhere any variable is used
Zffu Mar 14, 2026
1286dce
fix: fixed era system not working
Zffu Mar 14, 2026
d5a763f
Merge pull request #51 from Quickfall/feat/value-era-tracking
Zffu Mar 14, 2026
5c14b1c
feat: added this keyword
Zffu Mar 14, 2026
38c6bb6
feat: added this keyword in parameter parsing
Zffu Mar 14, 2026
cd0e561
feat: added struct type transmission in function declarations
Zffu Mar 14, 2026
a01ea4a
feat: added information about usage of this and enforced first placem…
Zffu Mar 14, 2026
940bdae
feat: added requires_this in HIR
Zffu Mar 14, 2026
0b6616b
feat: added ast struct func lowering
Zffu Mar 14, 2026
a282118
feat: added inner function parsing in AST
Zffu Mar 14, 2026
70ab353
feat: added working function parsing in structs
Zffu Mar 14, 2026
8a44abe
feat: added working function parsing in structs
Zffu Mar 14, 2026
0c3502d
Merge pull request #52 from Quickfall/feat/struct-funcs
Zffu Mar 14, 2026
f4bfd24
feat: added SSA value hint for variables
Zffu Mar 14, 2026
c77fcbd
feat: added variable kinds
Zffu Mar 14, 2026
ca12f75
feat: made lower_hir_variable_declaration handle ssa
Zffu Mar 15, 2026
55aea46
feat: made variable hints & kinds into an hashmap for better
Zffu Mar 15, 2026
a4b0c1f
feat: made SSA indexes global!
Zffu Mar 15, 2026
3a17fbe
feat: started to make blocks global
Zffu Mar 15, 2026
3295f93
feat: made function use references instead of raw blocks
Zffu Mar 15, 2026
4531660
feat: added MIRBlock::new_merge
Zffu Mar 15, 2026
9fcada4
feat: added PartialEq trait to CompactedType & BaseMIRValue
Zffu Mar 15, 2026
26da6ee
feat: added new build_phi
Zffu Mar 15, 2026
e12d8eb
feat: added ssa change resolving
Zffu Mar 15, 2026
3a9b0be
feat: added MIRVariableReference to seamlessly interact with pointer …
Zffu Mar 15, 2026
6092a56
feat: added working variable references inside of lowering
Zffu Mar 15, 2026
b0520ca
feat: added ref using in maths
Zffu Mar 15, 2026
8da2165
Merge pull request #53 from Quickfall/feat/ssa-vals
Zffu Mar 15, 2026
2699ab9
feat: added body lowering functions
Zffu Mar 15, 2026
d3516b1
feat: added mir lowering control mod
Zffu Mar 16, 2026
fda726f
feat: changed every MIR function to use block references instead of &…
Zffu Mar 16, 2026
800b4b7
feat: added for loop lowering
Zffu Mar 16, 2026
3e426f1
feat: added if statement lowering
Zffu Mar 17, 2026
b61dd64
feat: added leftover elements in body member
Zffu Mar 17, 2026
8f62af2
feat: potentially finished MIR
Zffu Mar 17, 2026
3de37a6
feat: added instruction fmt
Zffu Mar 17, 2026
2ce6370
feat: added MIR block fmt
Zffu Mar 17, 2026
a916c2f
feat: added missing fmt for ctx and functions
Zffu Mar 17, 2026
ef2a3cb
feat: finished sample mir
Zffu Mar 17, 2026
ef3e972
feat: added mir command
Zffu Mar 17, 2026
961285c
fix: fixed some ssa bugs
Zffu Mar 17, 2026
089ce7f
fix: fmt and ssa fixes
Zffu Mar 17, 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
22 changes: 22 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[workspace]
members = ["compiler/ast", "compiler/ast_parser", "compiler/astoir", "compiler/astoir_hir", "compiler/astoir_hir_lowering", "compiler/astoir_typing", "compiler/compiler_errors", "compiler/compiler_main", "compiler/compiler_utils", "testing"]
members = ["compiler/ast", "compiler/ast_parser", "compiler/astoir", "compiler/astoir_hir", "compiler/astoir_hir_lowering", "compiler/astoir_mir", "compiler/astoir_mir_lowering", "compiler/astoir_typing", "compiler/compiler_errors", "compiler/compiler_main", "compiler/compiler_utils", "testing"]
6 changes: 4 additions & 2 deletions compiler/ast/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub enum ASTTreeNodeKind {
IntegerLit { val: i128, hash: u64 },
StringLit(String),

ThisStructParam,

OperatorBasedConditionMember { lval: Box<ASTTreeNode>, rval: Box<ASTTreeNode>, operator: ComparingOperator },
BooleanBasedConditionMember { val: Box<ASTTreeNode>, negate: bool },

Expand All @@ -51,7 +53,7 @@ pub enum ASTTreeNodeKind {
ForBlock { initial_state: Box<ASTTreeNode>, cond: Box<ASTTreeNode>, increment: Box<ASTTreeNode>, body: Vec<Box<ASTTreeNode>> },

FunctionCall { func: HashedString, args: Vec<Box<ASTTreeNode>> },
FunctionDeclaration { func_name: HashedString, args: Vec<FunctionDeclarationArgument>, body: Vec<Box<ASTTreeNode>>, return_type: Option<CompleteType> },
FunctionDeclaration { func_name: HashedString, args: Vec<FunctionDeclarationArgument>, body: Vec<Box<ASTTreeNode>>, return_type: Option<CompleteType>, requires_this: bool },

ShadowFunctionDeclaration { func_name: HashedString, args: Vec<FunctionDeclarationArgument>, return_type: Option<CompleteType> },

Expand All @@ -74,7 +76,7 @@ impl ASTTreeNodeKind {

pub fn get_tree_name(&self) -> Option<HashedString> {
match self {
ASTTreeNodeKind::FunctionDeclaration { func_name, args: _, body: _, return_type: _ } => {
ASTTreeNodeKind::FunctionDeclaration { func_name, args: _, body: _, return_type: _ , requires_this: _} => {
return Some(HashedString::new(func_name.val.to_string()));
},

Expand Down
39 changes: 29 additions & 10 deletions compiler/ast_parser/src/functions/arguments.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
//! Module for parsing arguments

use ast::tree::FunctionDeclarationArgument;
use compiler_errors::errs::CompilerResult;
use ast::{tree::FunctionDeclarationArgument, types::CompleteType};
use compiler_errors::errs::{CompilerResult, ErrorKind, normal::CompilerError};
use compiler_utils::hash::HashedString;
use lexer::token::{LexerToken, LexerTokenType};

use crate::types::parse_type;

pub fn parse_function_arguments(tokens: &Vec<LexerToken>, ind: &mut usize) -> CompilerResult<Vec<FunctionDeclarationArgument>> {
pub fn parse_function_arguments(tokens: &Vec<LexerToken>, ind: &mut usize, struct_type: Option<CompleteType>) -> CompilerResult<(Vec<FunctionDeclarationArgument>, bool)> {
*ind += 1;

let mut depends_on_this: bool = false;
let mut args: Vec<FunctionDeclarationArgument> = Vec::new();

while *ind < tokens.len() && tokens[*ind].is_keyword() {
let var_type = parse_type(tokens, ind)?;
while *ind < tokens.len() && (tokens[*ind].is_keyword() || tokens[*ind].tok_type == LexerTokenType::This) {

if tokens[*ind].tok_type == LexerTokenType::This {
if struct_type.is_none() {
return Err(CompilerError::from_ast(ErrorKind::Error, "This requires to be within a struct!".to_string(), &tokens[*ind].pos, &tokens[*ind].get_end_pos()))
}

*ind += 1;
let var_name = tokens[*ind].expects_keyword()?;
if !args.is_empty() {
return Err(CompilerError::from_ast(ErrorKind::Error, "this must be the first parameter of the function.".to_string(), &tokens[*ind].pos, &tokens[*ind].get_end_pos()))
}

args.push(FunctionDeclarationArgument::new(var_name.0, var_type));
depends_on_this = true;

*ind += 1;
*ind += 1;

args.push(FunctionDeclarationArgument { name: HashedString::new("this".to_string()), argument_type: struct_type.clone().unwrap() })
} else {
let var_type = parse_type(tokens, ind)?;

*ind += 1;
let var_name = tokens[*ind].expects_keyword()?;

args.push(FunctionDeclarationArgument::new(var_name.0, var_type));

*ind += 1;
}

if tokens[*ind].tok_type == LexerTokenType::ParenClose {
break;
Expand All @@ -32,5 +51,5 @@ pub fn parse_function_arguments(tokens: &Vec<LexerToken>, ind: &mut usize) -> Co

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

Ok(args)
Ok((args, depends_on_this))
}
8 changes: 4 additions & 4 deletions compiler/ast_parser/src/functions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Parser module for functions

use ast::tree::{ASTTreeNode, ASTTreeNodeKind};
use ast::{tree::{ASTTreeNode, ASTTreeNodeKind}, types::CompleteType};
use compiler_errors::errs::CompilerResult;
use compiler_utils::hash::HashedString;
use lexer::token::{LexerToken, LexerTokenType};
Expand All @@ -11,7 +11,7 @@ pub mod shadow;
pub mod arguments;
pub mod returns;

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

*ind += 1;
Expand All @@ -20,7 +20,7 @@ pub fn parse_function_declaraction(tokens: &Vec<LexerToken>, ind: &mut usize) ->
*ind += 1;
tokens[*ind].expects(LexerTokenType::ParenOpen)?;

let args = parse_function_arguments(tokens, ind)?;
let args = parse_function_arguments(tokens, ind, struct_type)?;

*ind += 1;

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

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

return Ok(Box::new(ASTTreeNode::new(ASTTreeNodeKind::FunctionDeclaration { func_name: HashedString::new(function_name.0), args, body, return_type: ret_type }, start, end)));
return Ok(Box::new(ASTTreeNode::new(ASTTreeNodeKind::FunctionDeclaration { func_name: HashedString::new(function_name.0), args: args.0, body, return_type: ret_type, requires_this: args.1 }, start, end)));
}

pub fn parse_function_call(tokens: &Vec<LexerToken>, ind: &mut usize) -> CompilerResult<Box<ASTTreeNode>> {
Expand Down
4 changes: 2 additions & 2 deletions compiler/ast_parser/src/functions/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn parse_shadow_function_declaration(tokens: &Vec<LexerToken>, ind: &mut usi
*ind += 1;
tokens[*ind].expects(LexerTokenType::ParenOpen)?;

let args = parse_function_arguments(tokens, ind)?;
let args = parse_function_arguments(tokens, ind, None)?;

*ind += 1;

Expand All @@ -32,5 +32,5 @@ pub fn parse_shadow_function_declaration(tokens: &Vec<LexerToken>, ind: &mut usi
end = tokens[*ind - 1].get_end_pos().clone();
}

return Ok(Box::new(ASTTreeNode::new(ASTTreeNodeKind::ShadowFunctionDeclaration { func_name: HashedString::new(function_name.0), args, return_type: ret_type }, start, end)))
return Ok(Box::new(ASTTreeNode::new(ASTTreeNodeKind::ShadowFunctionDeclaration { func_name: HashedString::new(function_name.0), args: args.0, return_type: ret_type }, start, end)))
}
2 changes: 1 addition & 1 deletion compiler/ast_parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{control::{for_loop::parse_for_loop, if_else::parse_if_statement, whi
pub fn parse_ast_node(tokens: &Vec<LexerToken>, ind: &mut usize) -> CompilerResult<Box<ASTTreeNode>> {
match &tokens[*ind].tok_type {
LexerTokenType::Function => {
return parse_function_declaraction(tokens, ind);
return parse_function_declaraction(tokens, ind, None);
},

LexerTokenType::ShadowFunction => {
Expand Down
2 changes: 0 additions & 2 deletions compiler/ast_parser/src/structs/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ pub fn parse_types_field_member(tokens: &Vec<LexerToken>, ind: &mut usize) -> Co
let start = tokens[*ind].pos.clone();
let member_type = parse_type(tokens, ind)?;

*ind += 1;

let field_name = tokens[*ind].expects_keyword()?;

let end = tokens[*ind].get_end_pos().clone();
Expand Down
12 changes: 9 additions & 3 deletions compiler/ast_parser/src/structs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use compiler_errors::errs::CompilerResult;
use compiler_utils::hash::HashedString;
use lexer::token::{LexerToken, LexerTokenType};

use ast::tree::{ASTTreeNode, ASTTreeNodeKind};
use ast::{tree::{ASTTreeNode, ASTTreeNodeKind}, types::CompleteType};

use crate::structs::members::parse_types_field_member;
use crate::{functions::parse_function_declaraction, structs::members::parse_types_field_member};

pub mod members;

Expand All @@ -22,8 +22,14 @@ pub fn parse_type_declaration(tokens: &Vec<LexerToken>, ind: &mut usize, layout:

let mut members: Vec<Box<ASTTreeNode>> = Vec::new();

let temp_type = CompleteType { base_type: type_name.1, sizes: vec![], types: vec![], pointer: false, pointer_array: false, array_sz: 0 };

while tokens[*ind].tok_type != LexerTokenType::BracketClose {
members.push(parse_types_field_member(tokens, ind)?);
if tokens[*ind].tok_type == LexerTokenType::Function {
members.push(parse_function_declaraction(tokens, ind, Some(temp_type.clone()))?);
} else {
members.push(parse_types_field_member(tokens, ind)?);
}
}

let end = tokens[*ind].get_end_pos().clone();
Expand Down
4 changes: 3 additions & 1 deletion compiler/astoir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ edition = "2024"

[dependencies]
astoir_hir = {path = "../astoir_hir"}
astoir_mir = {path = "../astoir_mir"}
ast = { path = "../ast" }
compiler_errors = { path = "../compiler_errors" }
astoir_hir_lowering = { path = "../astoir_hir_lowering" }
astoir_hir_lowering = { path = "../astoir_hir_lowering" }
astoir_mir_lowering = { path = "../astoir_mir_lowering" }
14 changes: 12 additions & 2 deletions compiler/astoir/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
use ast::ctx::ParserCtx;
use astoir_hir::ctx::HIRContext;
use astoir_hir_lowering::lower_ast;
use compiler_errors::errs::{CompilerResult};
use astoir_mir::ctx::MIRContext;
use astoir_mir_lowering::lower_hir;
use compiler_errors::errs::{CompilerResult, normal::CompilerError};

pub enum IRLevel {
HIR
HIR,
MIR
}

pub fn run_astoir_hir(ctx: ParserCtx) -> CompilerResult<HIRContext> {
return lower_ast(ctx);
}

pub fn run_astoir_mir(ctx: ParserCtx) -> CompilerResult<MIRContext> {
return match lower_hir(run_astoir_hir(ctx)?) {
Ok(v) => Ok(v),
Err(e) => Err(CompilerError::from_base_posless(e))
}
}
Loading