Files
not-python2/src/obj/none.rs

40 lines
931 B
Rust
Raw Normal View History

use crate::obj::prelude::*;
use std::{any::Any, sync::LazyLock};
pub static NONE_INST: LazyLock<ObjPtr> = LazyLock::new(|| ObjPtr::new(None::new()));
static NONE_STR: LazyLock<ObjPtr> = LazyLock::new(|| ObjPtr::new(Str::new("None")));
static NONE_ATTRS: LazyLock<AttrsPtr> = LazyLock::new(|| {
attrs_ptr! {
//
"__str__" => builtin_fun_ptr!("__str__", |_vm, args, _state| {
if args.len() != 1 {
todo!("Throw exception: arity error");
}
BuiltinFunResult::Return(Some(ObjPtr::clone(&NONE_STR)))
}),
}
});
#[derive(Debug)]
pub struct None {
attrs: AttrsPtr,
}
impl None {
fn new() -> Self {
let attrs = AttrsPtr::clone(&NONE_ATTRS);
Self { attrs }
}
}
impl Obj for None {
fn attrs(&self) -> AttrsPtr {
AttrsPtr::clone(&self.attrs)
}
fn as_any(&self) -> &(dyn Any + 'static) {
self
}
}