diff --git a/src/CodeGen/reg_alloc/mod.rs b/src/CodeGen/reg_alloc/mod.rs index 6aca3eda..86fe45af 100644 --- a/src/CodeGen/reg_alloc/mod.rs +++ b/src/CodeGen/reg_alloc/mod.rs @@ -67,7 +67,7 @@ impl RegAlloc { let mut num = 0; - for ty in &func.args { + for (name, ty) in &func.args { let location = { if self.just_vars { self.curr_index += 1; @@ -99,14 +99,12 @@ impl RegAlloc { } } - let name = || func.arg(num).name; - self.vars.insert( - name(), + name.to_owned(), location ); - self.var_types.insert(name(), *ty); + self.var_types.insert(name.to_owned(), *ty); num += 1; } diff --git a/src/IR/func.rs b/src/IR/func.rs index 455246cf..35d3ee39 100644 --- a/src/IR/func.rs +++ b/src/IR/func.rs @@ -14,7 +14,7 @@ use crate::Support::ColorProfile; #[derive(Debug, Clone, PartialEq, Eq)] pub struct FunctionType { /// The function arguments (stored as: num, type) - pub args: Vec, + pub args: Vec<(String, TypeMetadata)>, /// The return type pub ret: TypeMetadata, /// After the given arguments any argument type can be supplied (like the printf function - is in c ...) @@ -23,7 +23,7 @@ pub struct FunctionType { impl FunctionType { /// Creates a new function type - pub fn new(args: Vec, ret: TypeMetadata) -> Self { + pub fn new(args: Vec<(String, TypeMetadata)>, ret: TypeMetadata) -> Self { Self { args: args, ret: ret, @@ -41,9 +41,9 @@ impl FunctionType { /// If the num doesn't exists, it panics pub fn arg(&self, num: usize) -> Var { let mut index = 0; - for meta in &self.args { + for (name, meta) in &self.args { if index == num { - return Var { name: format!("%{}", index), ty: *meta } + return Var { name: name.to_owned(), ty: *meta } } index += 1; @@ -238,7 +238,15 @@ impl Function { /// Creates a new function type pub fn FnTy(args: Vec, ret: TypeMetadata) -> FunctionType { - FunctionType::new(args, ret) + let mut processed = Vec::new(); + let mut index = 0; + + for arg in args { + processed.push((format!("%{index}"), arg)); + index += 1; + } + + FunctionType::new(processed, ret) } /// Creates a new Function diff --git a/src/IR/nodes/call.rs b/src/IR/nodes/call.rs index 829914eb..6bf8c901 100644 --- a/src/IR/nodes/call.rs +++ b/src/IR/nodes/call.rs @@ -43,7 +43,7 @@ impl Ir for Call, Var> { let args = &self.inner1.ty.args; for arg in &self.inner2 { if index < args.len() { - if matches!(args.get(index), Some(argty) if *argty != (*arg).ty.into()) { + if matches!(args.get(index), Some((_, argty)) if *argty != (*arg).ty) { Err(VerifyError::InvalidArgumentTypeFound)? } } else { diff --git a/src/IR/parser/gen.rs b/src/IR/parser/gen.rs index 97afaea6..8aa59083 100644 --- a/src/IR/parser/gen.rs +++ b/src/IR/parser/gen.rs @@ -28,8 +28,8 @@ impl IrGen { fn gen_func(&mut self, name: String, ret: TypeMetadata, args: (BTreeMap, bool), body: Vec<(String, IrBlock)>, scope: Linkage) { let mut ty = FunctionType::new(vec![], ret); - for (_, arg) in &args.0 { - ty.args.push( *arg ); + for (name, arg) in &args.0 { + ty.args.push( (name.to_owned(), *arg) ); } let mut raw = Function { diff --git a/src/IR/parser/semnatic.rs b/src/IR/parser/semnatic.rs index 9d634e67..dc05701a 100644 --- a/src/IR/parser/semnatic.rs +++ b/src/IR/parser/semnatic.rs @@ -1,7 +1,7 @@ use std::collections::{BTreeMap, HashMap}; use crate::Obj::Linkage; -use crate::IR::{BlockId, Const, FnTy, FuncId, FunctionType, Type, TypeMetadata, Var}; +use crate::IR::{BlockId, Const, FuncId, FunctionType, Type, TypeMetadata, Var}; use crate::prelude::ir::*; @@ -58,11 +58,15 @@ impl<'a> IrSemnatic<'a> { let mut fun_args = vec![]; - for (_, arg) in &args.0 { - fun_args.push( *arg ); + for (name, arg) in &args.0 { + fun_args.push( (name.to_owned(), *arg) ); } - let mut ty = FnTy(fun_args, ret); + let mut ty = FunctionType { + args: fun_args, + ret: ret, + any_args: false, + }; if args.1 { ty.activate_dynamic_arguments(); @@ -392,7 +396,7 @@ impl<'a> IrSemnatic<'a> { })? }; - if let Some(expected) = sig.args.get(index) { + if let Some((_, expected)) = sig.args.get(index) { if *expected != *arg { Err(IrError::WrongArgument { loc: loc.to_owned(), diff --git a/src/Target/wasm/printer.rs b/src/Target/wasm/printer.rs index c82d389d..70d28482 100644 --- a/src/Target/wasm/printer.rs +++ b/src/Target/wasm/printer.rs @@ -23,7 +23,7 @@ impl AsmPrinter for WasmAsmPrinter { let mut index = 0; - for arg in &func.ty.args { + for (_name, arg) in &func.ty.args { if index != 0 { fmt_ty.push(','); fmt_ty.push(' ');