Python interpreter built on Truffle and Graal VM
- int (arbitrary precision)
- str
- bool
- arithmetic (+, -, *, /, %)
- assignment (=, +=, -=, *=, /=, %=)
- comparison (==, !=, >, >=, <, <=)
- logical (not, and, or)
- if/else (no elif)
- while loop (no for)
- function definition, arbitrary argument number (only positional, no named)
- function nesting, recursion
- no
passblank statement - builtin functions:
x = str(arg)- convertargto string typex = int(arg)- convertargto int typeprint(arg)- printargto console (with newline)x = input()- read user input from console, assign to variablesleep(seconds)- sleep for given number of secondsexit()- exit the programx = time()- get millisecond-precision time- Not actual clock time, but good for measuring elapsed time
- Similar to Python's
time.time()but Pyterpreter cannot do imports so there we go - For compatibility in running pyterpreter scripts in Python, user a wrapper script where you import
time(), e.g.from time import time; import pyterpreter_script.py
- Some scripts that Pyterpreter can handle are in the benchmark folder
- JVM (tested on 8)
- It will work on regular HotspotVM
- For better performance run on GraalVM (Linux/MAC)
- Download labsjdk on bottom of the page
- Set
JAVA_HOMEto point to extracted LabsJDK archive andPATHtoJAVA_HOME/bin
- Gradle will be used or automatically downloaded when running
gradlew(see below) - In order to run Pyterpreter on Graal, copy or symlink Graal root directory to
pyterpreter/graalvm(download on the same URL as above, but use the links on the top of the page)
$ git clone git@github.com:melkamar/pyterpreter.git
$ cd pyterpreter
$ ./gradlew clean test jar
$ ./pyterpreter [args] # Non-graal
$ ./pyterpreter-graal [args] # Graal-enabled
- No arguments - start REPL
- Single argument - path to file - execute that file
-r file/in/resources- run file from inside pyterpreter jar. See resources folder- e.g.
java -jar build/libs/pyt*all* -r benchmark/fibonacci.pywill start fibonacci benchmark.
- e.g.
Using benchmark countdown.py, in milliseconds
- Hotspot 1722/356
- Graal 2627/438
:(