PyHP is an (incomplete!) implementation of the PHP language using the RPython technology. It uses JIT transformer provided by the RPython library to achieve good performance.
PyHP stands for Python + PHP, as RRpython is a subset of the Python language.
Highly unstable and work in progress.
HippyVM is too built on top of RPython, and is a complete, working implementation.
- all variable types like int, float, string, array, iterator
- if, while, for, foreach statements
- functions
- pass by value or by reference to a function
- global variables in function blocks using
global - global constants using
define() - (incomplete) standard library functions
main.py- main entry pointsourceparcer.py- parses a given PHP file using thegrammar.txtdefinition, and produces an AST tree consisting ofoperations.pynodesbytecode.py- turns the AST tree produced bysourceparcer.pyinto bytecode by callingcompile()on the tree. Produces aByteCodeinstance consisting ofopcodes.pynodesframe.py- execution frame. Contains the stack and the variables/functions map for the function or the global program. A frame instance is passed toexecutemethod of aByteCodeinstance as the only parametergrammar.txt- EBNF PHP grammar used bysourceparcer.py
Additional files:
operations.py- AST tree nodesopcodes.py- class per each opcode. Each opcode has aeval(frame)method which gets called by theBytecode.execute()methodsymbols.py- contains an optimizedMapclass used for symbols map inscopes.pystdlib.py- various PHP standard library methods likestrlenfunctions.py- wraps aByteCodeinstance or a native function fromstdlib.pyinto an object which then gets used to run a function or the main programdatatypes.py- all datatypes' box classes used to store the variables, like int, float, array, etc.
vagrant up
vagrant ssh
cd /var/www/pyhp
rpython -Ojit targetpyhp.py
Emit the -Ojit to compile an interpreter without JIT support. Speeds up the build
process by 5x, but the produced interpreter runs much slower.
./pyhp-c fibonacci.php
PYPYLOG=jit-log-opt:jit.txt ./pyhp-c fibonacci.php
Plot the trace as a graph
PYTHONPATH=$PYTHONPATH:/home/vagrant/pypy-src/ python ~/pypy-src/rpython/tool/logparser.py draw-time jit.txt --mainwidth=8000 filename.png
PYTHONPATH=$PYTHONPATH:/home/vagrant/pypy-src/ py.test tests