sm
This commit is contained in:
@@ -106,6 +106,18 @@ pub const InterpError = error{
|
||||
Unreachable,
|
||||
};
|
||||
|
||||
// ── BuildConfig ─────────────────────────────────────────────────────────
|
||||
// Mutable build configuration accumulated by #run blocks via BuildOptions methods.
|
||||
|
||||
pub const BuildConfig = struct {
|
||||
link_flags: std.ArrayList([]const u8) = .empty,
|
||||
output_path: ?[]const u8 = null,
|
||||
|
||||
pub fn deinit(self: *BuildConfig, alloc: Allocator) void {
|
||||
self.link_flags.deinit(alloc);
|
||||
}
|
||||
};
|
||||
|
||||
// ── Interpreter ─────────────────────────────────────────────────────────
|
||||
|
||||
pub const Interpreter = struct {
|
||||
@@ -121,6 +133,9 @@ pub const Interpreter = struct {
|
||||
// Global values: evaluated comptime globals, indexed by GlobalId
|
||||
global_values: std.AutoHashMap(u32, Value),
|
||||
|
||||
// Mutable build configuration — set by LLVMEmitter, written by #run blocks
|
||||
build_config: ?*BuildConfig = null,
|
||||
|
||||
pub fn init(module: *const Module, alloc: Allocator) Interpreter {
|
||||
return .{
|
||||
.module = module,
|
||||
@@ -1242,6 +1257,30 @@ pub const Interpreter = struct {
|
||||
const f = val.asFloat() orelse return error.TypeError;
|
||||
return .{ .value = .{ .float = @floor(f) } };
|
||||
},
|
||||
.build_options => {
|
||||
// Returns a void sentinel — the "handle" to BuildConfig
|
||||
return .{ .value = .void_val };
|
||||
},
|
||||
.build_options_add_link_flag => {
|
||||
// args: [opts_handle, flag_string]
|
||||
const str_val = frame.getRef(bi.args[1]);
|
||||
if (str_val.asString(self)) |s| {
|
||||
if (self.build_config) |bc| {
|
||||
bc.link_flags.append(self.alloc, self.alloc.dupe(u8, s) catch return error.CannotEvalComptime) catch return error.CannotEvalComptime;
|
||||
}
|
||||
}
|
||||
return .{ .value = .void_val };
|
||||
},
|
||||
.build_options_set_output_path => {
|
||||
// args: [opts_handle, path_string]
|
||||
const str_val = frame.getRef(bi.args[1]);
|
||||
if (str_val.asString(self)) |s| {
|
||||
if (self.build_config) |bc| {
|
||||
bc.output_path = self.alloc.dupe(u8, s) catch return error.CannotEvalComptime;
|
||||
}
|
||||
}
|
||||
return .{ .value = .void_val };
|
||||
},
|
||||
.cast, .type_of, .alloc, .dealloc => {
|
||||
return error.CannotEvalComptime;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user