sdl phase 1

This commit is contained in:
agra
2026-02-12 12:27:35 +02:00
parent cfac6791cb
commit 1087bd1977
10 changed files with 820 additions and 10 deletions

View File

@@ -245,6 +245,21 @@ pub const Analyzer = struct {
const elem_name = elem_type.displayName(self.allocator) catch return .void_type;
return .{ .many_pointer_type = .{ .element_name = elem_name } };
}
// Function pointer type: (ParamTypes) -> ReturnType
if (tn.data == .function_type_expr) {
const fte = tn.data.function_type_expr;
var param_types = std.ArrayList(Type).empty;
for (fte.param_types) |pt| {
param_types.append(self.allocator, self.resolveTypeNode(pt)) catch return .void_type;
}
const ret_ty = if (fte.return_type) |rt| self.resolveTypeNode(rt) else Type.void_type;
const ret_ptr = self.allocator.create(Type) catch return .void_type;
ret_ptr.* = ret_ty;
return .{ .function_type = .{
.param_types = param_types.toOwnedSlice(self.allocator) catch return .void_type,
.return_type = ret_ptr,
} };
}
// Sema does not resolve generics; codegen handles instantiation
if (tn.data == .parameterized_type_expr) {
return .void_type;
@@ -320,9 +335,12 @@ pub const Analyzer = struct {
if (self.fn_signatures.get(callee_name)) |sig| {
return sig.return_type;
}
// Built-in: sqrt returns same type as argument
// Built-in: sqrt/sin/cos returns same type as argument
const base = if (std.mem.lastIndexOfScalar(u8, callee_name, '.')) |idx| callee_name[idx + 1 ..] else callee_name;
if (std.mem.eql(u8, base, "sqrt")) {
if (std.mem.eql(u8, base, "sqrt") or
std.mem.eql(u8, base, "sin") or
std.mem.eql(u8, base, "cos"))
{
if (call_node.args.len > 0) return self.inferExprType(call_node.args[0]);
return .f32;
}
@@ -673,6 +691,7 @@ pub const Analyzer = struct {
.builtin_expr,
.foreign_expr,
.library_decl,
.function_type_expr,
.import_decl,
.array_type_expr,
.slice_type_expr,
@@ -929,6 +948,7 @@ pub fn findNodeAtOffset(node: *Node, offset: u32) ?*Node {
.builtin_expr,
.foreign_expr,
.library_decl,
.function_type_expr,
.enum_decl,
.struct_decl,
.union_decl,