authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-07 10:11:03+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-07 10:30:56+02:00
log56ea07f4fc20f479d82a7cb1633a15308a99c966
tree939afe92b57065b3aa61e4d1e51098e9e555e2df
parent7a2433419924af05e5e860031ff8279577fb25d5
signaturelock-open Commit is signed but in an unrecognized format.

self hosted compiler: comment out event.fs stuff


2 files changed, 68 insertions(+), 66 deletions(-)

src-self-hosted/compilation.zig+41-40
......@@ -242,7 +242,7 @@ pub const Compilation = struct {
242242
243243 c_int_types: [CInt.list.len]*Type.Int,
244244
245 fs_watch: *fs.Watch(*Scope.Root),
245 // fs_watch: *fs.Watch(*Scope.Root),
246246
247247 const IntTypeTable = std.HashMap(*const Type.Int.Key, *Type.Int, Type.Int.Key.hash, Type.Int.Key.eql);
248248 const ArrayTypeTable = std.HashMap(*const Type.Array.Key, *Type.Array, Type.Array.Key.hash, Type.Array.Key.eql);
......@@ -462,7 +462,7 @@ pub const Compilation = struct {
462462 .have_err_ret_tracing = false,
463463 .primitive_type_table = undefined,
464464
465 .fs_watch = undefined,
465 // .fs_watch = undefined,
466466 };
467467 comp.link_libs_list = ArrayList(*LinkLib).init(comp.arena());
468468 comp.primitive_type_table = TypeTable.init(comp.arena());
......@@ -531,8 +531,8 @@ pub const Compilation = struct {
531531 comp.root_package = try Package.create(comp.arena(), ".", "");
532532 }
533533
534 comp.fs_watch = try fs.Watch(*Scope.Root).create(16);
535 defer comp.fs_watch.destroy();
534 // comp.fs_watch = try fs.Watch(*Scope.Root).create(16);
535 // defer comp.fs_watch.destroy();
536536
537537 try comp.initTypes();
538538 defer comp.primitive_type_table.deinit();
......@@ -791,46 +791,47 @@ pub const Compilation = struct {
791791 self.events.put(Event{ .Error = err });
792792 }
793793
794 // First, get an item from the watch channel, waiting on the channel.
795 var group = event.Group(BuildError!void).init(self.gpa());
796 {
797 const ev = (self.fs_watch.channel.get()) catch |err| {
798 build_result = err;
799 continue;
800 };
801 const root_scope = ev.data;
802 group.call(rebuildFile, self, root_scope) catch |err| {
803 build_result = err;
804 continue;
805 };
806 }
807 // Next, get all the items from the channel that are buffered up.
808 while (self.fs_watch.channel.getOrNull()) |ev_or_err| {
809 if (ev_or_err) |ev| {
810 const root_scope = ev.data;
811 group.call(rebuildFile, self, root_scope) catch |err| {
812 build_result = err;
813 continue;
814 };
815 } else |err| {
816 build_result = err;
817 continue;
818 }
819 }
820 build_result = group.wait();
794 // // First, get an item from the watch channel, waiting on the channel.
795 // var group = event.Group(BuildError!void).init(self.gpa());
796 // {
797 // const ev = (self.fs_watch.channel.get()) catch |err| {
798 // build_result = err;
799 // continue;
800 // };
801 // const root_scope = ev.data;
802 // group.call(rebuildFile, self, root_scope) catch |err| {
803 // build_result = err;
804 // continue;
805 // };
806 // }
807 // // Next, get all the items from the channel that are buffered up.
808 // while (self.fs_watch.channel.getOrNull()) |ev_or_err| {
809 // if (ev_or_err) |ev| {
810 // const root_scope = ev.data;
811 // group.call(rebuildFile, self, root_scope) catch |err| {
812 // build_result = err;
813 // continue;
814 // };
815 // } else |err| {
816 // build_result = err;
817 // continue;
818 // }
819 // }
820 // build_result = group.wait();
821821 }
822822 }
823823
824824 async fn rebuildFile(self: *Compilation, root_scope: *Scope.Root) !void {
825825 const tree_scope = blk: {
826 const source_code = fs.readFile(
827 root_scope.realpath,
828 max_src_size,
829 ) catch |err| {
830 try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", @errorName(err));
831 return;
832 };
833 errdefer self.gpa().free(source_code);
826 const source_code = "";
827 // const source_code = fs.readFile(
828 // root_scope.realpath,
829 // max_src_size,
830 // ) catch |err| {
831 // try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", @errorName(err));
832 // return;
833 // };
834 // errdefer self.gpa().free(source_code);
834835
835836 const tree = try std.zig.parse(self.gpa(), source_code);
836837 errdefer {
......@@ -972,7 +973,7 @@ pub const Compilation = struct {
972973 };
973974 defer root_scope.base.deref(self);
974975
975 assert((try self.fs_watch.addFile(root_scope.realpath, root_scope)) == null);
976 // assert((try self.fs_watch.addFile(root_scope.realpath, root_scope)) == null);
976977 try self.rebuildFile(root_scope);
977978 }
978979 }
src-self-hosted/main.zig+27-26
......@@ -711,32 +711,33 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
711711 if (try held.value.put(file_path, {})) |_| return;
712712 }
713713
714 const source_code = event.fs.readFile(
715 file_path,
716 max_src_size,
717 ) catch |err| switch (err) {
718 error.IsDir, error.AccessDenied => {
719 // TODO make event based (and dir.next())
720 var dir = try fs.Dir.open(file_path);
721 defer dir.close();
722
723 var group = event.Group(FmtError!void).init(fmt.allocator);
724 while (try dir.next()) |entry| {
725 if (entry.kind == fs.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) {
726 const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name });
727 try group.call(fmtPath, fmt, full_path, check_mode);
728 }
729 }
730 return group.wait();
731 },
732 else => {
733 // TODO lock stderr printing
734 try stderr.print("unable to open '{}': {}\n", file_path, err);
735 fmt.any_error = true;
736 return;
737 },
738 };
739 defer fmt.allocator.free(source_code);
714 const source_code = "";
715 // const source_code = event.fs.readFile(
716 // file_path,
717 // max_src_size,
718 // ) catch |err| switch (err) {
719 // error.IsDir, error.AccessDenied => {
720 // // TODO make event based (and dir.next())
721 // var dir = try fs.Dir.open(file_path);
722 // defer dir.close();
723
724 // var group = event.Group(FmtError!void).init(fmt.allocator);
725 // while (try dir.next()) |entry| {
726 // if (entry.kind == fs.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) {
727 // const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name });
728 // try group.call(fmtPath, fmt, full_path, check_mode);
729 // }
730 // }
731 // return group.wait();
732 // },
733 // else => {
734 // // TODO lock stderr printing
735 // try stderr.print("unable to open '{}': {}\n", file_path, err);
736 // fmt.any_error = true;
737 // return;
738 // },
739 // };
740 // defer fmt.allocator.free(source_code);
740741
741742 const tree = std.zig.parse(fmt.allocator, source_code) catch |err| {
742743 try stderr.print("error parsing file '{}': {}\n", file_path, err);