haku2: add stats + fix crash w uninit vm
This commit is contained in:
parent
e667c6336a
commit
00a48527ca
12 changed files with 88 additions and 71 deletions
|
@ -43,31 +43,22 @@ export class BrushCostGauges extends HTMLElement {
|
|||
label: "Fuel",
|
||||
}),
|
||||
);
|
||||
this.objectsGauge = this.appendChild(
|
||||
createGauge({
|
||||
className: "objects",
|
||||
iconName: "object",
|
||||
label: "Objects",
|
||||
}),
|
||||
);
|
||||
this.memoryGauge = this.appendChild(
|
||||
createGauge({
|
||||
className: "memory",
|
||||
iconName: "memory",
|
||||
label: "Bulk memory",
|
||||
label: "Memory",
|
||||
}),
|
||||
);
|
||||
|
||||
this.codeSizeGauge.setValue(0);
|
||||
this.fuelGauge.setValue(0);
|
||||
this.objectsGauge.setValue(0);
|
||||
this.memoryGauge.setValue(0);
|
||||
}
|
||||
|
||||
update(stats) {
|
||||
this.codeSizeGauge.setValue(stats.astSize, stats.astSizeMax);
|
||||
this.fuelGauge.setValue(stats.fuel, stats.fuelMax);
|
||||
this.objectsGauge.setValue(stats.numRefs, stats.numRefsMax);
|
||||
this.memoryGauge.setValue(stats.memory, stats.memoryMax);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ let [hakuWasm, haku2Wasm] = await Promise.all([
|
|||
__haku2_log_info: makeLogFunction2("info"),
|
||||
__haku2_log_debug: makeLogFunction2("debug"),
|
||||
|
||||
// TODO: Renderer
|
||||
__haku2_canvas_begin: (c) => canvasBeginImpl(c),
|
||||
__haku2_canvas_line: (c, x1, y1, x2, y2) => canvasLineImpl(c, x1, y1, x2, y2),
|
||||
__haku2_canvas_rectangle: (c, x, y, width, height) =>
|
||||
|
@ -205,6 +204,7 @@ export class Haku {
|
|||
|
||||
#pLimits2 = 0;
|
||||
#pScratch2 = 0;
|
||||
#pDefs2 = 0;
|
||||
#pVm2 = 0;
|
||||
|
||||
#bytecode2 = null;
|
||||
|
@ -242,11 +242,14 @@ export class Haku {
|
|||
|
||||
w2.haku2_scratch_destroy(this.#pScratch2);
|
||||
w2.haku2_vm_destroy(this.#pVm2);
|
||||
w2.haku2_defs_destroy(this.#pDefs2);
|
||||
w2.haku2_limits_destroy(this.#pLimits2);
|
||||
w2.haku_dealloc(this.#bytecode2.ptr);
|
||||
}
|
||||
|
||||
setBrush(code) {
|
||||
w.haku_reset(this.#pInstance);
|
||||
|
||||
let brushCode = allocString(code);
|
||||
let statusCode = w.haku_compile_brush2(this.#pInstance, brushCode.length, brushCode.ptr);
|
||||
freeString(brushCode);
|
||||
|
@ -279,8 +282,11 @@ export class Haku {
|
|||
}
|
||||
|
||||
if (this.#pVm2 != 0) w2.haku2_vm_destroy(this.#pVm2);
|
||||
if (this.#pDefs2 != 0) w2.haku2_defs_destroy(this.#pDefs2);
|
||||
if (this.#bytecode2 != null) freeString2(this.#bytecode2);
|
||||
|
||||
console.log(w.haku_defs2(this.#pInstance), w.haku_defs_len2(this.#pInstance));
|
||||
|
||||
let pDefsString = dup1to2(
|
||||
w.haku_defs2(this.#pInstance),
|
||||
w.haku_defs_len2(this.#pInstance),
|
||||
|
@ -291,17 +297,17 @@ export class Haku {
|
|||
w.haku_tags_len2(this.#pInstance),
|
||||
1,
|
||||
);
|
||||
let defs = allocCheck(
|
||||
this.#pDefs2 = allocCheck(
|
||||
w2.haku2_defs_parse(
|
||||
pDefsString,
|
||||
pDefsString.ptr,
|
||||
w.haku_defs_len2(this.#pInstance),
|
||||
pTagsString,
|
||||
pTagsString.ptr,
|
||||
w.haku_tags_len2(this.#pInstance),
|
||||
),
|
||||
);
|
||||
|
||||
w2.haku2_scratch_reset(this.#pScratch2);
|
||||
this.#pVm2 = allocCheck(w2.haku2_vm_new(this.#pScratch2, defs, this.#pLimits2));
|
||||
this.#pVm2 = allocCheck(w2.haku2_vm_new());
|
||||
|
||||
this.#bytecode2 = dup1to2(
|
||||
w.haku_bytecode2(this.#pInstance),
|
||||
|
@ -310,7 +316,6 @@ export class Haku {
|
|||
);
|
||||
this.#localCount = w.haku_local_count2(this.#pInstance);
|
||||
|
||||
w2.haku2_defs_destroy(defs);
|
||||
freeString2(pDefsString);
|
||||
freeString2(pTagsString);
|
||||
|
||||
|
@ -341,7 +346,8 @@ export class Haku {
|
|||
return;
|
||||
}
|
||||
|
||||
w2.haku2_vm_reset(this.#pVm2, this.#fuel);
|
||||
w2.haku2_scratch_reset(this.#pScratch2);
|
||||
w2.haku2_vm_reset(this.#pVm2, this.#pScratch2, this.#pDefs2, this.#pLimits2, this.#fuel);
|
||||
let ok = w2.haku2_vm_run_main(
|
||||
this.#pVm2,
|
||||
this.#pScratch2,
|
||||
|
@ -405,18 +411,14 @@ export class Haku {
|
|||
}
|
||||
|
||||
get astSize() {
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
get numRefs() {
|
||||
return 0; // TODO
|
||||
return w.haku_stat_ast_size(this.#pInstance);
|
||||
}
|
||||
|
||||
get remainingFuel() {
|
||||
return 0; // TODO
|
||||
return w2.haku2_vm_fuel(this.#pVm2);
|
||||
}
|
||||
|
||||
get remainingMemory() {
|
||||
return 0; // TODO
|
||||
get usedMemory() {
|
||||
return w2.haku2_scratch_used(this.#pScratch2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,11 +94,9 @@ export class User {
|
|||
return {
|
||||
astSize: this.haku.astSize,
|
||||
astSizeMax: wallInfo.hakuLimits.ast_capacity,
|
||||
numRefs: this.haku.numRefs,
|
||||
numRefsMax: wallInfo.hakuLimits.ref_capacity,
|
||||
fuel: wallInfo.hakuLimits.fuel - this.haku.remainingFuel,
|
||||
fuelMax: wallInfo.hakuLimits.fuel,
|
||||
memory: wallInfo.hakuLimits.memory - this.haku.remainingMemory,
|
||||
memory: this.haku.usedMemory,
|
||||
memoryMax: wallInfo.hakuLimits.memory,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue