grumpyhome / grumpy

Grumpy is a Python to Go source code transcompiler and runtime.
Apache License 2.0
420 stars 18 forks source link

Include __future__ information on Code, allowing `division` future to be implemented #123

Open alanjds opened 5 years ago

alanjds commented 5 years ago

tl;dr: Code objects should receive the __future__ imports information applied to it.

Today the __future__ imports information is available only to the importer/compiler. No import occur really occur nor code is generated for it. This by itself already violates some of the __future__ documented semantics, but more important, the information is not forwarded to the Code object.

Having no clue of what __future__ flags are imported/activated and what are not, a Code cannot change its behaviors. This makes harder the possiblity of func intDiv() to change its operation in presence __future__.division (#37).

I explored the possibility of this flag to just change the transpiled code. It could fix code like print 1 / 2, but would not work for non-literal integers like a = 1; b = 2; print a / b or more complex ones.