Complete 3axis tutorial native and Web/WASM parity tools
This commit is contained in:
@@ -74,6 +74,7 @@ export class SimTask {
|
||||
if (!this.coreTask) return;
|
||||
const result = coreCall(this.core, name, "number", ["number", ...args.map(() => "number")], [this.coreTask, ...args]);
|
||||
if (result !== 0) throw new Error(`${code}_${result}`);
|
||||
this.syncFromCore();
|
||||
}
|
||||
|
||||
mirrorCommand(seq, tick) {
|
||||
@@ -81,6 +82,36 @@ export class SimTask {
|
||||
if (!this.coreTask) return;
|
||||
const result = coreCall(this.core, "sim_task_set_command", "number", ["number", "number", "number"], [this.coreTask, seq, tick]);
|
||||
if (result !== 0) throw new Error(`task_command_${result}`);
|
||||
this.syncFromCore();
|
||||
}
|
||||
|
||||
syncFromCore() {
|
||||
if (!this.coreTask || typeof this.core?._sim_task_canonical !== "function") return false;
|
||||
const required = coreCall(this.core, "sim_task_canonical", "number", ["number", "number", "number"], [this.coreTask, 0, 0]);
|
||||
if (!Number.isSafeInteger(required) || required <= 1 || required > 4096) throw new Error("task_core_canonical_invalid");
|
||||
const pointer = this.core._malloc(required);
|
||||
if (!pointer) throw new Error("task_core_canonical_allocation_failed");
|
||||
try {
|
||||
const written = coreCall(this.core, "sim_task_canonical", "number", ["number", "number", "number"], [this.coreTask, pointer, required]);
|
||||
const canonical = JSON.parse(readCoreString(this.core, pointer, written));
|
||||
if (canonical.schema !== TASK_SCHEMA || canonical.context_id !== this.contextId || canonical.session_id !== this.sessionId) throw new Error("task_core_canonical_context");
|
||||
this.state = {
|
||||
...this.state,
|
||||
state: canonical.state,
|
||||
mode: canonical.mode,
|
||||
program_status: canonical.program_status,
|
||||
seq: canonical.seq,
|
||||
simulation_tick: canonical.simulation_tick,
|
||||
current_line: canonical.current_line,
|
||||
};
|
||||
return true;
|
||||
} finally {
|
||||
this.core._free(pointer);
|
||||
}
|
||||
}
|
||||
|
||||
authority() {
|
||||
return this.coreTask && typeof this.core?._sim_task_canonical === "function" ? "wasm_task_canonical" : "js_compat";
|
||||
}
|
||||
|
||||
setCommand(seq, tick) {
|
||||
@@ -140,6 +171,7 @@ export class SimTask {
|
||||
}
|
||||
|
||||
export() {
|
||||
this.syncFromCore();
|
||||
const unsigned = clone(this.state);
|
||||
return { ...unsigned, state_hash: fnv1a64(unsigned) };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user