creating a VM (ch15)
This commit is contained in:
1 parent
6c8cf697f1
commit
2a365287a8
5 files changed
+193
-110
No files matched your search
@@ -1,6 +1,26 @@
|
||||
const std = @import("std");
|
||||
const debug = std.debug;
|
||||
|
||||
const Chunk = @import("./chunk.zig").Chunk;
|
||||
const print_value = @import("./values.zig").print_value;
|
||||
|
||||
pub fn grow_capacity(capacity: usize) usize {
|
||||
if (capacity < 8) {
|
||||
return 8;
|
||||
}
|
||||
return capacity * 2;
|
||||
}
|
||||
|
||||
pub fn simple_instruction(opcode_name: []const u8, offset: usize) usize {
|
||||
debug.print("{s:16}\n", .{opcode_name});
|
||||
|
||||
return offset + 1;
|
||||
}
|
||||
|
||||
pub fn constant_instruction(opcode_name: []const u8, chunk: Chunk, offset: usize) usize {
|
||||
const constant = chunk.code[offset + 1];
|
||||
debug.print("{s:16} {d:4} '", .{ opcode_name, constant });
|
||||
print_value(chunk.constants.values[constant]);
|
||||
debug.print("'\n", .{});
|
||||
return offset + 2;
|
||||
}
|
||||
Reference in new issue
Block a user