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