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>
This commit is contained in:
2023-04-01 22:34:35 -07:00
commit bfe7ca33bd
26 changed files with 13853 additions and 0 deletions

39
src/obj/none.rs Normal file
View File

@@ -0,0 +1,39 @@
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
}
}