diff --git a/ic10emu/src/errors.rs b/ic10emu/src/errors.rs index da7e76e..491de72 100644 --- a/ic10emu/src/errors.rs +++ b/ic10emu/src/errors.rs @@ -151,7 +151,7 @@ pub enum ICError { #[error("incorrect operand type for instruction `{inst}` operand {index}, not a {desired} ")] IncorrectOperandType { inst: InstructionOp, - index: u32, + index: usize, desired: String, }, #[error("unknown identifier {0}")] @@ -206,6 +206,8 @@ pub enum ICError { NoGeneratedValue(String), #[error("generated Enum {0}'s value does not parse as {1} . Report this error.")] BadGeneratedValueParse(String, String), + #[error("IC with id {0} is not sloted into a circuit holder")] + NoCircuitHolder(ObjectID), } impl ICError { diff --git a/ic10emu/src/interpreter.rs b/ic10emu/src/interpreter.rs index 0dec93f..f2566c8 100644 --- a/ic10emu/src/interpreter.rs +++ b/ic10emu/src/interpreter.rs @@ -34,6 +34,8 @@ use crate::{ use serde_with::serde_as; +pub mod instructions; + #[derive(Debug, Clone, Serialize, Deserialize)] pub enum ICState { Start, @@ -461,1680 +463,6 @@ impl IC { Clr => Ok(()), // TODO Clrd => Ok(()), // TODO Label => Ok(()), // NOP - Sleep => match &operands[..] { - [a] => { - let a = a.as_value(this, inst, 1)?; - let now = time::OffsetDateTime::now_local() - .unwrap_or_else(|_| time::OffsetDateTime::now_utc()); - this.state.replace(ICState::Sleep(now, a)); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 1)), - }, // TODO - Yield => match &operands[..] { - [] => { - this.state.replace(ICState::Yield); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 0)), - }, - Define => match &operands[..] { - [name, number] => { - let &Operand::Identifier(ident) = &name else { - return Err(IncorrectOperandType { - inst: line.instruction, - index: 1, - desired: "Name".to_owned(), - }); - }; - let &Operand::Number(num) = &number else { - return Err(IncorrectOperandType { - inst: line.instruction, - index: 2, - desired: "Number".to_owned(), - }); - }; - let mut defines = this.defines.borrow_mut(); - if defines.contains_key(&ident.name) { - Err(DuplicateDefine(ident.name.clone())) - } else { - defines.insert(ident.name.clone(), num.value()); - Ok(()) - } - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Alias => match &operands[..] { - [name, device_reg] => { - let &Operand::Identifier(ident) = &name else { - return Err(IncorrectOperandType { - inst: line.instruction, - index: 1, - desired: "Name".to_owned(), - }); - }; - let alias = match &device_reg { - Operand::RegisterSpec(RegisterSpec { - indirection, - target, - }) => Operand::RegisterSpec(RegisterSpec { - indirection: *indirection, - target: *target, - }), - Operand::DeviceSpec(DeviceSpec { device, connection }) => { - Operand::DeviceSpec(DeviceSpec { - device: *device, - connection: *connection, - }) - } - _ => { - return Err(IncorrectOperandType { - inst: line.instruction, - index: 2, - desired: "Device Or Register".to_owned(), - }) - } - }; - this.aliases.borrow_mut().insert(ident.name.clone(), alias); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Move => match &operands[..] { - [reg, val] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, line.instruction, 1)?; - - let val = val.as_value(this, inst, 2)?; - this.set_register(indirection, target, val)?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - - Beq => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a == b { c as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Beqal => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a == b { c as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Breq => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a == b { - (this.ip() as f64 + c) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Beqz => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a == 0.0 { b as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Beqzal => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a == 0.0 { b as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Breqz => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a == 0.0 { - (this.ip() as f64 + b) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Bne => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a != b { c as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Bneal => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a != b { c as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Brne => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a != b { - (this.ip() as f64 + c) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Bnez => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a != 0.0 { b as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Bnezal => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a != 0.0 { b as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Brnez => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a != 0.0 { - (this.ip() as f64 + b) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Blt => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a < b { c as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Bltal => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a < b { c as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Brlt => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a < b { - (this.ip() as f64 + c) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Ble => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a <= b { c as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Bleal => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a <= b { c as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Brle => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a <= b { - (this.ip() as f64 + c) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Blez => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a <= 0.0 { b as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Blezal => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a <= 0.0 { b as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Brlez => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a <= 0.0 { - (this.ip() as f64 + b) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Bltz => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a < 0.0 { b as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Bltzal => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a < 0.0 { b as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Brltz => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a < 0.0 { - (this.ip() as f64 + b) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Bgt => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a > b { c as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Bgtal => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a > b { c as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Brgt => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a > b { - (this.ip() as f64 + c) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Bgtz => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a > 0.0 { b as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Bgtzal => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a > 0.0 { b as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Brgtz => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a > 0.0 { - (this.ip() as f64 + b) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Bge => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a >= b { c as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Bgeal => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a >= b { c as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Brge => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a >= b { - (this.ip() as f64 + c) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Bgez => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a >= 0.0 { b as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Bgezal => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a >= 0.0 { b as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Brgez => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a >= 0.0 { - (this.ip() as f64 + b) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Bap => match &operands[..] { - [a, b, c, d] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - let d = d.as_value(this, inst, 4)?; - next_ip = if f64::abs(a - b) - <= f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) - { - d as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 4)), - }, - Bapal => match &operands[..] { - [a, b, c, d] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - let d = d.as_value(this, inst, 4)?; - next_ip = if f64::abs(a - b) - <= f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) - { - d as u32 - } else { - next_ip - }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 4)), - }, - Brap => match &operands[..] { - [a, b, c, d] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - let d = d.as_value(this, inst, 4)?; - next_ip = if f64::abs(a - b) - <= f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) - { - (this.ip() as f64 + d) as u32 - } else { - next_ip - }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 4)), - }, - Bapz => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a.abs() <= f64::max(b * a.abs(), f64::EPSILON * 8.0) { - c as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Bapzal => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a.abs() <= f64::max(b * a.abs(), f64::EPSILON * 8.0) { - c as u32 - } else { - next_ip - }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Brapz => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a.abs() <= f64::max(b * a.abs(), f64::EPSILON * 8.0) { - (this.ip() as f64 + c) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Bna => match &operands[..] { - [a, b, c, d] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - let d = d.as_value(this, inst, 4)?; - next_ip = if f64::abs(a - b) - > f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) - { - d as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 4)), - }, - Bnaal => match &operands[..] { - [a, b, c, d] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - let d = d.as_value(this, inst, 4)?; - next_ip = if f64::abs(a - b) - > f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) - { - d as u32 - } else { - next_ip - }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 4)), - }, - Brna => match &operands[..] { - [a, b, c, d] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - let d = d.as_value(this, inst, 4)?; - next_ip = if f64::abs(a - b) - > f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) - { - (this.ip() as f64 + d) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 4)), - }, - Bnaz => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a.abs() > f64::max(b * a.abs(), f64::EPSILON * 8.0) { - c as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Bnazal => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a.abs() > f64::max(b * a.abs(), f64::EPSILON * 8.0) { - c as u32 - } else { - next_ip - }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Brnaz => match &operands[..] { - [a, b, c] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - let c = c.as_value(this, inst, 3)?; - next_ip = if a.abs() > f64::max(b * a.abs(), f64::EPSILON * 8.0) { - (this.ip() as f64 + c) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Bdse => match &operands[..] { - [d, a] => { - let (device, _connection) = d.as_device(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - next_ip = if device.is_some() { a as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Bdseal => match &operands[..] { - [d, a] => { - let (device, _connection) = d.as_device(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - next_ip = if device.is_some() { a as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Brdse => match &operands[..] { - [d, a] => { - let (device, _connection) = d.as_device(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - next_ip = if device.is_some() { - (this.ip() as f64 + a) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Bdns => match &operands[..] { - [d, a] => { - let (device, _connection) = d.as_device(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - next_ip = if device.is_none() { a as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Bdnsal => match &operands[..] { - [d, a] => { - let (device, _connection) = d.as_device(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - next_ip = if device.is_none() { a as u32 } else { next_ip }; - this.al(); - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Brdns => match &operands[..] { - [d, a] => { - let (device, _connection) = d.as_device(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - next_ip = if device.is_none() { - (this.ip() as f64 + a) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Bnan => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a.is_nan() { b as u32 } else { next_ip }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Brnan => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - next_ip = if a.is_nan() { - (this.ip() as f64 + b) as u32 - } else { - next_ip - }; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - - J => match &operands[..] { - [a] => { - let a = a.as_value(this, inst, 1)?; - next_ip = a as u32; - Ok(()) - } - oprs => Err(ICError::too_many_operands(oprs.len(), 1)), - }, - Jal => match &operands[..] { - [a] => { - let a = a.as_value(this, inst, 1)?; - next_ip = a as u32; - this.al(); - Ok(()) - } - oprs => Err(ICError::too_many_operands(oprs.len(), 1)), - }, - Jr => match &operands[..] { - [a] => { - let a = a.as_value(this, inst, 1)?; - next_ip = (this.ip() as f64 + a) as u32; - Ok(()) - } - oprs => Err(ICError::too_many_operands(oprs.len(), 1)), - }, - - Seq => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register(indirection, target, if a == b { 1.0 } else { 0.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Seqz => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, if a == 0.0 { 1.0 } else { 0.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Sne => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register(indirection, target, if a != b { 1.0 } else { 0.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Snez => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, if a != 0.0 { 1.0 } else { 0.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Slt => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register(indirection, target, if a < b { 1.0 } else { 0.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Sltz => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, if a < 0.0 { 1.0 } else { 0.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Sle => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register(indirection, target, if a <= b { 1.0 } else { 0.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Slez => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, if a <= 0.0 { 1.0 } else { 0.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Sgt => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register(indirection, target, if a > b { 1.0 } else { 0.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Sgtz => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, if a > 0.0 { 1.0 } else { 0.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Sge => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register(indirection, target, if a >= b { 1.0 } else { 0.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Sgez => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, if a >= 0.0 { 1.0 } else { 0.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Sap => match &operands[..] { - [reg, a, b, c] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - let c = c.as_value(this, inst, 4)?; - this.set_register( - indirection, - target, - if f64::abs(a - b) - <= f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) - { - 1.0 - } else { - 0.0 - }, - )?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Sapz => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register( - indirection, - target, - if a.abs() <= f64::max(b * a.abs(), f64::EPSILON * 8.0) { - 1.0 - } else { - 0.0 - }, - )?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Sna => match &operands[..] { - [reg, a, b, c] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - let c = c.as_value(this, inst, 4)?; - this.set_register( - indirection, - target, - if f64::abs(a - b) - > f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) - { - 1.0 - } else { - 0.0 - }, - )?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 4)), - }, - Snaz => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register( - indirection, - target, - if a.abs() > f64::max(b * a.abs(), f64::EPSILON * 8.0) { - 1.0 - } else { - 0.0 - }, - )?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Sdse => match &operands[..] { - [reg, device] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let (device, _connection) = device.as_device(this, inst, 2)?; - this.set_register( - indirection, - target, - if device.is_some() { 1.0 } else { 0.0 }, - )?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Sdns => match &operands[..] { - [reg, device] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let (device, _connection) = device.as_device(this, inst, 2)?; - this.set_register( - indirection, - target, - if device.is_none() { 1.0 } else { 0.0 }, - )?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Snan => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, if a.is_nan() { 1.0 } else { 0.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Snanz => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, if a.is_nan() { 0.0 } else { 1.0 })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - - Select => match &operands[..] { - [reg, a, b, c] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - let c = c.as_value(this, inst, 4)?; - this.set_register(indirection, target, if a != 0.0 { b } else { c })?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 4)), - }, - - Add => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register(indirection, target, a + b)?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Sub => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register(indirection, target, a - b)?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Mul => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register(indirection, target, a * b)?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Div => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register(indirection, target, a / b)?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Mod => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 1)?; - let mut m = a % b; - if m < 0.0 { - m += b; - } - this.set_register(indirection, target, m)?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Exp => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::exp(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Log => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::ln(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Sqrt => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::sqrt(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - - Max => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register(indirection, target, f64::max(a, b))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Min => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register(indirection, target, f64::min(a, b))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Ceil => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::ceil(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Floor => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::floor(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Abs => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::abs(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Round => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::round(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Trunc => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::trunc(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - - Rand => match &operands[..] { - [reg] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let val = vm.random_f64(); - this.set_register(indirection, target, val)?; - Ok(()) - } - oprs => Err(ICError::too_many_operands(oprs.len(), 1)), - }, - - Sin => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::sin(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Cos => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::cos(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Tan => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::tan(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Asin => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::asin(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Acos => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::acos(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Atan => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - this.set_register(indirection, target, f64::atan(a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Atan2 => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value(this, inst, 2)?; - let b = b.as_value(this, inst, 3)?; - this.set_register(indirection, target, f64::atan2(a, b))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - - Sll | Sla => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value_i64(this, true, inst, 2)?; - let b = b.as_value_i32(this, true, inst, 3)?; - this.set_register(indirection, target, i64_to_f64(a << b))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Srl => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value_i64(this, false, inst, 2)?; - let b = b.as_value_i32(this, true, inst, 3)?; - this.set_register(indirection, target, i64_to_f64((a as u64 >> b) as i64))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Sra => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value_i64(this, true, inst, 2)?; - let b = b.as_value_i32(this, true, inst, 3)?; - this.set_register(indirection, target, i64_to_f64(a >> b))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - - And => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value_i64(this, true, inst, 2)?; - let b = b.as_value_i64(this, true, inst, 3)?; - this.set_register(indirection, target, i64_to_f64(a & b))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Or => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value_i64(this, true, inst, 2)?; - let b = b.as_value_i64(this, true, inst, 3)?; - this.set_register(indirection, target, i64_to_f64(a | b))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Xor => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value_i64(this, true, inst, 2)?; - let b = b.as_value_i64(this, true, inst, 3)?; - this.set_register(indirection, target, i64_to_f64(a ^ b))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Nor => match &operands[..] { - [reg, a, b] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value_i64(this, true, inst, 2)?; - let b = b.as_value_i64(this, true, inst, 3)?; - this.set_register(indirection, target, i64_to_f64(!(a | b)))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Not => match &operands[..] { - [reg, a] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let a = a.as_value_i64(this, true, inst, 2)?; - this.set_register(indirection, target, i64_to_f64(!a))?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - - Push => match &operands[..] { - [a] => { - let a = a.as_value(this, inst, 1)?; - this.push(a)?; - Ok(()) - } - oprs => Err(ICError::too_many_operands(oprs.len(), 1)), - }, - Pop => match &operands[..] { - [reg] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let val = this.pop()?; - this.set_register(indirection, target, val)?; - Ok(()) - } - oprs => Err(ICError::too_many_operands(oprs.len(), 1)), - }, - Poke => match &operands[..] { - [a, b] => { - let a = a.as_value(this, inst, 1)?; - let b = b.as_value(this, inst, 2)?; - this.poke(a, b)?; - Ok(()) - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 2)), - }, - Peek => match &operands[..] { - [reg] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let val = this.peek()?; - this.set_register(indirection, target, val)?; - Ok(()) - } - oprs => Err(ICError::too_many_operands(oprs.len(), 1)), - }, - - Get => match &operands[..] { - [reg, dev_id, addr] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let (Some(device_id), _connection) = dev_id.as_device(this, inst, 2)? - else { - return Err(DeviceNotSet); - }; - let device = vm.get_device_same_network(this.device, device_id); - match device { - Some(device) => match device.borrow().ic.as_ref() { - Some(ic_id) => { - let addr = addr.as_value(this, inst, 3)?; - let val = { - if ic_id == &this.id { - this.peek_addr(addr) - } else { - let ic = - vm.circuit_holders.get(ic_id).unwrap().borrow(); - ic.peek_addr(addr) - } - }?; - this.set_register(indirection, target, val)?; - Ok(()) - } - None => Err(DeviceHasNoIC), - }, - None => Err(UnknownDeviceID(device_id as f64)), - } - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Getd => match &operands[..] { - [reg, dev_id, addr] => { - let RegisterSpec { - indirection, - target, - } = reg.as_register(this, inst, 1)?; - let (Some(device_id), _connection) = dev_id.as_device(this, inst, 2)? - else { - return Err(DeviceNotSet); - }; - let device = vm.get_device_same_network(this.device, device_id); - match device { - Some(device) => match device.borrow().ic.as_ref() { - Some(ic_id) => { - let addr = addr.as_value(this, inst, 3)?; - let val = { - if ic_id == &this.id { - this.peek_addr(addr) - } else { - let ic = - vm.circuit_holders.get(ic_id).unwrap().borrow(); - ic.peek_addr(addr) - } - }?; - this.set_register(indirection, target, val)?; - Ok(()) - } - None => Err(DeviceHasNoIC), - }, - None => Err(UnknownDeviceID(device_id as f64)), - } - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Put => match &operands[..] { - [dev_id, addr, val] => { - let (Some(device_id), _connection) = dev_id.as_device(this, inst, 1)? - else { - return Err(DeviceNotSet); - }; - let device = vm.get_device_same_network(this.device, device_id); - match device { - Some(device) => match device.borrow().ic.as_ref() { - Some(ic_id) => { - let addr = addr.as_value(this, inst, 2)?; - let val = val.as_value(this, inst, 3)?; - if ic_id == &this.id { - this.poke(addr, val)?; - } else { - let ic = vm.circuit_holders.get(ic_id).unwrap().borrow(); - ic.poke(addr, val)?; - } - vm.set_modified(device_id); - Ok(()) - } - None => Err(DeviceHasNoIC), - }, - None => Err(UnknownDeviceID(device_id as f64)), - } - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, - Putd => match &operands[..] { - [dev_id, addr, val] => { - let device_id = dev_id.as_value(this, inst, 1)?; - if device_id >= u16::MAX as f64 || device_id < u16::MIN as f64 { - return Err(DeviceIndexOutOfRange(device_id)); - } - let device = vm.get_device_same_network(this.device, device_id as u32); - match device { - Some(device) => match device.borrow().ic.as_ref() { - Some(ic_id) => { - let addr = addr.as_value(this, inst, 2)?; - let val = val.as_value(this, inst, 3)?; - if ic_id == &this.id { - this.poke(addr, val)?; - } else { - let ic = vm.circuit_holders.get(ic_id).unwrap().borrow(); - ic.poke(addr, val)?; - } - vm.set_modified(device_id as u32); - Ok(()) - } - None => Err(DeviceHasNoIC), - }, - None => Err(UnknownDeviceID(device_id)), - } - } - oprs => Err(ICError::mismatch_operands(oprs.len(), 3)), - }, S => match &operands[..] { [dev, lt, val] => { diff --git a/ic10emu/src/interpreter/instructions.rs b/ic10emu/src/interpreter/instructions.rs new file mode 100644 index 0000000..e7ce18c --- /dev/null +++ b/ic10emu/src/interpreter/instructions.rs @@ -0,0 +1,2262 @@ +use crate::{ + errors::ICError, + interpreter::{i64_to_f64, ICState}, + vm::{ + instructions::{ + operands::{InstOperand, RegisterSpec}, + traits::*, + }, + object::{errors::MemoryError, traits::*, ObjectID}, + }, +}; +pub trait IC10Marker: IntegratedCircuit {} + +impl SleepInstruction for T { + /// sleep a(r?|num) + fn execute_inner(&mut self, a: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let now = + time::OffsetDateTime::now_local().unwrap_or_else(|_| time::OffsetDateTime::now_utc()); + self.set_state(ICState::Sleep(now, a)); + Ok(()) + } +} + +impl YieldInstruction for T { + /// yield + fn execute_inner(&mut self) -> Result<(), ICError> { + self.set_state(ICState::Yield); + Ok(()) + } +} + +impl DefineInstruction for T { + /// define str num + fn execute_inner(&mut self, string: &InstOperand, num: &InstOperand) -> Result<(), ICError> { + let ident = string.as_ident()?; + let num = num.as_number()?; + if self.get_defines().contains_key(&ident.name) { + Err(ICError::DuplicateDefine(ident.name.clone())) + } else { + self.get_defines_mut() + .insert(ident.name.clone(), num.value()); + Ok(()) + } + } +} + +impl AliasInstruction for T { + /// alias str r?|d? + fn execute_inner(&mut self, string: &InstOperand, r: &InstOperand) -> Result<(), ICError> { + let ident = string.as_ident()?; + let alias = r.as_aliasable()?; + self.get_aliases_mut().insert(ident.name.clone(), alias); + Ok(()) + } +} + +impl MoveInstruction for T { + /// move r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + + let val = a.as_value(self)?; + self.set_register(indirection, target, val)?; + Ok(()) + } +} + +impl BeqInstruction for T { + /// beq a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a == b { + self.set_next_instruction(c); + } + Ok(()) + } +} +impl BeqalInstruction for T { + /// beqal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a == b { + self.set_next_instruction(c); + self.al(); + } + Ok(()) + } +} + +impl BreqInstruction for T { + /// breq a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a == b { + self.set_next_instruction_relative(c); + } + Ok(()) + } +} + +impl BeqzInstruction for T { + /// beqz a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a == 0.0 { + self.set_next_instruction(b) + } + Ok(()) + } +} + +impl BeqzalInstruction for T { + /// beqzal a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a == 0.0 { + self.set_next_instruction(b); + self.al(); + } + Ok(()) + } +} + +impl BreqzInstruction for T { + /// breqz a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a == 0.0 { + self.set_next_instruction_relative(b); + } + Ok(()) + } +} + +impl BneInstruction for T { + /// bne a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a != b { + self.set_next_instruction(c); + } + Ok(()) + } +} + +impl BnealInstruction for T { + /// bneal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a != b { + self.set_next_instruction(c); + self.al(); + } + Ok(()) + } +} + +impl BrneInstruction for T { + /// brne a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a != b { + self.set_next_instruction_relative(c); + } + Ok(()) + } +} + +impl BnezInstruction for T { + /// bnez a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a != 0.0 { + self.set_next_instruction(b) + } + Ok(()) + } +} + +impl BnezalInstruction for T { + /// bnezal a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a != 0.0 { + self.set_next_instruction(b); + self.al(); + } + Ok(()) + } +} + +impl BrnezInstruction for T { + /// brnez a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a != 0.0 { + self.set_next_instruction_relative(b) + } + Ok(()) + } +} + +impl BltInstruction for T { + /// blt a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a < b { + self.set_next_instruction(c); + } + Ok(()) + } +} + +impl BltalInstruction for T { + /// bltal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a < b { + self.set_next_instruction(c); + self.al(); + } + Ok(()) + } +} + +impl BrltInstruction for T { + /// brlt a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a < b { + self.set_next_instruction_relative(c); + } + Ok(()) + } +} + +impl BltzInstruction for T { + /// bltz a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a < 0.0 { + self.set_next_instruction(b); + } + Ok(()) + } +} + +impl BltzalInstruction for T { + /// bltzal a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a < 0.0 { + self.set_next_instruction(b); + self.al(); + } + Ok(()) + } +} + +impl BrltzInstruction for T { + /// brltz a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a < 0.0 { + self.set_next_instruction_relative(b); + } + Ok(()) + } +} + +impl BleInstruction for T { + /// ble a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a <= b { + self.set_next_instruction(c); + } + Ok(()) + } +} +impl BlealInstruction for T { + /// bleal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a <= b { + self.set_next_instruction(c); + self.al(); + } + Ok(()) + } +} + +impl BrleInstruction for T { + /// brle a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a <= b { + self.set_next_instruction_relative(c); + } + Ok(()) + } +} + +impl BlezInstruction for T { + /// blez a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a <= 0.0 { + self.set_next_instruction(b); + } + Ok(()) + } +} + +impl BlezalInstruction for T { + /// blezal a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a <= 0.0 { + self.set_next_instruction(b); + self.al(); + } + Ok(()) + } +} + +impl BrlezInstruction for T { + /// brlez a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a <= 0.0 { + self.set_next_instruction_relative(b); + } + Ok(()) + } +} + +impl BgtInstruction for T { + /// bgt a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a > b { + self.set_next_instruction(c); + } + Ok(()) + } +} +impl BgtalInstruction for T { + /// bgtal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a > b { + self.set_next_instruction(c); + self.al(); + } + Ok(()) + } +} + +impl BrgtInstruction for T { + /// brgt a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a > b { + self.set_next_instruction_relative(c); + } + Ok(()) + } +} + +impl BgtzInstruction for T { + /// bgtz a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a > 0.0 { + self.set_next_instruction(b); + } + Ok(()) + } +} + +impl BgtzalInstruction for T { + /// bgtzal a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a > 0.0 { + self.set_next_instruction(b); + self.al(); + } + Ok(()) + } +} + +impl BrgtzInstruction for T { + /// brgtz a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a > 0.0 { + self.set_next_instruction_relative(b); + } + Ok(()) + } +} + +impl BgeInstruction for T { + /// bge a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a >= b { + self.set_next_instruction(c); + } + Ok(()) + } +} + +impl BgealInstruction for T { + /// bgeal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a >= b { + self.set_next_instruction(c); + self.al(); + } + Ok(()) + } +} + +impl BrgeInstruction for T { + /// brge a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a >= b { + self.set_next_instruction_relative(c); + } + Ok(()) + } +} + +impl BgezInstruction for T { + /// bgez a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a >= 0.0 { + self.set_next_instruction(b); + } + Ok(()) + } +} + +impl BgezalInstruction for T { + /// bgezal a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a >= 0.0 { + self.set_next_instruction(b); + self.al(); + } + Ok(()) + } +} + +impl BrgezInstruction for T { + /// brgez a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a >= 0.0 { + self.set_next_instruction_relative(b); + } + Ok(()) + } +} + +impl BapInstruction for T { + /// bap a(r?|num) b(r?|num) c(r?|num) d(r?|num) + fn execute_inner( + &mut self, + + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + d: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + let d = d.as_value(self)?; + if f64::abs(a - b) <= f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { + self.set_next_instruction(d); + } + Ok(()) + } +} + +impl BapalInstruction for T { + /// bapal a(r?|num) b(r?|num) c(r?|num) d(r?|num) + fn execute_inner( + &mut self, + + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + d: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + let d = d.as_value(self)?; + if f64::abs(a - b) <= f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { + self.set_next_instruction(d); + self.al(); + } + Ok(()) + } +} + +impl BrapInstruction for T { + /// brap a(r?|num) b(r?|num) c(r?|num) d(r?|num) + fn execute_inner( + &mut self, + + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + d: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + let d = d.as_value(self)?; + if f64::abs(a - b) <= f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { + self.set_next_instruction_relative(d); + } + Ok(()) + } +} + +impl BapzInstruction for T { + /// bapz a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a.abs() <= f64::max(b * a.abs(), f64::EPSILON * 8.0) { + } else { + self.set_next_instruction(c); + } + Ok(()) + } +} + +impl BapzalInstruction for T { + /// bapzal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a.abs() <= f64::max(b * a.abs(), f64::EPSILON * 8.0) { + } else { + self.set_next_instruction(c); + self.al(); + } + Ok(()) + } +} + +impl BrapzInstruction for T { + /// brapz a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a.abs() <= f64::max(b * a.abs(), f64::EPSILON * 8.0) { + } else { + self.set_next_instruction_relative(c); + } + Ok(()) + } +} + +impl BnaInstruction for T { + /// bna a(r?|num) b(r?|num) c(r?|num) d(r?|num) + fn execute_inner( + &mut self, + + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + d: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + let d = d.as_value(self)?; + if f64::abs(a - b) > f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { + self.set_next_instruction(d); + } + Ok(()) + } +} +impl BnaalInstruction for T { + /// bnaal a(r?|num) b(r?|num) c(r?|num) d(r?|num) + fn execute_inner( + &mut self, + + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + d: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + let d = d.as_value(self)?; + if f64::abs(a - b) > f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { + self.set_next_instruction(d); + self.al(); + } + Ok(()) + } +} +impl BrnaInstruction for T { + /// brna a(r?|num) b(r?|num) c(r?|num) d(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + d: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + let d = d.as_value(self)?; + if f64::abs(a - b) > f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { + self.set_next_instruction_relative(d); + } + Ok(()) + } +} + +impl BnazInstruction for T { + /// bnaz a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a.abs() > f64::max(b * a.abs(), f64::EPSILON * 8.0) { + self.set_next_instruction(c); + } + Ok(()) + } +} +impl BnazalInstruction for T { + /// bnazal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a.abs() > f64::max(b * a.abs(), f64::EPSILON * 8.0) { + self.set_next_instruction(c); + self.al(); + } + Ok(()) + } +} +impl BrnazInstruction for T { + /// brnaz a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + if a.abs() > f64::max(b * a.abs(), f64::EPSILON * 8.0) { + self.set_next_instruction_relative(c); + } + Ok(()) + } +} +impl BdseInstruction for T { + /// bdse d? a(r?|num) + fn execute_inner(&mut self, d: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let (device, connection) = d.as_device(self)?; + let a = a.as_value(self)?; + if self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_index(device, connection) + .is_some() + { + self.set_next_instruction(a); + } + Ok(()) + } +} + +impl BdsealInstruction for T { + /// bdseal d? a(r?|num) + fn execute_inner(&mut self, d: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let (device, connection) = d.as_device(self)?; + let a = a.as_value(self)?; + if self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_index(device, connection) + .is_some() + { + self.set_next_instruction(a); + self.al(); + } + Ok(()) + } +} + +impl BrdseInstruction for T { + /// brdse d? a(r?|num) + fn execute_inner(&mut self, d: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let (device, connection) = d.as_device(self)?; + let a = a.as_value(self)?; + if self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_index(device, connection) + .is_some() + { + self.set_next_instruction_relative(a); + } + Ok(()) + } +} + +impl BdnsInstruction for T { + /// bdns d? a(r?|num) + fn execute_inner(&mut self, d: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let (device, connection) = d.as_device(self)?; + let a = a.as_value(self)?; + if self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_index(device, connection) + .is_none() + { + self.set_next_instruction(a); + } + Ok(()) + } +} + +impl BdnsalInstruction for T { + /// bdnsal d? a(r?|num) + fn execute_inner(&mut self, d: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let (device, connection) = d.as_device(self)?; + let a = a.as_value(self)?; + if self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_index(device, connection) + .is_none() + { + self.set_next_instruction(a); + self.al(); + } + Ok(()) + } +} + +impl BrdnsInstruction for T { + /// brdns d? a(r?|num) + fn execute_inner(&mut self, d: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let (device, connection) = d.as_device(self)?; + let a = a.as_value(self)?; + if self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_index(device, connection) + .is_none() + { + self.set_next_instruction_relative(a); + } + Ok(()) + } +} + +impl BnanInstruction for T { + /// bnan a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a.is_nan() { + self.set_next_instruction(b); + } + Ok(()) + } +} + +impl BrnanInstruction for T { + /// brnan a(r?|num) b(r?|num) + fn execute_inner(&mut self, a: &InstOperand, b: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + let b = b.as_value(self)?; + if a.is_nan() { + self.set_next_instruction_relative(b); + } + Ok(()) + } +} + +impl JInstruction for T { + /// j int + fn execute_inner(&mut self, int: &InstOperand) -> Result<(), ICError> { + let int = int.as_value(self)?; + self.set_next_instruction(int); + Ok(()) + } +} +impl JalInstruction for T { + /// jal int + fn execute_inner(&mut self, int: &InstOperand) -> Result<(), ICError> { + let int = int.as_value(self)?; + self.set_next_instruction(int); + self.al(); + Ok(()) + } +} +impl JrInstruction for T { + /// jr int + fn execute_inner(&mut self, int: &InstOperand) -> Result<(), ICError> { + let int = int.as_value(self)?; + self.set_next_instruction_relative(int); + Ok(()) + } +} +impl SeqInstruction for T { + /// seq r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register(indirection, target, if a == b { 1.0 } else { 0.0 })?; + Ok(()) + } +} + +impl SeqzInstruction for T { + /// seqz r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, if a == 0.0 { 1.0 } else { 0.0 })?; + Ok(()) + } +} + +impl SneInstruction for T { + /// sne r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register(indirection, target, if a != b { 1.0 } else { 0.0 })?; + Ok(()) + } +} + +impl SnezInstruction for T { + /// snez r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, if a != 0.0 { 1.0 } else { 0.0 })?; + Ok(()) + } +} + +impl SltInstruction for T { + /// slt r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register(indirection, target, if a < b { 1.0 } else { 0.0 })?; + Ok(()) + } +} + +impl SltzInstruction for T { + /// sltz r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, if a < 0.0 { 1.0 } else { 0.0 })?; + Ok(()) + } +} + +impl SleInstruction for T { + /// sle r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register(indirection, target, if a <= b { 1.0 } else { 0.0 })?; + Ok(()) + } +} +impl SlezInstruction for T { + /// slez r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, if a <= 0.0 { 1.0 } else { 0.0 })?; + Ok(()) + } +} + +impl SgtInstruction for T { + /// sgt r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register(indirection, target, if a > b { 1.0 } else { 0.0 })?; + Ok(()) + } +} + +impl SgtzInstruction for T { + /// sgtz r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, if a > 0.0 { 1.0 } else { 0.0 })?; + Ok(()) + } +} + +impl SgeInstruction for T { + /// sge r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register(indirection, target, if a >= b { 1.0 } else { 0.0 })?; + Ok(()) + } +} + +impl SgezInstruction for T { + /// sgez r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, if a >= 0.0 { 1.0 } else { 0.0 })?; + Ok(()) + } +} + +impl SapInstruction for T { + /// sap r? a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + self.set_register( + indirection, + target, + if f64::abs(a - b) <= f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { + 1.0 + } else { + 0.0 + }, + )?; + Ok(()) + } +} + +impl SapzInstruction for T { + /// sapz r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register( + indirection, + target, + if a.abs() <= f64::max(b * a.abs(), f64::EPSILON * 8.0) { + 1.0 + } else { + 0.0 + }, + )?; + Ok(()) + } +} + +impl SnaInstruction for T { + /// sna r? a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + self.set_register( + indirection, + target, + if f64::abs(a - b) > f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { + 1.0 + } else { + 0.0 + }, + )?; + Ok(()) + } +} + +impl SnazInstruction for T { + /// snaz r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register( + indirection, + target, + if a.abs() > f64::max(b * a.abs(), f64::EPSILON * 8.0) { + 1.0 + } else { + 0.0 + }, + )?; + Ok(()) + } +} + +impl SdseInstruction for T { + /// sdse r? d? + fn execute_inner(&mut self, r: &InstOperand, d: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let (device, connection) = d.as_device(self)?; + let logicable = self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_index(device, connection); + self.set_register( + indirection, + target, + if logicable.is_some() { 1.0 } else { 0.0 }, + )?; + Ok(()) + } +} +impl SdnsInstruction for T { + /// sdns r? d? + fn execute_inner(&mut self, r: &InstOperand, d: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let (device, connection) = d.as_device(self)?; + let logicable = self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_index(device, connection); + self.set_register( + indirection, + target, + if logicable.is_none() { 1.0 } else { 0.0 }, + )?; + Ok(()) + } +} + +impl SnanInstruction for T { + /// snan r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, if a.is_nan() { 1.0 } else { 0.0 })?; + Ok(()) + } +} + +impl SnanzInstruction for T { + /// snanz r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, if a.is_nan() { 0.0 } else { 1.0 })?; + Ok(()) + } +} + +impl SelectInstruction for T { + /// select r? a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + c: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let c = c.as_value(self)?; + self.set_register(indirection, target, if a != 0.0 { b } else { c })?; + Ok(()) + } +} + +impl AddInstruction for T { + /// add r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register(indirection, target, a + b)?; + Ok(()) + } +} + +impl SubInstruction for T { + /// sub r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register(indirection, target, a - b)?; + Ok(()) + } +} +impl MulInstruction for T { + /// mul r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register(indirection, target, a * b)?; + Ok(()) + } +} +impl DivInstruction for T { + /// div r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register(indirection, target, a / b)?; + Ok(()) + } +} + +impl ModInstruction for T { + /// mod r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + let mut m = a % b; + if m < 0.0 { + m += b; + } + self.set_register(indirection, target, m)?; + Ok(()) + } +} + +impl ExpInstruction for T { + /// exp r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::exp(a))?; + Ok(()) + } +} + +impl LogInstruction for T { + /// log r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::ln(a))?; + Ok(()) + } +} + +impl SqrtInstruction for T { + /// sqrt r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::sqrt(a))?; + Ok(()) + } +} + +impl MaxInstruction for T { + /// max r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register(indirection, target, f64::max(a, b))?; + Ok(()) + } +} + +impl MinInstruction for T { + /// min r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register(indirection, target, f64::min(a, b))?; + Ok(()) + } +} +impl CeilInstruction for T { + /// ceil r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::ceil(a))?; + Ok(()) + } +} + +impl FloorInstruction for T { + /// floor r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::floor(a))?; + Ok(()) + } +} + +impl AbsInstruction for T { + /// abs r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::abs(a))?; + Ok(()) + } +} + +impl RoundInstruction for T { + /// round r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::round(a))?; + Ok(()) + } +} + +impl TruncInstruction for T { + /// trunc r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::trunc(a))?; + Ok(()) + } +} + +impl RandInstruction for T { + /// rand r? + fn execute_inner(&mut self, r: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let val = self.get_vm().random_f64(); + self.set_register(indirection, target, val)?; + Ok(()) + } +} +impl SinInstruction for T { + /// sin r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::sin(a))?; + Ok(()) + } +} +impl CosInstruction for T { + /// cos r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::cos(a))?; + Ok(()) + } +} +impl TanInstruction for T { + /// tan r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::tan(a))?; + Ok(()) + } +} +impl AsinInstruction for T { + /// asin r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::asin(a))?; + Ok(()) + } +} +impl AcosInstruction for T { + /// acos r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::acos(a))?; + Ok(()) + } +} +impl AtanInstruction for T { + /// atan r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + self.set_register(indirection, target, f64::atan(a))?; + Ok(()) + } +} +impl Atan2Instruction for T { + /// atan2 r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value(self)?; + let b = b.as_value(self)?; + self.set_register(indirection, target, f64::atan2(a, b))?; + Ok(()) + } +} + +impl SllInstruction for T { + /// sll r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value_i64(self, true)?; + let b = b.as_value_i32(self, true)?; + self.set_register(indirection, target, i64_to_f64(a << b))?; + Ok(()) + } +} + +impl SlaInstruction for T { + /// sla r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value_i64(self, true)?; + let b = b.as_value_i32(self, true)?; + self.set_register(indirection, target, i64_to_f64(a << b))?; + Ok(()) + } +} + +impl SrlInstruction for T { + /// srl r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value_i64(self, false)?; + let b = b.as_value_i32(self, true)?; + self.set_register(indirection, target, i64_to_f64((a as u64 >> b) as i64))?; + Ok(()) + } +} + +impl SraInstruction for T { + /// sra r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value_i64(self, true)?; + let b = b.as_value_i32(self, true)?; + self.set_register(indirection, target, i64_to_f64(a >> b))?; + Ok(()) + } +} + +impl AndInstruction for T { + /// and r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value_i64(self, true)?; + let b = b.as_value_i64(self, true)?; + self.set_register(indirection, target, i64_to_f64(a & b))?; + Ok(()) + } +} + +impl OrInstruction for T { + /// or r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value_i64(self, true)?; + let b = b.as_value_i64(self, true)?; + self.set_register(indirection, target, i64_to_f64(a | b))?; + Ok(()) + } +} + +impl XorInstruction for T { + /// xor r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value_i64(self, true)?; + let b = b.as_value_i64(self, true)?; + self.set_register(indirection, target, i64_to_f64(a ^ b))?; + Ok(()) + } +} + +impl NorInstruction for T { + /// nor r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + a: &InstOperand, + b: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value_i64(self, true)?; + let b = b.as_value_i64(self, true)?; + self.set_register(indirection, target, i64_to_f64(!(a | b)))?; + Ok(()) + } +} + +impl NotInstruction for T { + /// not r? a(r?|num) + fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let a = a.as_value_i64(self, true)?; + self.set_register(indirection, target, i64_to_f64(!a))?; + Ok(()) + } +} + +impl PushInstruction for T { + /// push a(r?|num) + fn execute_inner(&mut self, a: &InstOperand) -> Result<(), ICError> { + let a = a.as_value(self)?; + self.push_stack(a)?; + Ok(()) + } +} + +impl PopInstruction for T { + /// pop r? + fn execute_inner(&mut self, r: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let val = self.pop_stack()?; + self.set_register(indirection, target, val)?; + Ok(()) + } +} + +impl PokeInstruction for T { + /// poke address(r?|num) value(r?|num) + fn execute_inner(&mut self, address: &InstOperand, value: &InstOperand) -> Result<(), ICError> { + let address = address.as_value(self)?; + let value = value.as_value(self)?; + self.put_stack(address, value)?; + Ok(()) + } +} + +impl PeekInstruction for T { + /// peek r? + fn execute_inner(&mut self, r: &InstOperand) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let val = self.peek_stack()?; + self.set_register(indirection, target, val)?; + Ok(()) + } +} + +impl GetInstruction for T { + /// get r? d? address(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + d: &InstOperand, + address: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let address = address.as_value(self)?; + let (device, connection) = d.as_device(self)?; + let Some(logicable) = self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_index(device, connection) else { + return Err(ICError::DeviceNotSet); + }; + let Some(memory) = logicable.as_memory_readable() else { + return Err(MemoryError::NotReadable.into()); + }; + self.set_register(indirection, target, memory.get_memory(address as i32)?)?; + Ok(()) + } +} + +impl GetdInstruction for T { + /// getd r? id(r?|num) address(r?|num) + fn execute_inner( + &mut self, + r: &InstOperand, + id: &InstOperand, + address: &InstOperand, + ) -> Result<(), ICError> { + let RegisterSpec { + indirection, + target, + } = r.as_register(self)?; + let id = id.as_value(self)?; + let address = address.as_value(self)?; + let Some(logicable) = self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_id(id as ObjectID, None) else { + return Err(ICError::UnknownDeviceId(id)); + }; + let Some(memory) = logicable.as_memory_readable() else { + return Err(MemoryError::NotReadable.into()); + }; + self.set_register(indirection, target, memory.get_memory(address as i32)?)?; + Ok(()) + } +} + +impl PutInstruction for T { + /// put d? address(r?|num) value(r?|num) + fn execute_inner( + &mut self, + d: &InstOperand, + address: &InstOperand, + value: &InstOperand, + ) -> Result<(), ICError> { + let (device, connection) = d.as_device(self)?; + let address = address.as_value(self)?; + let value = value.as_value(self)?; + let Some(logicable) = self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_index_mut(device, connection) else { + return Err(ICError::DeviceNotSet); + }; + let Some(memory) = logicable.as_memory_writable() else { + return Err(MemoryError::NotWriteable.into()); + }; + memory.set_memory(address as i32, value)?; + Ok(()) + } +} + +impl PutdInstruction for T { + /// putd id(r?|num) address(r?|num) value(r?|num) + fn execute_inner( + &mut self, + id: &InstOperand, + address: &InstOperand, + value: &InstOperand, + ) -> Result<(), ICError> { + let id = id.as_value(self)?; + let address = address.as_value(self)?; + let value = value.as_value(self)?; + let Some(logicable) = self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_id_mut(id as ObjectID, None) else { + return Err(ICError::DeviceNotSet); + }; + let Some(memory) = logicable.as_memory_writable() else { + return Err(MemoryError::NotWriteable.into()); + }; + memory.set_memory(address as i32, value)?; + Ok(()) + } +} + +impl ClrInstruction for T { + /// clr d? + fn execute_inner(&mut self, d: &InstOperand) -> Result<(), ICError> { + let (device, connection) = d.as_device(self)?; + let Some(logicable) = self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_index_mut(device, connection) else { + return Err(ICError::DeviceNotSet); + }; + let Some(memory) = logicable.as_memory_writable() else { + return Err(MemoryError::NotWriteable.into()); + }; + memory.clear_memory()?; + Ok(()) + } +} +impl ClrdInstruction for T { + /// clrd id(r?|num) + fn execute_inner(&mut self, id: &InstOperand) -> Result<(), ICError> { + let id = id.as_value(self)?; + let Some(logicable) = self + .get_circuit_holder() + .ok_or(ICError::NoCircuitHolder(self.get_id()))? + .get_logicable_from_id_mut(id as ObjectID, None) else { + return Err(ICError::DeviceNotSet); + }; + let Some(memory) = logicable.as_memory_writable() else { + return Err(MemoryError::NotWriteable.into()); + }; + memory.clear_memory()?; + Ok(()) + } +} + +// impl HcfInstruction for T { +// /// hcf +// fn execute_inner(&mut self, vm: &VM) -> Result<(), ICError>; +// } +// impl LInstruction for T { +// /// l r? d? logicType +// fn execute_inner( +// &mut self, +// +// r: &InstOperand, +// d: &InstOperand, +// logic_type: &InstOperand, +// ) -> Result<(), ICError>; +// } +// impl LabelInstruction for T { +// /// label d? str +// fn execute_inner(&mut self, d: &InstOperand, str: &InstOperand) -> Result<(), ICError>; +// } +// impl LbInstruction for T { +// /// lb r? deviceHash logicType batchMode +// fn execute_inner( +// &mut self, +// +// r: &InstOperand, +// device_hash: &InstOperand, +// logic_type: &InstOperand, +// batch_mode: &InstOperand, +// ) -> Result<(), ICError>; +// } +// impl LbnInstruction for T { +// /// lbn r? deviceHash nameHash logicType batchMode +// fn execute_inner( +// &mut self, +// +// r: &InstOperand, +// device_hash: &InstOperand, +// name_hash: &InstOperand, +// logic_type: &InstOperand, +// batch_mode: &InstOperand, +// ) -> Result<(), ICError>; +// } +// impl LbnsInstruction for T { +// /// lbns r? deviceHash nameHash slotIndex logicSlotType batchMode +// fn execute_inner( +// &mut self, +// +// r: &InstOperand, +// device_hash: &InstOperand, +// name_hash: &InstOperand, +// slot_index: &InstOperand, +// logic_slot_type: &InstOperand, +// batch_mode: &InstOperand, +// ) -> Result<(), ICError>; +// } +// impl LbsInstruction for T { +// /// lbs r? deviceHash slotIndex logicSlotType batchMode +// fn execute_inner( +// &mut self, +// +// r: &InstOperand, +// device_hash: &InstOperand, +// slot_index: &InstOperand, +// logic_slot_type: &InstOperand, +// batch_mode: &InstOperand, +// ) -> Result<(), ICError>; +// } +// impl LdInstruction for T { +// /// ld r? id(r?|num) logicType +// fn execute_inner( +// &mut self, +// +// r: &InstOperand, +// id: &InstOperand, +// logic_type: &InstOperand, +// ) -> Result<(), ICError>; +// } +// impl LogInstruction for T { +// /// log r? a(r?|num) +// fn execute_inner(&mut self, r: &InstOperand, a: &InstOperand) -> Result<(), ICError>; +// } +// impl LrInstruction for T { +// /// lr r? d? reagentMode int +// fn execute_inner( +// &mut self, +// +// r: &InstOperand, +// d: &InstOperand, +// reagent_mode: &InstOperand, +// int: &InstOperand, +// ) -> Result<(), ICError>; +// } +// impl LsInstruction for T { +// /// ls r? d? slotIndex logicSlotType +// fn execute_inner( +// &mut self, +// +// r: &InstOperand, +// d: &InstOperand, +// slot_index: &InstOperand, +// logic_slot_type: &InstOperand, +// ) -> Result<(), ICError>; +// } +// impl SInstruction for T { +// /// s d? logicType r? +// fn execute_inner( +// &mut self, +// +// d: &InstOperand, +// logic_type: &InstOperand, +// r: &InstOperand, +// ) -> Result<(), ICError>; +// } +// impl SbInstruction for T { +// /// sb deviceHash logicType r? +// fn execute_inner( +// &mut self, +// +// device_hash: &InstOperand, +// logic_type: &InstOperand, +// r: &InstOperand, +// ) -> Result<(), ICError>; +// } +// impl SbnInstruction for T { +// /// sbn deviceHash nameHash logicType r? +// fn execute_inner( +// &mut self, +// +// device_hash: &InstOperand, +// name_hash: &InstOperand, +// logic_type: &InstOperand, +// r: &InstOperand, +// ) -> Result<(), ICError>; +// } +// impl SbsInstruction for T { +// /// sbs deviceHash slotIndex logicSlotType r? +// fn execute_inner( +// &mut self, +// +// device_hash: &InstOperand, +// slot_index: &InstOperand, +// logic_slot_type: &InstOperand, +// r: &InstOperand, +// ) -> Result<(), ICError>; +// } +// impl SdInstruction for T { +// /// sd id(r?|num) logicType r? +// fn execute_inner( +// &mut self, +// +// id: &InstOperand, +// logic_type: &InstOperand, +// r: &InstOperand, +// ) -> Result<(), ICError>; +// } +// impl SsInstruction for T { +// /// ss d? slotIndex logicSlotType r? +// fn execute_inner( +// &mut self, +// +// d: &InstOperand, +// slot_index: &InstOperand, +// logic_slot_type: &InstOperand, +// r: &InstOperand, +// ) -> Result<(), ICError>; +// } +// diff --git a/ic10emu/src/vm.rs b/ic10emu/src/vm.rs index a8e3cb4..e319d2b 100644 --- a/ic10emu/src/vm.rs +++ b/ic10emu/src/vm.rs @@ -87,6 +87,10 @@ impl VM { vm } + pub fn random_f64(&self) -> f64 { + self.random.borrow_mut().next_f64() + } + pub fn add_device_from_template( self: &Rc, template: ObjectTemplate, diff --git a/ic10emu/src/vm/instructions/operands.rs b/ic10emu/src/vm/instructions/operands.rs index ac270e2..c951314 100644 --- a/ic10emu/src/vm/instructions/operands.rs +++ b/ic10emu/src/vm/instructions/operands.rs @@ -59,13 +59,55 @@ pub enum Operand { Identifier(Identifier), } -impl Operand { - pub fn as_value( - &self, - ic: &IC, - inst: InstructionOp, - index: u32, - ) -> Result { +pub struct InstOperand { + pub operand: Operand, + pub inst: InstructionOp, + pub index: usize, +} + +impl InstOperand { + pub fn new(operand: &Operand, inst: InstructionOp, index: usize) -> Self { + InstOperand { + operand: operand.clone(), + inst, + index, + } + } + + pub fn as_ident(&self) -> Result { + let &Operand::Identifier(ident) = &self.operand else { + return Err(ICError::IncorrectOperandType { + inst: self.inst, + index: self.index, + desired: "Name".to_owned(), + }); + }; + Ok(ident) + } + + pub fn as_number(&self) -> Result { + let &Operand::Number(num) = &self.operand else { + return Err(ICError::IncorrectOperandType { + inst: self.inst, + index: self.index, + desired: "Number".to_owned(), + }); + }; + Ok(num) + } + + pub fn as_aliasable(&self) -> Result { + match &self.operand { + Operand::RegisterSpec { .. } | Operand::DeviceSpec { .. } => Ok(self.operand.clone()), + _ => Err(ICError::IncorrectOperandType { + inst: self.inst, + index: self.index, + desired: "Device Or Register".to_owned(), + }), + } + } + + pub fn as_value(&self, ic: &IC) -> Result { match self.translate_alias(ic) { Operand::RegisterSpec(RegisterSpec { indirection, @@ -117,8 +159,8 @@ impl Operand { } Operand::Identifier(id) => Err(ICError::UnknownIdentifier(id.name.to_string())), Operand::DeviceSpec { .. } => Err(ICError::IncorrectOperandType { - inst, - index, + inst: self.inst, + index: self.index, desired: "Value".to_owned(), }), } @@ -128,16 +170,14 @@ impl Operand { &self, ic: &IC, signed: bool, - inst: InstructionOp, - index: u32, ) -> Result { - match self { - Self::Number(num) => Ok(num.value_i64(signed)), + match &self.operand { + Operand::Number(num) => Ok(num.value_i64(signed)), _ => { - let val = self.as_value(ic, inst, index)?; - if val < -9.223_372_036_854_776E18 { + let val = self.as_value(ic)?; + if val < i64::MIN as f64 { Err(ICError::ShiftUnderflowI64) - } else if val <= 9.223_372_036_854_776E18 { + } else if val <= i64::MAX as f64 { Ok(interpreter::f64_to_i64(val, signed)) } else { Err(ICError::ShiftOverflowI64) @@ -149,13 +189,11 @@ impl Operand { &self, ic: &IC, signed: bool, - inst: InstructionOp, - index: u32, ) -> Result { - match self { - Self::Number(num) => Ok(num.value_i64(signed) as i32), + match &self.operand { + Operand::Number(num) => Ok(num.value_i64(signed) as i32), _ => { - let val = self.as_value(ic, inst, index)?; + let val = self.as_value(ic)?; if val < i32::MIN as f64 { Err(ICError::ShiftUnderflowI32) } else if val <= i32::MAX as f64 { @@ -167,112 +205,89 @@ impl Operand { } } - pub fn as_register( - &self, - ic: &IC, - inst: InstructionOp, - index: u32, - ) -> Result { + pub fn as_register(&self, ic: &IC) -> Result { match self.translate_alias(ic) { Operand::RegisterSpec(reg) => Ok(reg), Operand::Identifier(id) => Err(ICError::UnknownIdentifier(id.name.to_string())), _ => Err(ICError::IncorrectOperandType { - inst, - index, + inst: self.inst, + index: self.index, desired: "Register".to_owned(), }), } } + /// interpret the operand as a device index, i32::MAX is db pub fn as_device( &self, ic: &IC, - inst: InstructionOp, - index: u32, - ) -> Result<(Option, Option), ICError> { + ) -> Result<(i32, Option), ICError> { match self.translate_alias(ic) { Operand::DeviceSpec(DeviceSpec { device, connection }) => match device { - Device::Db => Ok((Some(0), connection)), - Device::Numbered(p) => Ok((Some(p), connection)), + Device::Db => Ok((i32::MAX, connection)), + Device::Numbered(p) => Ok((p as i32, connection)), Device::Indirect { indirection, target, } => { let val = ic.get_register(indirection, target)?; - Ok((Some(val as u32), connection)) + Ok((val as i32, connection)) } }, Operand::Identifier(id) => Err(ICError::UnknownIdentifier(id.name.to_string())), _ => Err(ICError::IncorrectOperandType { - inst, - index, + inst: self.inst, + index: self.index, desired: "Value".to_owned(), }), } } - pub fn as_logic_type( - &self, - ic: &IC, - inst: InstructionOp, - index: u32, - ) -> Result { - match &self { + pub fn as_logic_type(&self, ic: &IC) -> Result { + match &self.operand { Operand::Type { logic_type: Some(lt), .. } => Ok(*lt), - _ => LogicType::try_from(self.as_value(ic, inst, index)?), + _ => LogicType::try_from(self.as_value(ic)?), } } pub fn as_slot_logic_type( &self, ic: &IC, - inst: InstructionOp, - index: u32, ) -> Result { - match &self { + match &self.operand { Operand::Type { slot_logic_type: Some(slt), .. } => Ok(*slt), - _ => LogicSlotType::try_from(self.as_value(ic, inst, index)?), + _ => LogicSlotType::try_from(self.as_value(ic)?), } } - pub fn as_batch_mode( - &self, - ic: &IC, - inst: InstructionOp, - index: u32, - ) -> Result { - match &self { + pub fn as_batch_mode(&self, ic: &IC) -> Result { + match &self.operand { Operand::Type { batch_mode: Some(bm), .. } => Ok(*bm), - _ => BatchMode::try_from(self.as_value(ic, inst, index)?), + _ => BatchMode::try_from(self.as_value(ic)?), } } - pub fn as_reagent_mode( - &self, - ic: &IC, - inst: InstructionOp, - index: u32, - ) -> Result { - match &self { + pub fn as_reagent_mode(&self, ic: &IC) -> Result { + match &self.operand { Operand::Type { reagent_mode: Some(rm), .. } => Ok(*rm), - _ => ReagentMode::try_from(self.as_value(ic, inst, index)?), + _ => ReagentMode::try_from(self.as_value(ic)?), } } - pub fn translate_alias(&self, ic: &IC) -> Self { - match &self { + pub fn translate_alias(&self, ic: &IC) -> Operand { + match self.operand { Operand::Identifier(id) | Operand::Type { identifier: id, .. } => { if let Some(alias) = ic.get_aliases().get(&id.name) { alias.clone() @@ -281,7 +296,7 @@ impl Operand { } else if let Some(label) = ic.get_labels().get(&id.name) { Operand::Number(Number::Float(*label as f64)) } else { - self.clone() + self.operand.clone() } } _ => self.clone(), diff --git a/ic10emu/src/vm/instructions/traits.rs b/ic10emu/src/vm/instructions/traits.rs index 59c1b56..518a513 100644 --- a/ic10emu/src/vm/instructions/traits.rs +++ b/ic10emu/src/vm/instructions/traits.rs @@ -9,6 +9,7 @@ // // ================================================= +use crate::vm::instructions::enums::InstructionOp; use crate::vm::object::traits::IntegratedCircuit; pub trait AbsInstruction: IntegratedCircuit { /// abs r? a(r?|num) @@ -16,6 +17,18 @@ pub trait AbsInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + AbsInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Abs, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Abs, 1), + ) + } + /// abs r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait AcosInstruction: IntegratedCircuit { @@ -24,6 +37,18 @@ pub trait AcosInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + AcosInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Acos, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Acos, 1), + ) + } + /// acos r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait AddInstruction: IntegratedCircuit { @@ -33,6 +58,20 @@ pub trait AddInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + AddInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Add, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Add, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Add, 2), + ) + } + /// add r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait AliasInstruction: IntegratedCircuit { @@ -41,6 +80,18 @@ pub trait AliasInstruction: IntegratedCircuit { &mut self, string: &crate::vm::instructions::operands::Operand, r: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + AliasInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(string, InstructionOp::Alias, 0), + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Alias, 1), + ) + } + /// alias str r?|d? + fn execute_inner( + &mut self, + string: &crate::vm::instructions::operands::InstOperand, + r: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait AndInstruction: IntegratedCircuit { @@ -50,6 +101,20 @@ pub trait AndInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + AndInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::And, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::And, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::And, 2), + ) + } + /// and r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait AsinInstruction: IntegratedCircuit { @@ -58,6 +123,18 @@ pub trait AsinInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + AsinInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Asin, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Asin, 1), + ) + } + /// asin r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait AtanInstruction: IntegratedCircuit { @@ -66,6 +143,18 @@ pub trait AtanInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + AtanInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Atan, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Atan, 1), + ) + } + /// atan r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait Atan2Instruction: IntegratedCircuit { @@ -75,6 +164,20 @@ pub trait Atan2Instruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + Atan2Instruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Atan2, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Atan2, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Atan2, 2), + ) + } + /// atan2 r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BapInstruction: IntegratedCircuit { @@ -85,6 +188,22 @@ pub trait BapInstruction: IntegratedCircuit { b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, d: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BapInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bap, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bap, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bap, 2), + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Bap, 3), + ) + } + /// bap a(r?|num) b(r?|num) c(r?|num) d(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, + d: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BapalInstruction: IntegratedCircuit { @@ -95,6 +214,22 @@ pub trait BapalInstruction: IntegratedCircuit { b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, d: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BapalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bapal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bapal, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bapal, 2), + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Bapal, 3), + ) + } + /// bapal a(r?|num) b(r?|num) c(r?|num) d(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, + d: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BapzInstruction: IntegratedCircuit { @@ -104,6 +239,20 @@ pub trait BapzInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BapzInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bapz, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bapz, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bapz, 2), + ) + } + /// bapz a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BapzalInstruction: IntegratedCircuit { @@ -113,6 +262,20 @@ pub trait BapzalInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BapzalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bapzal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bapzal, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bapzal, 2), + ) + } + /// bapzal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BdnsInstruction: IntegratedCircuit { @@ -121,6 +284,18 @@ pub trait BdnsInstruction: IntegratedCircuit { &mut self, d: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BdnsInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Bdns, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bdns, 1), + ) + } + /// bdns d? a(r?|num) + fn execute_inner( + &mut self, + d: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BdnsalInstruction: IntegratedCircuit { @@ -129,6 +304,18 @@ pub trait BdnsalInstruction: IntegratedCircuit { &mut self, d: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BdnsalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Bdnsal, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bdnsal, 1), + ) + } + /// bdnsal d? a(r?|num) + fn execute_inner( + &mut self, + d: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BdseInstruction: IntegratedCircuit { @@ -137,6 +324,18 @@ pub trait BdseInstruction: IntegratedCircuit { &mut self, d: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BdseInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Bdse, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bdse, 1), + ) + } + /// bdse d? a(r?|num) + fn execute_inner( + &mut self, + d: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BdsealInstruction: IntegratedCircuit { @@ -145,6 +344,18 @@ pub trait BdsealInstruction: IntegratedCircuit { &mut self, d: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BdsealInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Bdseal, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bdseal, 1), + ) + } + /// bdseal d? a(r?|num) + fn execute_inner( + &mut self, + d: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BeqInstruction: IntegratedCircuit { @@ -154,6 +365,20 @@ pub trait BeqInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BeqInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Beq, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Beq, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Beq, 2), + ) + } + /// beq a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BeqalInstruction: IntegratedCircuit { @@ -163,6 +388,20 @@ pub trait BeqalInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BeqalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Beqal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Beqal, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Beqal, 2), + ) + } + /// beqal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BeqzInstruction: IntegratedCircuit { @@ -171,6 +410,18 @@ pub trait BeqzInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BeqzInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Beqz, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Beqz, 1), + ) + } + /// beqz a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BeqzalInstruction: IntegratedCircuit { @@ -179,6 +430,18 @@ pub trait BeqzalInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BeqzalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Beqzal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Beqzal, 1), + ) + } + /// beqzal a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BgeInstruction: IntegratedCircuit { @@ -188,6 +451,20 @@ pub trait BgeInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BgeInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bge, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bge, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bge, 2), + ) + } + /// bge a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BgealInstruction: IntegratedCircuit { @@ -197,6 +474,20 @@ pub trait BgealInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BgealInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bgeal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bgeal, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bgeal, 2), + ) + } + /// bgeal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BgezInstruction: IntegratedCircuit { @@ -205,6 +496,18 @@ pub trait BgezInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BgezInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bgez, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bgez, 1), + ) + } + /// bgez a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BgezalInstruction: IntegratedCircuit { @@ -213,6 +516,18 @@ pub trait BgezalInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BgezalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bgezal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bgezal, 1), + ) + } + /// bgezal a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BgtInstruction: IntegratedCircuit { @@ -222,6 +537,20 @@ pub trait BgtInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BgtInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bgt, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bgt, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bgt, 2), + ) + } + /// bgt a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BgtalInstruction: IntegratedCircuit { @@ -231,6 +560,20 @@ pub trait BgtalInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BgtalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bgtal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bgtal, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bgtal, 2), + ) + } + /// bgtal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BgtzInstruction: IntegratedCircuit { @@ -239,6 +582,18 @@ pub trait BgtzInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BgtzInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bgtz, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bgtz, 1), + ) + } + /// bgtz a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BgtzalInstruction: IntegratedCircuit { @@ -247,6 +602,18 @@ pub trait BgtzalInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BgtzalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bgtzal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bgtzal, 1), + ) + } + /// bgtzal a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BleInstruction: IntegratedCircuit { @@ -256,6 +623,20 @@ pub trait BleInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BleInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Ble, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Ble, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Ble, 2), + ) + } + /// ble a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BlealInstruction: IntegratedCircuit { @@ -265,6 +646,20 @@ pub trait BlealInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BlealInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bleal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bleal, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bleal, 2), + ) + } + /// bleal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BlezInstruction: IntegratedCircuit { @@ -273,6 +668,18 @@ pub trait BlezInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BlezInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Blez, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Blez, 1), + ) + } + /// blez a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BlezalInstruction: IntegratedCircuit { @@ -281,6 +688,18 @@ pub trait BlezalInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BlezalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Blezal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Blezal, 1), + ) + } + /// blezal a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BltInstruction: IntegratedCircuit { @@ -290,6 +709,20 @@ pub trait BltInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BltInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Blt, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Blt, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Blt, 2), + ) + } + /// blt a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BltalInstruction: IntegratedCircuit { @@ -299,6 +732,20 @@ pub trait BltalInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BltalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bltal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bltal, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bltal, 2), + ) + } + /// bltal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BltzInstruction: IntegratedCircuit { @@ -307,6 +754,18 @@ pub trait BltzInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BltzInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bltz, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bltz, 1), + ) + } + /// bltz a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BltzalInstruction: IntegratedCircuit { @@ -315,6 +774,18 @@ pub trait BltzalInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BltzalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bltzal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bltzal, 1), + ) + } + /// bltzal a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BnaInstruction: IntegratedCircuit { @@ -325,6 +796,22 @@ pub trait BnaInstruction: IntegratedCircuit { b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, d: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BnaInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bna, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bna, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bna, 2), + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Bna, 3), + ) + } + /// bna a(r?|num) b(r?|num) c(r?|num) d(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, + d: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BnaalInstruction: IntegratedCircuit { @@ -335,6 +822,22 @@ pub trait BnaalInstruction: IntegratedCircuit { b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, d: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BnaalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bnaal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bnaal, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bnaal, 2), + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Bnaal, 3), + ) + } + /// bnaal a(r?|num) b(r?|num) c(r?|num) d(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, + d: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BnanInstruction: IntegratedCircuit { @@ -343,6 +846,18 @@ pub trait BnanInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BnanInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bnan, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bnan, 1), + ) + } + /// bnan a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BnazInstruction: IntegratedCircuit { @@ -352,6 +867,20 @@ pub trait BnazInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BnazInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bnaz, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bnaz, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bnaz, 2), + ) + } + /// bnaz a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BnazalInstruction: IntegratedCircuit { @@ -361,6 +890,20 @@ pub trait BnazalInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BnazalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bnazal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bnazal, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bnazal, 2), + ) + } + /// bnazal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BneInstruction: IntegratedCircuit { @@ -370,6 +913,20 @@ pub trait BneInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BneInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bne, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bne, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bne, 2), + ) + } + /// bne a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BnealInstruction: IntegratedCircuit { @@ -379,6 +936,20 @@ pub trait BnealInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BnealInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bneal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bneal, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Bneal, 2), + ) + } + /// bneal a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BnezInstruction: IntegratedCircuit { @@ -387,6 +958,18 @@ pub trait BnezInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BnezInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bnez, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bnez, 1), + ) + } + /// bnez a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BnezalInstruction: IntegratedCircuit { @@ -395,6 +978,18 @@ pub trait BnezalInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BnezalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Bnezal, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Bnezal, 1), + ) + } + /// bnezal a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrapInstruction: IntegratedCircuit { @@ -405,6 +1000,22 @@ pub trait BrapInstruction: IntegratedCircuit { b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, d: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrapInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brap, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brap, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Brap, 2), + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Brap, 3), + ) + } + /// brap a(r?|num) b(r?|num) c(r?|num) d(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, + d: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrapzInstruction: IntegratedCircuit { @@ -414,6 +1025,20 @@ pub trait BrapzInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrapzInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brapz, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brapz, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Brapz, 2), + ) + } + /// brapz a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrdnsInstruction: IntegratedCircuit { @@ -422,6 +1047,18 @@ pub trait BrdnsInstruction: IntegratedCircuit { &mut self, d: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrdnsInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Brdns, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brdns, 1), + ) + } + /// brdns d? a(r?|num) + fn execute_inner( + &mut self, + d: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrdseInstruction: IntegratedCircuit { @@ -430,6 +1067,18 @@ pub trait BrdseInstruction: IntegratedCircuit { &mut self, d: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrdseInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Brdse, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brdse, 1), + ) + } + /// brdse d? a(r?|num) + fn execute_inner( + &mut self, + d: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BreqInstruction: IntegratedCircuit { @@ -439,6 +1088,20 @@ pub trait BreqInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BreqInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Breq, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Breq, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Breq, 2), + ) + } + /// breq a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BreqzInstruction: IntegratedCircuit { @@ -447,6 +1110,18 @@ pub trait BreqzInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BreqzInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Breqz, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Breqz, 1), + ) + } + /// breqz a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrgeInstruction: IntegratedCircuit { @@ -456,6 +1131,20 @@ pub trait BrgeInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrgeInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brge, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brge, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Brge, 2), + ) + } + /// brge a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrgezInstruction: IntegratedCircuit { @@ -464,6 +1153,18 @@ pub trait BrgezInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrgezInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brgez, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brgez, 1), + ) + } + /// brgez a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrgtInstruction: IntegratedCircuit { @@ -473,6 +1174,20 @@ pub trait BrgtInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrgtInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brgt, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brgt, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Brgt, 2), + ) + } + /// brgt a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrgtzInstruction: IntegratedCircuit { @@ -481,6 +1196,18 @@ pub trait BrgtzInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrgtzInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brgtz, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brgtz, 1), + ) + } + /// brgtz a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrleInstruction: IntegratedCircuit { @@ -490,6 +1217,20 @@ pub trait BrleInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrleInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brle, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brle, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Brle, 2), + ) + } + /// brle a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrlezInstruction: IntegratedCircuit { @@ -498,6 +1239,18 @@ pub trait BrlezInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrlezInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brlez, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brlez, 1), + ) + } + /// brlez a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrltInstruction: IntegratedCircuit { @@ -507,6 +1260,20 @@ pub trait BrltInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrltInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brlt, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brlt, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Brlt, 2), + ) + } + /// brlt a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrltzInstruction: IntegratedCircuit { @@ -515,6 +1282,18 @@ pub trait BrltzInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrltzInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brltz, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brltz, 1), + ) + } + /// brltz a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrnaInstruction: IntegratedCircuit { @@ -525,6 +1304,22 @@ pub trait BrnaInstruction: IntegratedCircuit { b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, d: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrnaInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brna, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brna, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Brna, 2), + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Brna, 3), + ) + } + /// brna a(r?|num) b(r?|num) c(r?|num) d(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, + d: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrnanInstruction: IntegratedCircuit { @@ -533,6 +1328,18 @@ pub trait BrnanInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrnanInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brnan, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brnan, 1), + ) + } + /// brnan a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrnazInstruction: IntegratedCircuit { @@ -542,6 +1349,20 @@ pub trait BrnazInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrnazInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brnaz, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brnaz, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Brnaz, 2), + ) + } + /// brnaz a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrneInstruction: IntegratedCircuit { @@ -551,6 +1372,20 @@ pub trait BrneInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrneInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brne, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brne, 1), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Brne, 2), + ) + } + /// brne a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait BrnezInstruction: IntegratedCircuit { @@ -559,6 +1394,18 @@ pub trait BrnezInstruction: IntegratedCircuit { &mut self, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + BrnezInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Brnez, 0), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Brnez, 1), + ) + } + /// brnez a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait CeilInstruction: IntegratedCircuit { @@ -567,6 +1414,18 @@ pub trait CeilInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + CeilInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Ceil, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Ceil, 1), + ) + } + /// ceil r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait ClrInstruction: IntegratedCircuit { @@ -574,6 +1433,16 @@ pub trait ClrInstruction: IntegratedCircuit { fn execute_clr( &mut self, d: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + ClrInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Clr, 0), + ) + } + /// clr d? + fn execute_inner( + &mut self, + d: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait ClrdInstruction: IntegratedCircuit { @@ -581,6 +1450,16 @@ pub trait ClrdInstruction: IntegratedCircuit { fn execute_clrd( &mut self, id: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + ClrdInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(id, InstructionOp::Clrd, 0), + ) + } + /// clrd id(r?|num) + fn execute_inner( + &mut self, + id: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait CosInstruction: IntegratedCircuit { @@ -589,6 +1468,18 @@ pub trait CosInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + CosInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Cos, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Cos, 1), + ) + } + /// cos r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait DefineInstruction: IntegratedCircuit { @@ -597,6 +1488,18 @@ pub trait DefineInstruction: IntegratedCircuit { &mut self, string: &crate::vm::instructions::operands::Operand, num: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + DefineInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(string, InstructionOp::Define, 0), + &crate::vm::instructions::operands::InstOperand::new(num, InstructionOp::Define, 1), + ) + } + /// define str num + fn execute_inner( + &mut self, + string: &crate::vm::instructions::operands::InstOperand, + num: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait DivInstruction: IntegratedCircuit { @@ -606,6 +1509,20 @@ pub trait DivInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + DivInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Div, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Div, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Div, 2), + ) + } + /// div r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait ExpInstruction: IntegratedCircuit { @@ -614,6 +1531,18 @@ pub trait ExpInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + ExpInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Exp, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Exp, 1), + ) + } + /// exp r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait FloorInstruction: IntegratedCircuit { @@ -622,6 +1551,18 @@ pub trait FloorInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + FloorInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Floor, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Floor, 1), + ) + } + /// floor r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait GetInstruction: IntegratedCircuit { @@ -631,6 +1572,20 @@ pub trait GetInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, d: &crate::vm::instructions::operands::Operand, address: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + GetInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Get, 0), + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Get, 1), + &crate::vm::instructions::operands::InstOperand::new(address, InstructionOp::Get, 2), + ) + } + /// get r? d? address(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + d: &crate::vm::instructions::operands::InstOperand, + address: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait GetdInstruction: IntegratedCircuit { @@ -640,17 +1595,45 @@ pub trait GetdInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, id: &crate::vm::instructions::operands::Operand, address: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + GetdInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Getd, 0), + &crate::vm::instructions::operands::InstOperand::new(id, InstructionOp::Getd, 1), + &crate::vm::instructions::operands::InstOperand::new(address, InstructionOp::Getd, 2), + ) + } + /// getd r? id(r?|num) address(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + id: &crate::vm::instructions::operands::InstOperand, + address: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait HcfInstruction: IntegratedCircuit { /// hcf - fn execute_hcf(&mut self) -> Result<(), crate::errors::ICError>; + fn execute_hcf(&mut self) -> Result<(), crate::errors::ICError> { + HcfInstruction::execute_inner(self) + } + /// hcf + fn execute_inner(&mut self) -> Result<(), crate::errors::ICError>; } pub trait JInstruction: IntegratedCircuit { /// j int fn execute_j( &mut self, int: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + JInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(int, InstructionOp::J, 0), + ) + } + /// j int + fn execute_inner( + &mut self, + int: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait JalInstruction: IntegratedCircuit { @@ -658,6 +1641,16 @@ pub trait JalInstruction: IntegratedCircuit { fn execute_jal( &mut self, int: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + JalInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(int, InstructionOp::Jal, 0), + ) + } + /// jal int + fn execute_inner( + &mut self, + int: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait JrInstruction: IntegratedCircuit { @@ -665,6 +1658,16 @@ pub trait JrInstruction: IntegratedCircuit { fn execute_jr( &mut self, int: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + JrInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(int, InstructionOp::Jr, 0), + ) + } + /// jr int + fn execute_inner( + &mut self, + int: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait LInstruction: IntegratedCircuit { @@ -674,6 +1677,20 @@ pub trait LInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, d: &crate::vm::instructions::operands::Operand, logic_type: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + LInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::L, 0), + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::L, 1), + &crate::vm::instructions::operands::InstOperand::new(logic_type, InstructionOp::L, 2), + ) + } + /// l r? d? logicType + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + d: &crate::vm::instructions::operands::InstOperand, + logic_type: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait LabelInstruction: IntegratedCircuit { @@ -682,6 +1699,18 @@ pub trait LabelInstruction: IntegratedCircuit { &mut self, d: &crate::vm::instructions::operands::Operand, string: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + LabelInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Label, 0), + &crate::vm::instructions::operands::InstOperand::new(string, InstructionOp::Label, 1), + ) + } + /// label d? str + fn execute_inner( + &mut self, + d: &crate::vm::instructions::operands::InstOperand, + string: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait LbInstruction: IntegratedCircuit { @@ -692,6 +1721,22 @@ pub trait LbInstruction: IntegratedCircuit { device_hash: &crate::vm::instructions::operands::Operand, logic_type: &crate::vm::instructions::operands::Operand, batch_mode: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + LbInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Lb, 0), + &crate::vm::instructions::operands::InstOperand::new(device_hash, InstructionOp::Lb, 1), + &crate::vm::instructions::operands::InstOperand::new(logic_type, InstructionOp::Lb, 2), + &crate::vm::instructions::operands::InstOperand::new(batch_mode, InstructionOp::Lb, 3), + ) + } + /// lb r? deviceHash logicType batchMode + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + device_hash: &crate::vm::instructions::operands::InstOperand, + logic_type: &crate::vm::instructions::operands::InstOperand, + batch_mode: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait LbnInstruction: IntegratedCircuit { @@ -703,6 +1748,28 @@ pub trait LbnInstruction: IntegratedCircuit { name_hash: &crate::vm::instructions::operands::Operand, logic_type: &crate::vm::instructions::operands::Operand, batch_mode: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + LbnInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Lbn, 0), + &crate::vm::instructions::operands::InstOperand::new( + device_hash, + InstructionOp::Lbn, + 1, + ), + &crate::vm::instructions::operands::InstOperand::new(name_hash, InstructionOp::Lbn, 2), + &crate::vm::instructions::operands::InstOperand::new(logic_type, InstructionOp::Lbn, 3), + &crate::vm::instructions::operands::InstOperand::new(batch_mode, InstructionOp::Lbn, 4), + ) + } + /// lbn r? deviceHash nameHash logicType batchMode + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + device_hash: &crate::vm::instructions::operands::InstOperand, + name_hash: &crate::vm::instructions::operands::InstOperand, + logic_type: &crate::vm::instructions::operands::InstOperand, + batch_mode: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait LbnsInstruction: IntegratedCircuit { @@ -715,6 +1782,42 @@ pub trait LbnsInstruction: IntegratedCircuit { slot_index: &crate::vm::instructions::operands::Operand, logic_slot_type: &crate::vm::instructions::operands::Operand, batch_mode: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + LbnsInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Lbns, 0), + &crate::vm::instructions::operands::InstOperand::new( + device_hash, + InstructionOp::Lbns, + 1, + ), + &crate::vm::instructions::operands::InstOperand::new(name_hash, InstructionOp::Lbns, 2), + &crate::vm::instructions::operands::InstOperand::new( + slot_index, + InstructionOp::Lbns, + 3, + ), + &crate::vm::instructions::operands::InstOperand::new( + logic_slot_type, + InstructionOp::Lbns, + 4, + ), + &crate::vm::instructions::operands::InstOperand::new( + batch_mode, + InstructionOp::Lbns, + 5, + ), + ) + } + /// lbns r? deviceHash nameHash slotIndex logicSlotType batchMode + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + device_hash: &crate::vm::instructions::operands::InstOperand, + name_hash: &crate::vm::instructions::operands::InstOperand, + slot_index: &crate::vm::instructions::operands::InstOperand, + logic_slot_type: &crate::vm::instructions::operands::InstOperand, + batch_mode: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait LbsInstruction: IntegratedCircuit { @@ -726,6 +1829,32 @@ pub trait LbsInstruction: IntegratedCircuit { slot_index: &crate::vm::instructions::operands::Operand, logic_slot_type: &crate::vm::instructions::operands::Operand, batch_mode: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + LbsInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Lbs, 0), + &crate::vm::instructions::operands::InstOperand::new( + device_hash, + InstructionOp::Lbs, + 1, + ), + &crate::vm::instructions::operands::InstOperand::new(slot_index, InstructionOp::Lbs, 2), + &crate::vm::instructions::operands::InstOperand::new( + logic_slot_type, + InstructionOp::Lbs, + 3, + ), + &crate::vm::instructions::operands::InstOperand::new(batch_mode, InstructionOp::Lbs, 4), + ) + } + /// lbs r? deviceHash slotIndex logicSlotType batchMode + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + device_hash: &crate::vm::instructions::operands::InstOperand, + slot_index: &crate::vm::instructions::operands::InstOperand, + logic_slot_type: &crate::vm::instructions::operands::InstOperand, + batch_mode: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait LdInstruction: IntegratedCircuit { @@ -735,6 +1864,20 @@ pub trait LdInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, id: &crate::vm::instructions::operands::Operand, logic_type: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + LdInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Ld, 0), + &crate::vm::instructions::operands::InstOperand::new(id, InstructionOp::Ld, 1), + &crate::vm::instructions::operands::InstOperand::new(logic_type, InstructionOp::Ld, 2), + ) + } + /// ld r? id(r?|num) logicType + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + id: &crate::vm::instructions::operands::InstOperand, + logic_type: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait LogInstruction: IntegratedCircuit { @@ -743,6 +1886,18 @@ pub trait LogInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + LogInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Log, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Log, 1), + ) + } + /// log r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait LrInstruction: IntegratedCircuit { @@ -753,6 +1908,26 @@ pub trait LrInstruction: IntegratedCircuit { d: &crate::vm::instructions::operands::Operand, reagent_mode: &crate::vm::instructions::operands::Operand, int: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + LrInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Lr, 0), + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Lr, 1), + &crate::vm::instructions::operands::InstOperand::new( + reagent_mode, + InstructionOp::Lr, + 2, + ), + &crate::vm::instructions::operands::InstOperand::new(int, InstructionOp::Lr, 3), + ) + } + /// lr r? d? reagentMode int + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + d: &crate::vm::instructions::operands::InstOperand, + reagent_mode: &crate::vm::instructions::operands::InstOperand, + int: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait LsInstruction: IntegratedCircuit { @@ -763,6 +1938,26 @@ pub trait LsInstruction: IntegratedCircuit { d: &crate::vm::instructions::operands::Operand, slot_index: &crate::vm::instructions::operands::Operand, logic_slot_type: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + LsInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Ls, 0), + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Ls, 1), + &crate::vm::instructions::operands::InstOperand::new(slot_index, InstructionOp::Ls, 2), + &crate::vm::instructions::operands::InstOperand::new( + logic_slot_type, + InstructionOp::Ls, + 3, + ), + ) + } + /// ls r? d? slotIndex logicSlotType + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + d: &crate::vm::instructions::operands::InstOperand, + slot_index: &crate::vm::instructions::operands::InstOperand, + logic_slot_type: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait MaxInstruction: IntegratedCircuit { @@ -772,6 +1967,20 @@ pub trait MaxInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + MaxInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Max, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Max, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Max, 2), + ) + } + /// max r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait MinInstruction: IntegratedCircuit { @@ -781,6 +1990,20 @@ pub trait MinInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + MinInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Min, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Min, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Min, 2), + ) + } + /// min r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait ModInstruction: IntegratedCircuit { @@ -790,6 +2013,20 @@ pub trait ModInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + ModInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Mod, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Mod, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Mod, 2), + ) + } + /// mod r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait MoveInstruction: IntegratedCircuit { @@ -798,6 +2035,18 @@ pub trait MoveInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + MoveInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Move, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Move, 1), + ) + } + /// move r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait MulInstruction: IntegratedCircuit { @@ -807,6 +2056,20 @@ pub trait MulInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + MulInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Mul, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Mul, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Mul, 2), + ) + } + /// mul r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait NorInstruction: IntegratedCircuit { @@ -816,6 +2079,20 @@ pub trait NorInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + NorInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Nor, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Nor, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Nor, 2), + ) + } + /// nor r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait NotInstruction: IntegratedCircuit { @@ -824,6 +2101,18 @@ pub trait NotInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + NotInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Not, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Not, 1), + ) + } + /// not r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait OrInstruction: IntegratedCircuit { @@ -833,6 +2122,20 @@ pub trait OrInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + OrInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Or, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Or, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Or, 2), + ) + } + /// or r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait PeekInstruction: IntegratedCircuit { @@ -840,6 +2143,16 @@ pub trait PeekInstruction: IntegratedCircuit { fn execute_peek( &mut self, r: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + PeekInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Peek, 0), + ) + } + /// peek r? + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait PokeInstruction: IntegratedCircuit { @@ -848,6 +2161,18 @@ pub trait PokeInstruction: IntegratedCircuit { &mut self, address: &crate::vm::instructions::operands::Operand, value: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + PokeInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(address, InstructionOp::Poke, 0), + &crate::vm::instructions::operands::InstOperand::new(value, InstructionOp::Poke, 1), + ) + } + /// poke address(r?|num) value(r?|num) + fn execute_inner( + &mut self, + address: &crate::vm::instructions::operands::InstOperand, + value: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait PopInstruction: IntegratedCircuit { @@ -855,6 +2180,16 @@ pub trait PopInstruction: IntegratedCircuit { fn execute_pop( &mut self, r: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + PopInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Pop, 0), + ) + } + /// pop r? + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait PushInstruction: IntegratedCircuit { @@ -862,6 +2197,16 @@ pub trait PushInstruction: IntegratedCircuit { fn execute_push( &mut self, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + PushInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Push, 0), + ) + } + /// push a(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait PutInstruction: IntegratedCircuit { @@ -871,6 +2216,20 @@ pub trait PutInstruction: IntegratedCircuit { d: &crate::vm::instructions::operands::Operand, address: &crate::vm::instructions::operands::Operand, value: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + PutInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Put, 0), + &crate::vm::instructions::operands::InstOperand::new(address, InstructionOp::Put, 1), + &crate::vm::instructions::operands::InstOperand::new(value, InstructionOp::Put, 2), + ) + } + /// put d? address(r?|num) value(r?|num) + fn execute_inner( + &mut self, + d: &crate::vm::instructions::operands::InstOperand, + address: &crate::vm::instructions::operands::InstOperand, + value: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait PutdInstruction: IntegratedCircuit { @@ -880,6 +2239,20 @@ pub trait PutdInstruction: IntegratedCircuit { id: &crate::vm::instructions::operands::Operand, address: &crate::vm::instructions::operands::Operand, value: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + PutdInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(id, InstructionOp::Putd, 0), + &crate::vm::instructions::operands::InstOperand::new(address, InstructionOp::Putd, 1), + &crate::vm::instructions::operands::InstOperand::new(value, InstructionOp::Putd, 2), + ) + } + /// putd id(r?|num) address(r?|num) value(r?|num) + fn execute_inner( + &mut self, + id: &crate::vm::instructions::operands::InstOperand, + address: &crate::vm::instructions::operands::InstOperand, + value: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait RandInstruction: IntegratedCircuit { @@ -887,6 +2260,16 @@ pub trait RandInstruction: IntegratedCircuit { fn execute_rand( &mut self, r: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + RandInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Rand, 0), + ) + } + /// rand r? + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait RoundInstruction: IntegratedCircuit { @@ -895,6 +2278,18 @@ pub trait RoundInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + RoundInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Round, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Round, 1), + ) + } + /// round r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SInstruction: IntegratedCircuit { @@ -904,6 +2299,20 @@ pub trait SInstruction: IntegratedCircuit { d: &crate::vm::instructions::operands::Operand, logic_type: &crate::vm::instructions::operands::Operand, r: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::S, 0), + &crate::vm::instructions::operands::InstOperand::new(logic_type, InstructionOp::S, 1), + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::S, 2), + ) + } + /// s d? logicType r? + fn execute_inner( + &mut self, + d: &crate::vm::instructions::operands::InstOperand, + logic_type: &crate::vm::instructions::operands::InstOperand, + r: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SapInstruction: IntegratedCircuit { @@ -914,6 +2323,22 @@ pub trait SapInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SapInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sap, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sap, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Sap, 2), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Sap, 3), + ) + } + /// sap r? a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SapzInstruction: IntegratedCircuit { @@ -923,6 +2348,20 @@ pub trait SapzInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SapzInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sapz, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sapz, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Sapz, 2), + ) + } + /// sapz r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SbInstruction: IntegratedCircuit { @@ -932,6 +2371,20 @@ pub trait SbInstruction: IntegratedCircuit { device_hash: &crate::vm::instructions::operands::Operand, logic_type: &crate::vm::instructions::operands::Operand, r: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SbInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(device_hash, InstructionOp::Sb, 0), + &crate::vm::instructions::operands::InstOperand::new(logic_type, InstructionOp::Sb, 1), + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sb, 2), + ) + } + /// sb deviceHash logicType r? + fn execute_inner( + &mut self, + device_hash: &crate::vm::instructions::operands::InstOperand, + logic_type: &crate::vm::instructions::operands::InstOperand, + r: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SbnInstruction: IntegratedCircuit { @@ -942,6 +2395,26 @@ pub trait SbnInstruction: IntegratedCircuit { name_hash: &crate::vm::instructions::operands::Operand, logic_type: &crate::vm::instructions::operands::Operand, r: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SbnInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new( + device_hash, + InstructionOp::Sbn, + 0, + ), + &crate::vm::instructions::operands::InstOperand::new(name_hash, InstructionOp::Sbn, 1), + &crate::vm::instructions::operands::InstOperand::new(logic_type, InstructionOp::Sbn, 2), + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sbn, 3), + ) + } + /// sbn deviceHash nameHash logicType r? + fn execute_inner( + &mut self, + device_hash: &crate::vm::instructions::operands::InstOperand, + name_hash: &crate::vm::instructions::operands::InstOperand, + logic_type: &crate::vm::instructions::operands::InstOperand, + r: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SbsInstruction: IntegratedCircuit { @@ -952,6 +2425,30 @@ pub trait SbsInstruction: IntegratedCircuit { slot_index: &crate::vm::instructions::operands::Operand, logic_slot_type: &crate::vm::instructions::operands::Operand, r: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SbsInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new( + device_hash, + InstructionOp::Sbs, + 0, + ), + &crate::vm::instructions::operands::InstOperand::new(slot_index, InstructionOp::Sbs, 1), + &crate::vm::instructions::operands::InstOperand::new( + logic_slot_type, + InstructionOp::Sbs, + 2, + ), + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sbs, 3), + ) + } + /// sbs deviceHash slotIndex logicSlotType r? + fn execute_inner( + &mut self, + device_hash: &crate::vm::instructions::operands::InstOperand, + slot_index: &crate::vm::instructions::operands::InstOperand, + logic_slot_type: &crate::vm::instructions::operands::InstOperand, + r: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SdInstruction: IntegratedCircuit { @@ -961,6 +2458,20 @@ pub trait SdInstruction: IntegratedCircuit { id: &crate::vm::instructions::operands::Operand, logic_type: &crate::vm::instructions::operands::Operand, r: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SdInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(id, InstructionOp::Sd, 0), + &crate::vm::instructions::operands::InstOperand::new(logic_type, InstructionOp::Sd, 1), + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sd, 2), + ) + } + /// sd id(r?|num) logicType r? + fn execute_inner( + &mut self, + id: &crate::vm::instructions::operands::InstOperand, + logic_type: &crate::vm::instructions::operands::InstOperand, + r: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SdnsInstruction: IntegratedCircuit { @@ -969,6 +2480,18 @@ pub trait SdnsInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, d: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SdnsInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sdns, 0), + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Sdns, 1), + ) + } + /// sdns r? d? + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + d: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SdseInstruction: IntegratedCircuit { @@ -977,6 +2500,18 @@ pub trait SdseInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, d: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SdseInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sdse, 0), + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Sdse, 1), + ) + } + /// sdse r? d? + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + d: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SelectInstruction: IntegratedCircuit { @@ -987,6 +2522,22 @@ pub trait SelectInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SelectInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Select, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Select, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Select, 2), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Select, 3), + ) + } + /// select r? a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SeqInstruction: IntegratedCircuit { @@ -996,6 +2547,20 @@ pub trait SeqInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SeqInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Seq, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Seq, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Seq, 2), + ) + } + /// seq r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SeqzInstruction: IntegratedCircuit { @@ -1004,6 +2569,18 @@ pub trait SeqzInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SeqzInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Seqz, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Seqz, 1), + ) + } + /// seqz r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SgeInstruction: IntegratedCircuit { @@ -1013,6 +2590,20 @@ pub trait SgeInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SgeInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sge, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sge, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Sge, 2), + ) + } + /// sge r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SgezInstruction: IntegratedCircuit { @@ -1021,6 +2612,18 @@ pub trait SgezInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SgezInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sgez, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sgez, 1), + ) + } + /// sgez r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SgtInstruction: IntegratedCircuit { @@ -1030,6 +2633,20 @@ pub trait SgtInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SgtInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sgt, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sgt, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Sgt, 2), + ) + } + /// sgt r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SgtzInstruction: IntegratedCircuit { @@ -1038,6 +2655,18 @@ pub trait SgtzInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SgtzInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sgtz, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sgtz, 1), + ) + } + /// sgtz r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SinInstruction: IntegratedCircuit { @@ -1046,6 +2675,18 @@ pub trait SinInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SinInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sin, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sin, 1), + ) + } + /// sin r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SlaInstruction: IntegratedCircuit { @@ -1055,6 +2696,20 @@ pub trait SlaInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SlaInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sla, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sla, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Sla, 2), + ) + } + /// sla r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SleInstruction: IntegratedCircuit { @@ -1064,6 +2719,20 @@ pub trait SleInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SleInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sle, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sle, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Sle, 2), + ) + } + /// sle r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SleepInstruction: IntegratedCircuit { @@ -1071,6 +2740,16 @@ pub trait SleepInstruction: IntegratedCircuit { fn execute_sleep( &mut self, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SleepInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sleep, 0), + ) + } + /// sleep a(r?|num) + fn execute_inner( + &mut self, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SlezInstruction: IntegratedCircuit { @@ -1079,6 +2758,18 @@ pub trait SlezInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SlezInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Slez, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Slez, 1), + ) + } + /// slez r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SllInstruction: IntegratedCircuit { @@ -1088,6 +2779,20 @@ pub trait SllInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SllInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sll, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sll, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Sll, 2), + ) + } + /// sll r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SltInstruction: IntegratedCircuit { @@ -1097,6 +2802,20 @@ pub trait SltInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SltInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Slt, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Slt, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Slt, 2), + ) + } + /// slt r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SltzInstruction: IntegratedCircuit { @@ -1105,6 +2824,18 @@ pub trait SltzInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SltzInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sltz, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sltz, 1), + ) + } + /// sltz r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SnaInstruction: IntegratedCircuit { @@ -1115,6 +2846,22 @@ pub trait SnaInstruction: IntegratedCircuit { a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, c: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SnaInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sna, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sna, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Sna, 2), + &crate::vm::instructions::operands::InstOperand::new(c, InstructionOp::Sna, 3), + ) + } + /// sna r? a(r?|num) b(r?|num) c(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, + c: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SnanInstruction: IntegratedCircuit { @@ -1123,6 +2870,18 @@ pub trait SnanInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SnanInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Snan, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Snan, 1), + ) + } + /// snan r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SnanzInstruction: IntegratedCircuit { @@ -1131,6 +2890,18 @@ pub trait SnanzInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SnanzInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Snanz, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Snanz, 1), + ) + } + /// snanz r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SnazInstruction: IntegratedCircuit { @@ -1140,6 +2911,20 @@ pub trait SnazInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SnazInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Snaz, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Snaz, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Snaz, 2), + ) + } + /// snaz r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SneInstruction: IntegratedCircuit { @@ -1149,6 +2934,20 @@ pub trait SneInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SneInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sne, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sne, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Sne, 2), + ) + } + /// sne r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SnezInstruction: IntegratedCircuit { @@ -1157,6 +2956,18 @@ pub trait SnezInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SnezInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Snez, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Snez, 1), + ) + } + /// snez r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SqrtInstruction: IntegratedCircuit { @@ -1165,6 +2976,18 @@ pub trait SqrtInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SqrtInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sqrt, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sqrt, 1), + ) + } + /// sqrt r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SraInstruction: IntegratedCircuit { @@ -1174,6 +2997,20 @@ pub trait SraInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SraInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sra, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sra, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Sra, 2), + ) + } + /// sra r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SrlInstruction: IntegratedCircuit { @@ -1183,6 +3020,20 @@ pub trait SrlInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SrlInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Srl, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Srl, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Srl, 2), + ) + } + /// srl r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SsInstruction: IntegratedCircuit { @@ -1193,6 +3044,26 @@ pub trait SsInstruction: IntegratedCircuit { slot_index: &crate::vm::instructions::operands::Operand, logic_slot_type: &crate::vm::instructions::operands::Operand, r: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SsInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(d, InstructionOp::Ss, 0), + &crate::vm::instructions::operands::InstOperand::new(slot_index, InstructionOp::Ss, 1), + &crate::vm::instructions::operands::InstOperand::new( + logic_slot_type, + InstructionOp::Ss, + 2, + ), + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Ss, 3), + ) + } + /// ss d? slotIndex logicSlotType r? + fn execute_inner( + &mut self, + d: &crate::vm::instructions::operands::InstOperand, + slot_index: &crate::vm::instructions::operands::InstOperand, + logic_slot_type: &crate::vm::instructions::operands::InstOperand, + r: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait SubInstruction: IntegratedCircuit { @@ -1202,6 +3073,20 @@ pub trait SubInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + SubInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Sub, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Sub, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Sub, 2), + ) + } + /// sub r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait TanInstruction: IntegratedCircuit { @@ -1210,6 +3095,18 @@ pub trait TanInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + TanInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Tan, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Tan, 1), + ) + } + /// tan r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait TruncInstruction: IntegratedCircuit { @@ -1218,6 +3115,18 @@ pub trait TruncInstruction: IntegratedCircuit { &mut self, r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + TruncInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Trunc, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Trunc, 1), + ) + } + /// trunc r? a(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait XorInstruction: IntegratedCircuit { @@ -1227,11 +3136,29 @@ pub trait XorInstruction: IntegratedCircuit { r: &crate::vm::instructions::operands::Operand, a: &crate::vm::instructions::operands::Operand, b: &crate::vm::instructions::operands::Operand, + ) -> Result<(), crate::errors::ICError> { + XorInstruction::execute_inner( + self, + &crate::vm::instructions::operands::InstOperand::new(r, InstructionOp::Xor, 0), + &crate::vm::instructions::operands::InstOperand::new(a, InstructionOp::Xor, 1), + &crate::vm::instructions::operands::InstOperand::new(b, InstructionOp::Xor, 2), + ) + } + /// xor r? a(r?|num) b(r?|num) + fn execute_inner( + &mut self, + r: &crate::vm::instructions::operands::InstOperand, + a: &crate::vm::instructions::operands::InstOperand, + b: &crate::vm::instructions::operands::InstOperand, ) -> Result<(), crate::errors::ICError>; } pub trait YieldInstruction: IntegratedCircuit { /// yield - fn execute_yield(&mut self) -> Result<(), crate::errors::ICError>; + fn execute_yield(&mut self) -> Result<(), crate::errors::ICError> { + YieldInstruction::execute_inner(self) + } + /// yield + fn execute_inner(&mut self) -> Result<(), crate::errors::ICError>; } pub trait ICInstructable: AbsInstruction diff --git a/ic10emu/src/vm/object/errors.rs b/ic10emu/src/vm/object/errors.rs index 3360eb6..478869c 100644 --- a/ic10emu/src/vm/object/errors.rs +++ b/ic10emu/src/vm/object/errors.rs @@ -23,6 +23,8 @@ pub enum MemoryError { StackUnderflow(i32, usize), #[error("stack overflow: {0} > range [0..{1})")] StackOverflow(i32, usize), - #[error("memory unit not present")] - NotPresent, + #[error("memory not readable")] + NotReadable, + #[error("memory not writeable")] + NotWriteable, } diff --git a/ic10emu/src/vm/object/stationpedia/structs/integrated_circuit.rs b/ic10emu/src/vm/object/stationpedia/structs/integrated_circuit.rs index 7a22d7a..2ca717d 100644 --- a/ic10emu/src/vm/object/stationpedia/structs/integrated_circuit.rs +++ b/ic10emu/src/vm/object/stationpedia/structs/integrated_circuit.rs @@ -1,7 +1,7 @@ use crate::{ errors::{ICError, LineError}, grammar, - interpreter::ICState, + interpreter::{ICState, instructions::IC10Marker}, vm::{ enums::{ basic_enums::{Class as SlotClass, GasType, SortingClass}, @@ -29,7 +29,6 @@ use std::{ collections::{BTreeMap, HashSet}, rc::Rc, }; -use ICError::*; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Program { @@ -283,7 +282,7 @@ impl Logicable for ItemIntegratedCircuit10 { fn can_slot_logic_read(&self, slt: LogicSlotType, index: f64) -> bool { false } - fn get_slot_logic(&self, slt: LogicSlotType, index: f64, _vm: &VM) -> Result { + fn get_slot_logic(&self, slt: LogicSlotType, index: f64) -> Result { return Err(LogicError::SlotIndexOutOfRange(index, self.slots_count())); } fn valid_logic_types(&self) -> Vec { @@ -348,10 +347,11 @@ impl SourceCode for ItemIntegratedCircuit10 { } impl IntegratedCircuit for ItemIntegratedCircuit10 { - fn get_circuit_holder(&self, vm: &Rc) -> Option { + fn get_circuit_holder(&self) -> Option { self.get_parent_slot() .map(|parent_slot| { - vm.get_object(parent_slot.parent) + self.get_vm() + .get_object(parent_slot.parent) .map(|obj| obj.borrow().as_circuit_holder()) .flatten() }) @@ -466,9 +466,15 @@ impl IntegratedCircuit for ItemIntegratedCircuit10 { fn get_aliases(&self) -> &BTreeMap { &self.aliases } + fn get_aliases_mut(&mut self) -> &mut BTreeMap { + &mut self.aliases + } fn get_defines(&self) -> &BTreeMap { &self.defines } + fn get_defines_mut(&mut self) -> &mut BTreeMap { + &mut self.defines + } fn get_labels(&self) -> &BTreeMap { &self.program.labels } @@ -480,1560 +486,4 @@ impl IntegratedCircuit for ItemIntegratedCircuit10 { } } -impl SleepInstruction for ItemIntegratedCircuit10 { - /// sleep a(r?|num) - fn execute_sleep(&mut self, vm: &VM, a: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Sleep, 1)?; - let now = - time::OffsetDateTime::now_local().unwrap_or_else(|_| time::OffsetDateTime::now_utc()); - self.state = ICState::Sleep(now, a); - Ok(()) - } -} - -impl YieldInstruction for ItemIntegratedCircuit10 { - /// yield - fn execute_yield(&mut self, vm: &VM) -> Result<(), ICError> { - self.state = ICState::Yield; - Ok(()) - } -} - -impl DefineInstruction for ItemIntegratedCircuit10 { - /// define str num - fn execute_define(&mut self, vm: &VM, string: &Operand, num: &Operand) -> Result<(), ICError> { - let &Operand::Identifier(ident) = &string else { - return Err(IncorrectOperandType { - inst: InstructionOp::Define, - index: 1, - desired: "Name".to_owned(), - }); - }; - let &Operand::Number(num) = &num else { - return Err(IncorrectOperandType { - inst: InstructionOp::Define, - index: 2, - desired: "Number".to_owned(), - }); - }; - if self.defines.contains_key(&ident.name) { - Err(DuplicateDefine(ident.name.clone())) - } else { - self.defines.insert(ident.name.clone(), num.value()); - Ok(()) - } - } -} - -impl AliasInstruction for ItemIntegratedCircuit10 { - /// alias str r?|d? - fn execute_alias(&mut self, vm: &VM, string: &Operand, r: &Operand) -> Result<(), ICError> { - let &Operand::Identifier(ident) = &string else { - return Err(IncorrectOperandType { - inst: InstructionOp::Alias, - index: 1, - desired: "Name".to_owned(), - }); - }; - let alias = match &r { - Operand::RegisterSpec(RegisterSpec { - indirection, - target, - }) => Operand::RegisterSpec(RegisterSpec { - indirection: *indirection, - target: *target, - }), - Operand::DeviceSpec(DeviceSpec { device, connection }) => { - Operand::DeviceSpec(DeviceSpec { - device: *device, - connection: *connection, - }) - } - _ => { - return Err(IncorrectOperandType { - inst: InstructionOp::Alias, - index: 2, - desired: "Device Or Register".to_owned(), - }) - } - }; - self.aliases.insert(ident.name.clone(), alias); - Ok(()) - } -} - -impl MoveInstruction for ItemIntegratedCircuit10 { - /// move r? a(r?|num) - fn execute_move(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError> { - let RegisterSpec { - indirection, - target, - } = r.as_register(self, InstructionOp::Move, 1)?; - - let val = a.as_value(self, InstructionOp::Move, 2)?; - self.set_register(indirection, target, val)?; - Ok(()) - } -} - -impl BeqInstruction for ItemIntegratedCircuit10 { - /// beq a(r?|num) b(r?|num) c(r?|num) - fn execute_beq( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Beq, 1)?; - let b = b.as_value(self, InstructionOp::Beq, 2)?; - let c = c.as_value(self, InstructionOp::Beq, 3)?; - if a == b { - self.set_next_instruction(c); - } - Ok(()) - } -} -impl BeqalInstruction for ItemIntegratedCircuit10 { - /// beqal a(r?|num) b(r?|num) c(r?|num) - fn execute_beqal( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Beqal, 1)?; - let b = b.as_value(self, InstructionOp::Beqal, 2)?; - let c = c.as_value(self, InstructionOp::Beqal, 3)?; - if a == b { - self.set_next_instruction(c); - self.al(); - } - Ok(()) - } -} - -impl BreqInstruction for ItemIntegratedCircuit10 { - /// breq a(r?|num) b(r?|num) c(r?|num) - fn execute_breq( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Breq, 1)?; - let b = b.as_value(self, InstructionOp::Breq, 2)?; - let c = c.as_value(self, InstructionOp::Breq, 3)?; - if a == b { - self.set_next_instruction_relative(c); - } - Ok(()) - } -} - -impl BeqzInstruction for ItemIntegratedCircuit10 { - /// beqz a(r?|num) b(r?|num) - fn execute_beqz(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Beqz, 1)?; - let b = b.as_value(self, InstructionOp::Beqz, 2)?; - if a == 0.0 { - self.set_next_instruction(b) - } - Ok(()) - } -} - -impl BeqzalInstruction for ItemIntegratedCircuit10 { - /// beqzal a(r?|num) b(r?|num) - fn execute_beqzal(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Beqzal, 1)?; - let b = b.as_value(self, InstructionOp::Beqzal, 2)?; - if a == 0.0 { - self.set_next_instruction(b); - self.al(); - } - Ok(()) - } -} - -impl BreqzInstruction for ItemIntegratedCircuit10 { - /// breqz a(r?|num) b(r?|num) - fn execute_breqz(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Breqz, 1)?; - let b = b.as_value(self, InstructionOp::Breqz, 2)?; - if a == 0.0 { - self.set_next_instruction_relative(b); - } - Ok(()) - } -} - -impl BneInstruction for ItemIntegratedCircuit10 { - /// bne a(r?|num) b(r?|num) c(r?|num) - fn execute_bne( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bne, 1)?; - let b = b.as_value(self, InstructionOp::Bne, 2)?; - let c = c.as_value(self, InstructionOp::Bne, 3)?; - if a != b { - self.set_next_instruction(c); - } - Ok(()) - } -} - -impl BnealInstruction for ItemIntegratedCircuit10 { - /// bneal a(r?|num) b(r?|num) c(r?|num) - fn execute_bneal( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bneal, 1)?; - let b = b.as_value(self, InstructionOp::Bneal, 2)?; - let c = c.as_value(self, InstructionOp::Bneal, 3)?; - if a != b { - self.set_next_instruction(c); - self.al(); - } - Ok(()) - } -} - -impl BrneInstruction for ItemIntegratedCircuit10 { - /// brne a(r?|num) b(r?|num) c(r?|num) - fn execute_brne( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brne, 1)?; - let b = b.as_value(self, InstructionOp::Brne, 2)?; - let c = c.as_value(self, InstructionOp::Brne, 3)?; - if a != b { - self.set_next_instruction_relative(c); - } - Ok(()) - } -} - -impl BnezInstruction for ItemIntegratedCircuit10 { - /// bnez a(r?|num) b(r?|num) - fn execute_bnez(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bnez, 1)?; - let b = b.as_value(self, InstructionOp::Bnez, 2)?; - if a != 0.0 { - self.set_next_instruction(b) - } - Ok(()) - } -} - -impl BnezalInstruction for ItemIntegratedCircuit10 { - /// bnezal a(r?|num) b(r?|num) - fn execute_bnezal(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bnezal, 1)?; - let b = b.as_value(self, InstructionOp::Bnezal, 2)?; - if a != 0.0 { - self.set_next_instruction(b); - self.al(); - } - Ok(()) - } -} - -impl BrnezInstruction for ItemIntegratedCircuit10 { - /// brnez a(r?|num) b(r?|num) - fn execute_brnez(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brnez, 1)?; - let b = b.as_value(self, InstructionOp::Brnez, 2)?; - if a != 0.0 { - self.set_next_instruction_relative(b) - } - Ok(()) - } -} - -impl BltInstruction for ItemIntegratedCircuit10 { - /// blt a(r?|num) b(r?|num) c(r?|num) - fn execute_blt( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Blt, 1)?; - let b = b.as_value(self, InstructionOp::Blt, 2)?; - let c = c.as_value(self, InstructionOp::Blt, 3)?; - if a < b { - self.set_next_instruction(c); - } - Ok(()) - } -} - -impl BltalInstruction for ItemIntegratedCircuit10 { - /// bltal a(r?|num) b(r?|num) c(r?|num) - fn execute_bltal( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bltal, 1)?; - let b = b.as_value(self, InstructionOp::Bltal, 2)?; - let c = c.as_value(self, InstructionOp::Bltal, 3)?; - if a < b { - self.set_next_instruction(c); - self.al(); - } - Ok(()) - } -} - -impl BrltInstruction for ItemIntegratedCircuit10 { - /// brlt a(r?|num) b(r?|num) c(r?|num) - fn execute_brlt( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brlt, 1)?; - let b = b.as_value(self, InstructionOp::Brlt, 2)?; - let c = c.as_value(self, InstructionOp::Brlt, 3)?; - if a < b { - self.set_next_instruction_relative(c); - } - Ok(()) - } -} - -impl BltzInstruction for ItemIntegratedCircuit10 { - /// bltz a(r?|num) b(r?|num) - fn execute_bltz(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bltz, 1)?; - let b = b.as_value(self, InstructionOp::Bltz, 2)?; - if a < 0.0 { - self.set_next_instruction(b); - } - Ok(()) - } -} - -impl BltzalInstruction for ItemIntegratedCircuit10 { - /// bltzal a(r?|num) b(r?|num) - fn execute_bltzal(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bltzal, 1)?; - let b = b.as_value(self, InstructionOp::Bltzal, 2)?; - if a < 0.0 { - self.set_next_instruction(b); - self.al(); - } - Ok(()) - } -} - -impl BrltzInstruction for ItemIntegratedCircuit10 { - /// brltz a(r?|num) b(r?|num) - fn execute_brltz(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brltz, 1)?; - let b = b.as_value(self, InstructionOp::Brltz, 2)?; - if a < 0.0 { - self.set_next_instruction_relative(b); - } - Ok(()) - } -} - -impl BleInstruction for ItemIntegratedCircuit10 { - /// ble a(r?|num) b(r?|num) c(r?|num) - fn execute_ble( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Ble, 1)?; - let b = b.as_value(self, InstructionOp::Ble, 2)?; - let c = c.as_value(self, InstructionOp::Ble, 3)?; - if a <= b { - self.set_next_instruction(c); - } - Ok(()) - } -} -impl BlealInstruction for ItemIntegratedCircuit10 { - /// bleal a(r?|num) b(r?|num) c(r?|num) - fn execute_bleal( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bleal, 1)?; - let b = b.as_value(self, InstructionOp::Bleal, 2)?; - let c = c.as_value(self, InstructionOp::Bleal, 3)?; - if a <= b { - self.set_next_instruction(c); - self.al(); - } - Ok(()) - } -} - -impl BrleInstruction for ItemIntegratedCircuit10 { - /// brle a(r?|num) b(r?|num) c(r?|num) - fn execute_brle( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brle, 1)?; - let b = b.as_value(self, InstructionOp::Brle, 2)?; - let c = c.as_value(self, InstructionOp::Brle, 3)?; - if a <= b { - self.set_next_instruction_relative(c); - } - Ok(()) - } -} - -impl BlezInstruction for ItemIntegratedCircuit10 { - /// blez a(r?|num) b(r?|num) - fn execute_blez(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Blez, 1)?; - let b = b.as_value(self, InstructionOp::Blez, 2)?; - if a <= 0.0 { - self.set_next_instruction(b); - } - Ok(()) - } -} - -impl BlezalInstruction for ItemIntegratedCircuit10 { - /// blezal a(r?|num) b(r?|num) - fn execute_blezal(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Blezal, 1)?; - let b = b.as_value(self, InstructionOp::Blezal, 2)?; - if a <= 0.0 { - self.set_next_instruction(b); - self.al(); - } - Ok(()) - } -} - -impl BrlezInstruction for ItemIntegratedCircuit10 { - /// brlez a(r?|num) b(r?|num) - fn execute_brlez(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brlez, 1)?; - let b = b.as_value(self, InstructionOp::Brlez, 2)?; - if a <= 0.0 { - self.set_next_instruction_relative(b); - } - Ok(()) - } -} - -impl BgtInstruction for ItemIntegratedCircuit10 { - /// bgt a(r?|num) b(r?|num) c(r?|num) - fn execute_bgt( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bgt, 1)?; - let b = b.as_value(self, InstructionOp::Bgt, 2)?; - let c = c.as_value(self, InstructionOp::Bgt, 3)?; - if a > b { - self.set_next_instruction(c); - } - Ok(()) - } -} -impl BgtalInstruction for ItemIntegratedCircuit10 { - /// bgtal a(r?|num) b(r?|num) c(r?|num) - fn execute_bgtal( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bgtal, 1)?; - let b = b.as_value(self, InstructionOp::Bgtal, 2)?; - let c = c.as_value(self, InstructionOp::Bgtal, 3)?; - if a > b { - self.set_next_instruction(c); - self.al(); - } - Ok(()) - } -} - -impl BrgtInstruction for ItemIntegratedCircuit10 { - /// brgt a(r?|num) b(r?|num) c(r?|num) - fn execute_brgt( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brgt, 1)?; - let b = b.as_value(self, InstructionOp::Brgt, 2)?; - let c = c.as_value(self, InstructionOp::Brgt, 3)?; - if a > b { - self.set_next_instruction_relative(c); - } - Ok(()) - } -} - -impl BgtzInstruction for ItemIntegratedCircuit10 { - /// bgtz a(r?|num) b(r?|num) - fn execute_bgtz(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bgtz, 1)?; - let b = b.as_value(self, InstructionOp::Bgtz, 2)?; - if a > 0.0 { - self.set_next_instruction(b); - } - Ok(()) - } -} - -impl BgtzalInstruction for ItemIntegratedCircuit10 { - /// bgtzal a(r?|num) b(r?|num) - fn execute_bgtzal(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bgtzal, 1)?; - let b = b.as_value(self, InstructionOp::Bgtzal, 2)?; - if a > 0.0 { - self.set_next_instruction(b); - self.al(); - } - Ok(()) - } -} - -impl BrgtzInstruction for ItemIntegratedCircuit10 { - /// brgtz a(r?|num) b(r?|num) - fn execute_brgtz(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brgtz, 1)?; - let b = b.as_value(self, InstructionOp::Brgtz, 2)?; - if a > 0.0 { - self.set_next_instruction_relative(b); - } - Ok(()) - } -} - -impl BgeInstruction for ItemIntegratedCircuit10 { - /// bge a(r?|num) b(r?|num) c(r?|num) - fn execute_bge( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bge, 1)?; - let b = b.as_value(self, InstructionOp::Bge, 2)?; - let c = c.as_value(self, InstructionOp::Bge, 3)?; - if a >= b { - self.set_next_instruction(c); - } - Ok(()) - } -} - -impl BgealInstruction for ItemIntegratedCircuit10 { - /// bgeal a(r?|num) b(r?|num) c(r?|num) - fn execute_bgeal( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bgeal, 1)?; - let b = b.as_value(self, InstructionOp::Bgeal, 2)?; - let c = c.as_value(self, InstructionOp::Bgeal, 3)?; - if a >= b { - self.set_next_instruction(c); - self.al(); - } - Ok(()) - } -} - -impl BrgeInstruction for ItemIntegratedCircuit10 { - /// brge a(r?|num) b(r?|num) c(r?|num) - fn execute_brge( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brge, 1)?; - let b = b.as_value(self, InstructionOp::Brge, 2)?; - let c = c.as_value(self, InstructionOp::Brge, 3)?; - if a >= b { - self.set_next_instruction_relative(c); - } - Ok(()) - } -} - -impl BgezInstruction for ItemIntegratedCircuit10 { - /// bgez a(r?|num) b(r?|num) - fn execute_bgez(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bgez, 1)?; - let b = b.as_value(self, InstructionOp::Bgez, 2)?; - if a >= 0.0 { - self.set_next_instruction(b); - } - Ok(()) - } -} - -impl BgezalInstruction for ItemIntegratedCircuit10 { - /// bgezal a(r?|num) b(r?|num) - fn execute_bgezal(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bgeal, 1)?; - let b = b.as_value(self, InstructionOp::Bgeal, 2)?; - if a >= 0.0 { - self.set_next_instruction(b); - self.al(); - } - Ok(()) - } -} - -impl BrgezInstruction for ItemIntegratedCircuit10 { - /// brgez a(r?|num) b(r?|num) - fn execute_brgez(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brgez, 1)?; - let b = b.as_value(self, InstructionOp::Brgez, 2)?; - if a >= 0.0 { - self.set_next_instruction_relative(b); - } - Ok(()) - } -} - -impl BapInstruction for ItemIntegratedCircuit10 { - /// bap a(r?|num) b(r?|num) c(r?|num) d(r?|num) - fn execute_bap( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - d: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bap, 1)?; - let b = b.as_value(self, InstructionOp::Bap, 2)?; - let c = c.as_value(self, InstructionOp::Bap, 3)?; - let d = d.as_value(self, InstructionOp::Bap, 4)?; - if f64::abs(a - b) <= f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { - self.set_next_instruction(d); - } - Ok(()) - } -} - -impl BapalInstruction for ItemIntegratedCircuit10 { - /// bapal a(r?|num) b(r?|num) c(r?|num) d(r?|num) - fn execute_bapal( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - d: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bapal, 1)?; - let b = b.as_value(self, InstructionOp::Bapal, 2)?; - let c = c.as_value(self, InstructionOp::Bapal, 3)?; - let d = d.as_value(self, InstructionOp::Bapal, 4)?; - if f64::abs(a - b) <= f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { - self.set_next_instruction(d); - self.al(); - } - Ok(()) - } -} - -impl BrapInstruction for ItemIntegratedCircuit10 { - /// brap a(r?|num) b(r?|num) c(r?|num) d(r?|num) - fn execute_brap( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - d: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brap, 1)?; - let b = b.as_value(self, InstructionOp::Brap, 2)?; - let c = c.as_value(self, InstructionOp::Brap, 3)?; - let d = d.as_value(self, InstructionOp::Brap, 4)?; - if f64::abs(a - b) <= f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { - self.set_next_instruction_relative(d); - } - Ok(()) - } -} - -impl BapzInstruction for ItemIntegratedCircuit10 { - /// bapz a(r?|num) b(r?|num) c(r?|num) - fn execute_bapz( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bapz, 1)?; - let b = b.as_value(self, InstructionOp::Bapz, 2)?; - let c = c.as_value(self, InstructionOp::Bapz, 3)?; - if a.abs() <= f64::max(b * a.abs(), f64::EPSILON * 8.0) { - } else { - self.set_next_instruction(c); - } - Ok(()) - } -} - -impl BapzalInstruction for ItemIntegratedCircuit10 { - /// bapzal a(r?|num) b(r?|num) c(r?|num) - fn execute_bapzal( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bapzal, 1)?; - let b = b.as_value(self, InstructionOp::Bapzal, 2)?; - let c = c.as_value(self, InstructionOp::Bapzal, 3)?; - if a.abs() <= f64::max(b * a.abs(), f64::EPSILON * 8.0) { - } else { - self.set_next_instruction(c); - self.al(); - } - Ok(()) - } -} - -impl BrapzInstruction for ItemIntegratedCircuit10 { - /// brapz a(r?|num) b(r?|num) c(r?|num) - fn execute_brapz( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brapz, 1)?; - let b = b.as_value(self, InstructionOp::Brapz, 2)?; - let c = c.as_value(self, InstructionOp::Brapz, 3)?; - if a.abs() <= f64::max(b * a.abs(), f64::EPSILON * 8.0) { - } else { - self.set_next_instruction_relative(c); - } - Ok(()) - } -} - -impl BnaInstruction for ItemIntegratedCircuit10 { - /// bna a(r?|num) b(r?|num) c(r?|num) d(r?|num) - fn execute_bna( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - d: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bna, 1)?; - let b = b.as_value(self, InstructionOp::Bna, 2)?; - let c = c.as_value(self, InstructionOp::Bna, 3)?; - let d = d.as_value(self, InstructionOp::Bna, 4)?; - if f64::abs(a - b) > f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { - self.set_next_instruction(d); - } - Ok(()) - } -} -impl BnaalInstruction for ItemIntegratedCircuit10 { - /// bnaal a(r?|num) b(r?|num) c(r?|num) d(r?|num) - fn execute_bnaal( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - d: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bnaal, 1)?; - let b = b.as_value(self, InstructionOp::Bnaal, 2)?; - let c = c.as_value(self, InstructionOp::Bnaal, 3)?; - let d = d.as_value(self, InstructionOp::Bnaal, 4)?; - if f64::abs(a - b) > f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { - self.set_next_instruction(d); - self.al(); - } - Ok(()) - } -} -impl BrnaInstruction for ItemIntegratedCircuit10 { - /// brna a(r?|num) b(r?|num) c(r?|num) d(r?|num) - fn execute_brna( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - d: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brna, 1)?; - let b = b.as_value(self, InstructionOp::Brna, 2)?; - let c = c.as_value(self, InstructionOp::Brna, 3)?; - let d = d.as_value(self, InstructionOp::Brna, 4)?; - if f64::abs(a - b) > f64::max(c * f64::max(a.abs(), b.abs()), f64::EPSILON * 8.0) { - self.set_next_instruction_relative(d); - } - Ok(()) - } -} - -impl BnazInstruction for ItemIntegratedCircuit10 { - /// bnaz a(r?|num) b(r?|num) c(r?|num) - fn execute_bnaz( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bnaz, 1)?; - let b = b.as_value(self, InstructionOp::Bnaz, 2)?; - let c = c.as_value(self, InstructionOp::Bnaz, 3)?; - if a.abs() > f64::max(b * a.abs(), f64::EPSILON * 8.0) { - self.set_next_instruction(c); - } - Ok(()) - } -} -impl BnazalInstruction for ItemIntegratedCircuit10 { - /// bnazal a(r?|num) b(r?|num) c(r?|num) - fn execute_bnazal( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Bnazal, 1)?; - let b = b.as_value(self, InstructionOp::Bnazal, 2)?; - let c = c.as_value(self, InstructionOp::Bnazal, 3)?; - if a.abs() > f64::max(b * a.abs(), f64::EPSILON * 8.0) { - self.set_next_instruction(c); - self.al(); - } - Ok(()) - } -} -impl BrnazInstruction for ItemIntegratedCircuit10 { - /// brnaz a(r?|num) b(r?|num) c(r?|num) - fn execute_brnaz( - &mut self, - vm: &VM, - a: &Operand, - b: &Operand, - c: &Operand, - ) -> Result<(), ICError> { - let a = a.as_value(self, InstructionOp::Brnaz, 1)?; - let b = b.as_value(self, InstructionOp::Brnaz, 2)?; - let c = c.as_value(self, InstructionOp::Brnaz, 3)?; - if a.abs() > f64::max(b * a.abs(), f64::EPSILON * 8.0) { - self.set_next_instruction_relative(c); - } - Ok(()) - } -} -impl BdseInstruction for ItemIntegratedCircuit10 { - /// bdse d? a(r?|num) - fn execute_bdse(&mut self, vm: &VM, d: &Operand, a: &Operand) -> Result<(), ICError> { - let (device_id, _connection) = d.as_device(self, InstructionOp::Bdse, 1)?; - let a = a.as_value(self, InstructionOp::Bdse, 2)?; - if let Some(device_id) = device_id { - // FIXME: collect device and get logicable - self.set_next_instruction(a); - } - Ok(()) - } -} - -// impl BdsealInstruction for ItemIntegratedCircuit10 { -// /// bdseal d? a(r?|num) -// fn execute_bdseal(&mut self, vm: &VM, d: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl BrdseInstruction for ItemIntegratedCircuit10 { -// /// brdse d? a(r?|num) -// fn execute_brdse(&mut self, vm: &VM, d: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// -// impl AbsInstruction for ItemIntegratedCircuit10 { -// /// abs r? a(r?|num) -// fn execute_abs(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// -// impl AcosInstruction for ItemIntegratedCircuit10 { -// /// acos r? a(r?|num) -// fn execute_acos(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl AddInstruction for ItemIntegratedCircuit10 { -// /// add r? a(r?|num) b(r?|num) -// fn execute_add( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl AndInstruction for ItemIntegratedCircuit10 { -// /// and r? a(r?|num) b(r?|num) -// fn execute_and( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl AsinInstruction for ItemIntegratedCircuit10 { -// /// asin r? a(r?|num) -// fn execute_asin(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl AtanInstruction for ItemIntegratedCircuit10 { -// /// atan r? a(r?|num) -// fn execute_atan(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl Atan2Instruction for ItemIntegratedCircuit10 { -// /// atan2 r? a(r?|num) b(r?|num) -// fn execute_atan2( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl BdnsInstruction for ItemIntegratedCircuit10 { -// /// bdns d? a(r?|num) -// fn execute_bdns(&mut self, vm: &VM, d: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl BdnsalInstruction for ItemIntegratedCircuit10 { -// /// bdnsal d? a(r?|num) -// fn execute_bdnsal(&mut self, vm: &VM, d: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl BnanInstruction for ItemIntegratedCircuit10 { -// /// bnan a(r?|num) b(r?|num) -// fn execute_bnan(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError>; -// } -// impl BrdnsInstruction for ItemIntegratedCircuit10 { -// /// brdns d? a(r?|num) -// fn execute_brdns(&mut self, vm: &VM, d: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl BrnanInstruction for ItemIntegratedCircuit10 { -// /// brnan a(r?|num) b(r?|num) -// fn execute_brnan(&mut self, vm: &VM, a: &Operand, b: &Operand) -> Result<(), ICError>; -// } -// impl CeilInstruction for ItemIntegratedCircuit10 { -// /// ceil r? a(r?|num) -// fn execute_ceil(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl ClrInstruction for ItemIntegratedCircuit10 { -// /// clr d? -// fn execute_clr(&mut self, vm: &VM, d: &Operand) -> Result<(), ICError>; -// } -// impl ClrdInstruction for ItemIntegratedCircuit10 { -// /// clrd id(r?|num) -// fn execute_clrd(&mut self, vm: &VM, id: &Operand) -> Result<(), ICError>; -// } -// impl CosInstruction for ItemIntegratedCircuit10 { -// /// cos r? a(r?|num) -// fn execute_cos(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl DivInstruction for ItemIntegratedCircuit10 { -// /// div r? a(r?|num) b(r?|num) -// fn execute_div( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl ExpInstruction for ItemIntegratedCircuit10 { -// /// exp r? a(r?|num) -// fn execute_exp(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl FloorInstruction for ItemIntegratedCircuit10 { -// /// floor r? a(r?|num) -// fn execute_floor(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl GetInstruction for ItemIntegratedCircuit10 { -// /// get r? d? address(r?|num) -// fn execute_get( -// &mut self, -// vm: &VM, -// r: &Operand, -// d: &Operand, -// address: &Operand, -// ) -> Result<(), ICError>; -// } -// impl GetdInstruction for ItemIntegratedCircuit10 { -// /// getd r? id(r?|num) address(r?|num) -// fn execute_getd( -// &mut self, -// vm: &VM, -// r: &Operand, -// id: &Operand, -// address: &Operand, -// ) -> Result<(), ICError>; -// } -// impl HcfInstruction for ItemIntegratedCircuit10 { -// /// hcf -// fn execute_hcf(&mut self, vm: &VM) -> Result<(), ICError>; -// } -// impl JInstruction for ItemIntegratedCircuit10 { -// /// j int -// fn execute_j(&mut self, vm: &VM, int: &Operand) -> Result<(), ICError>; -// } -// impl JalInstruction for ItemIntegratedCircuit10 { -// /// jal int -// fn execute_jal(&mut self, vm: &VM, int: &Operand) -> Result<(), ICError>; -// } -// impl JrInstruction for ItemIntegratedCircuit10 { -// /// jr int -// fn execute_jr(&mut self, vm: &VM, int: &Operand) -> Result<(), ICError>; -// } -// impl LInstruction for ItemIntegratedCircuit10 { -// /// l r? d? logicType -// fn execute_l( -// &mut self, -// vm: &VM, -// r: &Operand, -// d: &Operand, -// logic_type: &Operand, -// ) -> Result<(), ICError>; -// } -// impl LabelInstruction for ItemIntegratedCircuit10 { -// /// label d? str -// fn execute_label(&mut self, vm: &VM, d: &Operand, str: &Operand) -> Result<(), ICError>; -// } -// impl LbInstruction for ItemIntegratedCircuit10 { -// /// lb r? deviceHash logicType batchMode -// fn execute_lb( -// &mut self, -// vm: &VM, -// r: &Operand, -// device_hash: &Operand, -// logic_type: &Operand, -// batch_mode: &Operand, -// ) -> Result<(), ICError>; -// } -// impl LbnInstruction for ItemIntegratedCircuit10 { -// /// lbn r? deviceHash nameHash logicType batchMode -// fn execute_lbn( -// &mut self, -// vm: &VM, -// r: &Operand, -// device_hash: &Operand, -// name_hash: &Operand, -// logic_type: &Operand, -// batch_mode: &Operand, -// ) -> Result<(), ICError>; -// } -// impl LbnsInstruction for ItemIntegratedCircuit10 { -// /// lbns r? deviceHash nameHash slotIndex logicSlotType batchMode -// fn execute_lbns( -// &mut self, -// vm: &VM, -// r: &Operand, -// device_hash: &Operand, -// name_hash: &Operand, -// slot_index: &Operand, -// logic_slot_type: &Operand, -// batch_mode: &Operand, -// ) -> Result<(), ICError>; -// } -// impl LbsInstruction for ItemIntegratedCircuit10 { -// /// lbs r? deviceHash slotIndex logicSlotType batchMode -// fn execute_lbs( -// &mut self, -// vm: &VM, -// r: &Operand, -// device_hash: &Operand, -// slot_index: &Operand, -// logic_slot_type: &Operand, -// batch_mode: &Operand, -// ) -> Result<(), ICError>; -// } -// impl LdInstruction for ItemIntegratedCircuit10 { -// /// ld r? id(r?|num) logicType -// fn execute_ld( -// &mut self, -// vm: &VM, -// r: &Operand, -// id: &Operand, -// logic_type: &Operand, -// ) -> Result<(), ICError>; -// } -// impl LogInstruction for ItemIntegratedCircuit10 { -// /// log r? a(r?|num) -// fn execute_log(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl LrInstruction for ItemIntegratedCircuit10 { -// /// lr r? d? reagentMode int -// fn execute_lr( -// &mut self, -// vm: &VM, -// r: &Operand, -// d: &Operand, -// reagent_mode: &Operand, -// int: &Operand, -// ) -> Result<(), ICError>; -// } -// impl LsInstruction for ItemIntegratedCircuit10 { -// /// ls r? d? slotIndex logicSlotType -// fn execute_ls( -// &mut self, -// vm: &VM, -// r: &Operand, -// d: &Operand, -// slot_index: &Operand, -// logic_slot_type: &Operand, -// ) -> Result<(), ICError>; -// } -// impl MaxInstruction for ItemIntegratedCircuit10 { -// /// max r? a(r?|num) b(r?|num) -// fn execute_max( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl MinInstruction for ItemIntegratedCircuit10 { -// /// min r? a(r?|num) b(r?|num) -// fn execute_min( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl ModInstruction for ItemIntegratedCircuit10 { -// /// mod r? a(r?|num) b(r?|num) -// fn execute_mod( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl MulInstruction for ItemIntegratedCircuit10 { -// /// mul r? a(r?|num) b(r?|num) -// fn execute_mul( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl NorInstruction for ItemIntegratedCircuit10 { -// /// nor r? a(r?|num) b(r?|num) -// fn execute_nor( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl NotInstruction for ItemIntegratedCircuit10 { -// /// not r? a(r?|num) -// fn execute_not(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl OrInstruction for ItemIntegratedCircuit10 { -// /// or r? a(r?|num) b(r?|num) -// fn execute_or(&mut self, vm: &VM, r: &Operand, a: &Operand, b: &Operand) -// -> Result<(), ICError>; -// } -// impl PeekInstruction for ItemIntegratedCircuit10 { -// /// peek r? -// fn execute_peek(&mut self, vm: &VM, r: &Operand) -> Result<(), ICError>; -// } -// impl PokeInstruction for ItemIntegratedCircuit10 { -// /// poke address(r?|num) value(r?|num) -// fn execute_poke(&mut self, vm: &VM, address: &Operand, value: &Operand) -> Result<(), ICError>; -// } -// impl PopInstruction for ItemIntegratedCircuit10 { -// /// pop r? -// fn execute_pop(&mut self, vm: &VM, r: &Operand) -> Result<(), ICError>; -// } -// impl PushInstruction for ItemIntegratedCircuit10 { -// /// push a(r?|num) -// fn execute_push(&mut self, vm: &VM, a: &Operand) -> Result<(), ICError>; -// } -// impl PutInstruction for ItemIntegratedCircuit10 { -// /// put d? address(r?|num) value(r?|num) -// fn execute_put( -// &mut self, -// vm: &VM, -// d: &Operand, -// address: &Operand, -// value: &Operand, -// ) -> Result<(), ICError>; -// } -// impl PutdInstruction for ItemIntegratedCircuit10 { -// /// putd id(r?|num) address(r?|num) value(r?|num) -// fn execute_putd( -// &mut self, -// vm: &VM, -// id: &Operand, -// address: &Operand, -// value: &Operand, -// ) -> Result<(), ICError>; -// } -// impl RandInstruction for ItemIntegratedCircuit10 { -// /// rand r? -// fn execute_rand(&mut self, vm: &VM, r: &Operand) -> Result<(), ICError>; -// } -// impl RoundInstruction for ItemIntegratedCircuit10 { -// /// round r? a(r?|num) -// fn execute_round(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl SInstruction for ItemIntegratedCircuit10 { -// /// s d? logicType r? -// fn execute_s( -// &mut self, -// vm: &VM, -// d: &Operand, -// logic_type: &Operand, -// r: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SapInstruction for ItemIntegratedCircuit10 { -// /// sap r? a(r?|num) b(r?|num) c(r?|num) -// fn execute_sap( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// c: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SapzInstruction for ItemIntegratedCircuit10 { -// /// sapz r? a(r?|num) b(r?|num) -// fn execute_sapz( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SbInstruction for ItemIntegratedCircuit10 { -// /// sb deviceHash logicType r? -// fn execute_sb( -// &mut self, -// vm: &VM, -// device_hash: &Operand, -// logic_type: &Operand, -// r: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SbnInstruction for ItemIntegratedCircuit10 { -// /// sbn deviceHash nameHash logicType r? -// fn execute_sbn( -// &mut self, -// vm: &VM, -// device_hash: &Operand, -// name_hash: &Operand, -// logic_type: &Operand, -// r: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SbsInstruction for ItemIntegratedCircuit10 { -// /// sbs deviceHash slotIndex logicSlotType r? -// fn execute_sbs( -// &mut self, -// vm: &VM, -// device_hash: &Operand, -// slot_index: &Operand, -// logic_slot_type: &Operand, -// r: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SdInstruction for ItemIntegratedCircuit10 { -// /// sd id(r?|num) logicType r? -// fn execute_sd( -// &mut self, -// vm: &VM, -// id: &Operand, -// logic_type: &Operand, -// r: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SdnsInstruction for ItemIntegratedCircuit10 { -// /// sdns r? d? -// fn execute_sdns(&mut self, vm: &VM, r: &Operand, d: &Operand) -> Result<(), ICError>; -// } -// impl SdseInstruction for ItemIntegratedCircuit10 { -// /// sdse r? d? -// fn execute_sdse(&mut self, vm: &VM, r: &Operand, d: &Operand) -> Result<(), ICError>; -// } -// impl SelectInstruction for ItemIntegratedCircuit10 { -// /// select r? a(r?|num) b(r?|num) c(r?|num) -// fn execute_select( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// c: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SeqInstruction for ItemIntegratedCircuit10 { -// /// seq r? a(r?|num) b(r?|num) -// fn execute_seq( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SeqzInstruction for ItemIntegratedCircuit10 { -// /// seqz r? a(r?|num) -// fn execute_seqz(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl SgeInstruction for ItemIntegratedCircuit10 { -// /// sge r? a(r?|num) b(r?|num) -// fn execute_sge( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SgezInstruction for ItemIntegratedCircuit10 { -// /// sgez r? a(r?|num) -// fn execute_sgez(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl SgtInstruction for ItemIntegratedCircuit10 { -// /// sgt r? a(r?|num) b(r?|num) -// fn execute_sgt( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SgtzInstruction for ItemIntegratedCircuit10 { -// /// sgtz r? a(r?|num) -// fn execute_sgtz(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl SinInstruction for ItemIntegratedCircuit10 { -// /// sin r? a(r?|num) -// fn execute_sin(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl SlaInstruction for ItemIntegratedCircuit10 { -// /// sla r? a(r?|num) b(r?|num) -// fn execute_sla( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SleInstruction for ItemIntegratedCircuit10 { -// /// sle r? a(r?|num) b(r?|num) -// fn execute_sle( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SlezInstruction for ItemIntegratedCircuit10 { -// /// slez r? a(r?|num) -// fn execute_slez(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl SllInstruction for ItemIntegratedCircuit10 { -// /// sll r? a(r?|num) b(r?|num) -// fn execute_sll( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SltInstruction for ItemIntegratedCircuit10 { -// /// slt r? a(r?|num) b(r?|num) -// fn execute_slt( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SltzInstruction for ItemIntegratedCircuit10 { -// /// sltz r? a(r?|num) -// fn execute_sltz(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl SnaInstruction for ItemIntegratedCircuit10 { -// /// sna r? a(r?|num) b(r?|num) c(r?|num) -// fn execute_sna( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// c: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SnanInstruction for ItemIntegratedCircuit10 { -// /// snan r? a(r?|num) -// fn execute_snan(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl SnanzInstruction for ItemIntegratedCircuit10 { -// /// snanz r? a(r?|num) -// fn execute_snanz(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl SnazInstruction for ItemIntegratedCircuit10 { -// /// snaz r? a(r?|num) b(r?|num) -// fn execute_snaz( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SneInstruction for ItemIntegratedCircuit10 { -// /// sne r? a(r?|num) b(r?|num) -// fn execute_sne( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SnezInstruction for ItemIntegratedCircuit10 { -// /// snez r? a(r?|num) -// fn execute_snez(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl SqrtInstruction for ItemIntegratedCircuit10 { -// /// sqrt r? a(r?|num) -// fn execute_sqrt(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl SraInstruction for ItemIntegratedCircuit10 { -// /// sra r? a(r?|num) b(r?|num) -// fn execute_sra( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SrlInstruction for ItemIntegratedCircuit10 { -// /// srl r? a(r?|num) b(r?|num) -// fn execute_srl( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SsInstruction for ItemIntegratedCircuit10 { -// /// ss d? slotIndex logicSlotType r? -// fn execute_ss( -// &mut self, -// vm: &VM, -// d: &Operand, -// slot_index: &Operand, -// logic_slot_type: &Operand, -// r: &Operand, -// ) -> Result<(), ICError>; -// } -// impl SubInstruction for ItemIntegratedCircuit10 { -// /// sub r? a(r?|num) b(r?|num) -// fn execute_sub( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } -// impl TanInstruction for ItemIntegratedCircuit10 { -// /// tan r? a(r?|num) -// fn execute_tan(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl TruncInstruction for ItemIntegratedCircuit10 { -// /// trunc r? a(r?|num) -// fn execute_trunc(&mut self, vm: &VM, r: &Operand, a: &Operand) -> Result<(), ICError>; -// } -// impl XorInstruction for ItemIntegratedCircuit10 { -// /// xor r? a(r?|num) b(r?|num) -// fn execute_xor( -// &mut self, -// vm: &VM, -// r: &Operand, -// a: &Operand, -// b: &Operand, -// ) -> Result<(), ICError>; -// } +impl IC10Marker for ItemIntegratedCircuit10 {} diff --git a/ic10emu/src/vm/object/traits.rs b/ic10emu/src/vm/object/traits.rs index f0da856..39d71c4 100644 --- a/ic10emu/src/vm/object/traits.rs +++ b/ic10emu/src/vm/object/traits.rs @@ -15,10 +15,9 @@ use crate::{ macros::tag_object_traits, ObjectID, Slot, }, - VM, }, }; -use std::{collections::BTreeMap, fmt::Debug, rc::Rc}; +use std::{collections::BTreeMap, fmt::Debug}; #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] pub struct ParentSlotInfo { @@ -63,7 +62,7 @@ tag_object_traits! { fn set_logic(&mut self, lt: LogicType, value: f64, force: bool) -> Result<(), LogicError>; fn get_logic(&self, lt: LogicType) -> Result; fn can_slot_logic_read(&self, slt: LogicSlotType, index: f64) -> bool; - fn get_slot_logic(&self, slt: LogicSlotType, index: f64, vm: &VM) -> Result; + fn get_slot_logic(&self, slt: LogicSlotType, index: f64) -> Result; fn valid_logic_types(&self) -> Vec; fn known_modes(&self) -> Option>; } @@ -78,10 +77,28 @@ tag_object_traits! { pub trait CircuitHolder: Logicable + Storage { fn clear_error(&mut self); fn set_error(&mut self, state: i32); - fn get_logicable_from_index(&self, device: usize, vm: &VM) -> Option; - fn get_logicable_from_index_mut(&self, device: usize, vm: &VM) -> Option; - fn get_logicable_from_id(&self, device: ObjectID, vm: &VM) -> Option; - fn get_logicable_from_id_mut(&self, device: ObjectID, vm: &VM) -> Option; + /// i32::MAX is db + fn get_logicable_from_index( + &self, + device: i32, + connection: Option, + ) -> Option; + /// i32::MAX is db + fn get_logicable_from_index_mut( + &self, + device: i32, + connection: Option, + ) -> Option; + fn get_logicable_from_id( + &self, + device: ObjectID, + connection: Option, + ) -> Option; + fn get_logicable_from_id_mut( + &self, + device: ObjectID, + connection: Option, + ) -> Option; fn get_source_code(&self) -> String; fn set_source_code(&self, code: String); fn get_batch(&self) -> Vec; @@ -102,7 +119,7 @@ tag_object_traits! { } pub trait IntegratedCircuit: Logicable + MemoryWritable + SourceCode + Item { - fn get_circuit_holder(&self, vm: &Rc) -> Option; + fn get_circuit_holder(&self) -> Option; fn get_instruction_pointer(&self) -> f64; fn set_next_instruction(&mut self, next_instruction: f64); fn set_next_instruction_relative(&mut self, offset: f64) { @@ -122,7 +139,9 @@ tag_object_traits! { fn get_stack(&self, addr: f64) -> Result; fn put_stack(&self, addr: f64, val: f64) -> Result; fn get_aliases(&self) -> &BTreeMap; + fn get_aliases_mut(&mut self) -> &mut BTreeMap; fn get_defines(&self) -> &BTreeMap; + fn get_defines_mut(&mut self) -> &mut BTreeMap; fn get_labels(&self) -> &BTreeMap; fn get_state(&self) -> ICState; fn set_state(&mut self, state: ICState); @@ -131,7 +150,7 @@ tag_object_traits! { pub trait Programmable: ICInstructable { fn get_source_code(&self) -> String; fn set_source_code(&self, code: String); - fn step(&mut self, vm: &VM, advance_ip_on_err: bool) -> Result<(), crate::errors::ICError>; + fn step(&mut self, advance_ip_on_err: bool) -> Result<(), crate::errors::ICError>; } pub trait Instructable: MemoryWritable { @@ -149,8 +168,7 @@ tag_object_traits! { slt: LogicSlotType, index: f64, value: f64, - vm: &VM, - force: bool + force: bool, ) -> Result<(), LogicError>; fn connection_list(&self) -> &[Connection]; fn connection_list_mut(&mut self) -> &mut [Connection]; @@ -166,13 +184,9 @@ tag_object_traits! { fn has_reagents(&self) -> bool; } - pub trait WirelessTransmit: Logicable { + pub trait WirelessTransmit: Logicable {} - } - - pub trait WirelessReceive: Logicable { - - } + pub trait WirelessReceive: Logicable {} pub trait Network: Logicable { fn contains(&self, id: &ObjectID) -> bool; @@ -192,7 +206,6 @@ tag_object_traits! { fn get_channel_data(&self) -> &[f64; 8]; } - } impl Debug for dyn Object { diff --git a/xtask/src/generate/instructions.rs b/xtask/src/generate/instructions.rs index 163312a..419d896 100644 --- a/xtask/src/generate/instructions.rs +++ b/xtask/src/generate/instructions.rs @@ -133,7 +133,8 @@ fn write_instruction_trait( instruction: (&str, &stationpedia::Command), ) -> color_eyre::Result<()> { let (name, info) = instruction; - let trait_name = format!("{}Instruction", name.to_case(Case::Pascal)); + let op_name = name.to_case(Case::Pascal); + let trait_name = format!("{op_name}Instruction"); let operands = operand_names(&info.example) .iter() .map(|name| { @@ -148,12 +149,45 @@ fn write_instruction_trait( }) .collect::>() .join(", "); + let operands_inner = operand_names(&info.example) + .iter() + .map(|name| { + let mut n: &str = name; + if n == "str" { + n = "string"; + } + format!( + "{}: &crate::vm::instructions::operands::InstOperand", + n.to_case(Case::Snake) + ) + }) + .collect::>() + .join(", "); + let operand_call = operand_names(&info.example) + .iter() + .enumerate() + .map(|(index, name)| { + let mut n: &str = name; + if n == "str" { + n = "string"; + } + format!( + "&crate::vm::instructions::operands::InstOperand::new({}, InstructionOp::{op_name}, {index})", + n.to_case(Case::Snake) + ) + }) + .collect::>() + .join(", "); let example = utils::strip_color(&info.example); write!( writer, "pub trait {trait_name}: IntegratedCircuit {{\n \ /// {example} \n \ - fn execute_{name}(&mut self, {operands}) -> Result<(), crate::errors::ICError>;\n\ + fn execute_{name}(&mut self, {operands}) -> Result<(), crate::errors::ICError> {{\n \ + {trait_name}::execute_inner(self, {operand_call})\n \ + }}\n \ + /// {example} \n \ + fn execute_inner(&mut self, {operands_inner}) -> Result<(), crate::errors::ICError>;\n\ }}" )?; Ok(()) @@ -176,6 +210,7 @@ fn write_instruction_trait_use(writer: &mut T) -> color_eyre: writer, "\ use crate::vm::object::traits::IntegratedCircuit;\n\ + use crate::vm::instructions::enums::InstructionOp;\n\ " )?; Ok(())