diff --git a/src/obj/int.rs b/src/obj/int.rs index 600a052..029dc5f 100644 --- a/src/obj/int.rs +++ b/src/obj/int.rs @@ -13,6 +13,22 @@ pub struct IntObj { thread_local! { static VTABLE: VTable = VTableBuilder::default() + .with_builtin("__eq__", |machine, _| { + let rhs_ptr: ObjPtr = machine.stack_pop()?; + let lhs_ptr: ObjPtr = machine.stack_pop()?; + let lhs = lhs_ptr.as_any().downcast_ref::(); + let rhs = rhs_ptr.as_any().downcast_ref::(); + let result = if let (Some(lhs), Some(rhs)) = (lhs, rhs) { + lhs.value() == rhs.value() + } else if let (Some(lhs), Some(rhs)) = (lhs, rhs_ptr.as_any().downcast_ref::()) { + // implicit upcast for this comparison allowed + lhs.value() as Float == rhs.value() + } else { + false + }; + machine.stack_push(BoolObj::new(result))?; + Ok(BuiltinExit::Return) + }) .with_builtin("__splat__", |machine, _| { let rhs_ptr: ObjPtr = machine.stack_pop()?; let lhs_ptr: ObjPtr = machine.stack_pop()?; diff --git a/src/vm/error.rs b/src/vm/error.rs index 6e3ef8a..264c8ab 100644 --- a/src/vm/error.rs +++ b/src/vm/error.rs @@ -15,7 +15,7 @@ pub enum RuntimeError { #[error("cannot call value '{0}'")] CannotCall(String), - #[error("expected {0} value")] + #[error("expected {0}")] WrongValue(String), #[error("at {0}")]