simpler vm
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user