Compare commits

..

No commits in common. "master" and "zig-0.15" have entirely different histories.

6 changed files with 30 additions and 35 deletions

1
.gitignore vendored
View file

@ -1,2 +1 @@
/.zig-cache/ /.zig-cache/
/zig-pkg/

View file

@ -34,7 +34,7 @@ pub fn build(b: *std.Build) void {
ts_bin_query_gen.use_llvm = value; ts_bin_query_gen.use_llvm = value;
ts_bin_query_gen.use_lld = value; ts_bin_query_gen.use_lld = value;
} }
ts_bin_query_gen.root_module.link_libc = true; ts_bin_query_gen.linkLibC();
ts_bin_query_gen.root_module.addImport("cbor", cbor_dep.module("cbor")); ts_bin_query_gen.root_module.addImport("cbor", cbor_dep.module("cbor"));
ts_bin_query_gen.root_module.addImport("treez", tree_sitter_host_dep.module("treez")); ts_bin_query_gen.root_module.addImport("treez", tree_sitter_host_dep.module("treez"));
ts_bin_query_gen.root_module.addImport("build_options", options_mod); ts_bin_query_gen.root_module.addImport("build_options", options_mod);

View file

@ -2,16 +2,16 @@
.name = .flow_syntax, .name = .flow_syntax,
.version = "0.7.2", .version = "0.7.2",
.fingerprint = 0x3ba2584ea1cec85f, .fingerprint = 0x3ba2584ea1cec85f,
.minimum_zig_version = "0.16.0-dev.3133+5ec8e45f3", .minimum_zig_version = "0.15.2",
.dependencies = .{ .dependencies = .{
.tree_sitter = .{ .tree_sitter = .{
.url = "https://github.com/neurocyte/tree-sitter/releases/download/master-70dbb6fa9d998bcf599c3aaeecac7479e9ee3f0c/source.tar.gz", .url = "https://github.com/neurocyte/tree-sitter/releases/download/master-9327512f8d36343bb3adfa6fb982b0b467ddce91/source.tar.gz",
.hash = "tree_sitter-0.26.7-z0LhyGSQZzENNbCzqsMPu63xwpZI1WTHcf62imt-H6YL", .hash = "tree_sitter-0.26.7-z0LhyJOPZzF4S6ZW6MrFTfJgiM9Fp81hqKrXUKSBaUAc",
}, },
.cbor = .{ .cbor = .{
.url = "git+https://github.com/neurocyte/cbor?ref=master#66c28df31b8e4448dac7edf063417f2234d6f3c9", .url = "git+https://github.com/neurocyte/cbor?ref=master#7d2eeb68c8a2fb3f4d6baad6cc04c521b92974c0",
.hash = "cbor-1.1.0-RcQE_DZMAQBg77bTLWHEMF7QSF2lWUudUbarD9xC5yVJ", .hash = "cbor-1.0.0-RcQE_AswAQAPlqBCZXYQf9DZXn-0Ubt8Mk03ZcJWcsAG",
}, },
}, },
.paths = .{ .paths = .{

View file

@ -12,16 +12,15 @@ pub const tss = @import("ts_serializer.zig");
pub const FileType = @import("file_type.zig"); pub const FileType = @import("file_type.zig");
const Query = treez.Query; const Query = treez.Query;
io: std.Io,
allocator: std.mem.Allocator, allocator: std.mem.Allocator,
mutex: ?std.Io.Mutex, mutex: ?std.Thread.Mutex,
highlights: std.StringHashMapUnmanaged(*CacheEntry) = .{}, highlights: std.StringHashMapUnmanaged(*CacheEntry) = .{},
injections: std.StringHashMapUnmanaged(*CacheEntry) = .{}, injections: std.StringHashMapUnmanaged(*CacheEntry) = .{},
errors: std.StringHashMapUnmanaged(*CacheEntry) = .{}, errors: std.StringHashMapUnmanaged(*CacheEntry) = .{},
ref_count: usize = 1, ref_count: usize = 1,
const CacheEntry = struct { const CacheEntry = struct {
mutex: ?std.Io.Mutex, mutex: ?std.Thread.Mutex,
query: ?*Query, query: ?*Query,
query_arena: ?*std.heap.ArenaAllocator, query_arena: ?*std.heap.ArenaAllocator,
query_type: QueryType, query_type: QueryType,
@ -61,13 +60,12 @@ const CacheError = error{
pub const Error = CacheError || QueryParseError || QuerySerializeError; pub const Error = CacheError || QueryParseError || QuerySerializeError;
pub fn create(io: std.Io, allocator: std.mem.Allocator, opts: struct { lock: bool = false }) !*Self { pub fn create(allocator: std.mem.Allocator, opts: struct { lock: bool = false }) !*Self {
const self = try allocator.create(Self); const self = try allocator.create(Self);
errdefer allocator.destroy(self); errdefer allocator.destroy(self);
self.* = .{ self.* = .{
.io = io,
.allocator = allocator, .allocator = allocator,
.mutex = if (opts.lock) .init else null, .mutex = if (opts.lock) .{} else null,
}; };
return self; return self;
} }
@ -83,8 +81,8 @@ fn add_ref_locked(self: *Self) void {
fn release_ref_unlocked_and_maybe_destroy(self: *Self) void { fn release_ref_unlocked_and_maybe_destroy(self: *Self) void {
{ {
if (self.mutex) |*mtx| mtx.lockUncancelable(self.io); if (self.mutex) |*mtx| mtx.lock();
defer if (self.mutex) |*mtx| mtx.unlock(self.io); defer if (self.mutex) |*mtx| mtx.unlock();
self.ref_count -= 1; self.ref_count -= 1;
if (self.ref_count > 0) return; if (self.ref_count > 0) return;
} }
@ -106,8 +104,8 @@ fn release_cache_entry_hash_map(allocator: std.mem.Allocator, hash_map: *std.Str
} }
fn get_cache_entry(self: *Self, file_type: FileType, comptime query_type: QueryType) CacheError!*CacheEntry { fn get_cache_entry(self: *Self, file_type: FileType, comptime query_type: QueryType) CacheError!*CacheEntry {
if (self.mutex) |*mtx| mtx.lockUncancelable(self.io); if (self.mutex) |*mtx| mtx.lock();
defer if (self.mutex) |*mtx| mtx.unlock(self.io); defer if (self.mutex) |*mtx| mtx.unlock();
const hash = switch (query_type) { const hash = switch (query_type) {
.highlights => &self.highlights, .highlights => &self.highlights,
@ -122,7 +120,7 @@ fn get_cache_entry(self: *Self, file_type: FileType, comptime query_type: QueryT
q.* = .{ q.* = .{
.query = null, .query = null,
.query_arena = null, .query_arena = null,
.mutex = if (self.mutex) |_| .init else null, .mutex = if (self.mutex) |_| .{} else null,
.lang_fn = file_type.lang_fn, .lang_fn = file_type.lang_fn,
.file_type_name = file_type.name, .file_type_name = file_type.name,
.query_type = query_type, .query_type = query_type,
@ -134,8 +132,8 @@ fn get_cache_entry(self: *Self, file_type: FileType, comptime query_type: QueryT
} }
fn get_cached_query(self: *Self, entry: *CacheEntry) Error!?*Query { fn get_cached_query(self: *Self, entry: *CacheEntry) Error!?*Query {
if (entry.mutex) |*mtx| mtx.lockUncancelable(self.io); if (entry.mutex) |*mtx| mtx.lock();
defer if (entry.mutex) |*mtx| mtx.unlock(self.io); defer if (entry.mutex) |*mtx| mtx.unlock();
return if (entry.query) |query| query else blk: { return if (entry.query) |query| query else blk: {
const lang = entry.lang_fn() orelse std.debug.panic("tree-sitter parser function failed for language: {s}", .{entry.file_type_name}); const lang = entry.lang_fn() orelse std.debug.panic("tree-sitter parser function failed for language: {s}", .{entry.file_type_name});
@ -175,7 +173,7 @@ pub fn get(self: *Self, file_type: FileType, comptime query_type: QueryType) Err
const query = try self.get_cached_query(try self.get_cache_entry(file_type, query_type)); const query = try self.get_cached_query(try self.get_cache_entry(file_type, query_type));
if (query != null) self.add_ref_locked(); if (query != null) self.add_ref_locked();
return switch (@typeInfo(ReturnType(query_type))) { return switch (@typeInfo(ReturnType(query_type))) {
.optional => query, .optional => |_| query,
else => query.?, else => query.?,
}; };
} }

View file

@ -27,7 +27,7 @@ query: *Query,
errors_query: *Query, errors_query: *Query,
injections: ?*Query, injections: ?*Query,
tree: ?*treez.Tree = null, tree: ?*treez.Tree = null,
injection_list: std.ArrayList(Injection) = .empty, injection_list: std.ArrayListUnmanaged(Injection) = .{},
content: ?[]u8 = null, content: ?[]u8 = null,
pub const Injection = struct { pub const Injection = struct {
@ -484,16 +484,15 @@ pub fn count_error_nodes(self: *const Self) usize {
} }
test "simple build and link test" { test "simple build and link test" {
const io = std.testing.io;
const gpa = std.testing.allocator; const gpa = std.testing.allocator;
const zig_file_type = @import("file_type.zig").get_by_name_static("zig") orelse return error.TestFailed; const zig_file_type = @import("file_type.zig").get_by_name_static("zig") orelse return error.TestFailed;
const query_cache = try QueryCache.create(io, gpa, .{}); const query_cache = try QueryCache.create(gpa, .{});
defer query_cache.deinit(); defer query_cache.deinit();
const syntax = try create(zig_file_type, gpa, query_cache); const syntax = try create(zig_file_type, gpa, query_cache);
defer syntax.destroy(); defer syntax.destroy();
const content = try std.Io.Dir.readFileAlloc(.cwd(), io, "src/syntax.zig", gpa, .unlimited); const content = try std.fs.cwd().readFileAlloc(gpa, "src/syntax.zig", std.math.maxInt(usize));
defer gpa.free(content); defer gpa.free(content);
try syntax.refresh_full(content); try syntax.refresh_full(content);

View file

@ -6,25 +6,24 @@ pub const tss = @import("ts_serializer.zig");
const verbose = false; const verbose = false;
pub fn main(init: std.process.Init) anyerror!void { pub fn main() anyerror!void {
const io = init.io;
const allocator = std.heap.c_allocator; const allocator = std.heap.c_allocator;
const args = try std.process.argsAlloc(allocator);
var opt_output_file_path: ?[]const u8 = null; var opt_output_file_path: ?[]const u8 = null;
var args = try init.minimal.args.iterateAllocator(allocator); var i: usize = 1;
defer args.deinit(); while (i < args.len) : (i += 1) {
_ = args.next(); const arg = args[i];
while (args.next()) |arg| {
if (opt_output_file_path != null) fatal("duplicated {s} argument", .{arg}); if (opt_output_file_path != null) fatal("duplicated {s} argument", .{arg});
opt_output_file_path = arg; opt_output_file_path = args[i];
} }
const output_file_path = opt_output_file_path orelse fatal("missing output file", .{}); const output_file_path = opt_output_file_path orelse fatal("missing output file", .{});
var output_file = std.Io.Dir.cwd().createFile(io, output_file_path, .{}) catch |err| { var output_file = std.fs.cwd().createFile(output_file_path, .{}) catch |err| {
fatal("unable to open '{s}': {s}", .{ output_file_path, @errorName(err) }); fatal("unable to open '{s}': {s}", .{ output_file_path, @errorName(err) });
}; };
defer output_file.close(io); defer output_file.close();
var output = std.Io.Writer.Allocating.init(allocator); var output = std.Io.Writer.Allocating.init(allocator);
const writer = &output.writer; const writer = &output.writer;
@ -94,7 +93,7 @@ pub fn main(init: std.process.Init) anyerror!void {
} }
} }
try output_file.writeStreamingAll(io, output.written()); try output_file.writeAll(output.written());
if (verbose) if (verbose)
std.log.info("file_types total {d} bytes", .{output.written().len}); std.log.info("file_types total {d} bytes", .{output.written().len});
} }