simpler vm
Some checks failed
Test / build (push) Waiting to run
Build / build (push) Successful in 11m8s
Publish Image / publish (push) Has been cancelled

This commit is contained in:
2024-04-01 17:21:55 -04:00
parent f9e6e164b0
commit 803f330e82
6 changed files with 246 additions and 317 deletions

View File

@@ -14,8 +14,14 @@ func Len(args ...object.Object) object.Object {
return newError(err.Error())
}
if size, ok := args[0].(object.Sizeable); ok {
return object.Integer{Value: int64(size.Len())}
switch obj := args[0].(type) {
case object.String:
return object.Integer{Value: int64(obj.Len())}
case *object.Array:
return object.Integer{Value: int64(obj.Len())}
case *object.Hash:
return object.Integer{Value: int64(obj.Len())}
default:
return newError("TypeError: object of type '%s' has no len()", args[0].Type())
}
return newError("TypeError: object of type '%s' has no len()", args[0].Type())
}