Skip to content

Commit

Permalink
add the --no-run option
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexicon226 committed Jun 24, 2024
1 parent 849ae9f commit 35b7b10
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/calculator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from math import add
def add(x, y) -> int:
return x + y

in1 = input("Input 1st number: ")
in2 = input("Input 2nd number: ")
Expand Down
2 changes: 0 additions & 2 deletions examples/math.py

This file was deleted.

1 change: 1 addition & 0 deletions src/graph/Graph.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub fn walkInst(graph: *Graph, inst: Instruction) !void {

// instructions that only have N arguments
.BUILD_LIST,
.BUILD_TUPLE,
=> {
for (0..inst.extra) |i| {
try graph.edges.append(allocator, .{
Expand Down
13 changes: 10 additions & 3 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub fn log(

const Args = struct {
make_graph: bool,
run: bool,
};

pub fn main() !u8 {
Expand Down Expand Up @@ -104,6 +105,7 @@ pub fn main() !u8 {
var file_path: ?[:0]const u8 = null;
var options: Args = .{
.make_graph = false,
.run = true,
};

while (args.next()) |arg| {
Expand All @@ -127,6 +129,8 @@ pub fn main() !u8 {
}
} else if (std.mem.eql(u8, arg, "--graph")) {
options.make_graph = true;
} else if (std.mem.eql(u8, arg, "--no-run")) {
options.run = false;
}
}

Expand All @@ -148,6 +152,10 @@ fn usage() void {
\\ Options:
\\ --help, -h Print this message
\\ --version, -v Print the version
\\
\\ Debug Options:
\\ --no-run Doesn't run the VM, useful for debugging Osmium
\\ --graph, Creates a "graph.bin" which contains CFG information
;

const stdout = std.io.getStdOut().writer();
Expand Down Expand Up @@ -210,14 +218,13 @@ pub fn run_file(
}

var vm = try Vm.init(gc_allocator, file_name, seed);
defer vm.deinit();
{
var dir_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
const source_file_path = try std.os.getFdPath(source_file.handle, &dir_path_buf);
try vm.initBuiltinMods(source_file_path);
}

try vm.run();
defer vm.deinit();
if (options.run) try vm.run();

main_log.debug("Run stats:", .{});
main_log.debug(
Expand Down

0 comments on commit 35b7b10

Please sign in to comment.