Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const settext = () => {
this.attr('text.value/text', help.sig2base(this.get('inputSignals').in, this.get('numbase')));
}
settext();
this.listenTo(this, 'change:inputSignals', settext);
this.listenTo(this, 'change:numbase', settext);
},
gateParams: NumBase.prototype.gateParams.concat(['bits'])
});
export const NumDisplayView = NumBaseView;
// Numeric entry -- parses a number from a text box
export const NumEntry = NumBase.define('NumEntry', {
bits: 1,
propagation: 0,
buttonState: Vector3vl.xes(1),
attrs: {
'.body': { fill: 'white', stroke: 'black', 'stroke-width': 2 },
'foreignObject.valinput': {
'ref-x': 5, 'ref-y': 0,
width: 60, height: 30
}
}
}, {
initialize: function(args) {
this.listenTo(this, 'change:size', (x, size) => {
this.attr('foreignObject.valinput/width', size.width - 10)
});
NumBase.prototype.initialize.apply(this, arguments);
},
constructor: function(args) {
if (!args.bits) args.bits = 1;
}
},
render() {
joint.dia.ElementView.prototype.render.apply(this, arguments);
this.updatePortSignals('in', this.model.get('inputSignals'));
this.updatePortSignals('out', this.model.get('outputSignals'));
}
});
// Connecting wire model
export const Wire = joint.dia.Link.define('Wire', {
attrs: {
'.connection': { 'stroke-width': 2 },
'.marker-vertex': { r: 7 }
},
signal: Vector3vl.xes(1),
bits: 1,
router: { name: 'orthogonal' },
connector: { name: 'rounded', args: { radius: 10 }}
}, {
markup: [
'
} else {
bits_args['ref-y'] = -3;
bits_args['text-anchor'] = 'middle';
}
if (side == 'left') {
bits_args['ref-dx'] = 6;
} else if (side == 'right') {
bits_args['ref-x'] = -6;
} else if (side == 'top') {
bits_args['ref-y'] = 6;
} else console.assert(false);
_.set(args, ['attrs', 'text.bits.port_' + port.id], bits_args);
}
const signame = port.dir == 'in' ? 'inputSignals' : 'outputSignals';
if (_.get(args, [signame, port.id]) === undefined) {
_.set(args, [signame, port.id], Vector3vl.xes(port.bits));
}
return '';
},
getGateParams: function() {
};
const pol = what => polarity[what] ? 1 : -1;
if (data.arst.get(0) == pol('arst')) {
this.set('current_state', this.get('init_state'));
} else {
const last_clk = this.last_clk;
this.last_clk = data.clk.get(0);
if (data.clk.get(0) == pol('clock') && last_clk == -pol('clock')) {
const trans = next_trans();
this.set('current_state',
trans ? trans.getTargetElement().get('stateNo') : this.get('init_state'));
}
}
const trans = next_trans();
this.set('next_trans', trans.id);
if (!trans) return { out: Vector3vl.xes(bits.out) };
else return { out: trans.get('ctrlOut') };
}
});
function clearInput(end, gate) {
setInput(Vector3vl.xes(gate.ports[end.port].bits), end, gate);
}
this.listenTo(graph, 'change:target', function(wire, end) {
const do_read = (portname, port) => {
if (!check_enabled(portname, port)) {
if ('clock_polarity' in port)
out[portname + 'data'] = this.get('outputSignals')[portname + 'data'];
else
out[portname + 'data'] = Vector3vl.xes(this.get('bits'));
return;
}
if (!data[portname + 'addr'].isFullyDefined)
out[portname + 'data'] = Vector3vl.xes(this.get('bits'));
else {
const addr = calc_addr(data[portname + 'addr']);
if (valid_addr(addr))
out[portname + 'data'] = this.memdata.get(addr);
else
out[portname + 'data'] = Vector3vl.xes(this.get('bits'));
}
};
const do_write = (portname, port) => {
operation: function(data) {
const i = this.muxInput(data.sel);
if (i === undefined) return { out: Vector3vl.xes(this.get('bits').in) };
return { out: data['in' + i] };
},
gateParams: Gate.prototype.gateParams.concat(['bits'])
operation: function(data) {
const bits = this.get('bits');
const sgn = this.get('signed');
if (!data.in1.isFullyDefined || !data.in2.isFullyDefined)
return { out: Vector3vl.xes(1) };
return {
out: Vector3vl.fromBool(this.arithcomp(
help.sig2bigint(data.in1, sgn.in1),
help.sig2bigint(data.in2, sgn.in2)))
};
},
gateParams: Gate.prototype.gateParams.concat(['bits', 'signed'])
export function base2sig(str, bits, base) {
switch(base) {
case 'bin': return Vector3vl.fromBin(str, bits);
case 'oct': return Vector3vl.fromOct(str, bits);
case 'hex': return Vector3vl.fromHex(str, bits);
case 'dec':
if (str == 'x') return Vector3vl.xes(bits);
return bigint2sig(bigInt(str), bits);
}
}