diff --git a/README.md b/README.md index d5a1ac802..8a45c2425 100644 --- a/README.md +++ b/README.md @@ -30,15 +30,12 @@ Or use pip to install extra modules: # Code organization - - parser: python lexing, parsing and ast - - vm: python virtual machine - - src: using the other subcrates to bring rustpython to life. - -The files in the top level directory are from [windelbouwman/rspython][rspython] which contains an implementation of the parser and vm in `src/` - -An alternative implementation of python virtual machine that are compatible with CPython parser are from [shinglyu/RustPython][rustpython] and is located in the `VM/` folder. - -We are in the process of merging the two implementation to form a single implementation. + - `parser`: python lexing, parsing and ast + - `vm`: python virtual machine + - `src`: using the other subcrates to bring rustpython to life. + - `docs`: documentation (work in progress) + - `py_code_object`: CPython bytecode to rustpython bytecode convertor (work in progress) + - `tests`: integration test snippets # Community @@ -48,8 +45,6 @@ Chat with us on [gitter][gitter]. The initial work was based on [windelbouwman/rspython](https://github.com/windelbouwman/rspython) and [shinglyu/RustPython](https://github.com/shinglyu/RustPython) -[rspython]: https://github.com/windelbouwman/rspython -[rustpython]: https://github.com/shinglyu/RustPython [gitter]: https://gitter.im/rustpython/Lobby # Links @@ -57,3 +52,6 @@ The initial work was based on [windelbouwman/rspython](https://github.com/windel These are some useful links to related projects: - https://github.com/ProgVal/pythonvm-rust +- https://github.com/shinglyu/RustPython +- https://github.com/windelbouwman/rspython + diff --git a/py_code_object/init_env.sh b/py_code_object/init_env.sh deleted file mode 100644 index 7842e1c54..000000000 --- a/py_code_object/init_env.sh +++ /dev/null @@ -1,7 +0,0 @@ -virtualenv venv --python=python3 -source venv/bin/activate -pip install bytecode - -source ~/.cargo/env -rustup install nightly -rustup default nightly diff --git a/py_code_object/requirements.txt b/py_code_object/requirements.txt deleted file mode 100644 index 027584177..000000000 --- a/py_code_object/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -byteplay==0.2 diff --git a/py_code_object/test.sh b/py_code_object/test.sh deleted file mode 100755 index 03828b006..000000000 --- a/py_code_object/test.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# Usage: test.sh [--bytecode|--dis] -# --bytecode: print the bytecode -# --dis: run dis - -set -e - -MODE="run" - -case "${2}" in - "--bytecode" ) - MODE="view_bytecode" - ;; - "--dis" ) - MODE="run_dis" - ;; - * ) - ;; -esac - -TESTCASE=$(basename ${1}) -#TMP_FILE="test_${TESTCASE}.bytecode" -TMP_FILE="${1}.bytecode" - -python compile_code.py "${1}" > "${TMP_FILE}" - -echo "${MODE}" -case "${MODE}" in - "run" ) - cd RustPython - RUST_BACKTRACE=1 cargo run "../${TMP_FILE}" - ;; - "view_bytecode" ) - cat "${TMP_FILE}" | python -m json.tool - ;; - "run_dis" ) - python -m dis "${1}" - ;; - * ) - echo "Not a valid mode!" - ;; -esac - diff --git a/py_code_object/test_all.bat b/py_code_object/test_all.bat deleted file mode 100644 index 139811e43..000000000 --- a/py_code_object/test_all.bat +++ /dev/null @@ -1,11 +0,0 @@ -:: win bat - - -cd tests - -for %%i in (*.py) do python ../compile_code.py %%i >../bytes/%%i.bytecode -cd .. - -REM cd RustPython -REM for %%i in (../bytes/*.vbytecode) do echo %%i -REM cd .. diff --git a/py_code_object/test_all.sh b/py_code_object/test_all.sh deleted file mode 100755 index 0eadb632f..000000000 --- a/py_code_object/test_all.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env bash -# set -e - -source venv/bin/activate -#TESTCASE=tests/variables.py -# TESTCASE=tests/variables.py -#TESTCASE=tests/minimum.py -unexpected_count=0 -expected_count=0 -fail_titles=$"" - -RED='\033[0;31m' -NC='\033[0m' # No Color - -for TESTCASE in $(find ../tests -name \*.py -print) -do - echo "TEST START: ${TESTCASE}" - echo "--------------------------------" - FILENAME="$(basename ${TESTCASE})" - xfail=false - if [ "${FILENAME:0:6}" = "xfail_" ]; then - echo "Expected FAIL" - xfail=true - fi - - - python compile_code.py $TESTCASE > $TESTCASE.bytecode - cd RustPython - cargo run ../$TESTCASE.bytecode - - - if [[ $? -ne 0 ]]; then - if [ "${xfail}" = true ]; then - echo "== FAIL as expected ==" - let expected_count=expected_count+1 - else - printf "${RED}== FAIL, expected PASS ==${NC}\n" - let unexpected_count=unexpected_count+1 - fail_titles=$"${fail_titles}\n${TESTCASE}\t${RED}FAIL${NC} (expected PASS)" - fi - else - if [ "${xfail}" = true ]; then - printf "${RED}== PASS, expected FAIL ==${NC}\n" - let unexpected_count=unexpected_count+1 - let unexpected_count=unexpected_count+1 - fail_titles=$"${fail_titles}\n${TESTCASE}\t${RED}PASS${NC} (expected FAIL)" - else - echo "== PASS as expected ==" - let expected_count=expected_count+1 - fi - fi - cd .. - echo "--------------------------------" - -done - -echo "Summary" -echo "================" -printf "${RED}${unexpected_count} unexpected${NC}, ${expected_count} expected" -echo "" -echo "" -echo "unexpected results:" -printf "${fail_titles}" -echo "" -echo "================" diff --git a/py_code_object/Pipfile b/tests/Pipfile similarity index 100% rename from py_code_object/Pipfile rename to tests/Pipfile diff --git a/py_code_object/Pipfile.lock b/tests/Pipfile.lock similarity index 100% rename from py_code_object/Pipfile.lock rename to tests/Pipfile.lock diff --git a/tests/test_snippets.py b/tests/test_snippets.py index 243e7ccdb..d855d0c61 100644 --- a/tests/test_snippets.py +++ b/tests/test_snippets.py @@ -83,12 +83,13 @@ def create_test_function(cls, filename, method): setattr(cls, test_function_name, test_function) -def populate(cls): - """ Decorator function which can populate a unittest.TestCase class """ - for method in ['cpython', 'cpython_bytecode', 'rustpython']: +def populate(method): + def wrapper(cls): + """ Decorator function which can populate a unittest.TestCase class """ for filename in get_test_files(): create_test_function(cls, filename, method) - return cls + return cls + return wrapper def get_test_files(): @@ -102,6 +103,8 @@ def get_test_files(): yield os.path.abspath(filepath) -@populate +@populate('cpython') +# @populate('cpython_bytecode') +@populate('rustpython') class SampleTestCase(unittest.TestCase): pass