improve errors, add warnings, add some compile-time optimizations, fix variables, make sure conditionals and loops get booleans, affirm types, keep variables to a single type

This commit is contained in:
Neemek 2025-03-20 12:13:30 +01:00
parent e34b423967
commit b1b8e61f57
Signed by: neemek
GPG key ID: 28360A8951CD0E9B
14 changed files with 435 additions and 118 deletions

View file

@ -22,7 +22,7 @@ func GetAllTestCases() map[string]AllTestCase {
},
},
"func": {
"func sum(a: number, b: number) {\n\treturn a + b\n}\nsum(1, 2)",
"func sum(a: number, b: number) number {\n\treturn a + b\n}\n_ = sum(1, 2)",
[]Value{
&VariableValue{
"sum",
@ -54,6 +54,21 @@ func GetAllTestCases() map[string]AllTestCase {
},
},
},
"list": {
"a := [1, 2]",
[]Value{
&VariableValue{
"a",
&ListValue{
[]Value{
&NumberValue{1},
&NumberValue{2},
},
},
0,
},
},
},
}
}
@ -84,7 +99,7 @@ func TestAll(t *testing.T) {
}
t.Log("Initializing compiler")
c := NewCompiler()
c := NewCompiler([]rune(tc.src))
t.Log("Compiling parse tree")
err = c.Compile(tree)
@ -119,7 +134,7 @@ func BenchmarkAll(b *testing.B) {
p := NewParser(tokens)
tree, _ := p.Parse()
c := NewCompiler()
c := NewCompiler([]rune(tc.src))
_ = c.Compile(tree)
vm := NewVM(c.Chunk, 256, 256)