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
pass
blank statement - builtin functions:
x = str(arg)
- convertarg
to string typex = int(arg)
- convertarg
to int typeprint(arg)
- printarg
to 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_HOME
to point to extracted LabsJDK archive andPATH
toJAVA_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.py
will start fibonacci benchmark.
- e.g.
Using benchmark countdown.py
, in milliseconds
- Hotspot 1722/356
- Graal 2627/438
:(