From c85423ae79d6d8e3266b6398de78278ad97a2d78 Mon Sep 17 00:00:00 2001 From: imxyy_soope_ Date: Sun, 26 Apr 2026 16:57:24 +0800 Subject: [PATCH] implement unary operations --- fix-vm/src/dispatch_tailcall.rs | 4 ++-- fix-vm/src/instructions/arithmetic.rs | 15 +++++++++++---- fix-vm/src/lib.rs | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fix-vm/src/dispatch_tailcall.rs b/fix-vm/src/dispatch_tailcall.rs index 741f59c..708fc1d 100644 --- a/fix-vm/src/dispatch_tailcall.rs +++ b/fix-vm/src/dispatch_tailcall.rs @@ -173,8 +173,8 @@ tail_fn!(op_geq, (ctx, reader, mc)); tail_fn!(op_concat, (reader, mc)); tail_fn!(op_update, (reader, mc)); -tail_fn!(op_neg, ()); -tail_fn!(op_not, ()); +tail_fn!(op_neg, (reader, mc)); +tail_fn!(op_not, (reader, mc)); tail_fn!(op_jump_if_false, (reader, mc)); tail_fn!(op_jump_if_true, (reader, mc)); diff --git a/fix-vm/src/instructions/arithmetic.rs b/fix-vm/src/instructions/arithmetic.rs index d44bb43..2cb080a 100644 --- a/fix-vm/src/instructions/arithmetic.rs +++ b/fix-vm/src/instructions/arithmetic.rs @@ -196,13 +196,20 @@ impl<'gc> crate::Vm<'gc> { } #[inline(always)] - pub(crate) fn op_neg(&mut self) -> Step { - todo!("implement unary operation"); + pub(crate) fn op_neg(&mut self, reader: &mut BytecodeReader<'_>, mc: &Mutation<'gc>) -> Step { + let rhs = self.try_force::(reader, mc)?; + match rhs { + NixNum::Int(int) => self.push(Value::make_int(-int, mc)), + NixNum::Float(float) => self.push(Value::new_float(-float)), + } + Step::Continue(()) } #[inline(always)] - pub(crate) fn op_not(&mut self) -> Step { - todo!("implement unary operation"); + pub(crate) fn op_not(&mut self, reader: &mut BytecodeReader<'_>, mc: &Mutation<'gc>) -> Step { + let rhs = self.try_force::(reader, mc)?; + self.push(Value::new_inline(!rhs)); + Step::Continue(()) } pub(crate) fn values_equal( diff --git a/fix-vm/src/lib.rs b/fix-vm/src/lib.rs index d50db93..ac2fd4f 100644 --- a/fix-vm/src/lib.rs +++ b/fix-vm/src/lib.rs @@ -641,8 +641,8 @@ impl<'gc> Vm<'gc> { OpConcat => self.op_concat(&mut reader, mc), OpUpdate => self.op_update(&mut reader, mc), - OpNeg => self.op_neg(), - OpNot => self.op_not(), + OpNeg => self.op_neg(&mut reader, mc), + OpNot => self.op_not(&mut reader, mc), JumpIfFalse => self.op_jump_if_false(&mut reader, mc), JumpIfTrue => self.op_jump_if_true(&mut reader, mc),