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,7 +225,8 @@ func GetCompileTestData() map[string]CompileTestData {
NumberValue(3),
},
},
"sum_function": {
"sum_function": {&BlockNode{
[]Node{
&AssignNode{
"sum",
&FunctionNode{
@ -245,6 +246,8 @@ func GetCompileTestData() map[string]CompileTestData {
},
true,
},
},
},
[]Value{
&VariableValue{
"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,
},
},
},
}
}