Refactor Type to be an int
Some checks failed
Publish Image / publish (push) Waiting to run
Test / build (push) Waiting to run
Build / build (push) Has been cancelled

This commit is contained in:
Chuck Smith
2024-03-29 11:01:15 -04:00
parent f65d7bfb1c
commit 12d43c9835
58 changed files with 164 additions and 132 deletions

View File

@@ -67,8 +67,7 @@ func (e *encoder) WriteValue(data any) error {
func (e *encoder) WriteObjects(objs ...object.Object) (err error) {
for _, obj := range objs {
err = errors.Join(err, e.WriteValue(len(string(obj.Type()))))
err = errors.Join(err, e.WriteString(string(obj.Type())))
err = errors.Join(err, e.WriteValue(obj.Type()))
switch o := obj.(type) {
case *object.Null:
@@ -145,16 +144,16 @@ func (d *decoder) String(len int) (s string) {
func (d *decoder) Objects(len int) (o []object.Object) {
for i := 0; i < len; i++ {
switch t := d.String(d.Int()); t {
case object.NULL_OBJ:
switch t := object.Type(d.Int()); t {
case object.NullType:
o = append(o, &object.Null{})
case object.BOOLEAN_OBJ:
case object.BooleanType:
o = append(o, &object.Boolean{Value: d.Byte() == 1})
case object.INTEGER_OBJ:
case object.IntegerType:
o = append(o, &object.Integer{Value: d.Int64()})
case object.STRING_OBJ:
case object.StringType:
o = append(o, &object.String{Value: d.String(d.Int())})
case object.COMPILED_FUNCTION_OBJ:
case object.CFunctionType:
// The order of the fields has to reflect the data layout in the encoded bytecode.
o = append(o, &object.CompiledFunction{
NumParameters: d.Int(),
@@ -162,7 +161,7 @@ func (d *decoder) Objects(len int) (o []object.Object) {
Instructions: d.Bytes(d.Int()),
})
default:
panic(fmt.Sprintf("decoder: unsupported decoding for type %s", t))
panic(fmt.Sprintf("decoder: unsupported decoding for type %d", t))
}
}
return