This commit is contained in:
agra
2026-02-14 14:03:16 +02:00
parent 025b790411
commit fe7efeadb0
10 changed files with 320 additions and 10 deletions

View File

@@ -147,6 +147,10 @@ pub const Instruction = union(enum) {
gt,
gte,
// Bitwise
bit_and,
bit_or,
// Logic
not,
@@ -451,6 +455,8 @@ pub const Compiler = struct {
.lte => .lte,
.gt => .gt,
.gte => .gte,
.bit_and => .bit_and,
.bit_or => .bit_or,
.and_op, .or_op => unreachable,
});
}
@@ -1026,6 +1032,20 @@ pub const VM = struct {
const a = try self.pop();
try self.push(try self.arith(a, b, .mod_op));
},
.bit_and => {
const b = try self.pop();
const a = try self.pop();
if (a == .int_val and b == .int_val) {
try self.push(.{ .int_val = a.int_val & b.int_val });
} else return error.TypeError;
},
.bit_or => {
const b = try self.pop();
const a = try self.pop();
if (a == .int_val and b == .int_val) {
try self.push(.{ .int_val = a.int_val | b.int_val });
} else return error.TypeError;
},
.negate => {
const v = try self.pop();
try self.push(switch (v) {