making the displayed paths relative to the root file
Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
parent
820a36cb68
commit
5ba0251f17
|
@ -71,7 +71,7 @@ pub fn build(b: *std.Build) !void {
|
|||
const test_step = b.step("test", "run tests");
|
||||
const run_step = b.step("run", "Run the app");
|
||||
|
||||
//check_step.dependOn(&exe.step);
|
||||
check_step.dependOn(&exe.step);
|
||||
run_step.dependOn(&b.addRunArtifact(exe).step);
|
||||
|
||||
const fuzz_finding_tests = fuzzing: {
|
||||
|
|
7
foo.hb
7
foo.hb
|
@ -1,10 +1,9 @@
|
|||
|
||||
main := fn(): uint {
|
||||
Map := fn(I: type, F: type): type return struct{}
|
||||
Map := fn(I: type, F: type): type return struct {}
|
||||
|
||||
foo := fn(vl: int, $foo: type): Map(u8, foo) return .()
|
||||
foo := fn(vl: int, $oo: type): Map(u8, oo) return .()
|
||||
|
||||
foo()
|
||||
_ = foo(0, u8)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -450,10 +450,6 @@ pub fn unwrapTyConst(self: *Codegen, pos: anytype, cnst: *Value) !Types.Id {
|
|||
return self.report(pos, "expected type, {} is not", .{cnst.ty});
|
||||
}
|
||||
self.ensureLoaded(cnst);
|
||||
if (cnst.id == .Imaginary) {
|
||||
std.debug.dumpCurrentStackTrace(@returnAddress());
|
||||
return self.report(pos, "what a fuck {}", .{cnst.ty});
|
||||
}
|
||||
return @enumFromInt(try self.partialEval(pos, cnst.id.Value));
|
||||
}
|
||||
|
||||
|
@ -461,7 +457,6 @@ pub const LookupResult = union(enum) { ty: Types.Id, cnst: u64 };
|
|||
|
||||
pub fn lookupScopeItem(self: *Codegen, pos: Ast.Pos, bsty: Types.Id, name: []const u8) !Value {
|
||||
const other_file = bsty.file() orelse {
|
||||
std.debug.dumpCurrentStackTrace(@returnAddress());
|
||||
return self.report(pos, "{} does not declare this", .{bsty});
|
||||
};
|
||||
const ast = self.types.getFile(other_file);
|
||||
|
@ -549,7 +544,6 @@ pub fn loadIdent(self: *Codegen, pos: Ast.Pos, id: Ast.Ident) !Value {
|
|||
}
|
||||
cursor = cursor.parent();
|
||||
} else {
|
||||
std.debug.dumpCurrentStackTrace(@returnAddress());
|
||||
return self.report(pos, "ICE: parser did not catch this", .{});
|
||||
};
|
||||
|
||||
|
|
|
@ -272,6 +272,7 @@ fn parseUnitWithoutTail(self: *Parser) Error!Id {
|
|||
self.capture_boundary = self.active_syms.items.len;
|
||||
defer self.capture_boundary = prev_capture_boundary;
|
||||
|
||||
const capture_scope = self.captures.items.len;
|
||||
const comptime_arg_start = self.comptime_idents.items.len;
|
||||
defer self.comptime_idents.items.len = comptime_arg_start;
|
||||
const args = try self.parseListTyped(.@"(", .@",", .@")", Ast.Arg, parseArg);
|
||||
|
@ -280,7 +281,6 @@ fn parseUnitWithoutTail(self: *Parser) Error!Id {
|
|||
_ = try self.expectAdvance(.@":");
|
||||
const ret = try self.parseExpr();
|
||||
|
||||
const capture_scope = self.captures.items.len;
|
||||
const body = body: {
|
||||
defer self.finalizeVariables(scope_frame);
|
||||
break :body try self.parseExpr();
|
||||
|
|
39
src/main.zig
39
src/main.zig
|
@ -203,10 +203,37 @@ const Loader = struct {
|
|||
const base = self.base;
|
||||
const file = self.files.items[@intFromEnum(opts.from)];
|
||||
const rel_base = std.fs.path.dirname(file.path) orelse "";
|
||||
const path = self.path_projections.get(opts.path) orelse
|
||||
std.fs.path.resolve(self.gpa, &.{ rel_base, opts.path }) catch return null;
|
||||
const mangled_path = self.path_projections.get(opts.path) orelse
|
||||
std.fs.path.join(self.gpa, &.{ base, rel_base, opts.path }) catch return null;
|
||||
const path = std.fs.cwd().realpathAlloc(self.gpa, mangled_path) catch mangled_path;
|
||||
|
||||
const canon = path[base.len..];
|
||||
const canon = if (std.mem.startsWith(u8, path, base)) path[base.len + 1 ..] else b: {
|
||||
var base_segments = std.fs.path.componentIterator(base) catch break :b path;
|
||||
var path_segments = std.fs.path.componentIterator(path) catch break :b path;
|
||||
|
||||
while (true) {
|
||||
if (std.mem.eql(
|
||||
u8,
|
||||
(base_segments.peekNext() orelse break).path,
|
||||
(path_segments.peekNext() orelse break).path,
|
||||
)) {
|
||||
_ = base_segments.next();
|
||||
_ = path_segments.next();
|
||||
} else break;
|
||||
}
|
||||
|
||||
const rem = path_segments.path[path_segments.end_index + 1 ..];
|
||||
var dd_count: usize = 0;
|
||||
while (base_segments.next() != null) dd_count += 1;
|
||||
|
||||
const buf = self.gpa.alloc(u8, dd_count * 3 + rem.len) catch break :b path;
|
||||
for (0..dd_count) |i| {
|
||||
@memcpy(buf[i * 3 ..][0..3], "../");
|
||||
}
|
||||
@memcpy(buf[dd_count * 3 ..], rem);
|
||||
|
||||
break :b buf;
|
||||
};
|
||||
|
||||
for (self.files.items, 0..) |fl, i| {
|
||||
if (std.mem.eql(u8, fl.path, canon)) return @enumFromInt(i);
|
||||
|
@ -235,14 +262,16 @@ const Loader = struct {
|
|||
root: []const u8,
|
||||
diagnostics: std.io.AnyWriter,
|
||||
) !?struct { []const hb.Ast, []const u8 } {
|
||||
const real_root = std.fs.cwd().realpathAlloc(gpa, root) catch root;
|
||||
|
||||
var self = Loader{
|
||||
.gpa = gpa,
|
||||
.base = std.fs.path.dirname(root) orelse "",
|
||||
.base = std.fs.path.dirname(real_root) orelse "",
|
||||
.path_projections = path_projections,
|
||||
};
|
||||
|
||||
const slot = try self.files.addOne(self.gpa);
|
||||
slot.path = root;
|
||||
slot.path = std.fs.path.basename(root);
|
||||
slot.source = std.fs.cwd().readFileAlloc(self.gpa, root, max_file_len) catch {
|
||||
try diagnostics.print("could not read the root file: {s}", .{root});
|
||||
return null;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
foo := @use("bar")
|
||||
goo := @use("fa.hb")
|
||||
mfoo := @use("../foo.hb")
|
||||
|
||||
main := fn(): uint {
|
||||
_ = mfoo.main()
|
||||
return goo.fun + foo.fun
|
||||
}
|
||||
|
|
|
@ -1,53 +1,53 @@
|
|||
main:
|
||||
st $31, $254, -24, 24
|
||||
addi64 $254, $254, -24
|
||||
jal $31, $0, :main.some_fn3(some_int = uint)(fnc = main.some_fn)
|
||||
jal $31, $0, :main.some_fn3(some_int = uint)(fnc = main.some_fn(some_int = uint))
|
||||
cp $32, $1
|
||||
jal $31, $0, :main.some_fn3(some_int = uint)(fnc = main.some_fn3(some_int = uint)(fnc = main.some_fn2(some_fn = main.some_fn)))
|
||||
jal $31, $0, :main.some_fn3(some_int = uint)(fnc = main.some_fn3(some_int = uint)(fnc = main.some_fn2(some_int = uint, some_fn = main.some_fn(some_int = uint))))
|
||||
cp $33, $1
|
||||
add64 $32, $32, $33
|
||||
cp $1, $32
|
||||
addi64 $254, $254, 24
|
||||
ld $31, $254, -24, 24
|
||||
tx
|
||||
main.some_fn3(some_int = uint)(fnc = main.some_fn3(some_int = uint)(fnc = main.some_fn2(some_fn = main.some_fn))):
|
||||
main.some_fn3(some_int = uint)(fnc = main.some_fn3(some_int = uint)(fnc = main.some_fn2(some_int = uint, some_fn = main.some_fn(some_int = uint)))):
|
||||
st $31, $254, -16, 16
|
||||
addi64 $254, $254, -16
|
||||
jal $31, $0, :main.some_fn3(some_int = uint)(fnc = main.some_fn2(some_fn = main.some_fn))
|
||||
jal $31, $0, :main.some_fn3(some_int = uint)(fnc = main.some_fn2(some_int = uint, some_fn = main.some_fn(some_int = uint)))
|
||||
cp $32, $1
|
||||
addi64 $32, $32, 10
|
||||
cp $1, $32
|
||||
addi64 $254, $254, 16
|
||||
ld $31, $254, -16, 16
|
||||
jala $0, $31, 0
|
||||
main.some_fn3(some_int = uint)(fnc = main.some_fn2(some_fn = main.some_fn)):
|
||||
main.some_fn3(some_int = uint)(fnc = main.some_fn2(some_int = uint, some_fn = main.some_fn(some_int = uint))):
|
||||
st $31, $254, -16, 16
|
||||
addi64 $254, $254, -16
|
||||
jal $31, $0, :main.some_fn2(some_fn = main.some_fn)
|
||||
jal $31, $0, :main.some_fn2(some_int = uint, some_fn = main.some_fn(some_int = uint))
|
||||
cp $32, $1
|
||||
addi64 $32, $32, 10
|
||||
cp $1, $32
|
||||
addi64 $254, $254, 16
|
||||
ld $31, $254, -16, 16
|
||||
jala $0, $31, 0
|
||||
main.some_fn2(some_fn = main.some_fn):
|
||||
main.some_fn2(some_int = uint, some_fn = main.some_fn(some_int = uint)):
|
||||
st $31, $254, -16, 16
|
||||
addi64 $254, $254, -16
|
||||
jal $31, $0, :main.some_fn
|
||||
jal $31, $0, :main.some_fn(some_int = uint)
|
||||
cp $32, $1
|
||||
addi64 $32, $32, 1
|
||||
cp $1, $32
|
||||
addi64 $254, $254, 16
|
||||
ld $31, $254, -16, 16
|
||||
jala $0, $31, 0
|
||||
main.some_fn:
|
||||
main.some_fn(some_int = uint):
|
||||
li64 $13, 1
|
||||
cp $1, $13
|
||||
jala $0, $31, 0
|
||||
main.some_fn3(some_int = uint)(fnc = main.some_fn):
|
||||
main.some_fn3(some_int = uint)(fnc = main.some_fn(some_int = uint)):
|
||||
st $31, $254, -16, 16
|
||||
addi64 $254, $254, -16
|
||||
jal $31, $0, :main.some_fn
|
||||
jal $31, $0, :main.some_fn(some_int = uint)
|
||||
cp $32, $1
|
||||
addi64 $32, $32, 10
|
||||
cp $1, $32
|
||||
|
|
Loading…
Reference in a new issue