hdl.ast: add Value.{any,all}, mapping to $reduce_{or,and}.

Refs #147.
This commit is contained in:
whitequark 2019-09-13 13:14:52 +00:00
parent bdb70ad45f
commit b23a9794a4
5 changed files with 52 additions and 3 deletions

View file

@ -129,6 +129,12 @@ class _RHSValueCompiler(_ValueCompiler):
return lambda state: normalize(-arg(state), shape)
if value.op == "b":
return lambda state: normalize(bool(arg(state)), shape)
if value.op == "r|":
return lambda state: normalize(arg(state) != 0, shape)
if value.op == "r&":
val, = value.operands
mask = (1 << len(val)) - 1
return lambda state: normalize(arg(state) == mask, shape)
elif len(value.operands) == 2:
lhs, rhs = map(self, value.operands)
if value.op == "+":

View file

@ -375,6 +375,9 @@ class _RHSValueCompiler(_ValueCompiler):
(1, "~"): "$not",
(1, "-"): "$neg",
(1, "b"): "$reduce_bool",
(1, "r|"): "$reduce_or",
(1, "r&"): "$reduce_and",
(1, "r^"): "$reduce_xor",
(2, "+"): "$add",
(2, "-"): "$sub",
(2, "*"): "$mul",