@mintplayer/polyglot-target-php 0.10.0 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/polyglot-plugin.json +458 -154
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintplayer/polyglot-target-php",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "description": "MintPlayer Polyglot PHP target — a pure-JSON language plugin (spec + emission rules + capabilities + std bindings) for the polyglot transpiler.",
5
5
  "keywords": [
6
6
  "polyglot",
@@ -1,7 +1,21 @@
1
1
  {
2
- "schema": 1,
2
+ "schema": 2,
3
3
  "name": "php",
4
+ "preludePerFile": true,
5
+ "options": {
6
+ "namespace": {
7
+ "default": "",
8
+ "pattern": "^([A-Za-z_][A-Za-z0-9_]*(\\\\[A-Za-z_][A-Za-z0-9_]*)*)?$",
9
+ "scope": "closure"
10
+ }
11
+ },
12
+ "originMapping": {
13
+ "style": "sourceMapV3",
14
+ "sidecarExtension": ".map",
15
+ "footer": "// sourceMappingURL=$f"
16
+ },
4
17
  "capabilities": {
18
+ "utf16Strings:index": "emulated",
5
19
  "patternMatching": "native",
6
20
  "withExpressions": "native",
7
21
  "properties": "emulated",
@@ -33,6 +47,7 @@
33
47
  },
34
48
  "blockStyle": "bracesKnR",
35
49
  "stmtEnd": ";",
50
+ "operandSnapshot": "(${tmp} = {0})",
36
51
  "throwKeyword": "throw",
37
52
  "rethrow": "throw $__e;",
38
53
  "memberOp": "->",
@@ -40,6 +55,49 @@
40
55
  "trueLit": "true",
41
56
  "falseLit": "false",
42
57
  "nullLit": "null",
58
+ "nativeCoalesceAssign": true,
59
+ "assignmentOrder": "valueFirst",
60
+ "literals": {
61
+ "string": {
62
+ "quote": "\"",
63
+ "map": {
64
+ "\\": "\\\\",
65
+ "\"": "\\\"",
66
+ "\n": "\\n",
67
+ "\t": "\\t",
68
+ "\r": "\\r",
69
+ "$": "\\$"
70
+ },
71
+ "codepoint": "\\u{$H}",
72
+ "astral": "\\u{$H}"
73
+ },
74
+ "interp": {
75
+ "quote": "\"",
76
+ "map": {
77
+ "\\": "\\\\",
78
+ "\"": "\\\"",
79
+ "\n": "\\n",
80
+ "\t": "\\t",
81
+ "\r": "\\r",
82
+ "$": "\\$"
83
+ },
84
+ "codepoint": "\\u{$H}",
85
+ "astral": "\\u{$H}"
86
+ },
87
+ "char": {
88
+ "quote": "\"",
89
+ "map": {
90
+ "\\": "\\\\",
91
+ "\"": "\\\"",
92
+ "\n": "\\n",
93
+ "\t": "\\t",
94
+ "\r": "\\r",
95
+ "$": "\\$"
96
+ },
97
+ "codepoint": "\\u{$H}",
98
+ "astral": "\\u{$H}"
99
+ }
100
+ },
43
101
  "wrapInt": {
44
102
  "u8": "(($x) & 0xff)",
45
103
  "u16": "(($x) & 0xffff)",
@@ -49,14 +107,21 @@
49
107
  "i32": "(((($x) & 0xffffffff) ^ 0x80000000) - 0x80000000)"
50
108
  },
51
109
  "wrapAtom": {
52
- "recv": [
53
- "binary",
54
- "unary",
55
- "cond",
56
- "cast"
57
- ],
58
- "unary": [
59
- "binary"
110
+ "recvPrimary": [
111
+ "var",
112
+ "this",
113
+ "call",
114
+ "methodCall",
115
+ "member",
116
+ "index",
117
+ "str",
118
+ "char",
119
+ "bool",
120
+ "null",
121
+ "extern",
122
+ "nullAssert",
123
+ "tuple",
124
+ "makeCase"
60
125
  ]
61
126
  },
62
127
  "generics": {
@@ -64,7 +129,8 @@
64
129
  "boundsIntro": "",
65
130
  "boundsSep": "",
66
131
  "erase": [
67
- "INumber"
132
+ "INumber",
133
+ "IMapKey"
68
134
  ]
69
135
  },
70
136
  "tables": {
@@ -143,15 +209,36 @@
143
209
  "var",
144
210
  "while",
145
211
  "xor",
146
- "yield"
212
+ "yield",
213
+ "self",
214
+ "parent",
215
+ "int",
216
+ "float",
217
+ "bool",
218
+ "string",
219
+ "true",
220
+ "false",
221
+ "null",
222
+ "void",
223
+ "iterable",
224
+ "object",
225
+ "mixed",
226
+ "never",
227
+ "die",
228
+ "exit",
229
+ "eval",
230
+ "require_once",
231
+ "include_once",
232
+ "__halt_compiler"
147
233
  ],
234
+ "caseInsensitive": true,
148
235
  "escape": {
149
236
  "strategy": "suffix",
150
237
  "with": "_"
151
238
  },
152
239
  "mangle": {
153
240
  "replace": "$",
154
- "with": "_"
241
+ "with": "__"
155
242
  },
156
243
  "reserved": [
157
244
  "__e",
@@ -160,10 +247,29 @@
160
247
  "__opt*",
161
248
  "__w*"
162
249
  ],
250
+ "classBuiltins": [
251
+ "directory", "error", "generator", "closure", "exception", "errorexception", "typeerror", "valueerror",
252
+ "arithmeticerror", "divisionbyzeroerror", "argumentcounterror", "assertionerror", "compileerror", "parseerror",
253
+ "unhandledmatcherror", "throwable", "traversable", "iterator", "iteratoraggregate", "arrayaccess", "countable",
254
+ "stringable", "serializable", "jsonserializable", "arrayobject", "arrayiterator", "stdclass", "datetime",
255
+ "datetimeimmutable", "datetimeinterface", "datetimezone", "dateinterval", "dateperiod", "weakmap",
256
+ "weakreference", "fiber", "attribute", "unitenum", "backedenum", "splstack", "splqueue", "splobjectstorage",
257
+ "spldoublylinkedlist", "splfixedarray", "splheap", "splminheap", "splmaxheap", "splpriorityqueue",
258
+ "splsubject", "splobserver", "emptyiterator", "internaliterator", "runtimeexception", "logicexception",
259
+ "invalidargumentexception", "domainexception", "lengthexception", "outofrangeexception",
260
+ "outofboundsexception", "overflowexception", "rangeexception", "underflowexception",
261
+ "unexpectedvalueexception", "badfunctioncallexception", "badmethodcallexception"
262
+ ],
163
263
  "functionBuiltins": {
164
264
  "suffix": "_pg",
165
265
  "names": [
166
- "abs", "array_filter", "array_keys", "array_map", "array_merge",
266
+ "abs", "acos", "acosh", "array_key_exists", "array_key_first", "get_class", "is_object", "method_exists", "asin", "asinh", "atan", "atan2", "atanh",
267
+ "chr", "cosh", "fdiv", "file_exists", "file_get_contents", "file_put_contents", "fmod", "function_exists",
268
+ "iconv", "ini_set", "intdiv", "is_bool", "is_float", "is_infinite", "is_int", "is_nan", "is_string", "log10",
269
+ "ltrim", "pack", "preg_match", "preg_replace", "preg_replace_callback", "preg_split", "rtrim", "sinh",
270
+ "str_contains", "str_ends_with", "str_repeat", "str_replace", "str_starts_with", "strcmp", "strpos",
271
+ "strtolower", "strtoupper", "strtr", "tanh", "unlink", "unpack", "var_export",
272
+ "array_filter", "array_keys", "array_map", "array_merge",
167
273
  "array_pop", "array_push", "array_reverse", "array_shift", "array_slice",
168
274
  "array_splice", "array_values", "assert", "ceil", "compact", "cos", "count",
169
275
  "current", "date", "die", "each", "end", "eval", "exit",
@@ -176,7 +282,15 @@
176
282
  ]
177
283
  }
178
284
  },
179
- "preludes": {}
285
+ "preludes": {
286
+ "pgUeq": "if (!function_exists(__NAMESPACE__.'\\\\__pg_ueq')) {\n // a union value (a tagged array) compared as C# compares its generated case records (review r5): a record\n // payload by its equals(), a nested union recursively, anything else (a scalar, a class instance, a list) by ===\n function __pg_ueq($a, $b) {\n if (is_array($a)) {\n if (!is_array($b) || count($a) !== count($b)) {\n return false;\n }\n foreach ($a as $k => $v) {\n if (!array_key_exists($k, $b) || !__pg_ueq($v, $b[$k])) {\n return false;\n }\n }\n return true;\n }\n if (is_object($a) && is_object($b) && get_class($a) === get_class($b) && method_exists($a, 'equals')) {\n return $a->equals($b);\n }\n return $a === $b;\n }\n}\n",
287
+ "pgU64": "if (!function_exists(__NAMESPACE__.'\\\\__pg_u64parse')) {\n // a u64 above PHP_INT_MAX has no PHP int: refuse it loudly instead of clamping (SPEC 3.C PHP caveat)\n function __pg_u64parse($s) {\n $d = ltrim(ltrim($s, '+'), '0');\n if (strlen($d) > 19 || (strlen($d) === 19 && strcmp($d, '9223372036854775807') > 0)) {\n throw new \\Error(\"u64.parse: '\" . $s . \"' exceeds PHP's 63-bit integer range\");\n }\n return intval($s);\n }\n}\n",
288
+ "pgU16": "if (!function_exists(__NAMESPACE__.'\\\\__pg_u16')) {\n // UTF-16 code-unit indexing over PHP's UTF-8 strings (P40 B3, D15: needs ext-iconv). An ASCII string is\n // its own UTF-16 index space (fast path); any other is indexed through a cached UTF-16LE copy.\n function __pg_u16($s) {\n // null when ASCII, else the UTF-16LE copy. A short string is just recomputed; a long one is cached\n // (the last one, plus a small LRU), so indexing a long string in a loop is O(1) per call.\n static $ks = null, $kv = null, $lru = [];\n if ($ks === $s) {\n return $kv;\n }\n if (strlen($s) < 256) {\n return preg_match('/[\\x80-\\xFF]/', $s) ? __pg_u16le($s) : null;\n }\n if (array_key_exists($s, $lru)) {\n $v = $lru[$s];\n unset($lru[$s]);\n } else {\n $v = preg_match('/[\\x80-\\xFF]/', $s) ? __pg_u16le($s) : null;\n if (count($lru) >= 8) {\n unset($lru[array_key_first($lru)]);\n }\n }\n $lru[$s] = $v;\n $ks = $s;\n $kv = $v;\n return $v;\n }\n function __pg_u16le($s) {\n if (!function_exists('iconv')) {\n throw new \\Error('Polyglot: the PHP target needs the iconv extension (ext-iconv) for non-ASCII strings');\n }\n $r = @iconv('UTF-8', 'UTF-16LE', $s);\n if ($r !== false) {\n return $r;\n }\n // not valid UTF-8: a lone surrogate a substring split off (held as WTF-8) \u2014 decode by hand\n $out = '';\n $n = strlen($s);\n for ($i = 0; $i < $n;) {\n $b = ord($s[$i]);\n if ($b < 0x80) {\n $c = $b;\n $i += 1;\n } elseif ($b < 0xE0) {\n $c = (($b & 0x1F) << 6) | (ord($s[$i + 1]) & 0x3F);\n $i += 2;\n } elseif ($b < 0xF0) {\n $c = (($b & 0x0F) << 12) | ((ord($s[$i + 1]) & 0x3F) << 6) | (ord($s[$i + 2]) & 0x3F);\n $i += 3;\n } else {\n $c = (($b & 0x07) << 18) | ((ord($s[$i + 1]) & 0x3F) << 12) | ((ord($s[$i + 2]) & 0x3F) << 6) | (ord($s[$i + 3]) & 0x3F);\n $i += 4;\n }\n if ($c >= 0x10000) {\n $c -= 0x10000;\n $out .= pack('v2', 0xD800 + ($c >> 10), 0xDC00 + ($c & 0x3FF));\n } else {\n $out .= pack('v', $c);\n }\n }\n return $out;\n }\n function __pg_u16_unit8($c) {\n if ($c < 0x80) {\n return chr($c);\n }\n if ($c < 0x800) {\n return chr(0xC0 | ($c >> 6)) . chr(0x80 | ($c & 0x3F));\n }\n return chr(0xE0 | ($c >> 12)) . chr(0x80 | (($c >> 6) & 0x3F)) . chr(0x80 | ($c & 0x3F));\n }\n function __pg_u16_to8($u) {\n $r = @iconv('UTF-16LE', 'UTF-8', $u);\n if ($r !== false) {\n return $r;\n }\n $out = '';\n $n = strlen($u);\n for ($i = 0; $i < $n; $i += 2) {\n $c = ord($u[$i]) | (ord($u[$i + 1]) << 8);\n if ($c >= 0xD800 && $c <= 0xDBFF && $i + 3 < $n) {\n $d = ord($u[$i + 2]) | (ord($u[$i + 3]) << 8);\n if ($d >= 0xDC00 && $d <= 0xDFFF) {\n $c = 0x10000 + (($c - 0xD800) << 10) + ($d - 0xDC00);\n $out .= chr(0xF0 | ($c >> 18)) . chr(0x80 | (($c >> 12) & 0x3F)) . chr(0x80 | (($c >> 6) & 0x3F)) . chr(0x80 | ($c & 0x3F));\n $i += 2;\n continue;\n }\n }\n $out .= __pg_u16_unit8($c);\n }\n return $out;\n }\n function __pg_len16($s) {\n $v = __pg_u16($s);\n return $v === null ? strlen($s) : strlen($v) >> 1;\n }\n function __pg_u16_char($s, $i) {\n $v = __pg_u16($s);\n return $v === null ? $s[$i] : __pg_u16_unit8(ord($v[2 * $i]) | (ord($v[2 * $i + 1]) << 8));\n }\n function __pg_u16_cp($s, $i) {\n $v = __pg_u16($s);\n if ($v === null) {\n return ord($s[$i]);\n }\n $c = ord($v[2 * $i]) | (ord($v[2 * $i + 1]) << 8);\n if ($c >= 0xD800 && $c <= 0xDBFF && 2 * $i + 3 < strlen($v)) {\n $d = ord($v[2 * $i + 2]) | (ord($v[2 * $i + 3]) << 8);\n if ($d >= 0xDC00 && $d <= 0xDFFF) {\n return 0x10000 + (($c - 0xD800) << 10) + ($d - 0xDC00);\n }\n }\n return $c;\n }\n function __pg_u16_sub($s, $a, $b) {\n $v = __pg_u16($s);\n return $v === null ? substr($s, $a, $b - $a) : __pg_u16_to8(substr($v, 2 * $a, 2 * ($b - $a)));\n }\n function __pg_u16_find($s, $n, $f) {\n static $kn = null, $kascii = true, $kv = '';\n if ($kn !== $n) {\n $kascii = !preg_match('/[\\x80-\\xFF]/', $n);\n $kv = null;\n $kn = $n;\n }\n $v = __pg_u16($s);\n if ($v === null) {\n if (!$kascii) {\n return -1;\n }\n $p = strpos($s, $n, $f);\n return $p === false ? -1 : $p;\n }\n if ($kv === null) {\n $kv = __pg_u16le($n); // the needle is reconverted only when it changes\n }\n $p = 2 * $f;\n while (($p = strpos($v, $kv, $p)) !== false) {\n if (($p & 1) === 0) {\n return $p >> 1;\n }\n $p++;\n }\n return -1;\n }\n function __pg_cmp16($a, $b) {\n if (preg_match('/[\\x80-\\xFF]/', $a) || preg_match('/[\\x80-\\xFF]/', $b)) {\n // UTF-16BE bytes order exactly as UTF-16 code units do (UTF-8 bytes order as code points)\n $a = $a === '' ? '' : pack('n*', ...unpack('v*', __pg_u16le($a)));\n $b = $b === '' ? '' : pack('n*', ...unpack('v*', __pg_u16le($b)));\n }\n $r = strcmp($a, $b);\n return $r < 0 ? -1 : ($r > 0 ? 1 : 0);\n }\n function __pg_u16_lone(...$xs) {\n // a lone surrogate (held as WTF-8, ED A0-BF ..) only matches like C#/TS in the UTF-16 view; without\n // one, the UTF-8 byte answer is the UTF-16 answer\n foreach ($xs as $x) {\n if (preg_match('/\\xED[\\xA0-\\xBF]/', $x)) {\n return true;\n }\n }\n return false;\n }\n function __pg_u16_has($s, $n) {\n return __pg_u16_lone($s, $n) ? __pg_u16_find($s, $n, 0) !== -1 : str_contains($s, $n);\n }\n function __pg_u16_starts($s, $p) {\n return __pg_u16_lone($s, $p) ? str_starts_with(__pg_u16le($s), __pg_u16le($p)) : str_starts_with($s, $p);\n }\n function __pg_u16_ends($s, $p) {\n return __pg_u16_lone($s, $p) ? str_ends_with(__pg_u16le($s), __pg_u16le($p)) : str_ends_with($s, $p);\n }\n function __pg_u16_pieces($s, $sep) {\n // the UTF-16LE pieces of $s around $sep, matching only at unit-aligned (even) offsets\n $v = __pg_u16le($s);\n $k = __pg_u16le($sep);\n $kl = strlen($k);\n $out = [];\n $from = 0;\n $p = 0;\n while (($p = strpos($v, $k, $p)) !== false) {\n if (($p & 1) === 0) {\n $out[] = substr($v, $from, $p - $from);\n $p += $kl;\n $from = $p;\n } else {\n $p++;\n }\n }\n $out[] = substr($v, $from);\n return $out;\n }\n function __pg_u16_replace($s, $n, $r) {\n if (!__pg_u16_lone($s, $n, $r)) {\n return str_replace($n, $r, $s);\n }\n return __pg_u16_to8(implode(__pg_u16le($r), __pg_u16_pieces($s, $n)));\n }\n function __pg_u16_split($s, $sep) {\n if (!__pg_u16_lone($s, $sep)) {\n return explode($sep, $s);\n }\n return array_map(fn($u) => __pg_u16_to8($u),__pg_u16_pieces($s, $sep));\n }\n}\n",
289
+ "pgChr8": "if (!function_exists(__NAMESPACE__.'\\\\__pg_chr8')) {\n // a Unicode scalar value -> UTF-8 (string.fromCodePoint; no mbstring needed, S17)\n function __pg_chr8($c) {\n if ($c < 0x80) {\n return chr($c);\n }\n if ($c < 0x800) {\n return chr(0xC0 | ($c >> 6)) . chr(0x80 | ($c & 0x3F));\n }\n if ($c < 0x10000) {\n return chr(0xE0 | ($c >> 12)) . chr(0x80 | (($c >> 6) & 0x3F)) . chr(0x80 | ($c & 0x3F));\n }\n return chr(0xF0 | ($c >> 18)) . chr(0x80 | (($c >> 12) & 0x3F)) . chr(0x80 | (($c >> 6) & 0x3F)) . chr(0x80 | ($c & 0x3F));\n }\n}\n",
290
+ "pgMap": "if (!function_exists(__NAMESPACE__.'\\\\__pg_mk')) {\n // Map<K, V> over \\ArrayObject (P40 B4). A PHP array turns the string key \"10\" into the int 10, so string\n // keys are stored prefixed with \"s\" and stripped again by keys(); integer keys are stored as they are.\n function __pg_mk($k) {\n return is_int($k) ? $k : \"s\" . $k;\n }\n function __pg_mget($m, $k) {\n $k = __pg_mk($k);\n return $m->offsetExists($k) ? $m[$k] : null;\n }\n function __pg_mdel($m, $k) {\n $k = __pg_mk($k);\n if (!$m->offsetExists($k)) {\n return false;\n }\n $m->offsetUnset($k);\n return true;\n }\n function __pg_mkeys($m) {\n $r = [];\n foreach ($m as $k => $v) {\n $r[] = is_int($k) ? $k : substr($k, 1);\n }\n return new \\ArrayObject($r);\n }\n}\n",
291
+ "pgNn": "if (!function_exists(__NAMESPACE__.'\\\\__pg_nn')) {\n function __pg_nn($v, $at) {\n if ($v === null) {\n throw new \\UnexpectedValueException(\"null-assert failed (\" . $at . \")\");\n }\n return $v;\n }\n}\n",
292
+ "pgStr": "if (!function_exists(__NAMESPACE__.'\\\\__pg_str')) {\n function __pg_str($x) {\n if ($x === null) {\n return \"null\";\n }\n if (is_bool($x)) {\n return $x ? \"true\" : \"false\";\n }\n if (is_string($x)) {\n if (preg_match('//u', $x)) {\n return $x;\n }\n $x = preg_replace_callback('/\\xED([\\xA0-\\xAF])([\\x80-\\xBF])\\xED([\\xB0-\\xBF])([\\x80-\\xBF])/', function ($m) {\n $c = 0x10000 + ((((ord($m[1]) & 0x0F) << 6) | (ord($m[2]) & 0x3F)) << 10) + ((((ord($m[3]) & 0x0F) << 6) | (ord($m[4]) & 0x3F)));\n return chr(0xF0 | ($c >> 18)) . chr(0x80 | (($c >> 12) & 0x3F)) . chr(0x80 | (($c >> 6) & 0x3F)) . chr(0x80 | ($c & 0x3F));\n }, $x);\n return preg_replace('/\\xED[\\xA0-\\xBF][\\x80-\\xBF]/', \"\\u{FFFD}\", $x);\n }\n if (!is_float($x)) {\n return (string)$x;\n }\n if (is_nan($x)) {\n return \"NaN\";\n }\n if (is_infinite($x)) {\n return $x > 0 ? \"Infinity\" : \"-Infinity\";\n }\n if ($x == 0.0) {\n return \"0\";\n }\n $old = ini_set('serialize_precision', '-1');\n $s = var_export($x, true);\n if ($old !== false) {\n ini_set('serialize_precision', $old);\n }\n $neg = $s[0] === '-';\n if ($neg) {\n $s = substr($s, 1);\n }\n $p = strpos($s, 'E');\n $m = $p === false ? $s : substr($s, 0, $p);\n $e = $p === false ? 0 : (int)substr($s, $p + 1);\n $dot = strpos($m, '.');\n $i = $dot === false ? $m : substr($m, 0, $dot);\n $f = $dot === false ? '' : substr($m, $dot + 1);\n $d = ltrim($i . $f, '0');\n $n = strlen($i) + $e - (strlen($i) + strlen($f) - strlen($d));\n $d = rtrim($d, '0');\n $k = strlen($d);\n if ($k <= $n && $n <= 21) {\n $r = $d . str_repeat('0', $n - $k);\n } elseif (0 < $n && $n <= 21) {\n $r = substr($d, 0, $n) . '.' . substr($d, $n);\n } elseif (-6 < $n && $n <= 0) {\n $r = '0.' . str_repeat('0', -$n) . $d;\n } else {\n $r = $d[0] . ($k > 1 ? '.' . substr($d, 1) : '') . 'e' . ($n >= 1 ? '+' : '-') . abs($n - 1);\n }\n return $neg ? '-' . $r : $r;\n }\n}\n"
293
+ }
180
294
  },
181
295
  "std": {
182
296
  "std.collections": {
@@ -186,10 +300,19 @@
186
300
  "List.add": "$this[] = $0",
187
301
  "List.clear": "$this->exchangeArray([])",
188
302
  "List.removeAll": "$this->exchangeArray(array_values(array_filter($this->getArrayCopy(), fn($__e) => !(($0)($__e)))))",
189
- "List.removeAt": "$this->exchangeArray((function ($__a, $__i) { array_splice($__a, $__i, 1); return $__a; })($this->getArrayCopy(), $0))"
303
+ "List.removeAt": "$this->exchangeArray((function ($__a, $__i) { array_splice($__a, $__i, 1); return $__a; })($this->getArrayCopy(), $0))",
304
+ "Map.type": "\\ArrayObject",
305
+ "Map.constructor": "new \\ArrayObject([])",
306
+ "Map.count": "count($this)",
307
+ "Map.get": { "template": "__pg_mget($this, $0)", "requires": ["pgMap"] },
308
+ "Map.set": { "template": "$this[__pg_mk($0)] = $1", "requires": ["pgMap"] },
309
+ "Map.has": { "template": "$this->offsetExists(__pg_mk($0))", "requires": ["pgMap"] },
310
+ "Map.remove": { "template": "__pg_mdel($this, $0)", "requires": ["pgMap"] },
311
+ "Map.keys": { "template": "__pg_mkeys($this)", "requires": ["pgMap"] },
312
+ "Map.values": "new \\ArrayObject(array_values($this->getArrayCopy()))"
190
313
  },
191
314
  "std.io": {
192
- "print": "echo is_bool($x) ? ($x ? \"true\" : \"false\") : $x, \"\\n\"",
315
+ "print": { "template": "echo __pg_str($x), \"\\n\"", "requires": ["pgStr"] },
193
316
  "readText": "file_get_contents($path)",
194
317
  "writeText": "file_put_contents($path, $content)",
195
318
  "appendText": "file_put_contents($path, $content, FILE_APPEND)",
@@ -198,13 +321,24 @@
198
321
  },
199
322
  "std.strings": {
200
323
  "string.isEmpty": "($this === '')",
201
- "string.len": "strlen($this)",
324
+ "string.len": { "template": "__pg_len16($this)", "requires": ["pgU16"] },
202
325
  "string.toUpper": "strtoupper($this)",
203
326
  "string.toLower": "strtolower($this)",
204
- "string.charAt": "substr($this, $0, 1)",
205
- "string.codePointAt": "ord(substr($this, $0, 1))",
206
- "string.codePoints": "str_split($this)",
207
- "string.toI32": "intval($this)"
327
+ "string.toUpperAscii": "strtr($this, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')",
328
+ "string.toLowerAscii": "strtr($this, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')",
329
+ "string.codePoints": "preg_split('//u', $this, -1, PREG_SPLIT_NO_EMPTY)",
330
+ "string.startsWith": { "template": "__pg_u16_starts($this, $0)", "requires": ["pgU16"] },
331
+ "string.endsWith": { "template": "__pg_u16_ends($this, $0)", "requires": ["pgU16"] },
332
+ "string.contains": { "template": "__pg_u16_has($this, $0)", "requires": ["pgU16"] },
333
+ "string.trimAscii": "trim($this, \" \\t\\n\\x0B\\x0C\\r\")",
334
+ "compareOrdinal": { "template": "__pg_cmp16($a, $b)", "requires": ["pgU16"] },
335
+ "string.__pgCharAt": { "template": "__pg_u16_char($this, $0)", "requires": ["pgU16"] },
336
+ "string.__pgCodePointAt": { "template": "__pg_u16_cp($this, $0)", "requires": ["pgU16"] },
337
+ "string.__pgSubstring": { "template": "__pg_u16_sub($this, $0, $1)", "requires": ["pgU16"] },
338
+ "string.__pgIndexOf": { "template": "__pg_u16_find($this, $0, $1)", "requires": ["pgU16"] },
339
+ "string.__pgReplaceAll": { "template": "__pg_u16_replace($this, $0, $1)", "requires": ["pgU16"] },
340
+ "string.__pgSplit": { "template": "new \\ArrayObject(__pg_u16_split($this, $0))", "requires": ["pgU16"] },
341
+ "string.__pgFromCodePoint": { "template": "__pg_chr8($0)", "requires": ["pgChr8"] }
208
342
  },
209
343
  "std.core": {
210
344
  "Error.type": "\\Exception",
@@ -214,21 +348,24 @@
214
348
  "Array.type": "\\ArrayObject",
215
349
  "Array.constructor": "new \\ArrayObject()",
216
350
  "Array.count": "count($this)",
217
- "i8.parse": "intval($0)",
218
- "i16.parse": "intval($0)",
219
- "i32.parse": "intval($0)",
220
- "i64.parse": "intval($0)",
221
- "u8.parse": "intval($0)",
222
- "u16.parse": "intval($0)",
223
- "u32.parse": "intval($0)",
224
- "u64.parse": "intval($0)",
225
- "f32.parse": "floatval($0)",
226
- "f64.parse": "floatval($0)"
351
+ "__pgText.rawLen": "strlen($0)",
352
+ "__pgText.rawCode": "ord($0[$1])",
353
+ "i8.__pgParse": "intval($0)",
354
+ "i16.__pgParse": "intval($0)",
355
+ "i32.__pgParse": "intval($0)",
356
+ "i64.__pgParse": "intval($0)",
357
+ "u8.__pgParse": "intval($0)",
358
+ "u16.__pgParse": "intval($0)",
359
+ "u32.__pgParse": "intval($0)",
360
+ "u64.__pgParse": { "template": "__pg_u64parse($0)", "requires": ["pgU64"] },
361
+ "f32.__pgParse": "unpack('g', pack('g', floatval($0)))[1]",
362
+ "f64.__pgParse": "floatval($0)"
227
363
  },
228
364
  "std.math": {
229
365
  "Math.PI": "M_PI",
230
366
  "Math.E": "M_E",
231
367
  "Math.sqrt": "sqrt($0)",
368
+ "Math.isNaN": "is_nan($0)",
232
369
  "Math.ln": "log($0)",
233
370
  "Math.log": "log($0)",
234
371
  "Math.log2": "log($0, 2)",
@@ -264,7 +401,7 @@
264
401
  "get": "node.text"
265
402
  },
266
403
  "Float": {
267
- "get": "node.text"
404
+ "get": "node.widenedText"
268
405
  },
269
406
  "Bool": {
270
407
  "case": {
@@ -284,33 +421,45 @@
284
421
  },
285
422
  "Null": "null",
286
423
  "Str": {
287
- "fn": "escapeString",
424
+ "fn": "quoted",
288
425
  "args": [
426
+ "string",
289
427
  {
290
428
  "get": "node.value"
291
429
  }
292
430
  ]
293
431
  },
294
432
  "Char": {
295
- "fn": "escapeString",
433
+ "fn": "quoted",
296
434
  "args": [
435
+ "char",
297
436
  {
298
437
  "get": "node.value"
299
438
  }
300
439
  ]
301
440
  },
302
441
  "Var": {
303
- "tmpl": [
304
- "$",
305
- {
306
- "fn": "ident",
307
- "args": [
442
+ "case": {
443
+ "when": [
444
+ [
445
+ { "eq": ["node.liveModuleRead", "true"] },
446
+ { "tmpl": ["$GLOBALS['", { "fn": "ident", "args": [ { "get": "node.name" } ] }, "']"] }
447
+ ]
448
+ ],
449
+ "else": {
450
+ "tmpl": [
451
+ "$",
308
452
  {
309
- "get": "node.name"
453
+ "fn": "ident",
454
+ "args": [
455
+ {
456
+ "get": "node.name"
457
+ }
458
+ ]
310
459
  }
311
460
  ]
312
461
  }
313
- ]
462
+ }
314
463
  },
315
464
  "This": "$this",
316
465
  "Extern": {
@@ -321,6 +470,14 @@
321
470
  {
322
471
  "case": {
323
472
  "when": [
473
+ [
474
+ { "eq": ["node.calleeKind", "member"] },
475
+ { "tmpl": ["(", { "emit": "node.calleeExpr" }, ")"] }
476
+ ],
477
+ [
478
+ { "has": "node.hasCalleeExpr" },
479
+ { "emitChild": "node.calleeExpr", "side": "recv" }
480
+ ],
324
481
  [
325
482
  { "eq": ["node.isFree", "true"] },
326
483
  {
@@ -333,7 +490,7 @@
333
490
  "fn": "identFn",
334
491
  "args": [
335
492
  {
336
- "get": "node.mangledCallee"
493
+ "get": "node.uniqueCallee"
337
494
  }
338
495
  ]
339
496
  }
@@ -363,12 +520,12 @@
363
520
  }
364
521
  }
365
522
  },
366
- "(",
367
523
  {
368
- "map": "node.args",
369
- "sep": ", "
370
- },
371
- ")"
524
+ "case": {
525
+ "when": [[ { "eq": ["node.isRef", "true"] }, "(...)" ]],
526
+ "else": { "tmpl": [ "(", { "map": "node.args", "sep": ", " }, ")" ] }
527
+ }
528
+ }
372
529
  ]
373
530
  },
374
531
  "Member": {
@@ -382,10 +539,20 @@
382
539
  },
383
540
  {
384
541
  "tmpl": [
385
- {
542
+ { "fn": "identType", "args": [ {
386
543
  "get": "node.staticType"
387
- },
388
- "::"
544
+ } ] },
545
+ "::",
546
+ { "case": { "when": [ [
547
+ { "and": [
548
+ { "eq": ["node.staticField", "true"] },
549
+ { "not": { "and": [
550
+ { "eq": ["node.staticFieldMutable", "false"] },
551
+ { "eq": ["node.staticFieldInitIsLiteral", "true"] }
552
+ ] } }
553
+ ] },
554
+ "$"
555
+ ] ] } }
389
556
  ]
390
557
  }
391
558
  ]
@@ -453,14 +620,7 @@
453
620
  },
454
621
  {
455
622
  "tmpl": [
456
- {
457
- "fn": "ident",
458
- "args": [
459
- {
460
- "get": "node.method"
461
- }
462
- ]
463
- },
623
+ { "fn": "mangleName", "args": [ { "fn": "ident", "args": [ { "get": "node.freeName" } ] } ] },
464
624
  "(",
465
625
  {
466
626
  "emit": "node.object"
@@ -499,9 +659,9 @@
499
659
  },
500
660
  {
501
661
  "tmpl": [
502
- {
662
+ { "fn": "identType", "args": [ {
503
663
  "get": "node.staticType"
504
- },
664
+ } ] },
505
665
  "::",
506
666
  {
507
667
  "fn": "ident",
@@ -719,7 +879,7 @@
719
879
  "tmpl": [
720
880
  "new ",
721
881
  {
722
- "fn": "ident",
882
+ "fn": "identType",
723
883
  "args": [
724
884
  {
725
885
  "get": "node.typeName"
@@ -741,6 +901,26 @@
741
901
  { "type": "node.testType" }
742
902
  ]
743
903
  },
904
+ "NullAssert": {
905
+ "case": {
906
+ "when": [
907
+ [
908
+ { "eq": ["node.isFail", "true"] },
909
+ { "tmpl": ["throw new \\UnexpectedValueException(", { "fn": "quoted", "args": ["string", { "get": "node.message" }] }, ")"] }
910
+ ]
911
+ ],
912
+ "else": {
913
+ "tmpl": [
914
+ { "fn": "require", "args": ["pgNn"] },
915
+ "__pg_nn(",
916
+ { "emit": "node.operand" },
917
+ ", ",
918
+ { "fn": "quoted", "args": ["string", { "get": "node.where" }] },
919
+ ")"
920
+ ]
921
+ }
922
+ }
923
+ },
744
924
  "AsCast": {
745
925
  "case": {
746
926
  "when": [
@@ -777,6 +957,10 @@
777
957
  "Unary": {
778
958
  "case": {
779
959
  "when": [
960
+ [
961
+ { "eq": ["node.negatesInt64Min", "true"] },
962
+ "PHP_INT_MIN"
963
+ ],
780
964
  [
781
965
  {
782
966
  "and": [
@@ -945,8 +1129,9 @@
945
1129
  "lits": "node.chunks",
946
1130
  "holes": "node.holes",
947
1131
  "lit": {
948
- "fn": "escapeString",
1132
+ "fn": "quoted",
949
1133
  "args": [
1134
+ "interp",
950
1135
  {
951
1136
  "get": "item"
952
1137
  }
@@ -971,11 +1156,30 @@
971
1156
  ") ? \"true\" : \"false\") . "
972
1157
  ]
973
1158
  }
1159
+ ],
1160
+ [
1161
+ {
1162
+ "or": [
1163
+ { "eq": ["item.typeIsInt", "true"] },
1164
+ { "eq": ["item.typeIsString", "true"] },
1165
+ { "eq": ["item.typeIsChar", "true"] }
1166
+ ]
1167
+ },
1168
+ {
1169
+ "tmpl": [
1170
+ " . (",
1171
+ {
1172
+ "emit": "item"
1173
+ },
1174
+ ") . "
1175
+ ]
1176
+ }
974
1177
  ]
975
1178
  ],
976
1179
  "else": {
977
1180
  "tmpl": [
978
- " . (",
1181
+ { "fn": "require", "args": ["pgStr"] },
1182
+ " . __pg_str(",
979
1183
  {
980
1184
  "emit": "item"
981
1185
  },
@@ -992,6 +1196,19 @@
992
1196
  "Binary": {
993
1197
  "case": {
994
1198
  "when": [
1199
+ [
1200
+ {
1201
+ "and": [
1202
+ { "or": [ { "eq": [ "node.op", "==" ] }, { "eq": [ "node.op", "!=" ] } ] },
1203
+ { "eq": [ "node.lhsIsUnion", "true" ] }
1204
+ ]
1205
+ },
1206
+ { "tmpl": [
1207
+ { "fn": "require", "args": ["pgUeq"] },
1208
+ { "case": { "when": [ [ { "eq": [ "node.op", "!=" ] }, "!" ] ] } },
1209
+ "__pg_ueq(", { "emit": "node.lhs" }, ", ", { "emit": "node.rhs" }, ")"
1210
+ ] }
1211
+ ],
995
1212
  [
996
1213
  {
997
1214
  "and": [
@@ -1161,6 +1378,10 @@
1161
1378
  ]
1162
1379
  }
1163
1380
  ],
1381
+ [
1382
+ { "and": [ { "eq": ["node.typeIsFloat", "true"] }, { "eq": ["node.op", "/"] } ] },
1383
+ { "tmpl": [ "fdiv(", { "emit": "node.lhs" }, ", ", { "emit": "node.rhs" }, ")" ] }
1384
+ ],
1164
1385
  [
1165
1386
  {
1166
1387
  "and": [
@@ -1453,7 +1674,10 @@
1453
1674
  "tmpl": [
1454
1675
  " && $__e instanceof ",
1455
1676
  {
1456
- "type": "item.type"
1677
+ "case": {
1678
+ "when": [[{ "eq": ["item.typeName", "Error"] }, "\\Throwable"]],
1679
+ "else": { "type": "item.type" }
1680
+ }
1457
1681
  }
1458
1682
  ]
1459
1683
  }
@@ -1576,6 +1800,15 @@
1576
1800
  {
1577
1801
  "case": {
1578
1802
  "when": [
1803
+ [
1804
+ {
1805
+ "eq": [
1806
+ "item.typeName",
1807
+ "Error"
1808
+ ]
1809
+ },
1810
+ "\\Throwable"
1811
+ ],
1579
1812
  [
1580
1813
  {
1581
1814
  "eq": [
@@ -1587,7 +1820,8 @@
1587
1820
  "type": "item.type"
1588
1821
  }
1589
1822
  ]
1590
- ]
1823
+ ],
1824
+ "else": "\\Throwable"
1591
1825
  }
1592
1826
  },
1593
1827
  " $__e)"
@@ -1663,8 +1897,9 @@
1663
1897
  "tmpl": [
1664
1898
  "[\"tag\" => ",
1665
1899
  {
1666
- "fn": "escapeString",
1900
+ "fn": "quoted",
1667
1901
  "args": [
1902
+ "string",
1668
1903
  {
1669
1904
  "get": "node.caseName"
1670
1905
  }
@@ -1677,8 +1912,9 @@
1677
1912
  "tmpl": [
1678
1913
  ", ",
1679
1914
  {
1680
- "fn": "escapeString",
1915
+ "fn": "quoted",
1681
1916
  "args": [
1917
+ "string",
1682
1918
  {
1683
1919
  "get": "item.name"
1684
1920
  }
@@ -1869,8 +2105,9 @@
1869
2105
  "tmpl": [
1870
2106
  "$_m[",
1871
2107
  {
1872
- "fn": "escapeString",
2108
+ "fn": "quoted",
1873
2109
  "args": [
2110
+ "string",
1874
2111
  {
1875
2112
  "get": "item.field"
1876
2113
  }
@@ -2024,8 +2261,9 @@
2024
2261
  "tmpl": [
2025
2262
  "$_m[",
2026
2263
  {
2027
- "fn": "escapeString",
2264
+ "fn": "quoted",
2028
2265
  "args": [
2266
+ "string",
2029
2267
  {
2030
2268
  "get": "item.field"
2031
2269
  }
@@ -2062,6 +2300,10 @@
2062
2300
  ]
2063
2301
  }
2064
2302
  ],
2303
+ [
2304
+ { "eq": ["item.pattern.isNullLiteral", "true"] },
2305
+ { "tmpl": ["$_m === null"] }
2306
+ ],
2065
2307
  [
2066
2308
  {
2067
2309
  "eq": [
@@ -2071,7 +2313,7 @@
2071
2313
  },
2072
2314
  {
2073
2315
  "tmpl": [
2074
- "$_m == ",
2316
+ "$_m === ",
2075
2317
  {
2076
2318
  "emit": "item.pattern.literal"
2077
2319
  }
@@ -2087,7 +2329,7 @@
2087
2329
  },
2088
2330
  {
2089
2331
  "tmpl": [
2090
- "$_m == ",
2332
+ "$_m === ",
2091
2333
  {
2092
2334
  "get": "item.pattern.enumType"
2093
2335
  },
@@ -2107,10 +2349,11 @@
2107
2349
  },
2108
2350
  {
2109
2351
  "tmpl": [
2110
- "$_m[\"tag\"] == ",
2352
+ "$_m[\"tag\"] === ",
2111
2353
  {
2112
- "fn": "escapeString",
2354
+ "fn": "quoted",
2113
2355
  "args": [
2356
+ "string",
2114
2357
  {
2115
2358
  "get": "item.pattern.ctorCase"
2116
2359
  }
@@ -2133,8 +2376,9 @@
2133
2376
  "tmpl": [
2134
2377
  " && $_m[",
2135
2378
  {
2136
- "fn": "escapeString",
2379
+ "fn": "quoted",
2137
2380
  "args": [
2381
+ "string",
2138
2382
  {
2139
2383
  "get": "item.field"
2140
2384
  }
@@ -2214,7 +2458,7 @@
2214
2458
  "tmpl": [
2215
2459
  "interface ",
2216
2460
  {
2217
- "fn": "ident",
2461
+ "fn": "identType",
2218
2462
  "args": [
2219
2463
  {
2220
2464
  "get": "decl.name"
@@ -2344,7 +2588,7 @@
2344
2588
  ]
2345
2589
  ],
2346
2590
  "else": {
2347
- "fn": "ident",
2591
+ "fn": "identType",
2348
2592
  "args": [
2349
2593
  {
2350
2594
  "get": "type.name"
@@ -2353,6 +2597,19 @@
2353
2597
  }
2354
2598
  }
2355
2599
  },
2600
+ "rangeEndDecl": {
2601
+ "case": {
2602
+ "when": [ [ { "eq": [ "stmt.rangeEndSimple", "false" ] },
2603
+ { "tmpl": [ ", $", { "fn": "ident", "args": [ { "get": "stmt.rangeEndTemp" } ] }, " = ", { "emit": "stmt.rangeEnd" } ] } ] ],
2604
+ "else": ""
2605
+ }
2606
+ },
2607
+ "rangeEndRead": {
2608
+ "case": {
2609
+ "when": [ [ { "eq": [ "stmt.rangeEndSimple", "true" ] }, { "emit": "stmt.rangeEnd" } ] ],
2610
+ "else": { "tmpl": [ "$", { "fn": "ident", "args": [ { "get": "stmt.rangeEndTemp" } ] } ] }
2611
+ }
2612
+ },
2356
2613
  "ForStmt": {
2357
2614
  "case": {
2358
2615
  "when": [
@@ -2380,7 +2637,20 @@
2380
2637
  {
2381
2638
  "emit": "stmt.rangeStart"
2382
2639
  },
2383
- "; $",
2640
+ { "call": "rangeEndDecl" },
2641
+ "; ",
2642
+ {
2643
+ "case": {
2644
+ "when": [
2645
+ [
2646
+ { "and": [ { "eq": [ "stmt.inclusiveMayWrap", "true" ] }, { "eq": [ "stmt.rangeIs64", "true" ] } ] },
2647
+ { "tmpl": [ "\\is_int($", { "fn": "ident", "args": [ { "get": "stmt.binding" } ] }, ") && " ] }
2648
+ ]
2649
+ ],
2650
+ "else": ""
2651
+ }
2652
+ },
2653
+ "$",
2384
2654
  {
2385
2655
  "fn": "ident",
2386
2656
  "args": [
@@ -2405,9 +2675,7 @@
2405
2675
  "else": " < "
2406
2676
  }
2407
2677
  },
2408
- {
2409
- "emit": "stmt.rangeEnd"
2410
- },
2678
+ { "call": "rangeEndRead" },
2411
2679
  "; $",
2412
2680
  {
2413
2681
  "fn": "ident",
@@ -2567,7 +2835,7 @@
2567
2835
  "fn": "identFn",
2568
2836
  "args": [
2569
2837
  {
2570
- "get": "decl.emitName"
2838
+ "get": "decl.uniqueName"
2571
2839
  }
2572
2840
  ]
2573
2841
  }
@@ -2671,12 +2939,12 @@
2671
2939
  "block": {
2672
2940
  "head": {
2673
2941
  "tmpl": [
2674
- "if (!function_exists('",
2942
+ "if (!function_exists(__NAMESPACE__.'\\\\",
2675
2943
  {
2676
2944
  "fn": "ident",
2677
2945
  "args": [
2678
2946
  {
2679
- "get": "decl.emitName"
2947
+ "get": "decl.uniqueName"
2680
2948
  }
2681
2949
  ]
2682
2950
  },
@@ -2753,7 +3021,9 @@
2753
3021
  ")"
2754
3022
  ]
2755
3023
  },
2756
- "MethodDecl": {
3024
+ "MethodDecl": { "case": { "when": [
3025
+ [ { "eq": [ "decl.isAbstract", "true" ] }, { "line": { "tmpl": [ "abstract ", { "call": "phpMethodSig" }, ";" ] } } ]
3026
+ ], "else": {
2757
3027
  "block": {
2758
3028
  "head": {
2759
3029
  "call": "phpMethodSig"
@@ -2792,14 +3062,14 @@
2792
3062
  }
2793
3063
  ]
2794
3064
  }
2795
- },
3065
+ } } },
2796
3066
  "EnumDecl": {
2797
3067
  "block": {
2798
3068
  "head": {
2799
3069
  "tmpl": [
2800
3070
  "class ",
2801
3071
  {
2802
- "fn": "ident",
3072
+ "fn": "identType",
2803
3073
  "args": [
2804
3074
  {
2805
3075
  "get": "decl.name"
@@ -2841,7 +3111,7 @@
2841
3111
  "tmpl": [
2842
3112
  "class ",
2843
3113
  {
2844
- "fn": "ident",
3114
+ "fn": "identType",
2845
3115
  "args": [
2846
3116
  {
2847
3117
  "get": "decl.name"
@@ -3030,12 +3300,15 @@
3030
3300
  }
3031
3301
  },
3032
3302
  "ClassDecl": {
3303
+ "seq": [
3304
+ {
3033
3305
  "block": {
3034
3306
  "head": {
3035
3307
  "tmpl": [
3308
+ { "case": { "when": [ [ { "eq": [ "decl.isAbstract", "true" ] }, "abstract " ] ] } },
3036
3309
  "class ",
3037
3310
  {
3038
- "fn": "ident",
3311
+ "fn": "identType",
3039
3312
  "args": [
3040
3313
  {
3041
3314
  "get": "decl.name"
@@ -3115,6 +3388,12 @@
3115
3388
  "item.isMutable",
3116
3389
  "false"
3117
3390
  ]
3391
+ },
3392
+ {
3393
+ "eq": [
3394
+ "item.initIsLiteral",
3395
+ "true"
3396
+ ]
3118
3397
  }
3119
3398
  ]
3120
3399
  },
@@ -3182,6 +3461,12 @@
3182
3461
  "item.isStatic",
3183
3462
  "true"
3184
3463
  ]
3464
+ },
3465
+ {
3466
+ "eq": [
3467
+ "item.initIsLiteral",
3468
+ "true"
3469
+ ]
3185
3470
  }
3186
3471
  ]
3187
3472
  },
@@ -3235,19 +3520,9 @@
3235
3520
  "when": [
3236
3521
  [
3237
3522
  {
3238
- "and": [
3239
- {
3240
- "eq": [
3241
- "decl.hasSuper",
3242
- "true"
3243
- ]
3244
- },
3245
- {
3246
- "eq": [
3247
- "decl.baseHasInit",
3248
- "true"
3249
- ]
3250
- }
3523
+ "eq": [
3524
+ "decl.baseHasInit",
3525
+ "true"
3251
3526
  ]
3252
3527
  },
3253
3528
  {
@@ -3308,12 +3583,50 @@
3308
3583
  }
3309
3584
  ]
3310
3585
  }
3586
+ },
3587
+ {
3588
+ "mapDecl": "decl.staticInitFields",
3589
+ "each": {
3590
+ "case": {
3591
+ "when": [
3592
+ [
3593
+ { "eq": ["item.initIsLiteral", "false"] },
3594
+ { "line": { "tmpl": [
3595
+ { "fn": "identType", "args": [ { "get": "decl.name" } ] },
3596
+ "::$",
3597
+ { "fn": "ident", "args": [ { "get": "item.name" } ] },
3598
+ " = ",
3599
+ { "emit": "item.init" },
3600
+ ";"
3601
+ ] } }
3602
+ ]
3603
+ ]
3604
+ }
3605
+ }
3606
+ }
3607
+ ]
3311
3608
  },
3312
3609
  "Program": {
3313
3610
  "seq": [
3314
3611
  {
3315
3612
  "line": "<?php"
3316
3613
  },
3614
+ {
3615
+ "line": "// <auto-generated/>"
3616
+ },
3617
+ {
3618
+ "line": "// Generated by Polyglot. Do not edit: regenerate with `polyglot build`."
3619
+ },
3620
+ {
3621
+ "case": {
3622
+ "when": [
3623
+ [
3624
+ { "not": { "eq": ["option.namespace", ""] } },
3625
+ { "line": { "tmpl": ["namespace ", { "get": "option.namespace" }, ";"] } }
3626
+ ]
3627
+ ]
3628
+ }
3629
+ },
3317
3630
  {
3318
3631
  "case": {
3319
3632
  "when": [
@@ -3350,67 +3663,57 @@
3350
3663
  }
3351
3664
  },
3352
3665
  {
3353
- "mapMembers": "module.enums",
3354
- "rule": "EnumDecl"
3666
+ "fn": "preludeSlot"
3355
3667
  },
3356
3668
  {
3357
- "mapMembers": "module.records",
3358
- "rule": "RecordDecl"
3359
- },
3360
- {
3361
- "mapMembers": "module.interfaces",
3362
- "rule": "InterfaceDecl"
3363
- },
3364
- {
3365
- "mapMembers": "module.classes",
3366
- "rule": "ClassDecl"
3367
- },
3368
- {
3369
- "mapDecl": "module.globals",
3370
- "each": {
3371
- "line": {
3372
- "tmpl": [
3373
- "$",
3374
- {
3375
- "fn": "ident",
3376
- "args": [
3669
+ "mapOrder": "module.order",
3670
+ "kinds": {
3671
+ "enum": { "rule": "EnumDecl" },
3672
+ "interface": { "rule": "InterfaceDecl" },
3673
+ "union": { "rule": "UnionDecl" },
3674
+ "record": { "rule": "RecordDecl" },
3675
+ "function": { "rule": "FunctionDecl" },
3676
+ "extension": { "rule": "FunctionDecl" },
3677
+ "class": { "rule": "ClassDecl" },
3678
+ "global": {
3679
+ "each": {
3680
+ "line": {
3681
+ "tmpl": [
3682
+ "$",
3377
3683
  {
3378
- "get": "item.name"
3379
- }
3380
- ]
3381
- },
3382
- " = ",
3383
- {
3384
- "case": {
3385
- "when": [
3386
- [
3387
- {
3388
- "eq": [
3389
- "item.hasInit",
3390
- "true"
3391
- ]
3392
- },
3684
+ "fn": "ident",
3685
+ "args": [
3393
3686
  {
3394
- "emit": "item.init"
3687
+ "get": "item.name"
3395
3688
  }
3396
3689
  ]
3397
- ],
3398
- "else": "null"
3399
- }
3400
- },
3401
- ";"
3402
- ]
3690
+ },
3691
+ " = ",
3692
+ {
3693
+ "case": {
3694
+ "when": [
3695
+ [
3696
+ {
3697
+ "eq": [
3698
+ "item.hasInit",
3699
+ "true"
3700
+ ]
3701
+ },
3702
+ {
3703
+ "emit": "item.init"
3704
+ }
3705
+ ]
3706
+ ],
3707
+ "else": "null"
3708
+ }
3709
+ },
3710
+ ";"
3711
+ ]
3712
+ }
3713
+ }
3403
3714
  }
3404
3715
  }
3405
3716
  },
3406
- {
3407
- "mapMembers": "module.functions",
3408
- "rule": "FunctionDecl"
3409
- },
3410
- {
3411
- "mapMembers": "module.extensions",
3412
- "rule": "FunctionDecl"
3413
- },
3414
3717
  {
3415
3718
  "case": {
3416
3719
  "when": [
@@ -3443,5 +3746,6 @@
3443
3746
  ]
3444
3747
  }
3445
3748
  },
3446
- "fileExtension": ".php"
3749
+ "fileExtension": ".php",
3750
+ "lineComment": "//"
3447
3751
  }