@@ -185,6 +185,12 @@ impl List {
|
||||
FunctionResult::ReturnPush(item)
|
||||
}
|
||||
|
||||
pub(crate) fn len(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
let this = vm.frame_stack()[0].clone();
|
||||
let len = with_obj_downcast(this, |list: &List| list.list().len());
|
||||
Int::create(len as i64).into()
|
||||
}
|
||||
|
||||
pub(crate) fn push(vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||
let this = vm.frame_stack()[0].clone();
|
||||
let arg = vm.frame_stack()[1].clone();
|
||||
|
||||
@@ -158,7 +158,6 @@ pub fn init_types() {
|
||||
to_int => BuiltinFunction::create("to_int", BaseObj::not_implemented_un, 1),
|
||||
to_float => BuiltinFunction::create("to_float", BaseObj::not_implemented_un, 1),
|
||||
to_list => BuiltinFunction::create("to_list", BaseObj::not_implemented_un, 1),
|
||||
len => BuiltinFunction::create("len", BaseObj::not_implemented_un, 1),
|
||||
|
||||
// Constructor
|
||||
// TODO Ty::do_call, Ty::init - implement these methods
|
||||
@@ -181,6 +180,9 @@ pub fn init_types() {
|
||||
__pos__ => BuiltinFunction::create("__pos__", BaseObj::not_implemented_un, 1),
|
||||
__neg__ => BuiltinFunction::create("__neg__", BaseObj::not_implemented_un, 1),
|
||||
__not__ => BuiltinFunction::create("__not__", BaseObj::not, 1),
|
||||
|
||||
// Methods
|
||||
len => BuiltinFunction::create("len", BaseObj::not_implemented_un, 1),
|
||||
},
|
||||
Obj {
|
||||
//__call__ => BuiltinFunction::create("__call__",
|
||||
@@ -197,6 +199,8 @@ pub fn init_types() {
|
||||
__index__ => BuiltinFunction::create("__index__", List::index, 2),
|
||||
|
||||
// Methods
|
||||
len => BuiltinFunction::create("len", List::len, 1),
|
||||
|
||||
push => BuiltinFunction::create("push", List::push, 2),
|
||||
pop => BuiltinFunction::create("pop", List::pop, 1),
|
||||
},
|
||||
@@ -206,7 +210,6 @@ pub fn init_types() {
|
||||
to_int => BuiltinFunction::create("to_int", Str::to_int, 1),
|
||||
to_float => BuiltinFunction::create("to_float", Str::to_float, 1),
|
||||
to_list => BuiltinFunction::create("to_list", Str::to_list, 1),
|
||||
len => BuiltinFunction::create("len", Str::len, 1),
|
||||
|
||||
// Constructor
|
||||
__call__ => BuiltinFunction::create("__call__", Str::do_call, 2),
|
||||
@@ -219,6 +222,7 @@ pub fn init_types() {
|
||||
__index__ => BuiltinFunction::create("__index__", Str::index, 2),
|
||||
|
||||
// Methods
|
||||
len => BuiltinFunction::create("len", Str::len, 1),
|
||||
// TODO Str methods - .lower, .upper, .slice, etc
|
||||
},
|
||||
Int {
|
||||
|
||||
Reference in New Issue
Block a user