Fix VM memory allocation optimizations by reducing what we allocate on the heap
This commit is contained in:
@@ -42,7 +42,7 @@ func runVmTests(t *testing.T, tests []vmTestCase) {
|
||||
// switch constant := constant.(type) {
|
||||
// case *object.CompiledFunction:
|
||||
// fmt.Printf(" Instructions:\n%s", constant.Instructions)
|
||||
// case *object.Integer:
|
||||
// case object.Integer:
|
||||
// fmt.Printf(" Value: %d\n", constant.Value)
|
||||
// }
|
||||
//
|
||||
@@ -129,13 +129,13 @@ func testExpectedObject(t *testing.T, expected interface{}, actual object.Object
|
||||
}
|
||||
}
|
||||
|
||||
case *object.Null:
|
||||
case object.Null:
|
||||
if actual != Null {
|
||||
t.Errorf("object is not Null: %T (%+v)", actual, actual)
|
||||
}
|
||||
|
||||
case *object.Error:
|
||||
errObj, ok := actual.(*object.Error)
|
||||
case object.Error:
|
||||
errObj, ok := actual.(object.Error)
|
||||
if !ok {
|
||||
t.Errorf("object is not Error: %T (%+v)", actual, actual)
|
||||
return
|
||||
@@ -153,7 +153,7 @@ func parse(input string) *ast.Program {
|
||||
}
|
||||
|
||||
func testIntegerObject(expected int64, actual object.Object) error {
|
||||
result, ok := actual.(*object.Integer)
|
||||
result, ok := actual.(object.Integer)
|
||||
if !ok {
|
||||
return fmt.Errorf("object is not Integer. got=%T (%+v", actual, actual)
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func testIntegerObject(expected int64, actual object.Object) error {
|
||||
}
|
||||
|
||||
func testBooleanObject(expected bool, actual object.Object) error {
|
||||
result, ok := actual.(*object.Boolean)
|
||||
result, ok := actual.(object.Boolean)
|
||||
if !ok {
|
||||
return fmt.Errorf("object is not Boolean. got=%T (%+v", actual, actual)
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func testBooleanObject(expected bool, actual object.Object) error {
|
||||
}
|
||||
|
||||
func testStringObject(expected string, actual object.Object) error {
|
||||
result, ok := actual.(*object.String)
|
||||
result, ok := actual.(object.String)
|
||||
if !ok {
|
||||
return fmt.Errorf("object is not String. got=%T (%+v", actual, actual)
|
||||
}
|
||||
@@ -379,15 +379,15 @@ func TestHashLiterals(t *testing.T) {
|
||||
{
|
||||
"{1: 2, 2: 3}",
|
||||
map[object.HashKey]int64{
|
||||
(&object.Integer{Value: 1}).HashKey(): 2,
|
||||
(&object.Integer{Value: 2}).HashKey(): 3,
|
||||
(object.Integer{Value: 1}).HashKey(): 2,
|
||||
(object.Integer{Value: 2}).HashKey(): 3,
|
||||
},
|
||||
},
|
||||
{
|
||||
"{1 + 1: 2 * 2, 3 + 3: 4 * 4}",
|
||||
map[object.HashKey]int64{
|
||||
(&object.Integer{Value: 2}).HashKey(): 4,
|
||||
(&object.Integer{Value: 6}).HashKey(): 16,
|
||||
(object.Integer{Value: 2}).HashKey(): 4,
|
||||
(object.Integer{Value: 6}).HashKey(): 16,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -400,14 +400,14 @@ func TestHashMerging(t *testing.T) {
|
||||
{
|
||||
`{} + {"a": 1}`,
|
||||
map[object.HashKey]int64{
|
||||
(&object.String{Value: "a"}).HashKey(): 1,
|
||||
(object.String{Value: "a"}).HashKey(): 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
`{"a": 1} + {"b": 2}`,
|
||||
map[object.HashKey]int64{
|
||||
(&object.String{Value: "a"}).HashKey(): 1,
|
||||
(&object.String{Value: "b"}).HashKey(): 2,
|
||||
(object.String{Value: "a"}).HashKey(): 1,
|
||||
(object.String{Value: "b"}).HashKey(): 2,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user