@native-sdk/cli 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.zig +73 -37
- package/build.zig +239 -5
- package/native-sdk.d.ts +5 -1
- package/package.json +13 -12
- package/packages/core/compile-surface/core.ts +30 -0
- package/packages/core/package-lock.json +6 -6
- package/packages/core/package.json +3 -3
- package/packages/core/scripts/scriptc-toolchain.json +44 -44
- package/packages/core/scripts/stage_external_core.mjs +27 -16
- package/packages/core/sdk/core.d.ts +24 -1
- package/packages/core/sdk/core.ts +51 -1
- package/packages/core/sdk/events.d.ts +5 -0
- package/packages/core/sdk/events.ts +10 -0
- package/packages/core/src/bridge_descriptors.ts +3 -3
- package/packages/core/src/checker.ts +20 -0
- package/packages/core/src/cli.ts +2 -11
- package/packages/core/src/context_menus.ts +76 -0
- package/packages/core/src/diagnostics.ts +7 -0
- package/packages/core/src/extent_program.ts +53 -0
- package/packages/core/src/frontend.ts +12 -10
- package/packages/core/src/markup_canonical.ts +140 -0
- package/packages/core/src/markup_construction.ts +189 -0
- package/packages/core/src/markup_display.ts +43 -0
- package/packages/core/src/markup_document.ts +226 -0
- package/packages/core/src/markup_elements.ts +225 -0
- package/packages/core/src/markup_expressions.ts +79 -0
- package/packages/core/src/markup_imports.ts +146 -0
- package/packages/core/src/markup_parser.ts +228 -0
- package/packages/core/src/markup_runtime.ts +93 -0
- package/packages/core/src/markup_scalars.ts +143 -0
- package/packages/core/src/markup_shapes.ts +243 -0
- package/packages/core/src/markup_specialized.ts +242 -0
- package/packages/core/src/markup_text.ts +86 -0
- package/packages/core/src/markup_values.ts +336 -0
- package/packages/core/src/portable_sources.json +24 -0
- package/packages/core/src/registered_font.ts +2 -3
- package/packages/core/src/runtime_policy.ts +24 -0
- package/packages/core/src/scalar_text.ts +1 -3
- package/packages/core/src/scroll_mutation.ts +86 -0
- package/packages/core/src/scroll_tree.ts +86 -0
- package/packages/core/src/service_contract.ts +53 -2
- package/packages/core/src/sqlite_cli.ts +3 -46
- package/packages/core/src/sqlite_codegen.ts +84 -0
- package/packages/core/src/staged_rebuild.ts +60 -0
- package/packages/core/src/view_bridge.ts +161 -0
- package/packages/core/src/view_check.ts +145 -0
- package/packages/core/src/view_evaluator.ts +823 -0
- package/packages/core/src/view_frontend.ts +340 -218
- package/packages/core/src/view_program.ts +221 -0
- package/packages/core/src/view_reload.ts +166 -0
- package/packages/core/src/view_reload_watch.ts +98 -0
- package/packages/core/src/view_sources.ts +34 -0
- package/packages/core/src/virtual_windows.ts +88 -0
- package/packages/core/src/web_panes.ts +67 -0
- package/packages/core/src/widget_continuity.ts +37 -0
- package/packages/core/src/widget_reconcile.ts +63 -0
- package/packages/core/src/widget_retention.ts +62 -0
- package/skill-data/native-ui/SKILL.md +2 -2
- package/skill-data/ts-core/SKILL.md +5 -3
- package/skill-data/ts-services/references/service-surface.md +29 -5
- package/src/app_runner/root.zig +14 -0
- package/src/app_runner/ts_compiled_view.zig +88 -17
- package/src/app_runner/ts_core_main.zig +43 -5
- package/src/app_runner/ts_core_mobile.zig +1 -1
- package/src/automation/server.zig +56 -3
- package/src/embed/host.zig +2 -0
- package/src/embed/tests.zig +2 -0
- package/src/embed/ui_host.zig +2 -0
- package/src/platform/keyboard_input.zig +32 -0
- package/src/platform/linux/root.zig +2 -0
- package/src/platform/macos/appkit_host.h +7 -2
- package/src/platform/macos/appkit_host.m +31 -9
- package/src/platform/macos/cef_host.mm +15 -1
- package/src/platform/macos/global_shortcuts.zig +138 -0
- package/src/platform/macos/key_codes.zig +102 -0
- package/src/platform/macos/keyboard_input.zig +81 -0
- package/src/platform/macos/root.zig +25 -3
- package/src/platform/macos/webview_inspection_test.m +106 -0
- package/src/platform/null_platform.zig +104 -0
- package/src/platform/root.zig +14 -0
- package/src/platform/types.zig +102 -0
- package/src/platform/windows/global_shortcuts.zig +157 -0
- package/src/platform/windows/key_codes.zig +63 -0
- package/src/platform/windows/keyboard_input.zig +136 -0
- package/src/platform/windows/root.zig +15 -0
- package/src/primitives/canvas/decision_reuse.zig +133 -0
- package/src/primitives/canvas/font_ttf.zig +27 -3
- package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
- package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
- package/src/primitives/canvas/fonts/OFL.txt +93 -0
- package/src/primitives/canvas/fonts/README.md +15 -0
- package/src/primitives/canvas/intrinsic_measure_policy.zig +4 -1
- package/src/primitives/canvas/markdown_tests.zig +3 -3
- package/src/primitives/canvas/reference.zig +3 -5
- package/src/primitives/canvas/reference_tests.zig +58 -0
- package/src/primitives/canvas/registered_font_policy.zig +1 -1
- package/src/primitives/canvas/root.zig +7 -4
- package/src/primitives/canvas/text_metrics.zig +32 -39
- package/src/primitives/canvas/text_metrics_tests.zig +52 -7
- package/src/primitives/canvas/text_query_policy.zig +142 -3
- package/src/primitives/canvas/text_scalar_policy.zig +80 -2
- package/src/primitives/canvas/tokens.zig +9 -0
- package/src/primitives/canvas/ui.zig +1 -0
- package/src/primitives/canvas/ui_markup.zig +69 -14
- package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +1407 -23
- package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
- package/src/primitives/canvas/ui_markup_construction.zig +146 -0
- package/src/primitives/canvas/ui_markup_display.zig +82 -0
- package/src/primitives/canvas/ui_markup_document.zig +196 -0
- package/src/primitives/canvas/ui_markup_elements.zig +163 -0
- package/src/primitives/canvas/ui_markup_expr.zig +192 -2
- package/src/primitives/canvas/ui_markup_imports.zig +262 -0
- package/src/primitives/canvas/ui_markup_parser.zig +117 -0
- package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
- package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
- package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
- package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
- package/src/primitives/canvas/ui_markup_text.zig +128 -0
- package/src/primitives/canvas/ui_markup_values.zig +368 -0
- package/src/primitives/canvas/ui_markup_view.zig +2817 -74
- package/src/primitives/canvas/virtual_extent_policy.zig +58 -0
- package/src/primitives/canvas/virtual_extents.zig +47 -33
- package/src/primitives/canvas/widget_metric_policy.zig +4 -1
- package/src/primitives/canvas/widget_runtime.zig +2 -1
- package/src/root.zig +5 -0
- package/src/runtime/api.zig +1 -0
- package/src/runtime/bridge_descriptor_policy.zig +1 -1
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/canvas_widget_context_menu.zig +179 -0
- package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
- package/src/runtime/canvas_widget_runtime.zig +306 -92
- package/src/runtime/context_menu_policy.zig +112 -0
- package/src/runtime/core.zig +14 -0
- package/src/runtime/effects.zig +172 -4
- package/src/runtime/effects_host_tests.zig +25 -0
- package/src/runtime/flow.zig +1 -0
- package/src/runtime/flow_reference.zig +1 -0
- package/src/runtime/global_shortcuts.zig +75 -0
- package/src/runtime/keyboard_input.zig +86 -0
- package/src/runtime/root.zig +3 -0
- package/src/runtime/scroll_mutation_policy.zig +130 -0
- package/src/runtime/scroll_mutation_runtime.zig +158 -0
- package/src/runtime/scroll_tree_policy.zig +99 -0
- package/src/runtime/session_record.zig +7 -0
- package/src/runtime/staged_rebuild_policy.zig +83 -0
- package/src/runtime/system_services.zig +19 -0
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_core_host.zig +126 -0
- package/src/runtime/ts_ui_app.zig +24 -0
- package/src/runtime/ui_app.zig +274 -31
- package/src/runtime/ui_app_tests.zig +48 -179
- package/src/runtime/ui_app_window_tests.zig +133 -0
- package/src/runtime/view_reload.zig +226 -0
- package/src/runtime/view_widget_scroll.zig +30 -21
- package/src/runtime/view_widget_tree.zig +43 -13
- package/src/runtime/virtual_window_policy.zig +128 -0
- package/src/runtime/web_pane_policy.zig +111 -0
- package/src/runtime/web_pane_test_cases.zig +204 -0
- package/src/runtime/widget_continuity_policy.zig +73 -0
- package/src/runtime/widget_reconcile_policy.zig +81 -0
- package/src/runtime/widget_retention_policy.zig +75 -0
- package/src/runtime/window_views.zig +19 -4
- package/src/security/root.zig +1 -0
- package/src/tooling/templates.zig +8 -0
- package/src/tooling/ts_core.zig +84 -1
- package/src/tooling/verbs.zig +79 -15
- package/tools/corewire/core.test.ts +25 -3
- package/tools/corewire/core_abi.zig +4 -0
- package/tools/corewire/core_contract.ts +1 -1
- package/tools/corewire/core_goldens.json +75 -75
- package/tools/corewire/core_projection.ts +3 -2
- package/tools/corewire/emit_mirror.ts +19 -9
- package/tools/corewire/facade_templates.ts +1 -1
- package/tools/corewire/intake.test.ts +4 -0
- package/tools/corewire/intake_goldens.json +50 -50
- package/tools/corewire/invocation.test.ts +4 -0
- package/tools/corewire/invocation_goldens.json +3 -3
- package/tools/corewire/mirror_templates.ts +4 -0
- package/tools/corewire/profile_emission.ts +2 -0
- package/tools/corewire/sidecar.zig +2 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//! Runtime value capabilities for statically lowered markup. The same compiled
|
|
2
|
+
//! programs used by the interpreter admit values and select borrowed keys/enum
|
|
3
|
+
//! fields. Native retains exact integer bounds, numeric casts and typed storage.
|
|
4
|
+
const std = @import("std");
|
|
5
|
+
const markup = @import("ui_markup.zig");
|
|
6
|
+
const values = @import("ui_markup_values.zig");
|
|
7
|
+
const elements = @import("ui_markup_elements.zig");
|
|
8
|
+
const canvas = @import("root.zig");
|
|
9
|
+
|
|
10
|
+
pub fn enumValue(comptime T: type, owner: markup.expr.Policy, text: []const u8) ?T {
|
|
11
|
+
var request = values.Request.init(15);
|
|
12
|
+
defer request.deinit();
|
|
13
|
+
request.blob(text);
|
|
14
|
+
const fields = @typeInfo(T).@"enum".fields;
|
|
15
|
+
request.word(fields.len);
|
|
16
|
+
inline for (fields) |field| request.blob(field.name);
|
|
17
|
+
const row = request.decision(owner);
|
|
18
|
+
if (row.action == 0) return null;
|
|
19
|
+
if (row.action != 74 or row.fields[0] >= fields.len) @panic("invalid compiled markup enum capability");
|
|
20
|
+
inline for (fields, 0..) |field, index| if (row.fields[0] == index) return @field(T, field.name);
|
|
21
|
+
unreachable;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pub fn convert(comptime T: type, owner: markup.expr.Policy, value: markup.expr.Value, comptime payload: bool) ?T {
|
|
25
|
+
const class = comptime values.typeClass(T);
|
|
26
|
+
const within = if (comptime class == 4)
|
|
27
|
+
value == .integer and value.integer >= (if (payload) std.math.minInt(T) else 0) and value.integer <= std.math.maxInt(T)
|
|
28
|
+
else
|
|
29
|
+
false;
|
|
30
|
+
const row = values.decide(owner, if (payload) 5 else 4, &.{ class, values.kind(value), @intFromBool(within) });
|
|
31
|
+
if (row.action == 255) return null;
|
|
32
|
+
if (row.action != class) @panic("invalid compiled markup conversion capability");
|
|
33
|
+
return switch (comptime class) {
|
|
34
|
+
1 => switch (value) {
|
|
35
|
+
.float => |number| @floatCast(number),
|
|
36
|
+
.integer => |number| @floatFromInt(number),
|
|
37
|
+
else => unreachable,
|
|
38
|
+
},
|
|
39
|
+
2 => markup.expr.truthyWithPolicy(owner, value),
|
|
40
|
+
3 => enumValue(T, owner, value.string),
|
|
41
|
+
4 => @intCast(value.integer),
|
|
42
|
+
5 => value.string,
|
|
43
|
+
else => unreachable,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
pub fn key(owner: markup.expr.Policy, value: markup.expr.Value, omitted_default: bool) error{InvalidValue}!?canvas.UiKey {
|
|
48
|
+
const row = elements.decide(owner, 4, &.{ 1, @intFromBool(omitted_default), 1, switch (value) {
|
|
49
|
+
.integer => 0,
|
|
50
|
+
.float => 1,
|
|
51
|
+
.string => 2,
|
|
52
|
+
.boolean => 3,
|
|
53
|
+
}, @intFromBool(value == .string and value.string.len == 0) });
|
|
54
|
+
return switch (row.action) {
|
|
55
|
+
0 => null,
|
|
56
|
+
1 => canvas.uiKey(@as(u64, @bitCast(value.integer))),
|
|
57
|
+
2 => canvas.uiKey(value.string),
|
|
58
|
+
255 => error.InvalidValue,
|
|
59
|
+
else => @panic("invalid compiled markup key capability"),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
pub fn resource(owner: markup.expr.Policy, value: markup.expr.Value, channel: u8) elements.Record {
|
|
64
|
+
return values.decide(owner, 1, &.{ channel, values.kind(value), @intFromBool(value == .integer and value.integer >= 0) });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// Policy sees exact i64 words and selects admission/clamping; native casts the original value.
|
|
68
|
+
pub fn collectionIndex(owner: markup.expr.Policy, value: markup.expr.Value, comptime clamp_negative: bool) ?usize {
|
|
69
|
+
const row = values.integerOption(owner, if (clamp_negative) 1 else 0, value, 0);
|
|
70
|
+
return switch (row.action) {
|
|
71
|
+
1 => @intCast(value.integer),
|
|
72
|
+
2 => if (clamp_negative) 0 else @panic("invalid static index clamp capability"),
|
|
73
|
+
255 => null,
|
|
74
|
+
else => @panic("invalid static index capability"),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
//! Copied construction facts and borrowed native storage capabilities.
|
|
2
|
+
const std = @import("std");
|
|
3
|
+
const m = @import("ui_markup.zig");
|
|
4
|
+
const scratch = std.heap.page_allocator;
|
|
5
|
+
|
|
6
|
+
pub const Record = struct { action: u8, code: u8, fields: [5]usize };
|
|
7
|
+
pub fn number(bytes: []const u8, at: usize) usize {
|
|
8
|
+
if (bytes.len -| at < 8) @panic("short construction number");
|
|
9
|
+
const n: f64 = @bitCast(std.mem.readInt(u64, bytes[at..][0..8], .little));
|
|
10
|
+
if (!std.math.isFinite(n) or n < 0 or n > 9007199254740991 or n != @trunc(n) or n >= @as(f64, @floatFromInt(std.math.maxInt(usize)))) @panic("invalid construction number");
|
|
11
|
+
return @intFromFloat(n);
|
|
12
|
+
}
|
|
13
|
+
fn header(bytes: []const u8, mode: u8) usize {
|
|
14
|
+
if (bytes.len < 16 or bytes[0] != 110 or bytes[1] != 1 or bytes[2] != mode) @panic("invalid construction response");
|
|
15
|
+
for (bytes[3..8]) |b| if (b != 0) @panic("invalid construction reserved byte");
|
|
16
|
+
return number(bytes, 8);
|
|
17
|
+
}
|
|
18
|
+
fn record(bytes: []const u8) Record {
|
|
19
|
+
if (bytes.len != 48) @panic("invalid construction record");
|
|
20
|
+
for (bytes[2..8]) |b| if (b != 0) @panic("invalid construction reserved byte");
|
|
21
|
+
var out: Record = .{ .action = bytes[0], .code = bytes[1], .fields = undefined };
|
|
22
|
+
for (&out.fields, 0..) |*field, i| field.* = number(bytes, 8 + i * 8);
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
pub const Program = struct {
|
|
26
|
+
bytes: []u8,
|
|
27
|
+
at: usize = 16,
|
|
28
|
+
pub fn deinit(self: *Program) void {
|
|
29
|
+
scratch.free(self.bytes);
|
|
30
|
+
}
|
|
31
|
+
pub fn next(self: *Program) ?Record {
|
|
32
|
+
if (self.at == self.bytes.len) return null;
|
|
33
|
+
if (self.bytes.len - self.at < 48) @panic("truncated construction program");
|
|
34
|
+
const out = record(self.bytes[self.at..][0..48]);
|
|
35
|
+
self.at += 48;
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
pub const Request = struct {
|
|
40
|
+
bytes: std.ArrayListUnmanaged(u8) = .empty,
|
|
41
|
+
nodes: std.ArrayListUnmanaged(m.MarkupNode) = .empty,
|
|
42
|
+
pub fn init(mode: u8) Request {
|
|
43
|
+
var out: Request = .{};
|
|
44
|
+
out.bytes.appendSlice(scratch, &.{ 110, 1, mode, 1 }) catch @panic("construction transport allocation failed");
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
pub fn deinit(self: *Request) void {
|
|
48
|
+
self.bytes.deinit(scratch);
|
|
49
|
+
self.nodes.deinit(scratch);
|
|
50
|
+
}
|
|
51
|
+
pub fn word(self: *Request, value: usize) void {
|
|
52
|
+
if (value > 9007199254740991) @panic("construction word exceeds exact range");
|
|
53
|
+
var raw: [8]u8 = undefined;
|
|
54
|
+
std.mem.writeInt(u64, &raw, @bitCast(@as(f64, @floatFromInt(value))), .little);
|
|
55
|
+
self.bytes.appendSlice(scratch, &raw) catch @panic("construction transport allocation failed");
|
|
56
|
+
}
|
|
57
|
+
pub fn words(self: *Request, values: []const usize) void {
|
|
58
|
+
for (values) |value| self.word(value);
|
|
59
|
+
}
|
|
60
|
+
pub fn blob(self: *Request, value: []const u8) void {
|
|
61
|
+
self.word(value.len);
|
|
62
|
+
self.bytes.appendSlice(scratch, value) catch @panic("construction transport allocation failed");
|
|
63
|
+
}
|
|
64
|
+
pub fn node(self: *Request, value: m.MarkupNode, descend: bool) void {
|
|
65
|
+
self.word(self.nodes.items.len);
|
|
66
|
+
self.nodes.append(scratch, value) catch @panic("construction transport allocation failed");
|
|
67
|
+
self.words(&.{ @intFromEnum(value.kind), value.attrs.len });
|
|
68
|
+
for (value.attrs) |attr| {
|
|
69
|
+
self.blob(attr.name);
|
|
70
|
+
self.blob(attr.value);
|
|
71
|
+
}
|
|
72
|
+
self.word(if (descend) value.children.len else 0);
|
|
73
|
+
if (descend) for (value.children) |child| self.node(child, child.kind != .use_block and child.kind != .slot_block);
|
|
74
|
+
}
|
|
75
|
+
pub fn useSite(self: *Request, value: m.MarkupNode) void {
|
|
76
|
+
// Only the first child is a structural witness. Consumer content is
|
|
77
|
+
// visited later under the captured scope, never in this preflight.
|
|
78
|
+
self.word(self.nodes.items.len);
|
|
79
|
+
self.nodes.append(scratch, value) catch @panic("construction transport allocation failed");
|
|
80
|
+
self.words(&.{ @intFromEnum(value.kind), value.attrs.len });
|
|
81
|
+
for (value.attrs) |attr| {
|
|
82
|
+
self.blob(attr.name);
|
|
83
|
+
self.blob(attr.value);
|
|
84
|
+
}
|
|
85
|
+
self.word(@intFromBool(value.children.len != 0));
|
|
86
|
+
if (value.children.len != 0) self.node(value.children[0], false);
|
|
87
|
+
}
|
|
88
|
+
pub fn decision(self: *Request, owner: m.expr.Policy) Record {
|
|
89
|
+
var out: [64]u8 = undefined;
|
|
90
|
+
if (owner(self.bytes.items, &out) != out.len or header(&out, 1) != 1) @panic("invalid construction decision");
|
|
91
|
+
return record(out[16..]);
|
|
92
|
+
}
|
|
93
|
+
pub fn program(self: *Request, owner: m.expr.Policy) error{OutOfMemory}!Program {
|
|
94
|
+
self.bytes.items[3] = 0;
|
|
95
|
+
var sizing: [16]u8 = undefined;
|
|
96
|
+
if (owner(self.bytes.items, &sizing) != sizing.len) @panic("invalid construction sizing");
|
|
97
|
+
const count = header(&sizing, 0);
|
|
98
|
+
const size = std.math.add(usize, 16, std.math.mul(usize, count, 48) catch return error.OutOfMemory) catch return error.OutOfMemory;
|
|
99
|
+
const out = try scratch.alloc(u8, size);
|
|
100
|
+
errdefer scratch.free(out);
|
|
101
|
+
self.bytes.items[3] = 1;
|
|
102
|
+
if (owner(self.bytes.items, out) != size or header(out, 1) != count) @panic("invalid construction program");
|
|
103
|
+
return .{ .bytes = out };
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
pub fn decide(owner: m.expr.Policy, mode: u8, values: []const usize) Record {
|
|
107
|
+
var request = Request.init(mode);
|
|
108
|
+
defer request.deinit();
|
|
109
|
+
request.words(values);
|
|
110
|
+
return request.decision(owner);
|
|
111
|
+
}
|
|
112
|
+
pub fn message(code: u8) []const u8 {
|
|
113
|
+
return switch (code) {
|
|
114
|
+
1 => m.import_unresolved_message,
|
|
115
|
+
2 => m.component_file_view_message,
|
|
116
|
+
3 => m.template_top_level_message,
|
|
117
|
+
4 => m.import_top_level_message,
|
|
118
|
+
5 => m.slot_outside_template_message,
|
|
119
|
+
6 => "text content is only allowed inside text-bearing elements",
|
|
120
|
+
7 => "structure tags are only allowed inside an element",
|
|
121
|
+
8 => "if requires a test attribute",
|
|
122
|
+
9 => m.else_placement_message,
|
|
123
|
+
10 => m.use_template_attr_message,
|
|
124
|
+
11 => m.use_undefined_template_message,
|
|
125
|
+
12 => m.use_earlier_template_message,
|
|
126
|
+
13 => "template expansion nests too deeply",
|
|
127
|
+
14 => m.template_one_child_message,
|
|
128
|
+
15 => m.template_one_slot_message,
|
|
129
|
+
16 => m.use_children_without_slot_message,
|
|
130
|
+
17 => m.use_forwarded_event_message,
|
|
131
|
+
18 => m.use_extra_arg_message,
|
|
132
|
+
19 => "template args nest too deep",
|
|
133
|
+
20 => m.template_default_literal_message,
|
|
134
|
+
21 => m.template_default_quoted_message,
|
|
135
|
+
22 => m.use_missing_arg_message,
|
|
136
|
+
23 => m.slot_attrs_message,
|
|
137
|
+
24 => m.slot_children_message,
|
|
138
|
+
25 => "for requires an each attribute",
|
|
139
|
+
26 => "for requires an as attribute",
|
|
140
|
+
27 => "for nesting is too deep",
|
|
141
|
+
28 => m.for_children_message,
|
|
142
|
+
29 => m.invalid_expression_message,
|
|
143
|
+
30 => "each does not name an iterable (a model slice, array, or fn - or a slice-valued template arg)",
|
|
144
|
+
else => @panic("invalid construction diagnostic"),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//! Numeric rendering and arena capabilities for copied display programs.
|
|
2
|
+
//! Plans contain no pointers and are fully admitted before any allocation.
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
const expr = @import("ui_markup_expr.zig");
|
|
5
|
+
|
|
6
|
+
fn execute(owner: expr.Policy, mode: u8, value: expr.Value, digits: usize, out: *std.ArrayListUnmanaged(u8), arena: std.mem.Allocator) error{OutOfMemory}!bool {
|
|
7
|
+
const kind: u8 = @as(u8, @intFromEnum(expr.kindOf(value))) + 1;
|
|
8
|
+
const request = [8]u8{ 104, 1, mode, kind, @intCast(digits), if (value == .boolean and value.boolean) 1 else 0, 0, 0 };
|
|
9
|
+
var output: [40]u8 = undefined;
|
|
10
|
+
const size = owner(&request, &output);
|
|
11
|
+
if (size < 8 or size > output.len or output[0] != 104 or output[1] != 1 or output[2] != mode or
|
|
12
|
+
output[3] == 0 or output[3] > 6 or output[4] > 5 or output[5] != 0 or output[6] != 0 or output[7] != 0 or
|
|
13
|
+
size != 8 + @as(usize, output[3]) * 4 + output[4]) @panic("invalid markup display header");
|
|
14
|
+
const literal = output[8 + @as(usize, output[3]) * 4 .. size];
|
|
15
|
+
var prepared = false;
|
|
16
|
+
var rendered = false;
|
|
17
|
+
for (0..output[3]) |i| {
|
|
18
|
+
const at = 8 + i * 4;
|
|
19
|
+
const a = output[at + 1];
|
|
20
|
+
const b = output[at + 2];
|
|
21
|
+
if (output[at + 3] != 0) @panic("invalid markup display instruction");
|
|
22
|
+
switch (output[at]) {
|
|
23
|
+
0, 1 => {
|
|
24
|
+
if (kind != (if (output[at] == 0) @as(u8, 2) else 3) or b != 0 or a != (if (mode == 0) @as(usize, 0) else digits))
|
|
25
|
+
@panic("invalid markup numeric capability");
|
|
26
|
+
rendered = true;
|
|
27
|
+
},
|
|
28
|
+
2 => {
|
|
29
|
+
if (mode != 2 or (value != .integer and value != .float) or a != 0 or b != 0) @panic("invalid markup scaling capability");
|
|
30
|
+
prepared = true;
|
|
31
|
+
},
|
|
32
|
+
3 => {
|
|
33
|
+
if (mode == 0 or (mode == 2 and !prepared) or (mode == 1 and value != .float) or a != digits or b != 0)
|
|
34
|
+
@panic("invalid markup decimal capability");
|
|
35
|
+
rendered = true;
|
|
36
|
+
},
|
|
37
|
+
4 => if (value != .string or a != 0 or b != 0) @panic("invalid markup source capability"),
|
|
38
|
+
5 => if (!rendered or a != 0 or b != 0) @panic("invalid markup body capability"),
|
|
39
|
+
6 => if (@as(usize, a) + b > literal.len) @panic("invalid markup literal capability"),
|
|
40
|
+
7 => if (b > 6) @panic("invalid markup repeat capability"),
|
|
41
|
+
else => @panic("unknown markup display capability"),
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
var buffer: [80]u8 = undefined;
|
|
45
|
+
var body: []const u8 = undefined;
|
|
46
|
+
var number: f32 = undefined;
|
|
47
|
+
for (0..output[3]) |i| {
|
|
48
|
+
const at = 8 + i * 4;
|
|
49
|
+
const a = output[at + 1];
|
|
50
|
+
const b = output[at + 2];
|
|
51
|
+
switch (output[at]) {
|
|
52
|
+
0 => body = std.fmt.bufPrint(buffer[0..64], "{d}", .{value.integer}) catch return error.OutOfMemory,
|
|
53
|
+
1 => body = std.fmt.bufPrint(buffer[0..64], "{d}", .{value.float}) catch return error.OutOfMemory,
|
|
54
|
+
2 => {
|
|
55
|
+
const fraction: f32 = if (value == .integer) @floatFromInt(value.integer) else value.float;
|
|
56
|
+
number = fraction * 100;
|
|
57
|
+
if (!std.math.isFinite(number)) return false;
|
|
58
|
+
},
|
|
59
|
+
3 => {
|
|
60
|
+
const float = if (mode == 2) number else value.float;
|
|
61
|
+
if (!std.math.isFinite(float)) return false;
|
|
62
|
+
body = std.fmt.float.render(&buffer, float, .{ .mode = .decimal, .precision = a }) catch return false;
|
|
63
|
+
},
|
|
64
|
+
4 => try out.appendSlice(arena, value.string),
|
|
65
|
+
5 => try out.appendSlice(arena, body),
|
|
66
|
+
6 => try out.appendSlice(arena, literal[a..][0..b]),
|
|
67
|
+
7 => try out.appendNTimes(arena, a, b),
|
|
68
|
+
else => unreachable,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
pub fn append(owner: expr.Policy, out: *std.ArrayListUnmanaged(u8), arena: std.mem.Allocator, value: expr.Value) error{OutOfMemory}!void {
|
|
75
|
+
if (!try execute(owner, 0, value, 0, out, arena)) unreachable;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
pub fn fixed(owner: expr.Policy, value: expr.Value, digits: usize, percent: bool, arena: std.mem.Allocator) error{OutOfMemory}!?[]const u8 {
|
|
79
|
+
var out: std.ArrayListUnmanaged(u8) = .empty;
|
|
80
|
+
if (!try execute(owner, if (percent) 2 else 1, value, digits, &out, arena)) return null;
|
|
81
|
+
return out.items;
|
|
82
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
//! Runtime grammar action transport. The compiled owner chooses syntax,
|
|
2
|
+
//! spans, positions, document order, inline separators and failure timing.
|
|
3
|
+
//! Native retains borrowed source slices and the original arena operations.
|
|
4
|
+
const std = @import("std");
|
|
5
|
+
const m = @import("ui_markup.zig");
|
|
6
|
+
|
|
7
|
+
pub fn parse(owner: m.expr.Policy, parser: *m.Parser) m.ParseError!m.MarkupDocument {
|
|
8
|
+
// Scratch transport never consumes the document allocator: replay keeps
|
|
9
|
+
// its original append/resize/alloc sequence, including on syntax failure.
|
|
10
|
+
const scratch = std.heap.page_allocator;
|
|
11
|
+
const request = try scratch.alloc(u8, std.math.add(usize, 32, parser.source.len) catch return error.OutOfMemory);
|
|
12
|
+
defer scratch.free(request);
|
|
13
|
+
@memset(request[0..32], 0);
|
|
14
|
+
request[0] = 107;
|
|
15
|
+
request[1] = 1;
|
|
16
|
+
put(request, 8, parser.index);
|
|
17
|
+
put(request, 16, parser.line);
|
|
18
|
+
put(request, 24, parser.column);
|
|
19
|
+
@memcpy(request[32..], parser.source);
|
|
20
|
+
var header: [16]u8 = undefined;
|
|
21
|
+
if (owner(request, &header) != 16 or header[0] != 107 or header[1] != 1 or header[2] != 0)
|
|
22
|
+
@panic("invalid document sizing response");
|
|
23
|
+
for (header[3..8]) |b| if (b != 0) @panic("invalid document sizing reserved bytes");
|
|
24
|
+
const count = number(&header, 8);
|
|
25
|
+
if (count == 0) @panic("empty compiled document tape");
|
|
26
|
+
const size = std.math.add(usize, 16, std.math.mul(usize, count, 96) catch return error.OutOfMemory) catch return error.OutOfMemory;
|
|
27
|
+
const tape = try scratch.alloc(u8, size);
|
|
28
|
+
defer scratch.free(tape);
|
|
29
|
+
request[2] = 1;
|
|
30
|
+
if (owner(request, tape) != size or tape[0] != 107 or tape[1] != 1 or tape[2] != 1 or number(tape, 8) != count)
|
|
31
|
+
@panic("invalid compiled document tape");
|
|
32
|
+
for (tape[3..8]) |b| if (b != 0) @panic("invalid document tape reserved bytes");
|
|
33
|
+
var reader: Reader = .{ .parser = parser, .tape = tape[16..] };
|
|
34
|
+
return reader.document();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fn put(bytes: []u8, at: usize, value: usize) void {
|
|
38
|
+
if (value > 9007199254740991) @panic("document position exceeds exact transport range");
|
|
39
|
+
std.mem.writeInt(u64, bytes[at..][0..8], @bitCast(@as(f64, @floatFromInt(value))), .little);
|
|
40
|
+
}
|
|
41
|
+
fn number(bytes: []const u8, at: usize) usize {
|
|
42
|
+
const value: f64 = @bitCast(std.mem.readInt(u64, bytes[at..][0..8], .little));
|
|
43
|
+
if (!std.math.isFinite(value) or value < 0 or value > 9007199254740991 or value != @trunc(value) or value >= @as(f64, @floatFromInt(std.math.maxInt(usize))))
|
|
44
|
+
@panic("invalid compiled document integer");
|
|
45
|
+
return @intFromFloat(value);
|
|
46
|
+
}
|
|
47
|
+
const Record = struct {
|
|
48
|
+
action: u8,
|
|
49
|
+
code: u8,
|
|
50
|
+
fields: [8]usize,
|
|
51
|
+
};
|
|
52
|
+
const Reader = struct {
|
|
53
|
+
parser: *m.Parser,
|
|
54
|
+
tape: []const u8,
|
|
55
|
+
cursor: usize = 0,
|
|
56
|
+
|
|
57
|
+
fn next(self: *Reader) m.ParseError!Record {
|
|
58
|
+
if (self.cursor >= self.tape.len) @panic("truncated compiled document tape");
|
|
59
|
+
const raw = self.tape[self.cursor..][0..96];
|
|
60
|
+
self.cursor += 96;
|
|
61
|
+
for (raw[2..8]) |b| if (b != 0) @panic("invalid document record reserved bytes");
|
|
62
|
+
const index = number(raw, 8);
|
|
63
|
+
const line = number(raw, 16);
|
|
64
|
+
const column = number(raw, 24);
|
|
65
|
+
if (index < self.parser.index or index > self.parser.source.len or line == 0 or column == 0)
|
|
66
|
+
@panic("invalid compiled document cursor");
|
|
67
|
+
self.parser.index = index;
|
|
68
|
+
self.parser.line = line;
|
|
69
|
+
self.parser.column = column;
|
|
70
|
+
var record: Record = .{ .action = raw[0], .code = raw[1], .fields = undefined };
|
|
71
|
+
for (&record.fields, 0..) |*field, i| field.* = number(raw, 32 + i * 8);
|
|
72
|
+
if (record.action == 12) {
|
|
73
|
+
if (record.fields[0] == 0 or record.fields[1] == 0) @panic("invalid document diagnostic position");
|
|
74
|
+
self.parser.diagnostic = .{ .line = record.fields[0], .column = record.fields[1], .message = message(record.code) };
|
|
75
|
+
return error.MarkupSyntax;
|
|
76
|
+
}
|
|
77
|
+
return record;
|
|
78
|
+
}
|
|
79
|
+
fn span(self: *Reader, start: usize, end: usize) []const u8 {
|
|
80
|
+
if (start > end or end > self.parser.source.len) @panic("invalid compiled document span");
|
|
81
|
+
return self.parser.source[start..end];
|
|
82
|
+
}
|
|
83
|
+
fn done(self: *Reader) void {
|
|
84
|
+
if (self.cursor != self.tape.len) @panic("trailing compiled document actions");
|
|
85
|
+
}
|
|
86
|
+
fn document(self: *Reader) m.ParseError!m.MarkupDocument {
|
|
87
|
+
var imports: std.ArrayListUnmanaged(m.MarkupNode) = .empty;
|
|
88
|
+
var templates: std.ArrayListUnmanaged(m.MarkupNode) = .empty;
|
|
89
|
+
while (true) {
|
|
90
|
+
const first = try self.next();
|
|
91
|
+
if (first.action == 11) {
|
|
92
|
+
self.done();
|
|
93
|
+
return .{ .imports = imports.items, .templates = templates.items, .source_bytes = self.parser.source.len };
|
|
94
|
+
}
|
|
95
|
+
const node = try self.element(first);
|
|
96
|
+
const action = try self.next();
|
|
97
|
+
switch (action.action) {
|
|
98
|
+
8 => try imports.append(self.parser.arena, node),
|
|
99
|
+
9 => try templates.append(self.parser.arena, node),
|
|
100
|
+
10 => {
|
|
101
|
+
self.done();
|
|
102
|
+
return .{ .imports = imports.items, .templates = templates.items, .root = node, .source_bytes = self.parser.source.len };
|
|
103
|
+
},
|
|
104
|
+
else => @panic("invalid document storage action"),
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
fn element(self: *Reader, first: Record) m.ParseError!m.MarkupNode {
|
|
109
|
+
if (first.action != 1 or first.code > @intFromEnum(m.MarkupNodeKind.slot_block)) @panic("invalid document element action");
|
|
110
|
+
var attrs: std.ArrayListUnmanaged(m.MarkupAttr) = .empty;
|
|
111
|
+
var header: Record = undefined;
|
|
112
|
+
while (true) {
|
|
113
|
+
const action = try self.next();
|
|
114
|
+
if (action.action != 2) {
|
|
115
|
+
header = action;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
const f = action.fields;
|
|
119
|
+
if (action.code > 1) @panic("invalid document attribute action");
|
|
120
|
+
try attrs.append(self.parser.arena, .{
|
|
121
|
+
.name = self.span(f[0], f[1]),
|
|
122
|
+
.value = if (action.code == 0) "" else self.span(f[2], f[3]),
|
|
123
|
+
.line = f[4],
|
|
124
|
+
.column = f[5],
|
|
125
|
+
.name_span = .{ .start = f[0], .end = f[1] },
|
|
126
|
+
.value_span = .{ .start = f[2], .end = f[3] },
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
var node: m.MarkupNode = .{
|
|
130
|
+
.kind = @enumFromInt(first.code),
|
|
131
|
+
.name = self.span(first.fields[3], first.fields[4]),
|
|
132
|
+
.attrs = attrs.items,
|
|
133
|
+
.line = first.fields[1],
|
|
134
|
+
.column = first.fields[2],
|
|
135
|
+
.span = .{ .start = first.fields[0], .end = self.parser.index },
|
|
136
|
+
};
|
|
137
|
+
if (header.action == 3) return node;
|
|
138
|
+
if (header.action != 4) @panic("invalid document header action");
|
|
139
|
+
var children: std.ArrayListUnmanaged(m.MarkupNode) = .empty;
|
|
140
|
+
while (true) {
|
|
141
|
+
const action = try self.next();
|
|
142
|
+
if (action.action == 6) {
|
|
143
|
+
node.children = children.items;
|
|
144
|
+
const separators = action.fields[0];
|
|
145
|
+
if (separators > 0) {
|
|
146
|
+
if (separators >= children.items.len) @panic("invalid document separator count");
|
|
147
|
+
const out = try self.parser.arena.alloc(m.MarkupNode, children.items.len + separators);
|
|
148
|
+
var copied: usize = 0;
|
|
149
|
+
for (0..separators) |i| {
|
|
150
|
+
const separator = try self.next();
|
|
151
|
+
const f = separator.fields;
|
|
152
|
+
if (separator.action != 7 or f[0] <= copied or f[0] >= children.items.len)
|
|
153
|
+
@panic("invalid document separator action");
|
|
154
|
+
@memcpy(out[copied + i .. f[0] + i], children.items[copied..f[0]]);
|
|
155
|
+
_ = self.span(f[1], f[2]);
|
|
156
|
+
out[f[0] + i] = .{ .kind = .text, .text = " ", .line = f[3], .column = f[4], .span = .{ .start = f[1], .end = f[2] } };
|
|
157
|
+
copied = f[0];
|
|
158
|
+
}
|
|
159
|
+
@memcpy(out[copied + separators ..], children.items[copied..]);
|
|
160
|
+
node.children = out;
|
|
161
|
+
}
|
|
162
|
+
node.span.end = self.parser.index;
|
|
163
|
+
return node;
|
|
164
|
+
}
|
|
165
|
+
const child: m.MarkupNode = if (action.action == 5) .{
|
|
166
|
+
.kind = .text,
|
|
167
|
+
.text = self.span(action.fields[0], action.fields[1]),
|
|
168
|
+
.line = action.fields[2],
|
|
169
|
+
.column = action.fields[3],
|
|
170
|
+
.span = .{ .start = action.fields[0], .end = action.fields[1] },
|
|
171
|
+
} else try self.element(action);
|
|
172
|
+
try children.append(self.parser.arena, child);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
fn message(code: u8) []const u8 {
|
|
178
|
+
return switch (code) {
|
|
179
|
+
1 => m.empty_document_message,
|
|
180
|
+
2 => "expected end of file after the root element",
|
|
181
|
+
3 => "expected '<' to open an element",
|
|
182
|
+
4 => "unterminated element tag",
|
|
183
|
+
5 => "expected '>' after '/' in a self-closing tag",
|
|
184
|
+
6 => "expected '>' to close the element tag",
|
|
185
|
+
7 => "expected '>' in closing tag",
|
|
186
|
+
8 => "expected a lowercase kebab-case name",
|
|
187
|
+
9 => "expected '\"' to open an attribute value",
|
|
188
|
+
10 => "attribute values may not contain newlines",
|
|
189
|
+
11 => "unterminated attribute value",
|
|
190
|
+
12 => "closing tag does not match the open element",
|
|
191
|
+
13 => m.import_top_level_message,
|
|
192
|
+
14 => m.max_templates_message,
|
|
193
|
+
15 => "element was never closed",
|
|
194
|
+
else => @panic("invalid compiled document diagnostic"),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
//! Copied element/schema facts and explicit native builder capabilities.
|
|
2
|
+
const std = @import("std");
|
|
3
|
+
const m = @import("ui_markup.zig");
|
|
4
|
+
const scratch = std.heap.page_allocator;
|
|
5
|
+
|
|
6
|
+
pub const Record = struct { action: u8, code: u8, fields: [5]usize };
|
|
7
|
+
pub fn number(bytes: []const u8, at: usize) usize {
|
|
8
|
+
if (bytes.len -| at < 8) @panic("short element number");
|
|
9
|
+
const n: f64 = @bitCast(std.mem.readInt(u64, bytes[at..][0..8], .little));
|
|
10
|
+
if (!std.math.isFinite(n) or n < 0 or n > 9007199254740991 or n != @trunc(n) or n >= @as(f64, @floatFromInt(std.math.maxInt(usize)))) @panic("invalid element number");
|
|
11
|
+
return @intFromFloat(n);
|
|
12
|
+
}
|
|
13
|
+
fn header(bytes: []const u8, mode: u8) usize {
|
|
14
|
+
if (bytes.len < 16 or bytes[0] != 111 or bytes[1] != 1 or bytes[2] != mode) @panic("invalid element response");
|
|
15
|
+
for (bytes[3..8]) |b| if (b != 0) @panic("invalid element reserved byte");
|
|
16
|
+
return number(bytes, 8);
|
|
17
|
+
}
|
|
18
|
+
fn record(bytes: []const u8) Record {
|
|
19
|
+
if (bytes.len != 48) @panic("invalid element record");
|
|
20
|
+
for (bytes[2..8]) |b| if (b != 0) @panic("invalid element reserved byte");
|
|
21
|
+
var out: Record = .{ .action = bytes[0], .code = bytes[1], .fields = undefined };
|
|
22
|
+
for (&out.fields, 0..) |*field, i| field.* = number(bytes, 8 + i * 8);
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
pub const Program = struct {
|
|
26
|
+
bytes: []u8,
|
|
27
|
+
at: usize = 16,
|
|
28
|
+
pub fn deinit(self: *Program) void {
|
|
29
|
+
scratch.free(self.bytes);
|
|
30
|
+
}
|
|
31
|
+
pub fn next(self: *Program) ?Record {
|
|
32
|
+
if (self.at == self.bytes.len) return null;
|
|
33
|
+
if (self.bytes.len - self.at < 48) @panic("truncated element program");
|
|
34
|
+
const out = record(self.bytes[self.at..][0..48]);
|
|
35
|
+
self.at += 48;
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
pub const Request = struct {
|
|
40
|
+
bytes: std.ArrayListUnmanaged(u8) = .empty,
|
|
41
|
+
pub fn init(mode: u8) Request {
|
|
42
|
+
var out: Request = .{};
|
|
43
|
+
out.bytes.appendSlice(scratch, &.{ 111, 1, mode, 1 }) catch @panic("element transport allocation failed");
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
pub fn deinit(self: *Request) void {
|
|
47
|
+
self.bytes.deinit(scratch);
|
|
48
|
+
}
|
|
49
|
+
pub fn word(self: *Request, value: usize) void {
|
|
50
|
+
if (value > 9007199254740991) @panic("element word exceeds exact range");
|
|
51
|
+
var raw: [8]u8 = undefined;
|
|
52
|
+
std.mem.writeInt(u64, &raw, @bitCast(@as(f64, @floatFromInt(value))), .little);
|
|
53
|
+
self.bytes.appendSlice(scratch, &raw) catch @panic("element transport allocation failed");
|
|
54
|
+
}
|
|
55
|
+
pub fn words(self: *Request, values: []const usize) void {
|
|
56
|
+
for (values) |value| self.word(value);
|
|
57
|
+
}
|
|
58
|
+
pub fn blob(self: *Request, value: []const u8) void {
|
|
59
|
+
self.word(value.len);
|
|
60
|
+
self.bytes.appendSlice(scratch, value) catch @panic("element transport allocation failed");
|
|
61
|
+
}
|
|
62
|
+
pub fn names(self: *Request, values: []const []const u8) void {
|
|
63
|
+
self.word(values.len);
|
|
64
|
+
for (values) |value| self.blob(value);
|
|
65
|
+
}
|
|
66
|
+
pub fn node(self: *Request, value: m.MarkupNode, children: bool) void {
|
|
67
|
+
self.blob(value.name);
|
|
68
|
+
self.word(value.attrs.len);
|
|
69
|
+
for (value.attrs) |attribute| {
|
|
70
|
+
self.blob(attribute.name);
|
|
71
|
+
self.blob(attribute.value);
|
|
72
|
+
// Only cached storage metadata crosses this boundary. The
|
|
73
|
+
// compiled owner derives raw and name-aware literal admission.
|
|
74
|
+
self.word(if (attribute.typed) |typed| @as(usize, @intFromEnum(typed.*)) + 1 else 0);
|
|
75
|
+
}
|
|
76
|
+
self.word(if (children) value.children.len else 0);
|
|
77
|
+
if (children) for (value.children) |child| {
|
|
78
|
+
self.word(@intFromEnum(child.kind));
|
|
79
|
+
self.blob(child.name);
|
|
80
|
+
self.blob(child.text);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
pub fn decision(self: *Request, owner: m.expr.Policy) Record {
|
|
84
|
+
var out: [64]u8 = undefined;
|
|
85
|
+
if (owner(self.bytes.items, &out) != out.len or header(&out, 1) != 1) @panic("invalid element decision");
|
|
86
|
+
return record(out[16..]);
|
|
87
|
+
}
|
|
88
|
+
pub fn program(self: *Request, owner: m.expr.Policy) error{OutOfMemory}!Program {
|
|
89
|
+
self.bytes.items[3] = 0;
|
|
90
|
+
var sizing: [16]u8 = undefined;
|
|
91
|
+
if (owner(self.bytes.items, &sizing) != sizing.len) @panic("invalid element sizing");
|
|
92
|
+
const count = header(&sizing, 0);
|
|
93
|
+
const size = std.math.add(usize, 16, std.math.mul(usize, count, 48) catch return error.OutOfMemory) catch return error.OutOfMemory;
|
|
94
|
+
const out = try scratch.alloc(u8, size);
|
|
95
|
+
errdefer scratch.free(out);
|
|
96
|
+
self.bytes.items[3] = 1;
|
|
97
|
+
if (owner(self.bytes.items, out) != size or header(out, 1) != count) @panic("invalid element program");
|
|
98
|
+
return .{ .bytes = out };
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
pub fn decide(owner: m.expr.Policy, mode: u8, values: []const usize) Record {
|
|
102
|
+
var request = Request.init(mode);
|
|
103
|
+
defer request.deinit();
|
|
104
|
+
request.words(values);
|
|
105
|
+
return request.decision(owner);
|
|
106
|
+
}
|
|
107
|
+
pub fn message(code: u8) []const u8 {
|
|
108
|
+
return switch (code) {
|
|
109
|
+
3 => m.step_parent_message,
|
|
110
|
+
4 => m.series_parent_message,
|
|
111
|
+
5 => m.context_menu_parent_message,
|
|
112
|
+
6 => m.input_group_actions_parent_message,
|
|
113
|
+
7 => m.span_parent_message,
|
|
114
|
+
8 => m.reactions_parent_message,
|
|
115
|
+
9 => "unknown element",
|
|
116
|
+
10 => m.context_menu_single_message,
|
|
117
|
+
11 => m.context_menu_host_message,
|
|
118
|
+
12 => m.reactions_single_message,
|
|
119
|
+
13 => m.bubble_text_attr_message,
|
|
120
|
+
14 => m.non_hit_target_handler_message,
|
|
121
|
+
15 => m.autofocus_element_message,
|
|
122
|
+
16 => m.stack_container_gap_message,
|
|
123
|
+
17 => m.wrap_element_message,
|
|
124
|
+
18 => m.overflow_element_message,
|
|
125
|
+
19 => m.submit_on_enter_element_message,
|
|
126
|
+
20 => m.overflow_value_message,
|
|
127
|
+
21 => m.text_size_element_message,
|
|
128
|
+
22 => m.size_value_message,
|
|
129
|
+
23 => m.split_children_message,
|
|
130
|
+
24 => m.image_missing_image_message,
|
|
131
|
+
25 => m.image_children_message,
|
|
132
|
+
26 => m.terminal_missing_pty_message,
|
|
133
|
+
27 => m.terminal_children_message,
|
|
134
|
+
28 => m.a11y_unlabeled_radiogroup_message,
|
|
135
|
+
29 => m.a11y_icon_only_message,
|
|
136
|
+
30 => m.a11y_unlabeled_control_message,
|
|
137
|
+
31 => m.a11y_unlabeled_editable_message,
|
|
138
|
+
32 => m.a11y_unknown_role_message,
|
|
139
|
+
33 => m.a11y_container_role_message,
|
|
140
|
+
34 => m.icon_missing_name_message,
|
|
141
|
+
35 => m.icon_children_message,
|
|
142
|
+
36 => m.text_or_children_content_message,
|
|
143
|
+
40 => m.image_source_element_message,
|
|
144
|
+
41 => m.image_source_binding_message,
|
|
145
|
+
42 => m.image_source_complete_message,
|
|
146
|
+
43 => m.scrollback_element_message,
|
|
147
|
+
44 => m.terminal_text_attr_message,
|
|
148
|
+
45 => m.video_flag_element_message,
|
|
149
|
+
46 => m.icon_name_element_message,
|
|
150
|
+
47 => "unknown attribute for this element",
|
|
151
|
+
48 => m.style_token_literal_message,
|
|
152
|
+
50 => "invalid message expression: on-* takes a Msg tag (\"add\") or tag with one binding payload (\"toggle:{item.id}\")",
|
|
153
|
+
51 => m.on_scroll_element_message,
|
|
154
|
+
52 => m.on_terminal_element_message,
|
|
155
|
+
53 => m.on_terminal_payload_message,
|
|
156
|
+
54 => m.on_resize_element_message,
|
|
157
|
+
55 => m.on_dismiss_element_message,
|
|
158
|
+
56 => m.on_reach_end_element_message,
|
|
159
|
+
57 => "unknown event attribute",
|
|
160
|
+
58 => "keys must be integers or strings",
|
|
161
|
+
else => @panic("invalid element diagnostic"),
|
|
162
|
+
};
|
|
163
|
+
}
|