for comparisons. * * It is a word for word translation of the canonical form (Printer / Assembler): every word, name and block has one * counterpart, so toCanonical(toHuman($s)) === $s, and a human file compiles to the same bytes (the Assembler * compiles the canonical text). isHuman() tells the two apart (a human file starts with `module`). */ final class Human { /** statements (the machine's words without their c) => French */ public const STATEMENTS = [ 'nul' => 'rien', 'breakpt' => 'point_arret', 'eval' => 'calcule', 'mul' => 'multiplie', 'div' => 'divise', 'vprint' => 'affiche_valeur', 'sprinti' => 'affiche_texte_i', 'sprinta' => 'affiche_texte', 'locate' => 'position_texte', 'tab' => 'tabulation', 'dim' => 'dimension', 'random' => 'graine_hasard', 'leave' => 'quitte', 'protect' => 'protege', 'asleep' => 'endors', 'clock' => 'horloge', 'anim' => 'anime', 'scmov' => 'ecran_deplace', 'scset' => 'ecran_place', 'clipping' => 'decoupe', 'switching' => 'bascule_ecrans', 'wlive' => 'lance_attend', 'unload' => 'decharge', 'wakeup' => 'reveille', 'sleep' => 'dort', 'live' => 'lance', 'kill' => 'tue', 'stop' => 'fin_tour', 'stopret' => 'fin_tour_retour', 'exit' => 'termine', 'load' => 'charge', 'defsc' => 'definit_ecran', 'screen' => 'ecran', 'put' => 'place', 'putnat' => 'place_naturel', 'erase' => 'efface', 'erasen' => 'efface_num', 'set' => 'positionne', 'mov' => 'deplace', 'opensc' => 'ouvre_ecran', 'closesc' => 'ferme_ecran', 'erasall' => 'efface_tout', 'delforme' => 'supprime_forme', 'tstmov' => 'teste_deplace', 'tstset' => 'teste_position', 'ftstmov' => 'teste_deplace_f', 'ftstset' => 'teste_position_f', 'succent' => 'entite_suivante', 'predent' => 'entite_precedente', 'nearent' => 'entite_proche', 'neartyp' => 'type_proche', 'nearmat' => 'matiere_proche', 'viewent' => 'entite_vue', 'viewtyp' => 'type_vu', 'viewmat' => 'matiere_vue', 'orient' => 'oriente', 'rstent' => 'reinit_entite', 'send' => 'envoie', 'scanon' => 'clavier_on', 'scanoff' => 'clavier_off', 'interon' => 'interruptions_on', 'interoff' => 'interruptions_off', 'scanclr' => 'clavier_vide', 'allentity' => 'toutes_entites', 'defcolor' => 'definit_couleur', 'timing' => 'cadence_vm', 'explode' => 'explose', 'noise' => 'bruit', 'initab' => 'init_tableau', 'fopen' => 'ouvre_fichier', 'fclose' => 'ferme_fichier', 'fcreat' => 'cree_fichier', 'fdel' => 'supprime_fichier', 'freadv' => 'lit_valeur', 'fwritev' => 'ecrit_valeur', 'fwritei' => 'ecrit_entier', 'freadb' => 'lit_bloc', 'fwriteb' => 'ecrit_bloc', 'plot' => 'point', 'draw' => 'trace', 'box' => 'cadre', 'boxf' => 'cadre_plein', 'ink' => 'encre', 'pset' => 'crayon_place', 'pmove' => 'crayon_deplace', 'pmode' => 'crayon_mode', 'picture' => 'image', 'xyscroll' => 'defilement', 'linking' => 'lie', 'mouson' => 'souris_on', 'mousoff' => 'souris_off', 'mouse' => 'lit_souris', 'defmouse' => 'forme_souris', 'setmouse' => 'place_souris', 'defvect' => 'definit_vecteurs', 'setvect' => 'vecteurs', 'nul2' => 'rien2', 'approach' => 'approche', 'escape' => 'echappe', 'vtstmov' => 'teste_deplace_v', 'vftstmov' => 'teste_deplace_vf', 'vmov' => 'deplace_v', 'defworld' => 'definit_monde', 'world' => 'monde', 'findmat' => 'cherche_matiere', 'findtyp' => 'cherche_type', 'music' => 'musique', 'delmusic' => 'coupe_musique', 'cadence' => 'tempo', 'setvolum' => 'volume', 'xinv' => 'inverse_x', 'xinvon' => 'inverse_x_on', 'xinvoff' => 'inverse_x_off', 'listent' => 'liste_entites', 'sound' => 'son', 'msound' => 'son_m', 'redon' => 'reduction_on', 'redoff' => 'reduction_off', 'delsound' => 'coupe_son', 'wmov' => 'deplace_w', 'wtstmov' => 'teste_deplace_w', 'wftstmov' => 'teste_deplace_wf', 'tstform' => 'teste_forme', 'xput' => 'place_x', 'xputat' => 'place_x_en', 'mput' => 'place_m', 'mputat' => 'place_m_en', 'mxput' => 'place_mx', 'mxputat' => 'place_mx_en', 'mmusic' => 'musique_m', 'mforme' => 'forme_m', 'settime' => 'regle_heure', 'gettime' => 'lit_heure', 'vinput' => 'saisie_valeur', 'sinput' => 'saisie_texte', 'asleepfar' => 'endors_loin', 'asleepon' => 'endors_on', 'asleepoff' => 'endors_off', 'runfilm' => 'joue_film', 'vpicprint' => 'imprime_valeur', 'spicprint' => 'imprime_texte', 'vputprint' => 'ecrit_nombre', 'sputprint' => 'ecrit_texte', 'font' => 'police', 'paper' => 'papier', 'toblack' => 'au_noir', 'movcolor' => 'bouge_couleur', 'topalet' => 'vers_palette', 'numput' => 'place_numero', 'scheart' => 'ecran_centre', 'scpos' => 'ecran_position', 'scsize' => 'ecran_taille', 'schoriz' => 'ecran_horizontal', 'scvertic' => 'ecran_vertical', 'screduce' => 'ecran_reduit', 'scscale' => 'ecran_echelle', 'reducing' => 'reduction', 'scmap' => 'ecran_carte', 'scdump' => 'ecran_copie', 'findcla' => 'cherche_classe', 'nearcla' => 'classe_proche', 'viewcla' => 'classe_vue', 'instru' => 'instrument', 'minstru' => 'instrument_m', 'ordspr' => 'ordre_sprites', 'align' => 'aligne', 'backstar' => 'fond_etoiles', 'starring' => 'etoiles', 'engine' => 'moteur', 'autobase' => 'base_auto', 'quality' => 'qualite', 'hsprite' => 'sprite_h', 'selpalet' => 'choisit_palette', 'linepalet' => 'palette_ligne', 'automode' => 'mode_auto', 'autofile' => 'fichier_auto', 'cancel' => 'annule', 'cancall' => 'annule_tout', 'cancen' => 'annule_entite', 'blast' => 'souffle', 'scback' => 'ecran_fond', 'scrolpage' => 'defile_page', 'matent' => 'matiere_entite', 'shrink' => 'retrecit', 'defmap' => 'definit_carte', 'setmap' => 'regle_carte', 'putmap' => 'place_carte', 'savepal' => 'garde_palette', 'sczoom' => 'ecran_zoom', 'texmap' => 'texture', 'alloctab' => 'alloue_tableau', 'freetab' => 'libere_tableau', 'scantab' => 'parcourt_tableau', 'neartab' => 'tableau_proche', 'scsun' => 'ecran_soleil', 'darkpal' => 'palette_sombre', 'scdark' => 'ecran_sombre', 'aset' => 'place_a', 'amov' => 'deplace_a', 'scaset' => 'ecran_place_a', 'scamov' => 'ecran_deplace_a', 'scfollow' => 'ecran_suit', 'scview' => 'ecran_vue', 'walkmap' => 'marche_carte', 'atstmap' => 'teste_carte', 'avtstmov' => 'teste_avance', 'avmov' => 'avance', 'aim' => 'vise', 'pointpix' => 'point_pixel', 'chartmap' => 'charte_carte', 'scsky' => 'ecran_ciel', // escapes (cesc1 + a byte) 'esc1' => 'echap1', 'soundon' => 'son_on', 'soundoff' => 'son_off', 'musicon' => 'musique_on', 'musicoff' => 'musique_off', 'delfilm' => 'coupe_film', 'openfilm' => 'ouvre_film', ]; /** the words of the blocks, jumps and switches */ public const CONTROL = [ 'if' => 'si', 'ifnot' => 'saufsi', 'while' => 'tantque', 'goto' => 'aller', 'call' => 'appel', 'start' => 'sequence', 'loop' => 'boucle', 'switch' => 'selon', 'case' => 'cas', 'end' => 'fin', 'ifz' => 'si_nul', 'ifnz' => 'si_non_nul', 'ifeq' => 'si_egal', 'ifne' => 'si_different', 'ret' => 'retour', 'data' => 'donnees', ]; /** the header's directives */ public const DIRECTIVES = [ 'script' => 'module', 'id' => 'numero', 'class' => 'classe', 'memory' => 'memoire', 'pack' => 'compression', 'check' => 'controle', 'resources' => 'ressources', 'main' => 'depart', 'before' => 'avant', 'after' => 'apres', ]; /** functions and the function-like targets */ public const FUNCTIONS = [ 'inkey' => 'touche', 'shiftkey' => 'touches_mode', 'getkey' => 'attend_touche', 'joy' => 'manette', 'keyon' => 'touche_enfoncee', 'joykey' => 'manette_touche', 'rnd' => 'hasard', 'prnd' => 'hasard_p', 'sgn' => 'signe', 'not' => 'non', 'free' => 'memoire_libre', 'model' => 'modele', 'left' => 'gauche', 'right' => 'droite', 'mid' => 'milieu', 'len' => 'longueur', 'asc' => 'code', 'chr' => 'caractere', 'str' => 'en_texte', 'val' => 'en_nombre', 'existf' => 'fichier_existe', 'change' => 'changement', 'country' => 'pays', 'gettext' => 'lit_texte', 'push' => 'empile', 'pile' => 'depile', 'spush' => 'empile_texte', 'spile' => 'depile_texte', 'pnul' => 'rien_v', 'fin' => 'fin_calcul', ]; /** operators (canonical => human); the words et / ou / oux / mod / equ are operators in the human form */ private const OPERATORS = [ '==' => '=', '!=' => '<>', '=' => ':=', '&' => 'et', '|' => 'ou', '^' => 'oux', '%' => 'mod', 'eqv' => 'equ', '$==' => '$=', '$!=' => '$<>', ]; /** the variables: canonical prefix => [type words, scope] */ private const KINDS = [ 'vb' => ['octet', 'local'], 'vw' => ['mot', 'local'], 'vs' => ['texte', 'local'], 'tb' => ['tableau octets', 'local'], 'tw' => ['tableau mots', 'local'], 'ts' => ['tableau textes', 'local'], 'to' => ['adresses textes', 'local'], 'mb' => ['octet', 'global'], 'mw' => ['mot', 'global'], 'ms' => ['texte', 'global'], 'mtb' => ['tableau octets', 'global'], 'mtw' => ['tableau mots', 'global'], 'mts' => ['tableau textes', 'global'], 'hb' => ['champ octet', ''], 'hw' => ['champ mot', ''], 'hs' => ['champ texte', ''], 'hts' => ['champ tableau textes', ''], '&v' => ['zone', 'local'], '&m' => ['zone', 'global'], ]; /** names the decompiler cannot know, found by reading the scripts (Robinson's Requiem's main variables) */ public const KNOWN = [ 'mw[0xe82]' => 'souris_x', 'mw[0xe84]' => 'souris_y', 'mw[0x2d6a]' => 'souris_y_ecran', 'mw[0x1a12]' => 'touche_lue', 'mw[0x1a10]' => 'etat_manette', 'mb[0xe88]' => 'bouton', 'mb[0x184c]' => 'allure', 'mb[0x19de]' => 'objet_tenu', 'mb[0x1a0e]' => 'furtif', 'mb[0xe68]' => 'langue', ]; /** per script: its own variables we could name */ public const KNOWN_LOCAL = [ 'yoda' => ['vw[0xb6]' => 'direction'], 'flags' => ['vb[0x52]' => 'vague'], ]; private const COMMENTS = ['// dead code' => '// code jamais atteint']; private const TOKEN = '/\G(\s+|\/\/.*|"(?:[^"\\\\]|\\\\.)*"|0x[0-9a-fA-F]+|\$(?=[0-9a-fA-F])[0-9a-fA-F]+|\d+|[A-Za-z_][A-Za-z0-9_]*(?:\.\d+)?' . '|\$==|\$!=|\$<=|\$>=|\$<>|\$\+|\$<|\$>|\$=|==|!=|<=|>=|<>|:=|\+=|-=|->|.)/s'; public static function isHuman(string $source): bool { return (bool) preg_match('/^\s*module\s+"/m', $source); } /** @return list */ private static function tokens(string $line): array { preg_match_all(self::TOKEN, $line, $m); return $m[0]; } // --- canonical -> human ------------------------------------------------------------------------------------- public static function toHuman(string $canonical): string { $script = preg_match('/^\s*script\s+"([^"]+)"/m', $canonical, $m) ? strtolower($m[1]) : ''; $lines = explode("\n", $canonical); // the labels that are routines (called, started, entry points) are named proc_, the others et_ $procs = []; foreach ($lines as $line) { if (preg_match_all('/\b(?:call|start|main|before|after)(?:\.\d+)?\s+(L[0-9a-f]{4,})\b/', $line, $mm)) { foreach ($mm[1] as $l) { $procs[$l] = true; } } } $names = new \ArrayObject(); // canonical variable => [name, prefix, offset text] $out = []; $blocks = []; foreach ($lines as $line) { $out[] = self::lineToHuman($line, $names, $procs, $script, $blocks); } // the declarations after the header (before the first blank line that follows it) if (count($names) > 0) { $decl = self::declarations($names); $at = 0; foreach ($out as $i => $l) { if (preg_match('/^\s*(module|numero|classe|memoire|compression|controle|specs|ressources|depart|avant|apres)\b/', $l)) { $at = $i + 1; } elseif ($at > 0 && trim($l) !== '' && !str_starts_with(ltrim($l), '//')) { break; } } array_splice($out, $at, 0, array_merge([''], $decl)); } return implode("\n", $out); } private static function lineToHuman(string $line, \ArrayObject $names, array $procs, string $script, array &$blocks): string { $indent = (string) preg_replace('/\S.*$/s', '', $line); $body = substr($line, strlen($indent)); // the blocks if ($body === '}') { return $indent . (array_pop($blocks) === 'while' ? 'fintantque' : 'finsi'); } if ($body === '} else {') { return $indent . 'sinon'; } $suffix = ''; if (preg_match('/^(if|while) (.*) \{$/s', $body, $m)) { $blocks[] = $m[1]; $body = $m[1] . ' ' . $m[2]; $suffix = $m[1] === 'if' ? ' alors' : ' faire'; } $t = self::tokens($body); $n = count($t); $o = ''; for ($i = 0; $i < $n; $i++) { $tok = $t[$i]; // a variable: prefix[...] (and &v[...] / &m[...]) $prefix = null; if (($tok === '&') && ($t[$i + 1] ?? '') !== '' && in_array($t[$i + 1], ['v', 'm'], true) && ($t[$i + 2] ?? '') === '[') { $prefix = '&' . $t[$i + 1]; $i++; } elseif (isset(self::KINDS[$tok]) && ($t[$i + 1] ?? '') === '[') { $prefix = $tok; } if ($prefix !== null) { $j = $i + 1; $inner = ''; for ($j = $i + 2; $j < $n && $t[$j] !== ']'; $j++) { $inner .= $t[$j]; } $canon = $prefix . '[' . $inner . ']'; $o .= self::nameOf($canon, $prefix, $inner, $names, $script); $i = $j; continue; } if (str_starts_with($tok, '//')) { $o .= self::COMMENTS[$tok] ?? $tok; continue; } if (str_starts_with($tok, '0x')) { $o .= '$' . substr($tok, 2); continue; } if (preg_match('/^[A-Za-z_]/', $tok)) { // z"..." / hex"...": literal prefixes if (($tok === 'z' || $tok === 'hex') && (($t[$i + 1] ?? '')[0] ?? '') === '"') { $o .= $tok; continue; } [$word, $size] = array_pad(explode('.', $tok, 2), 2, null); $o .= self::wordToHuman($word, $procs, $o) . ($size !== null ? '.' . $size : ''); continue; } $o .= self::OPERATORS[$tok] ?? $tok; } return $indent . $o . $suffix; } /** a word of the canonical form (a statement at the start of the line, a function, a label...) */ private static function wordToHuman(string $word, array $procs, string $before): string { $first = trim($before) === ''; if ($first && isset(self::DIRECTIVES[$word])) { return self::DIRECTIVES[$word]; } if (isset(self::CONTROL[$word])) { return self::CONTROL[$word]; } if (isset(self::OPERATORS[$word])) { return self::OPERATORS[$word]; } if (preg_match('/^L([0-9a-f]{4,})$/', $word, $m)) { return (isset($procs[$word]) ? 'proc_' : 'et_') . $m[1]; } if (isset(self::STATEMENTS[$word]) && ($first || str_ends_with(rtrim($before), 'echap1'))) { return self::STATEMENTS[$word]; } if (isset(self::FUNCTIONS[$word])) { return self::FUNCTIONS[$word]; } return $word; } private static function nameOf(string $canon, string $prefix, string $inner, \ArrayObject $names, string $script): string { // a variable forced to its long form (vb:loc[...]): kept as it is if (str_contains($inner, ':')) { return $canon; } if ($prefix[0] === 'h') { // another entity's: hb[0x54, 0x4c] = the entity whose number is the word at 0x54, its field at 0x4c [$ent, $field] = array_map('trim', explode(',', $inner, 2)) + [1 => '0x0']; $entName = self::nameOf("vw[$ent]", 'vw', $ent, $names, $script); $fieldName = self::declare($prefix . "[*, $field]", $prefix, $field, $names, $script); return $entName . '->' . $fieldName; } return self::declare($canon, $prefix, $inner, $names, $script); } private static function declare(string $key, string $prefix, string $off, \ArrayObject $names, string $script): string { if (!isset($names[$key])) { $name = self::KNOWN_LOCAL[$script][$key] ?? self::KNOWN[$key] ?? null; if ($name === null) { [$type, $scope] = self::KINDS[$prefix]; $hex = str_replace(['-0x', '0x'], ['m', ''], $off); $base = match (true) { $prefix[0] === 'h' => 'champ_' . str_replace(['champ ', ' '], ['', '_'], $type), $type === 'zone' => 'zone', default => str_replace(['tableau octets', 'tableau mots', 'tableau textes', 'adresses textes', ' '], ['octets', 'mots', 'textes', 'adr_textes', '_'], $type), }; $name = ($scope === 'global' ? 'g_' : '') . $base . '_' . $hex; } $names[$key] = [$name, $prefix, $off]; } return $names[$key][0]; } /** @return list */ private static function declarations(\ArrayObject $names): array { $rows = []; foreach ($names as [$name, $prefix, $off]) { [$type, $scope] = self::KINDS[$prefix]; $hex = preg_replace('/(-?)0x/', '$1$', $off); $rows[] = [($scope !== '' ? $scope . ' ' : '') . $type, $name, $hex, $prefix]; } usort($rows, static fn ($a, $b) => [$a[3][0] === 'h', $a[0], $a[1]] <=> [$b[3][0] === 'h', $b[0], $b[1]]); $w1 = max(array_map(static fn ($r) => strlen($r[0]), $rows)); $w2 = max(array_map(static fn ($r) => strlen($r[1]), $rows)); $out = ['variables']; foreach ($rows as [$kind, $name, $hex]) { $out[] = ' ' . str_pad($kind, $w1) . ' ' . str_pad($name, $w2) . ' @ ' . $hex; } $out[] = 'fin_variables'; return $out; } // --- human -> canonical ------------------------------------------------------------------------------------- /** @var list after toCanonical(): the human file's line (1-based) of each canonical line */ public static array $lines = []; public static function toCanonical(string $human): string { $lines = explode("\n", $human); $keepAt = []; // the declarations: name => canonical text $vars = []; $fields = []; $keep = []; $in = false; $start = null; foreach ($lines as $k => $line) { $tl = trim($line); if ($tl === 'variables') { $in = true; $start = $k; continue; } if ($in) { if ($tl === 'fin_variables') { $in = false; // the blank line the declarations were given if ($start > 0 && trim($lines[$start - 1]) === '') { array_pop($keep); array_pop($keepAt); } continue; } if (!preg_match('/^(local |global )?(.+?)\s+(\w+)\s+@\s+(-?)\$([0-9a-fA-F]+)$/', $tl, $m)) { throw new CompileError("variables: cannot read \"$tl\"", $k + 1); } $scope = trim($m[1]); $type = trim($m[2]); $off = $m[4] . '0x' . $m[5]; $prefix = self::prefixOf($type, $scope); if ($prefix === null) { throw new CompileError("variables: unknown kind \"$scope $type\"", $k + 1); } if ($prefix[0] === 'h') { $fields[$m[3]] = [$prefix, $off]; } elseif ($prefix[0] === '&') { $vars[$m[3]] = $prefix . '[' . $off . ']'; } else { $vars[$m[3]] = $prefix . '[' . $off . ']'; } continue; } $keep[] = $line; $keepAt[] = $k + 1; } self::$lines = $keepAt; $statements = array_flip(self::STATEMENTS); $control = array_flip(self::CONTROL); $directives = array_flip(self::DIRECTIVES); $functions = array_flip(self::FUNCTIONS); $operators = array_flip(self::OPERATORS); $comments = array_flip(self::COMMENTS); $out = []; $blocks = []; foreach ($keep as $line) { $indent = (string) preg_replace('/\S.*$/s', '', $line); $body = substr($line, strlen($indent)); if ($body === 'finsi' || $body === 'fintantque') { $out[] = $indent . '}'; continue; } if ($body === 'sinon') { $out[] = $indent . '} else {'; continue; } $suffix = ''; if (preg_match('/^(si|tantque) (.*) (alors|faire)$/s', $body, $m)) { $body = $m[1] . ' ' . $m[2]; $suffix = ' {'; } $t = self::tokens($body); $n = count($t); $o = ''; for ($i = 0; $i < $n; $i++) { $tok = $t[$i]; if (str_starts_with($tok, '//')) { $o .= $comments[$tok] ?? $tok; continue; } if ($tok[0] === '$' && strlen($tok) > 1 && ctype_xdigit(substr($tok, 1))) { $o .= '0x' . substr($tok, 1); continue; } if ($tok === '@' && isset($vars[$t[$i + 1] ?? ''])) { $o .= $vars[$t[++$i]]; continue; } if (preg_match('/^[A-Za-z_]/', $tok)) { if (($tok === 'z' || $tok === 'hex') && (($t[$i + 1] ?? '')[0] ?? '') === '"') { $o .= $tok; continue; } // another entity's field: ent->field if (($t[$i + 1] ?? '') === '->' && isset($fields[$t[$i + 2] ?? ''])) { $ent = $vars[$tok] ?? null; if ($ent === null || !preg_match('/^vw\[(.+)\]$/', $ent, $em)) { throw new CompileError("$tok->{$t[$i + 2]}: $tok is not a declared word"); } [$fp, $foff] = $fields[$t[$i + 2]]; $o .= $fp . '[' . $em[1] . ', ' . $foff . ']'; $i += 2; continue; } if (isset($vars[$tok])) { $o .= $vars[$tok]; continue; } [$word, $size] = array_pad(explode('.', $tok, 2), 2, null); $first = trim($o) === ''; $c = match (true) { $first && isset($directives[$word]) => $directives[$word], isset($control[$word]) => $control[$word], isset($operators[$word]) => $operators[$word], (bool) preg_match('/^(?:proc|et)_([0-9a-f]{4,})$/', $word, $lm) => 'L' . $lm[1], isset($statements[$word]) && ($first || str_ends_with(rtrim($o), 'esc1')) => $statements[$word], isset($functions[$word]) => $functions[$word], default => $word, }; $o .= $c . ($size !== null ? '.' . $size : ''); continue; } $o .= $operators[$tok] ?? $tok; } $out[] = $indent . $o . $suffix; } return implode("\n", $out); } /** A canonical line number (a compile error) -> the human file's. */ public static function humanLine(int $canonicalLine): int { return self::$lines[$canonicalLine - 1] ?? $canonicalLine; } /** Compiles any form (App\Alis\Lang\Assembler; Forms); errors give the line of the text given. */ public static function compile(string $source, callable $readFile): Script { if (Basic::isBasic($source)) { $canonical = Basic::toCanonical($source); try { return (new Assembler())->compile($canonical, $readFile); } catch (CompileError $e) { $line = Basic::basicLine($e->sourceLine); throw new CompileError(preg_replace('/^line \d+/', "line $line", $e->getMessage()), $line); } } if (!self::isHuman($source)) { return (new Assembler())->compile($source, $readFile); } $canonical = self::toCanonical($source); try { return (new Assembler())->compile($canonical, $readFile); } catch (CompileError $e) { $line = self::humanLine($e->sourceLine); throw new CompileError(preg_replace('/^line \d+/', "line $line", $e->getMessage()), $line); } } private static function prefixOf(string $type, string $scope): ?string { foreach (self::KINDS as $prefix => [$t, $s]) { if ($t === $type && $s === $scope) { return $prefix; } } return null; } }