<?phpnamespace App\Alis\Compiled\Templates;use App\Alis\Compiled\Context;use App\Alis\Compiled\Templates;/** Opcodes 0x00-0x07: cnul, cesc1 (and its escapes), cesc2, cesc3, cbreakpt, cjsr8 / 16 / 24. */final class Ops00{ public static function register(): void { // cnul: stops the interpreter Templates::$op['cnul'] = static fn (array $i, Context $c): string => 'Alis::$state = \App\Alis\C::eAlisStateStopped;'; // cbreakpt: empty in the VM Templates::$op['cbreakpt'] = static fn (array $i, Context $c): string => ''; // cesc1: version 10 does nothing (not even reading the escape byte); the others run the escape's handler // from the version's table with the stream just after the escape byte (the handler reads its own operands) Templates::$op['cesc1'] = static function (array $i, Context $c): ?string { $esc = null; foreach ($i['ops'] as $op) { if ($op[0] === 'esc') { $esc = $op; } } if ($esc === null) { return null; } return sprintf( "if (Alis::\$platform->version != 10) {\n \$s->pc = \$o + 0x%x;\n (\\App\\Alis\\Tables::\$tab_codesc1[%d])();\n}", $i['at'] + 2, $esc[1] ); }; foreach ([8, 16, 24] as $bits) { Templates::$op["cjsr$bits"] = static function (array $i, Context $c): string { $target = null; foreach ($i['ops'] as $op) { if ($op[0] === 'j') { $target = $op[2]; } } if ($target === null) { throw new \LogicException('no jump operand'); } // the return OFFSET (relative to pc_org) of the instruction after this one, then the jump return '\App\Alis\xpush32(\App\Alis\s32($s->pc - $s->pc_org));' . "\n" . Context::go($target); }; } }}