aboutsummaryrefslogtreecommitdiff
path: root/src/compile.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/compile.zig')
-rw-r--r--src/compile.zig21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/compile.zig b/src/compile.zig
index acae7ff..c837495 100644
--- a/src/compile.zig
+++ b/src/compile.zig
@@ -14,7 +14,7 @@ pub const Instr = struct {
pub const Type = union(enum) {
constant: Constant,
bin_op: BinOp,
- print: Print,
+ proc_call: ProcCall,
discard: Discard,
};
@@ -43,11 +43,17 @@ pub const Instr = struct {
}
};
- pub const Print = struct {
+ pub const ProcCall = struct {
dest: VReg,
arg: VReg,
+ proc: Proc,
- pub fn sources(self: Print) Sources {
+ const Proc = enum {
+ print,
+ read_int,
+ };
+
+ pub fn sources(self: ProcCall) Sources {
return Sources.fromSlice(&.{self.arg}) catch unreachable;
}
};
@@ -68,7 +74,7 @@ pub const Instr = struct {
pub fn dest(self: *const Instr) ?VReg {
return switch (self.type) {
- inline .constant, .bin_op, .print => |s| s.dest,
+ inline .constant, .bin_op, .proc_call => |s| s.dest,
// inline .x => null,
};
}
@@ -167,14 +173,13 @@ const CompileContext = struct {
});
},
.call => |call| {
- if (call.proc.type != .identifier or
- !std.mem.eql(u8, call.proc.loc.getIdent(self.source), "print"))
- return error.CantCallAnythingButPrint;
+ if (call.proc.type != .identifier) return error.CanOnlyCallIdentifiers;
+ const proc = std.meta.stringToEnum(Instr.ProcCall.Proc, call.proc.loc.getIdent(self.source)) orelse return error.UnknownProcedure;
const arg = try self.compileExpr(call.arg);
try self.addInstr(.{
.loc = expr.loc,
- .type = .{ .print = .{ .dest = dest, .arg = arg } },
+ .type = .{ .proc_call = .{ .dest = dest, .arg = arg, .proc = proc } },
});
},
.identifier => {