diff options
| author | Bobby <[email protected]> | 2024-02-18 00:17:54 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-02-18 00:17:54 -0500 |
| commit | 8415754488747d96d40ffc5ff77631ef3cfec44a (patch) | |
| tree | 5b42d32c15002cf47ac792f7eb4d4790527c7c3e /evaluator/evaluator.go | |
| parent | 57a79dc622311ec5beeafb8af8bcaeff940b4720 (diff) | |
| download | mana-8415754488747d96d40ffc5ff77631ef3cfec44a.tar.xz mana-8415754488747d96d40ffc5ff77631ef3cfec44a.zip | |
Eval Minus Prefix Operator
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} +} |
