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

@ -8,107 +8,66 @@ import (
type AllTestCase struct {
src string
expectedStack []Value
expectedScope []map[string]Value
}
func GetAllTestCases() map[string]AllTestCase {
return map[string]AllTestCase{
"constant_number": {
"a := 1",
[]Value{
&VariableValue{
"a",
&IntegerValue{new(big.Int).SetInt64(1)},
0,
},
[]Value{&IntegerValue{new(big.Int).SetInt64(1)}},
[]map[string]Value{
{"a": &IntegerValue{new(big.Int).SetInt64(1)}},
},
},
"func": {
"fn sum(a: int, b: int) -> int {\n\treturn a + b\n}\n_ = sum(1, 2)",
[]Value{
&VariableValue{
"sum",
&FunctionValue{
Name: "sum",
Params: []FunctionParameter{
{
"a",
&IntegerSignature{},
},
{
"b",
&IntegerSignature{},
},
},
Chunk: &Chunk{
Bytecode: []Bytecode{
InstructionDescend,
InstructionGetLocal, 0,
InstructionGetLocal, 1,
InstructionAddInt,
InstructionReturn,
InstructionAscend,
},
Constants: []Value{&StringValue{"a"}, &StringValue{"b"}},
},
},
0,
},
},
"fn sum(a: int, b: int) -> int {\n\treturn a + b\n}\nres := sum(1, 2)",
[]Value{&IntegerValue{new(big.Int).SetInt64(3)}},
[]map[string]Value{},
},
"list": {
"a := [1.0, 2.0]",
[]Value{
&VariableValue{
"a",
&ListValue{
[]Value{
&FloatValue{1},
&FloatValue{2},
},
"a := [1.0, 2.0]\n{}",
[]Value{&NilValue{}},
[]map[string]Value{
{"a": &ListValue{
[]Value{
&FloatValue{1},
&FloatValue{2},
},
0,
},
}},
},
},
"constant_list_concat": {
"a := [1, 2] + [3]",
[]Value{
&VariableValue{
"a",
&ListValue{
[]Value{
&IntegerValue{big.NewInt(1)},
&IntegerValue{big.NewInt(2)},
&IntegerValue{big.NewInt(3)},
},
"a := [1, 2] + [3]\n{}",
[]Value{&NilValue{}},
[]map[string]Value{
{"a": &ListValue{
[]Value{
&IntegerValue{big.NewInt(1)},
&IntegerValue{big.NewInt(2)},
&IntegerValue{big.NewInt(3)},
},
0,
},
}},
},
},
"list_concat": {
"a := [1.0, 2.0]\nb := a + [3.0]",
[]Value{
&VariableValue{
"a",
&ListValue{
"a := [1.0, 2.0]\nb := a + [3.0]\nnil",
[]Value{&NilValue{}},
[]map[string]Value{
{
"a": &ListValue{
[]Value{
&FloatValue{1},
&FloatValue{2},
},
},
0,
},
&VariableValue{
"b",
&ListValue{
"b": &ListValue{
[]Value{
&FloatValue{1},
&FloatValue{2},
&FloatValue{3},
},
},
0,
},
},
},
@ -160,7 +119,13 @@ func TestAll(t *testing.T) {
}
t.Log("Comparing stacks")
CompareStacks(t, tc.expectedStack, vm.stack)
// expected scope == nil => we don't care
if tc.expectedScope != nil {
CompareScope(t, tc.expectedScope, vm.scope)
}
})
}
}