Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Windows support
Browse files Browse the repository at this point in the history
closes #74
giann committed Jul 31, 2024
1 parent 7528467 commit 81c5daa
Showing 2 changed files with 28 additions and 8 deletions.
11 changes: 9 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
@@ -283,7 +283,7 @@ pub fn build(b: *Build) !void {
try buildMimalloc(b, target, build_mode)
else
null;
const lib_linenoise = if (!is_wasm)
const lib_linenoise = if (!is_wasm and target.result.os.tag != .windows)
try buildLinenoise(b, target, build_mode)
else
null;
@@ -738,10 +738,17 @@ pub fn buildMir(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.O
"-O3",
"-DNDEBUG=1",
"-DMIR_PARALLEL_GEN=1",
"-fno-sanitize=undefined", // MIR has some undefined behaviour somewhere so we need this
"-fno-sanitize=undefined",
// "-fsanitize=address",
// "-fno-sanitize=alignment",
},
},
);

if (target.result.os.tag == .windows) {
lib.linkSystemLibrary("kernel32");
lib.linkSystemLibrary("psapi");
}

return lib;
}
25 changes: 19 additions & 6 deletions src/repl.zig
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ const ObjForeignContainer = _obj.ObjForeignContainer;
const Parser = @import("Parser.zig");
const CompileError = Parser.CompileError;
const JIT = @import("Jit.zig");
const ln = @import("linenoise.zig");
const ln = if (builtin.os.tag != .windows) @import("linenoise.zig") else void;
const Value = @import("value.zig").Value;
const disassembler = @import("disassembler.zig");
const dumpStack = disassembler.dumpStack;
@@ -146,8 +146,10 @@ pub fn repl(allocator: std.mem.Allocator) !void {
.{std.posix.getenv("HOME") orelse "."},
);

_ = ln.linenoiseHistorySetMaxLen(100);
_ = ln.linenoiseHistoryLoad(@ptrCast(buzz_history_path.items.ptr));
if (builtin.os.tag != .windows) {
_ = ln.linenoiseHistorySetMaxLen(100);
_ = ln.linenoiseHistoryLoad(@ptrCast(buzz_history_path.items.ptr));
}

// Import std and debug as commodity
_ = runSource(
@@ -163,17 +165,28 @@ pub fn repl(allocator: std.mem.Allocator) !void {
var previous_parser_globals = try parser.globals.clone();
var previous_globals = try vm.globals.clone();
var previous_type_registry = try gc.type_registry.registry.clone();
const stdin_buffer = if (builtin.os.tag == .windows)
gc.allocator.alloc(u8, 2048) catch @panic("Out of memory")
else
null;

while (true) {
const read_source = ln.linenoise(PROMPT);
const read_source = if (builtin.os.tag != .windows)
ln.linenoise(PROMPT)
else
std.io.getStdIn().reader().readUntilDelimiterOrEof(stdin_buffer, '\n') catch |err|
std.debug.panic("{}\n", .{err});

if (read_source == null) {
std.process.exit(0);
}

const source = std.mem.span(read_source.?);

_ = ln.linenoiseHistoryAdd(source);
_ = ln.linenoiseHistorySave(@ptrCast(buzz_history_path.items.ptr));
if (builtin.os.tag != .windows) {
_ = ln.linenoiseHistoryAdd(source);
_ = ln.linenoiseHistorySave(@ptrCast(buzz_history_path.items.ptr));
}

if (source.len > 0) {
// Highlight input

0 comments on commit 81c5daa

Please sign in to comment.