hdl.ast: actually implement the // operator.

This commit is contained in:
whitequark 2019-09-28 19:33:24 +00:00
parent 450d7efdf2
commit 1621ceb65a
5 changed files with 29 additions and 5 deletions

View file

@ -146,6 +146,10 @@ class _RHSValueCompiler(_ValueCompiler):
return lambda state: normalize(lhs(state) - rhs(state), shape)
if value.op == "*":
return lambda state: normalize(lhs(state) * rhs(state), shape)
if value.op == "//":
def floordiv(lhs, rhs):
return 0 if rhs == 0 else lhs // rhs
return lambda state: normalize(floordiv(lhs(state), rhs(state)), shape)
if value.op == "&":
return lambda state: normalize(lhs(state) & rhs(state), shape)
if value.op == "|":

View file

@ -388,7 +388,7 @@ class _RHSValueCompiler(_ValueCompiler):
(2, "+"): "$add",
(2, "-"): "$sub",
(2, "*"): "$mul",
(2, "/"): "$div",
(2, "//"): "$div",
(2, "%"): "$mod",
(2, "**"): "$pow",
(2, "<<"): "$sshl",