Skip to content

Commit 1720a03

Browse files
committed
fix(parser): Minus operand can be placeholders
1 parent d27f54c commit 1720a03

30 files changed

Lines changed: 447 additions & 404 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ zig-cache/
44
zig-out/
55
zig-test/
66
dist/
7+
zig-pkg/
78

89
.vscode/
910
*.bc

build.zig

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ const builtin = @import("builtin");
33
const Build = std.Build;
44

55
pub fn build(b: *Build) !void {
6-
var envMap = try std.process.getEnvMap(b.allocator);
7-
defer envMap.deinit();
8-
96
const build_mode = b.standardOptimizeOption(.{});
107
const target = b.standardTargetOptions(.{});
118
const is_wasm = target.result.cpu.arch.isWasm();
@@ -15,7 +12,6 @@ pub fn build(b: *Build) !void {
1512
b,
1613
is_wasm,
1714
target,
18-
envMap,
1915
);
2016
const build_option_module = build_options.step(b);
2117

@@ -259,7 +255,7 @@ pub fn build(b: *Build) !void {
259255
const test_step = b.step("test", "Run all the tests");
260256
const run_tests = b.addRunArtifact(tests);
261257
run_tests.cwd = b.path(".");
262-
run_tests.setEnvironmentVariable("BUZZ_PATH", envMap.get("BUZZ_PATH") orelse std.fs.path.dirname(b.exe_dir).?);
258+
run_tests.setEnvironmentVariable("BUZZ_PATH", b.graph.environ_map.get("BUZZ_PATH") orelse std.fs.path.dirname(b.exe_dir).?);
263259
run_tests.step.dependOn(install_step); // wait for libraries to be installed
264260
test_step.dependOn(&run_tests.step);
265261

@@ -270,14 +266,14 @@ pub fn build(b: *Build) !void {
270266

271267
// Link non-zig deps to executables and library
272268
for (ext_deps) |dep| {
273-
c.linkLibrary(dep);
269+
c.root_module.linkLibrary(dep);
274270

275271
if (target.result.os.tag == .windows) {
276-
c.linkSystemLibrary("bcrypt");
272+
c.root_module.linkSystemLibrary("bcrypt", .{});
277273
}
278274

279275
if (build_options.needLibC()) {
280-
c.linkLibC();
276+
c.root_module.link_libc = true;
281277
}
282278
}
283279
}
@@ -286,7 +282,7 @@ pub fn build(b: *Build) !void {
286282
// So that JIT compiled function can reference buzz_api
287283
for ([_]?*std.Build.Step.Compile{ exe, behavior_exe, debugger_exe, lsp_exe, check_exe, fuzz }) |comp| {
288284
if (comp) |c| {
289-
c.linkLibrary(static_lib);
285+
c.root_module.linkLibrary(static_lib);
290286
}
291287
}
292288

@@ -385,17 +381,18 @@ pub fn build(b: *Build) !void {
385381

386382
// No need to link anything when building for wasm since everything is static
387383
if (build_options.needLibC()) {
388-
std_lib.linkLibC();
384+
std_lib.root_module.link_libc = true;
389385
}
390386

391387
for (ext_deps) |dep| {
392-
std_lib.linkLibrary(dep);
388+
std_lib.root_module.linkLibrary(dep);
393389
}
394390

395-
std_lib.linkLibrary(static_lib);
391+
std_lib.root_module.linkLibrary(static_lib);
396392
std_lib.root_module.addImport("build_options", build_option_module);
397393

398394
b.default_step.dependOn(&std_lib.step);
395+
check_exe.step.dependOn(&std_lib.step);
399396
}
400397
}
401398

@@ -429,13 +426,14 @@ pub fn buildPcre2(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin
429426
.target = target,
430427
.optimize = optimize,
431428
.sanitize_c = .off,
429+
.link_libc = true,
432430
},
433431
),
434432
},
435433
);
436-
lib.addIncludePath(b.path("vendors/pcre2/src"));
437-
lib.addIncludePath(copyFiles.getDirectory().path(b, "vendors/pcre2/src"));
438-
lib.addCSourceFiles(
434+
lib.root_module.addIncludePath(b.path("vendors/pcre2/src"));
435+
lib.root_module.addIncludePath(copyFiles.getDirectory().path(b, "vendors/pcre2/src"));
436+
lib.root_module.addCSourceFiles(
439437
.{
440438
.files = &.{
441439
"vendors/pcre2/src/pcre2_auto_possess.c",
@@ -467,14 +465,13 @@ pub fn buildPcre2(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin
467465
.flags = flags,
468466
},
469467
);
470-
lib.addCSourceFile(
468+
lib.root_module.addCSourceFile(
471469
.{
472470
.file = copyFiles.getDirectory().path(b, "vendors/pcre2/src/pcre2_chartables.c"),
473471
.flags = flags,
474472
},
475473
);
476474
lib.step.dependOn(&copyFiles.step);
477-
lib.linkLibC();
478475
b.installArtifact(lib);
479476

480477
return lib;
@@ -490,15 +487,15 @@ pub fn buildMimalloc(b: *Build, target: Build.ResolvedTarget, optimize: std.buil
490487
.{
491488
.target = target,
492489
.optimize = optimize,
490+
.link_libc = true,
493491
},
494492
),
495493
},
496494
);
497495

498-
lib.addIncludePath(b.path("./vendors/mimalloc/include"));
499-
lib.linkLibC();
496+
lib.root_module.addIncludePath(b.path("./vendors/mimalloc/include"));
500497

501-
lib.addCSourceFiles(
498+
lib.root_module.addCSourceFiles(
502499
.{
503500
.files = &.{
504501
"./vendors/mimalloc/src/alloc.c",
@@ -553,13 +550,14 @@ pub fn buildLinenoise(b: *Build, target: Build.ResolvedTarget, optimize: std.bui
553550
.target = target,
554551
.optimize = optimize,
555552
.sanitize_c = .off,
553+
.link_libc = true,
556554
},
557555
),
558556
},
559557
);
560558

561-
lib.addIncludePath(b.path("vendors/linenoise"));
562-
lib.addCSourceFiles(
559+
lib.root_module.addIncludePath(b.path("vendors/linenoise"));
560+
lib.root_module.addCSourceFiles(
563561
.{
564562
.files = &.{
565563
"vendors/linenoise/linenoise.c",
@@ -569,7 +567,6 @@ pub fn buildLinenoise(b: *Build, target: Build.ResolvedTarget, optimize: std.bui
569567
},
570568
},
571569
);
572-
lib.linkLibC();
573570
b.installArtifact(lib);
574571

575572
return lib;
@@ -622,16 +619,15 @@ pub fn buildMir(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.O
622619
.{
623620
.target = target,
624621
.optimize = optimize,
622+
.link_libc = true,
625623
},
626624
),
627625
},
628626
);
629627

630-
lib.addIncludePath(b.path("./vendors/mir"));
631-
632-
lib.linkLibC();
628+
lib.root_module.addIncludePath(b.path("./vendors/mir"));
633629

634-
lib.addCSourceFiles(
630+
lib.root_module.addCSourceFiles(
635631
.{
636632
.files = &.{
637633
"./vendors/mir/mir.c",
@@ -649,8 +645,8 @@ pub fn buildMir(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.O
649645
);
650646

651647
if (target.result.os.tag == .windows) {
652-
lib.linkSystemLibrary("kernel32");
653-
lib.linkSystemLibrary("psapi");
648+
lib.root_module.linkSystemLibrary("kernel32", .{});
649+
lib.root_module.linkSystemLibrary("psapi", .{});
654650
}
655651
b.installArtifact(lib);
656652

@@ -776,13 +772,13 @@ const BuildOptions = struct {
776772
recursive_call_limit: ?u32,
777773
stack_size: usize = 100_000,
778774

779-
pub fn init(b: *Build, is_wasm: bool, target: Build.ResolvedTarget, envMap: std.process.EnvMap) BuildOptions {
775+
pub fn init(b: *Build, is_wasm: bool, target: Build.ResolvedTarget) BuildOptions {
780776
return BuildOptions{
781777
.target = target,
782778
.version = std.SemanticVersion{ .major = 0, .minor = 6, .patch = 0 },
783779
// Current commit sha
784-
.sha = envMap.get("GIT_SHA") orelse
785-
envMap.get("GITHUB_SHA") orelse std.mem.trim(
780+
.sha = b.graph.environ_map.get("GIT_SHA") orelse
781+
b.graph.environ_map.get("GITHUB_SHA") orelse std.mem.trim(
786782
u8,
787783
b.run(
788784
&.{
@@ -865,7 +861,7 @@ const BuildOptions = struct {
865861
.debug_access = b.option(
866862
bool,
867863
"gc_debug_access",
868-
"Track objects access",
864+
"Show access debug information for the garbage collector",
869865
) orelse false,
870866
.on = b.option(
871867
bool,

build.zig.zon

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
.minimum_zig_version = "0.16.0-dev.747+493ad58ff",
66
.dependencies = .{
77
.clap = .{
8-
.url = "git+https://github.com/Hejsil/zig-clap.git#5289e0753cd274d65344bef1c114284c633536ea",
9-
.hash = "clap-0.11.0-oBajB-HnAQDPCKYzwF7rO3qDFwRcD39Q0DALlTSz5H7e",
8+
.url = "git+https://github.com/Hejsil/zig-clap.git#27621cb7207643f914bae7b01902b22a8b5916e7",
9+
.hash = "clap-0.11.0-oBajBxDoAQChQCl4LRM4tyf-VChKLbhYilS806xxzxrQ",
1010
},
1111
.lsp_kit = .{
12-
.url = "git+https://github.com/zigtools/lsp-kit.git#6274eebace9a6a82ce182e24468fef88e0b95f37",
13-
.hash = "lsp_kit-0.1.0-bi_PLzAyCgClDh8_M0U9Q50ysdsQBuRuBTZfwg6rZPd6",
12+
.url = "git+https://github.com/zigtools/lsp-kit.git#98d6bed6e42a0866e1e2ba0867673d9f57ca6687",
13+
.hash = "lsp_kit-0.1.0-bi_PLwozDAApVpvVJHz80NPklig5biWlZCkyxjFbOtiD",
1414
},
1515
.dap_kit = .{
16-
.url = "git+https://github.com/buzz-language/dap-kit.git#0b82af2837f4ded84ae55a41d1591b3a9b75365d",
17-
.hash = "dap_kit-0.0.0-OvEgyGFeAgATdO-Up0sxHeCpfQ6aOs6ekOwJ_nX4yOOX",
16+
.url = "git+https://github.com/buzz-language/dap-kit.git#ecce55528350f747ad303ebbcc00ac355348ffc5",
17+
.hash = "dap_kit-0.0.0-OvEgyIpoAgDtqc7DDa3WLn714zz5VGUJQCQpf_yAoj2i",
1818
},
1919
},
2020
.paths = .{""},

src/Ast.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub const Slice = struct {
4040
const components = self.nodes.items(.components);
4141

4242
// Hold previous node's leaves
43-
var node_queue = std.ArrayList(Node.Index){};
43+
var node_queue = std.ArrayList(Node.Index).empty;
4444
try node_queue.append(allocator, root);
4545
defer node_queue.deinit(allocator);
4646

@@ -647,7 +647,7 @@ pub const Slice = struct {
647647
} else if (right_integer) |ri| {
648648
return Value.fromInteger(ri +% left_integer.?);
649649
} else if (right_list) |rl| {
650-
var new_list = std.ArrayList(Value){};
650+
var new_list = std.ArrayList(Value).empty;
651651
try new_list.appendSlice(gc.allocator, left_list.?.items.items);
652652
try new_list.appendSlice(gc.allocator, rl.items.items);
653653

src/Chunk.zig

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,21 @@ const RegistryContext = struct {
194194
}
195195

196196
pub fn eql(_: RegistryContext, a: Self, b: Self) bool {
197-
return std.mem.eql(u32, a.code.items, b.code.items) and
198-
std.mem.eql(Value, a.constants.items, b.constants.items);
197+
if (!std.mem.eql(u32, a.code.items, b.code.items)) {
198+
return false;
199+
}
200+
201+
if (a.constants.items.len != b.constants.items.len) {
202+
return false;
203+
}
204+
205+
for (a.constants.items, b.constants.items) |ca, cb| {
206+
if (ca.val != cb.val) {
207+
return false;
208+
}
209+
}
210+
211+
return true;
199212
}
200213
};
201214

0 commit comments

Comments
 (0)