Make named lambdas report their names in errors
This commit is contained in:
parent
fd15903260
commit
00631e66a5
|
@ -308,11 +308,7 @@ pub const RuntimeEnv = struct {
|
|||
};
|
||||
}
|
||||
|
||||
const chunk_name = try self.new_string(file_name);
|
||||
|
||||
defer self.discard(chunk_name);
|
||||
|
||||
break: make_chunk try Chunk.make(self, chunk_name, &root.environment);
|
||||
break: make_chunk try Chunk.make(self, file_name, &root.environment);
|
||||
};
|
||||
|
||||
defer chunk.free(self);
|
||||
|
|
|
@ -576,9 +576,9 @@ pub fn free(self: *Self, env: *kym.RuntimeEnv) void {
|
|||
self.bindings = &.{};
|
||||
}
|
||||
|
||||
pub fn make(env: *kym.RuntimeEnv, name: *const kym.RuntimeRef, environment: *const tree.Environment) kym.RuntimeError!Self {
|
||||
pub fn make(env: *kym.RuntimeEnv, name: []const coral.io.Byte, environment: *const tree.Environment) kym.RuntimeError!Self {
|
||||
var chunk = Self{
|
||||
.name = name.acquire(),
|
||||
.name = try env.new_symbol(name),
|
||||
.opcodes = OpcodeList.make(env.allocator),
|
||||
.constants = ConstList.make(env.allocator),
|
||||
.bindings = &.{},
|
||||
|
@ -634,6 +634,7 @@ pub const typeinfo = &kym.Typeinfo{
|
|||
.name = "lambda",
|
||||
.destruct = typeinfo_destruct,
|
||||
.call = typeinfo_call,
|
||||
.to_string = typeinfo_to_string,
|
||||
};
|
||||
|
||||
fn typeinfo_call(env: *kym.RuntimeEnv, userdata: []coral.io.Byte, frame: kym.Frame) kym.RuntimeError!?*kym.RuntimeRef {
|
||||
|
@ -653,3 +654,7 @@ fn typeinfo_call(env: *kym.RuntimeEnv, userdata: []coral.io.Byte, frame: kym.Fra
|
|||
fn typeinfo_destruct(env: *kym.RuntimeEnv, userdata: []coral.io.Byte) void {
|
||||
@as(*Self, @ptrCast(@alignCast(userdata))).free(env);
|
||||
}
|
||||
|
||||
fn typeinfo_to_string(env: *kym.RuntimeEnv, userdata: []coral.io.Byte) coral.io.AllocationError!*kym.RuntimeRef {
|
||||
return env.to_string(@as(*Self, @ptrCast(@alignCast(userdata))).name);
|
||||
}
|
||||
|
|
|
@ -86,11 +86,7 @@ fn compile_expression(self: Self, environment: *const tree.Environment, expressi
|
|||
},
|
||||
|
||||
.lambda_construct => |lambda_construct| {
|
||||
const anonymous_chunk_name = try self.env.new_symbol(name orelse "<lambda>");
|
||||
|
||||
defer self.env.discard(anonymous_chunk_name);
|
||||
|
||||
var chunk = try Chunk.make(self.env, anonymous_chunk_name, lambda_construct.environment);
|
||||
var chunk = try Chunk.make(self.env, name orelse "<lambda>", lambda_construct.environment);
|
||||
|
||||
errdefer chunk.free(self.env);
|
||||
|
||||
|
|
Loading…
Reference in New Issue