we in era3 boys; overhauled expression system, and variables are now in maps

This commit is contained in:
Neemek 2026-07-09 23:10:49 +02:00
parent bf29e6c3dd
commit 43e450c207
Signed by: neemek
GPG key ID: 84FFE4D7D40AB25E
14 changed files with 945 additions and 452 deletions

View file

@ -30,6 +30,7 @@ func BenchmarkNewCompiler(b *testing.B) {
type CompileTestData struct {
program *Program
expectedStack []Value
expectedScope []map[string]Value
}
func GetCompileTestData() map[string]CompileTestData {
@ -40,7 +41,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"a",
&ReferenceNode{"a", 0, 0},
&StringNode{
"Hello world!",
"\"Hello world!\"",
@ -54,21 +55,21 @@ func GetCompileTestData() map[string]CompileTestData {
},
"",
},
[]Value{
&VariableValue{
"a",
&StringValue{"Hello world!"},
0,
[]Value{&StringValue{"Hello world!"}},
[]map[string]Value{
{
"a": &StringValue{"Hello world!"},
},
},
},
/* these tests are so fucking unmaintainable
"conditional_false": {
&Program{
[]Import{},
&BlockNode{
[]Node{
&AssignNode{
"a",
&ReferenceNode{"a", 0, 0},
&FloatNode{
0,
0, 0,
@ -84,7 +85,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"a",
&ReferenceNode{"a", 0, 0},
&FloatNode{
1,
0, 0,
@ -117,7 +118,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"a",
&ReferenceNode{"a", 0, 0},
&FloatNode{
0,
0, 0,
@ -133,7 +134,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"a",
&ReferenceNode{"a", 0, 0},
&FloatNode{
1,
0, 0,
@ -166,7 +167,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"a",
&ReferenceNode{"a", 0, 0},
&FloatNode{
0,
0, 0,
@ -182,7 +183,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"a",
&ReferenceNode{"a", 0, 0},
&FloatNode{
1,
0, 0,
@ -196,7 +197,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"a",
&ReferenceNode{"a", 0, 0},
&FloatNode{
2,
0, 0,
@ -228,7 +229,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"a",
&ReferenceNode{"a", 0, 0},
&FloatNode{
0,
0, 0,
@ -244,7 +245,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"a",
&ReferenceNode{"a", 0, 0},
&FloatNode{
1,
0, 0,
@ -258,7 +259,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"a",
&ReferenceNode{"a", 0, 0},
&FloatNode{
2,
0, 0,
@ -290,7 +291,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"a",
&ReferenceNode{"a", 0, 0},
&BinaryNode{
BinaryAddition,
&FloatNode{
@ -325,7 +326,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"sum",
&ReferenceNode{name: "sum"},
&FunctionNode{
"sum",
[]FunctionParameter{
@ -411,7 +412,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"a",
&ReferenceNode{"a", 0, 0},
&FunctionNode{
"a",
[]FunctionParameter{},
@ -419,7 +420,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
"b",
&ReferenceNode{"b", 0, 0},
&FloatNode{
1,
0, 0,
@ -448,7 +449,6 @@ func GetCompileTestData() map[string]CompileTestData {
0, 0,
},
[]Node{},
false,
0, 0,
},
},
@ -488,7 +488,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
statements: []Node{
&AssignNode{
name: "a",
dest: &ReferenceNode{"a", 0, 0},
value: &ListNode{
items: []Node{
&FloatNode{value: 1},
@ -498,7 +498,7 @@ func GetCompileTestData() map[string]CompileTestData {
declare: true,
},
&AssignNode{
name: "b",
dest: &ReferenceNode{"b", 0, 0},
value: &ListNode{
items: []Node{
&StringNode{value: "Hello"},
@ -540,7 +540,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
name: "a",
dest: &ReferenceNode{"a", 0, 0},
value: &UnaryNode{
UnaryNegate,
&FloatNode{
@ -570,7 +570,7 @@ func GetCompileTestData() map[string]CompileTestData {
&BlockNode{
[]Node{
&AssignNode{
name: "a",
dest: &ReferenceNode{"a", 0, 0},
value: &UnaryNode{
UnaryNot,
&BooleanNode{
@ -593,6 +593,7 @@ func GetCompileTestData() map[string]CompileTestData {
},
},
},
*/
}
}
@ -642,6 +643,7 @@ func TestCompile(t *testing.T) {
t.Log("Executed bytecode")
CompareStacks(t, testCase.expectedStack, vm.stack)
CompareScope(t, testCase.expectedScope, vm.scope)
})
}
}
@ -691,7 +693,7 @@ func TestCompiler_CleanStack(t *testing.T) {
}
// make sure stack has only assigned values
for i := 0; i < int(vm.stack.Current); i++ {
for i := 1; i < int(vm.stack.Current); i++ {
v := vm.stack.items[i]
if v == nil || v.Type() != VariableValueType {