Add List::len method

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2024-09-30 17:46:03 -07:00
parent e5756d6f1a
commit a370d3a56f
2 changed files with 12 additions and 2 deletions

View File

@@ -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 {