Add (heavily work in progress) documentation.
To render correctly, the docs require: * pygments/pygments#1441
This commit is contained in:
parent
8dacbbb2b2
commit
399b8f9863
21 changed files with 1565 additions and 23 deletions
|
|
@ -135,7 +135,7 @@ class Value(metaclass=ABCMeta):
|
|||
self.src_loc = tracer.get_src_loc(1 + src_loc_at)
|
||||
|
||||
def __bool__(self):
|
||||
raise TypeError("Attempted to convert nMigen value to boolean")
|
||||
raise TypeError("Attempted to convert nMigen value to Python boolean")
|
||||
|
||||
def __invert__(self):
|
||||
return Operator("~", [self])
|
||||
|
|
@ -184,7 +184,7 @@ class Value(metaclass=ABCMeta):
|
|||
# Neither Python nor HDLs implement shifts by negative values; prohibit any shifts
|
||||
# by a signed value to make sure the shift amount can always be interpreted as
|
||||
# an unsigned value.
|
||||
raise NotImplementedError("Shift by a signed value is not supported")
|
||||
raise TypeError("Shift amount must be unsigned")
|
||||
def __lshift__(self, other):
|
||||
other = Value.cast(other)
|
||||
other.__check_shamt()
|
||||
|
|
|
|||
|
|
@ -214,10 +214,9 @@ class Module(_ModuleBuilderRoot, Elaboratable):
|
|||
width, signed = cond.shape()
|
||||
if signed:
|
||||
warnings.warn("Signed values in If/Elif conditions usually result from inverting "
|
||||
"Python booleans with ~, which leads to unexpected results: ~True is "
|
||||
"-2, which is truthful. Replace `~flag` with `not flag`. (If this is "
|
||||
"a false positive, silence this warning with "
|
||||
"`m.If(x)` → `m.If(x.bool())`.)",
|
||||
"Python booleans with ~, which leads to unexpected results. "
|
||||
"Replace `~flag` with `not flag`. (If this is a false positive, "
|
||||
"silence this warning with `m.If(x)` → `m.If(x.bool())`.)",
|
||||
SyntaxWarning, stacklevel=4)
|
||||
return cond
|
||||
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ class ValueTestCase(FHDLTestCase):
|
|||
|
||||
def test_bool(self):
|
||||
with self.assertRaises(TypeError,
|
||||
msg="Attempted to convert nMigen value to boolean"):
|
||||
msg="Attempted to convert nMigen value to Python boolean"):
|
||||
if Const(0):
|
||||
pass
|
||||
|
||||
|
|
@ -466,11 +466,11 @@ class OperatorTestCase(FHDLTestCase):
|
|||
self.assertEqual(v1.shape(), unsigned(11))
|
||||
|
||||
def test_shl_wrong(self):
|
||||
with self.assertRaises(NotImplementedError,
|
||||
msg="Shift by a signed value is not supported"):
|
||||
with self.assertRaises(TypeError,
|
||||
msg="Shift amount must be unsigned"):
|
||||
1 << Const(0, signed(6))
|
||||
with self.assertRaises(NotImplementedError,
|
||||
msg="Shift by a signed value is not supported"):
|
||||
with self.assertRaises(TypeError,
|
||||
msg="Shift amount must be unsigned"):
|
||||
Const(1, unsigned(4)) << -1
|
||||
|
||||
def test_shr(self):
|
||||
|
|
@ -479,11 +479,11 @@ class OperatorTestCase(FHDLTestCase):
|
|||
self.assertEqual(v1.shape(), unsigned(4))
|
||||
|
||||
def test_shr_wrong(self):
|
||||
with self.assertRaises(NotImplementedError,
|
||||
msg="Shift by a signed value is not supported"):
|
||||
with self.assertRaises(TypeError,
|
||||
msg="Shift amount must be unsigned"):
|
||||
1 << Const(0, signed(6))
|
||||
with self.assertRaises(NotImplementedError,
|
||||
msg="Shift by a signed value is not supported"):
|
||||
with self.assertRaises(TypeError,
|
||||
msg="Shift amount must be unsigned"):
|
||||
Const(1, unsigned(4)) << -1
|
||||
|
||||
def test_lt(self):
|
||||
|
|
|
|||
|
|
@ -289,9 +289,9 @@ class DSLTestCase(FHDLTestCase):
|
|||
m = Module()
|
||||
with self.assertWarns(SyntaxWarning,
|
||||
msg="Signed values in If/Elif conditions usually result from inverting Python "
|
||||
"booleans with ~, which leads to unexpected results: ~True is -2, which is "
|
||||
"truthful. Replace `~flag` with `not flag`. (If this is a false positive, "
|
||||
"silence this warning with `m.If(x)` → `m.If(x.bool())`.)"):
|
||||
"booleans with ~, which leads to unexpected results. Replace `~flag` with "
|
||||
"`not flag`. (If this is a false positive, silence this warning with "
|
||||
"`m.If(x)` → `m.If(x.bool())`.)"):
|
||||
with m.If(~True):
|
||||
pass
|
||||
|
||||
|
|
@ -301,9 +301,9 @@ class DSLTestCase(FHDLTestCase):
|
|||
pass
|
||||
with self.assertWarns(SyntaxWarning,
|
||||
msg="Signed values in If/Elif conditions usually result from inverting Python "
|
||||
"booleans with ~, which leads to unexpected results: ~True is -2, which is "
|
||||
"truthful. Replace `~flag` with `not flag`. (If this is a false positive, "
|
||||
"silence this warning with `m.If(x)` → `m.If(x.bool())`.)"):
|
||||
"booleans with ~, which leads to unexpected results. Replace `~flag` with "
|
||||
"`not flag`. (If this is a false positive, silence this warning with "
|
||||
"`m.If(x)` → `m.If(x.bool())`.)"):
|
||||
with m.Elif(~True):
|
||||
pass
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue