-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wasm): Simplify registering accessor via prop_name("…")
* Introduce `[comp].allocatePROP` * Imports `env:cABIprop` and `env:cache` in instance/[comp].wasm
- Loading branch information
Showing
13 changed files
with
181 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
/// <reference types="./registry.d.ts" /> | ||
/** @typedef {import("./registry.js")} $ */ | ||
|
||
/** @type $["event"] */ export let event; | ||
/** @type $["setCurrentEvent"] */ | ||
export const setCurrentEvent = (event_) => { | ||
event = event_; | ||
}; | ||
|
||
/** @type $["event"] */ | ||
export let event; | ||
|
||
/** @type $["value"] */ export let value; | ||
/** @type $["setCurrentValue"] */ | ||
export const setCurrentValue = (value_) => { | ||
value = value_; | ||
}; | ||
|
||
/** @type $["value"] */ | ||
export let value; | ||
/** @type $["module"] */ export let module; | ||
/** @type $["setCurrentModule"] */ | ||
export const setCurrentmodule = (module_) => { | ||
module = module_; | ||
}; | ||
|
||
/** @type $["index"] */ | ||
export const index = Symbol(); | ||
|
||
/** @type $["default"] */ | ||
export default new WeakMap(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { PropCache, WasmBinder } from "../registry.js"; | ||
|
||
export const memory: WebAssembly.Memory; | ||
export const offset: WebAssembly.Global, | ||
index: WebAssembly.Global, | ||
scopeSize: WebAssembly.Global; | ||
|
||
export function prop( | ||
propNameAddr: number, | ||
propNameLen: number, | ||
): [addr: number, len: number]; | ||
|
||
export function cache(addr: number, len: number): void; | ||
|
||
declare type MayCache = PropCache | undefined; | ||
declare type Series = WasmBinder["series_"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/// <reference types="./imports.d.ts" /> | ||
/** @typedef {import("./imports.js")} $ */ | ||
/** @typedef {import("./imports.js").MayCache} MayCache */ | ||
/** @typedef {import("./imports.js").Series} Series */ | ||
import registry, { module } from "../registry.js"; | ||
|
||
export const memory = new WebAssembly.Memory({ initial: 1 }); | ||
|
||
const muti32 = () => new WebAssembly.Global({ mutable: true, value: "i32" }); | ||
export const offset = muti32(), | ||
index = muti32(), | ||
scopeSize = muti32(); | ||
|
||
const utf8 = new TextDecoder(); | ||
|
||
let /** @type string|undefined */ propName; | ||
let /** @type Series|undefined */ series_; | ||
|
||
/** @type $["prop"] */ | ||
export function prop(propNameAddr, propNameLen) { | ||
propName = utf8.decode(memory.buffer.slice(propNameAddr, propNameLen)); | ||
series_ = /** @type MayCache */ (registry.get(module))?.[propName].series_; | ||
return series_?.[index.value] ?? [0, -1]; | ||
} | ||
|
||
/** @type $["cache"] */ | ||
export function cache(addr, len) { | ||
/** @type Series */ (series_)[index.value] = [addr, len]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,19 @@ | ||
use libnusa::{number, Accessor}; | ||
use std::sync::OnceLock; | ||
|
||
#[derive(Default)] | ||
struct This { | ||
count: number::u8, | ||
} | ||
static THIS: OnceLock<This> = OnceLock::new(); | ||
|
||
#[no_mangle] | ||
fn constructor() { | ||
let _ = THIS.set(This::default()); | ||
} | ||
|
||
#[no_mangle] | ||
fn set_count(value: u8) { | ||
if let Some(this) = THIS.get() { | ||
this.count.set(value); | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
fn get_count() -> u8 { | ||
if let Some(this) = THIS.get() { | ||
this.count.get() | ||
} else { | ||
unreachable!() | ||
} | ||
thread_local! { | ||
static THIS: This = This { | ||
count: number::u8::prop_name("count"), | ||
}; | ||
} | ||
|
||
#[no_mangle] | ||
fn increment() { | ||
if let Some(this) = THIS.get() { | ||
this.count.set(this.count.get() + 1) | ||
} else { | ||
unreachable!() | ||
} | ||
THIS.with(|this| { | ||
this.count.set(this.count.get() + 1); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.