1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
//! Native C ABI. The caller supplies aligned instance storage; no global VM,
//! allocator, OS call or browser dependency is part of this selected module.
const Engine = @import("engine.zig").Engine;
const fixed_definition = @hasDecl(@import("root"), "pure_definition");
// Keep ReleaseSafe bounds/overflow checks. Unexpected internal invariant
// failures trap without importing a process-wide stack unwinder or I/O layer.
// Expected authored errors still return the ordinary scalar status codes.
pub const panic = @import("std").debug.no_panic;
export fn pure_scalar_bytes() usize {
return @sizeOf(Engine);
}
export fn pure_scalar_alignment() usize {
return @alignOf(Engine);
}
export fn pure_scalar_initialize(memory: ?*anyopaque, size: usize) ?*Engine {
const pointer = memory orelse return null;
if (size < @sizeOf(Engine) or @intFromPtr(pointer) % @alignOf(Engine) != 0) return null;
const instance: *Engine = @ptrCast(@alignCast(pointer));
instance.* = .{};
return instance;
}
export fn pure_scalar_reset_all(instance: *Engine) void {
instance.reset_all();
}
export fn pure_scalar_install_fixed(instance: *Engine, identity: *const [32]u8,
state_count: u32, input_count: u32, instruction_count: u32,
handler_count: u32, target_count: u32, restored: ?[*]const f64) u32 {
return instance.installFixed(identity, state_count, input_count, instruction_count,
handler_count, target_count, restored);
}
export fn pure_scalar_begin_program(instance: *Engine, state_count: u32, input_count: u32) u32 {
if (comptime fixed_definition) return 1;
return instance.begin_program(state_count, input_count);
}
export fn pure_scalar_abort_program(instance: *Engine) void {
if (comptime fixed_definition) return;
instance.abort_program();
}
export fn pure_scalar_put_state(instance: *Engine, id: u32, initial: f64, old_id: i32) u32 {
if (comptime fixed_definition) return 1;
return instance.put_state(id, initial, old_id);
}
export fn pure_scalar_put_instruction(instance: *Engine, op: u32, arg: u32, value: f64) u32 {
if (comptime fixed_definition) return 1;
return instance.put_instruction(op, arg, value);
}
export fn pure_scalar_put_handler(instance: *Engine, event: u32, start: u32, length: u32) u32 {
if (comptime fixed_definition) return 1;
return instance.put_handler(event, start, length);
}
export fn pure_scalar_bind_handler(instance: *Engine, handler: u32, base: u32, count: u32) u32 {
if (comptime fixed_definition) return 1;
return instance.bind_handler(handler, base, count);
}
export fn pure_scalar_put_pointer_target(instance: *Engine, input: u32, base: u32, count: u32) u32 {
if (comptime fixed_definition) return 1;
return instance.put_pointer_target(input, base, count);
}
export fn pure_scalar_bind_target_handler(instance: *Engine, handler: u32, count: u32) u32 {
if (comptime fixed_definition) return 1;
return instance.bind_target_handler(handler, count);
}
export fn pure_scalar_put_restored_value(instance: *Engine, id: u32, value: f64) u32 {
if (comptime fixed_definition) return 1;
return instance.put_restored_value(id, value);
}
export fn pure_scalar_commit_program(instance: *Engine) u32 {
if (comptime fixed_definition) return 1;
return instance.commit_program();
}
export fn pure_scalar_commit_restored_program(instance: *Engine) u32 {
if (comptime fixed_definition) return 1;
return instance.commit_restored_program();
}
export fn pure_scalar_reset_state(instance: *Engine) void {
instance.reset_state();
}
export fn pure_scalar_dispatch(instance: *Engine, event: u32, dt: f64) u32 {
return instance.dispatch(event, dt);
}
export fn pure_scalar_dispatch_point(instance: *Engine, event: u32, x: f64, y: f64) u32 {
return instance.dispatch_point(event, x, y);
}
export fn pure_scalar_dispatch_target(instance: *Engine, event: u32, target: u32, x: f64, y: f64) u32 {
return instance.dispatch_target(event, target, x, y);
}
export fn pure_scalar_dispatch_value(instance: *Engine, event: u32, value: f64) u32 {
return instance.dispatch_value(event, value);
}
export fn pure_scalar_eval_at(instance: *Engine, start: u32, length: u32) f64 {
return instance.eval_at(start, length);
}
export fn pure_scalar_configure_evaluation(instance: *Engine, cache: u32, history: u32) u32 {
return instance.configure_evaluation(cache, history);
}
export fn pure_scalar_forget_evaluation(instance: *Engine, flags: u32) void {
instance.forget_evaluation(flags);
}
export fn pure_scalar_begin_evaluation(instance: *Engine, limit: u32) void {
instance.begin_evaluation(limit);
}
export fn pure_scalar_eval_bounded(instance: *Engine, start: u32, length: u32) f64 {
return instance.eval_bounded(start, length);
}
export fn pure_scalar_evaluation_info(instance: *Engine, id: u32) u32 {
return instance.evaluation_info(id);
}
export fn pure_scalar_get_state(instance: *Engine, id: u32) f64 {
return instance.get_state(id);
}
export fn pure_scalar_info(instance: *Engine, id: u32) u32 {
return instance.info(id);
}
export fn pure_scalar_layout(instance: *Engine, id: u32) u32 {
return instance.layout(id);
}
|