diff --git a/build.zig b/build.zig index cd69176..81bacf3 100644 --- a/build.zig +++ b/build.zig @@ -68,7 +68,20 @@ pub fn build(b: *std.Build) !void { exe.root_module.addImport("cpython", cpython_dep.module("cpython")); exe.root_module.addImport("vaxis", libvaxis.module("vaxis")); - exe_options.addOption([]const u8, "lib_path", "../python/Lib"); + // install the Lib folder from python + const python_dep = b.dependency("python", .{}); + const libpython_install = b.addInstallDirectory(.{ + .source_dir = python_dep.path("Lib"), + .install_dir = .{ .custom = "python" }, + .install_subdir = "Lib", + }); + exe.step.dependOn(&libpython_install.step); + + exe_options.addOption( + []const u8, + "lib_path", + b.getInstallPath(.{ .custom = "python" }, "Lib"), + ); const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); diff --git a/build.zig.zon b/build.zig.zon index 3edd201..dea4bc2 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -13,8 +13,10 @@ .url = "https://github.com/Rexicon226/zig-tracer/archive/6400e066bb3849be4906f3b6e124d6c8c5a5083f.tar.gz", .hash = "122057453dba0b0cf6f07610d692cc7ab3f1d66defa150c936b398144812564a0c08", }, - .cpython = .{ - .path = "../zig-cpython", + // needs to be kept in sync with cpython dep + .python = .{ + .url = "https://github.com/Rexicon226/cpython/archive/cdb93314157b15ba6ba0832f4ad7c84c11088331.tar.gz", + .hash = "12201233efd4fb9453166782f1beb083953b3e9cc2b347621a55482addf0714e6962", }, .libgc = .{ .url = "https://github.com/Rexicon226/zig-libgc/archive/1ea12e140ec1471af5d15dae71b225764c9747ba.tar.gz", @@ -24,5 +26,9 @@ .url = "https://github.com/rockorager/libvaxis/archive/c213919849114ce03def64806af546b9fc391859.tar.gz", .hash = "12206f2265ca2262f919ec125ff7fe15fa6f3be622806e211d7a9bd3055ba51a0908", }, + .cpython = .{ + .url = "https://github.com/Rexicon226/zig-cpython/archive/6ee418f9f7be7e811e5555f73a0335905c386914.tar.gz", + .hash = "122017c3777f28ab50709a456371d710e3a00c9ac82959128319ffbdfb18f1528c2a", + }, }, } diff --git a/src/modules/builtins.zig b/src/modules/builtins.zig index 88b0d90..9b74e39 100644 --- a/src/modules/builtins.zig +++ b/src/modules/builtins.zig @@ -98,7 +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 = vm.stdout; + const stdout = vm.getStdout(); for (args, 0..) |arg, i| { printSafe(stdout, "{}", .{arg}); @@ -146,8 +146,8 @@ fn input(vm: *Vm, args: []const Object, maybe_kw: ?KW_Type) BuiltinError!void { const prompt = args[0]; const prompt_string = prompt.get(.string); - const stdout = std.io.getStdOut(); - printSafe(stdout.writer(), "{s}", .{prompt_string}); + const stdout = vm.getStdout(); + printSafe(stdout, "{s}", .{prompt_string}); } const stdin = std.io.getStdIn(); diff --git a/src/vm/Vm.zig b/src/vm/Vm.zig index 415e0a9..13665d9 100644 --- a/src/vm/Vm.zig +++ b/src/vm/Vm.zig @@ -56,7 +56,7 @@ crash_info: crash_report.VmContext, builtin_mods: std.StringHashMapUnmanaged(Object.Payload.Module) = .{}, /// Default set to FD1 -stdout: std.io.AnyWriter, +stdout_override: ?std.io.AnyWriter, /// Takes ownership of `co`. pub fn init(allocator: Allocator, co: CodeObject) !Vm { @@ -69,7 +69,7 @@ pub fn init(allocator: Allocator, co: CodeObject) !Vm { .co = co, .crash_info = crash_report.prepVmContext(co), .stack = try std.ArrayListUnmanaged(Object).initCapacity(allocator, co.stacksize), - .stdout = std.io.getStdOut().writer().any(), + .stdout_override = null, }; assert(vm.scopes.items.len == 0); @@ -795,6 +795,11 @@ fn setNewCo( vm.co = new_co; } +const stdout = std.io.getStdOut().writer(); +pub fn getStdout(vm: *const Vm) std.io.AnyWriter { + return vm.stdout_override orelse stdout.any(); +} + pub fn fail( vm: *Vm, comptime fmt: []const u8, diff --git a/src/vm/debug.zig b/src/vm/debug.zig index eafdfb3..b9cfe9b 100644 --- a/src/vm/debug.zig +++ b/src/vm/debug.zig @@ -76,7 +76,7 @@ const State = struct { } const vm = state.vm; - vm.stdout = state.stdout.writer().any(); + vm.stdout_override = state.stdout.writer().any(); vm.is_running = true; while (vm.is_running) {