diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2025-01-22 00:30:28 +0100 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2025-01-22 00:30:59 +0100 |
commit | 596cfe8b9d7319085465bbd134247e2967652f6f (patch) | |
tree | 106c0926321316cac67d57ea94df8444fd0b3f8f /src/evaluator.zig | |
parent | Feature: Add support for division and multiplication (diff) | |
download | interpreter-596cfe8b9d7319085465bbd134247e2967652f6f.tar.gz interpreter-596cfe8b9d7319085465bbd134247e2967652f6f.tar.bz2 interpreter-596cfe8b9d7319085465bbd134247e2967652f6f.zip |
Feature: Add support for negation
Diffstat (limited to 'src/evaluator.zig')
-rw-r--r-- | src/evaluator.zig | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/evaluator.zig b/src/evaluator.zig index 9f8b61f..798d66c 100644 --- a/src/evaluator.zig +++ b/src/evaluator.zig @@ -174,6 +174,10 @@ pub const Evaluator = struct { }, .UNARY_EXPRESSION => |x| { const val = try self.get_expression_value(x.expression) orelse return EvaluatorError.EvaluationError; + if (!x.negation) { + std.debug.assert(val.* == .NUMBER); + return try self.create_variable(.{ .NUMBER = -val.NUMBER }); + } std.debug.assert(val.* == .BOOLEAN); return try self.create_variable(.{ .BOOLEAN = !val.BOOLEAN }); }, @@ -268,7 +272,6 @@ const Environment = struct { .allocator = allocator, }; - //TODO: Add more scopes when evaluating functions // Create global scope try self.create_scope(); |