<?php
class WebASM {
private $_input;
private $_val;
private $_0 = 0;
private $_1 = 0;
private $_2 = 0;
private $_3 = 0;
private $_4 = 0;
private $_5 = 0;
private $_6 = 0;
private $_7 = 0;
public function __construct($code) {
$this->_0 = $code;
unset($code);
if(!is_string($this->_0)) {
$this->_0 = 0;
return 1;
}
if(preg_match('#^file\:#', $this->_0)) {
$this->_0 = preg_replace('#^file\:#', '', $this->_0);
if(file_exists($this->_0)) {
$this->_0 = file_get_contents($this->_0);
}
else {
$this->_0 = 0;
return 1;
}
}
$this->_0 = preg_replace_callback('#(.*):#', function ($matches) {
if(is_numeric($matches[1])) {
return 'a'.$matches[0];
}
else {
return '//'.$matches[0];
}
}, $this->_0);
$this->_0 = preg_replace('#pri?nt (.*)#', 'echo(\$this->_$1);', $this->_0);
$this->_0 = preg_replace('#set ([0-7]) ([0-9]{1,256})#U', '\$this->_$1 = $2;', $this->_0);
$this->_0 = preg_replace('#copyto ([0-7])#', '\$this->_$1 = \$this->_val;', $this->_0);
$this->_0 = preg_replace('#copyfrom ([0-7])#', '\$this->_val = \$this->_$1;', $this->_0);
//$this->_0 = preg_replace('#pro?mpt (str|int) ([0-9]{256})#', 'echo($1);', $this->_0);
$this->_0 = preg_replace('#add ([0-7])#', '\$this->_val = \$this->_val + \$this->_$1;', $this->_0);
$this->_0 = preg_replace('#sub ([0-7])#', '\$this->_val = \$this->_val - \$this->_$1;', $this->_0);
$this->_0 = preg_replace('#jump ([0-9]{1,256}) if ([0-7]) ([0-9]{1,256})#', 'if(\$this->_$2 == $3) goto a$1;', $this->_0);
$this->_0 = preg_replace('#jump ([0-9]{1,256}) if ([0-9]{1,256})#', 'if(\$this->_val == $2) goto a$1;', $this->_0);
$this->_0 = preg_replace('#jump ([0-9]{1,256})#', 'goto a$1;', $this->_0);
$this->_0 = preg_replace('#(die|re?tu?rn|exit)#', 'return 0;', $this->_0);
$this->_0 = '$c = function () {'.$this->_0.'return 1;};$x=$c();if($x!=0)echo("An error has occured.");';
eval($this->_0);
}
}
$code = <<<WebASM
set 0 1
set 1 1
copyfrom 0
0:
add 1
jump 1 if 3
jump 0
1:
copyto 0
print 0
lol:
print 1
WebASM;
$asm = new WebASM($code);
- Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.16, 8.4.1 - 8.4.3
- 31An error has occured.
preferences:
133.65 ms | 408 KiB | 5 Q