-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
58 lines (50 loc) · 2.57 KB
/
index.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* ChickenASM Programming Language
* Copyright (C) 2013 powder96 <https://github.com/powder96/>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once(__DIR__ . '/ChickenASMLanguage/ChickenASMLanguage.php');
define('EXAMPLES_DIR', __DIR__ . '/examples');
run(EXAMPLES_DIR . '/helloworld.chn', '(unused)', 'Hello world');
run(EXAMPLES_DIR . '/quine.chn', '(unused)', 'chicken');
run(EXAMPLES_DIR . '/cat.chn', 'Chicken Power!', 'Chicken Power!');
run(EXAMPLES_DIR . '/99chickens.chn', '9', '9 chickens 8 chickens 7 chickens 6 chickens 5 chickens 4 chickens 3 chickens 2 chickens 1 chicken no chickens ');
run(EXAMPLES_DIR . '/deadfish.chn', 'iissiso', ' 289 ');
function run($file, $input, $expectedOutput) {
echo '<h3>' . $file . '</h3>';
echo 'Input: <code>' . $input . '</code><br />';
try {
$compiler = new ChickenASMLanguage\ChickenCompiler(file_get_contents($file));
$opcodes = $compiler->compile();
$vm = new ChickenASMLanguage\VirtualMachine($opcodes, $input);
$output = $vm->execute();
$log = $vm->getExecutionLog();
}
catch(Exception $e) {
$output = $e->getMessage();
$log = '';
}
echo 'Output: <code>' . $output . ' <small><em>[' . htmlspecialchars($output) . ']</em></small></code><br />';
if($output !== $expectedOutput)
echo 'Expected output: <code>' . $expectedOutput . ' <small><em>[' . htmlspecialchars($expectedOutput) .
']</em></small></code>';
if(!empty($log)) {
$htmlId = md5($file);
echo "<a href=\"#\" id=\"log-button-{$htmlId}\" onclick=\"document.getElementById('log-{$htmlId}').style.display = '';\">Log</a>";
echo "<pre id=\"log-{$htmlId}\" style=\"display: none;\">" . htmlspecialchars($log) . '</pre></span>';
}
echo '<hr />';
}