This commit is contained in:
agra
2026-02-15 11:35:47 +02:00
parent da1a69ade8
commit 476bf0d268
3 changed files with 317 additions and 259 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,10 @@ const types = @import("types.zig");
const Type = types.Type; const Type = types.Type;
const unescape = @import("unescape.zig"); const unescape = @import("unescape.zig");
fn baseName(name: []const u8) []const u8 {
return if (std.mem.lastIndexOfScalar(u8, name, '.')) |idx| name[idx + 1 ..] else name;
}
/// Runtime value for comptime evaluation. /// Runtime value for comptime evaluation.
/// Replaces codegen's JitResult with richer type support. /// Replaces codegen's JitResult with richer type support.
pub const Value = union(enum) { pub const Value = union(enum) {
@@ -651,7 +655,7 @@ pub const Compiler = struct {
if (callee_name) |name| { if (callee_name) |name| {
// Check if it's a builtin // Check if it's a builtin
const base = if (std.mem.lastIndexOfScalar(u8, name, '.')) |idx| name[idx + 1 ..] else name; const base = baseName(name);
if (std.meta.stringToEnum(BuiltinId, base)) |id| { if (std.meta.stringToEnum(BuiltinId, base)) |id| {
try self.emit(.{ .call_builtin = .{ .id = id, .arg_count = @intCast(call_node.args.len) } }); try self.emit(.{ .call_builtin = .{ .id = id, .arg_count = @intCast(call_node.args.len) } });
} else { } else {

View File

@@ -6,6 +6,10 @@ const Type = @import("types.zig").Type;
const errors = @import("errors.zig"); const errors = @import("errors.zig");
const Diagnostic = errors.Diagnostic; const Diagnostic = errors.Diagnostic;
fn baseName(name: []const u8) []const u8 {
return if (std.mem.lastIndexOfScalar(u8, name, '.')) |idx| name[idx + 1 ..] else name;
}
pub const SymbolKind = enum { pub const SymbolKind = enum {
variable, variable,
constant, constant,
@@ -344,7 +348,7 @@ pub const Analyzer = struct {
return sig.return_type; return sig.return_type;
} }
// Built-in: sqrt/sin/cos 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; const base = baseName(callee_name);
if (std.mem.eql(u8, base, "sqrt") or if (std.mem.eql(u8, base, "sqrt") or
std.mem.eql(u8, base, "sin") or std.mem.eql(u8, base, "sin") or
std.mem.eql(u8, base, "cos")) std.mem.eql(u8, base, "cos"))