Skip to content

Commit 6359cd3

Browse files
committed
Add doctest examples for corecircuits.py. Also:
* Reduce the size of doctest comment blocks. * Discourage use of `enum_mux`, use conditional assignment instead. * Update `mux` to use a named `default` parameter, instead of using `**kwargs`. * Make `shift_left_arithmetic` a proper alias of `shift_left_logical`. * Add a lot of links.
1 parent e7e007a commit 6359cd3

File tree

9 files changed

+953
-460
lines changed

9 files changed

+953
-460
lines changed

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ to successfully run the test, but the lines are commented out because they are
4646
not worth showing in every example. These blocks look like:
4747

4848
```
49-
..
50-
# For ``doctest``.
49+
.. doctest only::
50+
5151
>>> import pyrtl
5252
>>> pyrtl.reset_working_block()
5353
```

docs/helpers.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The functions below provide ways of combining, slicing, and extending
88
:class:`WireVectors<.WireVector>` in ways that are often useful in hardware
99
design. The functions below extend those member functions of the
1010
:class:`.WireVector` class itself (which provides support for the Python
11-
builtin ``len``, slicing e.g. ``wire[3:6]``,
11+
builtin :func:`len`, slicing e.g. ``wire[3:6]``,
1212
:meth:`~pyrtl.wire.WireVector.zero_extended`,
1313
:meth:`~pyrtl.wire.WireVector.sign_extended`, and many operators such as
1414
addition and multiplication).
@@ -28,8 +28,9 @@ In PyRTL there is only one function in charge of coercing values into
2828
:class:`WireVectors<.WireVector>`, and that is :func:`.as_wires`. This function
2929
is called in almost all helper functions and classes to manage the mixture of
3030
constants and :class:`WireVectors<.WireVector>` that naturally occur in
31-
hardware development. See :ref:`wirevector_coercion` for examples and more
32-
details.
31+
hardware development.
32+
33+
See :ref:`wirevector_coercion` for examples and more details.
3334

3435
.. autofunction:: pyrtl.corecircuits.as_wires
3536

@@ -38,7 +39,6 @@ Control Flow Hardware
3839

3940
.. autofunction:: pyrtl.corecircuits.mux
4041
.. autofunction:: pyrtl.corecircuits.select
41-
.. autofunction:: pyrtl.corecircuits.enum_mux
4242
.. autofunction:: pyrtl.corecircuits.bitfield_update
4343
.. autofunction:: pyrtl.corecircuits.bitfield_update_set
4444
.. autoclass:: pyrtl.helperfuncs.MatchedFields
@@ -100,10 +100,10 @@ addition, subtraction, multiplication, comparison, and many others).
100100
.. autofunction:: pyrtl.corecircuits.signed_le
101101
.. autofunction:: pyrtl.corecircuits.signed_gt
102102
.. autofunction:: pyrtl.corecircuits.signed_ge
103-
.. autofunction:: pyrtl.corecircuits.shift_left_arithmetic
104-
.. autofunction:: pyrtl.corecircuits.shift_right_arithmetic
105103
.. autofunction:: pyrtl.corecircuits.shift_left_logical
104+
.. autofunction:: pyrtl.corecircuits.shift_left_arithmetic
106105
.. autofunction:: pyrtl.corecircuits.shift_right_logical
106+
.. autofunction:: pyrtl.corecircuits.shift_right_arithmetic
107107

108108
Encoders and Decoders
109109
---------------------

pyrtl/core.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ class Block:
273273
274274
``ops``: ``&``, ``|``, ``^``, ``n``, ``~``, ``+``, ``-``, ``*``.
275275
276-
All inputs must be the same ``bitwidth``. Logical operations produce as many
277-
bits as are in the input, while ``+`` and ``-`` produce ``n + 1`` bits, and
278-
``*`` produces ``2 * n`` bits.
276+
All inputs must be the same :attr:`~.WireVector.bitwidth`. Logical operations
277+
produce as many bits as are in the input, while ``+`` and ``-`` produce ``n + 1``
278+
bits, and ``*`` produces ``2 * n`` bits.
279279
280280
* In addition there are some operations for performing comparisons
281281
that should perform the operation specified. The ``=`` ``op`` is checking
@@ -396,8 +396,8 @@ def _add_memblock(self, mem):
396396
def get_memblock_by_name(self, name: str, strict: bool = False) -> MemBlock:
397397
"""Get a :class:`.MemBlock` from the ``Block``, by name.
398398
399-
..
400-
# For ``doctest``.
399+
.. doctest only::
400+
401401
>>> import pyrtl
402402
>>> pyrtl.reset_working_block()
403403
@@ -446,8 +446,8 @@ def wirevector_subset(self, cls: tuple[type] = None,
446446
447447
Filters ``WireVectors`` by type.
448448
449-
..
450-
# For ``doctest``.
449+
.. doctest only::
450+
451451
>>> import pyrtl
452452
>>> pyrtl.reset_working_block()
453453
@@ -951,7 +951,7 @@ def _get_useful_callpoint_name():
951951
952952
This function walks back the current frame stack attempting to find the
953953
first frame that is not part of the pyrtl module. The filename (stripped
954-
of path and .py extention) and line number of that call are returned.
954+
of path and .py extension) and line number of that call are returned.
955955
This point should be the point where the user-level code is making the
956956
call to some pyrtl intrisic (for example, calling "mux"). If the
957957
attempt to find the callpoint fails for any reason, None is returned.

0 commit comments

Comments
 (0)