-
Notifications
You must be signed in to change notification settings - Fork 644
fix for #17 #265
base: master
Are you sure you want to change the base?
fix for #17 #265
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
compiler/block.py
Outdated
raise util.ParseError(node, msg) | ||
self.vars[name] = Var(name, Var.TYPE_PARAM, arg_index=i) | ||
if isinstance(name, list): | ||
self.add_vars(i, 'τ'.join(name), node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it turns out the arg tuples can be nested:
>>> def f((a, (b, c))):
... print a, b, c
...
>>> f((1, (2, 3)))
1 2 3
This points to a recursive approach similar to the way _tie_target() in stmt.py works. My intuition is that we can use the exact same mechanism (grumpy.TieTarget struct) for unpacking the args.
Also, Var represents Python variables and are used to resolve names and handle scoping rules so I don't think you want to create a pseudo Var to represent the tuple. Instead you want to put the special unpacking logic somewhere around here. But instead of assigning to each of the locals for the args, that's where you want to do the unpacking use the TieTarget mechanism.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trotterdylan - Since we are passing the Tuple as a single argument, we'll need some sort of Vars to hold the values inside the function as we need to Tie these arguments to the respective variables/arguments. Instead of pseudo Vars, what do you suggest?
Another approach could be to unpack them while constructing the arguments to the function itself and pass all the unpacked values as directly.
Let me know!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can allocate a Go variable to hold the temporary value. Look for uses of Block.alloc_temp() in the code. The way this works for assignments is very similar to what I imagine you will need to do. It's a little indirect, but here's the relevant alloc for normal assignments: https://github.com/google/grumpy/blob/master/compiler/stmt.py#L640
I think the code for tuple argument unpacking will be very similar to that for tuple assignments. Hopefully you can reuse _build_assign_target(), _tie_target(), etc.
@trotterdylan - The build is failing in go 1.9 as mentioned in #378 |
This is something which I could come up with in a couple of hours. The idea is to merge the constituent tuple arguments into a single argument (by joining argument names with τ) and get them unpacked inside the function using array notation.
Let me know your thoughts on the same. Unit tests are still work in progress; will update the PR once they are ready!