Files
not-python2/src/obj/none.rs
Alek Ratzloff bfe7ca33bd Initial commit
* Parser, compiler, objects, and VM base implementations
* Stuff will print out, functions called, etc
* There are probably plenty of bugs but this is a good starting point to
  start committing changes into git

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2023-04-01 22:34:35 -07:00

40 lines
931 B
Rust

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
}
}