diff options
| author | Baitinq <[email protected]> | 2025-03-29 11:22:13 +0100 |
|---|---|---|
| committer | Baitinq <[email protected]> | 2025-03-29 11:27:15 +0100 |
| commit | d74c6a363cf457a2197f3f10c0d567a77573e79c (patch) | |
| tree | b82cad7904e8493c28cfa1612de2e0e081484e0c /src/evaluator.zig | |
| parent | Codegen: Support void type (diff) | |
| download | interpreter-d74c6a363cf457a2197f3f10c0d567a77573e79c.tar.gz interpreter-d74c6a363cf457a2197f3f10c0d567a77573e79c.tar.bz2 interpreter-d74c6a363cf457a2197f3f10c0d567a77573e79c.zip | |
Feature: Add basic support for pointer references and dereferences
Diffstat (limited to 'src/evaluator.zig')
| -rw-r--r-- | src/evaluator.zig | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/evaluator.zig b/src/evaluator.zig index f3c0a6c..5d97eed 100644 --- a/src/evaluator.zig +++ b/src/evaluator.zig @@ -186,12 +186,17 @@ 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 }); + switch (x.typ) { + .NOT => { + std.debug.assert(val.* == .BOOLEAN); + return try self.create_variable(.{ .BOOLEAN = !val.BOOLEAN }); + }, + .MINUS => { + std.debug.assert(val.* == .NUMBER); + return try self.create_variable(.{ .NUMBER = -val.NUMBER }); + }, + else => unreachable, } - std.debug.assert(val.* == .BOOLEAN); - return try self.create_variable(.{ .BOOLEAN = !val.BOOLEAN }); }, .EQUALITY_EXPRESSION => |x| { const lhs = try self.get_expression_value(x.lhs) orelse return EvaluatorError.EvaluationError; |