diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 94252b7f..00000000 --- a/.gitmodules +++ /dev/null @@ -1,15 +0,0 @@ -[submodule "src/ext/clap"] - path = src/ext/clap - url = https://github.com/Hejsil/zig-clap.git -[submodule "mir"] - path = vendors/mir - url = https://github.com/vnmakarov/mir -[submodule "vendors/pcre2"] - path = vendors/pcre2 - url = https://github.com/PCRE2Project/pcre2 -[submodule "vendors/mimalloc"] - path = vendors/mimalloc - url = https://github.com/microsoft/mimalloc.git -[submodule "vendors/linenoise"] - path = vendors/linenoise - url = https://github.com/antirez/linenoise.git diff --git a/build.zig b/build.zig index 5bae0d32..c3b7ebf3 100644 --- a/build.zig +++ b/build.zig @@ -240,59 +240,26 @@ pub fn build(b: *Build) !void { }, }; - var sys_libs = std.ArrayList([]const u8).init(b.allocator); - defer sys_libs.deinit(); - var includes = std.ArrayList([]const u8).init(b.allocator); - defer includes.deinit(); - var llibs = std.ArrayList([]const u8).init(b.allocator); - defer llibs.deinit(); - - sys_libs.appendSlice( - &[_][]const u8{ - "mir", - }, - ) catch unreachable; - - includes.appendSlice(&[_][]const u8{ - "/usr/local/include", - "/usr/include", - "./vendors/mir", - "./vendors/mimalloc/include", - }) catch unreachable; - - llibs.appendSlice(&[_][]const u8{ - "/usr/local/lib", - "/usr/lib", - "./vendors/mir", - }) catch unreachable; - - const lib_pcre2 = try buildPcre2(b, target, build_mode); - const lib_mimalloc = if (build_options.mimalloc) try buildMimalloc(b, target, build_mode) else null; - const lib_linenoise = try buildLinenoise(b, target, build_mode); - - // If macOS, add homebrew paths - if (builtin.os.tag == .macos) { - const result = std.ChildProcess.run( - .{ - .allocator = b.allocator, - .argv = &[_][]const u8{ "brew", "--prefix" }, - }, - ) catch null; + const clap = b.dependency("clap", .{ .target = target, .optimize = build_mode }); + const mod_clap = clap.module("clap"); - const prefix = if (result) |r| - std.mem.trim(u8, r.stdout, "\n") - else - std.os.getenv("HOMEBREW_PREFIX") orelse "/opt/homebrew"; + const pcre2 = b.dependency("pcre2", .{ .target = target, .optimize = build_mode }); + const lib_pcre2 = pcre2.artifact("pcre2"); - var include = std.ArrayList(u8).init(b.allocator); - include.writer().print("{s}{s}include", .{ prefix, std.fs.path.sep_str }) catch unreachable; + const lib_mimalloc: ?*std.Build.CompileStep = if (build_options.mimalloc) blk: { + const mimalloc = b.dependency("mimalloc", .{ .target = target, .optimize = build_mode }); + break :blk mimalloc.artifact("mimalloc"); + } else null; - var lib = std.ArrayList(u8).init(b.allocator); - lib.writer().print("{s}{s}lib", .{ prefix, std.fs.path.sep_str }) catch unreachable; + const linenoise = b.dependency("linenosie", .{ .target = target, .optimize = build_mode }); + const lib_linenoise = linenoise.artifact("linenoise"); - includes.append(include.items) catch unreachable; - llibs.append(lib.items) catch unreachable; - } + const mir = b.dependency("mir", .{ + .target = target, + // Safe builds are not working because mir doesn't play too well with undefined behavior + .optimize = std.builtin.OptimizeMode.ReleaseFast, + }); + const lib_mir = mir.artifact("mir"); var exe = b.addExecutable(.{ .name = "buzz", @@ -301,6 +268,7 @@ pub fn build(b: *Build) !void { .optimize = build_mode, }); b.installArtifact(exe); + exe.addModule("clap", mod_clap); const run_exe = b.addRunArtifact(exe); run_exe.step.dependOn(install_step); @@ -309,17 +277,6 @@ pub fn build(b: *Build) !void { } b.step("run", "run buzz").dependOn(&run_exe.step); - for (includes.items) |include| { - exe.addIncludePath(.{ .path = include }); - } - for (llibs.items) |lib| { - exe.addLibraryPath(.{ .path = lib }); - } - for (sys_libs.items) |slib| { - // FIXME: if mir is linked as static library (libmir.a), here also need to link libc - // it's better to built it with Zig's build system - exe.linkSystemLibrary(slib); - } if (build_options.needLibC()) { exe.linkLibC(); } @@ -334,64 +291,38 @@ pub fn build(b: *Build) !void { .optimize = build_mode, }); b.installArtifact(lib); - for (includes.items) |include| { - lib.addIncludePath(.{ .path = include }); - } - for (llibs.items) |llib| { - lib.addLibraryPath(.{ .path = llib }); - } - for (sys_libs.items) |slib| { - lib.linkSystemLibrary(slib); - } - if (build_options.needLibC()) { - lib.linkLibC(); - } lib.main_mod_path = .{ .path = "src" }; lib.addOptions("build_options", build_options.step(b)); lib.linkLibrary(lib_pcre2); - if (lib_mimalloc) |mimalloc| { - lib.linkLibrary(mimalloc); + if (lib_mimalloc) |mimalloc_| { + lib.linkLibrary(mimalloc_); if (lib.target.getOsTag() == .windows) { lib.linkSystemLibrary("bcrypt"); } } // So that JIT compiled function can reference buzz_api exe.linkLibrary(lib); + exe.linkLibrary(lib_mir); exe.linkLibrary(lib_linenoise); b.default_step.dependOn(&exe.step); b.default_step.dependOn(&lib.step); - const lib_paths = [_][]const u8{ - "src/lib/buzz_std.zig", - "src/lib/buzz_io.zig", - "src/lib/buzz_gc.zig", - "src/lib/buzz_os.zig", - "src/lib/buzz_fs.zig", - "src/lib/buzz_math.zig", - "src/lib/buzz_debug.zig", - "src/lib/buzz_buffer.zig", - "src/lib/buzz_crypto.zig", - "src/lib/buzz_http.zig", - "src/lib/buzz_ffi.zig", - "src/lib/buzz_serialize.zig", - }; - // Zig only libs - const lib_names = [_][]const u8{ - "std", - "io", - "gc", - "os", - "fs", - "math", - "debug", - "buffer", - "crypto", - "http", - "ffi", - "serialize", + const native_libs = [_]struct { []const u8, []const u8 }{ + .{ "std", "src/lib/buzz_std.zig" }, + .{ "io", "src/lib/buzz_io.zig" }, + .{ "gc", "src/lib/buzz_gc.zig" }, + .{ "os", "src/lib/buzz_os.zig" }, + .{ "fs", "src/lib/buzz_fs.zig" }, + .{ "math", "src/lib/buzz_math.zig" }, + .{ "debug", "src/lib/buzz_debug.zig" }, + .{ "buffer", "src/lib/buzz_buffer.zig" }, + .{ "crypto", "src/lib/buzz_crypto.zig" }, + .{ "http", "src/lib/buzz_http.zig" }, + .{ "ffi", "src/lib/buzz_ffi.zig" }, + .{ "serialize", "src/lib/buzz_serialize.zig" }, }; const all_lib_names = [_][]const u8{ "std", @@ -407,48 +338,40 @@ pub fn build(b: *Build) !void { "errors", "ffi", "serialize", + "test", }; // TODO: this section is slow. Modifying Buzz parser shouldn't trigger recompile of all buzz dynamic libraries - var libs = [_]*std.build.LibExeObjStep{undefined} ** lib_names.len; - for (lib_paths, 0..) |lib_path, index| { - var std_lib = b.addSharedLibrary(.{ - .name = lib_names[index], - .root_source_file = Build.FileSource.relative(lib_path), + var libs = [_]*std.build.LibExeObjStep{undefined} ** native_libs.len; + for (&libs, native_libs) |*std_lib, native_lib| { + std_lib.* = b.addSharedLibrary(.{ + .name = native_lib[0], + .root_source_file = Build.FileSource.relative(native_lib[1]), .target = target, .optimize = build_mode, }); - const artifact = b.addInstallArtifact(std_lib, .{}); + const artifact = b.addInstallArtifact(std_lib.*, .{}); install_step.dependOn(&artifact.step); artifact.dest_dir = .{ .custom = "lib/buzz" }; - for (includes.items) |include| { - std_lib.addIncludePath(.{ .path = include }); - } - for (llibs.items) |llib| { - std_lib.addLibraryPath(.{ .path = llib }); - } - for (sys_libs.items) |slib| { - std_lib.linkSystemLibrary(slib); - } if (build_options.needLibC()) { - std_lib.linkLibC(); + std_lib.*.linkLibC(); } - std_lib.main_mod_path = .{ .path = "src" }; - std_lib.linkLibrary(lib_pcre2); - if (lib_mimalloc) |mimalloc| { - std_lib.linkLibrary(mimalloc); - if (std_lib.target.getOsTag() == .windows) { - std_lib.linkSystemLibrary("bcrypt"); + std_lib.*.main_mod_path = .{ .path = "src" }; + std_lib.*.linkLibrary(lib_pcre2); + if (lib_mimalloc) |mimalloc_| { + std_lib.*.linkLibrary(mimalloc_); + if (std_lib.*.target.getOsTag() == .windows) { + std_lib.*.linkSystemLibrary("bcrypt"); } } - std_lib.linkLibrary(lib); - std_lib.addOptions("build_options", build_options.step(b)); + std_lib.*.linkLibrary(lib); + std_lib.*.addOptions("build_options", build_options.step(b)); // Adds `$BUZZ_PATH/lib` and `/usr/local/lib/buzz` as search path for other shared lib referenced by this one (libbuzz.dylib most of the time) - std_lib.addRPath( + std_lib.*.addRPath( .{ .path = b.fmt( "{s}" ++ std.fs.path.sep_str ++ "lib/buzz", @@ -456,11 +379,9 @@ pub fn build(b: *Build) !void { ), }, ); - std_lib.addRPath(.{ .path = "/usr/local/lib/buzz" }); - - b.default_step.dependOn(&std_lib.step); + std_lib.*.addRPath(.{ .path = "/usr/local/lib/buzz" }); - libs[index] = std_lib; + b.default_step.dependOn(&std_lib.*.step); } for (all_lib_names) |name| { @@ -476,21 +397,12 @@ pub fn build(b: *Build) !void { .target = target, .optimize = build_mode, }); - for (includes.items) |include| { - tests.addIncludePath(.{ .path = include }); - } - for (llibs.items) |llib| { - tests.addLibraryPath(.{ .path = llib }); - } - for (sys_libs.items) |slib| { - tests.linkSystemLibrary(slib); - } if (build_options.needLibC()) { tests.linkLibC(); } tests.linkLibrary(lib_pcre2); - if (lib_mimalloc) |mimalloc| { - tests.linkLibrary(mimalloc); + if (lib_mimalloc) |mimalloc_| { + tests.linkLibrary(mimalloc_); if (tests.target.getOsTag() == .windows) { tests.linkSystemLibrary("bcrypt"); } @@ -504,166 +416,3 @@ pub fn build(b: *Build) !void { run_tests.step.dependOn(install_step); // wait for libraries to be installed test_step.dependOn(&run_tests.step); } - -pub fn buildPcre2(b: *Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode) !*Build.Step.Compile { - const copyFiles = b.addWriteFiles(); - copyFiles.addCopyFileToSource( - .{ .path = "vendors/pcre2/src/config.h.generic" }, - "vendors/pcre2/src/config.h", - ); - copyFiles.addCopyFileToSource( - .{ .path = "vendors/pcre2/src/pcre2.h.generic" }, - "vendors/pcre2/src/pcre2.h", - ); - copyFiles.addCopyFileToSource( - .{ .path = "vendors/pcre2/src/pcre2_chartables.c.dist" }, - "vendors/pcre2/src/pcre2_chartables.c", - ); - - const lib = b.addStaticLibrary(.{ - .name = "pcre2", - .target = target, - .optimize = optimize, - }); - lib.addIncludePath(.{ .path = "src" }); - lib.addCSourceFiles( - .{ - .files = &.{ - "vendors/pcre2/src/pcre2_auto_possess.c", - "vendors/pcre2/src/pcre2_compile.c", - "vendors/pcre2/src/pcre2_config.c", - "vendors/pcre2/src/pcre2_context.c", - "vendors/pcre2/src/pcre2_convert.c", - "vendors/pcre2/src/pcre2_dfa_match.c", - "vendors/pcre2/src/pcre2_error.c", - "vendors/pcre2/src/pcre2_extuni.c", - "vendors/pcre2/src/pcre2_find_bracket.c", - "vendors/pcre2/src/pcre2_maketables.c", - "vendors/pcre2/src/pcre2_match.c", - "vendors/pcre2/src/pcre2_match_data.c", - "vendors/pcre2/src/pcre2_newline.c", - "vendors/pcre2/src/pcre2_ord2utf.c", - "vendors/pcre2/src/pcre2_pattern_info.c", - "vendors/pcre2/src/pcre2_script_run.c", - "vendors/pcre2/src/pcre2_serialize.c", - "vendors/pcre2/src/pcre2_string_utils.c", - "vendors/pcre2/src/pcre2_study.c", - "vendors/pcre2/src/pcre2_substitute.c", - "vendors/pcre2/src/pcre2_substring.c", - "vendors/pcre2/src/pcre2_tables.c", - "vendors/pcre2/src/pcre2_ucd.c", - "vendors/pcre2/src/pcre2_valid_utf.c", - "vendors/pcre2/src/pcre2_xclass.c", - "vendors/pcre2/src/pcre2_chartables.c", - }, - .flags = &.{ - "-std=c99", - "-DHAVE_CONFIG_H", - "-DPCRE2_CODE_UNIT_WIDTH=8", - "-DPCRE2_STATIC", - }, - }, - ); - lib.step.dependOn(©Files.step); - lib.linkLibC(); - b.installArtifact(lib); - - return lib; -} - -pub fn buildMimalloc(b: *Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode) !*Build.Step.Compile { - const lib = b.addStaticLibrary( - .{ - .name = "mimalloc", - .target = target, - .optimize = optimize, - }, - ); - - lib.addIncludePath(.{ .path = "./vendors/mimalloc/include" }); - lib.linkLibC(); - - if (lib.target.getOsTag() == .macos) { - var macOS_sdk_path = std.ArrayList(u8).init(b.allocator); - try macOS_sdk_path.writer().print( - "{s}/usr/include", - .{ - (std.ChildProcess.run(.{ - .allocator = b.allocator, - .argv = &.{ - "xcrun", - "--show-sdk-path", - }, - .cwd = b.pathFromRoot("."), - .expand_arg0 = .expand, - }) catch { - std.debug.print("Warning: failed to get MacOSX sdk path", .{}); - unreachable; - }).stdout, - }, - ); - - lib.addSystemIncludePath(.{ .path = macOS_sdk_path.items }); - // Github macos-12 runner (https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md). - lib.addSystemIncludePath(.{ .path = "/Applications/Xcode_14.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include" }); - lib.addSystemIncludePath(.{ .path = "/Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk/usr/include" }); - lib.addSystemIncludePath(.{ .path = "/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include" }); - lib.addSystemIncludePath(.{ .path = "/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include" }); - lib.addSystemIncludePath(.{ .path = "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include" }); - } - - lib.addCSourceFiles( - .{ - .files = &.{ - "./vendors/mimalloc/src/alloc-aligned.c", - "./vendors/mimalloc/src/alloc.c", - "./vendors/mimalloc/src/arena.c", - "./vendors/mimalloc/src/bitmap.c", - "./vendors/mimalloc/src/heap.c", - "./vendors/mimalloc/src/init.c", - "./vendors/mimalloc/src/options.c", - "./vendors/mimalloc/src/os.c", - "./vendors/mimalloc/src/page.c", - "./vendors/mimalloc/src/random.c", - "./vendors/mimalloc/src/segment-map.c", - "./vendors/mimalloc/src/segment.c", - "./vendors/mimalloc/src/stats.c", - "./vendors/mimalloc/src/prim/prim.c", - }, - .flags = if (lib.optimize != .Debug) - &.{ - "-DNDEBUG=1", - "-DMI_SECURE=0", - "-DMI_STAT=0", - } - else - &.{}, - }, - ); - - return lib; -} - -pub fn buildLinenoise(b: *Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode) !*Build.Step.Compile { - const lib = b.addStaticLibrary(.{ - .name = "linenoise", - .target = target, - .optimize = optimize, - }); - - lib.addIncludePath(.{ .path = "vendors/linenoise" }); - lib.addCSourceFiles( - .{ - .files = &.{ - "vendors/linenoise/linenoise.c", - }, - .flags = &.{ - "-Os", - }, - }, - ); - lib.linkLibC(); - b.installArtifact(lib); - - return lib; -} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 00000000..42ac8078 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,33 @@ +.{ + .name = "buzz", + .version = "0.0.1", + .paths = .{ + "build.zig", + "build.zig.zon", + "LICENSE", + "CHANGELOG.md", + "README.md", + "deps", + "src", + "tools", + "tests", + }, + .dependencies = .{ + .clap = .{ + .url = "https://github.com/Hejsil/zig-clap/archive/c394594d218c3c936547e590b461e69e6e0b20c4.tar.gz", + .hash = "122066d86920926a4a674adaaa10f158dc4961c2a47e588e605765455d74ca72c2ad", + }, + .pcre2 = .{ + .path = "./vendors/pcre2", + }, + .linenosie = .{ + .path = "./vendors/linenoise", + }, + .mimalloc= .{ + .path = "./vendors/mimalloc", + }, + .mir = .{ + .path = "./vendors/mir", + }, + }, +} diff --git a/src/builtin/list.zig b/src/builtin/list.zig index 952978ce..cd5bf601 100644 --- a/src/builtin/list.zig +++ b/src/builtin/list.zig @@ -118,7 +118,7 @@ fn lessThan(context: SortContext, lhs: Value, rhs: Value) bool { pub fn sort(ctx: *NativeCtx) c_int { var self = ObjList.cast(ctx.vm.peek(1).obj()).?; // fun compare(T lhs, T rhs) > bool - var sort_closure = ObjClosure.cast(ctx.vm.peek(0).obj()).?; + const sort_closure = ObjClosure.cast(ctx.vm.peek(0).obj()).?; std.sort.insertion( Value, @@ -170,15 +170,15 @@ pub fn clone(ctx: *NativeCtx) c_int { } pub fn join(ctx: *NativeCtx) c_int { - var self: *ObjList = ObjList.cast(ctx.vm.peek(1).obj()).?; - var separator: *ObjString = ObjString.cast(ctx.vm.peek(0).obj()).?; + const self: *ObjList = ObjList.cast(ctx.vm.peek(1).obj()).?; + const separator: *ObjString = ObjString.cast(ctx.vm.peek(0).obj()).?; var result = std.ArrayList(u8).init(ctx.vm.gc.allocator); var writer = result.writer(); defer result.deinit(); for (self.items.items, 0..) |item, i| { valueToString(&writer, item) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("could not stringify item") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("could not stringify item") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; @@ -186,7 +186,7 @@ pub fn join(ctx: *NativeCtx) c_int { if (i + 1 < self.items.items.len) { writer.writeAll(separator.string) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("could not join list") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("could not join list") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; @@ -195,7 +195,7 @@ pub fn join(ctx: *NativeCtx) c_int { } ctx.vm.push((ctx.vm.gc.copyString(result.items) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("could not join list") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("could not join list") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; @@ -210,14 +210,14 @@ pub fn sub(ctx: *NativeCtx) c_int { const upto = ctx.vm.peek(0).integerOrNull(); if (start < 0 or start >= self.items.items.len) { - var err: ?*ObjString = ctx.vm.gc.copyString("`start` is out of bound") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("`start` is out of bound") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; } if (upto != null and upto.? < 0) { - var err: ?*ObjString = ctx.vm.gc.copyString("`len` must greater or equal to 0") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("`len` must greater or equal to 0") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; @@ -227,19 +227,19 @@ pub fn sub(ctx: *NativeCtx) c_int { @as(usize, @intCast(start + upto.?)) else self.items.items.len; - var substr: []Value = self.items.items[@as(usize, @intCast(start))..limit]; + const substr: []Value = self.items.items[@as(usize, @intCast(start))..limit]; var list = ctx.vm.gc.allocateObject(ObjList, ObjList{ .type_def = self.type_def, .methods = self.methods.clone() catch { - var err: ?*ObjString = ctx.vm.gc.copyString("Could not get sub list") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("Could not get sub list") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; }, .items = std.ArrayList(Value).init(ctx.vm.gc.allocator), }) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("Could not get sub list") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("Could not get sub list") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; @@ -248,7 +248,7 @@ pub fn sub(ctx: *NativeCtx) c_int { ctx.vm.push(list.toValue()); list.items.appendSlice(substr) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("Could not get sub list") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("Could not get sub list") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; diff --git a/src/builtin/map.zig b/src/builtin/map.zig index 6d3fb27a..62e1de8f 100644 --- a/src/builtin/map.zig +++ b/src/builtin/map.zig @@ -292,19 +292,19 @@ pub fn keys(ctx: *NativeCtx) c_int { var result = std.ArrayList(Value).init(ctx.vm.gc.allocator); for (map_keys) |key| { result.append(key) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("could not get map keys") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("could not get map keys") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.False); return -1; }; } - var list_def: ObjList.ListDef = ObjList.ListDef.init( + const list_def: ObjList.ListDef = ObjList.ListDef.init( ctx.vm.gc.allocator, self.type_def.resolved_type.?.Map.key_type, ); - var list_def_union: ObjTypeDef.TypeUnion = .{ + const list_def_union: ObjTypeDef.TypeUnion = .{ .List = list_def, }; @@ -313,7 +313,7 @@ pub fn keys(ctx: *NativeCtx) c_int { .optional = false, .resolved_type = list_def_union, }) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("could not get map keys") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("could not get map keys") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.False); return -1; @@ -326,7 +326,7 @@ pub fn keys(ctx: *NativeCtx) c_int { ObjList, ObjList.init(ctx.vm.gc.allocator, list_def_type), ) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("could not get map keys") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("could not get map keys") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.False); return -1; @@ -347,27 +347,27 @@ pub fn values(ctx: *NativeCtx) c_int { const map_values: []Value = self.map.values(); var result = std.ArrayList(Value).init(ctx.vm.gc.allocator); result.appendSlice(map_values) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("could not get map values") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("could not get map values") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.False); return -1; }; - var list_def: ObjList.ListDef = ObjList.ListDef.init( + const list_def: ObjList.ListDef = ObjList.ListDef.init( ctx.vm.gc.allocator, self.type_def.resolved_type.?.Map.value_type, ); - var list_def_union: ObjTypeDef.TypeUnion = .{ + const list_def_union: ObjTypeDef.TypeUnion = .{ .List = list_def, }; - var list_def_type: *ObjTypeDef = ctx.vm.gc.type_registry.getTypeDef(ObjTypeDef{ + const list_def_type: *ObjTypeDef = ctx.vm.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .List, .optional = false, .resolved_type = list_def_union, }) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("could not get map values") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("could not get map values") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.False); return -1; @@ -377,7 +377,7 @@ pub fn values(ctx: *NativeCtx) c_int { ObjList, ObjList.init(ctx.vm.gc.allocator, list_def_type), ) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("could not get map values") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("could not get map values") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.False); return -1; diff --git a/src/builtin/pattern.zig b/src/builtin/pattern.zig index dd439efd..a9d81479 100644 --- a/src/builtin/pattern.zig +++ b/src/builtin/pattern.zig @@ -78,7 +78,7 @@ fn rawMatchAll(self: *ObjPattern, vm: *VM, subject: *ObjString) !?*ObjList { var offset: usize = 0; while (true) { if (try rawMatch(self, vm, subject, &offset)) |matches| { - var was_null = results == null; + const was_null = results == null; results = results orelse try vm.gc.allocateObject( ObjList, ObjList.init(vm.gc.allocator, matches.type_def), diff --git a/src/builtin/str.zig b/src/builtin/str.zig index 09426600..17948012 100644 --- a/src/builtin/str.zig +++ b/src/builtin/str.zig @@ -53,16 +53,16 @@ pub fn utf8Valid(ctx: *NativeCtx) c_int { pub fn utf8Codepoints(ctx: *NativeCtx) c_int { const str: *ObjString = ObjString.cast(ctx.vm.peek(0).obj()).?; - var list_def: ObjList.ListDef = ObjList.ListDef.init( + const list_def: ObjList.ListDef = ObjList.ListDef.init( ctx.vm.gc.allocator, ctx.vm.gc.type_registry.getTypeDef(.{ .def_type = .String }) catch @panic("Could not create list"), ); - var list_def_union: ObjTypeDef.TypeUnion = .{ + const list_def_union: ObjTypeDef.TypeUnion = .{ .List = list_def, }; - var list_def_type: *ObjTypeDef = ctx.vm.gc.type_registry.getTypeDef(ObjTypeDef{ + const list_def_type: *ObjTypeDef = ctx.vm.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .List, .optional = false, .resolved_type = list_def_union, @@ -107,7 +107,7 @@ pub fn repeat(ctx: *NativeCtx) c_int { return 1; } - var err: ?*ObjString = ctx.vm.gc.copyString("`n` should be an integer") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("`n` should be an integer") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; @@ -119,7 +119,7 @@ pub fn byte(ctx: *NativeCtx) c_int { const index_i = index.integer(); if (index_i < 0 or index_i >= self.string.len) { - var err: ?*ObjString = ctx.vm.gc.copyString("Out of bound access to str") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("Out of bound access to str") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; @@ -185,21 +185,21 @@ pub fn sub(ctx: *NativeCtx) c_int { const upto = ctx.vm.peek(0).integerOrNull(); if (start < 0 or start >= self.string.len) { - var err: ?*ObjString = ctx.vm.gc.copyString("`start` is out of bound") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("`start` is out of bound") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; } if (upto != null and upto.? < 0) { - var err: ?*ObjString = ctx.vm.gc.copyString("`len` must greater or equal to 0") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("`len` must greater or equal to 0") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; } const limit: usize = if (upto != null and @as(usize, @intCast(start + upto.?)) < self.string.len) @intCast(start + upto.?) else self.string.len; - var substr: []const u8 = self.string[@as(usize, @intCast(start))..limit]; + const substr: []const u8 = self.string[@as(usize, @intCast(start))..limit]; ctx.vm.push( (ctx.vm.gc.copyString(substr) catch @panic("Could not create string")).toValue(), @@ -213,19 +213,19 @@ pub fn split(ctx: *NativeCtx) c_int { const separator: *ObjString = ObjString.cast(ctx.vm.peek(0).obj()).?; // std.mem.split(u8, self.string, separator.string); - var list_def: ObjList.ListDef = ObjList.ListDef.init( + const list_def: ObjList.ListDef = ObjList.ListDef.init( ctx.vm.gc.allocator, ctx.vm.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .String, }) catch @panic("Could not create string"), ); - var list_def_union: ObjTypeDef.TypeUnion = .{ + const list_def_union: ObjTypeDef.TypeUnion = .{ .List = list_def, }; // TODO: reuse already allocated similar typedef - var list_def_type: *ObjTypeDef = ctx.vm.gc.type_registry.getTypeDef(ObjTypeDef{ + const list_def_type: *ObjTypeDef = ctx.vm.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .List, .optional = false, .resolved_type = list_def_union, @@ -260,7 +260,7 @@ pub fn split(ctx: *NativeCtx) c_int { pub fn encodeBase64(ctx: *NativeCtx) c_int { const str = ObjString.cast(ctx.vm.peek(0).obj()).?; - var encoded = ctx.vm.gc.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(str.string.len)) catch @panic("Could not create string"); + const encoded = ctx.vm.gc.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(str.string.len)) catch @panic("Could not create string"); defer ctx.vm.gc.allocator.free(encoded); var new_string = ctx.vm.gc.copyString( @@ -276,16 +276,16 @@ pub fn decodeBase64(ctx: *NativeCtx) c_int { const str = ObjString.cast(ctx.vm.peek(0).obj()).?; const size = std.base64.standard.Decoder.calcSizeForSlice(str.string) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("Could not decode string") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("Could not decode string") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; }; - var decoded = ctx.vm.gc.allocator.alloc(u8, size) catch @panic("Could not create string"); + const decoded = ctx.vm.gc.allocator.alloc(u8, size) catch @panic("Could not create string"); defer ctx.vm.gc.allocator.free(decoded); std.base64.standard.Decoder.decode(decoded, str.string) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("Could not decode string") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("Could not decode string") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; @@ -388,7 +388,7 @@ pub fn bin(ctx: *NativeCtx) c_int { for (0..result.len) |i| { result[i] = std.fmt.parseInt(u8, str.string[(i * 2)..(i * 2 + 2)], 16) catch { - var err: ?*ObjString = ctx.vm.gc.copyString("String does not contain valid hex values") catch null; + const err: ?*ObjString = ctx.vm.gc.copyString("String does not contain valid hex values") catch null; ctx.vm.push(if (err) |uerr| uerr.toValue() else Value.fromBoolean(false)); return -1; diff --git a/src/buzz_api.zig b/src/buzz_api.zig index a10b0411..727411f2 100644 --- a/src/buzz_api.zig +++ b/src/buzz_api.zig @@ -496,16 +496,16 @@ export fn bz_collect(self: *VM) bool { } export fn bz_newList(vm: *VM, of_type: Value) Value { - var list_def: ObjList.ListDef = ObjList.ListDef.init( + const list_def: ObjList.ListDef = ObjList.ListDef.init( vm.gc.allocator, ObjTypeDef.cast(of_type.obj()).?, ); - var list_def_union: ObjTypeDef.TypeUnion = .{ + const list_def_union: ObjTypeDef.TypeUnion = .{ .List = list_def, }; - var list_def_type: *ObjTypeDef = vm.gc.type_registry.getTypeDef(ObjTypeDef{ + const list_def_type: *ObjTypeDef = vm.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .List, .optional = false, .resolved_type = list_def_union, @@ -594,7 +594,7 @@ export fn bz_userDataToValue(userdata: *ObjUserData) Value { } export fn bz_newVM(self: *VM) ?*VM { - var vm = self.gc.allocator.create(VM) catch { + const vm = self.gc.allocator.create(VM) catch { return null; }; var gc = self.gc.allocator.create(GarbageCollector) catch { @@ -661,7 +661,7 @@ export fn bz_interpret(self: *VM, function: *ObjFunction) bool { } fn calleeIsCompiled(value: Value) bool { - var obj: *Obj = value.obj(); + const obj: *Obj = value.obj(); return switch (obj.obj_type) { .Bound => bound: { const bound = ObjBoundMethod.cast(obj).?; @@ -1054,7 +1054,7 @@ export fn bz_valueIs(self: Value, type_def: Value) Value { export fn bz_setTryCtx(self: *VM) *TryCtx { // It would be better that this was in an ALLOCA, but with it memory keeps slowing leaking // Maybe the jmp throws off the stack? - var try_ctx = self.gc.allocator.create(TryCtx) catch @panic("Could not create try context"); + const try_ctx = self.gc.allocator.create(TryCtx) catch @panic("Could not create try context"); try_ctx.* = .{ .previous = self.current_fiber.try_context, .env = undefined, @@ -1554,7 +1554,7 @@ export fn bz_writeZigValueToBuffer( @as(u8, 1) else @as(u8, 0)); - var bytes = std.mem.asBytes(&unwrapped); + const bytes = std.mem.asBytes(&unwrapped); buffer.replaceRange(at, bytes.len, bytes) catch @panic("Out of memory"); }, @@ -1563,13 +1563,13 @@ export fn bz_writeZigValueToBuffer( switch (ztype.Int.bits) { 64 => { const unwrapped = ObjUserData.cast(value.obj()).?.userdata; - var bytes = std.mem.asBytes(&unwrapped); + const bytes = std.mem.asBytes(&unwrapped); buffer.replaceRange(at, bytes.len, bytes) catch @panic("Out of memory"); }, 1...32 => { const unwrapped = value.integer(); - var bytes = std.mem.asBytes(&unwrapped)[0..(ztype.Int.bits / 8)]; + const bytes = std.mem.asBytes(&unwrapped)[0..(ztype.Int.bits / 8)]; buffer.replaceRange(at, bytes.len, bytes) catch @panic("Out of memory"); }, @@ -1579,13 +1579,13 @@ export fn bz_writeZigValueToBuffer( .Float => switch (ztype.Float.bits) { 32 => { const unwrapped = @as(f32, @floatCast(value.float())); - var bytes = std.mem.asBytes(&unwrapped); + const bytes = std.mem.asBytes(&unwrapped); buffer.replaceRange(at, bytes.len, bytes) catch @panic("Out of memory"); }, 64 => { const unwrapped = value.float(); - var bytes = std.mem.asBytes(&unwrapped); + const bytes = std.mem.asBytes(&unwrapped); buffer.replaceRange(at, bytes.len, bytes) catch @panic("Out of memory"); }, @@ -1607,7 +1607,7 @@ export fn bz_writeZigValueToBuffer( .Opaque, => { const unwrapped = ObjUserData.cast(value.obj()).?.userdata; - var bytes = std.mem.asBytes(&unwrapped); + const bytes = std.mem.asBytes(&unwrapped); buffer.replaceRange(at, bytes.len, bytes) catch @panic("Out of memory"); }, diff --git a/src/codegen.zig b/src/codegen.zig index 2f1d3bd7..8688d04a 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -233,7 +233,7 @@ pub const CodeGen = struct { } pub fn makeConstant(self: *Self, value: Value) !u24 { - var constant: u24 = try self.current.?.function.?.chunk.addConstant(null, value); + const constant: u24 = try self.current.?.function.?.chunk.addConstant(null, value); if (constant > Chunk.max_constants) { self.reportError("Too many constants in one chunk."); return 0; diff --git a/src/disassembler.zig b/src/disassembler.zig index b7bec3f3..8c23433d 100644 --- a/src/disassembler.zig +++ b/src/disassembler.zig @@ -311,7 +311,7 @@ pub fn disassembleInstruction(chunk: *Chunk, offset: usize) !usize { => triInstruction(instruction, chunk, offset), .OP_CLOSURE => closure: { - var constant: u24 = arg; + const constant: u24 = arg; var off_offset: usize = offset + 1; var value_str = try _value.valueToStringAlloc(global_allocator, chunk.constants.items[constant]); @@ -326,12 +326,12 @@ pub fn disassembleInstruction(chunk: *Chunk, offset: usize) !usize { }, ); - var function: *ObjFunction = ObjFunction.cast(chunk.constants.items[constant].obj()).?; + const function: *ObjFunction = ObjFunction.cast(chunk.constants.items[constant].obj()).?; var i: u8 = 0; while (i < function.upvalue_count) : (i += 1) { - var is_local: bool = chunk.code.items[off_offset] == 1; + const is_local: bool = chunk.code.items[off_offset] == 1; off_offset += 1; - var index: u8 = @intCast(chunk.code.items[off_offset]); + const index: u8 = @intCast(chunk.code.items[off_offset]); off_offset += 1; print( "\n{:0>3} | \t{s} {}\n", diff --git a/src/ext/clap b/src/ext/clap deleted file mode 160000 index f49b9470..00000000 --- a/src/ext/clap +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f49b94700e0761b7514abdca0e4f0e7f3f938a93 diff --git a/src/ffi.zig b/src/ffi.zig index 87ef72a4..c396169c 100644 --- a/src/ffi.zig +++ b/src/ffi.zig @@ -219,7 +219,7 @@ pub fn parseTypeExpr(self: *Self, ztype: []const u8) !?*Zdef { full.writer().print("const zig_type: {s};", .{ztype}) catch @panic("Out of memory"); - var zdef = try self.parse( + const zdef = try self.parse( null, t.Token.identifier(full.items), true, @@ -360,7 +360,7 @@ fn getZdef(self: *Self, decl_index: Ast.Node.Index) !?*Zdef { const zdef = try self.getZdef(decl.data.lhs); if (zdef) |uzdef| { - var opt_zdef = try self.gc.allocator.create(Zdef); + const opt_zdef = try self.gc.allocator.create(Zdef); opt_zdef.* = Zdef{ .zig_type = .{ .Optional = .{ @@ -701,7 +701,7 @@ fn ptrType(self: *Self, tag: Ast.Node.Tag, decl_index: Ast.Node.Index) anyerror! // Is it a null terminated string? // zig fmt: off - var zdef = try self.gc.allocator.create(Zdef); + const zdef = try self.gc.allocator.create(Zdef); zdef.* = if (ptr_type.const_token != null and child_type.zig_type == .Int and child_type.zig_type.Int.bits == 8 @@ -847,12 +847,12 @@ fn fnProto(self: *Self, tag: Ast.Node.Tag, decl_index: Ast.Node.Index) anyerror! parameters_zig_types.shrinkAndFree(parameters_zig_types.items.len); zig_fn_type.params = parameters_zig_types.items; - var type_def = o.ObjTypeDef{ + const type_def = o.ObjTypeDef{ .def_type = .Function, .resolved_type = .{ .Function = function_def }, }; - var zdef = try self.gc.allocator.create(Zdef); + const zdef = try self.gc.allocator.create(Zdef); zdef.* = .{ .zig_type = ZigType{ .Fn = zig_fn_type }, .type_def = try self.gc.type_registry.getTypeDef(type_def), diff --git a/src/lib/buzz_buffer.zig b/src/lib/buzz_buffer.zig index 4618e7d9..9bdf78af 100644 --- a/src/lib/buzz_buffer.zig +++ b/src/lib/buzz_buffer.zig @@ -1,11 +1,12 @@ const std = @import("std"); +const builtin = @import("builtin"); const api = @import("buzz_api.zig"); const native_endian = @import("builtin").target.cpu.arch.endian(); export fn BufferNew(ctx: *api.NativeCtx) c_int { const capacity = ctx.vm.bz_peek(0).integer(); - var buffer = api.VM.allocator.create(Buffer) catch { + const buffer = api.VM.allocator.create(Buffer) catch { @panic("Out of memory"); }; buffer.* = Buffer.init(api.VM.allocator, @intCast(capacity)) catch { @@ -22,7 +23,7 @@ export fn BufferNew(ctx: *api.NativeCtx) c_int { } export fn BufferDeinit(ctx: *api.NativeCtx) c_int { - var userdata = ctx.vm.bz_peek(0).bz_valueToUserData(); + const userdata = ctx.vm.bz_peek(0).bz_valueToUserData(); var buffer = Buffer.fromUserData(userdata); @@ -120,7 +121,7 @@ const Buffer = struct { var buffer_stream = std.io.fixedBufferStream(self.buffer.items[self.cursor..self.buffer.items.len]); var reader = buffer_stream.reader(); - const number = try reader.readIntNative(i32); + const number = try reader.readInt(i32, native_endian); self.cursor += @sizeOf(i32); @@ -135,7 +136,7 @@ const Buffer = struct { var writer = self.buffer.writer(); // Flag so we know it an integer - try writer.writeIntNative(i32, integer); + try writer.writeInt(i32, integer, native_endian); } pub fn readUserData(self: *Self, vm: *api.VM) !?*api.ObjUserData { @@ -146,7 +147,7 @@ const Buffer = struct { var buffer_stream = std.io.fixedBufferStream(self.buffer.items[self.cursor..self.buffer.items.len]); var reader = buffer_stream.reader(); - const number = try reader.readIntNative(u64); + const number = try reader.readInt(u64, native_endian); self.cursor += @sizeOf(u64); @@ -161,10 +162,7 @@ const Buffer = struct { var writer = self.buffer.writer(); // Flag so we know it an integer - try writer.writeIntNative( - u64, - userdata.bz_getUserDataPtr(), - ); + try writer.writeInt(u64, userdata.bz_getUserDataPtr(), native_endian); } pub fn readFloat(self: *Self) !?f64 { @@ -175,7 +173,7 @@ const Buffer = struct { var buffer_stream = std.io.fixedBufferStream(self.buffer.items[self.cursor..self.buffer.items.len]); var reader = buffer_stream.reader(); - const number = try reader.readIntNative(u64); + const number = try reader.readInt(u64, native_endian); self.cursor += @sizeOf(f64); @@ -190,7 +188,7 @@ const Buffer = struct { var writer = self.buffer.writer(); // Flag so we know it an float - try writer.writeIntNative(u64, @as(u64, @bitCast(float))); + try writer.writeInt(u64, @as(u64, @bitCast(float)), native_endian); } pub fn empty(self: *Self) void { @@ -481,7 +479,7 @@ inline fn rawWriteZ( return false; } - var len = api.VM.bz_zigValueSize(zig_type.?); + const len = api.VM.bz_zigValueSize(zig_type.?); buffer.buffer.ensureTotalCapacityPrecise(buffer.buffer.items.len + len) catch @panic("Out of memory"); buffer.buffer.expandToCapacity(); diff --git a/src/lib/buzz_fs.zig b/src/lib/buzz_fs.zig index 037825e3..2dab51d8 100644 --- a/src/lib/buzz_fs.zig +++ b/src/lib/buzz_fs.zig @@ -275,17 +275,17 @@ export fn list(ctx: *api.NativeCtx) c_int { const filename_slice = filename.?[0..len]; const dir = if (std.fs.path.isAbsolute(filename_slice)) - std.fs.openIterableDirAbsolute(filename_slice, .{}) catch |err| { + std.fs.openDirAbsolute(filename_slice, .{ .iterate = true }) catch |err| { handleOpenDirAbsoluteError(ctx, err); return -1; } else - std.fs.cwd().openIterableDir(filename_slice, .{}) catch |err| { + std.fs.cwd().openDir(filename_slice, .{ .iterate = true }) catch |err| { handleOpenDirError(ctx, err); return -1; }; - var file_list = api.ObjList.bz_newList( + const file_list = api.ObjList.bz_newList( ctx.vm, api.ObjTypeDef.bz_stringType(ctx.vm), ); diff --git a/src/lib/buzz_io.zig b/src/lib/buzz_io.zig index 2852625f..da562e57 100644 --- a/src/lib/buzz_io.zig +++ b/src/lib/buzz_io.zig @@ -66,7 +66,7 @@ export fn FileOpen(ctx: *api.NativeCtx) c_int { const filename = ctx.vm.bz_peek(1).bz_valueToString(&len); const filename_slice = filename.?[0..len]; - var file: std.fs.File = if (std.fs.path.isAbsolute(filename_slice)) + const file: std.fs.File = if (std.fs.path.isAbsolute(filename_slice)) switch (mode) { 0 => std.fs.openFileAbsolute(filename_slice, .{ .mode = .read_only }) catch |err| { handleFileOpenError(ctx, err); @@ -124,6 +124,7 @@ fn handleFileReadWriteError(ctx: *api.NativeCtx, err: anytype) void { error.ConnectionTimedOut, error.NotOpenForReading, error.NetNameDeleted, + error.SocketNotConnected, => ctx.vm.pushErrorEnum("errors.ReadWriteError", @errorName(err)), error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null), @@ -177,6 +178,7 @@ fn handleFileReadLineError(ctx: *api.NativeCtx, err: anytype) void { error.NotOpenForReading, error.OperationAborted, error.StreamTooLong, + error.SocketNotConnected, => ctx.vm.pushErrorEnum("errors.ReadWriteError", @errorName(err)), error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null), @@ -192,7 +194,7 @@ export fn FileReadLine(ctx: *api.NativeCtx) c_int { const file: std.fs.File = std.fs.File{ .handle = handle }; const reader = file.reader(); - var buffer = reader.readUntilDelimiterOrEofAlloc( + const buffer = reader.readUntilDelimiterOrEofAlloc( api.VM.allocator, '\n', if (max_size.isNull()) @@ -237,6 +239,7 @@ fn handleFileReadAllError(ctx: *api.NativeCtx, err: anytype) void { error.ConnectionTimedOut, error.NotOpenForReading, error.NetNameDeleted, + error.SocketNotConnected, => ctx.vm.pushErrorEnum("errors.ReadWriteError", @errorName(err)), error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null), @@ -358,7 +361,7 @@ export fn runFile(ctx: *api.NativeCtx) c_int { defer vm.bz_deinitVM(); // Compile - var function = vm.bz_compile( + const function = vm.bz_compile( if (source.len > 0) @as([*]const u8, @ptrCast(source)) else null, source.len, if (filename.len > 0) @as([*]const u8, @ptrCast(filename)) else null, diff --git a/src/lib/buzz_os.zig b/src/lib/buzz_os.zig index 37a9f299..49f1c580 100644 --- a/src/lib/buzz_os.zig +++ b/src/lib/buzz_os.zig @@ -211,6 +211,7 @@ fn handleConnectError(ctx: *api.NativeCtx, err: anytype) void { error.TimeoutTooBig, error.UnknownHostName, error.WouldBlock, + error.SocketNotConnected, => ctx.vm.pushErrorEnum("errors.SocketError", @errorName(err)), error.BadPathName, @@ -422,6 +423,7 @@ fn handleReadLineError(ctx: *api.NativeCtx, err: anytype) void { error.NotOpenForReading, error.OperationAborted, error.StreamTooLong, + error.SocketNotConnected, => ctx.vm.pushErrorEnum("errors.ReadWriteError", @errorName(err)), error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null), @@ -439,7 +441,7 @@ export fn SocketReadLine(ctx: *api.NativeCtx) c_int { const stream: std.net.Stream = .{ .handle = handle }; const reader = stream.reader(); - var buffer = reader.readUntilDelimiterAlloc( + const buffer = reader.readUntilDelimiterAlloc( api.VM.allocator, '\n', if (max_size.isNull()) @@ -484,7 +486,7 @@ export fn SocketReadAll(ctx: *api.NativeCtx) c_int { const stream: std.net.Stream = .{ .handle = handle }; const reader = stream.reader(); - var buffer = reader.readAllAlloc( + const buffer = reader.readAllAlloc( api.VM.allocator, if (max_size.isNull()) std.math.maxInt(usize) @@ -610,6 +612,7 @@ export fn SocketServerStart(ctx: *api.NativeCtx) c_int { error.SocketTypeNotSupported, error.SystemFdQuotaExceeded, error.TimeoutTooBig, + error.SocketNotConnected, => ctx.vm.pushErrorEnum("errors.SocketError", @errorName(err)), error.AccessDenied, error.BadPathName, @@ -709,6 +712,7 @@ export fn SocketServerAccept(ctx: *api.NativeCtx) c_int { .sockfd = server_socket, .kernel_backlog = default_options.kernel_backlog, .reuse_address = reuse_address, + .force_nonblocking = default_options.force_nonblocking, .reuse_port = reuse_port, .listen_address = undefined, }; @@ -726,6 +730,7 @@ export fn SocketServerAccept(ctx: *api.NativeCtx) c_int { error.ConnectionResetByPeer, error.NetworkSubsystemFailed, error.OperationNotSupported, + error.WouldBlock, => ctx.vm.pushErrorEnum("errors.SocketError", @errorName(err)), error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null), } diff --git a/src/main.zig b/src/main.zig index db7d2093..318ce23f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -15,7 +15,7 @@ const ObjTypeDef = _obj.ObjTypeDef; const TypeRegistry = @import("memory.zig").TypeRegistry; const FunctionNode = @import("node.zig").FunctionNode; const BuildOptions = @import("build_options"); -const clap = @import("ext/clap/clap.zig"); +const clap = @import("clap"); const GarbageCollector = @import("memory.zig").GarbageCollector; const MIRJIT = @import("mirjit.zig"); const _repl = @import("repl.zig"); @@ -114,7 +114,7 @@ fn runFile(allocator: Allocator, file_name: []const u8, args: [][:0]u8, flavor: try function_node.toJson(function_node, &json.writer()); - var without_nl = try std.mem.replaceOwned(u8, allocator, json.items, "\n", " "); + const without_nl = try std.mem.replaceOwned(u8, allocator, json.items, "\n", " "); defer allocator.free(without_nl); _ = try std.io.getStdOut().write(without_nl); @@ -168,7 +168,7 @@ fn runFile(allocator: Allocator, file_name: []const u8, args: [][:0]u8, flavor: try function_node.toJson(function_node, &json.writer()); - var without_nl = try std.mem.replaceOwned(u8, allocator, json.items, "\n", " "); + const without_nl = try std.mem.replaceOwned(u8, allocator, json.items, "\n", " "); defer allocator.free(without_nl); _ = try std.io.getStdOut().write(without_nl); @@ -318,7 +318,7 @@ test "Testing behavior" { while (try it.next()) |file| : (count += 1) { if (file.kind == .file and std.mem.endsWith(u8, file.name, ".buzz")) { - var file_name: []u8 = try allocator.alloc(u8, 6 + file.name.len); + const file_name: []u8 = try allocator.alloc(u8, 6 + file.name.len); defer allocator.free(file_name); std.debug.print("{s}\n", .{file.name}); @@ -348,7 +348,7 @@ test "Testing behavior" { while (try it.next()) |file| : (count += 1) { if (file.kind == .file and std.mem.endsWith(u8, file.name, ".buzz")) { - var file_name: []u8 = try allocator.alloc(u8, 21 + file.name.len); + const file_name: []u8 = try allocator.alloc(u8, 21 + file.name.len); defer allocator.free(file_name); _ = try std.fmt.bufPrint(file_name, "tests/compile_errors/{s}", .{file.name}); diff --git a/src/memory.zig b/src/memory.zig index 72c0ba1e..625230f8 100644 --- a/src/memory.zig +++ b/src/memory.zig @@ -62,7 +62,7 @@ pub const TypeRegistry = struct { } } - var type_def_ptr: *ObjTypeDef = try self.gc.allocateObject(ObjTypeDef, type_def); + const type_def_ptr: *ObjTypeDef = try self.gc.allocateObject(ObjTypeDef, type_def); if (BuildOptions.debug_placeholders) { std.debug.print("`{s}` @{}\n", .{ type_def_str, @intFromPtr(type_def_ptr) }); @@ -212,7 +212,7 @@ pub const GarbageCollector = struct { try self.collectGarbage(); } - var allocated = try self.allocator.create(T); + const allocated = try self.allocator.create(T); if (BuildOptions.gc_debug) { std.debug.print("Allocated @{} {}\n", .{ @intFromPtr(allocated), T }); @@ -242,10 +242,10 @@ pub const GarbageCollector = struct { pub fn allocateObject(self: *Self, comptime T: type, data: T) !*T { // var before: usize = self.bytes_allocated; - var obj: *T = try self.allocate(T); + const obj: *T = try self.allocate(T); obj.* = data; - var object: *Obj = switch (T) { + const object: *Obj = switch (T) { ObjString => ObjString.toObj(obj), ObjTypeDef => ObjTypeDef.toObj(obj), ObjUpValue => ObjUpValue.toObj(obj), @@ -305,7 +305,7 @@ pub const GarbageCollector = struct { } fn addObject(self: *Self, obj: *Obj) !void { - var new_node = try self.allocator.create(std.TailQueue(*Obj).Node); + const new_node = try self.allocator.create(std.TailQueue(*Obj).Node); new_node.* = .{ .data = obj, }; @@ -314,7 +314,7 @@ pub const GarbageCollector = struct { } pub fn allocateString(self: *Self, chars: []const u8) !*ObjString { - var string: *ObjString = try allocateObject( + const string: *ObjString = try allocateObject( self, ObjString, ObjString{ .string = chars }, @@ -330,8 +330,8 @@ pub const GarbageCollector = struct { return interned; } - var copy: []u8 = try self.allocateMany(u8, chars.len); - std.mem.copy(u8, copy, chars); + const copy: []u8 = try self.allocateMany(u8, chars.len); + @memcpy(copy, chars); if (BuildOptions.gc_debug) { std.debug.print("Allocated slice {*} `{s}`\n", .{ copy, copy }); @@ -504,7 +504,7 @@ pub const GarbageCollector = struct { switch (obj.obj_type) { .String => { - var obj_string = ObjString.cast(obj).?; + const obj_string = ObjString.cast(obj).?; // Remove it from interned strings _ = self.strings.remove(obj_string.string); @@ -550,7 +550,7 @@ pub const GarbageCollector = struct { free(self, ObjTypeDef, obj_typedef); }, .UpValue => { - var obj_upvalue = ObjUpValue.cast(obj).?; + const obj_upvalue = ObjUpValue.cast(obj).?; if (obj_upvalue.closed) |value| { if (value.isObj()) { try freeObj(self, value.obj()); @@ -637,7 +637,7 @@ pub const GarbageCollector = struct { free(self, ObjFiber, obj_fiber); }, .ForeignContainer => { - var obj_foreignstruct = ObjForeignContainer.cast(obj).?; + const obj_foreignstruct = ObjForeignContainer.cast(obj).?; self.freeMany(u8, obj_foreignstruct.data); @@ -808,7 +808,7 @@ pub const GarbageCollector = struct { } fn sweep(self: *Self, mode: Mode) !void { - var swept: usize = self.bytes_allocated; + const swept: usize = self.bytes_allocated; var obj_count: usize = 0; var obj_node: ?*std.TailQueue(*Obj).Node = self.objects.first; @@ -829,7 +829,7 @@ pub const GarbageCollector = struct { obj_node = node.next; } else { - var unreached: *Obj = node.data; + const unreached: *Obj = node.data; obj_node = node.next; self.objects.remove(node); diff --git a/src/mirjit.zig b/src/mirjit.zig index 380bcb40..55a5e0a1 100644 --- a/src/mirjit.zig +++ b/src/mirjit.zig @@ -326,7 +326,7 @@ pub fn compileZdefContainer(self: *Self, zdef_element: *const n.ZdefNode.ZdefEle switch (foreign_def.zig_type) { .Struct => { for (foreign_def.zig_type.Struct.fields) |field| { - var container_field = foreign_def.fields.getEntry(field.name).?; + const container_field = foreign_def.fields.getEntry(field.name).?; try getters.append( try self.buildZdefContainerGetter( @@ -352,7 +352,7 @@ pub fn compileZdefContainer(self: *Self, zdef_element: *const n.ZdefNode.ZdefEle .Union => { for (foreign_def.zig_type.Union.fields) |field| { - var container_field = foreign_def.fields.getEntry(field.name).?; + const container_field = foreign_def.fields.getEntry(field.name).?; _ = container_field; try getters.append( @@ -415,7 +415,7 @@ pub fn compileZdefContainer(self: *Self, zdef_element: *const n.ZdefNode.ZdefEle switch (foreign_def.zig_type) { .Struct => { for (foreign_def.zig_type.Struct.fields, 0..) |field, idx| { - var struct_field = foreign_def.fields.getEntry(field.name).?; + const struct_field = foreign_def.fields.getEntry(field.name).?; struct_field.value_ptr.*.getter = @alignCast(@ptrCast(m.MIR_gen( self.ctx, 0, @@ -431,7 +431,7 @@ pub fn compileZdefContainer(self: *Self, zdef_element: *const n.ZdefNode.ZdefEle }, .Union => { for (foreign_def.zig_type.Union.fields, 0..) |field, idx| { - var struct_field = foreign_def.fields.getEntry(field.name).?; + const struct_field = foreign_def.fields.getEntry(field.name).?; struct_field.value_ptr.*.getter = @alignCast(@ptrCast(m.MIR_gen( self.ctx, 0, @@ -468,9 +468,9 @@ fn buildZdefUnionGetter( ); // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - var vm_name = self.vm.gc.allocator.dupeZ(u8, "vm") catch @panic("Out of memory"); + const vm_name = self.vm.gc.allocator.dupeZ(u8, "vm") catch @panic("Out of memory"); defer self.vm.gc.allocator.free(vm_name); - var data_name = self.vm.gc.allocator.dupeZ(u8, "data") catch @panic("Out of memory"); + const data_name = self.vm.gc.allocator.dupeZ(u8, "data") catch @panic("Out of memory"); defer self.vm.gc.allocator.free(data_name); const function = m.MIR_new_func_arr( self.ctx, @@ -572,11 +572,11 @@ fn buildZdefUnionSetter( ); // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - var vm_name = self.vm.gc.allocator.dupeZ(u8, "vm") catch @panic("Out of memory"); + const vm_name = self.vm.gc.allocator.dupeZ(u8, "vm") catch @panic("Out of memory"); defer self.vm.gc.allocator.free(vm_name); - var data_name = self.vm.gc.allocator.dupeZ(u8, "data") catch @panic("Out of memory"); + const data_name = self.vm.gc.allocator.dupeZ(u8, "data") catch @panic("Out of memory"); defer self.vm.gc.allocator.free(data_name); - var new_value_name = self.vm.gc.allocator.dupeZ(u8, "new_value") catch @panic("Out of memory"); + const new_value_name = self.vm.gc.allocator.dupeZ(u8, "new_value") catch @panic("Out of memory"); defer self.vm.gc.allocator.free(new_value_name); const function = m.MIR_new_func_arr( self.ctx, @@ -679,9 +679,9 @@ fn buildZdefContainerGetter( ); // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - var vm_name = self.vm.gc.allocator.dupeZ(u8, "vm") catch @panic("Out of memory"); + const vm_name = self.vm.gc.allocator.dupeZ(u8, "vm") catch @panic("Out of memory"); defer self.vm.gc.allocator.free(vm_name); - var data_name = self.vm.gc.allocator.dupeZ(u8, "data") catch @panic("Out of memory"); + const data_name = self.vm.gc.allocator.dupeZ(u8, "data") catch @panic("Out of memory"); defer self.vm.gc.allocator.free(data_name); const function = m.MIR_new_func_arr( self.ctx, @@ -767,11 +767,11 @@ fn buildZdefContainerSetter( ); // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - var vm_name = self.vm.gc.allocator.dupeZ(u8, "vm") catch @panic("Out of memory"); + const vm_name = self.vm.gc.allocator.dupeZ(u8, "vm") catch @panic("Out of memory"); defer self.vm.gc.allocator.free(vm_name); - var data_name = self.vm.gc.allocator.dupeZ(u8, "data") catch @panic("Out of memory"); + const data_name = self.vm.gc.allocator.dupeZ(u8, "data") catch @panic("Out of memory"); defer self.vm.gc.allocator.free(data_name); - var new_value_name = self.vm.gc.allocator.dupeZ(u8, "new_value") catch @panic("Out of memory"); + const new_value_name = self.vm.gc.allocator.dupeZ(u8, "new_value") catch @panic("Out of memory"); defer self.vm.gc.allocator.free(new_value_name); const function = m.MIR_new_func_arr( self.ctx, @@ -965,7 +965,7 @@ pub fn compileZdef(self: *Self, zdef: *const n.ZdefNode.ZdefElement) Error!*o.Ob try wrapper_name.writer().print("zdef_{s}\x00", .{zdef.zdef.name}); - var dupped_symbol = self.vm.gc.allocator.dupeZ(u8, zdef.zdef.name) catch @panic("Out of memory"); + const dupped_symbol = self.vm.gc.allocator.dupeZ(u8, zdef.zdef.name) catch @panic("Out of memory"); defer self.vm.gc.allocator.free(dupped_symbol); const module = m.MIR_new_module(self.ctx, @ptrCast(wrapper_name.items.ptr)); @@ -1032,7 +1032,7 @@ pub fn compileZdef(self: *Self, zdef: *const n.ZdefNode.ZdefElement) Error!*o.Ob m.MIR_gen_init(self.ctx, 1); defer m.MIR_gen_finish(self.ctx); - var obj_native = try self.vm.gc.allocateObject( + const obj_native = try self.vm.gc.allocateObject( o.ObjNative, .{ .native = m.MIR_gen(self.ctx, 0, wrapper_item) orelse unreachable, @@ -1105,11 +1105,11 @@ fn buildZdefWrapper(self: *Self, zdef_element: *const n.ZdefNode.ZdefElement) Er try wrapper_protocol_name.writer().print("p_zdef_{s}\x00", .{zdef_element.zdef.name}); - var dupped_symbol = self.vm.gc.allocator.dupeZ(u8, zdef_element.zdef.name) catch @panic("Out of memory"); + const dupped_symbol = self.vm.gc.allocator.dupeZ(u8, zdef_element.zdef.name) catch @panic("Out of memory"); defer self.vm.gc.allocator.free(dupped_symbol); // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - var ctx_name = self.vm.gc.allocator.dupeZ(u8, "ctx") catch @panic("Out of memory"); + const ctx_name = self.vm.gc.allocator.dupeZ(u8, "ctx") catch @panic("Out of memory"); defer self.vm.gc.allocator.free(ctx_name); const function = m.MIR_new_func_arr( self.ctx, @@ -1181,7 +1181,7 @@ fn buildZdefWrapper(self: *Self, zdef_element: *const n.ZdefNode.ZdefElement) Er const buzz_return_type = function_def.return_type; - var return_mir_type = if (zig_return_type != .Void) + const return_mir_type = if (zig_return_type != .Void) zigToMIRRegType(zig_return_type) else null; @@ -4996,7 +4996,7 @@ fn generateFunction(self: *Self, function_node: *n.FunctionNode) Error!?m.MIR_op } // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - var ctx_name = self.vm.gc.allocator.dupeZ(u8, "ctx") catch @panic("Out of memory"); + const ctx_name = self.vm.gc.allocator.dupeZ(u8, "ctx") catch @panic("Out of memory"); defer self.vm.gc.allocator.free(ctx_name); const function = m.MIR_new_func_arr( self.ctx, @@ -5079,7 +5079,7 @@ fn generateNativeFn(self: *Self, function_node: *n.FunctionNode, raw_fn: m.MIR_i defer nativefn_qualified_name.deinit(); // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - var ctx_name = self.vm.gc.allocator.dupeZ(u8, "ctx") catch @panic("Out of memory"); + const ctx_name = self.vm.gc.allocator.dupeZ(u8, "ctx") catch @panic("Out of memory"); defer self.vm.gc.allocator.free(ctx_name); const function = m.MIR_new_func_arr( self.ctx, diff --git a/src/node.zig b/src/node.zig index ec047ec2..9a983840 100644 --- a/src/node.zig +++ b/src/node.zig @@ -181,7 +181,7 @@ pub const ParseNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = @as(*Self, @ptrCast(node)); try out.writeAll("\"type_def\": \""); @@ -333,7 +333,7 @@ pub const ExpressionNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Expression) { return null; } @@ -488,7 +488,7 @@ pub const GenericResolveNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .GenericResolve) { return null; } @@ -530,7 +530,7 @@ pub const GroupingNode = struct { } fn generate(nodePtr: *anyopaque, codegenPtr: *anyopaque, breaks: ?*std.ArrayList(usize)) anyerror!?*ObjFunction { - var codegen: *CodeGen = @ptrCast(@alignCast(codegenPtr)); + const codegen: *CodeGen = @ptrCast(@alignCast(codegenPtr)); const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.synchronize(codegen)) { @@ -577,7 +577,7 @@ pub const GroupingNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Grouping) { return null; } @@ -626,7 +626,7 @@ pub const NamedVariableNode = struct { return null; } - var self = Self.cast(node).?; + const self = Self.cast(node).?; var get_op: OpCode = undefined; var set_op: OpCode = undefined; @@ -677,8 +677,8 @@ pub const NamedVariableNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; try out.print( "{{\"node\": \"NamedVariable\", \"identifier\": \"{s}\", \"slot\": \"{}\", \"slot_type\": \"{}\",", @@ -718,7 +718,7 @@ pub const NamedVariableNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .NamedVariable) { return null; } @@ -760,7 +760,7 @@ pub const IntegerNode = struct { return null; } - var self = Self.cast(node).?; + const self = Self.cast(node).?; try codegen.emitConstant(self.node.location, Value.fromInteger(self.integer_constant)); @@ -771,8 +771,8 @@ pub const IntegerNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; try out.print("{{\"node\": \"Integer\", \"constant\": ", .{}); @@ -795,7 +795,7 @@ pub const IntegerNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Integer) { return null; } @@ -911,7 +911,7 @@ pub const RangeNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.print("{{\"node\": \"Range\", \"low\": ", .{}); @@ -939,7 +939,7 @@ pub const RangeNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Range) { return null; } @@ -981,7 +981,7 @@ pub const FloatNode = struct { return null; } - var self = Self.cast(node).?; + const self = Self.cast(node).?; try codegen.emitConstant(self.node.location, Value.fromFloat(self.float_constant)); @@ -992,8 +992,8 @@ pub const FloatNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; try out.print("{{\"node\": \"Float\", \"constant\": ", .{}); @@ -1016,7 +1016,7 @@ pub const FloatNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Float) { return null; } @@ -1044,7 +1044,7 @@ pub const BooleanNode = struct { } fn val(nodePtr: *anyopaque, _: *GarbageCollector) anyerror!Value { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); return Value.fromBoolean(Self.cast(node).?.constant); } @@ -1056,7 +1056,7 @@ pub const BooleanNode = struct { return null; } - var self = Self.cast(node).?; + const self = Self.cast(node).?; try codegen.emitOpCode(self.node.location, if (self.constant) .OP_TRUE else .OP_FALSE); @@ -1067,8 +1067,8 @@ pub const BooleanNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; try out.print("{{\"node\": \"Boolean\", \"constant\": \"{}\", ", .{self.constant}); @@ -1093,7 +1093,7 @@ pub const BooleanNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Boolean) { return null; } @@ -1121,7 +1121,7 @@ pub const StringLiteralNode = struct { } fn val(nodePtr: *anyopaque, _: *GarbageCollector) anyerror!Value { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); return Self.cast(node).?.constant.toValue(); } @@ -1144,8 +1144,8 @@ pub const StringLiteralNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; var escaped = try escape(global_allocator, self.constant.string); defer escaped.deinit(); @@ -1174,7 +1174,7 @@ pub const StringLiteralNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .StringLiteral) { return null; } @@ -1202,7 +1202,7 @@ pub const PatternNode = struct { } fn val(nodePtr: *anyopaque, _: *GarbageCollector) anyerror!Value { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); return Self.cast(node).?.constant.toValue(); } @@ -1225,8 +1225,8 @@ pub const PatternNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; var escaped = try escape(global_allocator, self.constant.source); defer escaped.deinit(); @@ -1249,7 +1249,7 @@ pub const PatternNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Pattern) { return null; } @@ -1295,7 +1295,7 @@ pub const StringNode = struct { defer list.deinit(); var str_value = std.ArrayList(u8).init(gc.allocator); - var writer = &str_value.writer(); + const writer = &str_value.writer(); for (self.elements) |element| { assert(element.isConstant(element)); @@ -1316,7 +1316,7 @@ pub const StringNode = struct { return null; } - var self = Self.cast(node).?; + const self = Self.cast(node).?; if (self.elements.len == 0) { // Push the empty string which is always the constant 0 @@ -1351,8 +1351,8 @@ pub const StringNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; try out.writeAll("{\"node\": \"String\", \"elements\": ["); @@ -1415,7 +1415,7 @@ pub const StringNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .String) { return null; } @@ -1461,7 +1461,7 @@ pub const NullNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); try out.writeAll("{\"node\": \"Null\", "); @@ -1479,7 +1479,7 @@ pub const NullNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Null) { return null; } @@ -1525,7 +1525,7 @@ pub const VoidNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); try out.writeAll("{\"node\": \"Void\", "); @@ -1543,7 +1543,7 @@ pub const VoidNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Void) { return null; } @@ -1608,7 +1608,7 @@ pub const ListNode = struct { return null; } - var self = Self.cast(node).?; + const self = Self.cast(node).?; const item_type = self.node.type_def.?.resolved_type.?.List.item_type; const list_offset: usize = try codegen.emitList(self.node.location); @@ -1642,8 +1642,8 @@ pub const ListNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; try out.writeAll("{\"node\": \"List\", \"items\": ["); @@ -1707,7 +1707,7 @@ pub const ListNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .List) { return null; } @@ -1784,7 +1784,7 @@ pub const MapNode = struct { return null; } - var self = Self.cast(node).?; + const self = Self.cast(node).?; const key_type = self.node.type_def.?.resolved_type.?.Map.key_type; const value_type = self.node.type_def.?.resolved_type.?.Map.value_type; @@ -1842,7 +1842,7 @@ pub const MapNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"Map\", \"items\": ["); @@ -1919,7 +1919,7 @@ pub const MapNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Map) { return null; } @@ -2032,7 +2032,7 @@ pub const UnwrapNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Unwrap) { return null; } @@ -2140,7 +2140,7 @@ pub const ForceUnwrapNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .ForceUnwrap) { return null; } @@ -2216,7 +2216,7 @@ pub const IsNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"Is\", \"left\": "); @@ -2246,7 +2246,7 @@ pub const IsNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Is) { return null; } @@ -2332,7 +2332,7 @@ pub const AsNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"AsOpt\", \"left\": "); @@ -2362,7 +2362,7 @@ pub const AsNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .As) { return null; } @@ -2483,7 +2483,7 @@ pub const UnaryNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"Unary\", \"left\": "); @@ -2514,7 +2514,7 @@ pub const UnaryNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Unary) { return null; } @@ -3128,7 +3128,7 @@ pub const BinaryNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"Binary\", \"left\": "); @@ -3178,7 +3178,7 @@ pub const BinaryNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Binary) { return null; } @@ -3383,7 +3383,7 @@ pub const SubscriptNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"Subscript\", \"subscripted\": "); @@ -3426,7 +3426,7 @@ pub const SubscriptNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Subscript) { return null; } @@ -3574,7 +3574,7 @@ pub const TryNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.print("{{\"node\": \"Try\", ", .{}); @@ -3633,7 +3633,7 @@ pub const TryNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Try) { return null; } @@ -3709,7 +3709,7 @@ pub const FunctionNode = struct { var self = Self.cast(node).?; - var enclosing = codegen.current; + const enclosing = codegen.current; codegen.current = try codegen.gc.allocator.create(Frame); codegen.current.?.* = Frame{ .enclosing = enclosing, @@ -3832,7 +3832,7 @@ pub const FunctionNode = struct { } } - var frame = codegen.current.?; + const frame = codegen.current.?; var current_function: *ObjFunction = frame.function.?; current_function.upvalue_count = @intCast(self.upvalue_binding.count()); @@ -3867,8 +3867,8 @@ pub const FunctionNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; try out.print( "{{\"node\": \"Function\", \"type\": \"{}\", \"name\": \"{s}\", ", @@ -4003,7 +4003,7 @@ pub const FunctionNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Function) { return null; } @@ -4110,7 +4110,7 @@ pub const YieldNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Yield) { return null; } @@ -4199,7 +4199,7 @@ pub const ResolveNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Resolve) { return null; } @@ -4288,7 +4288,7 @@ pub const ResumeNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Resume) { return null; } @@ -4372,7 +4372,7 @@ pub const AsyncCallNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .AsyncCall) { return null; } @@ -4673,7 +4673,7 @@ pub const CallNode = struct { try codegen.emit(node.location, @intCast(arg_count - correct_index - 1)); // Switch it in the reference - var temp = arguments_order_ref.items[index]; + const temp = arguments_order_ref.items[index]; arguments_order_ref.items[index] = arguments_order_ref.items[correct_index]; arguments_order_ref.items[correct_index] = temp; @@ -4857,7 +4857,7 @@ pub const CallNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"Call\""); @@ -4991,7 +4991,7 @@ pub const CallNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Call) { return null; } @@ -5050,7 +5050,7 @@ pub const FunDeclarationNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.print("{{\"node\": \"FunDeclaration\",\"slot_type\": \"{}\",\"function\": ", .{self.slot_type}); @@ -5081,7 +5081,7 @@ pub const FunDeclarationNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .FunDeclaration) { return null; } @@ -5160,7 +5160,7 @@ pub const VarDeclarationNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.print( @@ -5227,7 +5227,7 @@ pub const VarDeclarationNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .VarDeclaration) { return null; } @@ -5337,8 +5337,8 @@ pub const EnumNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; try out.writeAll("{\"node\": \"Enum\", \"cases\": ["); @@ -5403,7 +5403,7 @@ pub const EnumNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Enum) { return null; } @@ -5495,7 +5495,7 @@ pub const ThrowNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"Throw\", \"error_value\": "); @@ -5524,7 +5524,7 @@ pub const ThrowNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Throw) { return null; } @@ -5587,7 +5587,7 @@ pub const BreakNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Break) { return null; } @@ -5649,7 +5649,7 @@ pub const ContinueNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Continue) { return null; } @@ -5821,7 +5821,7 @@ pub const IfNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"If\", \"condition\": "); @@ -5885,7 +5885,7 @@ pub const IfNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .If) { return null; } @@ -5925,7 +5925,7 @@ pub const ReturnNode = struct { return null; } - var self = Self.cast(node).?; + const self = Self.cast(node).?; if (self.unconditional) { codegen.current.?.return_emitted = true; @@ -5965,8 +5965,8 @@ pub const ReturnNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; try out.writeAll("{\"node\": \"Return\", "); @@ -6001,7 +6001,7 @@ pub const ReturnNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Return) { return null; } @@ -6071,7 +6071,7 @@ pub const ForNode = struct { // Jump over expressions which will be executed at end of loop // TODO: since we don't generate as we parse, we can get rid of this jump and just generate the post_loop later - var body_jump: usize = try codegen.emitJump(self.node.location, .OP_JUMP); + const body_jump: usize = try codegen.emitJump(self.node.location, .OP_JUMP); const expr_loop: usize = codegen.currentCode(); for (self.post_loop.items) |expr| { @@ -6110,7 +6110,7 @@ pub const ForNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"For\", \"init_declarations\": ["); @@ -6199,7 +6199,7 @@ pub const ForNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .For) { return null; } @@ -6450,7 +6450,7 @@ pub const ForEachNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"ForEach\", "); @@ -6517,7 +6517,7 @@ pub const ForEachNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .ForEach) { return null; } @@ -6603,7 +6603,7 @@ pub const WhileNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"While\", \"condition\": "); @@ -6652,7 +6652,7 @@ pub const WhileNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .While) { return null; } @@ -6731,7 +6731,7 @@ pub const DoUntilNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"DoUntil\", \"condition\": "); @@ -6779,7 +6779,7 @@ pub const DoUntilNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .DoUntil) { return null; } @@ -6811,14 +6811,14 @@ pub const BlockNode = struct { } fn generate(nodePtr: *anyopaque, codegenPtr: *anyopaque, breaks: ?*std.ArrayList(usize)) anyerror!?*ObjFunction { - var codegen: *CodeGen = @ptrCast(@alignCast(codegenPtr)); + const codegen: *CodeGen = @ptrCast(@alignCast(codegenPtr)); var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.synchronize(codegen)) { return null; } - var self = Self.cast(node).?; + const self = Self.cast(node).?; for (self.statements.items) |statement| { _ = try statement.toByteCode(statement, codegen, breaks); @@ -6831,8 +6831,8 @@ pub const BlockNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; try out.writeAll("{\"node\": \"Block\", \"statements\": ["); @@ -6875,7 +6875,7 @@ pub const BlockNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Block) { return null; } @@ -6973,7 +6973,7 @@ pub const DotNode = struct { ); } - var get_code: ?OpCode = switch (callee_type.def_type) { + const get_code: ?OpCode = switch (callee_type.def_type) { .Object => .OP_GET_OBJECT_PROPERTY, .ObjectInstance, .ProtocolInstance => .OP_GET_INSTANCE_PROPERTY, .ForeignContainer => .OP_GET_FCONTAINER_INSTANCE_PROPERTY, @@ -7087,7 +7087,7 @@ pub const DotNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"Dot\", \"callee\": "); @@ -7133,7 +7133,7 @@ pub const DotNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Dot) { return null; } @@ -7326,7 +7326,7 @@ pub const ObjectInitNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"ObjectInit\", \"properties\": {"); @@ -7404,7 +7404,7 @@ pub const ObjectInitNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .ObjectInit) { return null; } @@ -7623,7 +7623,7 @@ pub const ObjectDeclarationNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.writeAll("{\"node\": \"ObjectDeclaration\", \"methods\": {"); @@ -7754,7 +7754,7 @@ pub const ObjectDeclarationNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .ObjectDeclaration) { return null; @@ -7806,7 +7806,7 @@ pub const ProtocolDeclarationNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); try out.writeAll("{\"node\": \"ProtocolDeclaration\", "); @@ -7816,7 +7816,7 @@ pub const ProtocolDeclarationNode = struct { } fn render(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer, depth: usize) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); const protocol_def = node.type_def.?.resolved_type.?.Protocol; @@ -7838,7 +7838,7 @@ pub const ProtocolDeclarationNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .ProtocolDeclaration) { return null; @@ -7889,8 +7889,8 @@ pub const ExportNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; try out.print("{{\"node\": \"Export\", ", .{}); @@ -7938,7 +7938,7 @@ pub const ExportNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Export) { return null; @@ -7990,7 +7990,7 @@ pub const TypeExpressionNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.print("{{\"node\": \"TypeExpression\", \"value\": \"", .{}); @@ -8022,7 +8022,7 @@ pub const TypeExpressionNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .TypeExpression) { return null; @@ -8087,7 +8087,7 @@ pub const TypeOfExpressionNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); var self = Self.cast(node).?; try out.print("{{\"node\": \"TypeOfExpression\", \"expression\": \"", .{}); @@ -8119,7 +8119,7 @@ pub const TypeOfExpressionNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .TypeOfExpression) { return null; @@ -8206,8 +8206,8 @@ pub const ZdefNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; try out.print("{{\"node\": \"Zdef\", \"lib_name\": {s}, ", .{self.lib_name.lexeme}); @@ -8250,7 +8250,7 @@ pub const ZdefNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Zdef) { return null; @@ -8293,7 +8293,7 @@ pub const ImportNode = struct { return null; } - var self = Self.cast(node).?; + const self = Self.cast(node).?; if (self.import) |import| { try codegen.emitConstant( @@ -8312,8 +8312,8 @@ pub const ImportNode = struct { } fn stringify(nodePtr: *anyopaque, out: *const std.ArrayList(u8).Writer) RenderError!void { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); - var self = Self.cast(node).?; + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const self = Self.cast(node).?; try out.print("{{\"node\": \"Import\", \"path\": \"{s}\"", .{self.path.literal_string.?}); @@ -8324,7 +8324,7 @@ pub const ImportNode = struct { try out.writeAll(",\"imported_symbols\": ["); if (self.imported_symbols) |imported_symbols| { var key_it = imported_symbols.keyIterator(); - var total = imported_symbols.count(); + const total = imported_symbols.count(); var count: usize = 0; while (key_it.next()) |symbol| { try out.print("\"{s}\"", .{symbol}); @@ -8383,7 +8383,7 @@ pub const ImportNode = struct { } pub fn cast(nodePtr: *anyopaque) ?*Self { - var node: *ParseNode = @ptrCast(@alignCast(nodePtr)); + const node: *ParseNode = @ptrCast(@alignCast(nodePtr)); if (node.node_type != .Import) { return null; diff --git a/src/obj.zig b/src/obj.zig index 0a36bc2b..1c7c277c 100644 --- a/src/obj.zig +++ b/src/obj.zig @@ -288,7 +288,7 @@ pub const Obj = struct { var it = container_def.fields.iterator(); while (it.next()) |kv| { - var dupped = try vm.gc.allocator.dupeZ(u8, kv.key_ptr.*); + const dupped = try vm.gc.allocator.dupeZ(u8, kv.key_ptr.*); defer vm.gc.allocator.free(dupped); try serialized_instance.set( @@ -386,7 +386,7 @@ pub const Obj = struct { .String => type_def.def_type == .String, .Type => type_def.def_type == .Type, .UpValue => uv: { - var upvalue: *ObjUpValue = ObjUpValue.cast(self).?; + const upvalue: *ObjUpValue = ObjUpValue.cast(self).?; break :uv valueTypeEql(upvalue.closed orelse upvalue.location.*, type_def); }, .EnumInstance => ei: { @@ -402,7 +402,7 @@ pub const Obj = struct { .Function => ObjFunction.cast(self).?.type_def.eql(type_def), .Closure => ObjClosure.cast(self).?.function.type_def.eql(type_def), .Bound => bound: { - var bound = ObjBoundMethod.cast(self).?; + const bound = ObjBoundMethod.cast(self).?; break :bound if (bound.closure) |cls| cls.function.type_def.eql(type_def) else unreachable; // TODO }, .List => ObjList.cast(self).?.type_def.eql(type_def), @@ -1669,7 +1669,7 @@ pub const ObjList = struct { // `value` arg is of item_type try parameters.put(try parser.gc.copyString("value"), self.item_type); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("append"), @@ -1681,9 +1681,9 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); + const native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); try self.methods.put("append", native_type); @@ -1694,7 +1694,7 @@ pub const ObjList = struct { // We omit first arg: it'll be OP_SWAPed in and we already parsed it // It's always the list. - var at_type = try parser.gc.type_registry.getTypeDef( + const at_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Integer, .optional = false, @@ -1703,7 +1703,7 @@ pub const ObjList = struct { try parameters.put(try parser.gc.copyString("at"), at_type); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("remove"), @@ -1719,9 +1719,9 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -1732,9 +1732,9 @@ pub const ObjList = struct { return native_type; } else if (mem.eql(u8, method, "len")) { - var parameters = std.AutoArrayHashMap(*ObjString, *ObjTypeDef).init(parser.gc.allocator); + const parameters = std.AutoArrayHashMap(*ObjString, *ObjTypeDef).init(parser.gc.allocator); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("len"), @@ -1750,9 +1750,9 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -1779,7 +1779,7 @@ pub const ObjList = struct { ), ); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("next"), @@ -1797,9 +1797,9 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -1838,7 +1838,7 @@ pub const ObjList = struct { var defaults = std.AutoArrayHashMap(*ObjString, Value).init(parser.gc.allocator); try defaults.put(len_str, Value.Null); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("sub"), @@ -1850,9 +1850,9 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -1870,7 +1870,7 @@ pub const ObjList = struct { try parameters.put(try parser.gc.copyString("needle"), self.item_type); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("indexOf"), @@ -1887,9 +1887,9 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -1907,7 +1907,7 @@ pub const ObjList = struct { try parameters.put(try parser.gc.copyString("separator"), try parser.gc.type_registry.getTypeDef(.{ .def_type = .String })); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("join"), @@ -1921,9 +1921,9 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -1949,7 +1949,7 @@ pub const ObjList = struct { // `value` arg is of item_type try parameters.put(try parser.gc.copyString("value"), self.item_type); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("insert"), @@ -1961,15 +1961,15 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); + const native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); try self.methods.put("insert", native_type); return native_type; } else if (mem.eql(u8, method, "pop")) { - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("pop"), @@ -1981,9 +1981,9 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); + const native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); try self.methods.put("pop", native_type); @@ -1997,7 +1997,7 @@ pub const ObjList = struct { try callback_parameters.put(try parser.gc.copyString("index"), try parser.gc.type_registry.getTypeDef(.{ .def_type = .Integer })); try callback_parameters.put(try parser.gc.copyString("element"), self.item_type); - var callback_method_def = ObjFunction.FunctionDef{ + const callback_method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), // TODO: is this ok? .script_name = try parser.gc.copyString("builtin"), @@ -2009,9 +2009,9 @@ pub const ObjList = struct { .generic_types = std.AutoArrayHashMap(*ObjString, *ObjTypeDef).init(parser.gc.allocator), }; - var callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; + const callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; - var callback_type = try parser.gc.type_registry.getTypeDef( + const callback_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = callback_resolved_type, @@ -2025,7 +2025,7 @@ pub const ObjList = struct { callback_type, ); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("forEach"), @@ -2037,9 +2037,9 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); + const native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); try self.methods.put("forEach", native_type); @@ -2083,9 +2083,9 @@ pub const ObjList = struct { callback_method_def.return_type = generic_type; - var callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; + const callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; - var callback_type = try parser.gc.type_registry.getTypeDef( + const callback_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = callback_resolved_type, @@ -2099,9 +2099,9 @@ pub const ObjList = struct { callback_type, ); - var new_list_def = ObjList.ListDef.init(parser.gc.allocator, generic_type); + const new_list_def = ObjList.ListDef.init(parser.gc.allocator, generic_type); - var new_list_type = ObjTypeDef.TypeUnion{ .List = new_list_def }; + const new_list_type = ObjTypeDef.TypeUnion{ .List = new_list_def }; var method_def = ObjFunction.FunctionDef{ .id = map_origin, @@ -2123,9 +2123,9 @@ pub const ObjList = struct { generic_type, ); - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); + const native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); try self.methods.put("map", native_type); @@ -2145,7 +2145,7 @@ pub const ObjList = struct { self.item_type, ); - var callback_method_def = ObjFunction.FunctionDef{ + const callback_method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), // TODO: is this ok? .script_name = try parser.gc.copyString("builtin"), @@ -2157,9 +2157,9 @@ pub const ObjList = struct { .generic_types = std.AutoArrayHashMap(*ObjString, *ObjTypeDef).init(parser.gc.allocator), }; - var callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; + const callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; - var callback_type = try parser.gc.type_registry.getTypeDef( + const callback_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = callback_resolved_type, @@ -2173,7 +2173,7 @@ pub const ObjList = struct { callback_type, ); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("filter"), @@ -2185,9 +2185,9 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); + const native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); try self.methods.put("filter", native_type); @@ -2223,7 +2223,7 @@ pub const ObjList = struct { generic_type, ); - var callback_method_def = ObjFunction.FunctionDef{ + const callback_method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), // TODO: is this ok? .script_name = try parser.gc.copyString("builtin"), @@ -2235,9 +2235,9 @@ pub const ObjList = struct { .generic_types = std.AutoArrayHashMap(*ObjString, *ObjTypeDef).init(parser.gc.allocator), }; - var callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; + const callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; - var callback_type = try parser.gc.type_registry.getTypeDef( + const callback_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = callback_resolved_type, @@ -2258,7 +2258,7 @@ pub const ObjList = struct { var generic_types = std.AutoArrayHashMap(*ObjString, *ObjTypeDef).init(parser.gc.allocator); try generic_types.put(try parser.gc.copyString("T"), generic_type); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = reduce_origin, .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("reduce"), @@ -2270,9 +2270,9 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -2291,7 +2291,7 @@ pub const ObjList = struct { try callback_parameters.put(try parser.gc.copyString("left"), self.item_type); try callback_parameters.put(try parser.gc.copyString("right"), self.item_type); - var callback_method_def = ObjFunction.FunctionDef{ + const callback_method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), // TODO: is this ok? .script_name = try parser.gc.copyString("builtin"), @@ -2303,9 +2303,9 @@ pub const ObjList = struct { .generic_types = std.AutoArrayHashMap(*ObjString, *ObjTypeDef).init(parser.gc.allocator), }; - var callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; + const callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; - var callback_type = try parser.gc.type_registry.getTypeDef( + const callback_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = callback_resolved_type, @@ -2319,7 +2319,7 @@ pub const ObjList = struct { callback_type, ); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("sort"), @@ -2331,9 +2331,9 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -2347,7 +2347,7 @@ pub const ObjList = struct { // We omit first arg: it'll be OP_SWAPed in and we already parsed it // It's always the list. - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("clone"), @@ -2359,9 +2359,9 @@ pub const ObjList = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -2533,7 +2533,7 @@ pub const ObjMap = struct { } if (mem.eql(u8, method, "size")) { - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("size"), @@ -2547,9 +2547,9 @@ pub const ObjMap = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -2567,7 +2567,7 @@ pub const ObjMap = struct { try parameters.put(try parser.gc.copyString("at"), self.key_type); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("remove"), @@ -2583,9 +2583,9 @@ pub const ObjMap = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -2596,16 +2596,16 @@ pub const ObjMap = struct { return native_type; } else if (mem.eql(u8, method, "keys")) { - var list_def: ObjList.ListDef = ObjList.ListDef.init( + const list_def: ObjList.ListDef = ObjList.ListDef.init( parser.gc.allocator, self.key_type, ); - var list_def_union: ObjTypeDef.TypeUnion = .{ + const list_def_union: ObjTypeDef.TypeUnion = .{ .List = list_def, }; - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("keys"), @@ -2621,9 +2621,9 @@ pub const ObjMap = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -2634,16 +2634,16 @@ pub const ObjMap = struct { return native_type; } else if (mem.eql(u8, method, "values")) { - var list_def: ObjList.ListDef = ObjList.ListDef.init( + const list_def: ObjList.ListDef = ObjList.ListDef.init( parser.gc.allocator, self.value_type, ); - var list_def_union: ObjTypeDef.TypeUnion = .{ + const list_def_union: ObjTypeDef.TypeUnion = .{ .List = list_def, }; - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("values"), @@ -2659,9 +2659,9 @@ pub const ObjMap = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -2680,7 +2680,7 @@ pub const ObjMap = struct { try callback_parameters.put(try parser.gc.copyString("left"), self.key_type); try callback_parameters.put(try parser.gc.copyString("right"), self.key_type); - var callback_method_def = ObjFunction.FunctionDef{ + const callback_method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), // TODO: is this ok? .script_name = try parser.gc.copyString("builtin"), @@ -2692,9 +2692,9 @@ pub const ObjMap = struct { .generic_types = std.AutoArrayHashMap(*ObjString, *ObjTypeDef).init(parser.gc.allocator), }; - var callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; + const callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; - var callback_type = try parser.gc.type_registry.getTypeDef( + const callback_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = callback_resolved_type, @@ -2708,7 +2708,7 @@ pub const ObjMap = struct { callback_type, ); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("sort"), @@ -2720,9 +2720,9 @@ pub const ObjMap = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -2743,7 +2743,7 @@ pub const ObjMap = struct { obj_map, ); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("diff"), @@ -2755,9 +2755,9 @@ pub const ObjMap = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -2778,7 +2778,7 @@ pub const ObjMap = struct { obj_map, ); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("intersect"), @@ -2790,9 +2790,9 @@ pub const ObjMap = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -2817,7 +2817,7 @@ pub const ObjMap = struct { self.value_type, ); - var callback_method_def = ObjFunction.FunctionDef{ + const callback_method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), // TODO: is this ok? .script_name = try parser.gc.copyString("builtin"), @@ -2829,9 +2829,9 @@ pub const ObjMap = struct { .generic_types = std.AutoArrayHashMap(*ObjString, *ObjTypeDef).init(parser.gc.allocator), }; - var callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; + const callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; - var callback_type = try parser.gc.type_registry.getTypeDef( + const callback_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = callback_resolved_type, @@ -2845,7 +2845,7 @@ pub const ObjMap = struct { callback_type, ); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("forEach"), @@ -2857,9 +2857,9 @@ pub const ObjMap = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); + const native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); try self.methods.put("forEach", native_type); @@ -2939,9 +2939,9 @@ pub const ObjMap = struct { &parser.gc.type_registry, ); - var callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; + const callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; - var callback_type = try parser.gc.type_registry.getTypeDef( + const callback_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = callback_resolved_type, @@ -2955,13 +2955,13 @@ pub const ObjMap = struct { callback_type, ); - var new_map_def = ObjMap.MapDef.init( + const new_map_def = ObjMap.MapDef.init( parser.gc.allocator, generic_key_type, generic_value_type, ); - var new_map_type = ObjTypeDef.TypeUnion{ .Map = new_map_def }; + const new_map_type = ObjTypeDef.TypeUnion{ .Map = new_map_def }; var method_def = ObjFunction.FunctionDef{ .id = map_origin, @@ -2988,9 +2988,9 @@ pub const ObjMap = struct { generic_value_type, ); - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -3015,7 +3015,7 @@ pub const ObjMap = struct { self.value_type, ); - var callback_method_def = ObjFunction.FunctionDef{ + const callback_method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), // TODO: is this ok? .script_name = try parser.gc.copyString("builtin"), @@ -3027,9 +3027,9 @@ pub const ObjMap = struct { .generic_types = std.AutoArrayHashMap(*ObjString, *ObjTypeDef).init(parser.gc.allocator), }; - var callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; + const callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; - var callback_type = try parser.gc.type_registry.getTypeDef( + const callback_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = callback_resolved_type, @@ -3043,7 +3043,7 @@ pub const ObjMap = struct { callback_type, ); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("filter"), @@ -3055,9 +3055,9 @@ pub const ObjMap = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); + const native_type = try parser.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type }); try self.methods.put("filter", native_type); @@ -3093,7 +3093,7 @@ pub const ObjMap = struct { generic_type, ); - var callback_method_def = ObjFunction.FunctionDef{ + const callback_method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), // TODO: is this ok? .script_name = try parser.gc.copyString("builtin"), @@ -3105,9 +3105,9 @@ pub const ObjMap = struct { .generic_types = std.AutoArrayHashMap(*ObjString, *ObjTypeDef).init(parser.gc.allocator), }; - var callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; + const callback_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = callback_method_def }; - var callback_type = try parser.gc.type_registry.getTypeDef( + const callback_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = callback_resolved_type, @@ -3128,7 +3128,7 @@ pub const ObjMap = struct { var generic_types = std.AutoArrayHashMap(*ObjString, *ObjTypeDef).init(parser.gc.allocator); try generic_types.put(try parser.gc.copyString("T"), generic_type); - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = reduce_origin, .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("reduce"), @@ -3140,9 +3140,9 @@ pub const ObjMap = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -3156,7 +3156,7 @@ pub const ObjMap = struct { // We omit first arg: it'll be OP_SWAPed in and we already parsed it // It's always the list. - var method_def = ObjFunction.FunctionDef{ + const method_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try parser.gc.copyString("builtin"), .name = try parser.gc.copyString("clone"), @@ -3168,9 +3168,9 @@ pub const ObjMap = struct { .function_type = .Extern, }; - var resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; + const resolved_type: ObjTypeDef.TypeUnion = .{ .Function = method_def }; - var native_type = try parser.gc.type_registry.getTypeDef( + const native_type = try parser.gc.type_registry.getTypeDef( ObjTypeDef{ .def_type = .Function, .resolved_type = resolved_type, @@ -3599,7 +3599,7 @@ pub const ObjTypeDef = struct { const resolved_type_union = ObjTypeDef.TypeUnion{ .Object = resolved }; - var new_object = ObjTypeDef{ + const new_object = ObjTypeDef{ .def_type = .Object, .optional = self.optional, .resolved_type = resolved_type_union, @@ -3625,7 +3625,7 @@ pub const ObjTypeDef = struct { ); } - var new_list_def = ObjList.ListDef{ + const new_list_def = ObjList.ListDef{ .item_type = try (try old_list_def.item_type.populateGenerics( where, origin, @@ -3636,7 +3636,7 @@ pub const ObjTypeDef = struct { .methods = methods, }; - var new_resolved = ObjTypeDef.TypeUnion{ .List = new_list_def }; + const new_resolved = ObjTypeDef.TypeUnion{ .List = new_list_def }; const new_list = ObjTypeDef{ .def_type = .List, @@ -3664,7 +3664,7 @@ pub const ObjTypeDef = struct { ); } - var new_map_def = ObjMap.MapDef{ + const new_map_def = ObjMap.MapDef{ .key_type = try old_map_def.key_type.populateGenerics( where, origin, @@ -3726,7 +3726,7 @@ pub const ObjTypeDef = struct { } } - var new_fun_def = ObjFunction.FunctionDef{ + const new_fun_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .name = old_fun_def.name, .script_name = old_fun_def.script_name, @@ -3876,7 +3876,7 @@ pub const ObjTypeDef = struct { if (object_def.anonymous) { try writer.writeAll("obj{ "); var it = object_def.fields.iterator(); - var count = object_def.fields.count(); + const count = object_def.fields.count(); var i: usize = 0; while (it.next()) |kv| { try kv.value_ptr.*.toStringRaw(writer, qualified); @@ -3942,7 +3942,7 @@ pub const ObjTypeDef = struct { if (object_def.anonymous) { try writer.writeAll(".{ "); var it = object_def.fields.iterator(); - var count = object_def.fields.count(); + const count = object_def.fields.count(); var i: usize = 0; while (it.next()) |kv| { try kv.value_ptr.*.toStringRaw(writer, qualified); @@ -4150,10 +4150,10 @@ pub const ObjTypeDef = struct { return self; } - var instance_type = try type_registry.getTypeDef( + const instance_type = try type_registry.getTypeDef( switch (self.def_type) { .Object => object: { - var resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ + const resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ .ObjectInstance = try self.cloneNonOptional(type_registry), }; @@ -4164,7 +4164,7 @@ pub const ObjTypeDef = struct { }; }, .Protocol => protocol: { - var resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ + const resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ .ProtocolInstance = try self.cloneNonOptional(type_registry), }; @@ -4175,7 +4175,7 @@ pub const ObjTypeDef = struct { }; }, .Enum => enum_instance: { - var resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ + const resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ .EnumInstance = try self.cloneNonOptional(type_registry), }; @@ -4478,8 +4478,8 @@ pub fn objToString(writer: *const std.ArrayList(u8).Writer, obj: *Obj) (Allocato ObjEnum.cast(obj).?.name.string, }), .EnumInstance => enum_instance: { - var instance: *ObjEnumInstance = ObjEnumInstance.cast(obj).?; - var enum_: *ObjEnum = instance.enum_ref; + const instance: *ObjEnumInstance = ObjEnumInstance.cast(obj).?; + const enum_: *ObjEnum = instance.enum_ref; break :enum_instance try writer.print("{s}.{s}", .{ enum_.name.string, @@ -4490,7 +4490,7 @@ pub fn objToString(writer: *const std.ArrayList(u8).Writer, obj: *Obj) (Allocato const bound: *ObjBoundMethod = ObjBoundMethod.cast(obj).?; if (bound.closure) |closure| { - var closure_name: []const u8 = closure.function.name.string; + const closure_name: []const u8 = closure.function.name.string; try writer.writeAll("bound method: "); try valueToString(writer, bound.receiver); @@ -4506,12 +4506,12 @@ pub fn objToString(writer: *const std.ArrayList(u8).Writer, obj: *Obj) (Allocato } }, .Native => { - var native: *ObjNative = ObjNative.cast(obj).?; + const native: *ObjNative = ObjNative.cast(obj).?; try writer.print("native: 0x{x}", .{@intFromPtr(native)}); }, .UserData => { - var userdata: *ObjUserData = ObjUserData.cast(obj).?; + const userdata: *ObjUserData = ObjUserData.cast(obj).?; try writer.print("userdata: 0x{x}", .{userdata.userdata}); }, diff --git a/src/parser.zig b/src/parser.zig index 2b71cbb3..63cf7e72 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -587,7 +587,7 @@ pub const Parser = struct { } fn beginFrame(self: *Self, function_type: FunctionType, function_node: *FunctionNode, this: ?*ObjTypeDef) !void { - var enclosing = self.current; + const enclosing = self.current; self.current = try self.gc.allocator.create(Frame); self.current.?.* = Frame{ .locals = [_]Local{undefined} ** 255, @@ -615,12 +615,12 @@ pub const Parser = struct { }, .EntryPoint, .ScriptEntryPoint => { // `args` is [str] - var list_def: ObjList.ListDef = ObjList.ListDef.init( + const list_def: ObjList.ListDef = ObjList.ListDef.init( self.gc.allocator, try self.gc.type_registry.getTypeDef(.{ .def_type = .String }), ); - var list_union: ObjTypeDef.TypeUnion = .{ .List = list_def }; + const list_union: ObjTypeDef.TypeUnion = .{ .List = list_def }; local.type_def = try self.gc.type_registry.getTypeDef(ObjTypeDef{ .def_type = .List, .resolved_type = list_union }); }, @@ -684,7 +684,7 @@ pub const Parser = struct { } } - var current_node = self.current.?.function_node; + const current_node = self.current.?.function_node; self.current = self.current.?.enclosing; return current_node; @@ -730,7 +730,7 @@ pub const Parser = struct { } fn closeScope(self: *Self, upto_depth: usize) !std.ArrayList(OpCode) { - var current = self.current.?; + const current = self.current.?; var closing = std.ArrayList(OpCode).init(self.gc.allocator); var local_count = current.local_count; @@ -864,7 +864,7 @@ pub const Parser = struct { constant: bool, relation: PlaceholderDef.PlaceholderRelation, ) anyerror!void { - var child_placeholder: PlaceholderDef = child.resolved_type.?.Placeholder; + const child_placeholder: PlaceholderDef = child.resolved_type.?.Placeholder; if (BuildOptions.debug_placeholders) { std.debug.print( @@ -1100,12 +1100,12 @@ pub const Parser = struct { // We can't create a field access placeholder without a name assert(child_placeholder.name != null); - var enum_def: ObjEnum.EnumDef = resolved_type.resolved_type.?.Enum; + const enum_def: ObjEnum.EnumDef = resolved_type.resolved_type.?.Enum; // Search for a case matching the placeholder for (enum_def.cases.items) |case| { if (mem.eql(u8, case, child_placeholder.name.?.string)) { - var enum_instance_def: ObjTypeDef.TypeUnion = .{ .EnumInstance = resolved_type }; + const enum_instance_def: ObjTypeDef.TypeUnion = .{ .EnumInstance = resolved_type }; try self.resolvePlaceholder(child, try self.gc.type_registry.getTypeDef(.{ .def_type = .EnumInstance, @@ -1142,7 +1142,7 @@ pub const Parser = struct { } // Assignment relation from a once Placeholder and now Object/Enum is creating an instance - var child_type: *ObjTypeDef = try resolved_type.toInstance(self.gc.allocator, &self.gc.type_registry); + const child_type: *ObjTypeDef = try resolved_type.toInstance(self.gc.allocator, &self.gc.type_registry); // Is child type matching the parent? try self.resolvePlaceholder(child, child_type, false); @@ -1205,7 +1205,7 @@ pub const Parser = struct { return; } - var placeholder_def: PlaceholderDef = placeholder.resolved_type.?.Placeholder; + const placeholder_def: PlaceholderDef = placeholder.resolved_type.?.Placeholder; if (BuildOptions.debug_placeholders) { std.debug.print( @@ -1282,7 +1282,7 @@ pub const Parser = struct { fn declaration(self: *Self) anyerror!?*ParseNode { const global_scope = self.current.?.scope_depth == 0; - var docblock: ?Token = if (global_scope and try self.match(.Docblock)) + const docblock: ?Token = if (global_scope and try self.match(.Docblock)) self.parser.previous_token.? else null; @@ -1521,7 +1521,7 @@ pub const Parser = struct { } else if (try self.match(.Throw)) { const start_location = self.parser.previous_token.?; // For now we don't care about the type. Later if we have `Error` type of data, we'll type check this - var error_value = try self.expression(false); + const error_value = try self.expression(false); try self.consume(.Semicolon, "Expected `;` after `throw` expression."); @@ -1587,7 +1587,7 @@ pub const Parser = struct { try qualified_object_name.writer().print("{s}.{s}", .{ qualifier, object_name.lexeme }); // Create a placeholder for self-reference which will be resolved at the end when declaring the object - var placeholder_index = try self.declarePlaceholder(object_name, null); + const placeholder_index = try self.declarePlaceholder(object_name, null); var object_placeholder = self.globals.items[placeholder_index].type_def; var object_def = ObjObject.ObjectDef.init( @@ -1601,7 +1601,7 @@ pub const Parser = struct { object_def.conforms_to.deinit(); object_def.conforms_to = protocols; - var resolved_type = ObjTypeDef.TypeUnion{ .Object = object_def }; + const resolved_type = ObjTypeDef.TypeUnion{ .Object = object_def }; // Create type var object_type: ObjTypeDef = .{ @@ -1609,7 +1609,7 @@ pub const Parser = struct { .resolved_type = resolved_type, }; - var object_frame: ObjectFrame = .{ + const object_frame: ObjectFrame = .{ .name = object_name, .type_def = object_placeholder, .generics = &object_type.resolved_type.?.Object.generic_types, @@ -1693,7 +1693,7 @@ pub const Parser = struct { function_node.static = static; } - var method_name: []const u8 = method_node.type_def.?.resolved_type.?.Function.name.string; + const method_name: []const u8 = method_node.type_def.?.resolved_type.?.Function.name.string; if (fields.get(method_name) != null) { self.reportError(.property_already_exists, "A member with that name already exists."); @@ -1906,17 +1906,17 @@ pub const Parser = struct { try qualified_protocol_name.writer().print("{s}.{s}", .{ qualifier, protocol_name.lexeme }); // Create a placeholder for self-reference which will be resolved at the end when declaring the object - var placeholder_index = try self.declarePlaceholder(protocol_name, null); + const placeholder_index = try self.declarePlaceholder(protocol_name, null); var protocol_placeholder = self.globals.items[placeholder_index].type_def; - var protocol_def = ObjObject.ProtocolDef.init( + const protocol_def = ObjObject.ProtocolDef.init( self.gc.allocator, protocol_name, try self.gc.copyString(protocol_name.lexeme), try self.gc.copyString(qualified_protocol_name.items), ); - var resolved_type = ObjTypeDef.TypeUnion{ .Protocol = protocol_def }; + const resolved_type = ObjTypeDef.TypeUnion{ .Protocol = protocol_def }; // Create type var protocol_type: ObjTypeDef = .{ @@ -1939,14 +1939,14 @@ pub const Parser = struct { try self.consume(.Fun, "Expected method definition"); const method_name_token = self.parser.current_token.?; - var method_node: *ParseNode = try self.method( + const method_node: *ParseNode = try self.method( true, try protocol_placeholder.toInstance(self.gc.allocator, &self.gc.type_registry), ); try self.consume(.Semicolon, "Expected `;` after method definition"); - var method_name: []const u8 = method_node.type_def.?.resolved_type.?.Function.name.string; + const method_name: []const u8 = method_node.type_def.?.resolved_type.?.Function.name.string; if (fields.get(method_name) != null) { self.reportError(.property_already_exists, "A method with that name already exists."); @@ -2164,7 +2164,7 @@ pub const Parser = struct { try self.consume(.Semicolon, "Expected `;` after for loop variables."); - var condition = try self.expression(false); + const condition = try self.expression(false); try self.consume(.Semicolon, "Expected `;` after for loop condition."); @@ -2296,7 +2296,7 @@ pub const Parser = struct { try self.consume(.LeftParen, "Expected `(` after `while`."); - var condition = try self.expression(false); + const condition = try self.expression(false); try self.consume(.RightParen, "Expected `)` after `while` condition."); @@ -2336,7 +2336,7 @@ pub const Parser = struct { try self.consume(.LeftParen, "Expected `(` after `until`."); - var condition = try self.expression(false); + const condition = try self.expression(false); try self.consume(.RightParen, "Expected `)` after `until` condition."); @@ -2563,7 +2563,7 @@ pub const Parser = struct { // If next token is `=`, means the identifier wasn't a user type but the variable name // and the type needs to be inferred if (!inferred_declaration) { - var user_type_name: Token = self.parser.previous_token.?.clone(); + const user_type_name: Token = self.parser.previous_token.?.clone(); // Is it a generic type defined in enclosing functions or object? if (self.resolveGeneric(try self.gc.copyString(self.parser.previous_token.?.lexeme))) |generic_type| { @@ -2827,7 +2827,7 @@ pub const Parser = struct { try self.consume(.Semicolon, "Expected `;` after import."); - var import = if (!self.reporter.had_error) + const import = if (!self.reporter.had_error) try self.importScript( file_name, if (prefix) |pr| pr.lexeme else null, @@ -2867,7 +2867,7 @@ pub const Parser = struct { or try self.checkAhead(.Dot, 0))) { // zig fmt: on try self.consume(.Identifier, "Expected identifier after `export`."); - var identifier = self.parser.previous_token.?; + const identifier = self.parser.previous_token.?; // Search for a global with that name if (try self.resolveGlobal(null, identifier)) |slot| { @@ -2938,7 +2938,7 @@ pub const Parser = struct { } try self.consume(.Identifier, "Expected function name."); - var name_token: Token = self.parser.previous_token.?; + const name_token: Token = self.parser.previous_token.?; const is_main = std.mem.eql(u8, name_token.lexeme, "main") and self.current.?.function_node.node.type_def != null and self.current.?.function_node.node.type_def.?.resolved_type.?.Function.function_type == .ScriptEntryPoint; @@ -3041,12 +3041,12 @@ pub const Parser = struct { } fn parseListType(self: *Self, generic_types: ?std.AutoArrayHashMap(*ObjString, *ObjTypeDef)) !*ObjTypeDef { - var list_item_type: *ObjTypeDef = try self.parseTypeDef(generic_types, true); + const list_item_type: *ObjTypeDef = try self.parseTypeDef(generic_types, true); try self.consume(.RightBracket, "Expected `]` after list type."); - var list_def = ObjList.ListDef.init(self.gc.allocator, list_item_type); - var resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ + const list_def = ObjList.ListDef.init(self.gc.allocator, list_item_type); + const resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ .List = list_def, }; @@ -3075,16 +3075,16 @@ pub const Parser = struct { } fn parseMapType(self: *Self, generic_types: ?std.AutoArrayHashMap(*ObjString, *ObjTypeDef)) !*ObjTypeDef { - var key_type: *ObjTypeDef = try self.parseTypeDef(generic_types, true); + const key_type: *ObjTypeDef = try self.parseTypeDef(generic_types, true); try self.consume(.Comma, "Expected `,` after key type."); - var value_type: *ObjTypeDef = try self.parseTypeDef(generic_types, true); + const value_type: *ObjTypeDef = try self.parseTypeDef(generic_types, true); try self.consume(.RightBrace, "Expected `}` after value type."); - var map_def = ObjMap.MapDef.init(self.gc.allocator, key_type, value_type); - var resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ + const map_def = ObjMap.MapDef.init(self.gc.allocator, key_type, value_type); + const resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ .Map = map_def, }; @@ -3133,7 +3133,7 @@ pub const Parser = struct { enum_case_type = try enum_case_type.toInstance(self.gc.allocator, &self.gc.type_registry); try self.consume(.Identifier, "Expected enum name."); - var enum_name: Token = self.parser.previous_token.?.clone(); + const enum_name: Token = self.parser.previous_token.?.clone(); // Qualified name to avoid cross script collision const qualifier = try std.mem.replaceOwned(u8, self.gc.allocator, self.script_name, "/", "."); @@ -3142,14 +3142,14 @@ pub const Parser = struct { defer qualified_name.deinit(); try qualified_name.writer().print("{s}.{s}", .{ qualifier, enum_name.lexeme }); - var enum_def: ObjEnum.EnumDef = ObjEnum.EnumDef.init( + const enum_def: ObjEnum.EnumDef = ObjEnum.EnumDef.init( self.gc.allocator, try self.gc.copyString(enum_name.lexeme), try self.gc.copyString(qualified_name.items), enum_case_type, ); - var enum_resolved: ObjTypeDef.TypeUnion = .{ .Enum = enum_def }; + const enum_resolved: ObjTypeDef.TypeUnion = .{ .Enum = enum_def }; var enum_type: *ObjTypeDef = try self.gc.type_registry.getTypeDef( .{ @@ -3254,7 +3254,7 @@ pub const Parser = struct { defer qualified_name.deinit(); try qualified_name.writer().print("{s}.anonymous", .{qualifier}); - var object_def = ObjObject.ObjectDef.init( + const object_def = ObjObject.ObjectDef.init( self.gc.allocator, start_location, try self.gc.copyString("anonymous"), @@ -3262,7 +3262,7 @@ pub const Parser = struct { true, ); - var resolved_type = ObjTypeDef.TypeUnion{ .Object = object_def }; + const resolved_type = ObjTypeDef.TypeUnion{ .Object = object_def }; // We build the object type has we parse its instanciation var object_type: ObjTypeDef = .{ @@ -3452,7 +3452,7 @@ pub const Parser = struct { _ = try self.advance(); } - var prefixRule: ?ParseFn = getRule(self.parser.previous_token.?.token_type).prefix; + const prefixRule: ?ParseFn = getRule(self.parser.previous_token.?.token_type).prefix; if (prefixRule == null) { self.reportError(.syntax, "Expected expression."); @@ -3460,14 +3460,14 @@ pub const Parser = struct { return CompileError.Unrecoverable; } - var canAssign: bool = @intFromEnum(precedence) <= @intFromEnum(Precedence.Assignment); + const canAssign: bool = @intFromEnum(precedence) <= @intFromEnum(Precedence.Assignment); var node: *ParseNode = try prefixRule.?(self, canAssign); while (@intFromEnum(getRule(self.parser.current_token.?.token_type).precedence) >= @intFromEnum(precedence)) { // Patch optional jumps if (self.opt_jumps) |jumps| { assert(jumps.items.len > 0); - var first_jump: Precedence = jumps.items[0]; + const first_jump: Precedence = jumps.items[0]; if (@intFromEnum(getRule(self.parser.current_token.?.token_type).precedence) < @intFromEnum(first_jump)) { jumps.deinit(); @@ -3483,7 +3483,7 @@ pub const Parser = struct { _ = try self.advance(); - var infixRule: InfixParseFn = getRule(self.parser.previous_token.?.token_type).infix.?; + const infixRule: InfixParseFn = getRule(self.parser.previous_token.?.token_type).infix.?; node = try infixRule(self, canAssign, node); } @@ -3700,7 +3700,7 @@ pub const Parser = struct { const yield_placeholder_resolved_type: ObjTypeDef.TypeUnion = .{ .Placeholder = PlaceholderDef.init(self.gc.allocator, self.parser.previous_token.?), }; - var yield_placeholder = try self.gc.type_registry.getTypeDef( + const yield_placeholder = try self.gc.type_registry.getTypeDef( .{ .def_type = .Placeholder, .resolved_type = yield_placeholder_resolved_type, @@ -3806,7 +3806,7 @@ pub const Parser = struct { return CompileError.Unrecoverable; } - var constant = try self.gc.allocateObject( + const constant = try self.gc.allocateObject( ObjPattern, .{ .source = source, @@ -4028,9 +4028,9 @@ pub const Parser = struct { fn unary(self: *Self, _: bool) anyerror!*ParseNode { const start_location = self.parser.previous_token.?; - var operator: TokenType = self.parser.previous_token.?.token_type; + const operator: TokenType = self.parser.previous_token.?.token_type; - var left: *ParseNode = try self.parsePrecedence(.Unary, false); + const left: *ParseNode = try self.parsePrecedence(.Unary, false); var node = try self.gc.allocator.create(UnaryNode); node.* = UnaryNode{ @@ -4135,7 +4135,7 @@ pub const Parser = struct { if (callee.type_def == null or callee.type_def.?.def_type != .Placeholder) { self.reporter.reportErrorAt(.callable, callee.location, "Can't be called"); } else { - var placeholder_resolved_type: ObjTypeDef.TypeUnion = .{ + const placeholder_resolved_type: ObjTypeDef.TypeUnion = .{ .Placeholder = PlaceholderDef.init(self.gc.allocator, node.node.location), }; @@ -4202,8 +4202,8 @@ pub const Parser = struct { const start_location = callee.location; try self.consume(.Identifier, "Expected property name after `.`"); - var member_name_token: Token = self.parser.previous_token.?; - var member_name: []const u8 = member_name_token.lexeme; + const member_name_token: Token = self.parser.previous_token.?; + const member_name: []const u8 = member_name_token.lexeme; var node = try self.gc.allocator.create(DotNode); node.* = DotNode{ @@ -4304,7 +4304,7 @@ pub const Parser = struct { }; placeholder_resolved_type.Placeholder.name = try self.gc.copyString(member_name_token.lexeme); - var placeholder: *ObjTypeDef = try self.gc.type_registry.getTypeDef(.{ + const placeholder: *ObjTypeDef = try self.gc.type_registry.getTypeDef(.{ .optional = false, .def_type = .Placeholder, .resolved_type = placeholder_resolved_type, @@ -4386,7 +4386,7 @@ pub const Parser = struct { }; placeholder_resolved_type.Placeholder.name = try self.gc.copyString(member_name); - var placeholder: *ObjTypeDef = try self.gc.type_registry.getTypeDef(.{ + const placeholder: *ObjTypeDef = try self.gc.type_registry.getTypeDef(.{ .optional = false, .def_type = .Placeholder, .resolved_type = placeholder_resolved_type, @@ -4438,7 +4438,7 @@ pub const Parser = struct { } }, .ProtocolInstance => { - var protocol: *ObjTypeDef = callee.type_def.?.resolved_type.?.ProtocolInstance; + const protocol: *ObjTypeDef = callee.type_def.?.resolved_type.?.ProtocolInstance; var protocol_def: ObjObject.ProtocolDef = protocol.resolved_type.?.Protocol; var method_type: ?*ObjTypeDef = protocol_def.methods.get(member_name); @@ -4478,11 +4478,11 @@ pub const Parser = struct { for (enum_def.cases.items, 0..) |case, index| { if (mem.eql(u8, case, member_name)) { - var enum_instance_resolved_type: ObjTypeDef.TypeUnion = .{ + const enum_instance_resolved_type: ObjTypeDef.TypeUnion = .{ .EnumInstance = callee.type_def.?, }; - var enum_instance: *ObjTypeDef = try self.gc.type_registry.getTypeDef(.{ + const enum_instance: *ObjTypeDef = try self.gc.type_registry.getTypeDef(.{ .optional = false, .def_type = .EnumInstance, .resolved_type = enum_instance_resolved_type, @@ -4622,7 +4622,7 @@ pub const Parser = struct { fn and_(self: *Self, _: bool, left: *ParseNode) anyerror!*ParseNode { const start_location = left.location; - var right: *ParseNode = try self.parsePrecedence(.And, false); + const right: *ParseNode = try self.parsePrecedence(.And, false); var node = try self.gc.allocator.create(BinaryNode); node.* = BinaryNode{ @@ -4644,7 +4644,7 @@ pub const Parser = struct { fn or_(self: *Self, _: bool, left: *ParseNode) anyerror!*ParseNode { const start_location = left.location; - var right: *ParseNode = try self.parsePrecedence(.And, false); + const right: *ParseNode = try self.parsePrecedence(.And, false); var node = try self.gc.allocator.create(BinaryNode); node.* = BinaryNode{ @@ -4776,11 +4776,11 @@ pub const Parser = struct { if (!type_def.optional) { switch (type_def.def_type) { .Placeholder => { - var placeholder_resolved_type: ObjTypeDef.TypeUnion = .{ + const placeholder_resolved_type: ObjTypeDef.TypeUnion = .{ .Placeholder = PlaceholderDef.init(self.gc.allocator, self.parser.previous_token.?), }; - var placeholder = try self.gc.type_registry.getTypeDef( + const placeholder = try self.gc.type_registry.getTypeDef( .{ .def_type = .Placeholder, .resolved_type = placeholder_resolved_type, @@ -4846,7 +4846,7 @@ pub const Parser = struct { if (item_type == null or try self.match(.Comma)) { var common_type: ?*ObjTypeDef = null; while (!(try self.match(.RightBracket)) and !(try self.match(.Eof))) { - var actual_item: *ParseNode = try self.expression(false); + const actual_item: *ParseNode = try self.expression(false); try items.append(actual_item); @@ -4889,11 +4889,11 @@ pub const Parser = struct { item_type = try self.gc.type_registry.getTypeDef(.{ .def_type = .Void }); } - var list_def = ObjList.ListDef.init(self.gc.allocator, item_type.?); + const list_def = ObjList.ListDef.init(self.gc.allocator, item_type.?); - var resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ .List = list_def }; + const resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ .List = list_def }; - var list_type: *ObjTypeDef = try self.gc.type_registry.getTypeDef( + const list_type: *ObjTypeDef = try self.gc.type_registry.getTypeDef( .{ .def_type = .List, .resolved_type = resolved_type, @@ -4937,9 +4937,9 @@ pub const Parser = struct { var common_key_type: ?*ObjTypeDef = null; var common_value_type: ?*ObjTypeDef = null; while (!(try self.match(.RightBrace)) and !(try self.match(.Eof))) { - var key: *ParseNode = try self.expression(false); + const key: *ParseNode = try self.expression(false); try self.consume(.Colon, "Expected `:` after key."); - var value: *ParseNode = try self.expression(false); + const value: *ParseNode = try self.expression(false); try keys.append(key); try values.append(value); @@ -4995,11 +4995,11 @@ pub const Parser = struct { value_type = try self.gc.type_registry.getTypeDef(.{ .def_type = .Void }); } - var map_def = ObjMap.MapDef.init(self.gc.allocator, key_type.?, value_type.?); + const map_def = ObjMap.MapDef.init(self.gc.allocator, key_type.?, value_type.?); - var resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ .Map = map_def }; + const resolved_type: ObjTypeDef.TypeUnion = ObjTypeDef.TypeUnion{ .Map = map_def }; - var map_type: *ObjTypeDef = try self.gc.type_registry.getTypeDef( + const map_type: *ObjTypeDef = try self.gc.type_registry.getTypeDef( .{ .optional = try self.match(.Question), .def_type = .Map, @@ -5043,7 +5043,7 @@ pub const Parser = struct { .def_type = .Function, }; - var function_def = ObjFunction.FunctionDef{ + const function_def = ObjFunction.FunctionDef{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try self.gc.copyString(self.script_name), .name = if (name) |uname| @@ -5059,7 +5059,7 @@ pub const Parser = struct { .resolved_generics = null, }; - var function_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = function_def }; + const function_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = function_def }; function_typedef.resolved_type = function_resolved_type; @@ -5135,9 +5135,9 @@ pub const Parser = struct { ); } - var param_type: *ObjTypeDef = try (try self.parseTypeDef(function_node.node.type_def.?.resolved_type.?.Function.generic_types, true)).toInstance(self.gc.allocator, &self.gc.type_registry); + const param_type: *ObjTypeDef = try (try self.parseTypeDef(function_node.node.type_def.?.resolved_type.?.Function.generic_types, true)).toInstance(self.gc.allocator, &self.gc.type_registry); - var slot: usize = try self.parseVariable( + const slot: usize = try self.parseVariable( false, param_type, true, // function arguments are constant @@ -5146,11 +5146,11 @@ pub const Parser = struct { var arg_name: *ObjString = undefined; if (self.current.?.scope_depth > 0) { - var local: Local = self.current.?.locals[slot]; + const local: Local = self.current.?.locals[slot]; arg_name = local.name; try function_node.node.type_def.?.resolved_type.?.Function.parameters.put(local.name, local.type_def); } else { - var global: Global = self.globals.items[slot]; + const global: Global = self.globals.items[slot]; arg_name = global.name; try function_node.node.type_def.?.resolved_type.?.Function.parameters.put(global.name, global.type_def); } @@ -5810,10 +5810,10 @@ pub const Parser = struct { self.reportErrorAtCurrent(.arguments_count, "Can't have more than 255 arguments."); } - var param_type: *ObjTypeDef = try self.parseTypeDef(merged_generic_types, true); + const param_type: *ObjTypeDef = try self.parseTypeDef(merged_generic_types, true); try self.consume(.Identifier, "Expected argument name"); - var param_name: []const u8 = self.parser.previous_token.?.lexeme; - var arg_name = try self.gc.copyString(param_name); + const param_name: []const u8 = self.parser.previous_token.?.lexeme; + const arg_name = try self.gc.copyString(param_name); try parameters.put(arg_name, param_type); @@ -5874,7 +5874,7 @@ pub const Parser = struct { .optional = try self.match(.Question), }; - var function_def: ObjFunction.FunctionDef = .{ + const function_def: ObjFunction.FunctionDef = .{ .id = ObjFunction.FunctionDef.nextId(), .script_name = try self.gc.copyString(self.script_name), .name = name orelse try self.gc.copyString("anonymous"), @@ -5887,7 +5887,7 @@ pub const Parser = struct { .error_types = if (error_types != null) error_types.?.items else null, }; - var function_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = function_def }; + const function_resolved_type: ObjTypeDef.TypeUnion = .{ .Function = function_def }; function_typedef.resolved_type = function_resolved_type; @@ -5895,7 +5895,7 @@ pub const Parser = struct { } fn parseUserType(self: *Self, instance: bool) !*ObjTypeDef { - var user_type_name: Token = self.parser.previous_token.?.clone(); + const user_type_name: Token = self.parser.previous_token.?.clone(); var var_type: ?*ObjTypeDef = null; var global_slot: ?usize = null; @@ -5969,7 +5969,7 @@ pub const Parser = struct { } pub fn parseTypeDefFrom(self: *Self, source: []const u8) anyerror!*ObjTypeDef { - var type_scanner = Scanner.init(self.gc.allocator, self.script_name, source); + const type_scanner = Scanner.init(self.gc.allocator, self.script_name, source); // Replace parser scanner with one that only looks at that substring const scanner = self.scanner; self.scanner = type_scanner; @@ -6063,7 +6063,7 @@ pub const Parser = struct { defer qualified_name.deinit(); try qualified_name.writer().print("{s}.anonymous", .{qualifier}); - var object_def = ObjObject.ObjectDef.init( + const object_def = ObjObject.ObjectDef.init( self.gc.allocator, start_location, try self.gc.copyString("anonymous"), @@ -6071,7 +6071,7 @@ pub const Parser = struct { true, ); - var resolved_type = ObjTypeDef.TypeUnion{ .Object = object_def }; + const resolved_type = ObjTypeDef.TypeUnion{ .Object = object_def }; var object_type: ObjTypeDef = .{ .def_type = .Object, @@ -6160,14 +6160,14 @@ pub const Parser = struct { } fn declareVariable(self: *Self, variable_type: *ObjTypeDef, name_token: ?Token, constant: bool, check_name: bool) !usize { - var name: Token = name_token orelse self.parser.previous_token.?; + const name: Token = name_token orelse self.parser.previous_token.?; if (self.current.?.scope_depth > 0) { // Check a local with the same name doesn't exists if (self.current.?.local_count > 0) { var i: usize = self.current.?.local_count - 1; while (check_name and i >= 0) : (i -= 1) { - var local: *Local = &self.current.?.locals[i]; + const local: *Local = &self.current.?.locals[i]; if (local.depth != -1 and local.depth < self.current.?.scope_depth) { break; @@ -6372,11 +6372,11 @@ pub const Parser = struct { } fn addUpvalue(self: *Self, frame: *Frame, index: usize, is_local: bool) !usize { - var upvalue_count: u8 = frame.upvalue_count; + const upvalue_count: u8 = frame.upvalue_count; var i: usize = 0; while (i < upvalue_count) : (i += 1) { - var upvalue: *UpValue = &frame.upvalues[i]; + const upvalue: *UpValue = &frame.upvalues[i]; if (upvalue.index == index and upvalue.is_local == is_local) { return i; } @@ -6399,13 +6399,13 @@ pub const Parser = struct { return null; } - var local: ?usize = try self.resolveLocal(frame.enclosing.?, name); + const local: ?usize = try self.resolveLocal(frame.enclosing.?, name); if (local) |resolved| { frame.enclosing.?.locals[resolved].is_captured = true; return try self.addUpvalue(frame, resolved, true); } - var upvalue: ?usize = try self.resolveUpvalue(frame.enclosing.?, name); + const upvalue: ?usize = try self.resolveUpvalue(frame.enclosing.?, name); if (upvalue) |resolved| { return try self.addUpvalue(frame, resolved, false); } diff --git a/src/scanner.zig b/src/scanner.zig index 1db9bd04..1c357bab 100644 --- a/src/scanner.zig +++ b/src/scanner.zig @@ -53,7 +53,7 @@ pub const Scanner = struct { return self.makeToken(.Eof, null, null, null); } - var char: u8 = self.advance(); + const char: u8 = self.advance(); return try switch (char) { 'b' => self.identifier(), 'a', 'c'...'z', 'A'...'Z' => self.identifier(), @@ -133,7 +133,7 @@ pub const Scanner = struct { fn skipWhitespaces(self: *Self) void { while (true) { - var char: u8 = self.peek(); + const char: u8 = self.peek(); switch (char) { ' ', '\r', '\t' => _ = self.advance(), @@ -181,7 +181,7 @@ pub const Scanner = struct { while (!self.isEOF()) { while (!self.isEOF()) { - var char: u8 = self.peek(); + const char: u8 = self.peek(); if (char == '\n') { self.current.line += 1; diff --git a/src/string_parser.zig b/src/string_parser.zig index 88150f84..beecc2de 100644 --- a/src/string_parser.zig +++ b/src/string_parser.zig @@ -122,16 +122,16 @@ pub const StringParser = struct { } fn interpolation(self: *Self) !void { - var expr: []const u8 = self.source[self.offset..]; + const expr: []const u8 = self.source[self.offset..]; var expr_scanner = Scanner.init(self.parser.gc.allocator, self.parser.script_name, expr); expr_scanner.line_offset = self.line_offset; expr_scanner.column_offset = self.column_offset; // Replace parser scanner with one that only looks at that substring - var scanner = self.parser.scanner; + const scanner = self.parser.scanner; self.parser.scanner = expr_scanner; - var parser = self.parser.parser; + const parser = self.parser.parser; self.parser.parser = ParserState.init(self.parser.gc.allocator); try self.parser.advance(); diff --git a/src/vm.zig b/src/vm.zig index 03c6ff04..76cc0703 100644 --- a/src/vm.zig +++ b/src/vm.zig @@ -162,7 +162,7 @@ pub const Fiber = struct { }; if (stack_slice != null) { - std.mem.copy(Value, self.stack, stack_slice.?); + @memcpy(self.stack, stack_slice.?); self.stack_top = @as([*]Value, @ptrCast(self.stack[stack_slice.?.len..])); } else { @@ -230,7 +230,7 @@ pub const Fiber = struct { .OP_FIBER_FOREACH => { _ = vm.pop(); - var value_slot: *Value = @ptrCast(vm.current_fiber.stack_top - 2); + const value_slot: *Value = @ptrCast(vm.current_fiber.stack_top - 2); value_slot.* = top; }, @@ -316,7 +316,7 @@ pub const Fiber = struct { // We don't care about the returned value _ = vm.pop(); - var value_slot: *Value = @ptrCast(vm.current_fiber.stack_top - 2); + const value_slot: *Value = @ptrCast(vm.current_fiber.stack_top - 2); value_slot.* = Value.Null; }, @@ -351,9 +351,9 @@ pub const VM = struct { ffi: FFI, pub fn init(gc: *GarbageCollector, import_registry: *ImportRegistry, flavor: RunFlavor) !Self { - var main_fiber = try gc.allocator.create(Fiber); + const main_fiber = try gc.allocator.create(Fiber); - var self: Self = .{ + const self: Self = .{ .gc = gc, .import_registry = import_registry, .globals = std.ArrayList(Value).init(gc.allocator), @@ -374,7 +374,7 @@ pub const VM = struct { } pub fn cliArgs(self: *Self, args: ?[][:0]u8) !*ObjList { - var list_def: ObjList.ListDef = ObjList.ListDef.init( + const list_def: ObjList.ListDef = ObjList.ListDef.init( self.gc.allocator, try self.gc.allocateObject( ObjTypeDef, @@ -382,11 +382,11 @@ pub const VM = struct { ), ); - var list_def_union: ObjTypeDef.TypeUnion = .{ + const list_def_union: ObjTypeDef.TypeUnion = .{ .List = list_def, }; - var list_def_type: *ObjTypeDef = try self.gc.allocateObject( + const list_def_type: *ObjTypeDef = try self.gc.allocateObject( ObjTypeDef, ObjTypeDef{ .def_type = .List, @@ -467,7 +467,7 @@ pub const VM = struct { } inline fn swap(self: *Self, from: u8, to: u8) void { - var temp: Value = (self.current_fiber.stack_top - to - 1)[0]; + const temp: Value = (self.current_fiber.stack_top - to - 1)[0]; (self.current_fiber.stack_top - to - 1)[0] = (self.current_fiber.stack_top - from - 1)[0]; (self.current_fiber.stack_top - from - 1)[0] = temp; } @@ -540,7 +540,7 @@ pub const VM = struct { inline fn readInstruction(self: *Self) u32 { const current_frame: *CallFrame = self.currentFrame().?; - var instruction: u32 = current_frame.closure.function.chunk.code.items[current_frame.ip]; + const instruction: u32 = current_frame.closure.function.chunk.code.items[current_frame.ip]; current_frame.ip += 1; @@ -1085,7 +1085,7 @@ pub const VM = struct { } fn OP_CLOSURE(self: *Self, current_frame: *CallFrame, _: u32, _: OpCode, arg: u24) void { - var function: *ObjFunction = self.readConstant(arg).obj().access(ObjFunction, .Function, self.gc).?; + const function: *ObjFunction = self.readConstant(arg).obj().access(ObjFunction, .Function, self.gc).?; var closure: *ObjClosure = self.gc.allocateObject( ObjClosure, ObjClosure.init(self.gc.allocator, self, function) catch |e| { @@ -1101,8 +1101,8 @@ pub const VM = struct { var i: usize = 0; while (i < function.upvalue_count) : (i += 1) { - var is_local: bool = self.readByte() == 1; - var index: u8 = self.readByte(); + const is_local: bool = self.readByte() == 1; + const index: u8 = self.readByte(); if (is_local) { closure.upvalues.append(self.captureUpvalue(&(current_frame.slots[index])) catch |e| { @@ -1404,7 +1404,7 @@ pub const VM = struct { panic(e); unreachable; }).?; - var member_value: Value = member.toValue(); + const member_value: Value = member.toValue(); (self.current_fiber.stack_top - arg_count - 1)[0] = member_value; self.callValue(member_value, arg_count, catch_value, false) catch |e| { @@ -1437,7 +1437,7 @@ pub const VM = struct { panic(e); unreachable; }).?; - var member_value: Value = member.toValue(); + const member_value: Value = member.toValue(); (self.current_fiber.stack_top - arg_count - 1)[0] = member_value; self.callValue(member_value, arg_count, catch_value, false) catch |e| { @@ -1470,7 +1470,7 @@ pub const VM = struct { panic(e); unreachable; }).?; - var member_value: Value = member.toValue(); + const member_value: Value = member.toValue(); (self.current_fiber.stack_top - arg_count - 1)[0] = member_value; self.callValue(member_value, arg_count, catch_value, false) catch |e| { panic(e); @@ -1504,7 +1504,7 @@ pub const VM = struct { unreachable; }).?; - var member_value: Value = member.toValue(); + const member_value: Value = member.toValue(); (self.current_fiber.stack_top - arg_count - 1)[0] = member_value; self.callValue(member_value, arg_count, catch_value, false) catch |e| { panic(e); @@ -1538,7 +1538,7 @@ pub const VM = struct { unreachable; }).?; - var member_value: Value = member.toValue(); + const member_value: Value = member.toValue(); (self.current_fiber.stack_top - arg_count - 1)[0] = member_value; self.callValue(member_value, arg_count, catch_value, false) catch |e| { panic(e); @@ -1561,7 +1561,7 @@ pub const VM = struct { // result_count > 0 when the return is `export` inline fn returnFrame(self: *Self) bool { - var result = self.pop(); + const result = self.pop(); const frame: *CallFrame = self.currentFrame().?; @@ -1656,7 +1656,7 @@ pub const VM = struct { }; // Top of stack is how many export we got - var exported_count = vm.peek(0).integer(); + const exported_count = vm.peek(0).integer(); // Copy them to this vm globals var import_cache = std.ArrayList(Value).init(self.gc.allocator); @@ -1835,7 +1835,7 @@ pub const VM = struct { fn OP_LIST_APPEND(self: *Self, _: *CallFrame, _: u32, _: OpCode, _: u24) void { var list: *ObjList = self.peek(1).obj().access(ObjList, .List, self.gc).?; - var list_value: Value = self.peek(0); + const list_value: Value = self.peek(0); list.rawAppend(self.gc, list_value) catch |e| { panic(e); @@ -1885,8 +1885,8 @@ pub const VM = struct { fn OP_SET_MAP(self: *Self, _: *CallFrame, _: u32, _: OpCode, _: u24) void { var map: *ObjMap = self.peek(2).obj().access(ObjMap, .Map, self.gc).?; - var key: Value = self.peek(1); - var value: Value = self.peek(0); + const key: Value = self.peek(1); + const value: Value = self.peek(0); map.set(self.gc, key, value) catch |e| { panic(e); @@ -1911,7 +1911,7 @@ pub const VM = struct { } fn OP_GET_LIST_SUBSCRIPT(self: *Self, _: *CallFrame, _: u32, _: OpCode, _: u24) void { - var list: *ObjList = self.peek(1).obj().access(ObjList, .List, self.gc).?; + const list: *ObjList = self.peek(1).obj().access(ObjList, .List, self.gc).?; const index = self.peek(0).integer(); if (index < 0) { @@ -1948,7 +1948,7 @@ pub const VM = struct { return; } - var list_item: Value = list.items.items[list_index]; + const list_item: Value = list.items.items[list_index]; // Pop list and index _ = self.pop(); @@ -1973,7 +1973,7 @@ pub const VM = struct { fn OP_GET_MAP_SUBSCRIPT(self: *Self, _: *CallFrame, _: u32, _: OpCode, _: u24) void { var map: *ObjMap = self.peek(1).obj().access(ObjMap, .Map, self.gc).?; - var index: Value = self.peek(0); + const index: Value = self.peek(0); // Pop map and key _ = self.pop(); @@ -2001,7 +2001,7 @@ pub const VM = struct { } fn OP_GET_STRING_SUBSCRIPT(self: *Self, _: *CallFrame, _: u32, _: OpCode, _: u24) void { - var str = self.peek(1).obj().access(ObjString, .String, self.gc).?; + const str = self.peek(1).obj().access(ObjString, .String, self.gc).?; const index = self.peek(0).integer(); if (index < 0) { @@ -2022,7 +2022,7 @@ pub const VM = struct { const str_index: usize = @intCast(index); if (str_index < str.string.len) { - var str_item: Value = (self.gc.copyString(&([_]u8{str.string[str_index]})) catch |e| { + const str_item: Value = (self.gc.copyString(&([_]u8{str.string[str_index]})) catch |e| { panic(e); unreachable; }).toValue(); @@ -2159,7 +2159,7 @@ pub const VM = struct { } fn OP_GET_ENUM_CASE(self: *Self, _: *CallFrame, _: u32, _: OpCode, arg: u24) void { - var enum_: *ObjEnum = self.peek(0).obj().access(ObjEnum, .Enum, self.gc).?; + const enum_: *ObjEnum = self.peek(0).obj().access(ObjEnum, .Enum, self.gc).?; _ = self.pop(); @@ -2191,7 +2191,7 @@ pub const VM = struct { } fn OP_GET_ENUM_CASE_VALUE(self: *Self, _: *CallFrame, _: u32, _: OpCode, _: u24) void { - var enum_case: *ObjEnumInstance = self.peek(0).obj().access(ObjEnumInstance, .EnumInstance, self.gc).?; + const enum_case: *ObjEnumInstance = self.peek(0).obj().access(ObjEnumInstance, .EnumInstance, self.gc).?; _ = self.pop(); self.push(enum_case.enum_ref.cases.items[enum_case.case]); @@ -2211,8 +2211,8 @@ pub const VM = struct { } fn OP_GET_ENUM_CASE_FROM_VALUE(self: *Self, _: *CallFrame, _: u32, _: OpCode, _: u24) void { - var case_value = self.pop(); - var enum_: *ObjEnum = self.pop().obj().access(ObjEnum, .Enum, self.gc).?; + const case_value = self.pop(); + const enum_: *ObjEnum = self.pop().obj().access(ObjEnum, .Enum, self.gc).?; var found = false; for (enum_.cases.items, 0..) |case, index| { @@ -2388,7 +2388,7 @@ pub const VM = struct { fn OP_PROPERTY(self: *Self, _: *CallFrame, _: u32, _: OpCode, arg: u24) void { const name = self.readString(arg); - var property: Value = self.peek(0); + const property: Value = self.peek(0); var object: *ObjObject = self.peek(1).obj().access(ObjObject, .Object, self.gc).?; if (object.type_def.resolved_type.?.Object.fields.contains(name.string)) { @@ -3411,7 +3411,7 @@ pub const VM = struct { fn OP_LIST_FOREACH(self: *Self, _: *CallFrame, _: u32, _: OpCode, _: u24) void { var key_slot: *Value = @ptrCast(self.current_fiber.stack_top - 3); - var value_slot: *Value = @ptrCast(self.current_fiber.stack_top - 2); + const value_slot: *Value = @ptrCast(self.current_fiber.stack_top - 2); var list: *ObjList = self.peek(0).obj().access(ObjList, .List, self.gc).?; // Get next index @@ -3447,14 +3447,14 @@ pub const VM = struct { fn OP_ENUM_FOREACH(self: *Self, _: *CallFrame, _: u32, _: OpCode, _: u24) void { var value_slot: *Value = @ptrCast(self.current_fiber.stack_top - 2); - var enum_case: ?*ObjEnumInstance = if (value_slot.*.isNull()) + const enum_case: ?*ObjEnumInstance = if (value_slot.*.isNull()) null else value_slot.obj().access(ObjEnumInstance, .EnumInstance, self.gc).?; var enum_: *ObjEnum = self.peek(0).obj().access(ObjEnum, .Enum, self.gc).?; // Get next enum case - var next_case: ?*ObjEnumInstance = enum_.rawNext(self, enum_case) catch |e| { + const next_case: ?*ObjEnumInstance = enum_.rawNext(self, enum_case) catch |e| { panic(e); unreachable; }; @@ -3475,12 +3475,12 @@ pub const VM = struct { } fn OP_MAP_FOREACH(self: *Self, _: *CallFrame, _: u32, _: OpCode, _: u24) void { - var key_slot: *Value = @ptrCast(self.current_fiber.stack_top - 3); - var value_slot: *Value = @ptrCast(self.current_fiber.stack_top - 2); + const key_slot: *Value = @ptrCast(self.current_fiber.stack_top - 3); + const value_slot: *Value = @ptrCast(self.current_fiber.stack_top - 2); var map: *ObjMap = self.peek(0).obj().access(ObjMap, .Map, self.gc).?; - var current_key: ?Value = if (!key_slot.*.isNull()) key_slot.* else null; + const current_key: ?Value = if (!key_slot.*.isNull()) key_slot.* else null; - var next_key: ?Value = map.rawNext(current_key); + const next_key: ?Value = map.rawNext(current_key); key_slot.* = if (next_key) |unext_key| unext_key else Value.Null; if (next_key) |unext_key| { @@ -3502,7 +3502,7 @@ pub const VM = struct { } fn OP_FIBER_FOREACH(self: *Self, _: *CallFrame, _: u32, _: OpCode, _: u24) void { - var value_slot: *Value = @ptrCast(self.current_fiber.stack_top - 2); + const value_slot: *Value = @ptrCast(self.current_fiber.stack_top - 2); var fiber = self.peek(0).obj().access(ObjFiber, .Fiber, self.gc).?; if (fiber.fiber.status == .Over) { @@ -4069,7 +4069,7 @@ pub const VM = struct { }, .String => { if (try ObjString.member(self, name)) |member| { - var member_value: Value = member.toValue(); + const member_value: Value = member.toValue(); (self.current_fiber.stack_top - arg_count - 1)[0] = member_value; try self.callValue(member_value, arg_count, catch_value, in_fiber); @@ -4081,7 +4081,7 @@ pub const VM = struct { }, .Pattern => { if (try ObjPattern.member(self, name)) |member| { - var member_value: Value = member.toValue(); + const member_value: Value = member.toValue(); (self.current_fiber.stack_top - arg_count - 1)[0] = member_value; try self.callValue(member_value, arg_count, catch_value, in_fiber); @@ -4093,7 +4093,7 @@ pub const VM = struct { }, .Fiber => { if (try ObjFiber.member(self, name)) |member| { - var member_value: Value = member.toValue(); + const member_value: Value = member.toValue(); (self.current_fiber.stack_top - arg_count - 1)[0] = member_value; try self.callValue(member_value, arg_count, catch_value, in_fiber); @@ -4107,7 +4107,7 @@ pub const VM = struct { const list = obj.access(ObjList, .List, self.gc).?; if (try list.member(self, name)) |member| { - var member_value: Value = member.toValue(); + const member_value: Value = member.toValue(); (self.current_fiber.stack_top - arg_count - 1)[0] = member_value; try self.callValue(member_value, arg_count, catch_value, in_fiber); @@ -4121,7 +4121,7 @@ pub const VM = struct { const map = obj.access(ObjMap, .Map, self.gc).?; if (try map.member(self, name)) |member| { - var member_value: Value = member.toValue(); + const member_value: Value = member.toValue(); (self.current_fiber.stack_top - arg_count - 1)[0] = member_value; try self.callValue(member_value, arg_count, catch_value, in_fiber); diff --git a/vendors/linenoise b/vendors/linenoise deleted file mode 160000 index 93b2db9b..00000000 --- a/vendors/linenoise +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 93b2db9bd4968f76148dd62cdadf050ed50b84b3 diff --git a/vendors/linenoise/build.zig b/vendors/linenoise/build.zig new file mode 100644 index 00000000..d7a8ffd3 --- /dev/null +++ b/vendors/linenoise/build.zig @@ -0,0 +1,31 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) !void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const upstream = b.dependency("linenoise", .{}); + + const lib = b.addStaticLibrary(.{ + .name = "linenoise", + .target = target, + .optimize = optimize, + }); + lib.linkLibC(); + lib.addIncludePath(upstream.path("")); + lib.installHeadersDirectoryOptions(.{ + .source_dir = upstream.path(""), + .install_dir = .header, + .install_subdir = "", + .include_extensions = &.{".h"}, + }); + + var flags = std.ArrayList([]const u8).init(b.allocator); + defer flags.deinit(); + lib.addCSourceFile(.{ + .file = upstream.path("linenoise.c"), + .flags = &.{}, + }); + + b.installArtifact(lib); +} diff --git a/vendors/linenoise/build.zig.zon b/vendors/linenoise/build.zig.zon new file mode 100644 index 00000000..17433003 --- /dev/null +++ b/vendors/linenoise/build.zig.zon @@ -0,0 +1,14 @@ +.{ + .name = "linenoise", + .version = "1.0.0", + .paths = .{ + "build.zig", + "build.zig.zon", + }, + .dependencies = .{ + .linenoise = .{ + .url = "https://github.com/antirez/linenoise/archive/refs/tags/1.0.tar.gz", + .hash = "1220d1ab00a43d157eb1413219a798b0ddee104e2e56b1a84dcd37b755565078d927", + }, + }, +} diff --git a/vendors/mimalloc b/vendors/mimalloc deleted file mode 160000 index 4e50d671..00000000 --- a/vendors/mimalloc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4e50d6714d471b72b2285e25a3df6c92db944593 diff --git a/vendors/mimalloc/build.zig b/vendors/mimalloc/build.zig new file mode 100644 index 00000000..f73bca02 --- /dev/null +++ b/vendors/mimalloc/build.zig @@ -0,0 +1,57 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) !void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const upstream = b.dependency("mimalloc", .{}); + + const lib = b.addStaticLibrary(.{ + .name = "mimalloc", + .target = target, + .optimize = optimize, + }); + lib.linkLibC(); + lib.addIncludePath(upstream.path("include")); + lib.installHeadersDirectoryOptions(.{ + .source_dir = upstream.path("include"), + .install_dir = .header, + .install_subdir = "", + .include_extensions = &.{".h"}, + }); + + const files = [_]std.Build.LazyPath{ + upstream.path("src/alloc-aligned.c"), + upstream.path("src/alloc.c"), + upstream.path("src/arena.c"), + upstream.path("src/bitmap.c"), + upstream.path("src/heap.c"), + upstream.path("src/init.c"), + upstream.path("src/options.c"), + upstream.path("src/os.c"), + upstream.path("src/page.c"), + upstream.path("src/random.c"), + upstream.path("src/segment-map.c"), + upstream.path("src/segment.c"), + upstream.path("src/stats.c"), + upstream.path("src/prim/prim.c"), + }; + + for (files) |file| { + lib.addCSourceFile( + .{ + .file = file, + .flags = if (lib.optimize != .Debug) + &.{ + "-DNDEBUG=1", + "-DMI_SECURE=0", + "-DMI_STAT=0", + } + else + &.{}, + }, + ); + } + + b.installArtifact(lib); +} diff --git a/vendors/mimalloc/build.zig.zon b/vendors/mimalloc/build.zig.zon new file mode 100644 index 00000000..05196f5d --- /dev/null +++ b/vendors/mimalloc/build.zig.zon @@ -0,0 +1,14 @@ +.{ + .name = "mimalloc", + .version = "2.1.2", + .paths = .{ + "build.zig", + "build.zig.zon", + }, + .dependencies = .{ + .mimalloc= .{ + .url = "https://github.com/microsoft/mimalloc/archive/4e50d6714d471b72b2285e25a3df6c92db944593.tar.gz", + .hash = "1220021f4285bf934936ad6e21aa79a301fe71a9a7c90f7563c7459db0afbcce7f5c", + }, + }, +} diff --git a/vendors/mir b/vendors/mir deleted file mode 160000 index b5bc9256..00000000 --- a/vendors/mir +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b5bc9256d75bbc078e430e1635d11599cf823ad8 diff --git a/vendors/mir/build.zig b/vendors/mir/build.zig new file mode 100644 index 00000000..22c24611 --- /dev/null +++ b/vendors/mir/build.zig @@ -0,0 +1,38 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) !void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const upstream = b.dependency("mir", .{}); + + const lib = b.addStaticLibrary(.{ + .name = "mir", + .target = target, + .optimize = optimize, + }); + lib.linkLibC(); + lib.addIncludePath(upstream.path("")); + lib.installHeadersDirectoryOptions(.{ + .source_dir = upstream.path(""), + .install_dir = .header, + .install_subdir = "", + .include_extensions = &.{".h"}, + }); + + var flags = std.ArrayList([]const u8).init(b.allocator); + defer flags.deinit(); + + const files = [_]std.build.LazyPath{ + upstream.path("mir.c"), + upstream.path("mir-gen.c"), + }; + for (files) |file| { + lib.addCSourceFile(.{ + .file = file, + .flags = &.{}, + }); + } + + b.installArtifact(lib); +} diff --git a/vendors/mir/build.zig.zon b/vendors/mir/build.zig.zon new file mode 100644 index 00000000..c8597e5b --- /dev/null +++ b/vendors/mir/build.zig.zon @@ -0,0 +1,14 @@ +.{ + .name = "mir", + .version = "1.0.0", + .paths = .{ + "build.zig", + "build.zig.zon", + }, + .dependencies = .{ + .mir = .{ + .url = "https://github.com/vnmakarov/mir/archive/b5bc9256d75bbc078e430e1635d11599cf823ad8.tar.gz", + .hash = "122095cea0c199fce718649f07f4e2b9e6a1adee6e0e45e51bb0180f6c331d9e96eb", + }, + }, +} diff --git a/vendors/pcre2 b/vendors/pcre2 deleted file mode 160000 index 52c08847..00000000 --- a/vendors/pcre2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 52c08847921a324c804cabf2814549f50bce1265 diff --git a/vendors/pcre2/build.zig b/vendors/pcre2/build.zig new file mode 100644 index 00000000..8a7357a3 --- /dev/null +++ b/vendors/pcre2/build.zig @@ -0,0 +1,197 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) !void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const upstream = b.dependency("pcre2", .{}); + + const lib = b.addStaticLibrary(.{ + .name = "pcre2", + .target = target, + .optimize = optimize, + }); + lib.linkLibC(); + lib.addIncludePath(upstream.path("src")); + lib.installHeadersDirectoryOptions(.{ + .source_dir = upstream.path("src"), + .install_dir = .header, + .install_subdir = "", + .include_extensions = &.{".h"}, + }); + + const config_h = b.addConfigHeader( + .{ + .style = .{ + .autoconf = upstream.path("src/config.h.in"), + }, + }, + .{ + .EBCDIC = null, + .EBCDIC_NL25 = null, + .HAVE_ATTRIBUTE_UNINITIALIZED = null, + .HAVE_BCOPY = null, + .HAVE_BZLIB_H = true, + .HAVE_DIRENT_H = true, + .HAVE_DLFCN_H = true, + .HAVE_EDITLINE_READLINE_H = null, + .HAVE_EDIT_READLINE_READLINE_H = null, + .HAVE_INTTYPES_H = true, + .HAVE_LIMITS_H = true, + .HAVE_MEMFD_CREATE = true, + .HAVE_MEMMOVE = true, + .HAVE_MINIX_CONFIG_H = null, + .HAVE_MKOSTEMP = null, + .HAVE_PTHREAD = true, + .HAVE_PTHREAD_PRIO_INHERIT = true, + .HAVE_READLINE_H = null, + .HAVE_READLINE_HISTORY_H = null, + .HAVE_READLINE_READLINE_H = null, + .HAVE_REALPATH = true, + .HAVE_SECURE_GETENV = null, + .HAVE_STDINT_H = true, + .HAVE_STDIO_H = true, + .HAVE_STDLIB_H = true, + .HAVE_STRERROR = true, + .HAVE_STRINGS_H = true, + .HAVE_STRING_H = true, + .HAVE_SYS_STAT_H = true, + .HAVE_SYS_TYPES_H = true, + .HAVE_SYS_WAIT_H = true, + .HAVE_UNISTD_H = true, + .HAVE_VISIBILITY = true, + .HAVE_WCHAR_H = true, + .HAVE_WINDOWS_H = null, + .HAVE_ZLIB_H = null, + .HEAP_LIMIT = 20000000, + .LT_OBJDIR = null, + .MATCH_LIMIT = 10000000, + .MATCH_LIMIT_DEPTH = .MATCH_LIMIT, + .NEVER_BACKSLASH_C = null, + .NEWLINE_DEFAULT = 2, + .PACKAGE = null, + .PACKAGE_BUGREPORT = null, + .PACKAGE_NAME = null, + .PACKAGE_STRING = null, + .PACKAGE_TARNAME = null, + .PACKAGE_URL = null, + .PACKAGE_VERSION = null, + .PARENS_NEST_LIMIT = 250, + .PCRE2GREP_BUFSIZE = null, + .PCRE2GREP_MAX_BUFSIZE = null, + .PCRE2POSIX_EXP_DECL = null, + .PCRE2POSIX_EXP_DEFN = null, + .PCRE2_DEBUG = null, + .PCRE2_EXP_DECL = null, + .PCRE2_EXP_DEFN = null, + .PCRE2_STATIC = null, + .PTHREAD_CREATE_JOINABLE = null, + .SLJIT_PROT_EXECUTABLE_ALLOCATOR = null, + .STDC_HEADERS = null, + .SUPPORT_JIT = null, + .SUPPORT_LIBBZ2 = null, + .SUPPORT_LIBEDIT = null, + .SUPPORT_LIBREADLINE = null, + .SUPPORT_LIBZ = null, + .SUPPORT_PCRE2GREP_CALLOUT = null, + .SUPPORT_PCRE2GREP_CALLOUT_FORK = null, + .SUPPORT_PCRE2GREP_JIT = null, + .SUPPORT_PCRE2_16 = null, + .SUPPORT_PCRE2_32 = null, + .SUPPORT_PCRE2_8 = null, + .SUPPORT_UNICODE = null, + .SUPPORT_VALGRIND = null, + ._ALL_SOURCE = null, + ._DARWIN_C_SOURCE = null, + .__EXTENSIONS__ = null, + ._GNU_SOURCE = null, + ._HPUX_ALT_XOPEN_SOCKET_API = null, + ._MINIX = null, + ._NETBSD_SOURCE = null, + ._OPENBSD_SOURCE = null, + ._POSIX_SOURCE = null, + ._POSIX_1_SOURCE = null, + ._POSIX_PTHREAD_SEMANTICS = null, + .__STDC_WANT_IEC_60559_ATTRIBS_EXT__ = null, + .__STDC_WANT_IEC_60559_BFP_EXT__ = null, + .__STDC_WANT_IEC_60559_DFP_EXT__ = null, + .__STDC_WANT_IEC_60559_FUNCS_EXT__ = null, + .__STDC_WANT_IEC_60559_TYPES_EXT__ = null, + .__STDC_WANT_LIB_EXT2__ = null, + .__STDC_WANT_MATH_SPEC_FUNCS__ = null, + ._TANDEM_SOURCE = null, + ._XOPEN_SOURCE = null, + .VERSION = null, + ._FILE_OFFSET_BITS = null, + ._LARGE_FILES = null, + .@"const" = null, + .int64_t = null, + .size_t = null, + .BSR_ANYCRLF = null, + .DISABLE_PERCENT_ZT = null, + .LINK_SIZE = 2, + .MAX_NAME_COUNT = 10009, + .MAX_NAME_SIZE = 32, + }, + ); + const pcre2_h = b.addConfigHeader(.{ + .include_path = "pcre2.h", + .style = .{ + // WORKAROUND: automake is broken for the pcre2.h.in file + .cmake = upstream.path("src/pcre2.h.generic"), + }, + }, .{}); + + // TODO: workaround because there is no way to copy file with lazy paths + const chartables = b.addConfigHeader(.{ + .include_path = "pcre2_chartables.c", + .style = .{ + .cmake = upstream.path("src/pcre2_chartables.c.dist"), + }, + }, .{}); + + lib.addConfigHeader(config_h); + lib.addConfigHeader(pcre2_h); + + const files = [_]std.Build.LazyPath{ + upstream.path("src/pcre2_auto_possess.c"), + upstream.path("src/pcre2_compile.c"), + upstream.path("src/pcre2_config.c"), + upstream.path("src/pcre2_context.c"), + upstream.path("src/pcre2_convert.c"), + upstream.path("src/pcre2_dfa_match.c"), + upstream.path("src/pcre2_error.c"), + upstream.path("src/pcre2_extuni.c"), + upstream.path("src/pcre2_find_bracket.c"), + upstream.path("src/pcre2_maketables.c"), + upstream.path("src/pcre2_match.c"), + upstream.path("src/pcre2_match_data.c"), + upstream.path("src/pcre2_newline.c"), + upstream.path("src/pcre2_ord2utf.c"), + upstream.path("src/pcre2_pattern_info.c"), + upstream.path("src/pcre2_script_run.c"), + upstream.path("src/pcre2_serialize.c"), + upstream.path("src/pcre2_string_utils.c"), + upstream.path("src/pcre2_study.c"), + upstream.path("src/pcre2_substitute.c"), + upstream.path("src/pcre2_substring.c"), + upstream.path("src/pcre2_tables.c"), + upstream.path("src/pcre2_ucd.c"), + upstream.path("src/pcre2_valid_utf.c"), + upstream.path("src/pcre2_xclass.c"), + chartables.getOutput(), + }; + for (files) |file| { + lib.addCSourceFile(.{ + .file = file, + .flags = &.{ + "-std=c99", + "-DHAVE_CONFIG_H", + "-DPCRE2_CODE_UNIT_WIDTH=8", + "-DPCRE2_STATIC", + }, + }); + } + + b.installArtifact(lib); +} diff --git a/vendors/pcre2/build.zig.zon b/vendors/pcre2/build.zig.zon new file mode 100644 index 00000000..de3b5fb6 --- /dev/null +++ b/vendors/pcre2/build.zig.zon @@ -0,0 +1,14 @@ +.{ + .name = "pcre2", + .version = "1.0.0", + .paths = .{ + "build.zig", + "build.zig.zon", + }, + .dependencies = .{ + .pcre2 = .{ + .url = "https://github.com/PCRE2Project/pcre2/archive/52c08847921a324c804cabf2814549f50bce1265.tar.gz", + .hash = "122070d222982480fa9a2146780c23263730773ea7d4f711c523ad3ff2496297f474", + }, + }, +}