Add base branch logic
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -15,6 +15,12 @@ static INT_ATTRS: LazyLock<AttrsPtr> = LazyLock::new(|| {
|
||||
|
||||
BuiltinFunResult::Return(Some(ObjPtr::new(Str::new(obj.value().to_string()))))
|
||||
}),
|
||||
"__bool__" => builtin_fun_ptr!("__bool__", |_vm, args, _state| {
|
||||
let arg_any = &args[0].as_any();
|
||||
let obj = arg_any.downcast_ref::<Int>().expect("Int.__bool__ did not receive Int?");
|
||||
let result = ObjPtr::clone(&BOOL_INSTS[obj.is_truthy() as usize]);
|
||||
BuiltinFunResult::Return(Some(result))
|
||||
}),
|
||||
}
|
||||
});
|
||||
|
||||
@@ -44,6 +50,10 @@ impl Obj for Int {
|
||||
fn as_any(&self) -> &(dyn Any + 'static) {
|
||||
self
|
||||
}
|
||||
|
||||
fn is_truthy(&self) -> bool {
|
||||
self.value() != 0
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for Int {
|
||||
|
||||
Reference in New Issue
Block a user