...
This commit is contained in:
@@ -2578,31 +2578,6 @@ pub const LLVMEmitter = struct {
|
||||
self.mapRef(result);
|
||||
},
|
||||
|
||||
// ── Context ops ──────────────────────────────────────────
|
||||
.context_load, .context_store, .context_save => {
|
||||
// Context ops are handled by the existing codegen glue
|
||||
// In the IR pipeline, these become load/store on a known global
|
||||
self.mapRef(c.LLVMGetUndef(self.toLLVMType(instruction.ty)));
|
||||
},
|
||||
.context_restore => {
|
||||
self.mapRef(c.LLVMGetUndef(self.toLLVMType(instruction.ty)));
|
||||
},
|
||||
|
||||
// ── Protocol ops ─────────────────────────────────────────
|
||||
.protocol_call_dynamic => |pc| {
|
||||
// Dynamic dispatch through vtable — extract method ptr from protocol value
|
||||
const receiver = self.resolveRef(pc.receiver);
|
||||
_ = receiver;
|
||||
// Stub: full protocol dispatch needs vtable layout info
|
||||
self.mapRef(c.LLVMGetUndef(self.toLLVMType(instruction.ty)));
|
||||
},
|
||||
.protocol_erase => |pe| {
|
||||
const concrete = self.resolveRef(pe.concrete);
|
||||
_ = concrete;
|
||||
// Stub: needs protocol struct construction
|
||||
self.mapRef(c.LLVMGetUndef(self.toLLVMType(instruction.ty)));
|
||||
},
|
||||
|
||||
// ── Vector ops ───────────────────────────────────────────
|
||||
.vec_splat => |un| {
|
||||
const scalar = self.resolveRef(un.operand);
|
||||
|
||||
@@ -196,19 +196,9 @@ pub const Op = union(enum) {
|
||||
/// Method-ID caching across call sites is added in step 1.17.
|
||||
jni_msg_send: JniMsgSend,
|
||||
|
||||
// ── Protocol dispatch ───────────────────────────────────────────
|
||||
protocol_call_dynamic: ProtocolCall, // vtable/inline dispatch
|
||||
protocol_erase: ProtocolErase, // concrete → protocol value (xx)
|
||||
|
||||
// ── Closure creation ────────────────────────────────────────────
|
||||
closure_create: ClosureCreate,
|
||||
|
||||
// ── Context ─────────────────────────────────────────────────────
|
||||
context_load: ContextOp, // read context field
|
||||
context_store: ContextOp, // write context field
|
||||
context_save, // save context state (for push)
|
||||
context_restore: UnaryOp, // restore context state (after push)
|
||||
|
||||
// ── Globals ─────────────────────────────────────────────────────
|
||||
global_get: GlobalId,
|
||||
global_addr: GlobalId, // address of a global (pointer, not load)
|
||||
@@ -377,27 +367,11 @@ pub const CompilerCall = struct {
|
||||
args: []const Ref,
|
||||
};
|
||||
|
||||
pub const ProtocolCall = struct {
|
||||
receiver: Ref, // protocol value (ctx + vtable/fn_ptrs)
|
||||
method_index: u32,
|
||||
args: []const Ref,
|
||||
};
|
||||
|
||||
pub const ProtocolErase = struct {
|
||||
concrete: Ref,
|
||||
protocol_type: TypeId,
|
||||
};
|
||||
|
||||
pub const ClosureCreate = struct {
|
||||
func: FuncId, // trampoline function
|
||||
env: Ref, // allocated env pointer (or Ref.none for no captures)
|
||||
};
|
||||
|
||||
pub const ContextOp = struct {
|
||||
field: StringId,
|
||||
value: Ref, // Ref.none for loads
|
||||
};
|
||||
|
||||
pub const GlobalSet = struct {
|
||||
global: GlobalId,
|
||||
value: Ref,
|
||||
|
||||
@@ -1127,7 +1127,7 @@ pub const Interpreter = struct {
|
||||
.placeholder => return .{ .value = .undef },
|
||||
|
||||
// ── Not yet evaluable at comptime ──────────────────
|
||||
.call_closure, .protocol_call_dynamic, .protocol_erase, .closure_create, .context_load, .context_store, .context_save, .context_restore, .union_get, .union_gep, .vec_splat, .vec_extract, .vec_insert => {
|
||||
.call_closure, .closure_create, .union_get, .union_gep, .vec_splat, .vec_extract, .vec_insert => {
|
||||
return error.CannotEvalComptime;
|
||||
},
|
||||
}
|
||||
|
||||
@@ -393,17 +393,6 @@ pub const Builder = struct {
|
||||
return self.emit(.{ .compiler_call = .{ .name = @intFromEnum(name_id), .args = owned } }, ret_ty);
|
||||
}
|
||||
|
||||
// ── Protocol ────────────────────────────────────────────────────
|
||||
|
||||
pub fn protocolCallDynamic(self: *Builder, receiver: Ref, method_index: u32, args: []const Ref, ret_ty: TypeId) Ref {
|
||||
const owned = self.module.alloc.dupe(Ref, args) catch unreachable;
|
||||
return self.emit(.{ .protocol_call_dynamic = .{ .receiver = receiver, .method_index = method_index, .args = owned } }, ret_ty);
|
||||
}
|
||||
|
||||
pub fn protocolErase(self: *Builder, concrete: Ref, protocol_type: TypeId) Ref {
|
||||
return self.emit(.{ .protocol_erase = .{ .concrete = concrete, .protocol_type = protocol_type } }, protocol_type);
|
||||
}
|
||||
|
||||
// ── Closure ─────────────────────────────────────────────────────
|
||||
|
||||
pub fn closureCreate(self: *Builder, func_id: FuncId, env: Ref, ty: TypeId) Ref {
|
||||
@@ -426,16 +415,6 @@ pub const Builder = struct {
|
||||
return self.emit(.{ .box_any = .{ .operand = operand, .source_type = source_type } }, .any);
|
||||
}
|
||||
|
||||
// ── Context ─────────────────────────────────────────────────────
|
||||
|
||||
pub fn contextLoad(self: *Builder, field: StringId, ty: TypeId) Ref {
|
||||
return self.emit(.{ .context_load = .{ .field = field, .value = .none } }, ty);
|
||||
}
|
||||
|
||||
pub fn contextStore(self: *Builder, field: StringId, value: Ref) void {
|
||||
self.emitVoid(.{ .context_store = .{ .field = field, .value = value } }, .void);
|
||||
}
|
||||
|
||||
// ── Terminators ─────────────────────────────────────────────────
|
||||
|
||||
pub fn br(self: *Builder, target: BlockId, args: []const Ref) void {
|
||||
|
||||
@@ -336,19 +336,6 @@ fn printInst(instruction: *const Inst, ref_idx: u32, tt: *const TypeTable, write
|
||||
try writer.writeAll(") : ");
|
||||
},
|
||||
|
||||
// ── Protocol ────────────────────────────────────────────
|
||||
.protocol_call_dynamic => |c| {
|
||||
try writer.print("protocol_call_dynamic %{d}.{d}(", .{ c.receiver.index(), c.method_index });
|
||||
try writeArgs(c.args, writer);
|
||||
try writer.writeAll(") : ");
|
||||
},
|
||||
.protocol_erase => |pe| {
|
||||
try writer.print("protocol_erase %{d} -> ", .{pe.concrete.index()});
|
||||
try writeType(pe.protocol_type, tt, writer);
|
||||
try writer.writeByte('\n');
|
||||
return;
|
||||
},
|
||||
|
||||
// ── Closure ─────────────────────────────────────────────
|
||||
.closure_create => |cc| {
|
||||
try writer.print("closure_create @{d}", .{cc.func.index()});
|
||||
@@ -358,26 +345,6 @@ fn printInst(instruction: *const Inst, ref_idx: u32, tt: *const TypeTable, write
|
||||
try writer.writeAll(" : ");
|
||||
},
|
||||
|
||||
// ── Context ─────────────────────────────────────────────
|
||||
.context_load => |co| {
|
||||
try writer.writeAll("context_load .");
|
||||
try writer.writeAll(tt.getString(co.field));
|
||||
try writer.writeAll(" : ");
|
||||
},
|
||||
.context_store => |co| {
|
||||
try writer.writeAll("context_store .");
|
||||
try writer.writeAll(tt.getString(co.field));
|
||||
try writer.print(", %{d}\n", .{co.value.index()});
|
||||
return;
|
||||
},
|
||||
.context_save => {
|
||||
try writer.writeAll("context_save : ");
|
||||
},
|
||||
.context_restore => |u| {
|
||||
try writer.print("context_restore %{d}\n", .{u.operand.index()});
|
||||
return;
|
||||
},
|
||||
|
||||
// ── Globals ─────────────────────────────────────────────
|
||||
.global_get => |gid| try writer.print("global_get @{d} : ", .{gid.index()}),
|
||||
.global_addr => |gid| try writer.print("global_addr @{d} : ", .{gid.index()}),
|
||||
@@ -554,7 +521,7 @@ fn writeConstant(val: ConstantValue, writer: Writer) !void {
|
||||
|
||||
fn isVoidOp(op: Op) bool {
|
||||
return switch (op) {
|
||||
.store, .heap_free, .context_store, .context_restore, .global_set, .br, .cond_br, .switch_br, .ret, .ret_void, .@"unreachable" => true,
|
||||
.store, .heap_free, .global_set, .br, .cond_br, .switch_br, .ret, .ret_void, .@"unreachable" => true,
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user