Implement BaseObjInst::eq and ::neq
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -84,59 +84,89 @@ pub(crate) fn print(vm: &mut Vm, state: FunctionState) -> FunctionResult {
|
||||
|
||||
impl BaseObjInst {
|
||||
pub(crate) fn add(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __add__ function (self: {:?}, rhs: {:?})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
todo!("Raise some kind of not implemented/not callable error for __add__ function (self: {}, rhs: {})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
}
|
||||
|
||||
pub(crate) fn sub(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __sub__ function (self: {:?}, rhs: {:?})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
todo!("Raise some kind of not implemented/not callable error for __sub__ function (self: {}, rhs: {})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
}
|
||||
|
||||
pub(crate) fn mul(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __mul__ function (self: {:?}, rhs: {:?})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
todo!("Raise some kind of not implemented/not callable error for __mul__ function (self: {}, rhs: {})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
}
|
||||
|
||||
pub(crate) fn div(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __div__ function (self: {:?}, rhs: {:?})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
todo!("Raise some kind of not implemented/not callable error for __div__ function (self: {}, rhs: {})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
}
|
||||
|
||||
pub(crate) fn and(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __and__ function (self: {:?}, rhs: {:?})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
todo!("Raise some kind of not implemented/not callable error for __and__ function (self: {}, rhs: {})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
}
|
||||
|
||||
pub(crate) fn or(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __or__ function (self: {:?}, rhs: {:?})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
todo!("Raise some kind of not implemented/not callable error for __or__ function (self: {}, rhs: {})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
}
|
||||
|
||||
pub(crate) fn ne(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __ne__ function (self: {:?}, rhs: {:?})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
pub(crate) fn ne(vm: &mut Vm, state: FunctionState) -> FunctionResult {
|
||||
match state {
|
||||
FunctionState::Begin => {
|
||||
// we actually want to be calling the lhs's eq function and then negate it
|
||||
let lhs = vm.frame_stack()[0].clone();
|
||||
let method_type = vm.builtins().get("Method").unwrap().clone();
|
||||
let eq_method = lhs
|
||||
.borrow_mut()
|
||||
.get_attr_lazy(lhs.clone(), method_type, "__eq__")
|
||||
.expect("no __eq__");
|
||||
let rhs = vm.frame_stack()[1].clone();
|
||||
vm.push(rhs);
|
||||
eq_method.borrow().call(vm, 1);
|
||||
FunctionResult::Yield(0)
|
||||
}
|
||||
FunctionState::Resume(0) => {
|
||||
let result = !vm.peek().borrow().is_truthy();
|
||||
vm.create_bool(result).into()
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn eq(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __eq__ function (self: {:?}, rhs: {:?})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
let lhs = vm.frame_stack()[0].borrow();
|
||||
let rhs = vm.frame_stack()[1].borrow();
|
||||
let equals = lhs.equals(&*rhs);
|
||||
vm.create_bool(equals).into()
|
||||
}
|
||||
|
||||
pub(crate) fn gt(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __gt__ function (self: {:?}, rhs: {:?})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
todo!("Raise some kind of not implemented/not callable error for __gt__ function (self: {}, rhs: {})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
}
|
||||
|
||||
pub(crate) fn ge(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __ge__ function (self: {:?}, rhs: {:?})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
todo!("Raise some kind of not implemented/not callable error for __ge__ function (self: {}, rhs: {})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
}
|
||||
|
||||
pub(crate) fn lt(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __lt__ function (self: {:?}, rhs: {:?})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
todo!("Raise some kind of not implemented/not callable error for __lt__ function (self: {}, rhs: {})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
}
|
||||
|
||||
pub(crate) fn le(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __le__ function (self: {:?}, rhs: {:?})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
todo!("Raise some kind of not implemented/not callable error for __le__ function (self: {}, rhs: {})", vm.frame_stack()[0].borrow(), vm.frame_stack()[1].borrow())
|
||||
}
|
||||
|
||||
pub(crate) fn pos(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __pos__ function (self: {:?})", vm.frame_stack()[0].borrow())
|
||||
todo!(
|
||||
"Raise some kind of not implemented/not callable error for __pos__ function (self: {})",
|
||||
vm.frame_stack()[0].borrow()
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn neg(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
todo!("Raise some kind of not implemented/not callable error for __neg__ function (self: {:?})", vm.frame_stack()[0].borrow())
|
||||
todo!(
|
||||
"Raise some kind of not implemented/not callable error for __neg__ function (self: {})",
|
||||
vm.frame_stack()[0].borrow()
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn not(vm: &mut Vm, state: FunctionState) -> FunctionResult {
|
||||
|
||||
Reference in New Issue
Block a user