tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

zig-wasm.mjs (725B)


      1 import {WasmRuntime} from '../runtime.mjs';
      2 import {treeSession} from '../tree-session.mjs';
      3 export async function create({bytes,name,artifacts}) {
      4   if(!artifacts?.wasm)throw new Error('Missing zig-wasm artifact');
      5   const runtime=await WasmRuntime.create(artifacts.wasm);
      6   try {
      7     const root=runtime.load(bytes,name);
      8     return treeSession(runtime,root,{
      9       scope:fn=>runtime.scope(fn),release:h=>runtime.release(h),
     10       ofText:(value,limit)=>runtime.ofText(value,limit),toText:h=>runtime.toText(h),
     11       collect:()=>runtime.collect(),stats:()=>({...runtime.stats(),memoryBytes:runtime.e.memory.buffer.byteLength}),
     12       dispose:()=>runtime.dispose(),
     13     });
     14   } catch(error) {runtime.dispose();throw error;}
     15 }