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.txt
definition, and produces an AST tree consisting ofoperations.py
nodesbytecode.py
- turns the AST tree produced bysourceparcer.py
into bytecode by callingcompile()
on the tree. Produces aByteCode
instance consisting ofopcodes.py
nodesframe.py
- execution frame. Contains the stack and the variables/functions map for the function or the global program. A frame instance is passed toexecute
method of aByteCode
instance 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 optimizedMap
class used for symbols map inscopes.py
stdlib.py
- various PHP standard library methods likestrlen
functions.py
- wraps aByteCode
instance or a native function fromstdlib.py
into 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