<?phpnamespace App\Alis\Lang;/** The words of the ALIS source language (docs/language.md): variables, operators, functions, statements. */final class Names{ /** bytes 0x80..0xff of the game's texts (DOS code page 437), as written in the source */ public const CP437 = 'ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ '; /** @return array<int, string> byte => its UTF-8 character */ public static function cp437(): array { static $map = null; return $map ??= array_combine(range(0x80, 0xff), preg_split('//u', self::CP437, -1, PREG_SPLIT_NO_EMPTY)); // no mbstring needed } /** binary operators (opernames) => symbol */ public const BINOPS = [ 'oand' => '&', 'oor' => '|', 'oxor' => '^', 'oeqv' => 'eqv', 'oegal' => '==', 'odiff' => '!=', 'oinfeg' => '<=', 'osupeg' => '>=', 'oinf' => '<', 'osup' => '>', 'oadd' => '+', 'osub' => '-', 'omod' => '%', 'odiv' => '/', 'omul' => '*', 'osadd' => '$+', 'osequal' => '$==', 'osdiff' => '$!=', 'osinfeg' => '$<=', 'ossupeg' => '$>=', 'osinf' => '$<', 'ossup' => '$>', ]; /** functions (opernames without operands, they work on the current value) => name */ public const FUNCS = [ 'ohimtp' => 'himtp', 'ohimtc' => 'himtc', 'ohimti' => 'himti', 'opile' => 'pile', 'opushacc' => 'push', 'oneg' => 'neg', 'oabs' => 'abs', 'ornd' => 'rnd', 'osgn' => 'sgn', 'onot' => 'not', 'oinkey' => 'inkey', 'okeyon' => 'keyon', 'ojoy' => 'joy', 'oprnd' => 'prnd', 'oscan' => 'scan', 'oshiftkey' => 'shiftkey', 'ofree' => 'free', 'omodel' => 'model', 'ogetkey' => 'getkey', 'oleft' => 'left', 'oright' => 'right', 'omid' => 'mid', 'olen' => 'len', 'oasc' => 'asc', 'ostr' => 'str', 'ospushacc' => 'spush', 'ospile' => 'spile', 'oval' => 'val', 'oexistf' => 'existf', 'ochr' => 'chr', 'ochange' => 'change', 'ocountry' => 'country', 'omip' => 'mip', 'ojoykey' => 'joykey', 'oconfig' => 'config', 'ogettext' => 'gettext', 'oips' => 'ips', // store / add targets without operand 'pnul' => 'pnul', 'shimp' => 'himp', 'shimtp' => 'himtp', 'shimtc' => 'himtc', 'shimti' => 'himti', 'spile' => 'push', 'ahimb' => 'himb', 'ahimp' => 'himp', 'ahimtc' => 'himtc', 'ahimti' => 'himti', 'ofin' => 'fin', ]; /** functions that give a value without reading the current one: written like values (inkey() == 80) */ public const VALUES = ['oinkey', 'oshiftkey', 'ogetkey', 'ochange', 'ocountry', 'omip', 'oconfig', 'oscan', 'opile', 'oips', 'omodel']; /** * The variable of an operand item: [prefix, addressing] (addressing: loc = s16 offset in the entity's * variables, dir = u8 offset there, main = the main script's variables, him = another entity's). * Prefixes: v (variable) / t (table) / m (main) + b (byte) / w (word) / s (string); "to" = a table's address. */ public static function variable(string $name): ?array { if (!preg_match('/^[osa](loc|dir|main|him)(b|w|p|tp|tc|ti|to)$/', $name, $m)) { return null; } $type = ['b' => 'b', 'w' => 'w', 'p' => 's', 'tc' => 'b', 'ti' => 'w', 'tp' => 's', 'to' => 'o'][$m[2]]; $table = $m[2][0] === 't'; $prefix = match ($m[1]) { 'loc', 'dir' => ($table ? 't' : 'v') . $type, 'main' => 'm' . ($table ? 't' : '') . $type, 'him' => 'h' . ($table ? 't' : '') . $type, }; return [$prefix, $m[1]]; } /** The statement word of an opcode (its name without the leading c). */ public static function statement(string $name): string { return substr($name, 1); }}