Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hdl-js

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hdl-js - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

2

package.json
{
"name": "hdl-js",
"version": "0.0.12",
"version": "0.0.13",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Hardware definition language (HDL) and Hardware simulator",

@@ -401,2 +401,40 @@ # hdl-js

Input and output pins can also be passed as _specifications_, rather than as actual `Pin` instances:
```js
const hdl = require('hdl-js');
const {
And,
And16,
} = hdl.emulator.BuiltInGates;
// Simple names:
const and1 = new And({
inputPins: ['a', 'b'],
outputPins: ['out'],
});
and1.setPinValues({a: 1, b: 0});
and1.eval();
console.log(and1.getPin('out').getValue()); // 0
// Spec with values and sizes:
const and2 = new And16({
inputPins: [
{name: 'a', size: 16, value: 1},
{name: 'b', size: 16, value: 0},
],
outputPins: [
{name: 'out', size: 16},
],
});
and2.eval();
console.log(and2.getPin('out').getValue()); // 0
```
It is possible to execute and test gate logic on the set of data:

@@ -471,3 +509,11 @@

[
{row: 0, pins: {out: 0}},
{
row: 0,
pins: {
out: {
expected: 1,
actual: 0,
},
},
},
]

@@ -474,0 +520,0 @@

@@ -8,2 +8,4 @@ /**

const And = require('../builtin-gates/And');
const And16 = require('../builtin-gates/And16');
const Gate = require('../Gate');

@@ -92,3 +94,4 @@ const Pin = require('../Pin');

expect(conflicts.length).toBe(1);
expect(conflicts[0]).toEqual({row: 0, pins: {out: 1}});
expect(conflicts[0])
.toEqual({row: 0, pins: {out: {expected: 0, actual: 1}}});

@@ -128,3 +131,11 @@ // Sets the outputs, no conflicts.

expect(conflicts[0])
.toEqual({row: 0, pins: {out: int16(0b1111111111111111)}});
.toEqual({
row: 0,
pins: {
out: {
expected: int16(0b1111111111111110),
actual: int16(0b1111111111111111),
}
}
});

@@ -141,4 +152,2 @@ // Sets the outputs, no conflicts.

it('get pin info', () => {
const And = require('../builtin-gates/And');
expect(And.getPinInfo('a')).toEqual({kind: 'input', name: 'a'});

@@ -157,2 +166,72 @@ expect(And.getPinInfo('b')).toEqual({kind: 'input', name: 'b'});

it('creates pins from spec', () => {
// ----------------------------------------
// Simple names spec.
const and1 = new And({
inputPins: ['a', 'b'],
outputPins: ['out'],
});
expect(and1.getInputPins()).toEqual([
new Pin({name: 'a'}),
new Pin({name: 'b'}),
]);
expect(and1.getOutputPins()).toEqual([
new Pin({name: 'out'}),
]);
// ----------------------------------------
// Object names spec.
const and2 = new And({
inputPins: [
{name: 'a', value: 1},
{name: 'b', value: 0},
],
outputPins: [
{name: 'out'},
],
});
expect(and2.getInputPins()).toEqual([
new Pin({name: 'a', value: 1}),
new Pin({name: 'b', value: 0}),
]);
expect(and2.getPin('a').getValue()).toBe(1);
expect(and2.getPin('b').getValue()).toBe(0);
and2.eval();
expect(and1.getOutputPins()).toEqual([
new Pin({name: 'out'}),
]);
expect(and2.getPin('out').getValue()).toBe(0);
// ----------------------------------------
// Size spec.
const and3 = new And16({
inputPins: [
{name: 'a', value: 1, size: 16},
{name: 'b', value: 0, size: 16},
],
outputPins: [
{name: 'out', size: 16},
],
});
expect(and3.getInputPins()).toEqual([
new Pin({name: 'a', value: 1, size: 16}),
new Pin({name: 'b', value: 0, size: 16}),
]);
expect(and3.getPin('a').getSize()).toBe(16);
expect(and3.getPin('b').getSize()).toBe(16);
});
});

@@ -34,5 +34,6 @@ /**

this._name = name;
this._inputPins = inputPins;
this._outputPins = outputPins;
this._inputPins = Gate.toPins(inputPins);
this._outputPins = Gate.toPins(outputPins);
this._buildNamesToPinsMap();

@@ -179,3 +180,6 @@ }

if (row.hasOwnProperty(pinName) && expectedValue !== actualValue) {
conflictsForRow[pinName] = actualValue;
conflictsForRow[pinName] = {
expected: expectedValue,
actual: actualValue,
};
}

@@ -280,2 +284,20 @@ }

/**
* Creates a Pin instance from a spec, or propagates
* if it's already a Pin instance.
*/
static toPins(pinSpecs) {
return pinSpecs.map(pin => {
if (pin instanceof Pin) {
return pin;
}
const spec = typeof pin === 'string'
? {name: pin}
: pin;
return new Pin(spec);
});
}
/**
* Builds a map from a pin name to the pin instance.

@@ -282,0 +304,0 @@ */

@@ -36,3 +36,3 @@ /**

if (value) {
if (value !== null) {
this.setValue(value);

@@ -39,0 +39,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc