diff --git a/examples/a.reid b/examples/a.reid
new file mode 100644
index 0000000..8b53d10
--- /dev/null
+++ b/examples/a.reid
@@ -0,0 +1,6 @@
+pub fn abs(f: f32) -> f32 {
+ if f < 0.0 {
+ return f * (0.0 - 1.0);
+ }
+ return f;
+}
diff --git a/reid/src/ast/process.rs b/reid/src/ast/process.rs
index 071b461..2d8c114 100644
--- a/reid/src/ast/process.rs
+++ b/reid/src/ast/process.rs
@@ -3,8 +3,8 @@ use std::path::PathBuf;
use crate::{
ast::{self},
mir::{
- self, CustomTypeKey, ModuleMap, NamedVariableRef, ReturnKind, SourceModuleId, StmtKind,
- StructField, StructType, WhileStatement,
+ self, CustomTypeKey, ModuleMap, NamedVariableRef, ReturnKind, SourceModuleId, StmtKind, StructField,
+ StructType, WhileStatement,
},
};
@@ -162,9 +162,7 @@ impl ast::Block {
*range,
),
ast::BlockLevelStatement::Import { _i } => todo!(),
- ast::BlockLevelStatement::Expression(e) => {
- (StmtKind::Expression(e.process(module_id)), e.1)
- }
+ ast::BlockLevelStatement::Expression(e) => (StmtKind::Expression(e.process(module_id)), e.1),
ast::BlockLevelStatement::Return(_, e) => {
if let Some(e) = e {
(StmtKind::Expression(e.process(module_id)), e.1)
@@ -197,11 +195,10 @@ impl ast::Block {
counter_range.as_meta(module_id),
)),
Box::new(mir::Expression(
- mir::ExprKind::Literal(mir::Literal::Vague(
- mir::VagueLiteral::Number(1),
- )),
+ mir::ExprKind::Literal(mir::Literal::Vague(mir::VagueLiteral::Number(1))),
counter_range.as_meta(module_id),
)),
+ mir::TypeKind::Vague(mir::VagueType::Unknown),
),
counter_range.as_meta(module_id),
),
@@ -220,6 +217,7 @@ impl ast::Block {
counter_range.as_meta(module_id),
)),
Box::new(end.process(module_id)),
+ mir::TypeKind::Vague(mir::VagueType::Unknown),
),
counter_range.as_meta(module_id),
),
@@ -292,22 +290,15 @@ impl ast::Expression {
binary_operator.mir(),
Box::new(lhs.process(module_id)),
Box::new(rhs.process(module_id)),
+ mir::TypeKind::Vague(mir::VagueType::Unknown),
),
- ast::ExpressionKind::FunctionCall(fn_call_expr) => {
- mir::ExprKind::FunctionCall(mir::FunctionCall {
- name: fn_call_expr.0.clone(),
- return_type: mir::TypeKind::Vague(mir::VagueType::Unknown),
- parameters: fn_call_expr
- .1
- .iter()
- .map(|e| e.process(module_id))
- .collect(),
- meta: fn_call_expr.2.as_meta(module_id),
- })
- }
- ast::ExpressionKind::BlockExpr(block) => {
- mir::ExprKind::Block(block.into_mir(module_id))
- }
+ ast::ExpressionKind::FunctionCall(fn_call_expr) => mir::ExprKind::FunctionCall(mir::FunctionCall {
+ name: fn_call_expr.0.clone(),
+ return_type: mir::TypeKind::Vague(mir::VagueType::Unknown),
+ parameters: fn_call_expr.1.iter().map(|e| e.process(module_id)).collect(),
+ meta: fn_call_expr.2.as_meta(module_id),
+ }),
+ ast::ExpressionKind::BlockExpr(block) => mir::ExprKind::Block(block.into_mir(module_id)),
ast::ExpressionKind::IfExpr(if_expression) => {
let cond = if_expression.0.process(module_id);
let then_block = if_expression.1.process(module_id);
@@ -364,6 +355,7 @@ impl ast::Expression {
expr.1.as_meta(module_id),
)),
Box::new(expr.process(module_id)),
+ mir::TypeKind::Vague(mir::VagueType::Unknown),
),
ast::UnaryOperator::Minus => mir::ExprKind::BinOp(
mir::BinaryOperator::Minus,
@@ -372,6 +364,7 @@ impl ast::Expression {
expr.1.as_meta(module_id),
)),
Box::new(expr.process(module_id)),
+ mir::TypeKind::Vague(mir::VagueType::Unknown),
),
},
ast::ExpressionKind::CastTo(expression, ty) => mir::ExprKind::CastTo(
@@ -457,15 +450,11 @@ impl ast::TypeKind {
ast::TypeKind::Array(type_kind, length) => {
mir::TypeKind::Array(Box::new(type_kind.clone().into_mir(source_mod)), *length)
}
- ast::TypeKind::Custom(name) => {
- mir::TypeKind::CustomType(CustomTypeKey(name.clone(), source_mod))
- }
+ ast::TypeKind::Custom(name) => mir::TypeKind::CustomType(CustomTypeKey(name.clone(), source_mod)),
ast::TypeKind::Borrow(type_kind, mutable) => {
mir::TypeKind::Borrow(Box::new(type_kind.clone().into_mir(source_mod)), *mutable)
}
- ast::TypeKind::Ptr(type_kind) => {
- mir::TypeKind::UserPtr(Box::new(type_kind.clone().into_mir(source_mod)))
- }
+ ast::TypeKind::Ptr(type_kind) => mir::TypeKind::UserPtr(Box::new(type_kind.clone().into_mir(source_mod))),
ast::TypeKind::F16 => mir::TypeKind::F16,
ast::TypeKind::F32B => mir::TypeKind::F32B,
ast::TypeKind::F32 => mir::TypeKind::F32,
diff --git a/reid/src/codegen/allocator.rs b/reid/src/codegen/allocator.rs
index 839d7b3..441064c 100644
--- a/reid/src/codegen/allocator.rs
+++ b/reid/src/codegen/allocator.rs
@@ -6,8 +6,7 @@ use reid_lib::{
};
use crate::mir::{
- self, CustomTypeKey, FunctionCall, FunctionDefinitionKind, IfExpression, SourceModuleId,
- TypeKind, WhileStatement,
+ self, CustomTypeKey, FunctionCall, FunctionDefinitionKind, IfExpression, SourceModuleId, TypeKind, WhileStatement,
};
#[derive(Debug)]
@@ -74,9 +73,7 @@ impl mir::FunctionDefinitionKind {
mir::FunctionDefinitionKind::Intrinsic(_) => {}
}
- Allocator {
- allocations: allocated,
- }
+ Allocator { allocations: allocated }
}
}
@@ -126,9 +123,7 @@ impl mir::Statement {
crate::mir::StmtKind::Expression(expression) => {
allocated.extend(expression.allocate(scope));
}
- crate::mir::StmtKind::While(WhileStatement {
- condition, block, ..
- }) => {
+ crate::mir::StmtKind::While(WhileStatement { condition, block, .. }) => {
allocated.extend(condition.allocate(scope));
allocated.extend(block.allocate(scope));
}
@@ -162,7 +157,7 @@ impl mir::Expression {
}
}
crate::mir::ExprKind::Literal(_) => {}
- crate::mir::ExprKind::BinOp(_, lhs, rhs) => {
+ crate::mir::ExprKind::BinOp(_, lhs, rhs, _) => {
allocated.extend(lhs.allocate(scope));
allocated.extend(rhs.allocate(scope));
}
diff --git a/reid/src/codegen/mod.rs b/reid/src/codegen/mod.rs
index 1326944..b94366a 100644
--- a/reid/src/codegen/mod.rs
+++ b/reid/src/codegen/mod.rs
@@ -5,20 +5,18 @@ use intrinsics::*;
use reid_lib::{
compile::CompiledModule,
debug_information::{
- DebugFileData, DebugLocalVariable, DebugLocation, DebugMetadata, DebugRecordKind,
- DebugSubprogramData, DebugSubprogramOptionals, DebugSubprogramType, DebugTypeData,
- DwarfFlags, InstructionDebugRecordData,
+ DebugFileData, DebugLocalVariable, DebugLocation, DebugMetadata, DebugRecordKind, DebugSubprogramData,
+ DebugSubprogramOptionals, DebugSubprogramType, DebugTypeData, DwarfFlags, InstructionDebugRecordData,
},
- CmpPredicate, ConstValue, Context, CustomTypeKind, Function, FunctionFlags, Instr, Module,
- NamedStruct, TerminatorKind as Term, Type,
+ CmpPredicate, ConstValue, Context, CustomTypeKind, Function, FunctionFlags, Instr, Module, NamedStruct,
+ TerminatorKind as Term, Type,
};
use scope::*;
use crate::{
mir::{
- self, implement::TypeCategory, pass::ScopeBinopKey, CustomTypeKey, FunctionDefinitionKind,
- NamedVariableRef, SourceModuleId, StructField, StructType, TypeDefinitionKind, TypeKind,
- WhileStatement,
+ self, implement::TypeCategory, pass::ScopeBinopKey, CustomTypeKey, FunctionDefinitionKind, NamedVariableRef,
+ SourceModuleId, StructField, StructType, TypeDefinitionKind, TypeKind, WhileStatement,
},
util::try_all,
};
@@ -83,9 +81,7 @@ struct State {
impl State {
/// Sets should load, returning a new state
fn load(self, should: bool) -> State {
- State {
- should_load: should,
- }
+ State { should_load: should }
}
}
@@ -235,10 +231,7 @@ impl mir::Module {
let ir_function = module.function(
&binop_fn_name,
binop.return_type.get_type(&type_values),
- vec![
- binop.lhs.1.get_type(&type_values),
- binop.rhs.1.get_type(&type_values),
- ],
+ vec![binop.lhs.1.get_type(&type_values), binop.rhs.1.get_type(&type_values)],
FunctionFlags {
inline: true,
..Default::default()
@@ -287,9 +280,7 @@ impl mir::Module {
&binop.return_type,
&ir_function,
match &binop.fn_kind {
- FunctionDefinitionKind::Local(_, meta) => {
- meta.into_debug(tokens, compile_unit)
- }
+ FunctionDefinitionKind::Local(_, meta) => meta.into_debug(tokens, compile_unit),
FunctionDefinitionKind::Extern(_) => None,
FunctionDefinitionKind::Intrinsic(_) => None,
},
@@ -352,9 +343,7 @@ impl mir::Module {
&mir_function.return_type,
&function,
match &mir_function.kind {
- FunctionDefinitionKind::Local(..) => {
- mir_function.signature().into_debug(tokens, compile_unit)
- }
+ FunctionDefinitionKind::Local(..) => mir_function.signature().into_debug(tokens, compile_unit),
FunctionDefinitionKind::Extern(_) => None,
FunctionDefinitionKind::Intrinsic(_) => None,
},
@@ -386,13 +375,10 @@ impl FunctionDefinitionKind {
let fn_param_ty = &return_type.get_debug_type(&debug, scope);
- let debug_ty =
- debug
- .info
- .debug_type(DebugTypeData::Subprogram(DebugSubprogramType {
- parameters: vec![*fn_param_ty],
- flags: DwarfFlags,
- }));
+ let debug_ty = debug.info.debug_type(DebugTypeData::Subprogram(DebugSubprogramType {
+ parameters: vec![*fn_param_ty],
+ flags: DwarfFlags,
+ }));
let subprogram = debug.info.subprogram(DebugSubprogramData {
name: name.clone(),
@@ -477,9 +463,7 @@ impl FunctionDefinitionKind {
}
if let Some(debug) = &scope.debug {
- if let Some(location) =
- &block.return_meta().into_debug(scope.tokens, debug.scope)
- {
+ if let Some(location) = &block.return_meta().into_debug(scope.tokens, debug.scope) {
let location = debug.info.location(&debug.scope, *location);
scope.block.set_terminator_location(location).unwrap();
}
@@ -536,11 +520,7 @@ impl mir::Block {
}
impl mir::Statement {
- fn codegen<'ctx, 'a>(
- &self,
- scope: &mut Scope<'ctx, 'a>,
- state: &State,
- ) -> Result