withSet method
Returns a copy of this Logic with the bits starting from startIndex
up until startIndex + update.width set to update instead
of their original value.
The return signal will be the same width. An exception will be thrown
if the position of the update would cause an overrun past the width.
Implementation
Logic withSet(int startIndex, Logic update) {
if (startIndex + update.width > width) {
throw RangeError('Width of update $update at startIndex $startIndex would'
' overrun the width of the original ($width).');
}
if (startIndex < 0) {
throw RangeError(
'Start index must be greater than zero but was $startIndex');
}
if (startIndex == 0 && update.width == width) {
// special case, setting whole thing, just return the same thing
return update;
}
return [
getRange(startIndex + update.width, width),
update,
getRange(0, startIndex),
].swizzle();
}