diff --git a/ic10emu/src/device.rs b/ic10emu/src/device.rs index 48b2e3d..06a4f06 100644 --- a/ic10emu/src/device.rs +++ b/ic10emu/src/device.rs @@ -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, }; diff --git a/ic10emu/src/grammar.rs b/ic10emu/src/grammar.rs index 0ba5559..41e582e 100644 --- a/ic10emu/src/grammar.rs +++ b/ic10emu/src/grammar.rs @@ -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 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::().is_ok()); - assert_eq!(lt as u16, value.unwrap()); + assert_eq!(lt as u16, value.unwrap().parse::().unwrap()); } for slt in LogicSlotType::iter() { println!("testing SlotLogicType.{slt}"); let value = slt.get_str("value"); assert!(value.is_some()); assert!(value.unwrap().parse::().is_ok()); - assert_eq!(slt as u8, value.unwrap()); + assert_eq!(slt as u8, value.unwrap().parse::().unwrap()); } for bm in LogicReagentMode::iter() { println!("testing BatchMode.{bm}"); let value = bm.get_str("value"); assert!(value.is_some()); assert!(value.unwrap().parse::().is_ok()); - assert_eq!(bm as u8, value.unwrap()); + assert_eq!(bm as u8, value.unwrap().parse::().unwrap()); } for rm in LogicReagentMode::iter() { println!("testing ReagentMode.{rm}"); let value = rm.get_str("value"); assert!(value.is_some()); assert!(value.unwrap().parse::().is_ok()); - assert_eq!(rm as u8, value.unwrap()); + assert_eq!(rm as u8, value.unwrap().parse::().unwrap()); } for le in BasicEnum::iter() { println!("testing BasicEnum {le}"); let value = le.get_str("value"); assert!(value.is_some()); assert!(value.unwrap().parse::().is_ok()); - assert_eq!(le.get_value(), value.unwrap()); + assert_eq!(le.get_value(), value.unwrap().parse::().unwrap()); } } diff --git a/ic10emu/src/interpreter.rs b/ic10emu/src/interpreter.rs index 0bd5f79..2676a4d 100644 --- a/ic10emu/src/interpreter.rs +++ b/ic10emu/src/interpreter.rs @@ -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::*; diff --git a/ic10emu/src/vm/enums/basic_enums.rs b/ic10emu/src/vm/enums/basic_enums.rs index 59d04c0..0d0d7af 100644 --- a/ic10emu/src/vm/enums/basic_enums.rs +++ b/ic10emu/src/vm/enums/basic_enums.rs @@ -3080,7 +3080,7 @@ impl std::str::FromStr for BasicEnum { type Err = crate::errors::ParseError; fn from_str(s: &str) -> Result { 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)), diff --git a/ic10emu/src/vm/instructions/enums.rs b/ic10emu/src/vm/instructions/enums.rs index f3a66cf..7495baa 100644 --- a/ic10emu/src/vm/instructions/enums.rs +++ b/ic10emu/src/vm/instructions/enums.rs @@ -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, diff --git a/xtask/src/generate/enums.rs b/xtask/src/generate/enums.rs index 315ab5b..a6d37b8 100644 --- a/xtask/src/generate/enums.rs +++ b/xtask/src/generate/enums.rs @@ -182,7 +182,7 @@ fn write_enum_aggragate_mod( type Err = crate::errors::ParseError;\n \ fn from_str(s: &str) -> Result {{\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 \ diff --git a/xtask/src/generate/instructions.rs b/xtask/src/generate/instructions.rs index 095e83a..778f9a4 100644 --- a/xtask/src/generate/instructions.rs +++ b/xtask/src/generate/instructions.rs @@ -52,7 +52,6 @@ fn write_instructions_enum( Display, EnumIter, EnumProperty, EnumString, FromRepr,\n\ }};\n use crate::vm::object::traits::Programmable;\n\ - use crate::vm::instructions::traits::*;\n\ " )?;