Add base branch logic

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2023-04-07 00:00:04 -07:00
parent 4d005494a3
commit 7bac4306c3
17 changed files with 20302 additions and 5491 deletions

View File

@@ -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 {