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:
@@ -99,6 +99,11 @@ fn disassemble_chunk(chunk: &Chunk, constants: &Vec<ObjP>, globals: &Vec<String>
|
||||
arg = format!("{depth}");
|
||||
info = format!("slot {slot} (name unknown)");
|
||||
}
|
||||
Op::BuildList(len) => {
|
||||
op_str = "BUILD_LIST";
|
||||
arg = format!("{len}");
|
||||
info = String::new();
|
||||
}
|
||||
Op::Nop => {
|
||||
op_str = "NOP";
|
||||
arg = String::new();
|
||||
|
||||
Reference in New Issue
Block a user