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
Assignment #315
Assignment #315
Conversation
Related issue from Mantle phanrahan/mantle#90 |
Pull Request Test Coverage Report for Build 1260
💛 - Coveralls |
Actually, using Then, code like this would work
Basically, to use |
Nice. I think overloading the value object is better. It is more general. It also preserves the semantics of =. I don't think there is any downside, assuming that the lhs is an inputs. The <= should still correspond to greater than or equal if the lhs and the rhs are both outputs. One slightly ambigious case is when the lhs is neither an input or an output. For example, an anonymous value which acts like a wire. Probably makes sense to treat that case as a wiring operator, but I haven't thought that through. |
One thing to watch out for using <=
doesn't work since <= has lower precedence than x if p then y. This need to be written as
|
Nasty, I'll open an issue, not sure what the best thing to do about this is besides documentation. Not sure if we can safeguard against it. We could try inspecting the AST and inserting the parenthesis if we can come up with a pattern matching rule that effectively identifies these cases. |
Note, this is based on the operators-docs branch, so should merge this first before merging that into master, or retarget this pull to master.
Adds support for the assignment operator on circuit definition ports and circuit instance ports. Here's an example snippet from one of the tests
It will raise a typeerror if you try to assign to an Input of a definition or an output of an instance.
One issue is that we're overloading the meaning of assignment here (specifically
__setitem__
), which is a foreign pattern for Python users. That is,magma_obj.i = v
no longer means, set the fieldi
tov
onmagma_obj
ifi
is an input port, instead it means wirev
toi
. An alternative syntax that should consider is using something like<=
. This has the benefit of being familiar to verilog programmers (non-blocking assign), and introduces less confusion with the=
semantics. That is, it would preserve the mental model that assigning to a field on an object just performs a__setattr__
.The use of
<=
without assigning the result to a value is probably not a common Python pattern (if used at all), so at least we're not overloading some expected behavior which might lead to trouble, particularly when onboarding a new user coming from Python.Here's what the alternative syntax would look like
Thoughts? After some thinking, my current inclination is towards using
<=
for the above mentioned reason related to breaking Python's standard semantics of=
.