-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
30 lines (21 loc) · 851 Bytes
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
use POPSuL\Brainfuck\BrainfuckOptimizer;
use POPSuL\Brainfuck\BrainfuckVM;
use POPSuL\Brainfuck\BrainfuckCompiler;
use POPSuL\Brainfuck\PHPGenerator;
require __DIR__ . '/vendor/autoload.php';
$code = <<<FUCK_MY_BRAIN_AGAIN
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++
.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.
------.--------.>+.>.
FUCK_MY_BRAIN_AGAIN;
$program = (new BrainfuckCompiler())->compile($code);
$optimized = $program->optimize(new BrainfuckOptimizer());
printf("Not optimized size: %d instructions\n", count($program->getInstructions()));
printf("Optimized size: %d instructions\n\n", count($optimized->getInstructions()));
$vm = new BrainfuckVM();
printf("Not optimized program:\n");
$vm->execute($program);
printf("Optimized program:\n");
$vm->execute($optimized);
//echo $program->generateCode(new PHPGenerator());