diff --git a/src/obj/boolean.rs b/src/obj/boolean.rs index 99ae3a9..79fc36c 100644 --- a/src/obj/boolean.rs +++ b/src/obj/boolean.rs @@ -51,7 +51,7 @@ pub static BOOL_TRUE: Lazy = Lazy::new(|| attrs: Default::default(), }, vtable: |obj_ref: ObjRef| vtable! { - BOOL_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), BOOL_BOOL_FUN.clone()), + BOOL_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), BOOL_BOOL_METH.clone()), } } ); @@ -67,7 +67,7 @@ pub static BOOL_FALSE: Lazy = Lazy::new(|| attrs: Default::default(), }, vtable: |obj_ref: ObjRef| vtable! { - BOOL_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), BOOL_BOOL_FUN.clone()), + BOOL_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), BOOL_BOOL_METH.clone()), } } ); @@ -77,7 +77,7 @@ pub static BOOL_FALSE: Lazy = Lazy::new(|| //////////////////////////////////////////////////////////////////////////////// /// Bool.__bool__(self) impl -static BOOL_BOOL_FUN: Lazy = Lazy::new(|| { +static BOOL_BOOL_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(1, |_callee, vm, args| { { read_obj_downcast!(let value: Option<&Bool> = &args[0]); diff --git a/src/obj/builtin.rs b/src/obj/builtin.rs index 7e8e12c..5a4edc2 100644 --- a/src/obj/builtin.rs +++ b/src/obj/builtin.rs @@ -1,3 +1,5 @@ +//! Builtin objects and functions. + use crate::{ obj::{prelude::*, reserved::*}, vm::{error::*, signal::*}, @@ -6,6 +8,10 @@ use maplit::btreemap; use once_cell::sync::Lazy; use std::collections::BTreeMap; +//////////////////////////////////////////////////////////////////////////////// +// Builtin free functions +//////////////////////////////////////////////////////////////////////////////// + pub static PRINTLN_BUILTIN_FUN: Lazy = Lazy::new(|| { NativeFun::new_obj(1, |_, vm, args| { // TODO : use __get_attr__ when it gets added @@ -64,6 +70,10 @@ pub static PRINT_BUILTIN_FUN: Lazy = Lazy::new(|| { }) }); +//////////////////////////////////////////////////////////////////////////////// +// Builtin objects +//////////////////////////////////////////////////////////////////////////////// + pub static BUILTIN_OBJS: Lazy> = Lazy::new(|| { btreemap! { PRINTLN_BUILTIN_NAME.sym => PRINTLN_BUILTIN_FUN.clone() as _, diff --git a/src/obj/int.rs b/src/obj/int.rs index de92d55..5a29d92 100644 --- a/src/obj/int.rs +++ b/src/obj/int.rs @@ -26,16 +26,16 @@ impl Int { attrs: Default::default(), }, vtable: |obj_ref: ObjRef| vtable! { - BOOL_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), INT_BOOL_FUN.clone()), - REPR_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), INT_STR_FUN.clone()), - STR_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), INT_STR_FUN.clone()), - INT_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), INT_INT_FUN.clone()), - PLUS_OP_NAME.sym => Method::new_obj(obj_ref.clone(), INT_ADD_FUN.clone()), - MINUS_OP_NAME.sym => Method::new_obj(obj_ref.clone(), INT_SUB_FUN.clone()), - TIMES_OP_NAME.sym => Method::new_obj(obj_ref.clone(), INT_MUL_FUN.clone()), - DIV_OP_NAME.sym => Method::new_obj(obj_ref.clone(), INT_DIV_FUN.clone()), - EQ_OP_NAME.sym => Method::new_obj(obj_ref.clone(), INT_EQ_FUN.clone()), - NE_OP_NAME.sym => Method::new_obj(obj_ref.clone(), INT_NE_FUN.clone()), + BOOL_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), INT_BOOL_METH.clone()), + REPR_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), INT_STR_METH.clone()), + STR_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), INT_STR_METH.clone()), + INT_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), INT_INT_METH.clone()), + PLUS_OP_NAME.sym => Method::new_obj(obj_ref.clone(), INT_ADD_METH.clone()), + MINUS_OP_NAME.sym => Method::new_obj(obj_ref.clone(), INT_SUB_METH.clone()), + TIMES_OP_NAME.sym => Method::new_obj(obj_ref.clone(), INT_MUL_METH.clone()), + DIV_OP_NAME.sym => Method::new_obj(obj_ref.clone(), INT_DIV_METH.clone()), + EQ_OP_NAME.sym => Method::new_obj(obj_ref.clone(), INT_EQ_METH.clone()), + NE_OP_NAME.sym => Method::new_obj(obj_ref.clone(), INT_NE_METH.clone()), } } } @@ -58,7 +58,7 @@ impl Debug for Int { //////////////////////////////////////////////////////////////////////////////// /// Int.__bool__(self) impl -static INT_BOOL_FUN: Lazy = Lazy::new(|| { +static INT_BOOL_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(1, |_callee, vm, args| { read_obj_downcast!(let int_obj: Option<&Int> = &args[0]); let int_obj = int_obj.ok_or_else(|| Error::ValueError { @@ -70,7 +70,7 @@ static INT_BOOL_FUN: Lazy = Lazy::new(|| { }); /// Int.__str__(self) impl -static INT_STR_FUN: Lazy = Lazy::new(|| { +static INT_STR_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(1, |_callee, vm, args| { read_obj_downcast!(let int_obj: Option<&Int> = &args[0]); let int_obj = int_obj.ok_or_else(|| Error::ValueError { @@ -82,7 +82,7 @@ static INT_STR_FUN: Lazy = Lazy::new(|| { }); /// Int.__int__(self) impl -static INT_INT_FUN: Lazy = Lazy::new(|| { +static INT_INT_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(1, |_callee, vm, args| { { read_obj_downcast!(let int_obj: Option<&Int> = &args[0]); @@ -98,7 +98,7 @@ static INT_INT_FUN: Lazy = Lazy::new(|| { }); /// Int.__add__(self, Int) impl -static INT_ADD_FUN: Lazy = Lazy::new(|| { +static INT_ADD_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(2, |_callee, vm, args| { read_obj_downcast!(let lhs: Option<&Int> = &args[0]); let lhs = lhs.ok_or_else(|| Error::ValueError { @@ -117,7 +117,7 @@ static INT_ADD_FUN: Lazy = Lazy::new(|| { }); /// Int.__sub__(self, Int) impl -static INT_SUB_FUN: Lazy = Lazy::new(|| { +static INT_SUB_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(2, |_callee, vm, args| { read_obj_downcast!(let lhs: Option<&Int> = &args[0]); let lhs = lhs.ok_or_else(|| Error::ValueError { @@ -136,7 +136,7 @@ static INT_SUB_FUN: Lazy = Lazy::new(|| { }); /// Int.__mul__(self, Int) impl -static INT_MUL_FUN: Lazy = Lazy::new(|| { +static INT_MUL_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(2, |_callee, vm, args| { read_obj_downcast!(let lhs: Option<&Int> = &args[0]); let lhs = lhs.ok_or_else(|| Error::ValueError { @@ -155,7 +155,7 @@ static INT_MUL_FUN: Lazy = Lazy::new(|| { }); /// Int.__div__(self, Int) impl -static INT_DIV_FUN: Lazy = Lazy::new(|| { +static INT_DIV_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(2, |_callee, vm, args| { read_obj_downcast!(let lhs: Option<&Int> = &args[0]); let lhs = lhs.ok_or_else(|| Error::ValueError { @@ -174,7 +174,7 @@ static INT_DIV_FUN: Lazy = Lazy::new(|| { }); /// Int.__eq__(self, Int) impl -static INT_EQ_FUN: Lazy = Lazy::new(|| { +static INT_EQ_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(2, |_callee, vm, args| { read_obj_downcast!(let lhs: Option<&Int> = &args[0]); let lhs = lhs.ok_or_else(|| Error::ValueError { @@ -193,7 +193,7 @@ static INT_EQ_FUN: Lazy = Lazy::new(|| { }); /// Int.__ne__(self, Int) impl -static INT_NE_FUN: Lazy = Lazy::new(|| { +static INT_NE_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(2, |_callee, vm, args| { read_obj_downcast!(let lhs: Option<&Int> = &args[0]); let lhs = lhs.ok_or_else(|| Error::ValueError { diff --git a/src/obj/mod.rs b/src/obj/mod.rs index 61bd8c8..fc12b18 100644 --- a/src/obj/mod.rs +++ b/src/obj/mod.rs @@ -66,8 +66,6 @@ pub trait Obj: Scan + GcDrop + Debug { obj_attr!(get_ty, TY_MEMBER_NAME); obj_attr!(get_call, CALL_MEMBER_NAME); obj_attr!(get_name, NAME_MEMBER_NAME); - //obj_attr!(get_get_attr, GET_ATTR_NAME); - //obj_attr!(get_set_attr, SET_ATTR_NAME); obj_attr!(get_self, SELF_MEMBER_NAME); obj_attr!(get_func, FUNC_MEMBER_NAME); obj_attr!(get_eq, EQ_OP_NAME); diff --git a/src/obj/str.rs b/src/obj/str.rs index bfd727b..d9ef33a 100644 --- a/src/obj/str.rs +++ b/src/obj/str.rs @@ -24,9 +24,9 @@ impl Str { attrs: Default::default(), }, vtable: |obj_ref: ObjRef| vtable! { - STR_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), STR_STR_FUN.clone()), - REPR_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), STR_REPR_FUN.clone()), - INT_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), STR_INT_FUN.clone()), + STR_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), STR_STR_METH.clone()), + REPR_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), STR_REPR_METH.clone()), + INT_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), STR_INT_METH.clone()), }, } } @@ -49,7 +49,7 @@ impl Debug for Str { //////////////////////////////////////////////////////////////////////////////// /// Str.__str__(self) impl -static STR_STR_FUN: Lazy = Lazy::new(|| { +static STR_STR_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(1, |_callee, vm, args| { { read_obj_downcast!(let str_obj: Option<&Str> = &args[0]); @@ -65,7 +65,7 @@ static STR_STR_FUN: Lazy = Lazy::new(|| { }); /// Str.__repr__(self) impl -static STR_REPR_FUN: Lazy = Lazy::new(|| { +static STR_REPR_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(1, |_callee, vm, args| { read_obj_downcast!(let str_obj: Option<&Str> = &args[0]); let str_obj = str_obj.ok_or_else(|| Error::ValueError { @@ -80,7 +80,7 @@ static STR_REPR_FUN: Lazy = Lazy::new(|| { }); /// Str.__int__(self) impl -static STR_INT_FUN: Lazy = Lazy::new(|| { +static STR_INT_METH: Lazy = Lazy::new(|| { NativeFun::new_obj(1, |_callee, vm, args| { read_obj_downcast!(let str_obj: Option<&Str> = &args[0]); let str_obj = str_obj.ok_or_else(|| Error::ValueError {