Fix VM memory allocation optimizations by reducing what we allocate on the heap
Some checks failed
Build / build (push) Successful in 10m25s
Publish Image / publish (push) Failing after 39s
Test / build (push) Successful in 11m19s

This commit is contained in:
Charles Smith
2024-03-31 20:44:50 -04:00
parent a85dc73954
commit aebbe43999
61 changed files with 383 additions and 370 deletions

View File

@@ -70,13 +70,13 @@ func (e *encoder) WriteObjects(objs ...object.Object) (err error) {
err = errors.Join(err, e.WriteValue(obj.Type()))
switch o := obj.(type) {
case *object.Null:
case object.Null:
break
case *object.Boolean:
case object.Boolean:
err = errors.Join(err, e.WriteValue(o.Value))
case *object.Integer:
case object.Integer:
err = errors.Join(err, e.WriteValue(o.Value))
case *object.String:
case object.String:
err = errors.Join(err, e.WriteValue(len(o.Value)))
err = errors.Join(err, e.WriteValue(o.Value))
case *object.CompiledFunction:
@@ -146,13 +146,13 @@ func (d *decoder) Objects(len int) (o []object.Object) {
for i := 0; i < len; i++ {
switch t := object.Type(d.Int()); t {
case object.NullType:
o = append(o, &object.Null{})
o = append(o, object.Null{})
case object.BooleanType:
o = append(o, &object.Boolean{Value: d.Byte() == 1})
o = append(o, object.Boolean{Value: d.Byte() == 1})
case object.IntegerType:
o = append(o, &object.Integer{Value: d.Int64()})
o = append(o, object.Integer{Value: d.Int64()})
case object.StringType:
o = append(o, &object.String{Value: d.String(d.Int())})
o = append(o, object.String{Value: d.String(d.Int())})
case object.CFunctionType:
// The order of the fields has to reflect the data layout in the encoded bytecode.
o = append(o, &object.CompiledFunction{