implement the new error system for the VM too

This commit is contained in:
afonya2 2025-06-08 21:50:17 +02:00
parent 532fffe725
commit 3e94e4a1dd
Signed by: afonya
GPG key ID: EBB9C4CAFAAFB2DC
2 changed files with 90 additions and 22 deletions

View file

@ -1,5 +1,3 @@
use std::f32::consts::E;
use crate::Context;
pub enum ErrorType {
@ -25,6 +23,7 @@ pub enum ErrorSubType {
VariableNotFound,
VariableAlreadyExists,
ArgumentDuplication,
TooManyArguments,
//Machine errors
RegisterNotFound,
MemoryOutOfBounds,
@ -38,7 +37,6 @@ pub enum ErrorSubType {
//Type errors
InvalidType,
WrongType,
NonStringKey,
}
pub struct ASLError {
@ -91,7 +89,7 @@ fn convert_subtypes_to_string(stype: &ErrorSubType) -> String {
ErrorSubType::DivisionByZero => String::from("Division by zero"),
ErrorSubType::InvalidType => String::from("Invalid type"),
ErrorSubType::WrongType => String::from("Wrong type"),
ErrorSubType::NonStringKey => String::from("Non-string key"),
ErrorSubType::TooManyArguments => String::from("Too many arguments"),
}
}
fn convert_subtypes_to_short(stype: &ErrorSubType) -> String {
@ -118,7 +116,7 @@ fn convert_subtypes_to_short(stype: &ErrorSubType) -> String {
ErrorSubType::DivisionByZero => String::from("DZ:"),
ErrorSubType::InvalidType => String::from("IT:"),
ErrorSubType::WrongType => String::from("WT:"),
ErrorSubType::NonStringKey => String::from("NS:"),
ErrorSubType::TooManyArguments => String::from("TA:"),
}
}