diff --git a/src/errors.rs b/src/errors.rs index 1fe38ad..8238889 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -27,6 +27,7 @@ pub enum ErrorSubType { VariableAlreadyExists, ArgumentDuplication, TooManyArguments, + NotEnoughArguments, NoExpression, //Machine errors RegisterNotFound, @@ -112,6 +113,7 @@ pub fn convert_subtypes_to_string(stype: &ErrorSubType) -> String { ErrorSubType::FileError => String::from("File error"), ErrorSubType::RuntimeError => String::from("Runtime error"), ErrorSubType::NoExpression => String::from("No expression found"), + ErrorSubType::NotEnoughArguments => String::from("Not enough arguments"), } } fn convert_subtypes_to_short(stype: &ErrorSubType) -> String { @@ -141,6 +143,7 @@ fn convert_subtypes_to_short(stype: &ErrorSubType) -> String { ErrorSubType::FileError => String::from("FE:"), ErrorSubType::RuntimeError => String::from("RE:"), ErrorSubType::NoExpression => String::from("NE:"), + ErrorSubType::NotEnoughArguments => String::from("NA:"), } } pub fn reverse_subtype_short(str: String) -> ErrorSubType { @@ -170,6 +173,7 @@ pub fn reverse_subtype_short(str: String) -> ErrorSubType { "FE" => ErrorSubType::FileError, "RE" => ErrorSubType::RuntimeError, "NE" => ErrorSubType::NoExpression, + "NA" => ErrorSubType::NotEnoughArguments, _ => panic!("Unknown error subtype short: {}", str), } } diff --git a/src/virtualmachine.rs b/src/virtualmachine.rs index 34484fe..757dcc3 100644 --- a/src/virtualmachine.rs +++ b/src/virtualmachine.rs @@ -821,15 +821,50 @@ impl Machine { match mem { VMMemory::Function(func) => { let arg = 0; + let mut nocon = false; for i in &self.stack { let mut new_mem = i.clone(); if self.functions[func.id].variables.len() <= arg || self.functions[func.id].variables[arg].start != 0 { - break; + let err = create_error(&format!("Too many arguments supplied for function: `{}`", func.id), operation.pos, ErrorType::SemanticError, ErrorSubType::TooManyArguments, &self.ctx[self.call_stack[executed_stack].func].clone()); + if executed_func.try_catch > 0 { + fallback_to_catch(&mut self.memory, &mut self.state, &mut self.functions, &mut self.call_stack, &mut executed_stack, executed_func, err); + executed_func = &func_clone[self.call_stack[executed_stack].func]; + nocon = true; + break; + } else { + print_error(&err, &self.ctx[self.call_stack[executed_stack].func].clone()); + self.state = VMState::Error(err); + return; + } } set_var_id(&mut new_mem, self.functions[func.id].variables[arg].id); self.memory.push(new_mem); } + for arg in &self.functions[func.id].variables { + if arg.start != 0 { + break; + } + match get_mem_pos_by_var_id(&self.memory, arg.id) { + None => { + let err = create_error(&format!("Not enough arguments supplied for function: `{}`", func.id), operation.pos, ErrorType::SemanticError, ErrorSubType::NotEnoughArguments, &self.ctx[self.call_stack[executed_stack].func].clone()); + if executed_func.try_catch > 0 { + fallback_to_catch(&mut self.memory, &mut self.state, &mut self.functions, &mut self.call_stack, &mut executed_stack, executed_func, err); + executed_func = &func_clone[self.call_stack[executed_stack].func]; + nocon = true; + break; + } else { + print_error(&err, &self.ctx[self.call_stack[executed_stack].func].clone()); + self.state = VMState::Error(err); + return; + } + }, + _ => {} + } + } self.stack.clear(); + if nocon { + continue; + } self.call_stack.push(CallStack { func: func.id, return_reg: operation.arg2 as usize, pc: 0 }); executed_func = &func_clone[func.id]; diff --git a/test.asl b/test.asl index 008de33..451416f 100644 --- a/test.asl +++ b/test.asl @@ -1,8 +1,8 @@ -gethelj a = 1 -piszolj { - ugass(a) - gethelj test = szaft"a"szaft+1 -} csecs(err) { - ugass(szaft"Hibás bemb"szaft, err) +lőcsve test(a,b) { + ugass(a,b) } -ugass(test) \ No newline at end of file +piszolj { + test(0) +} csecs (e) { + ugass(e) +} \ No newline at end of file