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.
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
- unicode support for function/variable names and string values. PHP 6 compatible!
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 aInterpreter
instance as the only parameterinterpreter.py
- loops over a list of bytecodes and evaluates aopcodes.py
handlergrammar.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 theInterpreter.execute()
methodsymbols.py
- contains an optimizedMap
class used for symbols map inscopes.py
stdlib.py
- various PHP standard library methods likestrlen
datatypes.py
- all datatypes' box classes used to store the variables, like int, float, array, etc.
Build the container first
docker build -t juokaz/pyhp .
or pull from docker hup
docker pull juokaz/pyhp
make build
Or to build without JIT support
make build-nojit
make bench
Or run any PHP file
./build/pyhp bench.php
./build/pyhp --server 8080
Accessible through http://localhost:8080/bench.php.
./build/pyhp --bytecode bench.php
./build/pyhp --ast bench.php
PYPYLOG=jit-log-opt:jit.txt ./build/pyhp bench.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
make tests
Or to run with coverage information
make tests-cov
docker build -t juokaz/pyhp .