New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Range and Array modeling types #2510
Conversation
I keep forgetting that |
Using |
Codecov Report
@@ Coverage Diff @@
## master #2510 +/- ##
==========================================
+ Coverage 74.46% 75.28% +0.81%
==========================================
Files 38 40 +2
Lines 6537 6752 +215
Branches 560 596 +36
==========================================
+ Hits 4868 5083 +215
Misses 1485 1485
Partials 184 184
Continue to review full report at Codecov.
|
We should also add Line 35 in 1536fd1
|
@cmarqu if you think there are any other exception that could improve, please comment. I need to refactor the |
Resolved issue where constructor would not check if |
Not entirely sure if the last set of changes is welcome, but it should make extending |
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
I think that's enough last minute cleanup @cocotb/maintainers. If there are no more comments in a couple days, I will merge. |
* Add Range modeling type Range datatype mimic's Python "range" type, but with inclusive right bounds like is seen in HDLs. * Add Array modeling type * Apply suggestions from code review Co-authored-by: Colin Marquardt <cmarqu42@gmail.com> * Use compat layer for cache and cached_property * Run black * Apply suggestions from code review Co-authored-by: Colin Marquardt <cmarqu42@gmail.com> * Remove 'you' from docstrings * Run pyupgrade --py36-plus * fix compat * Apply suggestions from code review Co-authored-by: Colin Marquardt <cmarqu42@gmail.com> * Fix compat again... * Add doctests * Improve indexing exception * More detail in exceptions * Improve constructor * encapsulate construction of value and range for subclasses * Apply suggestions from code review Co-authored-by: Colin Marquardt <cmarqu42@gmail.com> * Condense notes * don't use cached_property anymore * Improve equality * Update cocotb/types/range.py Co-authored-by: Eric Wieser <wieser.eric@gmail.com> * Improve error message * inline unnecessarily split function * Fix a bug * Explicitly state that right bound is inclusive * Improve method documentation * Apply suggestions from code review Co-authored-by: Colin Marquardt <cmarqu42@gmail.com> * Removed unused definition * Improve equality behavior * Improve documentation on equality and other operations * Use double quotes in docstrings like black * Improve warnings on differences with builtin sequence types * Simplify array element construction * Update cocotb/types/array.py * 100% coverage baby... * Apply suggestions from code review * Update cocotb/types/range.py Co-authored-by: Eric Wieser <wieser.eric@gmail.com> * Remove .length * Move 'concat' to base array * Apply suggestions from code review * Allow user to change bounds after array creation * mypy fixes * Additional black fixes * Further take Eric's advice and simplify the array code more * Fix mypy fixes * Make concat a free binary operation * Apply suggestions from code review * Improve concat implementation * Fixes for special method resolution * Fix __concat__=None problem * Fix occurences of __class__ * Final black run * Add note about constructing ranges * Add concat() to reference documentation Co-authored-by: Colin Marquardt <cmarqu42@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Follow on to #2485. xref #2059. Adds a
Range
andArray
type.The
Range
type is much like Python'srange
type, but has an inclusive right bound like is seen in both Verilog and VHDL. It support's VHDL'sto
anddownto
directions, Verilog's automatic directionality by not specifying a direction, and VHDL's null ranges.The
Array
type is a heterogenous fixed-length sequence type. It uses an initial value or a range to determine it's size at construction and it's size is fixed. It supports must of the same operations as a list that don't mutate the length. Uses aRange
to describe the indexing scheme, which is arbitrary, like is seen in both Verilog and VHDL. Some indexing and slicing behavior had to change compared to a list to make something that behaved intuitively.