New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fully combinational syntax #225
Conversation
What's still missing is the ability to call other |
Pull Request Test Coverage Report for Build 858
💛 - Coveralls |
Actually turns out function composition just works if you use it correctly (you only call another |
Looks great. I think using O as the default name makes sense. Can you return multiple values? |
Nope, but that's a good idea, I will add it. I propose that
|
Added the scaffolding to support Tuple as a return type, but testing it is blocked by:
Until then could think about merging this in and finishing support for tuples when the above two issues are resolved. |
I misspoke. I meant it would be nice to generate a circuit with multiple output arguments, For example, in mantle the counter returns O, COUT. |
A tuple would be the way to do that in Python (return (O, COUT)), we could implicitly flatten the tuple on the return type, but we'd need a way to automatically generate the names of the outputs, or have the user specify the name. If they just use variable names in the return statements, we could take that, but that would prevent the user from being able to return an expression, e.g. Maybe we could use the custom type annotation syntax to specify the name of the output ports? def a(I: m.In(m.Bits(2))) -> {"O": m.Bit, "COUT": m.Bit}:
pass or def a(I: m.In(m.Bits(2))) -> ("O", m.Bit, "COUT", m.Bit):
pass The dictionary syntax might make the most sense since you're implicitly describing the return of a record/bundle type. |
Another option is to integrate it with the class Add(m.Circuit):
IO = ["a", m.In(m.Bit), "b", m.In(m.Bit), "c", m.In(m.Bit), "O", m.Out(m.Bit), "COUT", m.Out(m.Bit)]
@circuit.combinational
def definition(a, b, c):
return a ^ b ^ c, a & b | b & c | c & a |
Re: tuples, we could also use named tuple (https://docs.python.org/3.7/library/collections.html#collections.namedtuple). |
This extends the syntax for
circuit.combinational
to match the proposed syntax from our planning meeting.This implements if then else and ternary expressions inside the combinational circuit definitions. It rewrites the function into a module that can be instantiated (using the function call syntax). It defaults to having an output port named
O
, although we could consider adding an option parameter to the decorator that lets you set the output port name.The major difference between this branch and the original
if
statement syntax proposal is that it doesn't mixwire
calls with the combinational circuit syntax. This allows you to easily use the function call abstraction for combinational logic, but forces you to decompose it from structural code.One question is, do we want to keep the ability to use
if
statements interleaved with structural code? That's what's proposed in #224. In this pull request,wire
calls are not supported inm.circuit.combinational
. It should be possible to factor it in a way to support both if we think they're both viable features.