-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Python's variable model is going to be at least a moderate pain to get exactly right. The problem is, of course, that variables aren't declared explicitly, but implicitly by assigning to them. This in itself isn't much of a problem to handle in NQP, but it's compounded by the fact that reading from an unbound variable should throw an exception.
Thus, the validity of the following snippet cannot be statically determined:
for x in things: pass
print(x)It can either print the last element of the list, or result in an exception if the list is empty (because x will not have been assigned to). Similar things can be achieved by assigning to variables in a while loop, or only some of the branches of an if.
The easy way to solve this would be for every block to have a hash that contains all the variables (which is probably the implementation strategy that gave rise to this stuff in the first place), but that's likely going to be kind of slow, so I'd like to avoid that. In the end, it may be easiest to implement this as a custom nqp::op (or rather two, one for reading and one for binding) that does the necessary magic.