Added overloaded support for str * int
This commit is contained in:
12
vm/vm.go
12
vm/vm.go
@@ -526,6 +526,18 @@ func (vm *VM) executeBinaryOperation(op code.Opcode) error {
|
||||
rightType := right.Type()
|
||||
|
||||
switch {
|
||||
|
||||
// " " * 4
|
||||
case left.Type() == object.STRING_OBJ && right.Type() == object.INTEGER_OBJ:
|
||||
leftVal := left.(*object.String).Value
|
||||
rightVal := right.(*object.Integer).Value
|
||||
return vm.push(&object.String{Value: strings.Repeat(leftVal, int(rightVal))})
|
||||
// 4 * " "
|
||||
case left.Type() == object.INTEGER_OBJ && right.Type() == object.STRING_OBJ:
|
||||
leftVal := left.(*object.Integer).Value
|
||||
rightVal := right.(*object.String).Value
|
||||
return vm.push(&object.String{Value: strings.Repeat(rightVal, int(leftVal))})
|
||||
|
||||
case leftType == object.BOOLEAN_OBJ && rightType == object.BOOLEAN_OBJ:
|
||||
return vm.executeBinaryBooleanOperation(op, left, right)
|
||||
case leftType == object.INTEGER_OBJ && rightType == object.INTEGER_OBJ:
|
||||
|
||||
Reference in New Issue
Block a user