refactor(vm) cleanup errors
This commit is contained in:
@@ -3,8 +3,7 @@ use crate::{
|
||||
interpreter::ICState,
|
||||
network::{CableConnectionType, Connection},
|
||||
vm::enums::script_enums::{
|
||||
LogicBatchMethod as BatchMode, LogicReagentMode as ReagentMode,
|
||||
LogicSlotType as SlotLogicType, LogicType,
|
||||
LogicReagentMode as ReagentMode, LogicSlotType as SlotLogicType, LogicType,
|
||||
},
|
||||
vm::VM,
|
||||
};
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
use crate::interpreter;
|
||||
use crate::tokens::{SplitConsecutiveIndicesExt, SplitConsecutiveWithIndices};
|
||||
use crate::vm::enums::script_enums::{
|
||||
LogicBatchMethod, LogicReagentMode, LogicSlotType, LogicType,
|
||||
};
|
||||
use crate::vm::instructions::{
|
||||
enums::InstructionOp,
|
||||
operands::{Device, DeviceSpec, Identifier, Number, Operand, RegisterSpec},
|
||||
Instruction, CONSTANTS_LOOKUP,
|
||||
};
|
||||
use crate::{
|
||||
errors::{ICError, ParseError},
|
||||
vm::enums::basic_enums::BasicEnum,
|
||||
interpreter,
|
||||
tokens::{SplitConsecutiveIndicesExt, SplitConsecutiveWithIndices},
|
||||
vm::{
|
||||
enums::{
|
||||
basic_enums::BasicEnum,
|
||||
script_enums::{LogicBatchMethod, LogicReagentMode, LogicSlotType, LogicType},
|
||||
},
|
||||
instructions::{
|
||||
enums::InstructionOp,
|
||||
operands::{Device, DeviceSpec, Identifier, Number, Operand, RegisterSpec},
|
||||
Instruction, CONSTANTS_LOOKUP,
|
||||
},
|
||||
},
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
use strum::{EnumProperty, IntoEnumIterator};
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
impl TryFrom<f64> for LogicType {
|
||||
type Error = ICError;
|
||||
@@ -1102,35 +1103,35 @@ mod tests {
|
||||
let value = lt.get_str("value");
|
||||
assert!(value.is_some());
|
||||
assert!(value.unwrap().parse::<u16>().is_ok());
|
||||
assert_eq!(lt as u16, value.unwrap());
|
||||
assert_eq!(lt as u16, value.unwrap().parse::<u16>().unwrap());
|
||||
}
|
||||
for slt in LogicSlotType::iter() {
|
||||
println!("testing SlotLogicType.{slt}");
|
||||
let value = slt.get_str("value");
|
||||
assert!(value.is_some());
|
||||
assert!(value.unwrap().parse::<u8>().is_ok());
|
||||
assert_eq!(slt as u8, value.unwrap());
|
||||
assert_eq!(slt as u8, value.unwrap().parse::<u8>().unwrap());
|
||||
}
|
||||
for bm in LogicReagentMode::iter() {
|
||||
println!("testing BatchMode.{bm}");
|
||||
let value = bm.get_str("value");
|
||||
assert!(value.is_some());
|
||||
assert!(value.unwrap().parse::<u8>().is_ok());
|
||||
assert_eq!(bm as u8, value.unwrap());
|
||||
assert_eq!(bm as u8, value.unwrap().parse::<u8>().unwrap());
|
||||
}
|
||||
for rm in LogicReagentMode::iter() {
|
||||
println!("testing ReagentMode.{rm}");
|
||||
let value = rm.get_str("value");
|
||||
assert!(value.is_some());
|
||||
assert!(value.unwrap().parse::<u8>().is_ok());
|
||||
assert_eq!(rm as u8, value.unwrap());
|
||||
assert_eq!(rm as u8, value.unwrap().parse::<u8>().unwrap());
|
||||
}
|
||||
for le in BasicEnum::iter() {
|
||||
println!("testing BasicEnum {le}");
|
||||
let value = le.get_str("value");
|
||||
assert!(value.is_some());
|
||||
assert!(value.unwrap().parse::<u32>().is_ok());
|
||||
assert_eq!(le.get_value(), value.unwrap());
|
||||
assert_eq!(le.get_value(), value.unwrap().parse::<u32>().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ use std::{
|
||||
};
|
||||
use std::{
|
||||
collections::{BTreeMap, HashSet},
|
||||
error::Error,
|
||||
fmt::Display,
|
||||
u32,
|
||||
};
|
||||
@@ -18,7 +17,7 @@ use time::format_description;
|
||||
|
||||
use crate::{
|
||||
device::SlotType,
|
||||
errors::{ICError, LineError, ParseError},
|
||||
errors::{ICError, LineError},
|
||||
grammar,
|
||||
vm::{
|
||||
enums::script_enums::{LogicSlotType as SlotLogicType, LogicType},
|
||||
@@ -2506,7 +2505,7 @@ pub fn i64_to_f64(i: i64) -> f64 {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::vm::VMError;
|
||||
use crate::errors::VMError;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -3080,7 +3080,7 @@ impl std::str::FromStr for BasicEnum {
|
||||
type Err = crate::errors::ParseError;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let end = s.len();
|
||||
match s {
|
||||
match s.to_lowercase().as_str() {
|
||||
"aircon.cold" => Ok(Self::AirCon(AirConditioningMode::Cold)),
|
||||
"aircon.hot" => Ok(Self::AirCon(AirConditioningMode::Hot)),
|
||||
"aircontrol.draught" => Ok(Self::AirControl(AirControlMode::Draught)),
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumIter, EnumProperty, EnumString, FromRepr};
|
||||
|
||||
use crate::vm::instructions::traits::*;
|
||||
use crate::vm::object::traits::Programmable;
|
||||
#[derive(
|
||||
Debug,
|
||||
|
||||
@@ -182,7 +182,7 @@ fn write_enum_aggragate_mod<T: std::io::Write>(
|
||||
type Err = crate::errors::ParseError;\n \
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {{\n \
|
||||
let end = s.len();\n \
|
||||
match s {{\n \
|
||||
match s.to_lowercase().as_str() {{\n \
|
||||
{arms}\n \
|
||||
_ => Err(crate::errors::ParseError{{ line: 0, start: 0, end, msg: format!(\"Unknown enum '{{}}'\", s) }})\n \
|
||||
}}\n \
|
||||
|
||||
@@ -52,7 +52,6 @@ fn write_instructions_enum<T: std::io::Write>(
|
||||
Display, EnumIter, EnumProperty, EnumString, FromRepr,\n\
|
||||
}};\n
|
||||
use crate::vm::object::traits::Programmable;\n\
|
||||
use crate::vm::instructions::traits::*;\n\
|
||||
"
|
||||
)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user