we in era3 boys; overhauled expression system, and variables are now in maps
This commit is contained in:
parent
bf29e6c3dd
commit
43e450c207
14 changed files with 945 additions and 452 deletions
|
|
@ -95,10 +95,12 @@ func BenchmarkNewVM(b *testing.B) {
|
|||
func GetExecutionTestData() map[string]struct {
|
||||
chunk *Chunk
|
||||
resultingStack []Value
|
||||
resultingScope []map[string]Value
|
||||
} {
|
||||
return map[string]struct {
|
||||
chunk *Chunk
|
||||
resultingStack []Value
|
||||
resultingScope []map[string]Value
|
||||
}{
|
||||
"two_plus_one": {
|
||||
NewChunk([]Bytecode{
|
||||
|
|
@ -112,6 +114,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&FloatValue{3},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"push_constant": {
|
||||
NewChunk(
|
||||
|
|
@ -125,6 +128,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&FloatValue{1},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"push_true": {
|
||||
NewChunk(
|
||||
|
|
@ -136,6 +140,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&BoolValue{true},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"push_false": {
|
||||
NewChunk(
|
||||
|
|
@ -147,6 +152,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&BoolValue{false},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"push_nil": {
|
||||
NewChunk(
|
||||
|
|
@ -158,6 +164,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&NilValue{},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"empty": {
|
||||
NewChunk(
|
||||
|
|
@ -165,6 +172,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{},
|
||||
),
|
||||
[]Value{},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
// (2 + 1) * 5 / (6 - 2)
|
||||
"full_arithmetic": {
|
||||
|
|
@ -187,6 +195,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&FloatValue{3.75},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"equality_true": {
|
||||
NewChunk(
|
||||
|
|
@ -202,6 +211,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&BoolValue{true},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"equality_false": {
|
||||
NewChunk(
|
||||
|
|
@ -217,6 +227,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&BoolValue{false},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"inequality_false": {
|
||||
NewChunk(
|
||||
|
|
@ -232,6 +243,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&BoolValue{false},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"inequality_true": {
|
||||
NewChunk(
|
||||
|
|
@ -247,6 +259,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&BoolValue{true},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"not_true": {
|
||||
NewChunk(
|
||||
|
|
@ -259,6 +272,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&BoolValue{false},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"not_false": {
|
||||
NewChunk(
|
||||
|
|
@ -271,6 +285,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&BoolValue{true},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"jump": {
|
||||
NewChunk(
|
||||
|
|
@ -286,6 +301,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&FloatValue{1},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"jump_false/false": {
|
||||
NewChunk(
|
||||
|
|
@ -302,6 +318,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&FloatValue{1},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"jump_false/true": {
|
||||
NewChunk(
|
||||
|
|
@ -318,6 +335,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&FloatValue{0}, &FloatValue{1},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"declare_local": {
|
||||
NewChunk(
|
||||
|
|
@ -329,11 +347,10 @@ func GetExecutionTestData() map[string]struct {
|
|||
&FloatValue{0}, &StringValue{"a"},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&VariableValue{
|
||||
"a",
|
||||
&FloatValue{0},
|
||||
0,
|
||||
[]Value{&FloatValue{0}},
|
||||
[]map[string]Value{
|
||||
{
|
||||
"a": &FloatValue{0},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -342,18 +359,19 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Bytecode{
|
||||
InstructionConstant, 0,
|
||||
InstructionDeclareLocal, 1,
|
||||
InstructionPop,
|
||||
InstructionConstant, 2,
|
||||
InstructionSetLocal, 1, // reassign
|
||||
InstructionPop,
|
||||
},
|
||||
[]Value{
|
||||
&FloatValue{0}, &StringValue{"a"}, &FloatValue{1},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&VariableValue{
|
||||
"a",
|
||||
&FloatValue{1},
|
||||
0,
|
||||
[]Value{},
|
||||
[]map[string]Value{
|
||||
{
|
||||
"a": &FloatValue{1},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -362,29 +380,30 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Bytecode{
|
||||
InstructionConstant, 0,
|
||||
InstructionDeclareLocal, 1,
|
||||
InstructionGetLocal, 1, // reassign
|
||||
},
|
||||
[]Value{
|
||||
&FloatValue{0}, &StringValue{"a"},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&VariableValue{
|
||||
"a",
|
||||
&FloatValue{0},
|
||||
0,
|
||||
},
|
||||
&FloatValue{0},
|
||||
},
|
||||
[]map[string]Value{
|
||||
{
|
||||
"a": &FloatValue{0},
|
||||
},
|
||||
},
|
||||
},
|
||||
"get_reassigned_local": {
|
||||
NewChunk(
|
||||
[]Bytecode{
|
||||
InstructionConstant, 0,
|
||||
InstructionDeclareLocal, 1,
|
||||
InstructionPop,
|
||||
InstructionGetLocal, 1,
|
||||
InstructionConstant, 2,
|
||||
InstructionSetLocal, 1, // reassign
|
||||
InstructionPop,
|
||||
InstructionGetLocal, 1,
|
||||
},
|
||||
[]Value{
|
||||
|
|
@ -392,26 +411,29 @@ func GetExecutionTestData() map[string]struct {
|
|||
},
|
||||
),
|
||||
[]Value{
|
||||
&VariableValue{
|
||||
"a",
|
||||
&FloatValue{1},
|
||||
0,
|
||||
},
|
||||
&FloatValue{0},
|
||||
&FloatValue{1},
|
||||
},
|
||||
[]map[string]Value{
|
||||
{
|
||||
"a": &FloatValue{1},
|
||||
},
|
||||
},
|
||||
},
|
||||
"variable_scope": {
|
||||
NewChunk(
|
||||
[]Bytecode{
|
||||
InstructionConstant, 0,
|
||||
InstructionDeclareLocal, 1,
|
||||
InstructionPop,
|
||||
InstructionDescend,
|
||||
InstructionConstant, 2,
|
||||
InstructionDeclareLocal, 3,
|
||||
InstructionPop,
|
||||
InstructionDescend,
|
||||
InstructionConstant, 4,
|
||||
InstructionDeclareLocal, 5,
|
||||
InstructionPop,
|
||||
InstructionAscend,
|
||||
InstructionAscend,
|
||||
},
|
||||
|
|
@ -421,11 +443,10 @@ func GetExecutionTestData() map[string]struct {
|
|||
&FloatValue{2}, &StringValue{"c"},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&VariableValue{
|
||||
"a",
|
||||
&FloatValue{0},
|
||||
0,
|
||||
[]Value{},
|
||||
[]map[string]Value{
|
||||
{
|
||||
"a": &FloatValue{0},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -469,12 +490,14 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&FloatValue{3},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
"function_calling_function": {
|
||||
NewChunk(
|
||||
[]Bytecode{
|
||||
InstructionConstant, 3,
|
||||
InstructionDeclareLocal, 4,
|
||||
InstructionPop,
|
||||
InstructionConstant, 0,
|
||||
InstructionConstant, 1,
|
||||
InstructionConstant, 2,
|
||||
|
|
@ -533,9 +556,11 @@ func GetExecutionTestData() map[string]struct {
|
|||
},
|
||||
),
|
||||
[]Value{
|
||||
&VariableValue{
|
||||
"square",
|
||||
&FunctionValue{
|
||||
&FloatValue{5},
|
||||
},
|
||||
[]map[string]Value{
|
||||
{
|
||||
"square": &FunctionValue{
|
||||
Name: "square",
|
||||
Params: []FunctionParameter{
|
||||
{
|
||||
|
|
@ -555,9 +580,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
},
|
||||
),
|
||||
},
|
||||
0,
|
||||
},
|
||||
&FloatValue{5},
|
||||
},
|
||||
},
|
||||
"list_concat": {
|
||||
|
|
@ -590,6 +613,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
},
|
||||
},
|
||||
},
|
||||
[]map[string]Value{},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue