fix linting, add to readme

This commit is contained in:
Ben 2020-09-28 00:45:56 -07:00
parent d184681eae
commit 6bcb3afb38
2 changed files with 23 additions and 19 deletions

View File

@ -9,6 +9,7 @@ Install
``` ```
npm i vcd-stream npm i vcd-stream
make wasm
``` ```
Require Require

View File

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