Skip to content

Commit

Permalink
Merge pull request #809 from Vexu/rewrite-type
Browse files Browse the repository at this point in the history
represent Type as a tagged union
  • Loading branch information
Vexu authored Jan 8, 2025
2 parents aed93e2 + 3169dc4 commit 58a9330
Show file tree
Hide file tree
Showing 64 changed files with 7,298 additions and 6,522 deletions.
4 changes: 3 additions & 1 deletion src/aro.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ pub const target_util = @import("aro/target.zig");
pub const Tokenizer = @import("aro/Tokenizer.zig");
pub const Toolchain = @import("aro/Toolchain.zig");
pub const Tree = @import("aro/Tree.zig");
pub const Type = @import("aro/Type.zig");
pub const TypeStore = @import("aro/TypeStore.zig");
pub const QualType = TypeStore.QualType;
pub const Type = TypeStore.Type;
pub const Value = @import("aro/Value.zig");

const backend = @import("backend");
Expand Down
245 changes: 130 additions & 115 deletions src/aro/Attribute.zig

Large diffs are not rendered by default.

272 changes: 131 additions & 141 deletions src/aro/Builtins.zig

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions src/aro/Builtins/eval.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const Builtins = @import("../Builtins.zig");
const Builtin = Builtins.Builtin;
const Parser = @import("../Parser.zig");
const Tree = @import("../Tree.zig");
const Type = @import("../Type.zig");
const TypeStore = @import("../TypeStore.zig");
const Type = TypeStore.Type;
const QualType = TypeStore.QualType;
const Value = @import("../Value.zig");

fn makeNan(comptime T: type, str: []const u8) T {
Expand All @@ -30,13 +32,13 @@ pub fn eval(tag: Builtin.Tag, p: *Parser, args: []const Tree.Node.Index) !Value
.__builtin_inf,
.__builtin_infl,
=> {
const ty: Type = switch (tag) {
.__builtin_inff => .{ .specifier = .float },
.__builtin_inf => .{ .specifier = .double },
.__builtin_infl => .{ .specifier = .long_double },
const qt: QualType = switch (tag) {
.__builtin_inff => .float,
.__builtin_inf => .double,
.__builtin_infl => .long_double,
else => unreachable,
};
const f: Interner.Key.Float = switch (ty.bitSizeof(p.comp).?) {
const f: Interner.Key.Float = switch (qt.bitSizeof(p.comp)) {
32 => .{ .f32 = std.math.inf(f32) },
64 => .{ .f64 = std.math.inf(f64) },
80 => .{ .f80 = std.math.inf(f80) },
Expand Down Expand Up @@ -70,7 +72,7 @@ pub fn eval(tag: Builtin.Tag, p: *Parser, args: []const Tree.Node.Index) !Value
const val = p.getDecayedStringLiteral(args[0]) orelse break :blk;
const bytes = p.comp.interner.get(val.ref()).bytes;

const f: Interner.Key.Float = switch ((Type{ .specifier = .double }).bitSizeof(p.comp).?) {
const f: Interner.Key.Float = switch (Type.Float.double.bits(p.comp)) {
32 => .{ .f32 = makeNan(f32, bytes) },
64 => .{ .f64 = makeNan(f64, bytes) },
80 => .{ .f80 = makeNan(f80, bytes) },
Expand Down
241 changes: 127 additions & 114 deletions src/aro/CodeGen.zig

Large diffs are not rendered by default.

438 changes: 123 additions & 315 deletions src/aro/Compilation.zig

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/aro/Diagnostics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub const Message = struct {
},
ignored_record_attr: struct {
tag: Attribute.Tag,
specifier: enum { @"struct", @"union", @"enum" },
tag_kind: enum { @"struct", @"union", @"enum" },
},
attribute_todo: struct {
tag: Attribute.Tag,
Expand Down Expand Up @@ -221,6 +221,7 @@ pub const Options = struct {
@"sign-conversion": Kind = .default,
@"address-of-packed-member": Kind = .default,
nonnull: Kind = .default,
@"atomic-access": Kind = .default,
};

const Diagnostics = @This();
Expand Down Expand Up @@ -432,7 +433,7 @@ pub fn renderMessage(comp: *Compilation, m: anytype, msg: Message) void {
}),
.ignored_record_attr => printRt(m, prop.msg, .{ "{s}", "{s}" }, .{
@tagName(msg.extra.ignored_record_attr.tag),
@tagName(msg.extra.ignored_record_attr.specifier),
@tagName(msg.extra.ignored_record_attr.tag_kind),
}),
.attribute_todo => printRt(m, prop.msg, .{ "{s}", "{s}" }, .{
@tagName(msg.extra.attribute_todo.tag),
Expand Down
90 changes: 66 additions & 24 deletions src/aro/Diagnostics/messages.def
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ missing_type_specifier_c23
.msg = "a type specifier is required for all declarations"
.kind = .@"error"

param_not_declared
.msg = "parameter '{s}' was not declared, defaults to 'int'"
.opt = W("implicit-int")
.extra = .str
.kind = .warning
.all = true

multiple_storage_class
.msg = "cannot combine with previous '{s}' declaration specifier"
.extra = .str
Expand All @@ -231,6 +238,16 @@ cannot_combine_spec
.extra = .str
.kind = .@"error"

cannot_combine_with_typedef
.msg = "'{s} type-name' is invalid"
.extra = .str
.kind = .@"error"

cannot_combine_with_typeof
.msg = "'{s} typeof' is invalid"
.extra = .str
.kind = .@"error"

duplicate_decl_spec
.msg = "duplicate '{s}' declaration specifier"
.extra = .str
Expand Down Expand Up @@ -269,11 +286,6 @@ extern_initializer
.opt = W("extern-initializer")
.kind = .warning

spec_from_typedef
.msg = "'{s}' came from typedef"
.extra = .str
.kind = .note

param_before_var_args
.msg = "ISO C requires a named parameter before '...'"
.kind = .@"error"
Expand Down Expand Up @@ -887,20 +899,44 @@ parameter_here
.kind = .note

atomic_array
.msg = "atomic cannot be applied to array type '{s}'"
.msg = "_Atomic cannot be applied to array type '{s}'"
.extra = .str
.kind = .@"error"

atomic_func
.msg = "atomic cannot be applied to function type '{s}'"
.msg = "_Atomic cannot be applied to function type '{s}'"
.extra = .str
.kind = .@"error"

atomic_incomplete
.msg = "atomic cannot be applied to incomplete type '{s}'"
.msg = "_Atomic cannot be applied to incomplete type '{s}'"
.extra = .str
.kind = .@"error"

atomic_atomic
.msg = "_Atomic cannot be applied to atomic type '{s}'"
.extra = .str
.kind = .@"error"

atomic_complex
.msg = "_Atomic cannot be applied to complex type '{s}'"
.extra = .str
.kind = .@"error"

atomic_qualified
.msg = "_Atomic cannot be applied to qualified type '{s}'"
.extra = .str
.kind = .@"error"

atomic_auto
.msg = "_Atomic cannot be applied to type 'auto' in C23"
.kind = .@"error"

atomic_access
.msg = "accessing a member of an atomic structure or union is undefined behavior"
.opt = W("atomic-access")
.kind = .@"error"

addr_of_register
.msg = "address of register variable requested"
.kind = .@"error"
Expand Down Expand Up @@ -1066,11 +1102,6 @@ arr_init_too_long
.extra = .str
.kind = .@"error"

invalid_typeof
.msg = "'{s} typeof' is invalid"
.extra = .str
.kind = .@"error"

division_by_zero
.msg = "{s} by zero is undefined"
.extra = .str
Expand Down Expand Up @@ -1226,6 +1257,11 @@ member_expr_ptr
.extra = .str
.kind = .@"error"

member_expr_atomic
.msg = "accessing a member of atomic type '{s}' is undefined behavior"
.extra = .str
.kind = .@"error"

no_such_member
.msg = "no member named {s}"
.extra = .str
Expand Down Expand Up @@ -1517,6 +1553,10 @@ func_field
.msg = "field declared as a function"
.kind = .@"error"

expected_member_name
.msg = "expected member name after declarator"
.kind = .@"error"

vla_field
.msg = "variable length array fields extension is not supported"
.kind = .@"error"
Expand Down Expand Up @@ -2211,15 +2251,11 @@ auto_type_requires_plain_declarator
.msg = "'__auto_type' requires a plain identifier as declarator"
.kind = .@"error"

invalid_cast_to_auto_type
.msg = "invalid cast to '__auto_type'"
.kind = .@"error"

auto_type_from_bitfield
.msg = "cannot use bit-field as '__auto_type' initializer"
.kind = .@"error"

array_of_auto_type
auto_type_array
.msg = "'{s}' declared as array of '__auto_type'"
.kind = .@"error"
.extra = .str
Expand Down Expand Up @@ -2494,10 +2530,6 @@ identifier_not_normalized
.extra = .normalized
.opt = W("normalized")

c23_auto_plain_declarator
.msg = "'auto' requires a plain identifier declarator"
.kind = .@"error"

c23_auto_single_declarator
.msg = "'auto' can only be used with a single declarator"
.kind = .@"error"
Expand All @@ -2506,9 +2538,19 @@ c32_auto_requires_initializer
.msg = "'auto' requires an initializer"
.kind = .@"error"

c23_auto_scalar_init
.msg = "'auto' requires a scalar initializer"
c23_auto_not_allowed
.msg = "'auto' not allowed in {s}"
.kind = .@"error"
.extra = .str

c23_auto_with_init_list
.msg = "cannot use 'auto' with array"
.kind = .@"error"

c23_auto_array
.msg = "'{s}' declared as array of 'auto'"
.kind = .@"error"
.extra = .str

negative_shift_count
.msg = "shift count is negative"
Expand Down
1 change: 0 additions & 1 deletion src/aro/InitList.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const Tree = @import("Tree.zig");
const Token = Tree.Token;
const TokenIndex = Tree.TokenIndex;
const Node = Tree.Node;
const Type = @import("Type.zig");

const Item = struct {
list: InitList,
Expand Down
Loading

0 comments on commit 58a9330

Please sign in to comment.