diff --git a/src/Codegen.zig b/src/Codegen.zig index b95045b2..77e36833 100644 --- a/src/Codegen.zig +++ b/src/Codegen.zig @@ -2220,7 +2220,6 @@ fn generateFunction(self: *Self, node: Ast.Node.Index, breaks: ?*Breaks) Error!? self.gc.allocator, self.ast, node, - node_type_def.resolved_type.?.Function.name, ); function.type_def = node_type_def; diff --git a/src/obj.zig b/src/obj.zig index 300ab104..0a26f8ea 100644 --- a/src/obj.zig +++ b/src/obj.zig @@ -543,11 +543,11 @@ pub const Obj = struct { }, .Closure => try writer.print("closure: 0x{x} `{s}`", .{ @intFromPtr(ObjClosure.cast(obj).?), - ObjClosure.cast(obj).?.function.name.string, + ObjClosure.cast(obj).?.function.type_def.resolved_type.?.Function.name.string, }), .Function => try writer.print("function: 0x{x} `{s}`", .{ @intFromPtr(ObjFunction.cast(obj).?), - ObjFunction.cast(obj).?.name.string, + ObjFunction.cast(obj).?.type_def.resolved_type.?.Function.name.string, }), .ObjectInstance => { const instance = ObjObjectInstance.cast(obj).?; @@ -648,7 +648,7 @@ pub const Obj = struct { const bound: *ObjBoundMethod = ObjBoundMethod.cast(obj).?; if (bound.closure) |closure| { - const closure_name: []const u8 = closure.function.name.string; + const closure_name: []const u8 = closure.function.type_def.resolved_type.?.Function.name.string; try writer.writeAll("bound method: "); try (bound.receiver).toString(writer); @@ -1267,7 +1267,6 @@ pub const ObjFunction = struct { type_def: *ObjTypeDef = undefined, // Undefined because function initialization is in several steps - name: *ObjString, chunk: Chunk, upvalue_count: u8 = 0, @@ -1282,9 +1281,8 @@ pub const ObjFunction = struct { // JIT compiled function callable by buzz VM native: ?*anyopaque = null, - pub fn init(allocator: Allocator, ast: Ast, node: Ast.Node.Index, name: *ObjString) !Self { + pub fn init(allocator: Allocator, ast: Ast, node: Ast.Node.Index) !Self { return Self{ - .name = name, .node = node, .chunk = Chunk.init(allocator, ast), }; @@ -1295,7 +1293,6 @@ pub const ObjFunction = struct { } pub fn mark(self: *Self, gc: *GarbageCollector) !void { - try gc.markObj(self.name.toObj()); try gc.markObj(@constCast(self.type_def.toObj())); if (BuildOptions.gc_debug) { io.print("MARKING CONSTANTS OF FUNCTION @{} {s}\n", .{ @intFromPtr(self), self.name.string }); diff --git a/src/vm.zig b/src/vm.zig index 8210c2da..b29d606b 100644 --- a/src/vm.zig +++ b/src/vm.zig @@ -4558,6 +4558,7 @@ pub const VM = struct { var writer = msg.writer(); if (next) |unext| { + const function_name = unext.closure.function.type_def.resolved_type.?.Function.name.string; writer.print( "\t{s} in \x1b[36m{s}\x1b[0m at {s}", .{ @@ -4568,9 +4569,9 @@ pub const VM = struct { else " ╰─", if (unext.closure.function.type_def.resolved_type.?.Function.function_type == .Test) - unext.closure.function.name.string[(std.mem.indexOfScalar(u8, unext.closure.function.name.string, ' ').? + 1)..] + function_name[(std.mem.indexOfScalar(u8, function_name, ' ').? + 1)..] else - unext.closure.function.name.string, + function_name, if (frame.call_site) |call_site| self.current_ast.tokens.items(.script_name)[call_site] else