diff options
Diffstat (limited to 'evaluator/evaluator.go')
| -rw-r--r-- | evaluator/evaluator.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/evaluator/evaluator.go b/evaluator/evaluator.go index 0cc003f..b8940a9 100644 --- a/evaluator/evaluator.go +++ b/evaluator/evaluator.go @@ -57,6 +57,8 @@ func evalPrefixExpression(operator string, right object.Object) object.Object { switch operator { case "!": return evalBangOperatorExpression(right) + case "-": + return evalMinusPrefixOperatorExpression(right) default: return NULL } @@ -74,3 +76,12 @@ func evalBangOperatorExpression(right object.Object) object.Object { return FALSE } } + +func evalMinusPrefixOperatorExpression(right object.Object) object.Object { + if right.Type() != object.INTEGER_OBJ { + return NULL + } + + value := right.(*object.Integer).Value + return &object.Integer{Value: -value} +} |
