feat: implement list literal syntax and List class with count property

Add support for list literals in the compiler with bracket-delimited syntax and comma-separated elements. Introduce the ObjList runtime type with a contiguous elements array, garbage collection marking, and proper memory deallocation. Expose a `List` class in the core library with a `count` method returning the number of elements. Update the grammar table to register `[` as a prefix token for list compilation instead of an infix subscript operator, and reorder opcode enum entries to place CODE_LIST before the load/store group.
This commit is contained in:
Bob Nystrom
2013-11-24 21:38:31 +00:00
parent 2490e6a425
commit cc117912fa
7 changed files with 156 additions and 18 deletions
+1
View File
@@ -24,3 +24,4 @@ bar.method(1, 2, 3, 4) // expect: bar
// TODO(bob): Private fields.
// TODO(bob): Super (or inner) calls.
// TODO(bob): Grammar for what expressions can follow "is".
// TODO(bob): Prevent extending built-in types.
+7
View File
@@ -0,0 +1,7 @@
io.write([].count) // expect: 0
io.write([1].count) // expect: 1
io.write([1, 2, 3, 4].count) // expect: 4
// TODO(bob): Literal syntax, including newline handling.
// TODO(bob): Unterminated list literal.
// TODO(bob): Subscript operator.