aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/zilch/App/event.js14
-rw-r--r--src/zilch/App/load.js (renamed from src/zilch/App/main.js)24
-rw-r--r--src/zilch/App/object-store.js6
-rw-r--r--src/zilch/App/root.zig3
-rw-r--r--src/zilch/root.zig17
5 files changed, 42 insertions, 22 deletions
diff --git a/src/zilch/App/event.js b/src/zilch/App/event.js
new file mode 100644
index 0000000..c55637c
--- /dev/null
+++ b/src/zilch/App/event.js
@@ -0,0 +1,14 @@
+async function wasm_handle_event(target, name, event, pass_event) {
+ await wasm_ready;
+
+ const component = target.getRootNode().host;
+
+ if (pass_event) {
+ const id = ObjectStore.generateFreeId();
+ ObjectStore.registerObject(id, event);
+ wasm.exports[name](component[ZsPtr], id);
+ ObjectStore.free(event);
+ } else {
+ wasm.exports[name](component[ZsPtr]);
+ }
+}
diff --git a/src/zilch/App/main.js b/src/zilch/App/load.js
index 265c886..e93a4a6 100644
--- a/src/zilch/App/main.js
+++ b/src/zilch/App/load.js
@@ -18,26 +18,20 @@ const imports = {
}
}
-async function wasm_handle_event(target, name, event, pass_event) {
- await wasm_ready;
-
- const component = target.getRootNode().host;
-
- if (pass_event) {
- const id = ObjectStore.generateFreeId();
- ObjectStore.registerObject(id, event);
- wasm.exports[name](component[ZsPtr], id);
- ObjectStore.free(event);
- } else {
- wasm.exports[name](component[ZsPtr]);
- }
-}
-
const wasm_ready = WebAssembly.instantiateStreaming(fetch("index.wasm"), imports).then(
({ instance, module }) => {
+ const view = new DataView(instance.exports.memory.buffer);
+ const type_names = [ 'Call', 'Value', 'Ptr' ];
+ const size_of = {};
+
+ for (const type of type_names) {
+ size_of[type] = view.getUint16(instance.exports[`type::size::${type}`], true);
+ }
+
wasm = {
exports: instance.exports,
memory: instance.exports.memory,
+ size_of: size_of,
}
},
);
diff --git a/src/zilch/App/object-store.js b/src/zilch/App/object-store.js
index 3566c89..33879c6 100644
--- a/src/zilch/App/object-store.js
+++ b/src/zilch/App/object-store.js
@@ -160,17 +160,17 @@ class ObjectStore {
for (let i = 0; i < length; ++i) {
const method = ObjectStore.decodeCall(calls_view, offset.call);
- offset.call += 8;
+ offset.call += wasm.size_of.Call;
let args = new Array(method.num_args).fill().map(_ => {
const value = ObjectStore.decodeValue(values_view, offset.value, results);
- offset.value += 16;
+ offset.value += wasm.size_of.Value;
return value;
});
const result = method.kind(...args);
const result_ptr = results_view.getUint32(offset.result, true);
- offset.result += 4;
+ offset.result += wasm.size_of.Ptr;
results.push(result);
diff --git a/src/zilch/App/root.zig b/src/zilch/App/root.zig
index 94f311b..c2cc024 100644
--- a/src/zilch/App/root.zig
+++ b/src/zilch/App/root.zig
@@ -90,7 +90,8 @@ pub fn App(comptime options: Options) type {
.node("script", .{}, &.{.text(@embedFile("symbols.js"))}),
.node("script", .{}, &.{.text(@embedFile("object-store.js"))}),
.node("script", .{}, &.{.text(functions)}),
- .node("script", .{}, &.{.text(@embedFile("main.js"))}),
+ .node("script", .{}, &.{.text(@embedFile("event.js"))}),
+ .node("script", .{}, &.{.text(@embedFile("load.js"))}),
.node("script", .{}, &.{.text(reg: {
var register_code: []const u8 = "";
diff --git a/src/zilch/root.zig b/src/zilch/root.zig
index 2a31691..1ececbb 100644
--- a/src/zilch/root.zig
+++ b/src/zilch/root.zig
@@ -2,9 +2,9 @@ const builtin = @import("builtin");
const std = @import("std");
pub const Env = @import("Env/root.zig");
-pub const Call = Call.Env;
-pub const AnyFuture = AnyFuture.Env;
-pub const Future = Future.Env;
+pub const Call = Env.Call;
+pub const AnyFuture = Env.AnyFuture;
+pub const Future = Env.Future;
pub const Value = Env.Value;
pub const log = @import("log/root.zig");
pub const html = @import("html/root.zig");
@@ -23,3 +23,14 @@ fn defaultPanic(msg: []const u8, _: ?usize) noreturn {
}
pub const panic = std.debug.FullPanic(defaultPanic);
+
+const Ptr = struct { o: *anyopaque };
+comptime {
+ const export_sizes = .{ Call, Value, Ptr };
+
+ for (export_sizes) |T| {
+ const size: u16 = @sizeOf(T);
+ const name = @typeName(T)[if (std.mem.findScalarLast(u8, @typeName(T), '.')) |i| i + 1 else 0..];
+ @export(&size, .{ .name = std.fmt.comptimePrint("type::size::{s}", .{name}) });
+ }
+}