Skip to content

Commit

Permalink
get basic breakpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexicon226 committed Jun 30, 2024
1 parent eac8ad4 commit c02080c
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn usage() void {
\\ Debug Options:
\\ --no-run Doesn't run the VM, useful for debugging Osmium
\\ --graph, Creates a "graph.bin" which contains CFG information
\\ --debug, Runs a interactable debug mode to debug the VM
\\ --debug, Runs a interactable mode to debug the VM
;

const stdout = std.io.getStdOut().writer();
Expand Down
3 changes: 1 addition & 2 deletions src/modules/builtins.zig
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ fn print(vm: *Vm, args: []const Object, maybe_kw: ?KW_Type) BuiltinError!void {
const t = tracer.trace(@src(), "builtin-print", .{});
defer t.end();

const stdout = std.io.getStdOut().writer();

const stdout = vm.stdout;
for (args, 0..) |arg, i| {
printSafe(stdout, "{}", .{arg});

Expand Down
21 changes: 12 additions & 9 deletions src/vm/Vm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,28 @@ crash_info: crash_report.VmContext,

builtin_mods: std.StringHashMapUnmanaged(Object.Payload.Module) = .{},

/// Default set to FD1
stdout: std.io.AnyWriter,

/// Takes ownership of `co`.
pub fn init(allocator: Allocator, co: CodeObject) !Vm {
const t = tracer.trace(@src(), "", .{});
defer t.end();

return .{
var vm: Vm = .{
.allocator = allocator,
.is_running = false,
.co = co,
.crash_info = crash_report.prepVmContext(co),
.stack = try std.ArrayListUnmanaged(Object).initCapacity(allocator, co.stacksize),
.stdout = std.io.getStdOut().writer().any(),
};

assert(vm.scopes.items.len == 0);
try vm.scopes.append(vm.allocator, .{});
try vm.co.process(vm.allocator);

return vm;
}

pub fn initBuiltinMods(vm: *Vm, mod_path: []const u8) !void {
Expand Down Expand Up @@ -117,12 +127,6 @@ pub fn run(
const t = tracer.trace(@src(), "", .{});
defer t.end();

// create the immediate scope
assert(vm.scopes.items.len == 0);
try vm.scopes.append(vm.allocator, .{});

try vm.co.process(vm.allocator);

vm.is_running = true;

vm.crash_info.push();
Expand Down Expand Up @@ -180,7 +184,7 @@ pub fn deinit(vm: *Vm) void {
vm.* = undefined;
}

fn exec(vm: *Vm, inst: Instruction) !void {
pub fn exec(vm: *Vm, inst: Instruction) !void {
const t = tracer.trace(@src(), "{s}", .{@tagName(inst.op)});
defer t.end();

Expand Down Expand Up @@ -307,7 +311,6 @@ fn execStoreName(vm: *Vm, inst: Instruction) !void {
const name = vm.co.getName(inst.extra);
// NOTE: STORE_NAME does NOT pop the stack, it only stores the TOS.
const tos = vm.stack.items[vm.stack.items.len - 1];
std.debug.print("STORE_NAME: {}\n", .{tos});
try vm.scopes.items[vm.depth].put(vm.allocator, name, tos);
}

Expand Down
Loading

0 comments on commit c02080c

Please sign in to comment.