array literals
Some checks failed
Build / build (push) Failing after 2m16s
Test / build (push) Failing after 1m46s

This commit is contained in:
Chuck Smith
2024-02-26 15:47:24 -05:00
parent e4bca02235
commit 8721665bc1
5 changed files with 105 additions and 0 deletions

View File

@@ -194,6 +194,16 @@ func (c *Compiler) Compile(node ast.Node) error {
str := &object.String{Value: node.Value}
c.emit(code.OpConstant, c.addConstant(str))
case *ast.ArrayLiteral:
for _, el := range node.Elements {
err := c.Compile(el)
if err != nil {
return err
}
}
c.emit(code.OpArray, len(node.Elements))
}
return nil