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

@@ -35,17 +35,21 @@ func (s String) String() string {
}
func (s String) Add(other Object) (Object, error) {
if !AssertTypes(other, StringType) {
switch obj := other.(type) {
case String:
return String{s.Value + obj.Value}, nil
default:
return nil, NewBinaryOpError(s, other, "+")
}
return String{s.Value + other.(String).Value}, nil
}
func (s String) Mul(other Object) (Object, error) {
if !AssertTypes(other, IntegerType) {
switch obj := other.(type) {
case Integer:
return String{strings.Repeat(s.Value, int(obj.Value))}, nil
default:
return nil, NewBinaryOpError(s, other, "*")
}
return String{strings.Repeat(s.Value, int(other.(Integer).Value))}, nil
}
func (s String) Get(index Object) (Object, error) {