purus 1.0.0 → 1.1.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "purus",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Purus - /ˈpuː.rus/ means pure✨ in Latin - is a beautiful, simple, and easy-to-use language. It compiles to JavaScript. It makes your fingers free from the Shift key. With Purus, you can write code almost without pressing the Shift key.",
5
5
  "main": "pkg/index.js",
6
6
  "module": "pkg/index.mjs",
package/pkg/lib/create.js CHANGED
@@ -5,6 +5,7 @@ const path = require("path");
5
5
  const readline = require("readline");
6
6
  const { spawnSync } = require("child_process");
7
7
  const { CONFIG_PURUS, PRETTIERRC, MAIN_PURUS, GITIGNORE } = require("./templates.js");
8
+ const pm = require("./pm.js");
8
9
 
9
10
  function question(rl, text) {
10
11
  return new Promise((resolve) => rl.question(text, (a) => resolve(a.trim())));
@@ -56,6 +57,10 @@ async function run() {
56
57
  // src/main.purus
57
58
  fs.writeFileSync(path.join(projectDir, "src/main.purus"), MAIN_PURUS);
58
59
 
60
+ // Detect the package manager from how we were launched (npx /
61
+ // pnpm dlx / yarn dlx / bunx), falling back to npm.
62
+ const manager = pm.detect(projectDir);
63
+
59
64
  // README.md
60
65
  const readme = `# ${projectName}
61
66
 
@@ -64,7 +69,7 @@ A [Purus](https://purus.work) project.
64
69
  ## Getting Started
65
70
 
66
71
  \`\`\`sh
67
- npm install
72
+ ${pm.installHint(manager)}
68
73
  purus build
69
74
  \`\`\`
70
75
 
@@ -72,10 +77,10 @@ purus build
72
77
 
73
78
  | Script | Description |
74
79
  |---|---|
75
- | \`npm run build\` | Compile Purus to JavaScript |
76
- | \`npm run exec\` | Run without compiling to files |
77
- | \`npm run format\` | Format with Prettier |
78
- | \`npm run lint\` | Lint with purus-lint |
80
+ | \`${manager} run build\` | Compile Purus to JavaScript |
81
+ | \`${manager} run exec\` | Run without compiling to files |
82
+ | \`${manager} run format\` | Format with Prettier |
83
+ | \`${manager} run lint\` | Lint with purus-lint |
79
84
  `;
80
85
  fs.writeFileSync(path.join(projectDir, "README.md"), readme);
81
86
 
@@ -88,22 +93,28 @@ purus build
88
93
  console.log(" README.md");
89
94
  console.log(" src/main.purus");
90
95
 
91
- // npm init
96
+ // Initialize package.json with the detected package manager
92
97
  console.log("");
93
- if (yesFlag) {
94
- console.log("Running npm init -y...");
95
- spawnSync("npm", ["init", "-y"], {
98
+ const initCmd = pm.initCommand(manager, yesFlag);
99
+ if (initCmd) {
100
+ console.log(`Running ${initCmd.cmd} ${initCmd.args.join(" ")}...`);
101
+ spawnSync(initCmd.cmd, initCmd.args, {
96
102
  cwd: projectDir,
97
103
  stdio: "inherit",
98
104
  shell: true,
99
105
  });
100
106
  } else {
101
- console.log("Running npm init...");
102
- spawnSync("npm", ["init"], {
103
- cwd: projectDir,
104
- stdio: "inherit",
105
- shell: true,
106
- });
107
+ // Managers whose init scaffolds extra files (e.g. bun) get a
108
+ // minimal package.json instead.
109
+ console.log("Creating package.json...");
110
+ fs.writeFileSync(
111
+ path.join(projectDir, "package.json"),
112
+ JSON.stringify(
113
+ { name: path.basename(projectDir), version: "1.0.0" },
114
+ null,
115
+ 2,
116
+ ) + "\n",
117
+ );
107
118
  }
108
119
 
109
120
  // Add scripts to package.json and set main/type
@@ -144,12 +155,13 @@ purus build
144
155
  "prettier",
145
156
  "purus",
146
157
  ];
147
- console.log("\nInstalling devDependencies...");
158
+ console.log(`\nInstalling devDependencies with ${manager}...`);
148
159
  for (const dep of devDeps) {
149
160
  console.log(` ${dep}`);
150
161
  }
151
162
  console.log("");
152
- spawnSync("npm", ["install", "--save-dev", ...devDeps], {
163
+ const addCmd = pm.addDevCommand(manager, devDeps);
164
+ spawnSync(addCmd.cmd, addCmd.args, {
153
165
  cwd: projectDir,
154
166
  stdio: "inherit",
155
167
  shell: true,
@@ -159,7 +171,7 @@ purus build
159
171
  console.log("\nDone! To get started:");
160
172
  console.log(` cd ${projectName}`);
161
173
  if (!installDeps) {
162
- console.log(" npm install");
174
+ console.log(` ${pm.installHint(manager)}`);
163
175
  }
164
176
  console.log(" purus build");
165
177
  } finally {
package/pkg/lib/init.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const fs = require("fs");
4
4
  const path = require("path");
5
5
  const { CONFIG_PURUS, PRETTIERRC, MAIN_PURUS, GITIGNORE } = require("./templates.js");
6
+ const pm = require("./pm.js");
6
7
 
7
8
  function run() {
8
9
  const cwd = process.cwd();
@@ -73,8 +74,9 @@ function run() {
73
74
  console.log(" package.json (skipped: scripts already set)");
74
75
  }
75
76
  } else {
77
+ const manager = pm.detect(cwd);
76
78
  console.log(
77
- "\nNo package.json found. Run `npm init` then `purus init` again to add scripts.",
79
+ `\nNo package.json found. Run \`${manager} init\` then \`purus init\` again to add scripts.`,
78
80
  );
79
81
  }
80
82
 
package/pkg/lib/pm.js ADDED
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Package manager detection and command mapping.
5
+ *
6
+ * Nothing is hardcoded to npm: the manager is detected from how the CLI
7
+ * was launched (npm_config_user_agent — set by `npx`, `pnpm dlx`,
8
+ * `yarn dlx`, `bunx`, and by `<pm> run` scripts), then from a lockfile
9
+ * in the target directory, and only falls back to npm as a default.
10
+ */
11
+
12
+ const fs = require("fs");
13
+ const path = require("path");
14
+
15
+ const KNOWN = new Set(["npm", "pnpm", "yarn", "bun"]);
16
+
17
+ const LOCKFILES = [
18
+ ["package-lock.json", "npm"],
19
+ ["pnpm-lock.yaml", "pnpm"],
20
+ ["yarn.lock", "yarn"],
21
+ ["bun.lock", "bun"],
22
+ ["bun.lockb", "bun"],
23
+ ];
24
+
25
+ function fromUserAgent() {
26
+ // e.g. "pnpm/9.12.0 npm/? node/v22.11.0 linux x64"
27
+ const ua = process.env.npm_config_user_agent || "";
28
+ const name = ua.split(" ")[0].split("/")[0];
29
+ return KNOWN.has(name) ? name : null;
30
+ }
31
+
32
+ function fromLockfile(dir) {
33
+ for (const [file, name] of LOCKFILES) {
34
+ if (fs.existsSync(path.join(dir, file))) return name;
35
+ }
36
+ return null;
37
+ }
38
+
39
+ /**
40
+ * Detect the package manager to use.
41
+ *
42
+ * @param {string} [dir] - Directory to check for lockfiles
43
+ * @returns {"npm"|"pnpm"|"yarn"|"bun"}
44
+ */
45
+ function detect(dir = process.cwd()) {
46
+ return fromUserAgent() || fromLockfile(dir) || "npm";
47
+ }
48
+
49
+ /**
50
+ * Command to initialize a package.json, or null when the manager's
51
+ * init scaffolds extra files (the caller should write a minimal
52
+ * package.json itself instead).
53
+ *
54
+ * @param {string} pm
55
+ * @param {boolean} yes - Non-interactive mode
56
+ * @returns {{ cmd: string, args: string[] } | null}
57
+ */
58
+ function initCommand(pm, yes) {
59
+ switch (pm) {
60
+ case "pnpm":
61
+ // pnpm init is always non-interactive
62
+ return { cmd: "pnpm", args: ["init"] };
63
+ case "yarn":
64
+ return { cmd: "yarn", args: yes ? ["init", "-y"] : ["init"] };
65
+ case "bun":
66
+ // bun init scaffolds index.ts/tsconfig — not wanted here
67
+ return null;
68
+ default:
69
+ return { cmd: "npm", args: yes ? ["init", "-y"] : ["init"] };
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Command to install packages as devDependencies.
75
+ *
76
+ * @param {string} pm
77
+ * @param {string[]} deps
78
+ * @returns {{ cmd: string, args: string[] }}
79
+ */
80
+ function addDevCommand(pm, deps) {
81
+ switch (pm) {
82
+ case "pnpm":
83
+ return { cmd: "pnpm", args: ["add", "-D", ...deps] };
84
+ case "yarn":
85
+ return { cmd: "yarn", args: ["add", "--dev", ...deps] };
86
+ case "bun":
87
+ return { cmd: "bun", args: ["add", "--dev", ...deps] };
88
+ default:
89
+ return { cmd: "npm", args: ["install", "--save-dev", ...deps] };
90
+ }
91
+ }
92
+
93
+ /**
94
+ * The plain "install dependencies" command shown in docs and hints.
95
+ *
96
+ * @param {string} pm
97
+ * @returns {string}
98
+ */
99
+ function installHint(pm) {
100
+ return pm === "yarn" ? "yarn" : `${pm} install`;
101
+ }
102
+
103
+ module.exports = { detect, initCommand, addDevCommand, installHint };
@@ -113,6 +113,9 @@ _M0DTPC16result6ResultGuRP311moonbitlang1x2fs7IOErrorE2Ok.prototype.$tag = 1;
113
113
  const _M0FP511moonbitlang1x3sys8internal3ffi24get__cli__args__internal = function() {
114
114
  return process.argv.slice(1);
115
115
  };
116
+ const _M0FP511moonbitlang1x3sys8internal3ffi4exit = function(code) {
117
+ process.exit(code);
118
+ };
116
119
  function _M0TP49puruslang5purus3src5lexer5Lexer(param0, param1, param2, param3, param4) {
117
120
  this.chars = param0;
118
121
  this.pos = param1;
@@ -494,9 +497,10 @@ function _M0TPB8MutLocalGRPB13StringBuilderE(param0) {
494
497
  function _M0TPB8MutLocalGbE(param0) {
495
498
  this.val = param0;
496
499
  }
497
- function _M0TP49puruslang5purus3src6parser6Parser(param0, param1) {
500
+ function _M0TP49puruslang5purus3src6parser6Parser(param0, param1, param2) {
498
501
  this.tokens = param0;
499
502
  this.pos = param1;
503
+ this.errors = param2;
500
504
  }
501
505
  function _M0DTP49puruslang5purus3src6parser12MatchPattern6LitPat(param0) {
502
506
  this._0 = param0;
@@ -1041,17 +1045,14 @@ function _M0TPB8MutLocalGsE(param0) {
1041
1045
  this.val = param0;
1042
1046
  }
1043
1047
  const _M0FP092moonbitlang_2fcore_2fbuiltin_2fStringBuilder_24as_24_40moonbitlang_2fcore_2fbuiltin_2eLogger = { method_0: _M0IPB13StringBuilderPB6Logger13write__string, method_1: _M0IP016_24default__implPB6Logger16write__substringGRPB13StringBuilderE, method_2: _M0IPB13StringBuilderPB6Logger11write__view, method_3: _M0IPB13StringBuilderPB6Logger11write__char, method_4: _M0IP016_24default__implPB6Logger28write__string__interpolationGRPB13StringBuilderE, method_5: _M0IP016_24default__implPB6Logger5writeGRPB13StringBuilderE };
1044
- const _M0MPB4Iter4nextN6constrS8926GcE = 0;
1045
- const _M0MPB4Iter4nextN6constrS8927GcE = 0;
1046
- const _M0MPB4Iter3newN6constrS8934GcE = 0;
1047
- const _M0FPB18brute__force__findN6constrS8937 = 0;
1048
- const _M0FPB28boyer__moore__horspool__findN6constrS8936 = 0;
1048
+ const _M0MPB4Iter4nextN6constrS9224GcE = 0;
1049
+ const _M0MPB4Iter4nextN6constrS9225GcE = 0;
1050
+ const _M0MPB4Iter3newN6constrS9232GcE = 0;
1051
+ const _M0FPB18brute__force__findN6constrS9235 = 0;
1052
+ const _M0FPB28boyer__moore__horspool__findN6constrS9234 = 0;
1049
1053
  function _M0FPC15abort5abortGRPB9ArrayViewGsEE(msg) {
1050
1054
  return $panic();
1051
1055
  }
1052
- function _M0FPC15abort5abortGyE(msg) {
1053
- return $panic();
1054
- }
1055
1056
  function _M0MPC15array10FixedArray12unsafe__blitGRPB17UnsafeMaybeUninitGsEE(dst, dst_offset, src, src_offset, len) {
1056
1057
  if (dst === src && dst_offset < src_offset) {
1057
1058
  let _tmp = 0;
@@ -1093,9 +1094,6 @@ function _M0MPB18UninitializedArray12unsafe__blitGsE(dst, dst_offset, src, src_o
1093
1094
  function _M0MPB13StringBuilder13write__objectGsE(self, obj) {
1094
1095
  _M0IP016_24default__implPB4Show6outputGsE(obj, { self: self, method_table: _M0FP092moonbitlang_2fcore_2fbuiltin_2fStringBuilder_24as_24_40moonbitlang_2fcore_2fbuiltin_2eLogger });
1095
1096
  }
1096
- function _M0MPB13StringBuilder13write__objectGiE(self, obj) {
1097
- _M0IP016_24default__implPB4Show6outputGiE(obj, { self: self, method_table: _M0FP092moonbitlang_2fcore_2fbuiltin_2fStringBuilder_24as_24_40moonbitlang_2fcore_2fbuiltin_2eLogger });
1098
- }
1099
1097
  function _M0MPC13int3Int16unsafe__to__char(self) {
1100
1098
  return self;
1101
1099
  }
@@ -1120,12 +1118,6 @@ function _M0FPB32code__point__of__surrogate__pair(leading, trailing) {
1120
1118
  function _M0MPC16uint166UInt1616unsafe__to__char(self) {
1121
1119
  return self;
1122
1120
  }
1123
- function _M0MPC16string10StringView6length(self) {
1124
- return self.end - self.start | 0;
1125
- }
1126
- function _M0MPC16string10StringView11unsafe__get(self, index) {
1127
- return self.str.charCodeAt(self.start + index | 0);
1128
- }
1129
1121
  function _M0IPB13StringBuilderPB6Logger13write__string(self, str) {
1130
1122
  self.val = `${self.val}${str}`;
1131
1123
  }
@@ -1191,21 +1183,18 @@ function _M0MPC16string10StringView13start__offset(self) {
1191
1183
  function _M0IP016_24default__implPB4Show6outputGsE(self, logger) {
1192
1184
  logger.method_table.method_0(logger.self, _M0IPC16string6StringPB4Show10to__string(self));
1193
1185
  }
1194
- function _M0IP016_24default__implPB4Show6outputGiE(self, logger) {
1195
- logger.method_table.method_0(logger.self, _M0IPC13int3IntPB4Show10to__string(self));
1196
- }
1197
1186
  function _M0MPB4Iter4nextGcE(self) {
1198
1187
  const _func = self.f;
1199
1188
  const result = _func();
1200
1189
  const _bind = self.size_hint;
1201
1190
  if (result === -1) {
1202
- self.size_hint = _M0MPB4Iter4nextN6constrS8927GcE;
1191
+ self.size_hint = _M0MPB4Iter4nextN6constrS9225GcE;
1203
1192
  } else {
1204
1193
  if (_bind === undefined) {
1205
1194
  } else {
1206
1195
  const _Some = _bind;
1207
1196
  const _n = _Some;
1208
- self.size_hint = _n > 0 ? _n - 1 | 0 : _M0MPB4Iter4nextN6constrS8926GcE;
1197
+ self.size_hint = _n > 0 ? _n - 1 | 0 : _M0MPB4Iter4nextN6constrS9224GcE;
1209
1198
  }
1210
1199
  }
1211
1200
  return result;
@@ -1220,34 +1209,25 @@ function _M0MPB4Iter3newGcE(f, size_hint) {
1220
1209
  } else {
1221
1210
  const _Some = size_hint;
1222
1211
  const _n = _Some;
1223
- size_hint$2 = _n > 0 ? _n : _M0MPB4Iter3newN6constrS8934GcE;
1212
+ size_hint$2 = _n > 0 ? _n : _M0MPB4Iter3newN6constrS9232GcE;
1224
1213
  }
1225
1214
  return new _M0TPB4IterGcE(f, size_hint$2);
1226
1215
  }
1227
1216
  function _M0MPC16string10StringView12view_2einner(self, start_offset, end_offset) {
1228
1217
  let end_offset$2;
1229
1218
  if (end_offset === undefined) {
1230
- end_offset$2 = _M0MPC16string10StringView6length(self);
1219
+ end_offset$2 = self.end - self.start | 0;
1231
1220
  } else {
1232
1221
  const _Some = end_offset;
1233
1222
  end_offset$2 = _Some;
1234
1223
  }
1235
- return start_offset >= 0 && (start_offset <= end_offset$2 && end_offset$2 <= _M0MPC16string10StringView6length(self)) ? new _M0TPC16string10StringView(self.str, self.start + start_offset | 0, self.start + end_offset$2 | 0) : _M0FPC15abort5abortGRPB9ArrayViewGsEE("Invalid index for View");
1224
+ return start_offset >= 0 && (start_offset <= end_offset$2 && end_offset$2 <= (self.end - self.start | 0)) ? new _M0TPC16string10StringView(self.str, self.start + start_offset | 0, self.start + end_offset$2 | 0) : _M0FPC15abort5abortGRPB9ArrayViewGsEE("Invalid index for View");
1236
1225
  }
1237
1226
  function _M0MPC16string10StringView9to__owned(self) {
1238
1227
  return self.str.substring(self.start, self.end);
1239
1228
  }
1240
- function _M0MPC15array9ArrayView6lengthGsE(self) {
1241
- return self.end - self.start | 0;
1242
- }
1243
- function _M0MPC15array9ArrayView6lengthGcE(self) {
1244
- return self.end - self.start | 0;
1245
- }
1246
- function _M0MPC15array9ArrayView6lengthGyE(self) {
1247
- return self.end - self.start | 0;
1248
- }
1249
1229
  function _M0MPC16string6String11from__array(chars) {
1250
- const buf = _M0MPB13StringBuilder21StringBuilder_2einner(Math.imul(_M0MPC15array9ArrayView6lengthGcE(chars), 4) | 0);
1230
+ const buf = _M0MPB13StringBuilder21StringBuilder_2einner(Math.imul(chars.end - chars.start | 0, 4) | 0);
1251
1231
  const _bind = chars.end - chars.start | 0;
1252
1232
  let _tmp = 0;
1253
1233
  while (true) {
@@ -1267,8 +1247,8 @@ function _M0IPB13StringBuilderPB6Logger11write__view(self, str) {
1267
1247
  self.val = `${self.val}${_M0MPC16string10StringView9to__owned(str)}`;
1268
1248
  }
1269
1249
  function _M0FPB28boyer__moore__horspool__find(haystack, needle) {
1270
- const haystack_len = _M0MPC16string10StringView6length(haystack);
1271
- const needle_len = _M0MPC16string10StringView6length(needle);
1250
+ const haystack_len = haystack.end - haystack.start | 0;
1251
+ const needle_len = needle.end - needle.start | 0;
1272
1252
  if (needle_len > 0) {
1273
1253
  if (haystack_len >= needle_len) {
1274
1254
  const skip_table = $make_array_len_and_init(256, needle_len);
@@ -1277,7 +1257,7 @@ function _M0FPB28boyer__moore__horspool__find(haystack, needle) {
1277
1257
  while (true) {
1278
1258
  const i = _tmp;
1279
1259
  if (i < _bind) {
1280
- const _tmp$2 = _M0MPC16string10StringView11unsafe__get(needle, i) & 255;
1260
+ const _tmp$2 = needle.str.charCodeAt(needle.start + i | 0) & 255;
1281
1261
  $bound_check(skip_table, _tmp$2);
1282
1262
  skip_table[_tmp$2] = (needle_len - 1 | 0) - i | 0;
1283
1263
  _tmp = i + 1 | 0;
@@ -1295,7 +1275,7 @@ function _M0FPB28boyer__moore__horspool__find(haystack, needle) {
1295
1275
  while (true) {
1296
1276
  const j = _tmp$3;
1297
1277
  if (j <= _bind$2) {
1298
- if (_M0IPC16uint166UInt16PB2Eq10not__equal(_M0MPC16string10StringView11unsafe__get(haystack, i + j | 0), _M0MPC16string10StringView11unsafe__get(needle, j))) {
1278
+ if (_M0IPC16uint166UInt16PB2Eq10not__equal(haystack.str.charCodeAt(haystack.start + (i + j | 0) | 0), needle.str.charCodeAt(needle.start + j | 0))) {
1299
1279
  break;
1300
1280
  }
1301
1281
  _tmp$3 = j + 1 | 0;
@@ -1304,7 +1284,7 @@ function _M0FPB28boyer__moore__horspool__find(haystack, needle) {
1304
1284
  return i;
1305
1285
  }
1306
1286
  }
1307
- const _tmp$4 = _M0MPC16string10StringView11unsafe__get(haystack, (i + needle_len | 0) - 1 | 0) & 255;
1287
+ const _tmp$4 = haystack.str.charCodeAt(haystack.start + ((i + needle_len | 0) - 1 | 0) | 0) & 255;
1308
1288
  $bound_check(skip_table, _tmp$4);
1309
1289
  _tmp$2 = i + skip_table[_tmp$4] | 0;
1310
1290
  continue;
@@ -1317,36 +1297,38 @@ function _M0FPB28boyer__moore__horspool__find(haystack, needle) {
1317
1297
  return undefined;
1318
1298
  }
1319
1299
  } else {
1320
- return _M0FPB28boyer__moore__horspool__findN6constrS8936;
1300
+ return _M0FPB28boyer__moore__horspool__findN6constrS9234;
1321
1301
  }
1322
1302
  }
1323
1303
  function _M0FPB18brute__force__find(haystack, needle) {
1324
- const haystack_len = _M0MPC16string10StringView6length(haystack);
1325
- const needle_len = _M0MPC16string10StringView6length(needle);
1304
+ const haystack_len = haystack.end - haystack.start | 0;
1305
+ const needle_len = needle.end - needle.start | 0;
1326
1306
  if (needle_len > 0) {
1327
1307
  if (haystack_len >= needle_len) {
1328
- const needle_first = _M0MPC16string10StringView11unsafe__get(needle, 0);
1308
+ const needle_first = needle.str.charCodeAt(needle.start);
1329
1309
  const forward_len = haystack_len - needle_len | 0;
1330
1310
  let _tmp = 0;
1331
1311
  while (true) {
1332
1312
  const i = _tmp;
1333
1313
  if (i <= forward_len) {
1334
- if (_M0IPC16uint166UInt16PB2Eq10not__equal(_M0MPC16string10StringView11unsafe__get(haystack, i), needle_first)) {
1335
- _tmp = i + 1 | 0;
1336
- continue;
1337
- }
1338
- let _tmp$2 = 1;
1339
- while (true) {
1340
- const j = _tmp$2;
1341
- if (j < needle_len) {
1342
- if (_M0IPC16uint166UInt16PB2Eq10not__equal(_M0MPC16string10StringView11unsafe__get(haystack, i + j | 0), _M0MPC16string10StringView11unsafe__get(needle, j))) {
1343
- break;
1314
+ _L: {
1315
+ if (_M0IPC16uint166UInt16PB2Eq10not__equal(haystack.str.charCodeAt(haystack.start + i | 0), needle_first)) {
1316
+ break _L;
1317
+ }
1318
+ let _tmp$2 = 1;
1319
+ while (true) {
1320
+ const j = _tmp$2;
1321
+ if (j < needle_len) {
1322
+ if (_M0IPC16uint166UInt16PB2Eq10not__equal(haystack.str.charCodeAt(haystack.start + (i + j | 0) | 0), needle.str.charCodeAt(needle.start + j | 0))) {
1323
+ break;
1324
+ }
1325
+ _tmp$2 = j + 1 | 0;
1326
+ continue;
1327
+ } else {
1328
+ return i;
1344
1329
  }
1345
- _tmp$2 = j + 1 | 0;
1346
- continue;
1347
- } else {
1348
- return i;
1349
1330
  }
1331
+ break _L;
1350
1332
  }
1351
1333
  _tmp = i + 1 | 0;
1352
1334
  continue;
@@ -1359,15 +1341,15 @@ function _M0FPB18brute__force__find(haystack, needle) {
1359
1341
  return undefined;
1360
1342
  }
1361
1343
  } else {
1362
- return _M0FPB18brute__force__findN6constrS8937;
1344
+ return _M0FPB18brute__force__findN6constrS9235;
1363
1345
  }
1364
1346
  }
1365
1347
  function _M0MPC16string10StringView4find(self, str) {
1366
- return _M0MPC16string10StringView6length(str) <= 4 ? _M0FPB18brute__force__find(self, str) : _M0FPB28boyer__moore__horspool__find(self, str);
1348
+ return (str.end - str.start | 0) <= 4 ? _M0FPB18brute__force__find(self, str) : _M0FPB28boyer__moore__horspool__find(self, str);
1367
1349
  }
1368
1350
  function _M0FPB33boyer__moore__horspool__rev__find(haystack, needle) {
1369
- const haystack_len = _M0MPC16string10StringView6length(haystack);
1370
- const needle_len = _M0MPC16string10StringView6length(needle);
1351
+ const haystack_len = haystack.end - haystack.start | 0;
1352
+ const needle_len = needle.end - needle.start | 0;
1371
1353
  if (needle_len > 0) {
1372
1354
  if (haystack_len >= needle_len) {
1373
1355
  const skip_table = $make_array_len_and_init(256, needle_len);
@@ -1375,7 +1357,7 @@ function _M0FPB33boyer__moore__horspool__rev__find(haystack, needle) {
1375
1357
  while (true) {
1376
1358
  const i = _tmp;
1377
1359
  if (i >= 1) {
1378
- const _tmp$2 = _M0MPC16string10StringView11unsafe__get(needle, i) & 255;
1360
+ const _tmp$2 = needle.str.charCodeAt(needle.start + i | 0) & 255;
1379
1361
  $bound_check(skip_table, _tmp$2);
1380
1362
  skip_table[_tmp$2] = i;
1381
1363
  _tmp = i - 1 | 0;
@@ -1392,7 +1374,7 @@ function _M0FPB33boyer__moore__horspool__rev__find(haystack, needle) {
1392
1374
  while (true) {
1393
1375
  const j = _tmp$3;
1394
1376
  if (j < needle_len) {
1395
- if (_M0IPC16uint166UInt16PB2Eq10not__equal(_M0MPC16string10StringView11unsafe__get(haystack, i + j | 0), _M0MPC16string10StringView11unsafe__get(needle, j))) {
1377
+ if (_M0IPC16uint166UInt16PB2Eq10not__equal(haystack.str.charCodeAt(haystack.start + (i + j | 0) | 0), needle.str.charCodeAt(needle.start + j | 0))) {
1396
1378
  break;
1397
1379
  }
1398
1380
  _tmp$3 = j + 1 | 0;
@@ -1401,7 +1383,7 @@ function _M0FPB33boyer__moore__horspool__rev__find(haystack, needle) {
1401
1383
  return i;
1402
1384
  }
1403
1385
  }
1404
- const _tmp$4 = _M0MPC16string10StringView11unsafe__get(haystack, i) & 255;
1386
+ const _tmp$4 = haystack.str.charCodeAt(haystack.start + i | 0) & 255;
1405
1387
  $bound_check(skip_table, _tmp$4);
1406
1388
  _tmp$2 = i - skip_table[_tmp$4] | 0;
1407
1389
  continue;
@@ -1424,31 +1406,34 @@ function _M0IPC16string6StringPB4Show10to__string(self) {
1424
1406
  return self;
1425
1407
  }
1426
1408
  function _M0FPB23brute__force__rev__find(haystack, needle) {
1427
- const haystack_len = _M0MPC16string10StringView6length(haystack);
1428
- const needle_len = _M0MPC16string10StringView6length(needle);
1409
+ const haystack_len = haystack.end - haystack.start | 0;
1410
+ const needle_len = needle.end - needle.start | 0;
1429
1411
  if (needle_len > 0) {
1430
1412
  if (haystack_len >= needle_len) {
1431
- const needle_first = _M0MPC16string10StringView11unsafe__get(needle, 0);
1432
- let _tmp = haystack_len - needle_len | 0;
1413
+ const needle_first = needle.str.charCodeAt(needle.start);
1414
+ const _bind = haystack_len - needle_len | 0;
1415
+ let _tmp = _bind;
1433
1416
  while (true) {
1434
1417
  const i = _tmp;
1435
1418
  if (i >= 0) {
1436
- if (_M0IPC16uint166UInt16PB2Eq10not__equal(_M0MPC16string10StringView11unsafe__get(haystack, i), needle_first)) {
1437
- _tmp = i - 1 | 0;
1438
- continue;
1439
- }
1440
- let _tmp$2 = 1;
1441
- while (true) {
1442
- const j = _tmp$2;
1443
- if (j < needle_len) {
1444
- if (_M0IPC16uint166UInt16PB2Eq10not__equal(_M0MPC16string10StringView11unsafe__get(haystack, i + j | 0), _M0MPC16string10StringView11unsafe__get(needle, j))) {
1445
- break;
1419
+ _L: {
1420
+ if (_M0IPC16uint166UInt16PB2Eq10not__equal(haystack.str.charCodeAt(haystack.start + i | 0), needle_first)) {
1421
+ break _L;
1422
+ }
1423
+ let _tmp$2 = 1;
1424
+ while (true) {
1425
+ const j = _tmp$2;
1426
+ if (j < needle_len) {
1427
+ if (_M0IPC16uint166UInt16PB2Eq10not__equal(haystack.str.charCodeAt(haystack.start + (i + j | 0) | 0), needle.str.charCodeAt(needle.start + j | 0))) {
1428
+ break;
1429
+ }
1430
+ _tmp$2 = j + 1 | 0;
1431
+ continue;
1432
+ } else {
1433
+ return i;
1446
1434
  }
1447
- _tmp$2 = j + 1 | 0;
1448
- continue;
1449
- } else {
1450
- return i;
1451
1435
  }
1436
+ break _L;
1452
1437
  }
1453
1438
  _tmp = i - 1 | 0;
1454
1439
  continue;
@@ -1465,7 +1450,7 @@ function _M0FPB23brute__force__rev__find(haystack, needle) {
1465
1450
  }
1466
1451
  }
1467
1452
  function _M0MPC16string10StringView9rev__find(self, str) {
1468
- return _M0MPC16string10StringView6length(str) <= 4 ? _M0FPB23brute__force__rev__find(self, str) : _M0FPB33boyer__moore__horspool__rev__find(self, str);
1453
+ return (str.end - str.start | 0) <= 4 ? _M0FPB23brute__force__rev__find(self, str) : _M0FPB33boyer__moore__horspool__rev__find(self, str);
1469
1454
  }
1470
1455
  function _M0MPC16string10StringView11has__suffix(self, str) {
1471
1456
  const _bind = _M0MPC16string10StringView9rev__find(self, str);
@@ -1474,7 +1459,7 @@ function _M0MPC16string10StringView11has__suffix(self, str) {
1474
1459
  } else {
1475
1460
  const _Some = _bind;
1476
1461
  const _i = _Some;
1477
- return _i === (_M0MPC16string10StringView6length(self) - _M0MPC16string10StringView6length(str) | 0);
1462
+ return _i === ((self.end - self.start | 0) - (str.end - str.start | 0) | 0);
1478
1463
  }
1479
1464
  }
1480
1465
  function _M0MPC16string6String11has__suffix(self, str) {
@@ -1531,7 +1516,7 @@ function _M0MPC16string6String4iter(self) {
1531
1516
  function _M0MPC16string6String12replace__all(self, old, new_) {
1532
1517
  const len = self.length;
1533
1518
  const buf = _M0MPB13StringBuilder21StringBuilder_2einner(len);
1534
- const old_len = _M0MPC16string10StringView6length(old);
1519
+ const old_len = old.end - old.start | 0;
1535
1520
  const new$2 = _M0MPC16string10StringView9to__owned(new_);
1536
1521
  if (old_len === 0) {
1537
1522
  _M0IPB13StringBuilderPB6Logger13write__string(buf, new$2);
@@ -1583,13 +1568,13 @@ function _M0MPC16string6String12replace__all(self, old, new_) {
1583
1568
  const view = _tmp;
1584
1569
  const end = _tmp$2;
1585
1570
  const seg = _M0MPC16string10StringView12view_2einner(view, 0, end);
1586
- _M0IP016_24default__implPB6Logger16write__substringGRPB13StringBuilderE(buf, _M0MPC16string10StringView4data(seg), _M0MPC16string10StringView13start__offset(seg), _M0MPC16string10StringView6length(seg));
1571
+ _M0IP016_24default__implPB6Logger16write__substringGRPB13StringBuilderE(buf, _M0MPC16string10StringView4data(seg), _M0MPC16string10StringView13start__offset(seg), seg.end - seg.start | 0);
1587
1572
  _M0IPB13StringBuilderPB6Logger13write__string(buf, new$2);
1588
1573
  if ((end + old_len | 0) <= len) {
1589
1574
  const next_view = _M0MPC16string10StringView12view_2einner(view, end + old_len | 0, undefined);
1590
1575
  const _bind = _M0MPC16string10StringView4find(next_view, old);
1591
1576
  if (_bind === undefined) {
1592
- _M0IP016_24default__implPB6Logger16write__substringGRPB13StringBuilderE(buf, _M0MPC16string10StringView4data(next_view), _M0MPC16string10StringView13start__offset(next_view), _M0MPC16string10StringView6length(next_view));
1577
+ _M0IP016_24default__implPB6Logger16write__substringGRPB13StringBuilderE(buf, _M0MPC16string10StringView4data(next_view), _M0MPC16string10StringView13start__offset(next_view), next_view.end - next_view.start | 0);
1593
1578
  break;
1594
1579
  } else {
1595
1580
  const _Some$2 = _bind;
@@ -1612,31 +1597,13 @@ function _M0MPC16string6String9to__array(self) {
1612
1597
  return rv;
1613
1598
  });
1614
1599
  }
1615
- function _M0IPC13int3IntPB4Show10to__string(self) {
1616
- return _M0MPC13int3Int18to__string_2einner(self, 10);
1617
- }
1618
- function _M0MPC15array9ArrayView2atGyE(self, index) {
1619
- if (index >= 0 && index < (self.end - self.start | 0)) {
1620
- const _tmp = self.buf;
1621
- const _tmp$2 = self.start + index | 0;
1622
- $bound_check(_tmp, _tmp$2);
1623
- return _tmp[_tmp$2];
1624
- } else {
1625
- const _string_builder = _M0MPB13StringBuilder21StringBuilder_2einner(60);
1626
- _M0IPB13StringBuilderPB6Logger13write__string(_string_builder, "index out of bounds: the len is from 0 to ");
1627
- _M0MPB13StringBuilder13write__objectGiE(_string_builder, self.end - self.start | 0);
1628
- _M0IPB13StringBuilderPB6Logger13write__string(_string_builder, " but the index is ");
1629
- _M0MPB13StringBuilder13write__objectGiE(_string_builder, index);
1630
- return _M0FPC15abort5abortGyE(_M0MPB13StringBuilder10to__string(_string_builder));
1631
- }
1632
- }
1633
1600
  function _M0MPC15array5Array31unsafe__make__and__blit_2einnerGsE(src, allocate_len, len, src_offset, dst_offset) {
1634
1601
  const dst = new Array(allocate_len);
1635
1602
  _M0MPB18UninitializedArray12unsafe__blitGsE(dst, dst_offset, src, src_offset, len);
1636
1603
  return dst;
1637
1604
  }
1638
1605
  function _M0MPC15array9ArrayView9to__ownedGsE(self) {
1639
- const len = _M0MPC15array9ArrayView6lengthGsE(self);
1606
+ const len = self.end - self.start | 0;
1640
1607
  return len === 0 ? [] : _M0MPC15array5Array31unsafe__make__and__blit_2einnerGsE(self.buf, len, len, self.start, 0);
1641
1608
  }
1642
1609
  function _M0MPC15bytes5Bytes5makei(length, value) {
@@ -1662,7 +1629,12 @@ function _M0FPB7printlnGsE(input) {
1662
1629
  console.log(_M0IPC16string6StringPB4Show10to__string(input));
1663
1630
  }
1664
1631
  function _M0MPC15bytes5Bytes11from__array(arr) {
1665
- return _M0MPC15bytes5Bytes5makei(_M0MPC15array9ArrayView6lengthGyE(arr), (i) => _M0MPC15array9ArrayView2atGyE(arr, i));
1632
+ return _M0MPC15bytes5Bytes5makei(arr.end - arr.start | 0, (i) => {
1633
+ if (i < 0 || i >= (arr.end - arr.start | 0)) {
1634
+ $panic();
1635
+ }
1636
+ return arr.buf[arr.start + i | 0];
1637
+ });
1666
1638
  }
1667
1639
  function _M0MPC15array5Array12view_2einnerGsE(self, start, end) {
1668
1640
  const len = self.length;
@@ -1688,21 +1660,11 @@ function _M0MPC15array5Array9is__emptyGRP49puruslang5purus3src5lexer5TokenE(self
1688
1660
  }
1689
1661
  function _M0MPC15array5Array2atGsE(self, index) {
1690
1662
  const len = self.length;
1691
- if (index >= 0 && index < len) {
1692
- $bound_check(self, index);
1693
- return self[index];
1694
- } else {
1695
- return $panic();
1696
- }
1663
+ return index >= 0 && index < len ? self[index] : $panic();
1697
1664
  }
1698
1665
  function _M0MPC15array5Array2atGcE(self, index) {
1699
1666
  const len = self.length;
1700
- if (index >= 0 && index < len) {
1701
- $bound_check(self, index);
1702
- return self[index];
1703
- } else {
1704
- return $panic();
1705
- }
1667
+ return index >= 0 && index < len ? self[index] : $panic();
1706
1668
  }
1707
1669
  function _M0IPC15array5ArrayPB2Eq5equalGsE(self, other) {
1708
1670
  const self_len = self.length;
@@ -1896,6 +1858,9 @@ function _M0FP511moonbitlang1x3sys8internal3ffi14get__cli__args() {
1896
1858
  function _M0FP311moonbitlang1x3sys14get__cli__args() {
1897
1859
  return _M0FP511moonbitlang1x3sys8internal3ffi14get__cli__args();
1898
1860
  }
1861
+ function _M0FP311moonbitlang1x3sys4exit(code) {
1862
+ _M0FP511moonbitlang1x3sys8internal3ffi4exit(code);
1863
+ }
1899
1864
  function _M0IP49puruslang5purus3src5lexer9TokenKindPB2Eq5equal(_x_114, _x_115) {
1900
1865
  let _x0_138;
1901
1866
  let _y0_139;
@@ -4087,7 +4052,7 @@ function _M0MP49puruslang5purus3src6parser6Parser6expect(self, expected) {
4087
4052
  _M0MP49puruslang5purus3src6parser6Parser7advance(self);
4088
4053
  }
4089
4054
  function _M0MP49puruslang5purus3src6parser6Parser3new(tokens) {
4090
- return new _M0TP49puruslang5purus3src6parser6Parser(tokens, 0);
4055
+ return new _M0TP49puruslang5purus3src6parser6Parser(tokens, 0, []);
4091
4056
  }
4092
4057
  function _M0MP49puruslang5purus3src6parser6Parser18parse__param__list(self) {
4093
4058
  const params = [];
@@ -4385,6 +4350,311 @@ function _M0MP49puruslang5purus3src6parser6Parser16parse__use__stmt(self) {
4385
4350
  return new _M0DTP49puruslang5purus3src6parser4Stmt9UseStdlib(module_name, module_name);
4386
4351
  }
4387
4352
  }
4353
+ function _M0FP49puruslang5purus3src6parser13keyword__text(tok) {
4354
+ switch (tok.$tag) {
4355
+ case 8: {
4356
+ return "const";
4357
+ }
4358
+ case 9: {
4359
+ return "let";
4360
+ }
4361
+ case 10: {
4362
+ return "var";
4363
+ }
4364
+ case 11: {
4365
+ return "be";
4366
+ }
4367
+ case 12: {
4368
+ return "add";
4369
+ }
4370
+ case 13: {
4371
+ return "sub";
4372
+ }
4373
+ case 14: {
4374
+ return "mul";
4375
+ }
4376
+ case 15: {
4377
+ return "div";
4378
+ }
4379
+ case 16: {
4380
+ return "fdiv";
4381
+ }
4382
+ case 17: {
4383
+ return "mod";
4384
+ }
4385
+ case 18: {
4386
+ return "neg";
4387
+ }
4388
+ case 19: {
4389
+ return "pow";
4390
+ }
4391
+ case 20: {
4392
+ return "eq";
4393
+ }
4394
+ case 21: {
4395
+ return "neq";
4396
+ }
4397
+ case 22: {
4398
+ return "lt";
4399
+ }
4400
+ case 23: {
4401
+ return "gt";
4402
+ }
4403
+ case 24: {
4404
+ return "le";
4405
+ }
4406
+ case 25: {
4407
+ return "ge";
4408
+ }
4409
+ case 26: {
4410
+ return "and";
4411
+ }
4412
+ case 27: {
4413
+ return "or";
4414
+ }
4415
+ case 28: {
4416
+ return "not";
4417
+ }
4418
+ case 29: {
4419
+ return "coal";
4420
+ }
4421
+ case 30: {
4422
+ return "band";
4423
+ }
4424
+ case 31: {
4425
+ return "bor";
4426
+ }
4427
+ case 32: {
4428
+ return "bxor";
4429
+ }
4430
+ case 33: {
4431
+ return "bnot";
4432
+ }
4433
+ case 34: {
4434
+ return "shl";
4435
+ }
4436
+ case 35: {
4437
+ return "shr";
4438
+ }
4439
+ case 36: {
4440
+ return "ushr";
4441
+ }
4442
+ case 37: {
4443
+ return "fn";
4444
+ }
4445
+ case 38: {
4446
+ return "return";
4447
+ }
4448
+ case 39: {
4449
+ return "to";
4450
+ }
4451
+ case 40: {
4452
+ return "if";
4453
+ }
4454
+ case 41: {
4455
+ return "elif";
4456
+ }
4457
+ case 42: {
4458
+ return "else";
4459
+ }
4460
+ case 43: {
4461
+ return "unless";
4462
+ }
4463
+ case 44: {
4464
+ return "then";
4465
+ }
4466
+ case 45: {
4467
+ return "while";
4468
+ }
4469
+ case 46: {
4470
+ return "until";
4471
+ }
4472
+ case 47: {
4473
+ return "do";
4474
+ }
4475
+ case 48: {
4476
+ return "yield";
4477
+ }
4478
+ case 49: {
4479
+ return "for";
4480
+ }
4481
+ case 50: {
4482
+ return "in";
4483
+ }
4484
+ case 51: {
4485
+ return "range";
4486
+ }
4487
+ case 52: {
4488
+ return "break";
4489
+ }
4490
+ case 53: {
4491
+ return "continue";
4492
+ }
4493
+ case 54: {
4494
+ return "match";
4495
+ }
4496
+ case 55: {
4497
+ return "when";
4498
+ }
4499
+ case 56: {
4500
+ return "switch";
4501
+ }
4502
+ case 57: {
4503
+ return "case";
4504
+ }
4505
+ case 58: {
4506
+ return "pipe";
4507
+ }
4508
+ case 59: {
4509
+ return "as";
4510
+ }
4511
+ case 60: {
4512
+ return "of";
4513
+ }
4514
+ case 61: {
4515
+ return "gives";
4516
+ }
4517
+ case 62: {
4518
+ return "typeof";
4519
+ }
4520
+ case 63: {
4521
+ return "void";
4522
+ }
4523
+ case 64: {
4524
+ return "instanceof";
4525
+ }
4526
+ case 65: {
4527
+ return "new";
4528
+ }
4529
+ case 66: {
4530
+ return "delete";
4531
+ }
4532
+ case 67: {
4533
+ return "this";
4534
+ }
4535
+ case 68: {
4536
+ return "async";
4537
+ }
4538
+ case 69: {
4539
+ return "await";
4540
+ }
4541
+ case 70: {
4542
+ return "try";
4543
+ }
4544
+ case 71: {
4545
+ return "catch";
4546
+ }
4547
+ case 72: {
4548
+ return "finally";
4549
+ }
4550
+ case 73: {
4551
+ return "throw";
4552
+ }
4553
+ case 74: {
4554
+ return "import";
4555
+ }
4556
+ case 75: {
4557
+ return "from";
4558
+ }
4559
+ case 76: {
4560
+ return "export";
4561
+ }
4562
+ case 77: {
4563
+ return "default";
4564
+ }
4565
+ case 78: {
4566
+ return "require";
4567
+ }
4568
+ case 79: {
4569
+ return "use";
4570
+ }
4571
+ case 80: {
4572
+ return "namespace";
4573
+ }
4574
+ case 81: {
4575
+ return "public";
4576
+ }
4577
+ case 82: {
4578
+ return "all";
4579
+ }
4580
+ case 83: {
4581
+ return "type";
4582
+ }
4583
+ case 84: {
4584
+ return "with";
4585
+ }
4586
+ case 5: {
4587
+ return "true";
4588
+ }
4589
+ case 6: {
4590
+ return "false";
4591
+ }
4592
+ case 92: {
4593
+ return "null";
4594
+ }
4595
+ case 93: {
4596
+ return "nil";
4597
+ }
4598
+ case 94: {
4599
+ return "undefined";
4600
+ }
4601
+ case 95: {
4602
+ return "nan";
4603
+ }
4604
+ case 96: {
4605
+ return "infinity";
4606
+ }
4607
+ case 97: {
4608
+ return "list";
4609
+ }
4610
+ case 98: {
4611
+ return "object";
4612
+ }
4613
+ case 85: {
4614
+ return "class";
4615
+ }
4616
+ case 86: {
4617
+ return "extends";
4618
+ }
4619
+ case 87: {
4620
+ return "super";
4621
+ }
4622
+ case 88: {
4623
+ return "static";
4624
+ }
4625
+ case 89: {
4626
+ return "private";
4627
+ }
4628
+ case 90: {
4629
+ return "get";
4630
+ }
4631
+ case 91: {
4632
+ return "set";
4633
+ }
4634
+ case 111: {
4635
+ return "blank";
4636
+ }
4637
+ default: {
4638
+ return undefined;
4639
+ }
4640
+ }
4641
+ }
4642
+ function _M0MP49puruslang5purus3src6parser6Parser21parse__property__name(self) {
4643
+ let name;
4644
+ _L: {
4645
+ const _bind = _M0FP49puruslang5purus3src6parser13keyword__text(_M0MP49puruslang5purus3src6parser6Parser4peek(self));
4646
+ if (_bind === undefined) {
4647
+ return _M0MP49puruslang5purus3src6parser6Parser18parse__ident__name(self);
4648
+ } else {
4649
+ const _Some = _bind;
4650
+ const _name = _Some;
4651
+ name = _name;
4652
+ break _L;
4653
+ }
4654
+ }
4655
+ self.pos = self.pos + 1 | 0;
4656
+ return name;
4657
+ }
4388
4658
  function _M0MP49puruslang5purus3src6parser6Parser11parse__expr(self) {
4389
4659
  return _M0MP49puruslang5purus3src6parser6Parser11parse__pipe(self);
4390
4660
  }
@@ -4886,7 +5156,7 @@ function _M0MP49puruslang5purus3src6parser6Parser14parse__postfix(self) {
4886
5156
  switch (_bind.$tag) {
4887
5157
  case 103: {
4888
5158
  self.pos = self.pos + 1 | 0;
4889
- const field = _M0MP49puruslang5purus3src6parser6Parser18parse__ident__name(self);
5159
+ const field = _M0MP49puruslang5purus3src6parser6Parser21parse__property__name(self);
4890
5160
  if (_M0IP49puruslang5purus3src5lexer9TokenKindPB2Eq5equal(_M0MP49puruslang5purus3src6parser6Parser4peek(self), _M0DTP49puruslang5purus3src5lexer9TokenKind8LBracket__)) {
4891
5161
  if (_M0MP49puruslang5purus3src6parser6Parser21is__computed__bracket(self)) {
4892
5162
  self.pos = self.pos + 1 | 0;
@@ -4932,7 +5202,7 @@ function _M0MP49puruslang5purus3src6parser6Parser14parse__postfix(self) {
4932
5202
  }
4933
5203
  case 107: {
4934
5204
  self.pos = self.pos + 1 | 0;
4935
- const field$2 = _M0MP49puruslang5purus3src6parser6Parser18parse__ident__name(self);
5205
+ const field$2 = _M0MP49puruslang5purus3src6parser6Parser21parse__property__name(self);
4936
5206
  if (_M0IP49puruslang5purus3src5lexer9TokenKindPB2Eq5equal(_M0MP49puruslang5purus3src6parser6Parser4peek(self), _M0DTP49puruslang5purus3src5lexer9TokenKind8LBracket__)) {
4937
5207
  if (_M0MP49puruslang5purus3src6parser6Parser21is__computed__bracket(self)) {
4938
5208
  self.pos = self.pos + 1 | 0;
@@ -5526,11 +5796,19 @@ function _M0MP49puruslang5purus3src6parser6Parser11parse__stmt(self) {
5526
5796
  case 11: {
5527
5797
  self.pos = self.pos + 1 | 0;
5528
5798
  const value = _M0MP49puruslang5purus3src6parser6Parser11parse__expr(self);
5529
- if (expr$2.$tag === 15) {
5530
- return new _M0DTP49puruslang5purus3src6parser4Stmt8ExprStmt(expr$2);
5531
- } else {
5532
- return _M0MP49puruslang5purus3src6parser6Parser14maybe__postfix(self, new _M0DTP49puruslang5purus3src6parser4Stmt6Assign(expr$2, value));
5799
+ let name;
5800
+ _L$6: {
5801
+ if (expr$2.$tag === 15) {
5802
+ const _Ident = expr$2;
5803
+ const _name = _Ident._0;
5804
+ name = _name;
5805
+ break _L$6;
5806
+ } else {
5807
+ return _M0MP49puruslang5purus3src6parser6Parser14maybe__postfix(self, new _M0DTP49puruslang5purus3src6parser4Stmt6Assign(expr$2, value));
5808
+ }
5533
5809
  }
5810
+ _M0MPC15array5Array4pushGRP49puruslang5purus3src5lexer5TokenE(self.errors, `bare identifier assignment ('${name} be ...') is not supported. Declare with 'const ${name} be ...' or 'let ${name} be ...', or use compound assignment such as '${name} add be 1'`);
5811
+ return new _M0DTP49puruslang5purus3src6parser4Stmt8ExprStmt(expr$2);
5534
5812
  }
5535
5813
  default: {
5536
5814
  return _M0MP49puruslang5purus3src6parser6Parser14maybe__postfix(self, new _M0DTP49puruslang5purus3src6parser4Stmt8ExprStmt(expr$2));
@@ -11346,8 +11624,26 @@ function _M0FP59puruslang5purus3src3cmd4main10cmd__build(args) {
11346
11624
  break;
11347
11625
  }
11348
11626
  }
11349
- const stmts = _M0MP49puruslang5purus3src6parser6Parser5parse(_M0MP49puruslang5purus3src6parser6Parser3new(filtered));
11350
- const header = no_header.val ? "" : "// Generated by Purus 1.0.0";
11627
+ const parser = _M0MP49puruslang5purus3src6parser6Parser3new(filtered);
11628
+ const stmts = _M0MP49puruslang5purus3src6parser6Parser5parse(parser);
11629
+ if (parser.errors.length > 0) {
11630
+ const _bind = parser.errors;
11631
+ const _bind$2 = _bind.length;
11632
+ let _tmp = 0;
11633
+ while (true) {
11634
+ const _ = _tmp;
11635
+ if (_ < _bind$2) {
11636
+ const msg = _bind[_];
11637
+ _M0FPB7printlnGsE(`Error: ${msg}`);
11638
+ _tmp = _ + 1 | 0;
11639
+ continue;
11640
+ } else {
11641
+ break;
11642
+ }
11643
+ }
11644
+ _M0FP311moonbitlang1x3sys4exit(1);
11645
+ }
11646
+ const header = no_header.val ? "" : "// Generated by Purus 1.1.0";
11351
11647
  const js = _M0MP49puruslang5purus3src7codegen9JsCodegen16generate_2einner(_M0MP49puruslang5purus3src7codegen9JsCodegen11new_2einner(cjs.val), stmts, header, shebang.val, strict.val);
11352
11648
  if (to_stdout.val) {
11353
11649
  _M0FPB7printlnGsE(js);
@@ -11468,7 +11764,25 @@ function _M0FP59puruslang5purus3src3cmd4main10cmd__check(file) {
11468
11764
  return undefined;
11469
11765
  }
11470
11766
  const tokens = _M0MP49puruslang5purus3src5lexer5Lexer8tokenize(_M0MP49puruslang5purus3src5lexer5Lexer3new(src));
11471
- _M0MP49puruslang5purus3src6parser6Parser5parse(_M0MP49puruslang5purus3src6parser6Parser3new(tokens));
11767
+ const parser = _M0MP49puruslang5purus3src6parser6Parser3new(tokens);
11768
+ _M0MP49puruslang5purus3src6parser6Parser5parse(parser);
11769
+ if (parser.errors.length > 0) {
11770
+ const _bind = parser.errors;
11771
+ const _bind$2 = _bind.length;
11772
+ let _tmp = 0;
11773
+ while (true) {
11774
+ const _ = _tmp;
11775
+ if (_ < _bind$2) {
11776
+ const msg = _bind[_];
11777
+ _M0FPB7printlnGsE(`Error: ${msg}`);
11778
+ _tmp = _ + 1 | 0;
11779
+ continue;
11780
+ } else {
11781
+ break;
11782
+ }
11783
+ }
11784
+ _M0FP311moonbitlang1x3sys4exit(1);
11785
+ }
11472
11786
  _M0FPB7printlnGsE(`OK: ${file}`);
11473
11787
  }
11474
11788
  (() => {
@@ -39,11 +39,17 @@ function compile(source, options = {}) {
39
39
  args.push("--type", "commonjs");
40
40
  }
41
41
  args.push(tmpFile);
42
- let result = execFileSync(process.execPath, [COMPILER_JS, ...args], {
43
- encoding: "utf8",
44
- stdio: ["pipe", "pipe", "pipe"],
45
- timeout: 30000,
46
- });
42
+ let result;
43
+ try {
44
+ result = execFileSync(process.execPath, [COMPILER_JS, ...args], {
45
+ encoding: "utf8",
46
+ stdio: ["pipe", "pipe", "pipe"],
47
+ timeout: 30000,
48
+ });
49
+ } catch (err) {
50
+ const detail = `${err.stdout || ""}${err.stderr || ""}`.trim();
51
+ throw new Error(detail || `Compile error: ${err.message}`);
52
+ }
47
53
  result = stdlib.postProcess(result);
48
54
  if (header) {
49
55
  return `// Generated by Purus ${VERSION}\n${result}`;
@@ -80,7 +86,8 @@ function check(source) {
80
86
  });
81
87
  return true;
82
88
  } catch (err) {
83
- throw new Error(`Syntax error: ${err.stderr || err.message}`);
89
+ const detail = `${err.stdout || ""}${err.stderr || ""}`.trim();
90
+ throw new Error(`Syntax error: ${detail || err.message}`);
84
91
  } finally {
85
92
  try {
86
93
  fs.unlinkSync(tmpFile);