Update error message, add Int.__eq__
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -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::<IntObj>();
|
||||
let rhs = rhs_ptr.as_any().downcast_ref::<IntObj>();
|
||||
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::<FloatObj>()) {
|
||||
// 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()?;
|
||||
|
||||
@@ -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}")]
|
||||
|
||||
Reference in New Issue
Block a user