[en] | [pt-br]
Interpreter implemented in PHP for the Compiler Battle
https://github.com/aripiprazole/rinha-de-compiler
This program will interpret a Rinha language AST in two ways:
- Tree-walker Interpreter: interprets the AST directly in memory
- Bytecode Interpreter: compiles the AST into Bytecode and interprets the bytecode directly in memory through a simple VM
The two methods will be executed in sequence and should give the same result.
For now the index.php file will only execute method 2.
The ./src/experiments
folder is not part of the project itself, but it contains fun studies that this competition gave me.
Clone
git clone [email protected]:dhrleandro/rinha-de-compiler-php.git
Docker command
docker build -t dhr-rinha-de-compiler-php .
docker run -v ./source.rinha.json:/var/rinha/source.rinha.json --memory=2gb --cpus=2 dhr-rinha-de-compiler-php
Examples:
Run in the project root folder.
docker run -v ./var/rinha/files/combination.json:/var/rinha/source.rinha.json --memory=2gb --cpus=2 dhr-rinha-de-compiler-php
docker run -v ./var/rinha/files/fib.json:/var/rinha/source.rinha.json --memory=2gb --cpus=2 dhr-rinha-de-compiler-php
docker run -v ./var/rinha/files/sum.json:/var/rinha/source.rinha.json --memory=2gb --cpus=2 dhr-rinha-de-compiler-php
docker run -v ./var/rinha/files/print.json:/var/rinha/source.rinha.json --memory=2gb --cpus=2 dhr-rinha-de-compiler-php
docker run -v ./var/rinha/files/test.json:/var/rinha/source.rinha.json --memory=2gb --cpus=2 dhr-rinha-de-compiler-php
or
Makefile command
make build
make run
You need PHP 8 and Composer 2
composer install
php index.php
https://github.com/aripiprazole/rinha-de-compiler/blob/main/SPECS.md
Feature | Checked |
---|---|
Int | OK |
Str | OK |
Call | OK |
Binary | OK |
Function | OK |
Let | OK |
If | OK |
Partially | |
First | - |
Second | - |
Bool | - |
Tuple | - |
Var | OK |