improve comptime interpreter stack trace message

This commit is contained in:
Techatrix 2023-01-26 17:14:42 +01:00
parent ca644d67c1
commit 9131285db1
2 changed files with 7 additions and 11 deletions

View File

@ -52,7 +52,7 @@ pub fn recordError(
.code = code,
.message = message,
});
if (previous != null) interpreter.allocator.free(message);
if (previous) |p| interpreter.allocator.free(p.value.message);
}
pub fn deinit(interpreter: *ComptimeInterpreter) void {

View File

@ -764,30 +764,26 @@ pub fn resolveTypeOfNodeInternal(store: *DocumentStore, arena: *std.heap.ArenaAl
log.info("Invoking interpreter!", .{});
store.ensureInterpreterExists(handle.uri) catch |err| {
log.err("Interpreter error: {s}", .{@errorName(err)});
log.err("Failed to interpret file: {s}", .{@errorName(err)});
if (@errorReturnTrace()) |trace| {
std.debug.dumpStackTrace(trace.*);
}
return null;
};
var interpreter = handle.interpreter.?;
var interpreter: *ComptimeInterpreter = handle.interpreter.?;
try interpreter.namespaces.append(interpreter.allocator, .{
.parent = .none,
.node_idx = 0,
.ty = .none,
});
const root_namespace = @intToEnum(ComptimeInterpreter.NamespaceIndex, 0);
// TODO: Start from current/nearest-current scope
const result = interpreter.interpret(node, .none, .{}) catch |err| {
log.err("Interpreter error: {s}", .{@errorName(err)});
const result = interpreter.interpret(node, root_namespace, .{}) catch |err| {
log.err("Failed to interpret node: {s}", .{@errorName(err)});
if (@errorReturnTrace()) |trace| {
std.debug.dumpStackTrace(trace.*);
}
return null;
};
const value = result.getValue() catch |err| {
log.err("Interpreter error: {s}", .{@errorName(err)});
log.err("interpreter return no result: {s}", .{@errorName(err)});
if (@errorReturnTrace()) |trace| {
std.debug.dumpStackTrace(trace.*);
}