EN
games/alis / src / Alis / Compiled / Templates / OpersC.php · commit 9c722cf
<?phpnamespace App\Alis\Compiled\Templates;use App\Alis\Compiled\Context;use App\Alis\Compiled\Templates;/** * Expression elements 0x76 (ofree) to 0xac (oips) of fn/opernames.php: the strings, the system queries and the * string comparisons. Thin elements call the VM's own function (same effects); the small ones are written again. * Left to the VM: ogetkey (it yields the frame and restarts the instruction), ogettext (v6 text search). */final class OpersC{    /** a string comparison: $op compares strncmp() with 0, D7 = $yes or $no */    private static function cmp(string $yes, string $no, string $op): \Closure    {        return static fn (array $e, Context $c): string => $c->opernameSwap($e['sub'][0]) . "\n"            . 'Alis::$varD7 = \strncmp(\App\Alis\mem_str(Alis::$sd6), \App\Alis\mem_str(Alis::$sd7), \App\Alis\mem_strlen(Alis::$sd6))'            . $op . ' ? ' . $yes . ' : ' . $no . ';';    }    private static function call(string $fn): \Closure    {        return static fn (array $e): string => '\App\Alis\\' . $fn . '();';    }    public static function register(): void    {        $o = &Templates::$oper;        $o[0x76] = self::call('ofree');        $o[0x78] = self::call('omodel');        // 0x7a ogetkey: left to the VM        $o[0x7c] = self::call('oleft');        // v6 overrides oright        $o[0x7e] = static fn (array $e): string => 'if (Alis::$platform->version >= 60) { \App\Alis\oright_v6(); } else { \App\Alis\oright(); }';        $o[0x80] = self::call('omid');        $o[0x82] = static fn (array $e): string => 'Alis::$varD7 = \App\Alis\mem_strlen(Alis::$sd7);';        $o[0x84] = self::call('oasc');        $o[0x86] = static fn (array $e): string => '\App\Alis\valtostr(Alis::$sd7, \App\Alis\s16(Alis::$varD7));';        $o[0x88] = static fn (array $e, Context $c): string => $c->opernameSwap($e['sub'][0]) . "\n"            . '\App\Alis\mem_putstr(Alis::$sd6, \App\Alis\mem_str(Alis::$sd6) . \App\Alis\mem_str(Alis::$sd7));' . "\n"            . '[Alis::$sd6, Alis::$sd7] = [Alis::$sd7, Alis::$sd6];';        $o[0x8a] = self::cmp('0', '-1', '');        $o[0x8c] = self::cmp('-1', '0', '');        $o[0x8e] = self::cmp('-1', '0', ' <= 0');        $o[0x90] = self::cmp('-1', '0', ' >= 0');        $o[0x92] = self::cmp('-1', '0', ' < 0');        $o[0x94] = self::cmp('-1', '0', ' > 0');        $o[0x96] = self::call('push_sd7');        $o[0x98] = static fn (array $e): string => '[Alis::$sd6, Alis::$sd7] = [Alis::$sd7, Alis::$sd6];' . "\n" . '\App\Alis\pop_sd6();';        $o[0x9a] = self::call('oval');        $o[0x9c] = self::call('oexistf');        $o[0x9e] = self::call('ochr');        $o[0xa0] = self::call('ochange');        $o[0xa2] = static fn (array $e): string => 'Alis::$varD7 = Alis::$pays;';        $o[0xa4] = self::call('omip');        $o[0xa6] = self::call('ojoykey');        $o[0xa8] = self::call('oconfig');        // 0xaa ogettext: left to the VM        $o[0xac] = self::call('oips');    }}