diff --git a/README.md b/README.md index eec6ccf..f97ca61 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Install ``` npm i vcd-stream +make wasm ``` Require diff --git a/lib/wrapper.js b/lib/wrapper.js index 3934bc3..db06330 100644 --- a/lib/wrapper.js +++ b/lib/wrapper.js @@ -1,5 +1,7 @@ 'use strict'; +/* global BigInt */ + const dotProp = require('dot-prop'); function _waitForStart(mod) { @@ -51,18 +53,18 @@ module.exports = () => { } bindCWrap(); bindCallback(); - } + }; // gets a string from a c heap pointer and length - const getString = (name,len) => { - const view = wasm.HEAPU8.subarray(name, name+len); + const getString = (name, len) => { + const view = wasm.HEAPU8.subarray(name, name+len); - let string = ''; - for (let i = 0; i < len; i++) { - string += String.fromCharCode(view[i]); - } - return string; - } + let string = ''; + for (let i = 0; i < len; i++) { + string += String.fromCharCode(view[i]); + } + return string; + }; let boundInfo; @@ -83,6 +85,7 @@ module.exports = () => { boundSet = wasm.addFunction(function(name, len, type, v0, v1) { let prop = getString(name, len); + let tmp; switch(type) { // set number @@ -102,7 +105,7 @@ module.exports = () => { break; // path to path (any type) case 3: - let tmp = dotProp.get(boundInfo, getString(v0, v1)); + tmp = dotProp.get(boundInfo, getString(v0, v1)); // console.log(`for ${getString(v0, v1)} got ${tmp}, set to ${prop}`); dotProp.set(boundInfo, prop, tmp); break; @@ -121,7 +124,7 @@ module.exports = () => { boundGet = wasm.addFunction(function(name, len) { let prop = getString(name, len); - return 42; + return prop; }, 'iii'); @@ -140,12 +143,12 @@ module.exports = () => { const view0 = wasm.HEAPU8.subarray(value, value+(valueWords*8)); const view1 = wasm.HEAPU8.subarray(mask, mask+(valueWords*8)); - let big_value = u8ToBn(view0); - let big_mask = u8ToBn(view1); + let bigValue = u8ToBn(view0); + let bigMask = u8ToBn(view1); - // console.log(big_value.toString(16)); + // console.log(bigValue.toString(16)); - ee[1](name, time, command, big_value, big_mask); + ee[1](name, time, command, bigValue, bigMask); }, 'viiiiiii'); }; @@ -157,20 +160,20 @@ module.exports = () => { boundInfo = info; ee[0] = cb0; ee[1] = cb1; - context = c.init(boundEE0,boundEE1,boundSet,boundGet); + context = c.init(boundEE0, boundEE1, boundSet, boundGet); + return context; }, execute: (ctx, cb0, cb1, info, chunk) => { boundInfo = info; ee[0] = cb0; ee[1] = cb1; - c.execute(ctx,boundEE0,boundEE1,boundSet,boundGet,chunk.toString()); + c.execute(ctx, boundEE0, boundEE1, boundSet, boundGet, chunk.toString()); }, setTrigger: (ctx, triggerString) => { return c.setTrigger(ctx, triggerString); }, getTime: (ctx) => { return BigInt(c.getTime(ctx)); - }, - time: () => total + start + } }; };