build options #compiler
This commit is contained in:
@@ -534,7 +534,7 @@ pub const Lowering = struct {
|
||||
// No AST? (builtins, foreign functions, or imported functions not in this file)
|
||||
const fd = self.fn_ast_map.get(name) orelse return;
|
||||
// Check builtin/foreign/generic — these stay as extern stubs
|
||||
if (fd.body.data == .builtin_expr or fd.body.data == .foreign_expr) return;
|
||||
if (fd.body.data == .builtin_expr or fd.body.data == .foreign_expr or fd.body.data == .compiler_expr) return;
|
||||
if (fd.type_params.len > 0) return; // generics handled by monomorphization (Step 3.13)
|
||||
|
||||
// Defer functions with type-category matches until all types are registered.
|
||||
@@ -685,7 +685,7 @@ pub const Lowering = struct {
|
||||
}
|
||||
|
||||
// Check if the function body is a builtin or foreign declaration (no body needed)
|
||||
if (fd.body.data == .builtin_expr or fd.body.data == .foreign_expr) {
|
||||
if (fd.body.data == .builtin_expr or fd.body.data == .foreign_expr or fd.body.data == .compiler_expr) {
|
||||
// Already declared by scanDecls/declareFunction (which handles #foreign renames)
|
||||
return;
|
||||
}
|
||||
@@ -3707,6 +3707,14 @@ pub const Lowering = struct {
|
||||
return self.lowerGenericCall(fd, func_name, c, args.items);
|
||||
}
|
||||
}
|
||||
// Check for #compiler free functions
|
||||
if (self.fn_ast_map.get(func_name)) |fd_check| {
|
||||
if (fd_check.body.data == .compiler_expr) {
|
||||
const ret_ty = if (fd_check.return_type) |rt| type_bridge.resolveAstType(rt, &self.module.types) else TypeId.void;
|
||||
return self.builder.compilerCall(func_name, args.items, ret_ty);
|
||||
}
|
||||
}
|
||||
|
||||
// Look up declared/extern function — try lazy lowering if not yet lowered
|
||||
{
|
||||
// First attempt: function may already be declared (from scanDecls)
|
||||
@@ -3960,18 +3968,16 @@ pub const Lowering = struct {
|
||||
// Try to resolve the method by struct type name
|
||||
const struct_name = self.getStructTypeName(obj_ty);
|
||||
if (struct_name) |sname| {
|
||||
// Intercept BuildOptions compiler builtins
|
||||
if (std.mem.eql(u8, sname, "BuildOptions")) {
|
||||
if (std.mem.eql(u8, fa.field, "add_link_flag")) {
|
||||
return self.builder.callBuiltin(.build_options_add_link_flag, method_args.items, .void);
|
||||
} else if (std.mem.eql(u8, fa.field, "set_output_path")) {
|
||||
return self.builder.callBuiltin(.build_options_set_output_path, method_args.items, .void);
|
||||
}
|
||||
}
|
||||
|
||||
// Try direct qualified name: StructName.method
|
||||
const qualified = std.fmt.allocPrint(self.alloc, "{s}.{s}", .{ sname, fa.field }) catch fa.field;
|
||||
|
||||
// Generic #compiler method dispatch
|
||||
if (self.fn_ast_map.get(qualified)) |method_fd| {
|
||||
if (method_fd.body.data == .compiler_expr) {
|
||||
return self.builder.compilerCall(qualified, method_args.items, .void);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for generic struct template method
|
||||
if (self.struct_instance_template.get(sname)) |tmpl_name| {
|
||||
// This is an instantiated generic struct — look up template method
|
||||
@@ -7595,13 +7601,14 @@ pub const Lowering = struct {
|
||||
const oi = self.module.types.get(obj_ty);
|
||||
if (oi == .@"struct") {
|
||||
const struct_name = self.module.types.getString(oi.@"struct".name);
|
||||
// Intercept BuildOptions compiler builtins
|
||||
if (std.mem.eql(u8, struct_name, "BuildOptions")) {
|
||||
if (std.mem.eql(u8, cfa.field, "add_link_flag") or std.mem.eql(u8, cfa.field, "set_output_path")) {
|
||||
const qualified = std.fmt.allocPrint(self.alloc, "{s}.{s}", .{ struct_name, cfa.field }) catch cfa.field;
|
||||
// Generic #compiler method dispatch — return type from declaration
|
||||
if (self.fn_ast_map.get(qualified)) |method_fd| {
|
||||
if (method_fd.body.data == .compiler_expr) {
|
||||
if (method_fd.return_type) |rt| return type_bridge.resolveAstType(rt, &self.module.types);
|
||||
return .void;
|
||||
}
|
||||
}
|
||||
const qualified = std.fmt.allocPrint(self.alloc, "{s}.{s}", .{ struct_name, cfa.field }) catch cfa.field;
|
||||
if (self.resolveFuncByName(qualified)) |fid| {
|
||||
return self.module.functions.items[@intFromEnum(fid)].ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user