Add lists
This introduces: * new syntax for list literals, put comma-separated values between braces for your new list * new syntax for indexing, do `foo[index]` to get the value in `foo` at `index`. Lists also allow negative indices too. Any type that wants to be indexed can include their own __index__ function as well. * new VM instruction, BuildList. List literals were a lot easier to implement using this rather than creating a new list, creating a temporary stack value, and then duplicating + pushing to that temporary value over and over. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -184,6 +184,21 @@ pub fn init_types() {
|
||||
Obj {
|
||||
//__call__ => BuiltinFunction::create("__call__",
|
||||
},
|
||||
List {
|
||||
// Conversion methods
|
||||
to_repr => BuiltinFunction::create("to_repr", List::to_repr, 1),
|
||||
|
||||
// Constructor
|
||||
__call__ => BuiltinFunction::create("__call__", List::do_call, 2),
|
||||
__init__ => BuiltinFunction::create("__init__", List::init, 2),
|
||||
|
||||
// Operators
|
||||
__index__ => BuiltinFunction::create("__index__", List::index, 2),
|
||||
|
||||
// Methods
|
||||
push => BuiltinFunction::create("push", List::push, 2),
|
||||
pop => BuiltinFunction::create("pop", List::pop, 1),
|
||||
},
|
||||
Str {
|
||||
// Conversion methods
|
||||
to_str => BuiltinFunction::create("to_str", Str::to_str, 1),
|
||||
@@ -198,7 +213,9 @@ pub fn init_types() {
|
||||
// Operators
|
||||
__add__ => BuiltinFunction::create("__add__", Str::add, 2),
|
||||
__mul__ => BuiltinFunction::create("__mul__", Str::mul, 2),
|
||||
// .lower, .upper, .slice, etc
|
||||
|
||||
// Methods
|
||||
// TODO Str methods - .lower, .upper, .slice, etc
|
||||
},
|
||||
Int {
|
||||
// Conversion methods
|
||||
|
||||
Reference in New Issue
Block a user