implement unary operations

This commit is contained in:
2026-04-26 16:57:24 +08:00
parent bc16596dd3
commit c85423ae79
3 changed files with 15 additions and 8 deletions
+2 -2
View File
@@ -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));
+11 -4
View File
@@ -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::<NixNum>(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::<bool>(reader, mc)?;
self.push(Value::new_inline(!rhs));
Step::Continue(())
}
pub(crate) fn values_equal(
+2 -2
View File
@@ -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),