Rename member function builtins to be named _METH instead of _FUN
This is to differentiate between methods (which have a 'self' binding) and functions (which are free). Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -51,7 +51,7 @@ pub static BOOL_TRUE: Lazy<BoolRef> = Lazy::new(||
|
|||||||
attrs: Default::default(),
|
attrs: Default::default(),
|
||||||
},
|
},
|
||||||
vtable: |obj_ref: ObjRef| vtable! {
|
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<BoolRef> = Lazy::new(||
|
|||||||
attrs: Default::default(),
|
attrs: Default::default(),
|
||||||
},
|
},
|
||||||
vtable: |obj_ref: ObjRef| vtable! {
|
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<BoolRef> = Lazy::new(||
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/// Bool.__bool__(self) impl
|
/// Bool.__bool__(self) impl
|
||||||
static BOOL_BOOL_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
static BOOL_BOOL_METH: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(1, |_callee, vm, args| {
|
NativeFun::new_obj(1, |_callee, vm, args| {
|
||||||
{
|
{
|
||||||
read_obj_downcast!(let value: Option<&Bool> = &args[0]);
|
read_obj_downcast!(let value: Option<&Bool> = &args[0]);
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
//! Builtin objects and functions.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
obj::{prelude::*, reserved::*},
|
obj::{prelude::*, reserved::*},
|
||||||
vm::{error::*, signal::*},
|
vm::{error::*, signal::*},
|
||||||
@@ -6,6 +8,10 @@ use maplit::btreemap;
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Builtin free functions
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
pub static PRINTLN_BUILTIN_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
pub static PRINTLN_BUILTIN_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(1, |_, vm, args| {
|
NativeFun::new_obj(1, |_, vm, args| {
|
||||||
// TODO : use __get_attr__ when it gets added
|
// TODO : use __get_attr__ when it gets added
|
||||||
@@ -64,6 +70,10 @@ pub static PRINT_BUILTIN_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Builtin objects
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
pub static BUILTIN_OBJS: Lazy<BTreeMap<Sym, ObjRef>> = Lazy::new(|| {
|
pub static BUILTIN_OBJS: Lazy<BTreeMap<Sym, ObjRef>> = Lazy::new(|| {
|
||||||
btreemap! {
|
btreemap! {
|
||||||
PRINTLN_BUILTIN_NAME.sym => PRINTLN_BUILTIN_FUN.clone() as _,
|
PRINTLN_BUILTIN_NAME.sym => PRINTLN_BUILTIN_FUN.clone() as _,
|
||||||
|
|||||||
@@ -26,16 +26,16 @@ impl Int {
|
|||||||
attrs: Default::default(),
|
attrs: Default::default(),
|
||||||
},
|
},
|
||||||
vtable: |obj_ref: ObjRef| vtable! {
|
vtable: |obj_ref: ObjRef| vtable! {
|
||||||
BOOL_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), INT_BOOL_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_FUN.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_FUN.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_FUN.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_FUN.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_FUN.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_FUN.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_FUN.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_FUN.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_FUN.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
|
/// Int.__bool__(self) impl
|
||||||
static INT_BOOL_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
static INT_BOOL_METH: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(1, |_callee, vm, args| {
|
NativeFun::new_obj(1, |_callee, vm, args| {
|
||||||
read_obj_downcast!(let int_obj: Option<&Int> = &args[0]);
|
read_obj_downcast!(let int_obj: Option<&Int> = &args[0]);
|
||||||
let int_obj = int_obj.ok_or_else(|| Error::ValueError {
|
let int_obj = int_obj.ok_or_else(|| Error::ValueError {
|
||||||
@@ -70,7 +70,7 @@ static INT_BOOL_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/// Int.__str__(self) impl
|
/// Int.__str__(self) impl
|
||||||
static INT_STR_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
static INT_STR_METH: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(1, |_callee, vm, args| {
|
NativeFun::new_obj(1, |_callee, vm, args| {
|
||||||
read_obj_downcast!(let int_obj: Option<&Int> = &args[0]);
|
read_obj_downcast!(let int_obj: Option<&Int> = &args[0]);
|
||||||
let int_obj = int_obj.ok_or_else(|| Error::ValueError {
|
let int_obj = int_obj.ok_or_else(|| Error::ValueError {
|
||||||
@@ -82,7 +82,7 @@ static INT_STR_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/// Int.__int__(self) impl
|
/// Int.__int__(self) impl
|
||||||
static INT_INT_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
static INT_INT_METH: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(1, |_callee, vm, args| {
|
NativeFun::new_obj(1, |_callee, vm, args| {
|
||||||
{
|
{
|
||||||
read_obj_downcast!(let int_obj: Option<&Int> = &args[0]);
|
read_obj_downcast!(let int_obj: Option<&Int> = &args[0]);
|
||||||
@@ -98,7 +98,7 @@ static INT_INT_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/// Int.__add__(self, Int) impl
|
/// Int.__add__(self, Int) impl
|
||||||
static INT_ADD_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
static INT_ADD_METH: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(2, |_callee, vm, args| {
|
NativeFun::new_obj(2, |_callee, vm, args| {
|
||||||
read_obj_downcast!(let lhs: Option<&Int> = &args[0]);
|
read_obj_downcast!(let lhs: Option<&Int> = &args[0]);
|
||||||
let lhs = lhs.ok_or_else(|| Error::ValueError {
|
let lhs = lhs.ok_or_else(|| Error::ValueError {
|
||||||
@@ -117,7 +117,7 @@ static INT_ADD_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/// Int.__sub__(self, Int) impl
|
/// Int.__sub__(self, Int) impl
|
||||||
static INT_SUB_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
static INT_SUB_METH: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(2, |_callee, vm, args| {
|
NativeFun::new_obj(2, |_callee, vm, args| {
|
||||||
read_obj_downcast!(let lhs: Option<&Int> = &args[0]);
|
read_obj_downcast!(let lhs: Option<&Int> = &args[0]);
|
||||||
let lhs = lhs.ok_or_else(|| Error::ValueError {
|
let lhs = lhs.ok_or_else(|| Error::ValueError {
|
||||||
@@ -136,7 +136,7 @@ static INT_SUB_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/// Int.__mul__(self, Int) impl
|
/// Int.__mul__(self, Int) impl
|
||||||
static INT_MUL_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
static INT_MUL_METH: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(2, |_callee, vm, args| {
|
NativeFun::new_obj(2, |_callee, vm, args| {
|
||||||
read_obj_downcast!(let lhs: Option<&Int> = &args[0]);
|
read_obj_downcast!(let lhs: Option<&Int> = &args[0]);
|
||||||
let lhs = lhs.ok_or_else(|| Error::ValueError {
|
let lhs = lhs.ok_or_else(|| Error::ValueError {
|
||||||
@@ -155,7 +155,7 @@ static INT_MUL_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/// Int.__div__(self, Int) impl
|
/// Int.__div__(self, Int) impl
|
||||||
static INT_DIV_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
static INT_DIV_METH: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(2, |_callee, vm, args| {
|
NativeFun::new_obj(2, |_callee, vm, args| {
|
||||||
read_obj_downcast!(let lhs: Option<&Int> = &args[0]);
|
read_obj_downcast!(let lhs: Option<&Int> = &args[0]);
|
||||||
let lhs = lhs.ok_or_else(|| Error::ValueError {
|
let lhs = lhs.ok_or_else(|| Error::ValueError {
|
||||||
@@ -174,7 +174,7 @@ static INT_DIV_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/// Int.__eq__(self, Int) impl
|
/// Int.__eq__(self, Int) impl
|
||||||
static INT_EQ_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
static INT_EQ_METH: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(2, |_callee, vm, args| {
|
NativeFun::new_obj(2, |_callee, vm, args| {
|
||||||
read_obj_downcast!(let lhs: Option<&Int> = &args[0]);
|
read_obj_downcast!(let lhs: Option<&Int> = &args[0]);
|
||||||
let lhs = lhs.ok_or_else(|| Error::ValueError {
|
let lhs = lhs.ok_or_else(|| Error::ValueError {
|
||||||
@@ -193,7 +193,7 @@ static INT_EQ_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/// Int.__ne__(self, Int) impl
|
/// Int.__ne__(self, Int) impl
|
||||||
static INT_NE_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
static INT_NE_METH: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(2, |_callee, vm, args| {
|
NativeFun::new_obj(2, |_callee, vm, args| {
|
||||||
read_obj_downcast!(let lhs: Option<&Int> = &args[0]);
|
read_obj_downcast!(let lhs: Option<&Int> = &args[0]);
|
||||||
let lhs = lhs.ok_or_else(|| Error::ValueError {
|
let lhs = lhs.ok_or_else(|| Error::ValueError {
|
||||||
|
|||||||
@@ -66,8 +66,6 @@ pub trait Obj: Scan + GcDrop + Debug {
|
|||||||
obj_attr!(get_ty, TY_MEMBER_NAME);
|
obj_attr!(get_ty, TY_MEMBER_NAME);
|
||||||
obj_attr!(get_call, CALL_MEMBER_NAME);
|
obj_attr!(get_call, CALL_MEMBER_NAME);
|
||||||
obj_attr!(get_name, NAME_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_self, SELF_MEMBER_NAME);
|
||||||
obj_attr!(get_func, FUNC_MEMBER_NAME);
|
obj_attr!(get_func, FUNC_MEMBER_NAME);
|
||||||
obj_attr!(get_eq, EQ_OP_NAME);
|
obj_attr!(get_eq, EQ_OP_NAME);
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ impl Str {
|
|||||||
attrs: Default::default(),
|
attrs: Default::default(),
|
||||||
},
|
},
|
||||||
vtable: |obj_ref: ObjRef| vtable! {
|
vtable: |obj_ref: ObjRef| vtable! {
|
||||||
STR_MEMBER_NAME.sym => Method::new_obj(obj_ref.clone(), STR_STR_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_FUN.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_FUN.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
|
/// Str.__str__(self) impl
|
||||||
static STR_STR_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
static STR_STR_METH: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(1, |_callee, vm, args| {
|
NativeFun::new_obj(1, |_callee, vm, args| {
|
||||||
{
|
{
|
||||||
read_obj_downcast!(let str_obj: Option<&Str> = &args[0]);
|
read_obj_downcast!(let str_obj: Option<&Str> = &args[0]);
|
||||||
@@ -65,7 +65,7 @@ static STR_STR_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/// Str.__repr__(self) impl
|
/// Str.__repr__(self) impl
|
||||||
static STR_REPR_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
static STR_REPR_METH: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(1, |_callee, vm, args| {
|
NativeFun::new_obj(1, |_callee, vm, args| {
|
||||||
read_obj_downcast!(let str_obj: Option<&Str> = &args[0]);
|
read_obj_downcast!(let str_obj: Option<&Str> = &args[0]);
|
||||||
let str_obj = str_obj.ok_or_else(|| Error::ValueError {
|
let str_obj = str_obj.ok_or_else(|| Error::ValueError {
|
||||||
@@ -80,7 +80,7 @@ static STR_REPR_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/// Str.__int__(self) impl
|
/// Str.__int__(self) impl
|
||||||
static STR_INT_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
static STR_INT_METH: Lazy<NativeFunRef> = Lazy::new(|| {
|
||||||
NativeFun::new_obj(1, |_callee, vm, args| {
|
NativeFun::new_obj(1, |_callee, vm, args| {
|
||||||
read_obj_downcast!(let str_obj: Option<&Str> = &args[0]);
|
read_obj_downcast!(let str_obj: Option<&Str> = &args[0]);
|
||||||
let str_obj = str_obj.ok_or_else(|| Error::ValueError {
|
let str_obj = str_obj.ok_or_else(|| Error::ValueError {
|
||||||
|
|||||||
Reference in New Issue
Block a user