-
Notifications
You must be signed in to change notification settings - Fork 9
/
parser.js
67 lines (51 loc) · 1.42 KB
/
parser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
const stream = require('stream');
const EventEmitter = require('events').EventEmitter;
let lib = require('bindings')('vcd.node');
module.exports = () => {
const wires = {};
const info = {stack: [wires], wires: wires};
const s = new stream.Writable();
// const lifee = new EventEmitter();
// gets called by c with 1 argument, a number
const lifemit = s.emit.bind(s);
const triee = new EventEmitter();
// gets called by c with 5 arguments
// string eventName
// bigint state->time
// int command
// bigint state->value
// bigint state->mask
const triemit = triee.emit.bind(triee);
let triemit2 = triemit;
const cxt = lib.init(lifemit, triemit, info);
s._write = function (chunk, encoding, callback) {
const err = lib.execute(cxt, lifemit, triemit2, info, chunk);
if (err) {
// console.log(info);
console.log(err);
// throw new Error(err);
}
callback();
};
s.change = {
on: (id, fn) => {
// console.log(id);
triemit2 = triemit;
triee.on(id, fn);
const triggerString = triee.eventNames().join('\0') + '\0\0';
lib.setTrigger(cxt, triggerString);
},
any: fn => {
triemit2 = fn;
lib.setTrigger(cxt, '\0');
}
};
s.info = info;
s.getTime = () => lib.getTime(cxt);
s.kill = () => {
lib.done(cxt, lifemit, triemit2, info);
s.end();
};
return s;
};