Skip to content

Make compiler fully compatible with py3 while retaining py2 support#34

Open
gorel wants to merge 5 commits into
KULeuven-COSIC:masterfrom
gorel:master
Open

Make compiler fully compatible with py3 while retaining py2 support#34
gorel wants to merge 5 commits into
KULeuven-COSIC:masterfrom
gorel:master

Conversation

@gorel
Copy link
Copy Markdown

@gorel gorel commented Jan 13, 2020

The Compiler/ directory was only compatible with Python2. This is a big issue since py2 support officially ended on January 1, 2020. In the interest of causing the least amount of friction, I retained py2 support in this diff, but my primary goal was to get the compiler to run in py3.

Here's the process I went through to add py3 support:

  1. python-futurize --stage1 -w Compiler/*.py
  2. Manual changes to retain py2 support (bytes, minor printing stuff)
  3. At this point, the code ran successfully in py2, but not in py3 yet
  4. python-futurize --stage2 -w Compiler/*.py
  5. Manual changes to add py3 support and keep py2 support (truediv, hash, long type hack, unicode/bytes, remove relative imports)

I may have missed some minor differences with int vs long still, so I'll audit my own changes again.

For testing, I simply ran python2 compile.py Programs/test_all/ and python3 compile.py Programs/test_all/. I'm not sure if there's a more rigorous way to test, but these both work with my changes.

Very open to any feedback you may have. I realize these changes may not be the prettiest, but my goal was functionality while touching as few lines of code as possible instead of making it look good.

@gorel
Copy link
Copy Markdown
Author

gorel commented Jan 13, 2020

Something to call out: In python3, there is no long type, so I use this hack to pretend we support it:

if sys.version[0] == "3":
    long = int

I'm not sure if this actually has implications (if there's something that depends on int being fixed-size), but if so, we'll need to find an alternative. Int in python3 is arbitrary-precision, so this was my solution to get the code to continue working. long is not a type in python3.

@NigelSmart
Copy link
Copy Markdown
Contributor

As explained on the mailing list the MAMBA python language is going to be phased out over the coming year. The next release will remove half of the python reliance already. Also this has resulted in a number of changes in our back end which I would need to integrate with your changes. Thus we are probably not going to integrate this.

Please email us if you are going to make big changes and keep in contact, as we have a quite a lot of changes in our private branch which we only push on a quarterly basis to the public repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants