fix sum_function test and add remove_func_vars test

This commit is contained in:
Neemek 2024-10-09 14:21:26 +02:00
parent 0d92fe235f
commit e1f2c81ab0
Signed by: neemek
GPG key ID: 28360A8951CD0E9B

View file

@ -225,26 +225,29 @@ func GetCompileTestData() map[string]CompileTestData {
NumberValue(3), NumberValue(3),
}, },
}, },
"sum_function": { "sum_function": {&BlockNode{
&AssignNode{ []Node{
"sum", &AssignNode{
&FunctionNode{
"sum", "sum",
[]string{"a", "b"}, &FunctionNode{
&BlockNode{ "sum",
[]Node{ []string{"a", "b"},
&ReturnNode{ &BlockNode{
&BinaryNode{ []Node{
BinaryAddition, &ReturnNode{
&ReferenceNode{"a"}, &BinaryNode{
&ReferenceNode{"b"}, BinaryAddition,
&ReferenceNode{"a"},
&ReferenceNode{"b"},
},
}, },
}, },
}, },
}, },
true,
}, },
true,
}, },
},
[]Value{ []Value{
&VariableValue{ &VariableValue{
"sum", "sum",
@ -269,6 +272,60 @@ func GetCompileTestData() map[string]CompileTestData {
}, },
}, },
}, },
"remove_func_vars": {
&BlockNode{
[]Node{
&AssignNode{
"a",
&FunctionNode{
"a",
[]string{},
&BlockNode{
[]Node{
&AssignNode{
"b",
&NumberNode{1},
true,
},
&ReturnNode{
&ReferenceNode{"b"},
},
},
},
},
true,
},
&CallNode{
"a",
[]Node{},
false,
},
},
},
[]Value{
&VariableValue{
"a",
FunctionValue{
"a",
[]string{},
NewChunk(
[]Bytecode{
InstructionDescend,
InstructionConstant, 0,
InstructionDeclareLocal, 1,
InstructionGetLocal, 1,
InstructionReturn,
InstructionAscend,
},
[]Value{
NumberValue(1), StringValue("b"),
},
),
},
0,
},
},
},
} }
} }