Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanstraten committed Jul 22, 2019
1 parent 5dfe55d commit 37c6d24
Show file tree
Hide file tree
Showing 3 changed files with 436 additions and 10 deletions.
8 changes: 4 additions & 4 deletions temp/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ A field descriptor is a (usually) YAML description of either a single field or
an array of fields. Each field produced by a field descriptor has exactly the
same characteristics, but maps to a different bitrange, and uses a different
array index on the register file interface. These bitranges can be described
either manually as an array or by means of a repeat count and the necessary
strides. Such repetition is useful when you have an array of similar registers,
for instance in a DMA controller with multiple channels, where each channel has
its own set of status and control flags.
by means of a repeat count and the necessary strides. Such repetition is useful
when you have an array of similar registers, for instance in a DMA controller
with multiple channels, where each channel has its own set of status and
control flags.

Note that this means that you can have four kinds of field descriptors:

Expand Down
15 changes: 9 additions & 6 deletions vhdmmio/config/choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ class Choice(ScalarLoader):
something whose `str()` representation performs the inverse of the
conversion function."""

def __init__(self, key, markdown, *choices):
default = choices[0][0]
if default is bool:
default = False
def __init__(self, key, markdown, *choices, default=Unset):
if default is not Unset:
default = choices[0][0]
if default is bool:
default = False
if not isinstance(default, (int, str, bool)) and default is not None:
raise ValueError('invalid default value')
super().__init__(key, markdown, default, Unset)
Expand Down Expand Up @@ -223,5 +224,7 @@ def choice(method):

def flag(method):
"""Convenience method for making flag `Choice`s, i.e. booleans that default
to `False`. The annotated method is never called."""
return Choice(method.__name__, method.__doc__, (bool, ''))
to `False`. The return value of the annotated method (cast to bool) is used
as the default value. The method should not take any arguments; not even
`self`."""
return Choice(method.__name__, method.__doc__, (bool, ''), bool(method()))
Loading

0 comments on commit 37c6d24

Please # to comment.