Pavel Durov
Pavel Durov

Reputation: 1297

PyPy, RPython and Python versions compatibility when translation process

I'm trying to translate my RPython program using the PyPy 3.* packages as it appears on the download page.

I can translate my simple RPython program only using the 2.7 PyPy version but not using any further versions. My RPython program:

import os
import sys

def entry_point(argv):
    os.write(1, bytes("Hello World!\n", "utf-8"))
    return 0


def target(*args):
    return entry_point, None

My script that downloads sources and binaries and runs the translation command:

#!/bin/bash
set -e

function get_pypy(){
  VERSION=$1
  rm -fr "${VERSION}-src.tar.bz2" "${VERSION}-osx64.tar.bz2" "${VERSION}-osx64" "${VERSION}-src"
  wget -S "https://downloads.python.org/pypy/${VERSION}-src.tar.bz2" && tar -xvf "${VERSION}-src.tar.bz2"
  wget -S "https://downloads.python.org/pypy/${VERSION}-osx64.tar.bz2" && tar -xvf "${VERSION}-osx64.tar.bz2"
}

function run_translate(){
  VERSION=$1
  FILENAME=$2
  "${PWD}/${VERSION}-osx64/bin/pypy" "${PWD}/${VERSION}-src/rpython/bin/rpython" "${PWD}/${FILENAME}"
}

# 3.9
VERSION=pypy3.9-v7.3.9
get_pypy "${VERSION}"
run_translate "${VERSION}" "hello_world.py"

When running it, I get this error:

 File "/Users/kimchi/git-repos/side-projects/bf.meta.tracing/scripts/python-versions/pypy3.9-v7.3.9-src/rpython/bin/rpython", line 17
    print __doc__
    ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(__doc__)?

source link

Looks like Python 3.9 is complaining about Python2.7 print statements. But they are both downloaded from 3.9 sources.

Any help will be appreciated :)

From what I have seen so far (documentation on this bit is quite out of date), there are two ways of running the transition process:

pypy ./rpython/bin/rpython program.py
# AND
python ./rpython/translator/goal/translate.py program.py

Is there any difference?

Upvotes: 1

Views: 186

Answers (1)

mattip
mattip

Reputation: 2563

Since RPython is a python2-language derivative, you must use a python2.7 (either CPython python2.7 or PyPy 2.7) to translate. If there are places in the documentation that this should be made clear, please point to them. Here, for instance, is one place it states clearly that RPython is built on python2.

The sources you downloaded will build a python3.9 interpreter, but the code is RPython (i.e. python2) much as the code for CPython3.9 is written in C.

Upvotes: 2

Related Questions