Skip to content

Commit

Permalink
Tweak generate.Tuple and generate.Union
Browse files Browse the repository at this point in the history
Leverage comptime fields to give generated Tuple a default value, allowing
TupleT and Tuple to be merged.

Only call generate.Tuple on the final output. This eliminates redundant
deduplication, and results in a simpler API (nested types just need to expose
a natural Zig tuple).

generate.Union leverages the new Tuple and removes unused features.
  • Loading branch information
karlseguin committed Feb 1, 2025
1 parent 00d332c commit fc0ec86
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 439 deletions.
2 changes: 1 addition & 1 deletion src/apiweb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ pub const Interfaces = generate.Tuple(.{
URL.Interfaces,
Iterators.Interfaces,
XMLSerializer.Interfaces,
});
}){};

pub const UserContext = @import("user_context.zig").UserContext;
5 changes: 2 additions & 3 deletions src/dom/character_data.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const std = @import("std");
const jsruntime = @import("jsruntime");
const Case = jsruntime.test_utils.Case;
const checkCases = jsruntime.test_utils.checkCases;
const generate = @import("../generate.zig");

const parser = @import("netsurf");

Expand All @@ -32,12 +31,12 @@ const ProcessingInstruction = @import("processing_instruction.zig").ProcessingIn
const HTMLElem = @import("../html/elements.zig");

// CharacterData interfaces
pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
Comment,
Text.Text,
Text.Interfaces,
ProcessingInstruction,
});
};

// CharacterData implementation
pub const CharacterData = struct {
Expand Down
6 changes: 2 additions & 4 deletions src/dom/dom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

const generate = @import("../generate.zig");

const DOMException = @import("exceptions.zig").DOMException;
const EventTarget = @import("event_target.zig").EventTarget;
const DOMImplementation = @import("implementation.zig").DOMImplementation;
Expand All @@ -27,7 +25,7 @@ const NodeList = @import("nodelist.zig");
const Nod = @import("node.zig");
const MutationObserver = @import("mutation_observer.zig");

pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
DOMException,
EventTarget,
DOMImplementation,
Expand All @@ -37,4 +35,4 @@ pub const Interfaces = generate.Tuple(.{
Nod.Node,
Nod.Interfaces,
MutationObserver.Interfaces,
});
};
6 changes: 2 additions & 4 deletions src/dom/mutation_observer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ const CallbackResult = jsruntime.CallbackResult;
const Case = jsruntime.test_utils.Case;
const checkCases = jsruntime.test_utils.checkCases;

const generate = @import("../generate.zig");

const NodeList = @import("nodelist.zig").NodeList;

pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
MutationObserver,
MutationRecord,
MutationRecords,
});
};

const Walker = @import("../dom/walker.zig").WalkerChildren;

Expand Down
10 changes: 4 additions & 6 deletions src/dom/node.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const HTML = @import("../html/html.zig");
const HTMLElem = @import("../html/elements.zig");

// Node interfaces
pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
Attr,
CData.CharacterData,
CData.Interfaces,
Expand All @@ -57,12 +57,10 @@ pub const Interfaces = generate.Tuple(.{
DocumentFragment,
HTMLCollection,
HTMLCollectionIterator,

HTML.Interfaces,
});
const Generated = generate.Union.compile(Interfaces);
pub const Union = Generated._union;
pub const Tags = Generated._enum;
};

pub const Union = generate.Union(Interfaces);

// Node implementation
pub const Node = struct {
Expand Down
5 changes: 2 additions & 3 deletions src/dom/nodelist.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const Callback = jsruntime.Callback;
const CallbackResult = jsruntime.CallbackResult;
const Case = jsruntime.test_utils.Case;
const checkCases = jsruntime.test_utils.checkCases;
const generate = @import("../generate.zig");

const NodeUnion = @import("node.zig").Union;
const Node = @import("node.zig").Node;
Expand All @@ -36,10 +35,10 @@ const log = std.log.scoped(.nodelist);

const DOMException = @import("exceptions.zig").DOMException;

pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
NodeListIterator,
NodeList,
});
};

pub const NodeListIterator = struct {
pub const mem_guarantied = true;
Expand Down
5 changes: 2 additions & 3 deletions src/dom/text.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const std = @import("std");
const jsruntime = @import("jsruntime");
const Case = jsruntime.test_utils.Case;
const checkCases = jsruntime.test_utils.checkCases;
const generate = @import("../generate.zig");

const parser = @import("netsurf");

Expand All @@ -31,9 +30,9 @@ const CDATASection = @import("cdata_section.zig").CDATASection;
const UserContext = @import("../user_context.zig").UserContext;

// Text interfaces
pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
CDATASection,
});
};

pub const Text = struct {
pub const Self = parser.Text;
Expand Down
8 changes: 4 additions & 4 deletions src/events/event.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ const ProgressEvent = @import("../xhr/progress_event.zig").ProgressEvent;
const log = std.log.scoped(.events);

// Event interfaces
pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
Event,
ProgressEvent,
});
const Generated = generate.Union.compile(Interfaces);
pub const Union = Generated._union;
};

pub const Union = generate.Union(Interfaces);

// https://dom.spec.whatwg.org/#event
pub const Event = struct {
Expand Down
Loading

0 comments on commit fc0ec86

Please sign in to comment.