@markw65/monkeyc-optimizer 1.1.23 → 1.1.25

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.
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_27ZJJM2Y_exports = {};
30
- __export(chunk_27ZJJM2Y_exports, {
29
+ var chunk_SNWJ2FZL_exports = {};
30
+ __export(chunk_SNWJ2FZL_exports, {
31
31
  EnumTagsConst: () => EnumTagsConst,
32
32
  LastTypeTag: () => LastTypeTag,
33
33
  ObjectLikeTagsConst: () => ObjectLikeTagsConst,
@@ -125,8 +125,8 @@ __export(chunk_27ZJJM2Y_exports, {
125
125
  visitorNode: () => visitorNode,
126
126
  xml_util_exports: () => xml_util_exports
127
127
  });
128
- module.exports = __toCommonJS(chunk_27ZJJM2Y_exports);
129
- var import_chunk_HHQDDCTP = require("./chunk-HHQDDCTP.cjs");
128
+ module.exports = __toCommonJS(chunk_SNWJ2FZL_exports);
129
+ var import_chunk_QFQPBQSO = require("./chunk-QFQPBQSO.cjs");
130
130
  var import_prettier_plugin_monkeyc = require("@markw65/prettier-plugin-monkeyc");
131
131
  var import_node_assert = __toESM(require("node:assert"));
132
132
  var import_prettier_plugin_monkeyc2 = require("@markw65/prettier-plugin-monkeyc");
@@ -148,8 +148,10 @@ var import_node_assert10 = __toESM(require("node:assert"));
148
148
  var import_node_assert11 = __toESM(require("node:assert"));
149
149
  var import_node_assert12 = __toESM(require("node:assert"));
150
150
  var import_node_assert13 = __toESM(require("node:assert"));
151
- var fs3 = __toESM(require("fs/promises"));
152
151
  var import_node_assert14 = __toESM(require("node:assert"));
152
+ var import_node_assert15 = __toESM(require("node:assert"));
153
+ var fs3 = __toESM(require("fs/promises"));
154
+ var import_node_assert16 = __toESM(require("node:assert"));
153
155
  var crypto = __toESM(require("node:crypto"));
154
156
  var path = __toESM(require("path"));
155
157
  var fs4 = __toESM(require("fs/promises"));
@@ -5121,7 +5123,7 @@ function peg$parse(input, options) {
5121
5123
  );
5122
5124
  }
5123
5125
  }
5124
- var init_xml = (0, import_chunk_HHQDDCTP.__esm)({
5126
+ var init_xml = (0, import_chunk_QFQPBQSO.__esm)({
5125
5127
  "src/xml.peggy"() {
5126
5128
  "use strict";
5127
5129
  peg$subclass(peg$SyntaxError, Error);
@@ -5466,7 +5468,7 @@ function getLiteralNode(node) {
5466
5468
  return null;
5467
5469
  }
5468
5470
  var mctreeTypeInfo;
5469
- var init_ast = (0, import_chunk_HHQDDCTP.__esm)({
5471
+ var init_ast = (0, import_chunk_QFQPBQSO.__esm)({
5470
5472
  "src/ast.ts"() {
5471
5473
  "use strict";
5472
5474
  mctreeTypeInfo = {
@@ -5536,7 +5538,7 @@ var init_ast = (0, import_chunk_HHQDDCTP.__esm)({
5536
5538
  }
5537
5539
  });
5538
5540
  var xml_util_exports = {};
5539
- (0, import_chunk_HHQDDCTP.__export)(xml_util_exports, {
5541
+ (0, import_chunk_QFQPBQSO.__export)(xml_util_exports, {
5540
5542
  Document: () => Document,
5541
5543
  Nodes: () => Nodes,
5542
5544
  PeggyError: () => PeggyError,
@@ -5669,7 +5671,7 @@ function visit_xml(contents, visitor) {
5669
5671
  });
5670
5672
  }
5671
5673
  var PeggyError, entities, Document, Nodes;
5672
- var init_xml_util = (0, import_chunk_HHQDDCTP.__esm)({
5674
+ var init_xml_util = (0, import_chunk_QFQPBQSO.__esm)({
5673
5675
  "src/xml-util.ts"() {
5674
5676
  "use strict";
5675
5677
  init_xml();
@@ -5839,7 +5841,7 @@ var init_xml_util = (0, import_chunk_HHQDDCTP.__esm)({
5839
5841
  };
5840
5842
  }
5841
5843
  });
5842
- var require_pend = (0, import_chunk_HHQDDCTP.__commonJS)({
5844
+ var require_pend = (0, import_chunk_QFQPBQSO.__commonJS)({
5843
5845
  "node_modules/pend/index.js"(exports, module2) {
5844
5846
  module2.exports = Pend;
5845
5847
  function Pend() {
@@ -5893,16 +5895,16 @@ var require_pend = (0, import_chunk_HHQDDCTP.__commonJS)({
5893
5895
  }
5894
5896
  }
5895
5897
  });
5896
- var require_fd_slicer = (0, import_chunk_HHQDDCTP.__commonJS)({
5898
+ var require_fd_slicer = (0, import_chunk_QFQPBQSO.__commonJS)({
5897
5899
  "node_modules/fd-slicer/index.js"(exports) {
5898
- var fs9 = (0, import_chunk_HHQDDCTP.__require)("fs");
5899
- var util = (0, import_chunk_HHQDDCTP.__require)("util");
5900
- var stream = (0, import_chunk_HHQDDCTP.__require)("stream");
5900
+ var fs9 = (0, import_chunk_QFQPBQSO.__require)("fs");
5901
+ var util = (0, import_chunk_QFQPBQSO.__require)("util");
5902
+ var stream = (0, import_chunk_QFQPBQSO.__require)("stream");
5901
5903
  var Readable = stream.Readable;
5902
5904
  var Writable = stream.Writable;
5903
5905
  var PassThrough = stream.PassThrough;
5904
5906
  var Pend = require_pend();
5905
- var EventEmitter2 = (0, import_chunk_HHQDDCTP.__require)("events").EventEmitter;
5907
+ var EventEmitter2 = (0, import_chunk_QFQPBQSO.__require)("events").EventEmitter;
5906
5908
  exports.createFromBuffer = createFromBuffer;
5907
5909
  exports.createFromFd = createFromFd;
5908
5910
  exports.BufferSlicer = BufferSlicer;
@@ -6159,9 +6161,9 @@ var require_fd_slicer = (0, import_chunk_HHQDDCTP.__commonJS)({
6159
6161
  }
6160
6162
  }
6161
6163
  });
6162
- var require_buffer_crc32 = (0, import_chunk_HHQDDCTP.__commonJS)({
6164
+ var require_buffer_crc32 = (0, import_chunk_QFQPBQSO.__commonJS)({
6163
6165
  "node_modules/buffer-crc32/index.js"(exports, module2) {
6164
- var Buffer2 = (0, import_chunk_HHQDDCTP.__require)("buffer").Buffer;
6166
+ var Buffer2 = (0, import_chunk_QFQPBQSO.__require)("buffer").Buffer;
6165
6167
  var CRC_TABLE = [
6166
6168
  0,
6167
6169
  1996959894,
@@ -6464,17 +6466,17 @@ var require_buffer_crc32 = (0, import_chunk_HHQDDCTP.__commonJS)({
6464
6466
  module2.exports = crc32;
6465
6467
  }
6466
6468
  });
6467
- var require_yauzl = (0, import_chunk_HHQDDCTP.__commonJS)({
6469
+ var require_yauzl = (0, import_chunk_QFQPBQSO.__commonJS)({
6468
6470
  "node_modules/yauzl/index.js"(exports) {
6469
- var fs9 = (0, import_chunk_HHQDDCTP.__require)("fs");
6470
- var zlib = (0, import_chunk_HHQDDCTP.__require)("zlib");
6471
+ var fs9 = (0, import_chunk_QFQPBQSO.__require)("fs");
6472
+ var zlib = (0, import_chunk_QFQPBQSO.__require)("zlib");
6471
6473
  var fd_slicer = require_fd_slicer();
6472
6474
  var crc32 = require_buffer_crc32();
6473
- var util = (0, import_chunk_HHQDDCTP.__require)("util");
6474
- var EventEmitter2 = (0, import_chunk_HHQDDCTP.__require)("events").EventEmitter;
6475
- var Transform = (0, import_chunk_HHQDDCTP.__require)("stream").Transform;
6476
- var PassThrough = (0, import_chunk_HHQDDCTP.__require)("stream").PassThrough;
6477
- var Writable = (0, import_chunk_HHQDDCTP.__require)("stream").Writable;
6475
+ var util = (0, import_chunk_QFQPBQSO.__require)("util");
6476
+ var EventEmitter2 = (0, import_chunk_QFQPBQSO.__require)("events").EventEmitter;
6477
+ var Transform = (0, import_chunk_QFQPBQSO.__require)("stream").Transform;
6478
+ var PassThrough = (0, import_chunk_QFQPBQSO.__require)("stream").PassThrough;
6479
+ var Writable = (0, import_chunk_QFQPBQSO.__require)("stream").Writable;
6478
6480
  exports.open = open2;
6479
6481
  exports.fromFd = fromFd;
6480
6482
  exports.fromBuffer = fromBuffer;
@@ -7163,14 +7165,14 @@ var require_yauzl = (0, import_chunk_HHQDDCTP.__commonJS)({
7163
7165
  }
7164
7166
  }
7165
7167
  });
7166
- var require_yazl = (0, import_chunk_HHQDDCTP.__commonJS)({
7168
+ var require_yazl = (0, import_chunk_QFQPBQSO.__commonJS)({
7167
7169
  "node_modules/yazl/index.js"(exports) {
7168
- var fs9 = (0, import_chunk_HHQDDCTP.__require)("fs");
7169
- var Transform = (0, import_chunk_HHQDDCTP.__require)("stream").Transform;
7170
- var PassThrough = (0, import_chunk_HHQDDCTP.__require)("stream").PassThrough;
7171
- var zlib = (0, import_chunk_HHQDDCTP.__require)("zlib");
7172
- var util = (0, import_chunk_HHQDDCTP.__require)("util");
7173
- var EventEmitter2 = (0, import_chunk_HHQDDCTP.__require)("events").EventEmitter;
7170
+ var fs9 = (0, import_chunk_QFQPBQSO.__require)("fs");
7171
+ var Transform = (0, import_chunk_QFQPBQSO.__require)("stream").Transform;
7172
+ var PassThrough = (0, import_chunk_QFQPBQSO.__require)("stream").PassThrough;
7173
+ var zlib = (0, import_chunk_QFQPBQSO.__require)("zlib");
7174
+ var util = (0, import_chunk_QFQPBQSO.__require)("util");
7175
+ var EventEmitter2 = (0, import_chunk_QFQPBQSO.__require)("events").EventEmitter;
7174
7176
  var crc32 = require_buffer_crc32();
7175
7177
  exports.ZipFile = ZipFile2;
7176
7178
  exports.dateToDosDateTime = dateToDosDateTime;
@@ -7827,7 +7829,7 @@ function skipClassDef(view, current, symbols) {
7827
7829
  const offset = symbols.symbolToLabelMap.get(f1 >>> 8);
7828
7830
  label = offset != null && symbols.symbols.get(offset)?.str || `method_${pc}`;
7829
7831
  }
7830
- symbols.methods.set(pc, { name: label, id: f1 >>> 8 });
7832
+ symbols.methods.set(pc, { name: label, id: f1 >>> 8, argc: null });
7831
7833
  }
7832
7834
  }
7833
7835
  return current;
@@ -7872,7 +7874,7 @@ function fixupClassDef(view, current, offsetMap) {
7872
7874
  }
7873
7875
  return current;
7874
7876
  }
7875
- var init_data = (0, import_chunk_HHQDDCTP.__esm)({
7877
+ var init_data = (0, import_chunk_QFQPBQSO.__esm)({
7876
7878
  "src/readprg/data.ts"() {
7877
7879
  "use strict";
7878
7880
  init_bytecode();
@@ -8015,7 +8017,7 @@ function findCalleesByNode(state, callee) {
8015
8017
  return null;
8016
8018
  return hasProperty(state.allFunctions, name) && state.allFunctions[name] || null;
8017
8019
  }
8018
- var init_function_info = (0, import_chunk_HHQDDCTP.__esm)({
8020
+ var init_function_info = (0, import_chunk_QFQPBQSO.__esm)({
8019
8021
  "src/function-info.ts"() {
8020
8022
  "use strict";
8021
8023
  init_ast();
@@ -8077,7 +8079,7 @@ function renameVariable(state, locals, declName2) {
8077
8079
  map2[name] = true;
8078
8080
  return name;
8079
8081
  }
8080
- var init_variable_renamer = (0, import_chunk_HHQDDCTP.__esm)({
8082
+ var init_variable_renamer = (0, import_chunk_QFQPBQSO.__esm)({
8081
8083
  "src/variable-renamer.ts"() {
8082
8084
  "use strict";
8083
8085
  init_api();
@@ -8910,7 +8912,7 @@ function fixNodeScope(state, lookupNode, nodeStack) {
8910
8912
  }
8911
8913
  return null;
8912
8914
  }
8913
- var init_inliner = (0, import_chunk_HHQDDCTP.__esm)({
8915
+ var init_inliner = (0, import_chunk_QFQPBQSO.__esm)({
8914
8916
  "src/inliner.ts"() {
8915
8917
  "use strict";
8916
8918
  init_api();
@@ -8920,7 +8922,7 @@ var init_inliner = (0, import_chunk_HHQDDCTP.__esm)({
8920
8922
  }
8921
8923
  });
8922
8924
  var StateNodeAttributes;
8923
- var init_optimizer_types = (0, import_chunk_HHQDDCTP.__esm)({
8925
+ var init_optimizer_types = (0, import_chunk_QFQPBQSO.__esm)({
8924
8926
  "src/optimizer-types.ts"() {
8925
8927
  "use strict";
8926
8928
  StateNodeAttributes = /* @__PURE__ */ ((StateNodeAttributes2) => {
@@ -9066,7 +9068,7 @@ function pragmaChecker(state, ast, diagnostics) {
9066
9068
  return null;
9067
9069
  });
9068
9070
  }
9069
- var init_pragma_checker = (0, import_chunk_HHQDDCTP.__esm)({
9071
+ var init_pragma_checker = (0, import_chunk_QFQPBQSO.__esm)({
9070
9072
  "src/pragma-checker.ts"() {
9071
9073
  "use strict";
9072
9074
  init_api();
@@ -9427,9 +9429,9 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
9427
9429
  );
9428
9430
  }
9429
9431
  } else {
9430
- (0, import_chunk_HHQDDCTP.forEach)(events, (e) => e.mayThrow = false);
9432
+ (0, import_chunk_QFQPBQSO.forEach)(events, (e) => e.mayThrow = false);
9431
9433
  }
9432
- (0, import_chunk_HHQDDCTP.forEach)(events, (event) => {
9434
+ (0, import_chunk_QFQPBQSO.forEach)(events, (event) => {
9433
9435
  if (event.mayThrow) {
9434
9436
  for (let i = localState.stack.length; i--; ) {
9435
9437
  const target = localState.stack[i].throw;
@@ -9570,11 +9572,11 @@ function getPostOrder(head) {
9570
9572
  return blocks;
9571
9573
  }
9572
9574
  var Terminals, LocalState;
9573
- var init_control_flow = (0, import_chunk_HHQDDCTP.__esm)({
9575
+ var init_control_flow = (0, import_chunk_QFQPBQSO.__esm)({
9574
9576
  "src/control-flow.ts"() {
9575
9577
  "use strict";
9576
9578
  init_ast();
9577
- (0, import_chunk_HHQDDCTP.init_util)();
9579
+ (0, import_chunk_QFQPBQSO.init_util)();
9578
9580
  Terminals = {
9579
9581
  BreakStatement: "break",
9580
9582
  ContinueStatement: "continue",
@@ -9604,12 +9606,12 @@ var init_control_flow = (0, import_chunk_HHQDDCTP.__esm)({
9604
9606
  if (!from.succs) {
9605
9607
  from.succs = [to];
9606
9608
  } else {
9607
- (0, import_chunk_HHQDDCTP.pushUnique)(from.succs, to);
9609
+ (0, import_chunk_QFQPBQSO.pushUnique)(from.succs, to);
9608
9610
  }
9609
9611
  if (!to.preds) {
9610
9612
  to.preds = [from];
9611
9613
  } else {
9612
- (0, import_chunk_HHQDDCTP.pushUnique)(to.preds, from);
9614
+ (0, import_chunk_QFQPBQSO.pushUnique)(to.preds, from);
9613
9615
  }
9614
9616
  }
9615
9617
  newBlock(block) {
@@ -9882,8 +9884,8 @@ function mergeObjectValues(to, from) {
9882
9884
  function mergeStateDecls(to, from) {
9883
9885
  let changed = false;
9884
9886
  let result = to;
9885
- (0, import_chunk_HHQDDCTP.forEach)(from, (v) => {
9886
- if ((0, import_chunk_HHQDDCTP.some)(to, (t) => t === v)) {
9887
+ (0, import_chunk_QFQPBQSO.forEach)(from, (v) => {
9888
+ if ((0, import_chunk_QFQPBQSO.some)(to, (t) => t === v)) {
9887
9889
  return;
9888
9890
  }
9889
9891
  if (Array.isArray(result)) {
@@ -10009,12 +10011,12 @@ function widenTypeHelper(t, depth) {
10009
10011
  function widenType(t) {
10010
10012
  return widenTypeHelper(t, 0);
10011
10013
  }
10012
- var init_union_type = (0, import_chunk_HHQDDCTP.__esm)({
10014
+ var init_union_type = (0, import_chunk_QFQPBQSO.__esm)({
10013
10015
  "src/type-flow/union-type.ts"() {
10014
10016
  "use strict";
10015
10017
  init_ast();
10016
10018
  init_data_flow();
10017
- (0, import_chunk_HHQDDCTP.init_util)();
10019
+ (0, import_chunk_QFQPBQSO.init_util)();
10018
10020
  init_intersection_type();
10019
10021
  init_sub_type();
10020
10022
  init_types();
@@ -10028,7 +10030,7 @@ function expandTypedef(t) {
10028
10030
  );
10029
10031
  const tExpanded = cloneType(t);
10030
10032
  clearValuesUnder(tExpanded, 262144, true);
10031
- (0, import_chunk_HHQDDCTP.forEach)(decls, (decl) => unionInto(tExpanded, decl.resolvedType));
10033
+ (0, import_chunk_QFQPBQSO.forEach)(decls, (decl) => unionInto(tExpanded, decl.resolvedType));
10032
10034
  return tExpanded;
10033
10035
  }
10034
10036
  function intersectEnum(t, e) {
@@ -10180,9 +10182,9 @@ function intersectionValue(pair) {
10180
10182
  case 4096:
10181
10183
  case 8192: {
10182
10184
  const common = [];
10183
- (0, import_chunk_HHQDDCTP.forEach)(
10185
+ (0, import_chunk_QFQPBQSO.forEach)(
10184
10186
  pair.avalue,
10185
- (sna) => (0, import_chunk_HHQDDCTP.some)(pair.bvalue, (snb) => sna === snb) && common.push(sna)
10187
+ (sna) => (0, import_chunk_QFQPBQSO.some)(pair.bvalue, (snb) => sna === snb) && common.push(sna)
10186
10188
  );
10187
10189
  if (!common.length)
10188
10190
  return null;
@@ -10190,9 +10192,9 @@ function intersectionValue(pair) {
10190
10192
  }
10191
10193
  case 16384: {
10192
10194
  const common = [];
10193
- (0, import_chunk_HHQDDCTP.forEach)(pair.avalue, (sna) => {
10195
+ (0, import_chunk_QFQPBQSO.forEach)(pair.avalue, (sna) => {
10194
10196
  const superA = getSuperClasses(sna);
10195
- (0, import_chunk_HHQDDCTP.forEach)(pair.bvalue, (snb) => {
10197
+ (0, import_chunk_QFQPBQSO.forEach)(pair.bvalue, (snb) => {
10196
10198
  if (sna === snb || superA && superA.has(snb)) {
10197
10199
  common.push(sna);
10198
10200
  }
@@ -10413,7 +10415,7 @@ function restrictExactTypesByEquality(a, b) {
10413
10415
  }
10414
10416
  case 262144:
10415
10417
  return restrictByEquality(
10416
- (0, import_chunk_HHQDDCTP.reduce)(
10418
+ (0, import_chunk_QFQPBQSO.reduce)(
10417
10419
  a.value,
10418
10420
  (cur, decl) => {
10419
10421
  unionInto(cur, decl.resolvedType);
@@ -10475,12 +10477,12 @@ function restrictByEquality(a, b) {
10475
10477
  }
10476
10478
  return restrictByEqualityByComponent(a, b);
10477
10479
  }
10478
- var init_intersection_type = (0, import_chunk_HHQDDCTP.__esm)({
10480
+ var init_intersection_type = (0, import_chunk_QFQPBQSO.__esm)({
10479
10481
  "src/type-flow/intersection-type.ts"() {
10480
10482
  "use strict";
10481
10483
  init_api();
10482
10484
  init_data_flow();
10483
- (0, import_chunk_HHQDDCTP.init_util)();
10485
+ (0, import_chunk_QFQPBQSO.init_util)();
10484
10486
  init_could_be();
10485
10487
  init_interp();
10486
10488
  init_types();
@@ -10566,14 +10568,14 @@ function subtypeOfValue(pair) {
10566
10568
  case 8192: {
10567
10569
  const asd = pair.avalue;
10568
10570
  const bsd = pair.bvalue;
10569
- return (0, import_chunk_HHQDDCTP.some)(asd, (sna) => (0, import_chunk_HHQDDCTP.some)(bsd, (snb) => sna === snb));
10571
+ return (0, import_chunk_QFQPBQSO.some)(asd, (sna) => (0, import_chunk_QFQPBQSO.some)(bsd, (snb) => sna === snb));
10570
10572
  }
10571
10573
  case 16384: {
10572
10574
  const asd = pair.avalue;
10573
10575
  const bsd = pair.bvalue;
10574
- return (0, import_chunk_HHQDDCTP.every)(asd, (sna) => {
10576
+ return (0, import_chunk_QFQPBQSO.every)(asd, (sna) => {
10575
10577
  const superA = getSuperClasses(sna);
10576
- return (0, import_chunk_HHQDDCTP.some)(bsd, (snb) => {
10578
+ return (0, import_chunk_QFQPBQSO.some)(bsd, (snb) => {
10577
10579
  if (sna === snb || superA && superA.has(snb)) {
10578
10580
  return true;
10579
10581
  }
@@ -10604,12 +10606,12 @@ function subtypeOfObj(a, b) {
10604
10606
  return subtypeOf(a[key], value2);
10605
10607
  });
10606
10608
  }
10607
- var init_sub_type = (0, import_chunk_HHQDDCTP.__esm)({
10609
+ var init_sub_type = (0, import_chunk_QFQPBQSO.__esm)({
10608
10610
  "src/type-flow/sub-type.ts"() {
10609
10611
  "use strict";
10610
10612
  init_api();
10611
10613
  init_data_flow();
10612
- (0, import_chunk_HHQDDCTP.init_util)();
10614
+ (0, import_chunk_QFQPBQSO.init_util)();
10613
10615
  init_intersection_type();
10614
10616
  init_types();
10615
10617
  init_union_type();
@@ -10942,7 +10944,7 @@ function evaluateLogicalTypes(op, left, right) {
10942
10944
  }
10943
10945
  }
10944
10946
  var operators;
10945
- var init_interp_binary = (0, import_chunk_HHQDDCTP.__esm)({
10947
+ var init_interp_binary = (0, import_chunk_QFQPBQSO.__esm)({
10946
10948
  "src/type-flow/interp-binary.ts"() {
10947
10949
  "use strict";
10948
10950
  init_could_be();
@@ -10957,13 +10959,13 @@ function isTypeStateKey(decl) {
10957
10959
  return Array.isArray(decl) || decl.type !== "MemberDecl" && decl.type !== "Unknown";
10958
10960
  }
10959
10961
  function declIsLocal(decl) {
10960
- return (0, import_chunk_HHQDDCTP.some)(
10962
+ return (0, import_chunk_QFQPBQSO.some)(
10961
10963
  decl,
10962
10964
  (d) => d.type === "BinaryExpression" || d.type === "Identifier" || d.type === "VariableDeclarator" && isLocal(d)
10963
10965
  );
10964
10966
  }
10965
10967
  function declIsNonLocal(decl) {
10966
- return (0, import_chunk_HHQDDCTP.some)(decl, (d) => d.type === "VariableDeclarator" && !isLocal(d));
10968
+ return (0, import_chunk_QFQPBQSO.some)(decl, (d) => d.type === "VariableDeclarator" && !isLocal(d));
10967
10969
  }
10968
10970
  function localDeclName(decl) {
10969
10971
  if (Array.isArray(decl))
@@ -10979,7 +10981,7 @@ function localDeclName(decl) {
10979
10981
  throw new Error(`Invalid local decl: ${declFullName(decl)}`);
10980
10982
  }
10981
10983
  function tsKey(key) {
10982
- return `${(0, import_chunk_HHQDDCTP.map)(key, (k) => {
10984
+ return `${(0, import_chunk_QFQPBQSO.map)(key, (k) => {
10983
10985
  if (k.type === "Literal") {
10984
10986
  return k.raw;
10985
10987
  } else if (isStateNode(k)) {
@@ -11011,7 +11013,7 @@ function describeEvent(event) {
11011
11013
  }
11012
11014
  function printBlockEvents(block, extra) {
11013
11015
  console.log("Events:");
11014
- (0, import_chunk_HHQDDCTP.forEach)(
11016
+ (0, import_chunk_QFQPBQSO.forEach)(
11015
11017
  block.events,
11016
11018
  (event) => console.log(` ${describeEvent(event)} ${extra ? extra(event) : ""}`)
11017
11019
  );
@@ -11128,12 +11130,12 @@ function resolveDottedMember(istate, object, next) {
11128
11130
  const mayThrow2 = !subtypeOf(object, type);
11129
11131
  return { mayThrow: mayThrow2, object: type, property };
11130
11132
  }
11131
- var init_type_flow_util = (0, import_chunk_HHQDDCTP.__esm)({
11133
+ var init_type_flow_util = (0, import_chunk_QFQPBQSO.__esm)({
11132
11134
  "src/type-flow/type-flow-util.ts"() {
11133
11135
  "use strict";
11134
11136
  init_api();
11135
11137
  init_data_flow();
11136
- (0, import_chunk_HHQDDCTP.init_util)();
11138
+ (0, import_chunk_QFQPBQSO.init_util)();
11137
11139
  init_intersection_type();
11138
11140
  init_sub_type();
11139
11141
  init_types();
@@ -11185,7 +11187,7 @@ function calleeObjectType(istate, callee) {
11185
11187
  }
11186
11188
  function checkCallArgs(istate, node, callees, args) {
11187
11189
  const allDiags = [];
11188
- const resultType = (0, import_chunk_HHQDDCTP.reduce)(
11190
+ const resultType = (0, import_chunk_QFQPBQSO.reduce)(
11189
11191
  callees,
11190
11192
  (result, cur) => {
11191
11193
  const curDiags = [];
@@ -11334,7 +11336,7 @@ function isOverride(cur, funcs) {
11334
11336
  const cls = cur.stack?.[cur.stack.length - 1]?.sn;
11335
11337
  if (cls?.type === "ClassDeclaration" && cls.superClasses) {
11336
11338
  const supers = getSuperClasses(cls);
11337
- if (supers && (0, import_chunk_HHQDDCTP.some)(funcs, (func) => {
11339
+ if (supers && (0, import_chunk_QFQPBQSO.some)(funcs, (func) => {
11338
11340
  if (func === cur)
11339
11341
  return false;
11340
11342
  const fcls = func.stack?.[func.stack.length - 1].sn;
@@ -11720,12 +11722,12 @@ function expandKeys(state, table) {
11720
11722
  return result;
11721
11723
  }
11722
11724
  var systemCallInfo, systemCallVersion;
11723
- var init_interp_call = (0, import_chunk_HHQDDCTP.__esm)({
11725
+ var init_interp_call = (0, import_chunk_QFQPBQSO.__esm)({
11724
11726
  "src/type-flow/interp-call.ts"() {
11725
11727
  "use strict";
11726
11728
  init_optimizer_types();
11727
11729
  init_api();
11728
- (0, import_chunk_HHQDDCTP.init_util)();
11730
+ (0, import_chunk_QFQPBQSO.init_util)();
11729
11731
  init_interp();
11730
11732
  init_sub_type();
11731
11733
  init_types();
@@ -12628,7 +12630,7 @@ function mustBeIdentical(a, b) {
12628
12630
  }
12629
12631
  return false;
12630
12632
  }
12631
- var init_interp = (0, import_chunk_HHQDDCTP.__esm)({
12633
+ var init_interp = (0, import_chunk_QFQPBQSO.__esm)({
12632
12634
  "src/type-flow/interp.ts"() {
12633
12635
  "use strict";
12634
12636
  init_api();
@@ -12847,7 +12849,7 @@ function typeFromTypeStateNode(state, sn, classVsObj) {
12847
12849
  );
12848
12850
  if (value2) {
12849
12851
  const a = [];
12850
- (0, import_chunk_HHQDDCTP.forEach)(value2, (v) => {
12852
+ (0, import_chunk_QFQPBQSO.forEach)(value2, (v) => {
12851
12853
  if (v !== sn)
12852
12854
  a.push(v);
12853
12855
  });
@@ -13222,7 +13224,7 @@ function mustBeFalse(arg) {
13222
13224
  return arg.type === 1 || arg.type === 2 || (arg.type === 8 || arg.type === 16) && arg.value != null && Number(arg.value) === 0;
13223
13225
  }
13224
13226
  function display(type) {
13225
- const names = (v, fn) => (0, import_chunk_HHQDDCTP.map)(v, fn).sort().filter((s, i, arr) => !i || s !== arr[i - 1]).join(" or ");
13227
+ const names = (v, fn) => (0, import_chunk_QFQPBQSO.map)(v, fn).sort().filter((s, i, arr) => !i || s !== arr[i - 1]).join(" or ");
13226
13228
  const parts = [];
13227
13229
  const displayOne = (tv) => {
13228
13230
  switch (tv.type) {
@@ -13413,13 +13415,13 @@ function getStateNodeDeclsFromType(state, object) {
13413
13415
  return decls;
13414
13416
  }
13415
13417
  var LastTypeTag, SingletonTypeTagsConst, UnionDataTypeTagsConst, ValueTypeTagsConst, ObjectLikeTagsConst, EnumTagsConst, TruthyTypes;
13416
- var init_types = (0, import_chunk_HHQDDCTP.__esm)({
13418
+ var init_types = (0, import_chunk_QFQPBQSO.__esm)({
13417
13419
  "src/type-flow/types.ts"() {
13418
13420
  "use strict";
13419
13421
  init_data_flow();
13420
13422
  init_api();
13421
13423
  init_ast();
13422
- (0, import_chunk_HHQDDCTP.init_util)();
13424
+ (0, import_chunk_QFQPBQSO.init_util)();
13423
13425
  init_interp();
13424
13426
  init_union_type();
13425
13427
  init_intersection_type();
@@ -13475,7 +13477,7 @@ function couldBeHelper(a, b, shallow) {
13475
13477
  262144
13476
13478
  /* Typedef */
13477
13479
  );
13478
- return typedef && (0, import_chunk_HHQDDCTP.some)(typedef, (td) => {
13480
+ return typedef && (0, import_chunk_QFQPBQSO.some)(typedef, (td) => {
13479
13481
  if (!td.resolvedType) {
13480
13482
  throw new Error(`No resolved type for ${td.fullName} in 'couldBe'`);
13481
13483
  }
@@ -13526,15 +13528,15 @@ function couldBeValue(pair, shallow) {
13526
13528
  }
13527
13529
  case 4096:
13528
13530
  case 8192: {
13529
- return (0, import_chunk_HHQDDCTP.some)(
13531
+ return (0, import_chunk_QFQPBQSO.some)(
13530
13532
  pair.avalue,
13531
- (sna) => (0, import_chunk_HHQDDCTP.some)(pair.bvalue, (snb) => sna === snb)
13533
+ (sna) => (0, import_chunk_QFQPBQSO.some)(pair.bvalue, (snb) => sna === snb)
13532
13534
  );
13533
13535
  }
13534
13536
  case 16384: {
13535
- return (0, import_chunk_HHQDDCTP.some)(pair.avalue, (sna) => {
13537
+ return (0, import_chunk_QFQPBQSO.some)(pair.avalue, (sna) => {
13536
13538
  const superA = getSuperClasses(sna);
13537
- return (0, import_chunk_HHQDDCTP.some)(pair.bvalue, (snb) => {
13539
+ return (0, import_chunk_QFQPBQSO.some)(pair.bvalue, (snb) => {
13538
13540
  if (sna === snb || superA && superA.has(snb)) {
13539
13541
  return true;
13540
13542
  }
@@ -13562,12 +13564,12 @@ function couldBeObj(a, b) {
13562
13564
  return couldBe(value2, b[key]);
13563
13565
  });
13564
13566
  }
13565
- var init_could_be = (0, import_chunk_HHQDDCTP.__esm)({
13567
+ var init_could_be = (0, import_chunk_QFQPBQSO.__esm)({
13566
13568
  "src/type-flow/could-be.ts"() {
13567
13569
  "use strict";
13568
13570
  init_api();
13569
13571
  init_data_flow();
13570
- (0, import_chunk_HHQDDCTP.init_util)();
13572
+ (0, import_chunk_QFQPBQSO.init_util)();
13571
13573
  init_types();
13572
13574
  }
13573
13575
  });
@@ -13888,7 +13890,7 @@ function eliminateDeadStores(state, func, graph, logThisRun) {
13888
13890
  });
13889
13891
  return { copyPropStores, changes };
13890
13892
  }
13891
- var init_dead_store = (0, import_chunk_HHQDDCTP.__esm)({
13893
+ var init_dead_store = (0, import_chunk_QFQPBQSO.__esm)({
13892
13894
  "src/type-flow/dead-store.ts"() {
13893
13895
  "use strict";
13894
13896
  init_api();
@@ -14484,7 +14486,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
14484
14486
  }
14485
14487
  if (selfClassDecl) {
14486
14488
  const baseObj = getObjectValue(baseElem.type);
14487
- if (baseObj && baseObj.klass.type === 16384 && (0, import_chunk_HHQDDCTP.some)(
14489
+ if (baseObj && baseObj.klass.type === 16384 && (0, import_chunk_QFQPBQSO.some)(
14488
14490
  baseObj.klass.value,
14489
14491
  (cls) => cls === selfClassDecl || getSuperClasses(cls)?.has(selfClassDecl) || getSuperClasses(selfClassDecl)?.has(cls) || false
14490
14492
  )) {
@@ -14529,7 +14531,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
14529
14531
  return [next, updateAny];
14530
14532
  }
14531
14533
  function typeConstraint(decls) {
14532
- return (0, import_chunk_HHQDDCTP.reduce)(
14534
+ return (0, import_chunk_QFQPBQSO.reduce)(
14533
14535
  decls,
14534
14536
  (cur, decl) => {
14535
14537
  if (decl.type === "Identifier" || decl.type === "BinaryExpression") {
@@ -14622,9 +14624,9 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
14622
14624
  stack: [],
14623
14625
  func
14624
14626
  };
14625
- const modifiableDecl = (decls, callees) => (0, import_chunk_HHQDDCTP.some)(
14627
+ const modifiableDecl = (decls, callees) => (0, import_chunk_QFQPBQSO.some)(
14626
14628
  decls,
14627
- (decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" && !isLocal(decl) && (!callees || (0, import_chunk_HHQDDCTP.some)(callees, (callee) => functionMayModify(state, callee, decl)))
14629
+ (decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" && !isLocal(decl) && (!callees || (0, import_chunk_QFQPBQSO.some)(callees, (callee) => functionMayModify(state, callee, decl)))
14628
14630
  );
14629
14631
  const mergeSuccState = (top, curState) => {
14630
14632
  top.succs?.forEach((succ) => {
@@ -14645,7 +14647,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
14645
14647
  type: 0
14646
14648
  /* Never */
14647
14649
  };
14648
- const result = (0, import_chunk_HHQDDCTP.every)(callees, (callee) => {
14650
+ const result = (0, import_chunk_QFQPBQSO.every)(callees, (callee) => {
14649
14651
  const info = sysCallInfo(istate.state, callee);
14650
14652
  if (!info)
14651
14653
  return false;
@@ -15045,7 +15047,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
15045
15047
  );
15046
15048
  }
15047
15049
  }
15048
- if (nodeCopyProp.size && event.node.type === "CallExpression" && (0, import_chunk_HHQDDCTP.some)(callees, (callee) => inlineRequested(state, callee))) {
15050
+ if (nodeCopyProp.size && event.node.type === "CallExpression" && (0, import_chunk_QFQPBQSO.some)(callees, (callee) => inlineRequested(state, callee))) {
15049
15051
  event.node.arguments.forEach((arg) => {
15050
15052
  const def = nodeCopyProp.get(arg);
15051
15053
  if (def && nodeCopyProp.get(def) !== false) {
@@ -15057,7 +15059,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
15057
15059
  let calleeEffects;
15058
15060
  curState.map.forEach((tsv, decl) => {
15059
15061
  let type = tsv.curType;
15060
- if ((type.value == null || !(type.type & (32768 | 512 | 1024))) && !(0, import_chunk_HHQDDCTP.some)(decl, (d) => d.type === "VariableDeclarator" && !isLocal(d))) {
15062
+ if ((type.value == null || !(type.type & (32768 | 512 | 1024))) && !(0, import_chunk_QFQPBQSO.some)(decl, (d) => d.type === "VariableDeclarator" && !isLocal(d))) {
15061
15063
  return;
15062
15064
  }
15063
15065
  if (modifiableDecl(decl, callees)) {
@@ -15070,7 +15072,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
15070
15072
  (0, import_node_assert3.default)(!tsv.copyPropItem);
15071
15073
  clearRelatedCopyPropEvents(curState, decl, nodeCopyProp);
15072
15074
  curState.map.set(decl, { curType: typeConstraint(decl) });
15073
- } else if (type.type & (32768 | 512 | 1024) && (calleeEffects == null ? calleeEffects = !callees || !(0, import_chunk_HHQDDCTP.every)(callees, (callee) => callee.info === false) : calleeEffects)) {
15075
+ } else if (type.type & (32768 | 512 | 1024) && (calleeEffects == null ? calleeEffects = !callees || !(0, import_chunk_QFQPBQSO.every)(callees, (callee) => callee.info === false) : calleeEffects)) {
15074
15076
  if (type.value != null && type.type & 32768) {
15075
15077
  const odata = getObjectValue(tsv.curType);
15076
15078
  if (odata?.obj) {
@@ -15118,7 +15120,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
15118
15120
  2
15119
15121
  /* Reassign */
15120
15122
  );
15121
- (0, import_chunk_HHQDDCTP.some)(event.decl, (decl) => {
15123
+ (0, import_chunk_QFQPBQSO.some)(event.decl, (decl) => {
15122
15124
  if (decl.type !== "VariableDeclarator" || decl.node.kind !== "var" || !isClassVariable(decl)) {
15123
15125
  return false;
15124
15126
  }
@@ -15126,7 +15128,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
15126
15128
  if (affected) {
15127
15129
  const objType = typeFromTypeStateNodes(
15128
15130
  istate.state,
15129
- (0, import_chunk_HHQDDCTP.map)(
15131
+ (0, import_chunk_QFQPBQSO.map)(
15130
15132
  event.decl,
15131
15133
  (decl2) => decl2.type === "VariableDeclarator" && decl2.stack[decl2.stack.length - 1].sn
15132
15134
  ).filter(
@@ -15147,7 +15149,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
15147
15149
  });
15148
15150
  if (wasComputedDecl) {
15149
15151
  curState.map.forEach((value2, decls) => {
15150
- if ((0, import_chunk_HHQDDCTP.some)(
15152
+ if ((0, import_chunk_QFQPBQSO.some)(
15151
15153
  decls,
15152
15154
  (decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" && !isLocal(decl)
15153
15155
  )) {
@@ -15191,14 +15193,14 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
15191
15193
  }
15192
15194
  if (!copyPropCandidate.ant || // If the ref isn't anticipated, we can't propagate it
15193
15195
  // in case it has side effects.
15194
- (0, import_chunk_HHQDDCTP.some)(
15196
+ (0, import_chunk_QFQPBQSO.some)(
15195
15197
  event2.calleeDecl,
15196
15198
  (callee) => callee.type === "FunctionDeclaration" && inlineRequested(state, callee)
15197
15199
  )) {
15198
15200
  return false;
15199
15201
  }
15200
15202
  }
15201
- if (!event2.decl || isTypeStateKey(event2.decl) && (0, import_chunk_HHQDDCTP.some)(
15203
+ if (!event2.decl || isTypeStateKey(event2.decl) && (0, import_chunk_QFQPBQSO.some)(
15202
15204
  event2.decl,
15203
15205
  (decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" || decl.type === "BinaryExpression" || decl.type === "Identifier"
15204
15206
  )) {
@@ -15306,7 +15308,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
15306
15308
  if (!successorsHandled) {
15307
15309
  if (logThisRun) {
15308
15310
  console.log(
15309
- ` merge to: ${(0, import_chunk_HHQDDCTP.map)(
15311
+ ` merge to: ${(0, import_chunk_QFQPBQSO.map)(
15310
15312
  top.succs,
15311
15313
  (succ) => succ.order || -1
15312
15314
  ).join(", ")}`
@@ -15543,7 +15545,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
15543
15545
  }, curInfo);
15544
15546
  if (rep === curInfo)
15545
15547
  return null;
15546
- const name = (0, import_chunk_HHQDDCTP.reduce)(
15548
+ const name = (0, import_chunk_QFQPBQSO.reduce)(
15547
15549
  rep.decl,
15548
15550
  (cur, decl) => decl.type === "VariableDeclarator" ? decl.name : cur,
15549
15551
  null
@@ -15644,7 +15646,7 @@ function updateByAssocPath(path7, property, union) {
15644
15646
  return property;
15645
15647
  }
15646
15648
  var logging, missingNullWorkaround;
15647
- var init_type_flow = (0, import_chunk_HHQDDCTP.__esm)({
15649
+ var init_type_flow = (0, import_chunk_QFQPBQSO.__esm)({
15648
15650
  "src/type-flow.ts"() {
15649
15651
  "use strict";
15650
15652
  init_api();
@@ -15663,7 +15665,7 @@ var init_type_flow = (0, import_chunk_HHQDDCTP.__esm)({
15663
15665
  init_type_flow_util();
15664
15666
  init_types();
15665
15667
  init_union_type();
15666
- (0, import_chunk_HHQDDCTP.init_util)();
15668
+ (0, import_chunk_QFQPBQSO.init_util)();
15667
15669
  logging = true;
15668
15670
  missingNullWorkaround = true;
15669
15671
  }
@@ -15980,7 +15982,7 @@ function variableCleanup(node) {
15980
15982
  }
15981
15983
  return null;
15982
15984
  }
15983
- var init_minimize_locals = (0, import_chunk_HHQDDCTP.__esm)({
15985
+ var init_minimize_locals = (0, import_chunk_QFQPBQSO.__esm)({
15984
15986
  "src/type-flow/minimize-locals.ts"() {
15985
15987
  "use strict";
15986
15988
  init_api();
@@ -16108,7 +16110,7 @@ function buildPREGraph(state, func) {
16108
16110
  const event = block.events[i];
16109
16111
  switch (event.type) {
16110
16112
  case "ref":
16111
- if ((0, import_chunk_HHQDDCTP.some)(
16113
+ if ((0, import_chunk_QFQPBQSO.some)(
16112
16114
  event.decl,
16113
16115
  (decl) => decl.type === "Literal" || decl.type === "VariableDeclarator" && decl.node.kind === "const"
16114
16116
  )) {
@@ -16126,7 +16128,7 @@ function buildPREGraph(state, func) {
16126
16128
  defs.add(event.decl);
16127
16129
  break;
16128
16130
  case "mod":
16129
- if (event.callees && (0, import_chunk_HHQDDCTP.every)(event.callees, (callee) => callee.info === false)) {
16131
+ if (event.callees && (0, import_chunk_QFQPBQSO.every)(event.callees, (callee) => callee.info === false)) {
16130
16132
  block.events.splice(i, 1);
16131
16133
  break;
16132
16134
  }
@@ -16365,7 +16367,7 @@ function computeAttributes(state, head) {
16365
16367
  }
16366
16368
  case "mod": {
16367
16369
  curState.forEach((candidates, decls) => {
16368
- if ((0, import_chunk_HHQDDCTP.some)(
16370
+ if ((0, import_chunk_QFQPBQSO.some)(
16369
16371
  decls,
16370
16372
  (decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" && candidates.live && (!event.callees || event.callees.some(
16371
16373
  (callee) => functionMayModify(state, callee, decl)
@@ -16645,7 +16647,7 @@ function applyReplacements(func, nodeMap, declMap) {
16645
16647
  );
16646
16648
  }
16647
16649
  var logging2, LocalRefCost;
16648
- var init_pre = (0, import_chunk_HHQDDCTP.__esm)({
16650
+ var init_pre = (0, import_chunk_QFQPBQSO.__esm)({
16649
16651
  "src/pre.ts"() {
16650
16652
  "use strict";
16651
16653
  init_api();
@@ -16654,7 +16656,7 @@ var init_pre = (0, import_chunk_HHQDDCTP.__esm)({
16654
16656
  init_data_flow();
16655
16657
  init_function_info();
16656
16658
  init_minimize_locals();
16657
- (0, import_chunk_HHQDDCTP.init_util)();
16659
+ (0, import_chunk_QFQPBQSO.init_util)();
16658
16660
  logging2 = false;
16659
16661
  LocalRefCost = 2;
16660
16662
  }
@@ -16834,7 +16836,7 @@ function isImportCandidate(module2, stack) {
16834
16836
  );
16835
16837
  });
16836
16838
  }
16837
- var init_minimize_modules = (0, import_chunk_HHQDDCTP.__esm)({
16839
+ var init_minimize_modules = (0, import_chunk_QFQPBQSO.__esm)({
16838
16840
  "src/type-flow/minimize-modules.ts"() {
16839
16841
  "use strict";
16840
16842
  init_api();
@@ -16960,7 +16962,7 @@ function beforeEvaluate(istate, node) {
16960
16962
  case "UnaryExpression":
16961
16963
  if (node.operator === "-") {
16962
16964
  const [arg] = istate.stack.slice(-1);
16963
- if ((arg.value.type & (8 | 16)) === arg.value.type && arg.value.value == null) {
16965
+ if ((arg.value.type & 120) === arg.value.type && arg.value.value == null) {
16964
16966
  const leftType = { type: 8, value: 0 };
16965
16967
  const rep = withLoc(
16966
16968
  {
@@ -16988,7 +16990,7 @@ function beforeEvaluate(istate, node) {
16988
16990
  break;
16989
16991
  }
16990
16992
  const id = node.right.argument;
16991
- if ((0, import_chunk_HHQDDCTP.every)(left.value.value, (m) => {
16993
+ if ((0, import_chunk_QFQPBQSO.every)(left.value.value, (m) => {
16992
16994
  if (hasProperty(m.decls, id.name))
16993
16995
  return false;
16994
16996
  return istate.state.lookup({
@@ -17428,13 +17430,13 @@ function tryDeEnumerate(istate, node, elem) {
17428
17430
  }
17429
17431
  return null;
17430
17432
  }
17431
- var init_optimize = (0, import_chunk_HHQDDCTP.__esm)({
17433
+ var init_optimize = (0, import_chunk_QFQPBQSO.__esm)({
17432
17434
  "src/type-flow/optimize.ts"() {
17433
17435
  "use strict";
17434
17436
  init_ast();
17435
17437
  init_inliner();
17436
17438
  init_type_flow();
17437
- (0, import_chunk_HHQDDCTP.init_util)();
17439
+ (0, import_chunk_QFQPBQSO.init_util)();
17438
17440
  init_interp();
17439
17441
  init_interp_binary();
17440
17442
  init_types();
@@ -17601,7 +17603,7 @@ function cleanupUnusedVars(state, node) {
17601
17603
  });
17602
17604
  return changes;
17603
17605
  }
17604
- var init_unused_exprs = (0, import_chunk_HHQDDCTP.__esm)({
17606
+ var init_unused_exprs = (0, import_chunk_QFQPBQSO.__esm)({
17605
17607
  "src/unused-exprs.ts"() {
17606
17608
  "use strict";
17607
17609
  init_api();
@@ -17966,7 +17968,7 @@ function markFunctionCalled(state, func) {
17966
17968
  state.calledFunctions[func.id.name] = [func];
17967
17969
  return;
17968
17970
  }
17969
- (0, import_chunk_HHQDDCTP.pushUnique)(state.calledFunctions[func.id.name], func);
17971
+ (0, import_chunk_QFQPBQSO.pushUnique)(state.calledFunctions[func.id.name], func);
17970
17972
  }
17971
17973
  async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
17972
17974
  const state = await analyze(
@@ -18606,7 +18608,7 @@ function optimizeCall(istate, node, context) {
18606
18608
  callees.forEach((c) => markFunctionCalled(state, c.node));
18607
18609
  return null;
18608
18610
  }
18609
- var init_mc_rewrite = (0, import_chunk_HHQDDCTP.__esm)({
18611
+ var init_mc_rewrite = (0, import_chunk_QFQPBQSO.__esm)({
18610
18612
  "src/mc-rewrite.ts"() {
18611
18613
  "use strict";
18612
18614
  init_api();
@@ -18624,12 +18626,12 @@ var init_mc_rewrite = (0, import_chunk_HHQDDCTP.__esm)({
18624
18626
  init_sub_type();
18625
18627
  init_types();
18626
18628
  init_unused_exprs();
18627
- (0, import_chunk_HHQDDCTP.init_util)();
18629
+ (0, import_chunk_QFQPBQSO.init_util)();
18628
18630
  init_variable_renamer();
18629
18631
  }
18630
18632
  });
18631
18633
  var negativeFixups;
18632
- var init_negative_fixups = (0, import_chunk_HHQDDCTP.__esm)({
18634
+ var init_negative_fixups = (0, import_chunk_QFQPBQSO.__esm)({
18633
18635
  "src/negative-fixups.ts"() {
18634
18636
  "use strict";
18635
18637
  negativeFixups = [
@@ -19174,7 +19176,7 @@ function add_one_resource(state, doc, module2, e) {
19174
19176
  }
19175
19177
  }
19176
19178
  var drawableSkips;
19177
- var init_resources = (0, import_chunk_HHQDDCTP.__esm)({
19179
+ var init_resources = (0, import_chunk_QFQPBQSO.__esm)({
19178
19180
  "src/resources.ts"() {
19179
19181
  "use strict";
19180
19182
  init_api();
@@ -19378,7 +19380,7 @@ function visitReferences(state, ast, name, defn, callback, includeDefs = false,
19378
19380
  collectNamespaces(ast, state);
19379
19381
  delete state.pre;
19380
19382
  }
19381
- var init_visitor = (0, import_chunk_HHQDDCTP.__esm)({
19383
+ var init_visitor = (0, import_chunk_QFQPBQSO.__esm)({
19382
19384
  "src/visitor.ts"() {
19383
19385
  "use strict";
19384
19386
  init_api();
@@ -19550,11 +19552,11 @@ function sameStateNodeDecl(a, b) {
19550
19552
  function sameLookupDefinition(a, b) {
19551
19553
  return (
19552
19554
  // sameStateNodeDecl(a.parent, b.parent) &&
19553
- (0, import_chunk_HHQDDCTP.sameArrays)(a.results, b.results, (ar, br) => sameStateNodeDecl(ar, br))
19555
+ (0, import_chunk_QFQPBQSO.sameArrays)(a.results, b.results, (ar, br) => sameStateNodeDecl(ar, br))
19554
19556
  );
19555
19557
  }
19556
19558
  function sameLookupResult(a, b) {
19557
- return (0, import_chunk_HHQDDCTP.sameArrays)(a, b, sameLookupDefinition);
19559
+ return (0, import_chunk_QFQPBQSO.sameArrays)(a, b, sameLookupDefinition);
19558
19560
  }
19559
19561
  function declKey(decl) {
19560
19562
  return isStateNode(decl) ? decl.type === "ModuleDeclaration" ? decl.fullName : decl.node : decl;
@@ -20021,7 +20023,7 @@ function stateFuncs() {
20021
20023
  if (!hasProperty(this.index, name)) {
20022
20024
  this.index[name] = [];
20023
20025
  }
20024
- (0, import_chunk_HHQDDCTP.pushUnique)(this.index[name], parent);
20026
+ (0, import_chunk_QFQPBQSO.pushUnique)(this.index[name], parent);
20025
20027
  }
20026
20028
  });
20027
20029
  break;
@@ -20077,7 +20079,7 @@ function stateFuncs() {
20077
20079
  if (!hasProperty(values, name)) {
20078
20080
  values[name] = [];
20079
20081
  }
20080
- if ((0, import_chunk_HHQDDCTP.pushUnique)(values[name], m) && currentEnum) {
20082
+ if ((0, import_chunk_QFQPBQSO.pushUnique)(values[name], m) && currentEnum) {
20081
20083
  if (!this.enumMap)
20082
20084
  this.enumMap = /* @__PURE__ */ new Map();
20083
20085
  this.enumMap.set(m, currentEnum);
@@ -20085,7 +20087,7 @@ function stateFuncs() {
20085
20087
  if (!hasProperty(this.index, name)) {
20086
20088
  this.index[name] = [];
20087
20089
  }
20088
- (0, import_chunk_HHQDDCTP.pushUnique)(this.index[name], parent);
20090
+ (0, import_chunk_QFQPBQSO.pushUnique)(this.index[name], parent);
20089
20091
  });
20090
20092
  break;
20091
20093
  }
@@ -20524,7 +20526,7 @@ function getSuperClasses(klass) {
20524
20526
  });
20525
20527
  return superClasses;
20526
20528
  }
20527
- var init_api = (0, import_chunk_HHQDDCTP.__esm)({
20529
+ var init_api = (0, import_chunk_QFQPBQSO.__esm)({
20528
20530
  "src/api.ts"() {
20529
20531
  init_ast();
20530
20532
  init_mc_rewrite();
@@ -20534,7 +20536,7 @@ var init_api = (0, import_chunk_HHQDDCTP.__esm)({
20534
20536
  init_sdk_util();
20535
20537
  init_type_flow_util();
20536
20538
  init_types();
20537
- (0, import_chunk_HHQDDCTP.init_util)();
20539
+ (0, import_chunk_QFQPBQSO.init_util)();
20538
20540
  init_visitor();
20539
20541
  }
20540
20542
  });
@@ -20650,7 +20652,7 @@ function buildDataFlowGraph(state, func, wantsLiteral, trackInsertionPoints, wan
20650
20652
  }
20651
20653
  const decl = lookupDefToDecl(results);
20652
20654
  if (decl && path7.length) {
20653
- if (wantsAllRefs && (0, import_chunk_HHQDDCTP.every)(
20655
+ if (wantsAllRefs && (0, import_chunk_QFQPBQSO.every)(
20654
20656
  decl,
20655
20657
  (d) => d.type === "VariableDeclarator" || d.type === "BinaryExpression" || d.type === "Identifier"
20656
20658
  )) {
@@ -20758,7 +20760,7 @@ function buildDataFlowGraph(state, func, wantsLiteral, trackInsertionPoints, wan
20758
20760
  const decls = findDecl(node);
20759
20761
  if (!decls)
20760
20762
  break;
20761
- if (trackInsertionPoints && (0, import_chunk_HHQDDCTP.some)(decls, (decl) => {
20763
+ if (trackInsertionPoints && (0, import_chunk_QFQPBQSO.some)(decls, (decl) => {
20762
20764
  if (decl.type === "VariableDeclarator") {
20763
20765
  const defStmts = decl.node.kind === "var" && liveDefs.get(null) || liveDefs.get(decl);
20764
20766
  if (defStmts) {
@@ -21001,7 +21003,7 @@ function getFlowEvent(node, stmt, findDecl) {
21001
21003
  return null;
21002
21004
  }
21003
21005
  var DataflowQueue;
21004
- var init_data_flow = (0, import_chunk_HHQDDCTP.__esm)({
21006
+ var init_data_flow = (0, import_chunk_QFQPBQSO.__esm)({
21005
21007
  "src/data-flow.ts"() {
21006
21008
  "use strict";
21007
21009
  init_api();
@@ -21009,8 +21011,8 @@ var init_data_flow = (0, import_chunk_HHQDDCTP.__esm)({
21009
21011
  init_control_flow();
21010
21012
  init_function_info();
21011
21013
  init_type_flow_util();
21012
- (0, import_chunk_HHQDDCTP.init_util)();
21013
- DataflowQueue = class extends import_chunk_HHQDDCTP.GenericQueue {
21014
+ (0, import_chunk_QFQPBQSO.init_util)();
21015
+ DataflowQueue = class extends import_chunk_QFQPBQSO.GenericQueue {
21014
21016
  constructor() {
21015
21017
  super((b, a) => (a.order || 0) - (b.order || 0));
21016
21018
  }
@@ -21303,6 +21305,74 @@ function getOpInfo(bytecode) {
21303
21305
  unhandledType(bytecode);
21304
21306
  }
21305
21307
  }
21308
+ function getOpEffects(bytecode) {
21309
+ switch (bytecode.op) {
21310
+ case 19:
21311
+ return 1;
21312
+ case 14:
21313
+ return 2;
21314
+ case 17:
21315
+ return 4;
21316
+ case 21:
21317
+ return 2 | 4;
21318
+ case 15:
21319
+ return 8 | 2 | 4;
21320
+ case 0:
21321
+ case 23:
21322
+ case 1:
21323
+ case 53:
21324
+ case 25:
21325
+ case 35:
21326
+ case 2:
21327
+ case 22:
21328
+ case 51:
21329
+ case 40:
21330
+ case 41:
21331
+ case 3:
21332
+ case 4:
21333
+ case 5:
21334
+ case 6:
21335
+ case 7:
21336
+ case 8:
21337
+ case 9:
21338
+ case 10:
21339
+ case 11:
21340
+ case 12:
21341
+ case 26:
21342
+ case 27:
21343
+ case 28:
21344
+ case 29:
21345
+ case 30:
21346
+ case 31:
21347
+ case 34:
21348
+ case 33:
21349
+ case 13:
21350
+ case 16:
21351
+ case 32:
21352
+ case 45:
21353
+ case 48:
21354
+ case 20:
21355
+ case 54:
21356
+ case 47:
21357
+ case 42:
21358
+ case 44:
21359
+ case 43:
21360
+ case 18:
21361
+ case 46:
21362
+ case 24:
21363
+ case 37:
21364
+ case 38:
21365
+ case 39:
21366
+ case 52:
21367
+ case 49:
21368
+ case 50:
21369
+ return 0;
21370
+ case 36:
21371
+ throw new Error(`Unknown opcode ${bytecode.op}`);
21372
+ default:
21373
+ unhandledType(bytecode);
21374
+ }
21375
+ }
21306
21376
  function isBoolOp(op) {
21307
21377
  switch (op) {
21308
21378
  case 32:
@@ -21327,7 +21397,7 @@ function isCondBranch(op) {
21327
21397
  return false;
21328
21398
  }
21329
21399
  var Opcodes;
21330
- var init_opcodes = (0, import_chunk_HHQDDCTP.__esm)({
21400
+ var init_opcodes = (0, import_chunk_QFQPBQSO.__esm)({
21331
21401
  "src/readprg/opcodes.ts"() {
21332
21402
  "use strict";
21333
21403
  init_data_flow();
@@ -21408,6 +21478,45 @@ function postOrderTraverse2(func, visitor) {
21408
21478
  };
21409
21479
  helper(func.offset);
21410
21480
  }
21481
+ function intersect(a, b) {
21482
+ if (a.size > b.size)
21483
+ return intersect(b, a);
21484
+ const result = /* @__PURE__ */ new Set();
21485
+ a.forEach((x) => b.has(x) && result.add(x));
21486
+ return result;
21487
+ }
21488
+ function computeDominators(func) {
21489
+ const states = /* @__PURE__ */ new Map();
21490
+ rpoPropagate(
21491
+ func,
21492
+ (block) => {
21493
+ let state = states.get(block.offset);
21494
+ if (!state) {
21495
+ state = /* @__PURE__ */ new Set();
21496
+ states.set(block.offset, state);
21497
+ }
21498
+ return new Set(state).add(block.offset);
21499
+ },
21500
+ null,
21501
+ () => {
21502
+ },
21503
+ (from, state, succBlock) => {
21504
+ const succState = states.get(succBlock.offset);
21505
+ if (!succState) {
21506
+ states.set(succBlock.offset, new Set(state));
21507
+ return true;
21508
+ }
21509
+ const newState = intersect(state, succState);
21510
+ if (newState.size !== succState.size) {
21511
+ states.set(succBlock.offset, newState);
21512
+ return true;
21513
+ }
21514
+ return false;
21515
+ }
21516
+ );
21517
+ states.forEach((state, offset) => state.add(offset));
21518
+ return states;
21519
+ }
21411
21520
  function computeJsrMap(func) {
21412
21521
  const jsrMap = /* @__PURE__ */ new Map();
21413
21522
  const findRets = (offset, rets, visited) => {
@@ -21439,7 +21548,7 @@ function computeJsrMap(func) {
21439
21548
  }
21440
21549
  function postOrderPropagate(func, preBlock, processBc, postBlock, merge) {
21441
21550
  const order = /* @__PURE__ */ new Map();
21442
- const queue = new import_chunk_HHQDDCTP.GenericQueue(
21551
+ const queue = new import_chunk_QFQPBQSO.GenericQueue(
21443
21552
  (b, a) => order.get(a) - order.get(b)
21444
21553
  );
21445
21554
  postOrderTraverse2(func, (block) => {
@@ -21498,7 +21607,7 @@ function rpoPropagate(func, preBlock, processBc, postBlock, merge) {
21498
21607
  });
21499
21608
  blocks.reverse().forEach((block, i) => order.set(block, i));
21500
21609
  }
21501
- const queue = new import_chunk_HHQDDCTP.GenericQueue(
21610
+ const queue = new import_chunk_QFQPBQSO.GenericQueue(
21502
21611
  (b, a) => order.get(a) - order.get(b)
21503
21612
  );
21504
21613
  queue.enqueue(func.blocks.get(func.offset));
@@ -21511,15 +21620,17 @@ function rpoPropagate(func, preBlock, processBc, postBlock, merge) {
21511
21620
  merge(top, localState, toBlock, isExSucc) && queue.enqueue(toBlock);
21512
21621
  };
21513
21622
  let flags;
21514
- for (let i = 0; i < top.bytecodes.length; i++) {
21515
- const bc = top.bytecodes[i];
21516
- flags = processBc(top, bc, localState);
21517
- if (flags != null && flags & 16) {
21518
- i = -1;
21519
- continue;
21520
- }
21521
- if (top.exsucc && (bc.op === 15 || bc.op === 51)) {
21522
- doMerge(top.exsucc, true);
21623
+ if (processBc) {
21624
+ for (let i = 0; i < top.bytecodes.length; i++) {
21625
+ const bc = top.bytecodes[i];
21626
+ flags = processBc(top, bc, localState);
21627
+ if (flags != null && flags & 16) {
21628
+ i = -1;
21629
+ continue;
21630
+ }
21631
+ if (top.exsucc && (bc.op === 15 || bc.op === 51)) {
21632
+ doMerge(top.exsucc, true);
21633
+ }
21523
21634
  }
21524
21635
  }
21525
21636
  postBlock(top, localState);
@@ -21541,13 +21652,216 @@ function rpoPropagate(func, preBlock, processBc, postBlock, merge) {
21541
21652
  queue.enqueue(func.blocks.get(top.taken));
21542
21653
  }
21543
21654
  }
21655
+ if (!processBc && top.exsucc) {
21656
+ doMerge(top.exsucc, true);
21657
+ }
21544
21658
  retMap.get(top.offset)?.forEach((retSucc) => doMerge(retSucc, false));
21545
21659
  }
21546
21660
  }
21547
- var init_cflow = (0, import_chunk_HHQDDCTP.__esm)({
21661
+ var init_cflow = (0, import_chunk_QFQPBQSO.__esm)({
21548
21662
  "src/readprg/cflow.ts"() {
21549
21663
  "use strict";
21550
- (0, import_chunk_HHQDDCTP.init_util)();
21664
+ (0, import_chunk_QFQPBQSO.init_util)();
21665
+ init_opcodes();
21666
+ }
21667
+ });
21668
+ function sizeBasedPRE2(func, context) {
21669
+ if (func.argc == null) {
21670
+ return;
21671
+ }
21672
+ const canonicalMap = /* @__PURE__ */ new Map();
21673
+ let states = /* @__PURE__ */ new Map();
21674
+ let incSp = null;
21675
+ const getBigInt = (bc, index, bcs) => {
21676
+ switch (bc.op) {
21677
+ case 50: {
21678
+ const buffer = new ArrayBuffer(Float64Array.BYTES_PER_ELEMENT);
21679
+ const view = new DataView(buffer);
21680
+ view.setFloat64(0, bc.arg);
21681
+ return view.getBigInt64(0) << 8n | BigInt(bc.op);
21682
+ }
21683
+ case 38: {
21684
+ const buffer = new ArrayBuffer(Float32Array.BYTES_PER_ELEMENT);
21685
+ const view = new DataView(buffer);
21686
+ view.setFloat32(0, bc.arg);
21687
+ return BigInt(view.getInt32(0)) << 8n | BigInt(bc.op);
21688
+ }
21689
+ case 39:
21690
+ if (bcs[index + 1]?.op === 48) {
21691
+ break;
21692
+ }
21693
+ case 37:
21694
+ case 49:
21695
+ case 52:
21696
+ case 24:
21697
+ return BigInt(bc.arg) << 8n | BigInt(bc.op);
21698
+ case 1:
21699
+ if (incSp != null) {
21700
+ incSp = false;
21701
+ }
21702
+ incSp = bc;
21703
+ return null;
21704
+ case 48:
21705
+ if (index && bcs[index - 1].op === 39) {
21706
+ return BigInt(bcs[index - 1].arg) << 8n | BigInt(bc.op);
21707
+ }
21708
+ break;
21709
+ }
21710
+ return null;
21711
+ };
21712
+ const order = /* @__PURE__ */ new Map();
21713
+ postOrderTraverse2(func, (block) => {
21714
+ order.set(block.offset, order.size);
21715
+ });
21716
+ order.forEach((order2, offset) => {
21717
+ const block = func.blocks.get(offset);
21718
+ (0, import_node_assert7.default)(block);
21719
+ const state = /* @__PURE__ */ new Map();
21720
+ block.bytecodes.forEach((bc, i, bcs) => {
21721
+ const id = getBigInt(bc, i, bcs);
21722
+ if (id == null)
21723
+ return;
21724
+ let canon = canonicalMap.get(id);
21725
+ if (!canon) {
21726
+ canon = /* @__PURE__ */ new Set();
21727
+ canonicalMap.set(id, canon);
21728
+ }
21729
+ canon.add(bc);
21730
+ state.set(id, canon);
21731
+ });
21732
+ states.set(block.offset, state);
21733
+ });
21734
+ if (incSp === false) {
21735
+ return;
21736
+ }
21737
+ states = new Map(
21738
+ Array.from(states).map(
21739
+ ([offset, state]) => [
21740
+ offset,
21741
+ new Map(Array.from(state).filter(([, bcs]) => bcs.size >= 3))
21742
+ ]
21743
+ ).filter(([, state]) => state.size)
21744
+ );
21745
+ if (!states.size)
21746
+ return;
21747
+ const dominatorMap = computeDominators(func);
21748
+ const insertionBlocks = /* @__PURE__ */ new Map();
21749
+ states.forEach((state, offset) => {
21750
+ const dominators = dominatorMap.get(offset);
21751
+ (0, import_node_assert7.default)(dominators);
21752
+ state.forEach((bcs, key) => {
21753
+ const insertions = insertionBlocks.get(key);
21754
+ if (!insertions) {
21755
+ insertionBlocks.set(key, dominators);
21756
+ } else {
21757
+ insertionBlocks.set(key, intersect(insertions, dominators));
21758
+ }
21759
+ });
21760
+ });
21761
+ let nextSlot = func.argc + (incSp?.arg ?? 0);
21762
+ const bytecode = (op, arg) => {
21763
+ const bc = { op, arg, size: opcodeSize(op), offset: context.nextOffset++ };
21764
+ if (arg == null)
21765
+ delete bc.arg;
21766
+ return bc;
21767
+ };
21768
+ if ((0, import_chunk_QFQPBQSO.wouldLog)("pre", 1)) {
21769
+ if ((0, import_chunk_QFQPBQSO.wouldLog)("pre", 5)) {
21770
+ (0, import_chunk_QFQPBQSO.log)(functionBanner(func, context, "PRE")());
21771
+ } else {
21772
+ (0, import_chunk_QFQPBQSO.log)(`================ PRE : ${func.name} ================
21773
+ `);
21774
+ }
21775
+ insertionBlocks.forEach((o, key) => {
21776
+ const bcs = canonicalMap.get(key);
21777
+ (0, import_chunk_QFQPBQSO.log)(
21778
+ `Replacing ${bcs.size} instances of ${bytecodeToString(
21779
+ bcs.values().next().value,
21780
+ context.symbolTable
21781
+ )}`
21782
+ );
21783
+ });
21784
+ }
21785
+ insertionBlocks.forEach((blockOffsets, key) => {
21786
+ const blockOffset = Array.from(blockOffsets).sort(
21787
+ (a, b) => order.get(a) - order.get(b)
21788
+ )[0];
21789
+ (0, import_node_assert7.default)(blockOffset != null);
21790
+ const block = func.blocks.get(blockOffset);
21791
+ (0, import_node_assert7.default)(block);
21792
+ const bcs = canonicalMap.get(key);
21793
+ (0, import_node_assert7.default)(bcs);
21794
+ let index = block.bytecodes.findIndex((bc2) => bcs.has(bc2));
21795
+ if (index < 0) {
21796
+ if (block.next && !block.taken) {
21797
+ index = block.bytecodes.length;
21798
+ }
21799
+ }
21800
+ const bc = bcs.values().next().value;
21801
+ const slot = nextSlot++;
21802
+ if (bc.op === 48) {
21803
+ (0, import_node_assert7.default)(index !== 0);
21804
+ let spush = null;
21805
+ func.blocks.forEach(
21806
+ (b) => states.get(b.offset)?.get(key) && b.bytecodes.forEach((bc2, i) => {
21807
+ if (bcs.has(bc2)) {
21808
+ (0, import_node_assert7.default)(i > 0);
21809
+ const prev = b.bytecodes[i - 1];
21810
+ if (!spush) {
21811
+ spush = { ...prev };
21812
+ }
21813
+ bc2.op = 0;
21814
+ prev.op = 18;
21815
+ prev.arg = slot;
21816
+ prev.size = 2;
21817
+ }
21818
+ })
21819
+ );
21820
+ (0, import_node_assert7.default)(spush);
21821
+ if (index >= 0 && index < block.bytecodes.length) {
21822
+ index--;
21823
+ }
21824
+ block.bytecodes.splice(
21825
+ index,
21826
+ 0,
21827
+ bytecode(spush.op, spush.arg),
21828
+ bytecode(48, void 0),
21829
+ bytecode(19, slot)
21830
+ );
21831
+ } else {
21832
+ block.bytecodes.splice(
21833
+ index,
21834
+ 0,
21835
+ bytecode(bc.op, bc.arg),
21836
+ bytecode(19, slot)
21837
+ );
21838
+ bcs.forEach((bc2) => {
21839
+ bc2.op = 18;
21840
+ bc2.arg = slot;
21841
+ bc2.size = 2;
21842
+ });
21843
+ }
21844
+ });
21845
+ if (incSp) {
21846
+ incSp.arg += insertionBlocks.size;
21847
+ } else {
21848
+ const startBlock = func.blocks.get(func.offset);
21849
+ const index = startBlock.bytecodes.length === 0 || startBlock.bytecodes[0].op !== 53 ? 0 : 1;
21850
+ startBlock.bytecodes.splice(
21851
+ index,
21852
+ 0,
21853
+ bytecode(1, insertionBlocks.size)
21854
+ );
21855
+ }
21856
+ (0, import_chunk_QFQPBQSO.logger)("pre", 5, functionBanner(func, context, "post-PRE"));
21857
+ return true;
21858
+ }
21859
+ var init_pre2 = (0, import_chunk_QFQPBQSO.__esm)({
21860
+ "src/readprg/pre.ts"() {
21861
+ "use strict";
21862
+ (0, import_chunk_QFQPBQSO.init_logger)();
21863
+ init_bytecode();
21864
+ init_cflow();
21551
21865
  init_opcodes();
21552
21866
  }
21553
21867
  });
@@ -21571,7 +21885,7 @@ function checkState(state) {
21571
21885
  const checkArray = (items) => items.forEach((item) => {
21572
21886
  item.equivs?.forEach((e) => {
21573
21887
  if (getEquivs(state, e) !== item.equivs) {
21574
- (0, import_node_assert7.default)(getEquivs(state, e) === item.equivs);
21888
+ (0, import_node_assert8.default)(getEquivs(state, e) === item.equivs);
21575
21889
  }
21576
21890
  });
21577
21891
  });
@@ -21896,7 +22210,7 @@ function interpBytecode(bc, localState, context) {
21896
22210
  }
21897
22211
  case 24: {
21898
22212
  const symbol = context.symbolTable?.symbols.get(bc.arg);
21899
- xpush(131072, symbol?.str);
22213
+ xpush(256, symbol?.str);
21900
22214
  break;
21901
22215
  }
21902
22216
  case 3:
@@ -21947,6 +22261,16 @@ function interpBytecode(bc, localState, context) {
21947
22261
  case 30:
21948
22262
  binary(">=");
21949
22263
  break;
22264
+ case 45: {
22265
+ removeEquiv2(localState, -localState.stack.length);
22266
+ const arg = localState.stack.pop()?.type ?? {
22267
+ type: 524287
22268
+ /* Any */
22269
+ };
22270
+ const result = evaluateUnaryTypes("~", arg);
22271
+ localState.stack.push({ type: result });
22272
+ break;
22273
+ }
21950
22274
  default: {
21951
22275
  const { pop, push } = getOpInfo(bc);
21952
22276
  for (let i = 0; i < pop; i++) {
@@ -21965,35 +22289,72 @@ function interpBytecode(bc, localState, context) {
21965
22289
  }
21966
22290
  function interpFunc(func, context) {
21967
22291
  const { symbolTable } = context;
22292
+ const resolvedBranches = /* @__PURE__ */ new Map();
21968
22293
  const equivSets = /* @__PURE__ */ new Map();
21969
22294
  const selfStores = /* @__PURE__ */ new Set();
21970
22295
  const liveInState = /* @__PURE__ */ new Map();
21971
22296
  const replacements = /* @__PURE__ */ new Map();
21972
- const interpLogging = (0, import_chunk_HHQDDCTP.wouldLog)("interp", 1);
22297
+ const interpLogging = (0, import_chunk_QFQPBQSO.wouldLog)("interp", 1);
21973
22298
  if (interpLogging) {
21974
- if ((0, import_chunk_HHQDDCTP.wouldLog)("interp", 7)) {
21975
- (0, import_chunk_HHQDDCTP.setBanner)(functionBanner(func, context, "interp"));
21976
- } else if ((0, import_chunk_HHQDDCTP.wouldLog)("interp", 3)) {
21977
- (0, import_chunk_HHQDDCTP.setBanner)(
22299
+ if ((0, import_chunk_QFQPBQSO.wouldLog)("interp", 7)) {
22300
+ (0, import_chunk_QFQPBQSO.setBanner)(functionBanner(func, context, "interp"));
22301
+ } else if ((0, import_chunk_QFQPBQSO.wouldLog)("interp", 3)) {
22302
+ (0, import_chunk_QFQPBQSO.setBanner)(
21978
22303
  () => `+++++++++++++ interp-prepare ${func.name} ++++++++++++++`
21979
22304
  );
21980
22305
  }
21981
22306
  }
22307
+ const branchRedirects = /* @__PURE__ */ new Map();
22308
+ const safeBranchBlocks = /* @__PURE__ */ new Map();
22309
+ func.blocks.forEach((block) => {
22310
+ if (block.taken == null || block.next == null)
22311
+ return;
22312
+ if ((block.preds?.size ?? 0) <= 1)
22313
+ return;
22314
+ const maxpops = 1;
22315
+ let depth = maxpops;
22316
+ let mindepth = maxpops;
22317
+ if (block.bytecodes.every((bc) => {
22318
+ if (getOpEffects(bc))
22319
+ return false;
22320
+ const { push, pop } = getOpInfo(bc);
22321
+ depth -= pop;
22322
+ if (depth < 0)
22323
+ return false;
22324
+ if (depth < mindepth)
22325
+ mindepth = depth;
22326
+ depth += push;
22327
+ return true;
22328
+ }) && depth === mindepth) {
22329
+ safeBranchBlocks.set(block.offset, maxpops - depth);
22330
+ }
22331
+ });
21982
22332
  rpoPropagate(
21983
22333
  func,
21984
22334
  (block) => {
21985
22335
  if (interpLogging) {
21986
- (0, import_chunk_HHQDDCTP.logger)(
22336
+ (0, import_chunk_QFQPBQSO.logger)(
21987
22337
  "interp",
21988
22338
  3,
21989
22339
  `${offsetToString(block.offset)}: ${block.bytecodes[0]?.lineNum ? lineInfoToString(block.bytecodes[0]?.lineNum, context) : ""}
21990
22340
  ${interpStateToString(liveInState.get(block.offset))}`
21991
22341
  );
21992
- (0, import_chunk_HHQDDCTP.logger)("interp", 9, blockToString(block, context));
22342
+ (0, import_chunk_QFQPBQSO.logger)("interp", 9, () => blockToString(block, context));
21993
22343
  }
21994
22344
  return cloneState2(liveInState.get(block.offset));
21995
22345
  },
21996
22346
  (block, bc, localState) => {
22347
+ if (interpLogging) {
22348
+ if ((0, import_chunk_QFQPBQSO.wouldLog)("interp", 8)) {
22349
+ (0, import_chunk_QFQPBQSO.log)(
22350
+ `${interpStateToString(localState)}
22351
+ ${bytecodeToString(
22352
+ bc,
22353
+ context.symbolTable
22354
+ )}`
22355
+ );
22356
+ }
22357
+ }
21997
22358
  switch (bc.op) {
21998
22359
  case 19: {
21999
22360
  selfStores.delete(bc);
@@ -22025,7 +22386,7 @@ function interpFunc(func, context) {
22025
22386
  case 39: {
22026
22387
  interpBytecode(bc, localState, context);
22027
22388
  const topType = localState.stack[localState.stack.length - 1].type;
22028
- (0, import_node_assert7.default)(isExact(topType));
22389
+ (0, import_node_assert8.default)(isExact(topType));
22029
22390
  const index = localState.loopBlock ? null : findEquivalent(localState, topType.type, topType.value);
22030
22391
  let blockReps = replacements.get(block);
22031
22392
  if (index != null) {
@@ -22061,15 +22422,15 @@ function interpFunc(func, context) {
22061
22422
  break;
22062
22423
  }
22063
22424
  case 40:
22064
- case 41:
22425
+ case 41: {
22065
22426
  if (block.taken === block.offset) {
22066
22427
  const inState = liveInState.get(block.offset);
22067
- (0, import_node_assert7.default)(inState);
22428
+ (0, import_node_assert8.default)(inState);
22068
22429
  if (inState.stack.length !== localState.stack.length - 1) {
22069
22430
  const condition = localState.stack[localState.stack.length - 1];
22070
22431
  const isTrue = mustBeTrue(condition.type);
22071
22432
  const isFalse = mustBeFalse(condition.type);
22072
- (0, import_node_assert7.default)(isTrue || isFalse);
22433
+ (0, import_node_assert8.default)(isTrue || isFalse);
22073
22434
  interpBytecode(bc, localState, context);
22074
22435
  if (isTrue === (bc.op === 40)) {
22075
22436
  localState.loopBlock = true;
@@ -22079,14 +22440,52 @@ function interpFunc(func, context) {
22079
22440
  return 4;
22080
22441
  }
22081
22442
  }
22443
+ resolvedBranches.delete(block);
22444
+ let flags = 0;
22445
+ const top = localState.stack[localState.stack.length - 1];
22446
+ if (top) {
22447
+ const isTrue = mustBeTrue(top.type);
22448
+ if (isTrue || mustBeFalse(top.type)) {
22449
+ const isTaken = isTrue === (bc.op === 40);
22450
+ flags = isTaken ? 8 : 4;
22451
+ resolvedBranches.set(block, isTaken);
22452
+ }
22453
+ }
22082
22454
  interpBytecode(bc, localState, context);
22083
- break;
22455
+ return flags;
22456
+ }
22084
22457
  default:
22085
22458
  interpBytecode(bc, localState, context);
22086
22459
  }
22087
22460
  return null;
22088
22461
  },
22089
- () => {
22462
+ (block, localState) => {
22463
+ const branchRedirect = (block2, localState2, next) => {
22464
+ if (next != null && !resolvedBranches.has(block2) && safeBranchBlocks.has(next) && (block2.taken == null || safeBranchBlocks.get(next) === 0)) {
22465
+ const state = cloneState2(localState2);
22466
+ const branchBlock = func.blocks.get(next);
22467
+ return branchBlock.bytecodes.every((bc) => {
22468
+ if (isCondBranch(bc.op)) {
22469
+ const top = state.stack[state.stack.length - 1];
22470
+ const isTrue = mustBeTrue(top.type);
22471
+ if (isTrue || mustBeFalse(top.type)) {
22472
+ branchRedirects.set(block2, {
22473
+ from: next,
22474
+ to: isTrue === (bc.op === 40) ? branchBlock.taken : branchBlock.next
22475
+ });
22476
+ return true;
22477
+ }
22478
+ return false;
22479
+ }
22480
+ interpBytecode(bc, state, context);
22481
+ return true;
22482
+ });
22483
+ }
22484
+ return false;
22485
+ };
22486
+ if (localState.loopBlock || !branchRedirect(block, localState, block.next) && !branchRedirect(block, localState, block.taken)) {
22487
+ branchRedirects.delete(block);
22488
+ }
22090
22489
  },
22091
22490
  (from, localState, succBlock, isExSucc) => {
22092
22491
  if (isExSucc) {
@@ -22112,14 +22511,14 @@ function interpFunc(func, context) {
22112
22511
  if (!mergeInto(localState, succState))
22113
22512
  return false;
22114
22513
  if (interpLogging) {
22115
- (0, import_chunk_HHQDDCTP.logger)("interp", 3, `Re-Merge to ${offsetToString(succBlock.offset)}`);
22514
+ (0, import_chunk_QFQPBQSO.logger)("interp", 3, `Re-Merge to ${offsetToString(succBlock.offset)}`);
22116
22515
  }
22117
22516
  return true;
22118
22517
  }
22119
22518
  );
22120
22519
  if (interpLogging) {
22121
- if ((0, import_chunk_HHQDDCTP.wouldLog)("interp", 5)) {
22122
- (0, import_chunk_HHQDDCTP.setBanner)(
22520
+ if ((0, import_chunk_QFQPBQSO.wouldLog)("interp", 5)) {
22521
+ (0, import_chunk_QFQPBQSO.setBanner)(
22123
22522
  functionBanner(func, context, "interp", (block, footer) => {
22124
22523
  if (footer)
22125
22524
  return "";
@@ -22127,32 +22526,50 @@ function interpFunc(func, context) {
22127
22526
  })
22128
22527
  );
22129
22528
  } else {
22130
- (0, import_chunk_HHQDDCTP.setBanner)(() => `=============== interp ${func.name} ==============`);
22529
+ (0, import_chunk_QFQPBQSO.setBanner)(() => `=============== interp ${func.name} ==============`);
22131
22530
  }
22132
22531
  if (equivSets.size) {
22133
- (0, import_chunk_HHQDDCTP.log)(`====== equivSets =====`);
22532
+ (0, import_chunk_QFQPBQSO.log)(`====== equivSets =====`);
22134
22533
  equivSets.forEach(
22135
- (value2, key) => (0, import_chunk_HHQDDCTP.log)(
22534
+ (value2, key) => (0, import_chunk_QFQPBQSO.log)(
22136
22535
  `L${key.arg} === ${Array.from(value2).sort().join(" ")} ${key.lineNum ? lineInfoToString(key.lineNum, context) : ""}`
22137
22536
  )
22138
22537
  );
22139
22538
  }
22140
22539
  if (selfStores.size) {
22141
- (0, import_chunk_HHQDDCTP.log)(`====== selfStores =====`);
22540
+ (0, import_chunk_QFQPBQSO.log)(`====== selfStores =====`);
22142
22541
  selfStores.forEach(
22143
- (value2) => (0, import_chunk_HHQDDCTP.log)(`${bytecodeToString(value2, symbolTable)}`)
22542
+ (value2) => (0, import_chunk_QFQPBQSO.log)(`${bytecodeToString(value2, symbolTable)}`)
22144
22543
  );
22145
22544
  }
22146
22545
  if (replacements.size) {
22147
- (0, import_chunk_HHQDDCTP.log)(`====== replacements =====`);
22546
+ (0, import_chunk_QFQPBQSO.log)(`====== replacements =====`);
22148
22547
  replacements.forEach(
22149
22548
  (blockRep) => blockRep.forEach(
22150
- (rep, bc) => (0, import_chunk_HHQDDCTP.log)(
22549
+ (rep, bc) => (0, import_chunk_QFQPBQSO.log)(
22151
22550
  `${bytecodeToString(bc, symbolTable)} => ${rep.invert ? "~" : ""}${bytecodeToString(rep, symbolTable)} ${bc.lineNum ? lineInfoToString(bc.lineNum, context) : ""}`
22152
22551
  )
22153
22552
  )
22154
22553
  );
22155
22554
  }
22555
+ if (resolvedBranches.size) {
22556
+ (0, import_chunk_QFQPBQSO.log)(`====== resolved branches =====`);
22557
+ resolvedBranches.forEach(
22558
+ (isTaken, block) => (0, import_chunk_QFQPBQSO.log)(
22559
+ `block ${offsetToString(block.offset)} is ${isTaken ? "always" : "never"} taken`
22560
+ )
22561
+ );
22562
+ }
22563
+ if (branchRedirects.size) {
22564
+ (0, import_chunk_QFQPBQSO.log)(`====== redirected branches =====`);
22565
+ branchRedirects.forEach(
22566
+ ({ to, from }, block) => (0, import_chunk_QFQPBQSO.log)(
22567
+ `block ${offsetToString(
22568
+ block.offset
22569
+ )} redirects from ${offsetToString(from)} to ${offsetToString(to)}${safeBranchBlocks.get(from) ? ` popping ${safeBranchBlocks.get(from)}` : ""}`
22570
+ )
22571
+ );
22572
+ }
22156
22573
  }
22157
22574
  selfStores.forEach((bc) => makeArgless(
22158
22575
  bc,
@@ -22176,15 +22593,48 @@ function interpFunc(func, context) {
22176
22593
  const invv = { ...orig };
22177
22594
  invv.op = 45;
22178
22595
  invv.size = 1;
22179
- invv.offset++;
22596
+ invv.offset = context.nextOffset++;
22180
22597
  delete invv.arg;
22181
22598
  block.bytecodes.splice(i + 1, 0, invv);
22182
22599
  }
22183
22600
  }
22184
22601
  });
22602
+ resolvedBranches.forEach((isTaken, block) => {
22603
+ const branch = block.bytecodes[block.bytecodes.length - 1];
22604
+ (0, import_node_assert8.default)(branch && isCondBranch(branch.op));
22605
+ if (isTaken) {
22606
+ redirect(func, block, block.next, block.taken);
22607
+ } else {
22608
+ redirect(func, block, block.taken, block.next);
22609
+ }
22610
+ delete block.taken;
22611
+ makeArgless(
22612
+ branch,
22613
+ 2
22614
+ /* popv */
22615
+ );
22616
+ });
22617
+ branchRedirects.forEach(({ from, to }, block) => {
22618
+ const pops = safeBranchBlocks.get(from);
22619
+ redirect(func, block, from, to);
22620
+ if (pops) {
22621
+ (0, import_node_assert8.default)(block.next && !block.taken);
22622
+ for (let i = 0; i < pops; i++) {
22623
+ block.bytecodes.push({
22624
+ op: 2,
22625
+ size: 1,
22626
+ offset: context.nextOffset++
22627
+ });
22628
+ }
22629
+ }
22630
+ });
22185
22631
  if (interpLogging)
22186
- (0, import_chunk_HHQDDCTP.setBanner)(null);
22187
- return { liveInState, equivSets };
22632
+ (0, import_chunk_QFQPBQSO.setBanner)(null);
22633
+ return {
22634
+ liveInState,
22635
+ equivSets,
22636
+ changes: selfStores.size || replacements.size || resolvedBranches.size || branchRedirects.size
22637
+ };
22188
22638
  }
22189
22639
  function instForType(type, offset) {
22190
22640
  if (!hasValue(type))
@@ -22217,7 +22667,7 @@ function instForType(type, offset) {
22217
22667
  };
22218
22668
  case 131072: {
22219
22669
  const match = type.value.match(/<(\d+)>$/);
22220
- (0, import_node_assert7.default)(match);
22670
+ (0, import_node_assert8.default)(match);
22221
22671
  return {
22222
22672
  op: 37,
22223
22673
  arg: parseInt(match[1], 10),
@@ -22228,11 +22678,11 @@ function instForType(type, offset) {
22228
22678
  }
22229
22679
  return null;
22230
22680
  }
22231
- var init_interp2 = (0, import_chunk_HHQDDCTP.__esm)({
22681
+ var init_interp2 = (0, import_chunk_QFQPBQSO.__esm)({
22232
22682
  "src/readprg/interp.ts"() {
22233
22683
  "use strict";
22234
22684
  init_interp_binary();
22235
- (0, import_chunk_HHQDDCTP.init_logger)();
22685
+ (0, import_chunk_QFQPBQSO.init_logger)();
22236
22686
  init_interp();
22237
22687
  init_types();
22238
22688
  init_union_type();
@@ -22242,7 +22692,7 @@ var init_interp2 = (0, import_chunk_HHQDDCTP.__esm)({
22242
22692
  }
22243
22693
  });
22244
22694
  function optimizeArrayInit(func, block, index, context, interpState) {
22245
- (0, import_node_assert8.default)(
22695
+ (0, import_node_assert9.default)(
22246
22696
  block.bytecodes[index].op === 20 || block.bytecodes[index].op === 54
22247
22697
  /* newba */
22248
22698
  );
@@ -22340,10 +22790,10 @@ function optimizeArrayInit(func, block, index, context, interpState) {
22340
22790
  i = found;
22341
22791
  }
22342
22792
  if (initType && (block.bytecodes[index].op === 20 ? initType.type === 1 : initType.type === 8 && initType.value === 0)) {
22343
- (0, import_chunk_HHQDDCTP.logger)(
22793
+ (0, import_chunk_QFQPBQSO.logger)(
22344
22794
  "array-init",
22345
22795
  1,
22346
- `${func.name}: Removing initialization of default initialized ${putvStarts.length} element array init at block ${offsetToString(
22796
+ () => `${func.name}: Removing initialization of default initialized ${putvStarts.length} element array init at block ${offsetToString(
22347
22797
  block.offset
22348
22798
  )}, starting at index ${index}, at offset ${offsetToString(
22349
22799
  block.bytecodes[index].offset
@@ -22360,7 +22810,7 @@ function optimizeArrayInit(func, block, index, context, interpState) {
22360
22810
  bc.op = 2;
22361
22811
  bc.size = 1;
22362
22812
  delete bc.arg;
22363
- (0, import_node_assert8.default)(
22813
+ (0, import_node_assert9.default)(
22364
22814
  op === 17
22365
22815
  /* aputv */
22366
22816
  );
@@ -22373,17 +22823,17 @@ function optimizeArrayInit(func, block, index, context, interpState) {
22373
22823
  convertAputv(offset - 1);
22374
22824
  }
22375
22825
  }
22376
- (0, import_chunk_HHQDDCTP.logger)(
22826
+ (0, import_chunk_QFQPBQSO.logger)(
22377
22827
  "array-init",
22378
22828
  1,
22379
- `${func.name}: Optimizing unused ${putvStarts.length} element array init at block ${offsetToString(
22829
+ () => `${func.name}: Optimizing unused ${putvStarts.length} element array init at block ${offsetToString(
22380
22830
  block.offset
22381
22831
  )}, starting at index ${index}, at offset ${offsetToString(
22382
22832
  block.bytecodes[index].offset
22383
22833
  )}`
22384
22834
  );
22385
- if ((0, import_chunk_HHQDDCTP.wouldLog)("array-init", 5)) {
22386
- (0, import_chunk_HHQDDCTP.log)(blockToString(block, context));
22835
+ if ((0, import_chunk_QFQPBQSO.wouldLog)("array-init", 5)) {
22836
+ (0, import_chunk_QFQPBQSO.log)(blockToString(block, context));
22387
22837
  }
22388
22838
  return true;
22389
22839
  }
@@ -22401,7 +22851,7 @@ function optimizeArrayInit(func, block, index, context, interpState) {
22401
22851
  for (let ix = putvStarts.length; ix--; ) {
22402
22852
  const dupIx = ++putvStarts[ix];
22403
22853
  const dup = block.bytecodes[dupIx];
22404
- (0, import_node_assert8.default)(dup.op === 46 && dup.arg === 0);
22854
+ (0, import_node_assert9.default)(dup.op === 46 && dup.arg === 0);
22405
22855
  block.bytecodes[dupIx].op = 18;
22406
22856
  block.bytecodes[dupIx].arg = local;
22407
22857
  }
@@ -22423,10 +22873,10 @@ function optimizeArrayInit(func, block, index, context, interpState) {
22423
22873
  if (putvStarts.length < 3)
22424
22874
  return false;
22425
22875
  tryLocal(3);
22426
- (0, import_chunk_HHQDDCTP.logger)(
22876
+ (0, import_chunk_QFQPBQSO.logger)(
22427
22877
  "array-init",
22428
22878
  1,
22429
- `${func.name}: Optimizing ${putvStarts.length} element array init with constant initializer ${bytecodeToString(
22879
+ () => `${func.name}: Optimizing ${putvStarts.length} element array init with constant initializer ${bytecodeToString(
22430
22880
  initInst,
22431
22881
  null
22432
22882
  )} at block ${offsetToString(
@@ -22449,10 +22899,10 @@ function optimizeArrayInit(func, block, index, context, interpState) {
22449
22899
  block.bytecodes[index + 1].arg = putvStarts.length;
22450
22900
  }
22451
22901
  }
22452
- (0, import_chunk_HHQDDCTP.logger)(
22902
+ (0, import_chunk_QFQPBQSO.logger)(
22453
22903
  "array-init",
22454
22904
  5,
22455
- `index: ${index}, i: ${i}
22905
+ () => `index: ${index}, i: ${i}
22456
22906
  ${blockToString(block, context)}`
22457
22907
  );
22458
22908
  const loopOffset2 = context.nextOffset;
@@ -22487,10 +22937,10 @@ ${blockToString(block, context)}`
22487
22937
  for (let i2 = putvStarts.length; i2-- > 1; ) {
22488
22938
  block.bytecodes.splice(putvStarts[i2], 2);
22489
22939
  }
22490
- (0, import_chunk_HHQDDCTP.logger)(
22940
+ (0, import_chunk_QFQPBQSO.logger)(
22491
22941
  "array-init",
22492
22942
  1,
22493
- `${func.name}: Optimizing ${putvStarts.length} element array init at block ${offsetToString(
22943
+ () => `${func.name}: Optimizing ${putvStarts.length} element array init at block ${offsetToString(
22494
22944
  block.offset
22495
22945
  )}, starting at index ${index}, at offset ${offsetToString(
22496
22946
  block.bytecodes[index].offset
@@ -22542,19 +22992,19 @@ ${blockToString(block, context)}`
22542
22992
  loop.taken = loopOffset;
22543
22993
  return true;
22544
22994
  }
22545
- var init_array_init = (0, import_chunk_HHQDDCTP.__esm)({
22995
+ var init_array_init = (0, import_chunk_QFQPBQSO.__esm)({
22546
22996
  "src/readprg/array-init.ts"() {
22547
22997
  "use strict";
22548
22998
  init_types();
22549
- (0, import_chunk_HHQDDCTP.init_util)();
22999
+ (0, import_chunk_QFQPBQSO.init_util)();
22550
23000
  init_bytecode();
22551
23001
  init_interp2();
22552
23002
  init_opcodes();
22553
23003
  }
22554
23004
  });
22555
23005
  function localDCE(func, context) {
22556
- if ((0, import_chunk_HHQDDCTP.wouldLog)("dce", 5)) {
22557
- (0, import_chunk_HHQDDCTP.setBanner)(
23006
+ if ((0, import_chunk_QFQPBQSO.wouldLog)("dce", 5)) {
23007
+ (0, import_chunk_QFQPBQSO.setBanner)(
22558
23008
  functionBanner(
22559
23009
  func,
22560
23010
  context,
@@ -22587,10 +23037,10 @@ function localDCE(func, context) {
22587
23037
  };
22588
23038
  func.blocks.forEach((block) => {
22589
23039
  const reportPopv = (i, item, kill) => {
22590
- (0, import_chunk_HHQDDCTP.logger)(
23040
+ (0, import_chunk_QFQPBQSO.logger)(
22591
23041
  "dce",
22592
23042
  2,
22593
- `${func.name}: Convert ${i}:${bytecodeToString(
23043
+ () => `${func.name}: Convert ${i}:${bytecodeToString(
22594
23044
  block.bytecodes[i],
22595
23045
  context.symbolTable
22596
23046
  )} to popv for ${item.deps.map(
@@ -22602,10 +23052,12 @@ function localDCE(func, context) {
22602
23052
  );
22603
23053
  };
22604
23054
  const reportNop = (item) => {
22605
- (0, import_chunk_HHQDDCTP.logger)(
23055
+ (0, import_chunk_QFQPBQSO.logger)(
22606
23056
  "dce",
22607
23057
  2,
22608
- `${func.name}: Kill ${item.deps.map((i) => bytecodeToString(block.bytecodes[i], context.symbolTable)).join(", ")}`
23058
+ () => `${func.name}: Kill ${item.deps.map(
23059
+ (i) => bytecodeToString(block.bytecodes[i], context.symbolTable)
23060
+ ).join(", ")}`
22609
23061
  );
22610
23062
  };
22611
23063
  changes = false;
@@ -22619,10 +23071,10 @@ function localDCE(func, context) {
22619
23071
  case 19: {
22620
23072
  const liveLocal = dceInfo.locals.has(bytecode.arg);
22621
23073
  if (!liveLocal) {
22622
- (0, import_chunk_HHQDDCTP.logger)(
23074
+ (0, import_chunk_QFQPBQSO.logger)(
22623
23075
  "dce",
22624
23076
  2,
22625
- `${func.name}: Killing store to unused local ${bytecode.arg} at ${offsetToString(block.offset)}:${i}`
23077
+ () => `${func.name}: Killing store to unused local ${bytecode.arg} at ${offsetToString(block.offset)}:${i}`
22626
23078
  );
22627
23079
  makePopv(bytecode);
22628
23080
  dceInfo.stack.push({ dead: true, deps: [i] });
@@ -22740,12 +23192,10 @@ function localDCE(func, context) {
22740
23192
  (bc) => bc.op !== 0
22741
23193
  /* nop */
22742
23194
  );
22743
- if ((0, import_chunk_HHQDDCTP.wouldLog)("dce", 3)) {
22744
- (0, import_chunk_HHQDDCTP.log)(functionBanner(func, context, "local-dce-end")());
22745
- }
23195
+ (0, import_chunk_QFQPBQSO.logger)("dce", 3, functionBanner(func, context, "local-dce-end"));
22746
23196
  }
22747
23197
  });
22748
- (0, import_chunk_HHQDDCTP.setBanner)(null);
23198
+ (0, import_chunk_QFQPBQSO.setBanner)(null);
22749
23199
  return anyChanges;
22750
23200
  }
22751
23201
  function computeLiveLocals(func) {
@@ -22788,10 +23238,354 @@ function computeLiveLocals(func) {
22788
23238
  );
22789
23239
  return { liveInLocals, liveOutLocals };
22790
23240
  }
22791
- var init_dce = (0, import_chunk_HHQDDCTP.__esm)({
23241
+ var init_dce = (0, import_chunk_QFQPBQSO.__esm)({
22792
23242
  "src/readprg/dce.ts"() {
22793
23243
  "use strict";
22794
- (0, import_chunk_HHQDDCTP.init_util)();
23244
+ (0, import_chunk_QFQPBQSO.init_util)();
23245
+ init_bytecode();
23246
+ init_cflow();
23247
+ init_opcodes();
23248
+ }
23249
+ });
23250
+ function cloneLive(locals) {
23251
+ const clone = /* @__PURE__ */ new Map();
23252
+ locals?.forEach((value2, key) => clone.set(key, new Set(value2)));
23253
+ return clone;
23254
+ }
23255
+ function mergeInto2(from, to) {
23256
+ let changed = false;
23257
+ from.forEach((local, key) => {
23258
+ const curr = to.get(key);
23259
+ if (!curr) {
23260
+ to.set(key, new Set(local));
23261
+ changed = true;
23262
+ return;
23263
+ }
23264
+ local.forEach((inst) => {
23265
+ if (!curr.has(inst)) {
23266
+ changed = true;
23267
+ curr.add(inst);
23268
+ }
23269
+ });
23270
+ });
23271
+ return changed;
23272
+ }
23273
+ function minimizeLocals2(func, equivSets, context) {
23274
+ const splitRanges = computeSplitRanges(func, equivSets);
23275
+ const locals = mergeSplitRanges(splitRanges);
23276
+ const numLocals = Math.max(...Array.from(splitRanges.keys())) + 1;
23277
+ (0, import_chunk_QFQPBQSO.logger)("locals", 10, functionBanner(func, context, "Minimize Locals"));
23278
+ const colors = /* @__PURE__ */ new Map();
23279
+ const merge = [];
23280
+ locals.forEach((local, key) => {
23281
+ if (key.op === 18 || key.arg === 0) {
23282
+ colors.set(key, key.arg);
23283
+ const merged = merge[key.arg];
23284
+ if (merged) {
23285
+ (0, import_node_assert10.default)(!key.arg);
23286
+ merged.push(key);
23287
+ } else {
23288
+ merge[key.arg] = [key];
23289
+ }
23290
+ }
23291
+ });
23292
+ locals.forEach((local, key) => {
23293
+ if (key.op === 18)
23294
+ return;
23295
+ let inUse = 0n;
23296
+ local.conflicts.forEach((conflict) => {
23297
+ const color = colors.get(conflict);
23298
+ if (color != null) {
23299
+ inUse |= 1n << BigInt(color);
23300
+ }
23301
+ });
23302
+ let lowest = 0;
23303
+ while (inUse & 1n) {
23304
+ lowest++;
23305
+ inUse >>= 1n;
23306
+ }
23307
+ colors.set(key, lowest);
23308
+ if (!merge[lowest]) {
23309
+ merge[lowest] = [key];
23310
+ } else {
23311
+ merge[lowest].push(key);
23312
+ }
23313
+ });
23314
+ if (merge.length >= numLocals)
23315
+ return false;
23316
+ if ((0, import_chunk_QFQPBQSO.wouldLog)("locals", 1)) {
23317
+ if (!(0, import_chunk_QFQPBQSO.wouldLog)("locals", 10)) {
23318
+ (0, import_chunk_QFQPBQSO.logger)("locals", 5, functionBanner(func, context, "Minimize Locals"));
23319
+ }
23320
+ (0, import_chunk_QFQPBQSO.log)(
23321
+ `>>> Merging locals in ${func.name} (in: ${numLocals} => out: ${merge.length})`
23322
+ );
23323
+ merge.slice().sort((a, b) => (colors.get(a[0]) ?? 0) - (colors.get(b[0]) ?? 0)).forEach(
23324
+ (merged) => (0, import_chunk_QFQPBQSO.log)(
23325
+ ` ${colors.get(merged[0])} - ${merged.map((k) => bytecodeToString(k, context.symbolTable)).join(" | ")}`
23326
+ )
23327
+ );
23328
+ }
23329
+ const fixupMap = /* @__PURE__ */ new Map();
23330
+ locals.forEach((value2, key) => {
23331
+ const color = colors.get(key);
23332
+ (0, import_node_assert10.default)(color != null);
23333
+ let name = null;
23334
+ Array.from(value2.live).some((bc) => {
23335
+ if ((bc.op === 18 || bc.op === 19) && bc.range) {
23336
+ if (!name) {
23337
+ name = bc.range.name;
23338
+ } else if (name !== bc.range.name) {
23339
+ if (typeof name === "string") {
23340
+ name = /* @__PURE__ */ new Set([name]);
23341
+ }
23342
+ name.add(bc.range.name);
23343
+ }
23344
+ }
23345
+ });
23346
+ let range = null;
23347
+ if (name) {
23348
+ if (typeof name !== "string") {
23349
+ name = Array.from(name).join("_");
23350
+ }
23351
+ range = { name, id: context.nextLocalId++ };
23352
+ if (key.op === 18) {
23353
+ range.isParam = true;
23354
+ }
23355
+ }
23356
+ value2.live.forEach((bc) => fixupMap.set(bc, { color, range }));
23357
+ });
23358
+ let argc = null;
23359
+ func.blocks.forEach((block) => {
23360
+ let filter = false;
23361
+ block.bytecodes.forEach((bc) => {
23362
+ switch (bc.op) {
23363
+ case 53:
23364
+ argc = bc.arg;
23365
+ break;
23366
+ case 1: {
23367
+ let newinc;
23368
+ if (argc != null) {
23369
+ newinc = merge.length - argc;
23370
+ } else {
23371
+ newinc = bc.arg + merge.length - numLocals;
23372
+ }
23373
+ if (newinc > 0) {
23374
+ bc.arg = newinc;
23375
+ } else {
23376
+ const nop = bc;
23377
+ nop.op = 0;
23378
+ delete nop.arg;
23379
+ nop.size = 1;
23380
+ filter = true;
23381
+ }
23382
+ break;
23383
+ }
23384
+ case 18:
23385
+ case 19: {
23386
+ const info = fixupMap.get(bc);
23387
+ (0, import_node_assert10.default)(info != null);
23388
+ bc.arg = info.color;
23389
+ if (info.range) {
23390
+ bc.range = info.range;
23391
+ } else {
23392
+ delete bc.range;
23393
+ }
23394
+ break;
23395
+ }
23396
+ }
23397
+ });
23398
+ if (filter) {
23399
+ block.bytecodes = block.bytecodes.filter(
23400
+ (bc) => bc.op !== 0
23401
+ /* nop */
23402
+ );
23403
+ }
23404
+ });
23405
+ return true;
23406
+ }
23407
+ function computeSplitRanges(func, equivSets) {
23408
+ const liveOutLocals = /* @__PURE__ */ new Map();
23409
+ const liveInLocals = /* @__PURE__ */ new Map();
23410
+ const splitRanges = /* @__PURE__ */ new Map();
23411
+ const recordLgetv = (locals, bc) => {
23412
+ const bcs = locals.get(bc.arg);
23413
+ if (!bcs) {
23414
+ locals.set(bc.arg, /* @__PURE__ */ new Set([bc]));
23415
+ } else {
23416
+ bcs.add(bc);
23417
+ }
23418
+ };
23419
+ const fakeLgetvs = /* @__PURE__ */ new Map();
23420
+ postOrderPropagate(
23421
+ func,
23422
+ (block) => cloneLive(liveOutLocals.get(block.offset)),
23423
+ (block, bc, locals) => {
23424
+ switch (bc.op) {
23425
+ case 42: {
23426
+ let fakeLgetv = fakeLgetvs.get(bc);
23427
+ if (!fakeLgetv) {
23428
+ fakeLgetv = {
23429
+ op: 18,
23430
+ arg: 0,
23431
+ size: 2,
23432
+ offset: bc.offset
23433
+ };
23434
+ fakeLgetvs.set(bc, fakeLgetv);
23435
+ }
23436
+ recordLgetv(locals, fakeLgetv);
23437
+ break;
23438
+ }
23439
+ case 18:
23440
+ recordLgetv(locals, bc);
23441
+ break;
23442
+ case 19: {
23443
+ let bcs = locals.get(bc.arg);
23444
+ if (!bcs) {
23445
+ bcs = /* @__PURE__ */ new Set();
23446
+ }
23447
+ let ranges = splitRanges.get(bc.arg);
23448
+ const equiv = equivSets.get(bc);
23449
+ const conflicts = /* @__PURE__ */ new Set();
23450
+ locals.forEach((liveBcs, local) => {
23451
+ if (local === bc.arg)
23452
+ return;
23453
+ if (equiv?.has(local))
23454
+ return;
23455
+ liveBcs.forEach((lbc) => conflicts.add(lbc));
23456
+ });
23457
+ if (!ranges) {
23458
+ splitRanges.set(
23459
+ bc.arg,
23460
+ ranges = /* @__PURE__ */ new Map([[bc, { live: bcs, conflicts }]])
23461
+ );
23462
+ } else {
23463
+ ranges.set(bc, { live: bcs, conflicts });
23464
+ }
23465
+ locals.delete(bc.arg);
23466
+ break;
23467
+ }
23468
+ case 51:
23469
+ case 15:
23470
+ if (block.exsucc) {
23471
+ const from = liveInLocals.get(block.exsucc);
23472
+ if (from) {
23473
+ mergeInto2(from, locals);
23474
+ }
23475
+ }
23476
+ break;
23477
+ }
23478
+ },
23479
+ (block, locals) => {
23480
+ liveInLocals.set(block.offset, locals);
23481
+ },
23482
+ (locals, predBlock, isExPred) => {
23483
+ if (isExPred)
23484
+ return false;
23485
+ const predLocals = liveOutLocals.get(predBlock.offset);
23486
+ if (!predLocals) {
23487
+ liveOutLocals.set(predBlock.offset, cloneLive(locals));
23488
+ return true;
23489
+ }
23490
+ return mergeInto2(locals, predLocals);
23491
+ }
23492
+ );
23493
+ const liveIn = liveInLocals.get(func.offset);
23494
+ liveIn?.forEach((bcs, num) => {
23495
+ const bc = bcs.values().next().value;
23496
+ let range = splitRanges.get(num);
23497
+ if (!range) {
23498
+ splitRanges.set(num, range = /* @__PURE__ */ new Map());
23499
+ }
23500
+ range.set(bc, { live: bcs, conflicts: /* @__PURE__ */ new Set() });
23501
+ });
23502
+ return splitRanges;
23503
+ }
23504
+ function mergeSplitRanges(splitRanges) {
23505
+ const bcToLiveRange = /* @__PURE__ */ new Map();
23506
+ splitRanges.forEach((range, localid) => {
23507
+ const reverseMap = /* @__PURE__ */ new Map();
23508
+ const pvMap = /* @__PURE__ */ new Map();
23509
+ range.forEach(({ live }, key) => {
23510
+ const putvSetRef = { ref: /* @__PURE__ */ new Set([key]) };
23511
+ pvMap.set(key, putvSetRef);
23512
+ live.forEach((bc) => {
23513
+ const m = reverseMap.get(bc);
23514
+ if (!m) {
23515
+ reverseMap.set(bc, putvSetRef);
23516
+ } else if (m.ref !== putvSetRef.ref) {
23517
+ putvSetRef.ref.forEach((pv) => {
23518
+ m.ref.add(pv);
23519
+ const other = pvMap.get(pv);
23520
+ other.ref = m.ref;
23521
+ });
23522
+ }
23523
+ });
23524
+ });
23525
+ const putvSets = /* @__PURE__ */ new Set();
23526
+ reverseMap.forEach(({ ref }) => putvSets.add(ref));
23527
+ range.forEach((x, key) => {
23528
+ const num = Array.from(putvSets).reduce(
23529
+ (count, set) => count + (set.has(key) ? 1 : 0),
23530
+ 0
23531
+ );
23532
+ (0, import_node_assert10.default)(num === 1);
23533
+ });
23534
+ const newRange = /* @__PURE__ */ new Map();
23535
+ putvSets.forEach((pvSet) => {
23536
+ let lputv = null;
23537
+ let singleRange = null;
23538
+ pvSet.forEach((pv) => {
23539
+ if (!lputv || pv.op === 18)
23540
+ lputv = pv;
23541
+ });
23542
+ pvSet.forEach((pv) => {
23543
+ const { live, conflicts } = range.get(pv);
23544
+ if (!singleRange) {
23545
+ singleRange = { live, conflicts };
23546
+ } else {
23547
+ live.forEach((l) => singleRange.live.add(l));
23548
+ conflicts.forEach((c) => singleRange.conflicts.add(c));
23549
+ }
23550
+ singleRange.live.add(pv);
23551
+ live.forEach((bc) => {
23552
+ const prev = bcToLiveRange.get(bc);
23553
+ (0, import_node_assert10.default)(!prev || prev === lputv);
23554
+ bcToLiveRange.set(bc, lputv);
23555
+ });
23556
+ });
23557
+ (0, import_node_assert10.default)(singleRange && lputv);
23558
+ newRange.set(lputv, singleRange);
23559
+ });
23560
+ splitRanges.set(localid, newRange);
23561
+ });
23562
+ const localInfo = /* @__PURE__ */ new Map();
23563
+ splitRanges.forEach((range) => {
23564
+ range.forEach((v, lputv) => {
23565
+ v.conflicts = new Set(
23566
+ Array.from(v.conflicts).flatMap((bc) => {
23567
+ const r = bcToLiveRange.get(bc);
23568
+ if (!r) {
23569
+ (0, import_node_assert10.default)(bc.arg === 0);
23570
+ return [];
23571
+ }
23572
+ return r;
23573
+ })
23574
+ );
23575
+ localInfo.set(lputv, v);
23576
+ });
23577
+ });
23578
+ localInfo.forEach((info, key) => {
23579
+ info.conflicts.forEach(
23580
+ (v) => localInfo.get(v).conflicts.add(key)
23581
+ );
23582
+ });
23583
+ return localInfo;
23584
+ }
23585
+ var init_locals = (0, import_chunk_QFQPBQSO.__esm)({
23586
+ "src/readprg/locals.ts"() {
23587
+ "use strict";
23588
+ (0, import_chunk_QFQPBQSO.init_logger)();
22795
23589
  init_bytecode();
22796
23590
  init_cflow();
22797
23591
  init_opcodes();
@@ -22824,9 +23618,9 @@ function blockSharing(func, context) {
22824
23618
  if (!any)
22825
23619
  return false;
22826
23620
  any = false;
22827
- const logging3 = (0, import_chunk_HHQDDCTP.wouldLog)("sharing", 1);
22828
- if (logging3 && (0, import_chunk_HHQDDCTP.wouldLog)("sharing", 10)) {
22829
- (0, import_chunk_HHQDDCTP.setBanner)(functionBanner(func, context, "sharing"));
23621
+ const logging3 = (0, import_chunk_QFQPBQSO.wouldLog)("sharing", 1);
23622
+ if (logging3 && (0, import_chunk_QFQPBQSO.wouldLog)("sharing", 10)) {
23623
+ (0, import_chunk_QFQPBQSO.setBanner)(functionBanner(func, context, "sharing"));
22830
23624
  }
22831
23625
  candidates.forEach((blocks) => {
22832
23626
  while (blocks.size > 1) {
@@ -22962,15 +23756,15 @@ function blockSharing(func, context) {
22962
23756
  block2.offset
22963
23757
  )})` : `block(${offsetToString(block2.offset)})`;
22964
23758
  };
22965
- (0, import_chunk_HHQDDCTP.log)(`Sharing ${showBlock(block)} with ${showBlock(target)}`);
22966
- if ((0, import_chunk_HHQDDCTP.wouldLog)("sharing", 5)) {
22967
- (0, import_chunk_HHQDDCTP.log)(blockToString(target, context));
23759
+ (0, import_chunk_QFQPBQSO.log)(`Sharing ${showBlock(block)} with ${showBlock(target)}`);
23760
+ if ((0, import_chunk_QFQPBQSO.wouldLog)("sharing", 5)) {
23761
+ (0, import_chunk_QFQPBQSO.log)(blockToString(target, context));
22968
23762
  }
22969
23763
  }
22970
23764
  if (target.bytecodes.length > length2) {
22971
23765
  splitBlock(func, target, -length2);
22972
23766
  }
22973
- (0, import_node_assert9.default)(block.bytecodes.length >= length2);
23767
+ (0, import_node_assert11.default)(block.bytecodes.length >= length2);
22974
23768
  if (block.bytecodes.length > length2) {
22975
23769
  splitBlock(func, block, block.bytecodes.length - length2);
22976
23770
  const next = block.next;
@@ -22991,28 +23785,43 @@ function blockSharing(func, context) {
22991
23785
  });
22992
23786
  }
22993
23787
  });
22994
- (0, import_chunk_HHQDDCTP.setBanner)(null);
23788
+ (0, import_chunk_QFQPBQSO.setBanner)(null);
22995
23789
  return any;
22996
23790
  }
22997
- var init_sharing = (0, import_chunk_HHQDDCTP.__esm)({
23791
+ var init_sharing = (0, import_chunk_QFQPBQSO.__esm)({
22998
23792
  "src/readprg/sharing.ts"() {
22999
23793
  "use strict";
23000
- (0, import_chunk_HHQDDCTP.init_util)();
23794
+ (0, import_chunk_QFQPBQSO.init_util)();
23001
23795
  init_bytecode();
23002
23796
  init_opcodes();
23003
23797
  }
23004
23798
  });
23005
23799
  function optimizeFunc(func, context) {
23006
- let changes;
23007
- let liveInState;
23008
- do {
23800
+ while (true) {
23801
+ let changes;
23009
23802
  cleanCfg2(func, context);
23010
23803
  changes = localDCE(func, context);
23011
- changes = blockSharing(func, context) || changes;
23012
23804
  changes = simpleOpts(func, context) || changes;
23013
- ({ liveInState } = interpFunc(func, context));
23805
+ const {
23806
+ liveInState,
23807
+ equivSets,
23808
+ changes: interpChanges
23809
+ } = interpFunc(func, context);
23810
+ changes = interpChanges || changes;
23014
23811
  changes = doArrayInits(func, liveInState, context) || changes;
23015
- } while (changes);
23812
+ if (changes)
23813
+ continue;
23814
+ changes = blockSharing(func, context) || changes;
23815
+ if (changes)
23816
+ continue;
23817
+ if (context.config.postBuildPRE !== false) {
23818
+ if (sizeBasedPRE2(func, context))
23819
+ continue;
23820
+ }
23821
+ if (!minimizeLocals2(func, equivSets, context) && !changes) {
23822
+ return;
23823
+ }
23824
+ }
23016
23825
  }
23017
23826
  function doArrayInits(func, liveInState, context) {
23018
23827
  const newAToProcess = /* @__PURE__ */ new Map();
@@ -23045,7 +23854,7 @@ function doArrayInits(func, liveInState, context) {
23045
23854
  }
23046
23855
  function simpleOpts(func, context) {
23047
23856
  const equalsSym = 8388787;
23048
- const logging3 = (0, import_chunk_HHQDDCTP.wouldLog)("optimize", 5);
23857
+ const logging3 = (0, import_chunk_QFQPBQSO.wouldLog)("optimize", 5);
23049
23858
  return Array.from(func.blocks.values()).reduce((changes, block) => {
23050
23859
  for (let i = block.bytecodes.length; i--; ) {
23051
23860
  const cur = block.bytecodes[i];
@@ -23053,7 +23862,7 @@ function simpleOpts(func, context) {
23053
23862
  block.bytecodes.splice(i, 1);
23054
23863
  changes = true;
23055
23864
  if (logging3) {
23056
- (0, import_chunk_HHQDDCTP.log)(`${func.name}: deleting ${bytecodeToString(cur, null)}`);
23865
+ (0, import_chunk_QFQPBQSO.log)(`${func.name}: deleting ${bytecodeToString(cur, null)}`);
23057
23866
  }
23058
23867
  } else if (i && cur.op === 39 && cur.arg === equalsSym) {
23059
23868
  changes = equalSymbolToEq(block, i) || changes;
@@ -23064,7 +23873,7 @@ function simpleOpts(func, context) {
23064
23873
  if (!shift && prev.op === 37) {
23065
23874
  block.bytecodes.splice(i - 1, 2);
23066
23875
  changes = true;
23067
- logging3 && (0, import_chunk_HHQDDCTP.log)(`${func.name}: deleting no-op shift (${shift})`);
23876
+ logging3 && (0, import_chunk_QFQPBQSO.log)(`${func.name}: deleting no-op shift (${shift})`);
23068
23877
  continue;
23069
23878
  }
23070
23879
  if (shift < (prev.op === 49 ? 64n : 31n)) {
@@ -23074,7 +23883,7 @@ function simpleOpts(func, context) {
23074
23883
  } else {
23075
23884
  prev.arg = BigInt.asIntN(64, mul);
23076
23885
  }
23077
- logging3 && (0, import_chunk_HHQDDCTP.log)(
23886
+ logging3 && (0, import_chunk_QFQPBQSO.log)(
23078
23887
  `${func.name}: converting shlv(${shift}) to mulv(${prev.arg})`
23079
23888
  );
23080
23889
  changes = true;
@@ -23089,14 +23898,14 @@ function simpleOpts(func, context) {
23089
23898
  func.blocks.get(block.taken).preds.delete(block.offset);
23090
23899
  delete block.taken;
23091
23900
  changes = true;
23092
- logging3 && (0, import_chunk_HHQDDCTP.log)(`${func.name}: deleting empty finally handler`);
23901
+ logging3 && (0, import_chunk_QFQPBQSO.log)(`${func.name}: deleting empty finally handler`);
23093
23902
  } else if (isCondBranch(cur.op)) {
23094
23903
  const next = func.blocks.get(block.next);
23095
23904
  const taken = func.blocks.get(block.taken);
23096
23905
  if (next.preds.size > 1 && taken.preds.size === 1) {
23097
23906
  const newOp = cur.op === 40 ? 41 : 40;
23098
23907
  if (logging3) {
23099
- (0, import_chunk_HHQDDCTP.log)(
23908
+ (0, import_chunk_QFQPBQSO.log)(
23100
23909
  `${func.name}: converting ${Opcodes[cur.op]} to ${Opcodes[newOp]}`
23101
23910
  );
23102
23911
  }
@@ -23109,7 +23918,7 @@ function simpleOpts(func, context) {
23109
23918
  const isBool = i >= 2 && isBoolOp(block.bytecodes[i - 2].op);
23110
23919
  if (next.next === block.taken && next.taken == null && taken.bytecodes.length === 1 && isCondBranch(taken.bytecodes[0].op) && next.bytecodes.length > 1 && next.bytecodes[next.bytecodes.length - 1].op === (cur.op === 41 ? 7 : 8) && (isBool || next.bytecodes.length > 2 && isBoolOp(next.bytecodes[next.bytecodes.length - 2].op)) && next.preds?.size === 1 && taken.preds?.size === 2) {
23111
23920
  if (logging3) {
23112
- (0, import_chunk_HHQDDCTP.log)(
23921
+ (0, import_chunk_QFQPBQSO.log)(
23113
23922
  `${func.name}: simplifying ${next.bytecodes[next.bytecodes.length - 1].op === 7 ? "'&&'" : "'||'"} at ${offsetToString(block.offset)}:${offsetToString(
23114
23923
  next.offset
23115
23924
  )}:${offsetToString(taken.offset)}:`
@@ -23126,7 +23935,7 @@ function simpleOpts(func, context) {
23126
23935
  changes = true;
23127
23936
  } else if (taken.next === block.next && taken.taken == null && next.bytecodes.length === 1 && isCondBranch(next.bytecodes[0].op) && taken.bytecodes.length > 1 && taken.bytecodes[taken.bytecodes.length - 1].op === (cur.op === 40 ? 7 : 8) && (isBool || taken.bytecodes.length > 2 && isBoolOp(taken.bytecodes[taken.bytecodes.length - 2].op)) && next.preds?.size === 2 && taken.preds?.size === 1) {
23128
23937
  if (logging3) {
23129
- (0, import_chunk_HHQDDCTP.log)(
23938
+ (0, import_chunk_QFQPBQSO.log)(
23130
23939
  `${func.name}: simplifying ${taken.bytecodes[taken.bytecodes.length - 1].op === 7 ? "'&&'" : "'||'"} at ${offsetToString(block.offset)}:${offsetToString(
23131
23940
  taken.offset
23132
23941
  )}:${offsetToString(next.offset)}:`
@@ -23175,7 +23984,7 @@ function equalSymbolToEq(block, equalsIndex) {
23175
23984
  offset: invokem.offset,
23176
23985
  size: 1
23177
23986
  });
23178
- (0, import_chunk_HHQDDCTP.logger)(
23987
+ (0, import_chunk_QFQPBQSO.logger)(
23179
23988
  "optimize",
23180
23989
  1,
23181
23990
  `Replacing <thing>.equals(:symbol) with <thing> eq :symbol at ${offsetToString(
@@ -23187,60 +23996,58 @@ function equalSymbolToEq(block, equalsIndex) {
23187
23996
  function isNopBlock(block) {
23188
23997
  return block.bytecodes.length === 0 || block.bytecodes.length === 1 && (block.bytecodes[0].op === 25 || block.bytecodes[0].op === 0);
23189
23998
  }
23190
- function cleanCfg2(func, context) {
23191
- if ((0, import_chunk_HHQDDCTP.wouldLog)("cfg", 10)) {
23192
- (0, import_chunk_HHQDDCTP.setBanner)(functionBanner(func, context, "sharing"));
23193
- }
23194
- const deadBlocks = /* @__PURE__ */ new Map();
23999
+ function removeNoOpBlocks(func) {
24000
+ const noOpBlocks = /* @__PURE__ */ new Map();
23195
24001
  func.blocks.forEach((block) => {
23196
24002
  if (isNopBlock(block) && block.offset !== func.offset) {
23197
- deadBlocks.set(block.offset, block.next);
24003
+ noOpBlocks.set(block.offset, block.next);
23198
24004
  }
23199
24005
  });
23200
- if (deadBlocks.size) {
23201
- deadBlocks.forEach((target, key) => {
23202
- let next = deadBlocks.get(target);
24006
+ if (noOpBlocks.size) {
24007
+ noOpBlocks.forEach((target, key) => {
24008
+ let next = noOpBlocks.get(target);
23203
24009
  if (next != null) {
23204
24010
  do {
23205
- deadBlocks.set(key, next);
23206
- next = deadBlocks.get(next);
24011
+ noOpBlocks.set(key, next);
24012
+ next = noOpBlocks.get(next);
23207
24013
  } while (next);
23208
24014
  }
23209
24015
  });
23210
24016
  func.blocks.forEach((block) => {
23211
24017
  if (block.next) {
23212
- const fixed = deadBlocks.get(block.next);
24018
+ const fixed = noOpBlocks.get(block.next);
23213
24019
  if (fixed) {
23214
24020
  redirect(func, block, block.next, fixed);
23215
24021
  }
23216
24022
  }
23217
24023
  if (block.taken) {
23218
- const fixed = deadBlocks.get(block.taken);
24024
+ const fixed = noOpBlocks.get(block.taken);
23219
24025
  if (fixed) {
23220
24026
  redirect(func, block, block.taken, fixed);
23221
24027
  }
23222
24028
  }
23223
24029
  if (block.exsucc) {
23224
- const fixed = deadBlocks.get(block.exsucc);
24030
+ const fixed = noOpBlocks.get(block.exsucc);
23225
24031
  if (fixed) {
23226
24032
  redirect(func, block, block.exsucc, fixed);
23227
24033
  }
23228
24034
  }
23229
24035
  });
23230
- deadBlocks.forEach((target, offset) => {
24036
+ noOpBlocks.forEach((target, offset) => {
23231
24037
  removeBlock(func, offset);
23232
24038
  });
23233
24039
  }
23234
- const deadCatches = /* @__PURE__ */ new Set();
24040
+ }
24041
+ function removeUnreachableCatches(func, context) {
23235
24042
  func.blocks.forEach((block) => {
23236
24043
  if (block.next && !block.taken && block.next !== block.offset && block.next !== func.offset) {
23237
24044
  const next = func.blocks.get(block.next);
23238
24045
  if (block.try === next.try) {
23239
24046
  if (next.preds.size === 1) {
23240
- (0, import_chunk_HHQDDCTP.logger)(
24047
+ (0, import_chunk_QFQPBQSO.logger)(
23241
24048
  "cfg",
23242
24049
  1,
23243
- `${func.name}: ${offsetToString(
24050
+ () => `${func.name}: ${offsetToString(
23244
24051
  block.offset
23245
24052
  )}: Merging linear blocks: ${blockToString(next, context)}`
23246
24053
  );
@@ -23251,7 +24058,7 @@ function cleanCfg2(func, context) {
23251
24058
  addPred(func, next.taken, block.offset);
23252
24059
  }
23253
24060
  if (next.exsucc) {
23254
- (0, import_node_assert10.default)(!block.exsucc || block.exsucc === next.exsucc);
24061
+ (0, import_node_assert12.default)(!block.exsucc || block.exsucc === next.exsucc);
23255
24062
  if (!block.exsucc) {
23256
24063
  block.exsucc = next.exsucc;
23257
24064
  addPred(func, next.exsucc, block.offset);
@@ -23260,10 +24067,10 @@ function cleanCfg2(func, context) {
23260
24067
  delete next.preds;
23261
24068
  removeBlock(func, next.offset);
23262
24069
  } else if (next.next == null && next.bytecodes.length < 3 && next.bytecodes.reduce((size, bc) => size + bc.size, 0) < 3 && countFallthroughPreds(func, next) > 1) {
23263
- (0, import_chunk_HHQDDCTP.logger)(
24070
+ (0, import_chunk_QFQPBQSO.logger)(
23264
24071
  "cfg",
23265
24072
  1,
23266
- `${func.name}: ${offsetToString(
24073
+ () => `${func.name}: ${offsetToString(
23267
24074
  block.offset
23268
24075
  )}: Merging short fallthrough block: ${blockToString(
23269
24076
  next,
@@ -23285,10 +24092,10 @@ function cleanCfg2(func, context) {
23285
24092
  switch (last.op) {
23286
24093
  case 41:
23287
24094
  case 40:
23288
- (0, import_chunk_HHQDDCTP.logger)(
24095
+ (0, import_chunk_QFQPBQSO.logger)(
23289
24096
  "cfg",
23290
24097
  1,
23291
- `${func.name}: killing no-op ${bytecodeToString(
24098
+ () => `${func.name}: killing no-op ${bytecodeToString(
23292
24099
  last,
23293
24100
  context.symbolTable
23294
24101
  )}`
@@ -23301,14 +24108,14 @@ function cleanCfg2(func, context) {
23301
24108
  delete block.taken;
23302
24109
  break;
23303
24110
  default:
23304
- (0, import_node_assert10.default)(false);
24111
+ (0, import_node_assert12.default)(false);
23305
24112
  }
23306
24113
  }
23307
24114
  if (block.try && !block.exsucc) {
23308
24115
  for (let i = block.try.length; i--; ) {
23309
24116
  const handler = block.try[i].handler;
23310
- if (!func.blocks.get(handler).preds?.size) {
23311
- (0, import_chunk_HHQDDCTP.logger)(
24117
+ if (!func.blocks.get(handler)?.preds?.size) {
24118
+ (0, import_chunk_QFQPBQSO.logger)(
23312
24119
  "cfg",
23313
24120
  1,
23314
24121
  `${func.name}: killing unused try-catch at ${offsetToString(
@@ -23316,7 +24123,6 @@ function cleanCfg2(func, context) {
23316
24123
  )} with handler at ${handler}`
23317
24124
  );
23318
24125
  block.try.splice(i, 1);
23319
- deadCatches.add(handler);
23320
24126
  }
23321
24127
  }
23322
24128
  if (!block.try.length) {
@@ -23324,56 +24130,75 @@ function cleanCfg2(func, context) {
23324
24130
  }
23325
24131
  }
23326
24132
  });
23327
- deadCatches.forEach((cb) => {
23328
- const todo = [cb];
23329
- for (let i = 0; i < todo.length; i++) {
23330
- const offset = todo[i];
23331
- const block = func.blocks.get(offset);
23332
- if (!block) {
23333
- todo.splice(i--, 1);
23334
- continue;
23335
- }
23336
- if (block.preds?.size) {
23337
- continue;
23338
- }
23339
- if (block.next != null)
23340
- todo.push(block.next);
23341
- if (block.taken != null)
23342
- todo.push(block.taken);
23343
- if (block.exsucc != null)
23344
- todo.push(block.exsucc);
23345
- removeBlock(func, offset);
23346
- todo.splice(i, 1);
23347
- i = -1;
23348
- }
24133
+ }
24134
+ function cleanCfg2(func, context) {
24135
+ if ((0, import_chunk_QFQPBQSO.wouldLog)("cfg", 10)) {
24136
+ (0, import_chunk_QFQPBQSO.setBanner)(functionBanner(func, context, "sharing"));
24137
+ }
24138
+ removeNoOpBlocks(func);
24139
+ removeUnreachableCatches(func, context);
24140
+ const deadBlocks = new Set(func.blocks.values());
24141
+ postOrderTraverse2(func, (block) => deadBlocks.delete(block));
24142
+ deadBlocks.forEach((block) => {
24143
+ block.next && removePred(func, block.next, block.offset);
24144
+ block.taken && removePred(func, block.taken, block.offset);
24145
+ block.exsucc && removePred(func, block.exsucc, block.offset);
23349
24146
  });
23350
- (0, import_chunk_HHQDDCTP.setBanner)(null);
24147
+ deadBlocks.forEach((block) => {
24148
+ (0, import_node_assert12.default)(!block.preds?.size);
24149
+ func.blocks.delete(block.offset);
24150
+ });
24151
+ (0, import_chunk_QFQPBQSO.setBanner)(null);
23351
24152
  }
23352
- var init_optimize2 = (0, import_chunk_HHQDDCTP.__esm)({
24153
+ var init_optimize2 = (0, import_chunk_QFQPBQSO.__esm)({
23353
24154
  "src/readprg/optimize.ts"() {
23354
24155
  "use strict";
23355
- (0, import_chunk_HHQDDCTP.init_util)();
24156
+ init_pre2();
24157
+ (0, import_chunk_QFQPBQSO.init_util)();
23356
24158
  init_array_init();
23357
24159
  init_bytecode();
23358
24160
  init_dce();
23359
24161
  init_interp2();
24162
+ init_locals();
23360
24163
  init_opcodes();
23361
24164
  init_sharing();
24165
+ init_cflow();
23362
24166
  }
23363
24167
  });
23364
24168
  function emitFunc(func, view, start, updateInfo, context) {
23365
24169
  cleanCfg2(func, context);
23366
24170
  groupBlocks(func);
23367
- const { offsetMap } = updateInfo;
23368
- const localsMap = /* @__PURE__ */ new Map();
23369
- let numArgs = 0;
23370
- updateInfo.localsMap.set(func, localsMap);
24171
+ const { liveInLocals } = getLocalsInfo(func);
24172
+ const liveLocalRanges = /* @__PURE__ */ new Map();
24173
+ const { localRanges, offsetMap } = updateInfo;
23371
24174
  const linktable = /* @__PURE__ */ new Map();
23372
24175
  let offset = start;
23373
24176
  let lineNum = null;
23374
24177
  const compareLineInfo = (a, b) => {
23375
24178
  return a.line === b.line && a.file === b.file && a.symbol === b.symbol && a.fileStr === b.fileStr && a.symbolStr === b.symbolStr;
23376
24179
  };
24180
+ const startLocalRange = (slot, id, name, isParam) => {
24181
+ const liveRange = liveLocalRanges.get(slot);
24182
+ if (liveRange) {
24183
+ if (liveRange.id === id) {
24184
+ return;
24185
+ }
24186
+ liveRange.endPc = offset - 1;
24187
+ liveLocalRanges.delete(slot);
24188
+ }
24189
+ if (id < 0)
24190
+ return;
24191
+ const newRange = {
24192
+ startPc: offset,
24193
+ endPc: offset,
24194
+ id,
24195
+ isParam,
24196
+ name,
24197
+ slot
24198
+ };
24199
+ liveLocalRanges.set(slot, newRange);
24200
+ localRanges.push(newRange);
24201
+ };
23377
24202
  const exceptionStack = [];
23378
24203
  Array.from(func.blocks.values()).forEach((block, i, blocks) => {
23379
24204
  offsetMap.set(block.offset, offset);
@@ -23402,6 +24227,10 @@ function emitFunc(func, view, start, updateInfo, context) {
23402
24227
  } else {
23403
24228
  exceptionStack.length = 0;
23404
24229
  }
24230
+ const liveInState = liveInLocals.get(block.offset);
24231
+ liveInState?.forEach(
24232
+ (local) => startLocalRange(local.slot, local.id, local.name, local.isParam)
24233
+ );
23405
24234
  block.bytecodes.forEach((bytecode) => {
23406
24235
  if (bytecode.op === 25) {
23407
24236
  return;
@@ -23413,17 +24242,26 @@ function emitFunc(func, view, start, updateInfo, context) {
23413
24242
  updateInfo.lineMap.push(lineNum);
23414
24243
  }
23415
24244
  }
23416
- offsetMap.set(bytecode.offset, offset);
23417
- if (bytecode.op === 53) {
23418
- numArgs = bytecode.arg;
23419
- } else if (bytecode.op === 19 || bytecode.op === 18) {
23420
- const li = localsMap.get(bytecode.arg);
23421
- if (!li) {
23422
- localsMap.set(bytecode.arg, { startPc: offset, endPc: offset });
24245
+ if (bytecode.op === 19) {
24246
+ const range = bytecode.range;
24247
+ if (range) {
24248
+ startLocalRange(
24249
+ bytecode.arg,
24250
+ range.id,
24251
+ range.name,
24252
+ range.isParam === true
24253
+ );
23423
24254
  } else {
23424
- li.endPc = offset + bytecode.size;
24255
+ startLocalRange(bytecode.arg, -1, "", false);
23425
24256
  }
23426
24257
  }
24258
+ if (isCondBranch(bytecode.op) && block.taken != null && block.taken === blocks[i + 1]?.offset) {
24259
+ const taken = block.next;
24260
+ block.next = block.taken;
24261
+ block.taken = taken;
24262
+ bytecode.arg = taken;
24263
+ bytecode.op = bytecode.op === 40 ? 41 : 40;
24264
+ }
23427
24265
  offset = emitBytecode(bytecode, view, offset, linktable);
23428
24266
  });
23429
24267
  if (block.next != null && block.next !== blocks[i + 1]?.offset) {
@@ -23436,17 +24274,14 @@ function emitFunc(func, view, start, updateInfo, context) {
23436
24274
  offset = emitBytecode(bc, view, offset, linktable);
23437
24275
  }
23438
24276
  });
23439
- (0, import_node_assert11.default)(exceptionStack.length === 0);
23440
- localsMap.forEach((item, slot) => {
23441
- if (slot < numArgs) {
23442
- item.startPc = start;
23443
- }
23444
- item.endPc = offset;
24277
+ (0, import_node_assert13.default)(exceptionStack.length === 0);
24278
+ liveLocalRanges.forEach((liveRange) => {
24279
+ liveRange.endPc = offset - 1;
23445
24280
  });
23446
24281
  linktable.forEach((target, from) => {
23447
24282
  const newOffset = offsetMap.get(target);
23448
24283
  if (newOffset == null) {
23449
- (0, import_node_assert11.default)(newOffset != null);
24284
+ (0, import_node_assert13.default)(newOffset != null);
23450
24285
  }
23451
24286
  view.setInt16(from, newOffset - from - 2);
23452
24287
  });
@@ -23490,7 +24325,7 @@ function groupBlocks(func) {
23490
24325
  sortHelper(item).forEach((offset) => itemsFromOffset.set(offset, item));
23491
24326
  itemsToSort.add(item);
23492
24327
  item.items.forEach((block) => {
23493
- (0, import_node_assert11.default)(!isCfgNode(block));
24328
+ (0, import_node_assert13.default)(!isCfgNode(block));
23494
24329
  if (block.next && itemsFromOffset.get(block.next) !== item) {
23495
24330
  item.succs.add(block.next);
23496
24331
  }
@@ -23526,13 +24361,13 @@ function groupBlocks(func) {
23526
24361
  });
23527
24362
  }
23528
24363
  cur.items.forEach((item) => {
23529
- (0, import_node_assert11.default)(!isCfgNode(item));
24364
+ (0, import_node_assert13.default)(!isCfgNode(item));
23530
24365
  if (isCfgNode(item)) {
23531
24366
  item.items.forEach((block) => {
23532
- (0, import_node_assert11.default)(!isCfgNode(block));
24367
+ (0, import_node_assert13.default)(!isCfgNode(block));
23533
24368
  ordered.push(block.offset);
23534
24369
  });
23535
- (0, import_node_assert11.default)(false);
24370
+ (0, import_node_assert13.default)(false);
23536
24371
  } else {
23537
24372
  ordered.push(item.offset);
23538
24373
  }
@@ -23546,10 +24381,73 @@ function groupBlocks(func) {
23546
24381
  sortHelper(outer).reverse().map((offset) => [offset, func.blocks.get(offset)])
23547
24382
  );
23548
24383
  }
23549
- var init_emit = (0, import_chunk_HHQDDCTP.__esm)({
24384
+ function getLocalsInfo(func) {
24385
+ const liveOutLocals = /* @__PURE__ */ new Map();
24386
+ const liveInLocals = /* @__PURE__ */ new Map();
24387
+ function mergeInto3(from, to) {
24388
+ let changed = false;
24389
+ from.forEach((local, key) => {
24390
+ const curr = to.get(key);
24391
+ if (!curr) {
24392
+ to.set(key, local);
24393
+ changed = true;
24394
+ return;
24395
+ }
24396
+ });
24397
+ return changed;
24398
+ }
24399
+ postOrderPropagate(
24400
+ func,
24401
+ (block) => new Map(liveOutLocals.get(block.offset)),
24402
+ (block, bc, locals) => {
24403
+ switch (bc.op) {
24404
+ case 18: {
24405
+ const range = bc.range;
24406
+ if (range) {
24407
+ locals.set(bc.arg, {
24408
+ name: range.name,
24409
+ id: range.id,
24410
+ isParam: range.isParam === true,
24411
+ slot: bc.arg
24412
+ });
24413
+ }
24414
+ break;
24415
+ }
24416
+ case 19:
24417
+ locals.delete(bc.arg);
24418
+ break;
24419
+ case 51:
24420
+ case 15:
24421
+ if (block.exsucc) {
24422
+ const from = liveInLocals.get(block.exsucc);
24423
+ if (from) {
24424
+ mergeInto3(from, locals);
24425
+ }
24426
+ }
24427
+ break;
24428
+ }
24429
+ },
24430
+ (block, locals) => {
24431
+ liveInLocals.set(block.offset, locals);
24432
+ },
24433
+ (locals, predBlock, isExPred) => {
24434
+ if (isExPred)
24435
+ return false;
24436
+ const predLocals = liveOutLocals.get(predBlock.offset);
24437
+ if (!predLocals) {
24438
+ liveOutLocals.set(predBlock.offset, new Map(locals));
24439
+ return true;
24440
+ }
24441
+ return mergeInto3(locals, predLocals);
24442
+ }
24443
+ );
24444
+ return { liveInLocals, liveOutLocals };
24445
+ }
24446
+ var init_emit = (0, import_chunk_QFQPBQSO.__esm)({
23550
24447
  "src/readprg/emit.ts"() {
23551
24448
  "use strict";
23552
24449
  init_ast();
24450
+ init_cflow();
23553
24451
  init_opcodes();
23554
24452
  init_optimize2();
23555
24453
  }
@@ -23586,13 +24484,13 @@ function fixupExceptions(context, updateInfo) {
23586
24484
  ].view;
23587
24485
  const elems = updateInfo.exceptionsMap.size;
23588
24486
  const sectionLength = 2 + 9 * elems;
23589
- (0, import_node_assert12.default)(sectionLength <= view.byteLength);
24487
+ (0, import_node_assert14.default)(sectionLength <= view.byteLength);
23590
24488
  view.setUint16(0, elems);
23591
24489
  let writePos = 2;
23592
24490
  updateInfo.exceptionsMap.forEach(
23593
24491
  (entries) => entries.forEach((entry) => {
23594
24492
  const handler = updateInfo.offsetMap.get(entry.handler);
23595
- (0, import_node_assert12.default)(handler != null);
24493
+ (0, import_node_assert14.default)(handler != null);
23596
24494
  write24(view, (writePos += 3) - 3, entry.tryStart);
23597
24495
  write24(view, (writePos += 3) - 3, entry.tryEnd);
23598
24496
  write24(view, (writePos += 3) - 3, handler);
@@ -23605,7 +24503,7 @@ function write24(view, current, value2) {
23605
24503
  view.setUint8(current + 1, value2 >>> 8);
23606
24504
  view.setUint8(current + 2, value2);
23607
24505
  }
23608
- var init_exceptions = (0, import_chunk_HHQDDCTP.__esm)({
24506
+ var init_exceptions = (0, import_chunk_QFQPBQSO.__esm)({
23609
24507
  "src/readprg/exceptions.ts"() {
23610
24508
  "use strict";
23611
24509
  init_bytecode();
@@ -23662,7 +24560,7 @@ function fixupHeader(context, updateInfo) {
23662
24560
  view.setUint32(25, offset);
23663
24561
  }
23664
24562
  }
23665
- var init_header = (0, import_chunk_HHQDDCTP.__esm)({
24563
+ var init_header = (0, import_chunk_QFQPBQSO.__esm)({
23666
24564
  "src/readprg/header.ts"() {
23667
24565
  "use strict";
23668
24566
  init_bytecode();
@@ -23769,7 +24667,7 @@ function fixupLineNum(context, updateInfo) {
23769
24667
  });
23770
24668
  });
23771
24669
  }
23772
- var init_linenum = (0, import_chunk_HHQDDCTP.__esm)({
24670
+ var init_linenum = (0, import_chunk_QFQPBQSO.__esm)({
23773
24671
  "src/readprg/linenum.ts"() {
23774
24672
  "use strict";
23775
24673
  init_sdk_util();
@@ -23781,13 +24679,77 @@ function offsetToString(offset) {
23781
24679
  }
23782
24680
  function fixSectionSize(section, sections, newSize) {
23783
24681
  const sectionInfo = sections[section];
23784
- (0, import_node_assert13.default)(sectionInfo);
24682
+ (0, import_node_assert15.default)(sectionInfo);
23785
24683
  const view = sectionInfo.view;
23786
24684
  sectionInfo.length = newSize;
23787
24685
  new DataView(view.buffer, view.byteOffset - 4, 4).setUint32(0, newSize);
23788
24686
  sectionInfo.view = new DataView(view.buffer, view.byteOffset, newSize);
23789
24687
  }
24688
+ function markLocals(context) {
24689
+ if (context.debugXml.body instanceof Error) {
24690
+ return;
24691
+ }
24692
+ const localMap = /* @__PURE__ */ new Map();
24693
+ let range = context.nextLocalId;
24694
+ context.debugXml.body.children("localVars").children("entry").elements.forEach((entry) => {
24695
+ const { startPc, endPc, stackId, name, arg } = entry.attr;
24696
+ (0, import_node_assert15.default)(startPc && endPc && stackId && name);
24697
+ const spc = Number(startPc.value.value) & 16777215;
24698
+ const epc = (Number(endPc.value.value) & 16777215) + 1;
24699
+ const sid = Number(stackId.value.value);
24700
+ let locals = localMap.get(spc);
24701
+ if (!locals) {
24702
+ locals = [];
24703
+ localMap.set(spc, locals);
24704
+ }
24705
+ range++;
24706
+ locals.push({
24707
+ name: name.value.value,
24708
+ arg: arg?.value.value === "true",
24709
+ epc,
24710
+ sid,
24711
+ range
24712
+ });
24713
+ });
24714
+ context.nextLocalId = range;
24715
+ const live = /* @__PURE__ */ new Map();
24716
+ const ends = /* @__PURE__ */ new Map();
24717
+ context.bytecodes.forEach((bc) => {
24718
+ const end = ends.get(bc.offset);
24719
+ if (end) {
24720
+ end.forEach((sid) => {
24721
+ (0, import_node_assert15.default)(live.has(sid));
24722
+ live.delete(sid);
24723
+ });
24724
+ ends.delete(bc.offset);
24725
+ }
24726
+ const locals = localMap.get(bc.offset);
24727
+ locals?.forEach((localInfo) => {
24728
+ if (live.has(localInfo.sid)) {
24729
+ (0, import_node_assert15.default)(!live.has(localInfo.sid));
24730
+ }
24731
+ live.set(localInfo.sid, localInfo);
24732
+ const e = ends.get(localInfo.epc);
24733
+ if (e == null) {
24734
+ ends.set(localInfo.epc, [localInfo.sid]);
24735
+ } else {
24736
+ e.push(localInfo.sid);
24737
+ }
24738
+ });
24739
+ if (bc.op === 18 || bc.op === 19) {
24740
+ const local = live.get(bc.arg);
24741
+ if (local) {
24742
+ const range2 = { name: local.name, id: local.range };
24743
+ if (local.arg) {
24744
+ range2.isParam = true;
24745
+ }
24746
+ bc.range = range2;
24747
+ }
24748
+ }
24749
+ });
24750
+ }
23790
24751
  function optimizeBytecode(context) {
24752
+ markLocals(context);
23791
24753
  const functions = findFunctions(context);
23792
24754
  const loggerFunc = process.env["MC_LOGGER_FUNC"] ? new RegExp(process.env["MC_LOGGER_FUNC"]) : null;
23793
24755
  const forEachFunction = (callback) => {
@@ -23795,24 +24757,24 @@ function optimizeBytecode(context) {
23795
24757
  functions.forEach(callback);
23796
24758
  return;
23797
24759
  }
23798
- (0, import_chunk_HHQDDCTP.bumpLogging)(null, 10);
23799
- functions.forEach((func2) => {
23800
- if (loggerFunc.test(func2.name ?? "<null>")) {
23801
- (0, import_chunk_HHQDDCTP.bumpLogging)(null, -10);
23802
- callback(func2);
23803
- (0, import_chunk_HHQDDCTP.bumpLogging)(null, 10);
24760
+ (0, import_chunk_QFQPBQSO.bumpLogging)(null, 10);
24761
+ functions.forEach((func) => {
24762
+ if (loggerFunc.test(func.name ?? "<null>")) {
24763
+ (0, import_chunk_QFQPBQSO.bumpLogging)(null, -10);
24764
+ callback(func);
24765
+ (0, import_chunk_QFQPBQSO.bumpLogging)(null, 10);
23804
24766
  return;
23805
24767
  }
23806
- callback(func2);
24768
+ callback(func);
23807
24769
  });
23808
- (0, import_chunk_HHQDDCTP.bumpLogging)(null, -10);
24770
+ (0, import_chunk_QFQPBQSO.bumpLogging)(null, -10);
23809
24771
  };
23810
- if ((0, import_chunk_HHQDDCTP.wouldLog)("list-input", 1)) {
24772
+ if ((0, import_chunk_QFQPBQSO.wouldLog)("list-input", 1)) {
23811
24773
  forEachFunction(
23812
- (func2) => (0, import_chunk_HHQDDCTP.wouldLog)("list-input", 1) && printFunction(func2, context)
24774
+ (func) => (0, import_chunk_QFQPBQSO.wouldLog)("list-input", 1) && printFunction(func, context)
23813
24775
  );
23814
24776
  }
23815
- forEachFunction((func2) => optimizeFunc(func2, context));
24777
+ forEachFunction((func) => optimizeFunc(func, context));
23816
24778
  const code = context.sections[
23817
24779
  -1059145026
23818
24780
  /* TEXT */
@@ -23820,23 +24782,23 @@ function optimizeBytecode(context) {
23820
24782
  let offset = 0;
23821
24783
  const updateInfo = {
23822
24784
  offsetMap: /* @__PURE__ */ new Map(),
23823
- localsMap: /* @__PURE__ */ new Map(),
24785
+ localRanges: [],
23824
24786
  lineMap: [],
23825
24787
  exceptionsMap: /* @__PURE__ */ new Map()
23826
24788
  };
23827
- forEachFunction((func2) => {
23828
- if (!func2.name)
24789
+ forEachFunction((func) => {
24790
+ if (!func.name)
23829
24791
  return;
23830
- (0, import_chunk_HHQDDCTP.logger)(
24792
+ (0, import_chunk_QFQPBQSO.logger)(
23831
24793
  "bytecode",
23832
24794
  5,
23833
- `${func2.name}: ${offset.toString(16)} ${offset - func2.offset}`
24795
+ `${func.name}: ${offset.toString(16)} ${offset - func.offset}`
23834
24796
  );
23835
- offset = emitFunc(func2, code, offset, updateInfo, context);
24797
+ offset = emitFunc(func, code, offset, updateInfo, context);
23836
24798
  });
23837
24799
  const { offsetMap } = updateInfo;
23838
24800
  offsetMap.set(code.byteLength, offset);
23839
- (0, import_chunk_HHQDDCTP.logger)(
24801
+ (0, import_chunk_QFQPBQSO.logger)(
23840
24802
  "bytecode",
23841
24803
  1,
23842
24804
  `${context.filepath}: code size: ${context.sections[
@@ -23848,9 +24810,9 @@ function optimizeBytecode(context) {
23848
24810
  ].length - offset}`
23849
24811
  );
23850
24812
  fixSectionSize(-1059145026, context.sections, offset);
23851
- if ((0, import_chunk_HHQDDCTP.wouldLog)("list-output", 1)) {
24813
+ if ((0, import_chunk_QFQPBQSO.wouldLog)("list-output", 1)) {
23852
24814
  forEachFunction(
23853
- (func2) => (0, import_chunk_HHQDDCTP.wouldLog)("list-output", 1) && printFunction(func2, context)
24815
+ (func) => (0, import_chunk_QFQPBQSO.wouldLog)("list-output", 1) && printFunction(func, context)
23854
24816
  );
23855
24817
  }
23856
24818
  fixupHeader(context, updateInfo);
@@ -23861,7 +24823,7 @@ function optimizeBytecode(context) {
23861
24823
  return;
23862
24824
  }
23863
24825
  const funcArray = Array.from(functions.values()).filter(
23864
- (func2) => func2.name != null
24826
+ (func) => func.name != null
23865
24827
  );
23866
24828
  funcArray.push({ offset: code.byteLength, blocks: /* @__PURE__ */ new Map() });
23867
24829
  const funcIndex = (pc) => {
@@ -23879,46 +24841,53 @@ function optimizeBytecode(context) {
23879
24841
  };
23880
24842
  const funcRange = (pc) => {
23881
24843
  const index = funcIndex(pc);
23882
- (0, import_node_assert13.default)(
24844
+ (0, import_node_assert15.default)(
23883
24845
  funcArray[index].offset <= (pc & 16777215) && funcArray[index + 1].offset > (pc & 16777215)
23884
24846
  );
23885
24847
  const s = offsetMap.get(funcArray[index].offset);
23886
24848
  const e = offsetMap.get(funcArray[index + 1].offset);
23887
24849
  if (s == null || e == null) {
23888
- (0, import_node_assert13.default)(s != null && e != null);
24850
+ (0, import_node_assert15.default)(s != null && e != null);
23889
24851
  }
23890
24852
  return [s + 268435456, e + 268435456];
23891
24853
  };
23892
- let func = funcArray[0];
23893
- let fend = funcArray[1].offset;
23894
- context.debugXml.body.children("localVars").children("entry").elements.forEach((entry) => {
23895
- const { startPc, endPc, stackId } = entry.attr;
23896
- (0, import_node_assert13.default)(startPc && endPc && stackId);
23897
- const spc = Number(startPc.value.value) & 16777215;
23898
- const epc = Number(endPc.value.value) & 16777215;
23899
- const sid = Number(stackId.value.value);
23900
- if (spc < func.offset || epc > fend) {
23901
- const index = funcIndex(Number(startPc.value.value));
23902
- func = funcArray[index];
23903
- fend = funcArray[index + 1].offset;
23904
- }
23905
- const info = updateInfo.localsMap.get(func);
23906
- (0, import_node_assert13.default)(info);
23907
- const local = info.get(sid);
23908
- if (!local) {
23909
- entry.attr = {};
24854
+ const localVars = context.debugXml.body.children("localVars");
24855
+ const addAttr = (element, attrName, attrValue) => {
24856
+ element.attr[attrName] = xml_util_exports.makeAttribute(attrName, attrValue);
24857
+ };
24858
+ localVars.elements.forEach((element, i) => {
24859
+ delete element.children;
24860
+ if (i)
23910
24861
  return;
23911
- }
23912
- startPc.value.value = (local.startPc + 268435456).toString();
23913
- endPc.value.value = (local.endPc + 268435455).toString();
24862
+ element.children = [];
24863
+ const children = element.children;
24864
+ updateInfo.localRanges.forEach((localRange) => {
24865
+ if (localRange.endPc === localRange.startPc) {
24866
+ return;
24867
+ }
24868
+ children.push({ type: "chardata", value: "\n" });
24869
+ const element2 = {
24870
+ type: "element",
24871
+ name: "entry",
24872
+ attr: {}
24873
+ };
24874
+ addAttr(element2, "name", localRange.name);
24875
+ if (localRange.isParam) {
24876
+ addAttr(element2, "arg", "true");
24877
+ }
24878
+ addAttr(element2, "startPc", (localRange.startPc + 268435456).toString());
24879
+ addAttr(element2, "endPc", (localRange.endPc + 268435456).toString());
24880
+ addAttr(element2, "stackId", localRange.slot.toString());
24881
+ children.push(element2);
24882
+ });
24883
+ children.push({ type: "chardata", value: "\n" });
23914
24884
  });
23915
- context.debugXml.body.children("localVars").deleteChildren((entry) => !entry.attr.startPc);
23916
24885
  context.debugXml.body.children("functions").children("functionEntry").elements.forEach((entry) => {
23917
24886
  const { startPc, endPc } = entry.attr;
23918
24887
  if (!startPc || !endPc)
23919
24888
  return;
23920
24889
  const range = funcRange(Number(startPc.value.value));
23921
- (0, import_node_assert13.default)(funcRange(Number(endPc.value.value))[0] === range[0]);
24890
+ (0, import_node_assert15.default)(funcRange(Number(endPc.value.value))[0] === range[0]);
23922
24891
  startPc.value.value = range[0].toString();
23923
24892
  endPc.value.value = (range[1] - 1).toString();
23924
24893
  });
@@ -23933,7 +24902,7 @@ ${functionToString(
23933
24902
  ---------------- ${func.name} ----------------`;
23934
24903
  }
23935
24904
  function printFunction(func, context) {
23936
- (0, import_chunk_HHQDDCTP.log)(functionToString(func, context));
24905
+ (0, import_chunk_QFQPBQSO.log)(functionToString(func, context));
23937
24906
  }
23938
24907
  function functionToString(func, context, extra) {
23939
24908
  const parts = [];
@@ -23954,7 +24923,7 @@ function blockToString(block, context) {
23954
24923
  const log2 = (msg) => parts.push(msg + "\n");
23955
24924
  log2(`${offsetToString(block.offset)}:`);
23956
24925
  block.try?.forEach((exInfo) => {
23957
- (0, import_node_assert13.default)(exInfo);
24926
+ (0, import_node_assert15.default)(exInfo);
23958
24927
  log2(
23959
24928
  `tryCatch - start: ${offsetToString(
23960
24929
  exInfo.tryStart
@@ -23989,6 +24958,12 @@ function lineInfoToString(lineInfo, context) {
23989
24958
  function bytecodeToString(bytecode, symbolTable) {
23990
24959
  let arg = null;
23991
24960
  switch (bytecode.op) {
24961
+ case 18:
24962
+ case 19:
24963
+ if (bytecode.range) {
24964
+ arg = `${bytecode.range.name} ${bytecode.arg}${bytecode.range.isParam ? " (param)" : ""}`;
24965
+ }
24966
+ break;
23992
24967
  case 39: {
23993
24968
  const argSym = symbolTable?.symbolToLabelMap.get(bytecode.arg);
23994
24969
  if (argSym) {
@@ -24002,7 +24977,7 @@ function bytecodeToString(bytecode, symbolTable) {
24002
24977
  case 24: {
24003
24978
  const symbol = symbolTable?.symbols.get(bytecode.arg);
24004
24979
  if (symbol) {
24005
- arg = symbol.str;
24980
+ arg = `${JSON.stringify(symbol.str)} (${bytecode.arg})`;
24006
24981
  }
24007
24982
  break;
24008
24983
  }
@@ -24109,15 +25084,18 @@ function findFunctions({
24109
25084
  }
24110
25085
  start = i + 1;
24111
25086
  mayThrow2 = false;
24112
- const exnEntry = exceptionsMap.get(nextBcOffset);
24113
- if (exnEntry) {
24114
- exnStack = exnStack.concat(exnEntry);
25087
+ const exnEntries = exceptionsMap.get(nextBcOffset);
25088
+ if (exnEntries) {
25089
+ exnStack = exnStack.concat(
25090
+ exnEntries.filter((exnEntry) => exnEntry.tryEnd > nextBcOffset)
25091
+ );
24115
25092
  }
24116
25093
  }
24117
25094
  });
24118
25095
  const functions = /* @__PURE__ */ new Map();
24119
25096
  while (blocks.size) {
24120
25097
  const func = /* @__PURE__ */ new Map();
25098
+ let argc = null;
24121
25099
  const queue = [blocks.keys().next().value];
24122
25100
  while (queue.length) {
24123
25101
  const next2 = queue.pop();
@@ -24126,11 +25104,13 @@ function findFunctions({
24126
25104
  continue;
24127
25105
  }
24128
25106
  func.set(next2, block);
25107
+ if (func.size === 1 && block.bytecodes.length && block.bytecodes[0].op === 53) {
25108
+ argc = block.bytecodes[0].arg;
25109
+ }
24129
25110
  blocks.delete(next2);
24130
- exceptionsMap.get(block.offset)?.forEach((exInfo) => {
24131
- queue.push(exInfo.tryEnd);
24132
- queue.push(exInfo.handler);
24133
- });
25111
+ if (block.exsucc != null) {
25112
+ queue.push(block.exsucc);
25113
+ }
24134
25114
  if (block.next != null) {
24135
25115
  queue.push(block.next);
24136
25116
  }
@@ -24141,10 +25121,17 @@ function findFunctions({
24141
25121
  const funcSorted = Array.from(func.keys()).sort((a, b) => a - b).map((key) => [key, func.get(key)]);
24142
25122
  const offset = funcSorted[0][0];
24143
25123
  const f = { offset, blocks: new Map(funcSorted) };
24144
- const name = symbolTable.methods.get(offset)?.name;
25124
+ const method = symbolTable.methods.get(offset);
25125
+ const name = method?.name;
24145
25126
  if (!name)
24146
25127
  continue;
24147
25128
  f.name = name;
25129
+ if (argc == null && method.argc != null) {
25130
+ argc = method.argc;
25131
+ }
25132
+ if (argc != null) {
25133
+ f.argc = argc;
25134
+ }
24148
25135
  functions.set(offset, f);
24149
25136
  }
24150
25137
  const addPred2 = (func, block, succ) => {
@@ -24179,7 +25166,7 @@ function makeArgless(bc, op) {
24179
25166
  }
24180
25167
  function removeBlock(func, offset) {
24181
25168
  const block = func.blocks.get(offset);
24182
- (0, import_node_assert13.default)(block && !block.preds?.size);
25169
+ (0, import_node_assert15.default)(block && !block.preds?.size);
24183
25170
  block.next && removePred(func, block.next, block.offset);
24184
25171
  block.taken && removePred(func, block.taken, block.offset);
24185
25172
  block.exsucc && removePred(func, block.exsucc, block.offset);
@@ -24187,9 +25174,7 @@ function removeBlock(func, offset) {
24187
25174
  }
24188
25175
  function removePred(func, target, pred) {
24189
25176
  const targetBlock = func.blocks.get(target);
24190
- if (!targetBlock.preds?.has(pred)) {
24191
- (0, import_node_assert13.default)(targetBlock.preds?.has(pred));
24192
- }
25177
+ (0, import_node_assert15.default)(targetBlock.preds?.has(pred));
24193
25178
  targetBlock.preds.delete(pred);
24194
25179
  }
24195
25180
  function addPred(func, target, pred) {
@@ -24219,7 +25204,7 @@ function redirect(func, block, from, to) {
24219
25204
  last.arg = to;
24220
25205
  break;
24221
25206
  default:
24222
- (0, import_node_assert13.default)(false);
25207
+ (0, import_node_assert15.default)(false);
24223
25208
  }
24224
25209
  } else {
24225
25210
  delete block.taken;
@@ -24227,8 +25212,8 @@ function redirect(func, block, from, to) {
24227
25212
  changes = true;
24228
25213
  }
24229
25214
  if (block.exsucc === from) {
24230
- (0, import_node_assert13.default)(to);
24231
- (0, import_node_assert13.default)(block.try);
25215
+ (0, import_node_assert15.default)(to);
25216
+ (0, import_node_assert15.default)(block.try);
24232
25217
  block.try[block.try.length - 1].handler = to;
24233
25218
  block.exsucc = to;
24234
25219
  changes = true;
@@ -24258,7 +25243,7 @@ function splitBlock(func, block, offset) {
24258
25243
  }
24259
25244
  };
24260
25245
  if (offset > 0) {
24261
- (0, import_node_assert13.default)(offset < block.bytecodes.length);
25246
+ (0, import_node_assert15.default)(offset < block.bytecodes.length);
24262
25247
  const tail = block.bytecodes.splice(offset);
24263
25248
  const tailBlock = {
24264
25249
  ...block,
@@ -24282,7 +25267,7 @@ function splitBlock(func, block, offset) {
24282
25267
  delete block.taken;
24283
25268
  }
24284
25269
  } else {
24285
- (0, import_node_assert13.default)(offset < 0 && offset + block.bytecodes.length > 0);
25270
+ (0, import_node_assert15.default)(offset < 0 && offset + block.bytecodes.length > 0);
24286
25271
  const head = block.bytecodes.splice(0, block.bytecodes.length + offset);
24287
25272
  const headBlock = {
24288
25273
  ...block,
@@ -24325,11 +25310,12 @@ function countFallthroughPreds(func, block) {
24325
25310
  }, 0);
24326
25311
  }
24327
25312
  var SectionKinds;
24328
- var init_bytecode = (0, import_chunk_HHQDDCTP.__esm)({
25313
+ var init_bytecode = (0, import_chunk_QFQPBQSO.__esm)({
24329
25314
  "src/readprg/bytecode.ts"() {
24330
25315
  "use strict";
24331
25316
  init_ast();
24332
- (0, import_chunk_HHQDDCTP.init_util)();
25317
+ init_sdk_util();
25318
+ (0, import_chunk_QFQPBQSO.init_util)();
24333
25319
  init_data();
24334
25320
  init_emit();
24335
25321
  init_exceptions();
@@ -24365,7 +25351,7 @@ function getPrgSignature(context) {
24365
25351
  if (!signature)
24366
25352
  return;
24367
25353
  const keyInfo = context.key.export({ format: "jwk" });
24368
- (0, import_node_assert14.default)(keyInfo.n && keyInfo.e);
25354
+ (0, import_node_assert16.default)(keyInfo.n && keyInfo.e);
24369
25355
  const modulusBuf = Buffer.from(keyInfo.n, "base64");
24370
25356
  const publicExponent = Array.from(Buffer.from(keyInfo.e, "base64")).reduce(
24371
25357
  (value2, n) => (value2 << 8) + n,
@@ -24377,7 +25363,7 @@ function getPrgSignature(context) {
24377
25363
  modulusBuf.byteOffset + delta,
24378
25364
  modulusBuf.byteLength - delta
24379
25365
  );
24380
- (0, import_node_assert14.default)(modulus.byteLength === 512 && signature.length === 512);
25366
+ (0, import_node_assert16.default)(modulus.byteLength === 512 && signature.length === 512);
24381
25367
  const sectionLength = signature.length + modulus.byteLength + 4;
24382
25368
  const buffer = new DataView(new ArrayBuffer(sectionLength + 8));
24383
25369
  buffer.setInt32(
@@ -24440,7 +25426,7 @@ function signView(key, view) {
24440
25426
  signer.end();
24441
25427
  return signer.sign(key);
24442
25428
  }
24443
- var init_signer = (0, import_chunk_HHQDDCTP.__esm)({
25429
+ var init_signer = (0, import_chunk_QFQPBQSO.__esm)({
24444
25430
  "src/readprg/signer.ts"() {
24445
25431
  "use strict";
24446
25432
  init_bytecode();
@@ -24454,7 +25440,7 @@ function hash(s) {
24454
25440
  return (h ^ h >>> 9) >>> 0;
24455
25441
  }
24456
25442
  var SymbolTable;
24457
- var init_symbols = (0, import_chunk_HHQDDCTP.__esm)({
25443
+ var init_symbols = (0, import_chunk_QFQPBQSO.__esm)({
24458
25444
  "src/readprg/symbols.ts"() {
24459
25445
  "use strict";
24460
25446
  SymbolTable = class {
@@ -24488,9 +25474,16 @@ var init_symbols = (0, import_chunk_HHQDDCTP.__esm)({
24488
25474
  const { startPc, name, parent } = functionEntry.attr;
24489
25475
  if (!startPc || !name)
24490
25476
  return;
25477
+ const argc = functionEntry.children?.filter(
25478
+ (node) => node.type === "element" && node.name === "param"
25479
+ ).length || null;
24491
25480
  const fullName = (parent ? debugXml.processRefs(parent.value.value) + "." : "") + debugXml.processRefs(name.value.value);
24492
25481
  const pc = Number(startPc.value.value) & 16777215;
24493
- this.methods.set(pc, { name: fullName, id: null });
25482
+ this.methods.set(pc, {
25483
+ name: fullName,
25484
+ id: null,
25485
+ argc: argc == null ? null : argc + 1
25486
+ });
24494
25487
  });
24495
25488
  debugXml.body.children("symbolTable").children("entry").elements.forEach((entry) => {
24496
25489
  const { id, symbol } = entry.attr;
@@ -24591,20 +25584,20 @@ async function build_project(product, options, lineCallback) {
24591
25584
  lineCallback || ((line) => console.log(line)),
24592
25585
  (line) => console.error(line)
24593
25586
  ];
24594
- await (0, import_chunk_HHQDDCTP.spawnByLine)(exe, args, handlers, {
25587
+ await (0, import_chunk_QFQPBQSO.spawnByLine)(exe, args, handlers, {
24595
25588
  cwd: workspace
24596
25589
  });
24597
25590
  }
24598
25591
  return { exe, args, program: path.resolve(workspace, program), product };
24599
25592
  }
24600
- var init_build = (0, import_chunk_HHQDDCTP.__esm)({
25593
+ var init_build = (0, import_chunk_QFQPBQSO.__esm)({
24601
25594
  "src/build.ts"() {
24602
25595
  "use strict";
24603
25596
  init_sdk_util();
24604
- (0, import_chunk_HHQDDCTP.init_util)();
25597
+ (0, import_chunk_QFQPBQSO.init_util)();
24605
25598
  }
24606
25599
  });
24607
- var require_ms = (0, import_chunk_HHQDDCTP.__commonJS)({
25600
+ var require_ms = (0, import_chunk_QFQPBQSO.__commonJS)({
24608
25601
  "node_modules/ms/index.js"(exports, module2) {
24609
25602
  var s = 1e3;
24610
25603
  var m = s * 60;
@@ -24718,7 +25711,7 @@ var require_ms = (0, import_chunk_HHQDDCTP.__commonJS)({
24718
25711
  }
24719
25712
  }
24720
25713
  });
24721
- var require_common = (0, import_chunk_HHQDDCTP.__commonJS)({
25714
+ var require_common = (0, import_chunk_QFQPBQSO.__commonJS)({
24722
25715
  "node_modules/debug/src/common.js"(exports, module2) {
24723
25716
  function setup(env) {
24724
25717
  createDebug.debug = createDebug;
@@ -24879,7 +25872,7 @@ var require_common = (0, import_chunk_HHQDDCTP.__commonJS)({
24879
25872
  module2.exports = setup;
24880
25873
  }
24881
25874
  });
24882
- var require_browser = (0, import_chunk_HHQDDCTP.__commonJS)({
25875
+ var require_browser = (0, import_chunk_QFQPBQSO.__commonJS)({
24883
25876
  "node_modules/debug/src/browser.js"(exports, module2) {
24884
25877
  exports.formatArgs = formatArgs;
24885
25878
  exports.save = save;
@@ -25046,7 +26039,7 @@ var require_browser = (0, import_chunk_HHQDDCTP.__commonJS)({
25046
26039
  };
25047
26040
  }
25048
26041
  });
25049
- var require_has_flag = (0, import_chunk_HHQDDCTP.__commonJS)({
26042
+ var require_has_flag = (0, import_chunk_QFQPBQSO.__commonJS)({
25050
26043
  "node_modules/has-flag/index.js"(exports, module2) {
25051
26044
  "use strict";
25052
26045
  module2.exports = (flag, argv = process.argv) => {
@@ -25057,11 +26050,11 @@ var require_has_flag = (0, import_chunk_HHQDDCTP.__commonJS)({
25057
26050
  };
25058
26051
  }
25059
26052
  });
25060
- var require_supports_color = (0, import_chunk_HHQDDCTP.__commonJS)({
26053
+ var require_supports_color = (0, import_chunk_QFQPBQSO.__commonJS)({
25061
26054
  "node_modules/supports-color/index.js"(exports, module2) {
25062
26055
  "use strict";
25063
- var os2 = (0, import_chunk_HHQDDCTP.__require)("os");
25064
- var tty = (0, import_chunk_HHQDDCTP.__require)("tty");
26056
+ var os2 = (0, import_chunk_QFQPBQSO.__require)("os");
26057
+ var tty = (0, import_chunk_QFQPBQSO.__require)("tty");
25065
26058
  var hasFlag = require_has_flag();
25066
26059
  var { env } = process;
25067
26060
  var forceColor;
@@ -25157,10 +26150,10 @@ var require_supports_color = (0, import_chunk_HHQDDCTP.__commonJS)({
25157
26150
  };
25158
26151
  }
25159
26152
  });
25160
- var require_node = (0, import_chunk_HHQDDCTP.__commonJS)({
26153
+ var require_node = (0, import_chunk_QFQPBQSO.__commonJS)({
25161
26154
  "node_modules/debug/src/node.js"(exports, module2) {
25162
- var tty = (0, import_chunk_HHQDDCTP.__require)("tty");
25163
- var util = (0, import_chunk_HHQDDCTP.__require)("util");
26155
+ var tty = (0, import_chunk_QFQPBQSO.__require)("tty");
26156
+ var util = (0, import_chunk_QFQPBQSO.__require)("util");
25164
26157
  exports.init = init;
25165
26158
  exports.log = log2;
25166
26159
  exports.formatArgs = formatArgs;
@@ -25329,7 +26322,7 @@ var require_node = (0, import_chunk_HHQDDCTP.__commonJS)({
25329
26322
  };
25330
26323
  }
25331
26324
  });
25332
- var require_src = (0, import_chunk_HHQDDCTP.__commonJS)({
26325
+ var require_src = (0, import_chunk_QFQPBQSO.__commonJS)({
25333
26326
  "node_modules/debug/src/index.js"(exports, module2) {
25334
26327
  if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
25335
26328
  module2.exports = require_browser();
@@ -25338,7 +26331,7 @@ var require_src = (0, import_chunk_HHQDDCTP.__commonJS)({
25338
26331
  }
25339
26332
  }
25340
26333
  });
25341
- var require_wrappy = (0, import_chunk_HHQDDCTP.__commonJS)({
26334
+ var require_wrappy = (0, import_chunk_QFQPBQSO.__commonJS)({
25342
26335
  "node_modules/wrappy/wrappy.js"(exports, module2) {
25343
26336
  module2.exports = wrappy;
25344
26337
  function wrappy(fn, cb) {
@@ -25367,7 +26360,7 @@ var require_wrappy = (0, import_chunk_HHQDDCTP.__commonJS)({
25367
26360
  }
25368
26361
  }
25369
26362
  });
25370
- var require_once = (0, import_chunk_HHQDDCTP.__commonJS)({
26363
+ var require_once = (0, import_chunk_QFQPBQSO.__commonJS)({
25371
26364
  "node_modules/once/once.js"(exports, module2) {
25372
26365
  var wrappy = require_wrappy();
25373
26366
  module2.exports = wrappy(once);
@@ -25410,7 +26403,7 @@ var require_once = (0, import_chunk_HHQDDCTP.__commonJS)({
25410
26403
  }
25411
26404
  }
25412
26405
  });
25413
- var require_end_of_stream = (0, import_chunk_HHQDDCTP.__commonJS)({
26406
+ var require_end_of_stream = (0, import_chunk_QFQPBQSO.__commonJS)({
25414
26407
  "node_modules/end-of-stream/index.js"(exports, module2) {
25415
26408
  var once = require_once();
25416
26409
  var noop = function() {
@@ -25503,11 +26496,11 @@ var require_end_of_stream = (0, import_chunk_HHQDDCTP.__commonJS)({
25503
26496
  module2.exports = eos;
25504
26497
  }
25505
26498
  });
25506
- var require_pump = (0, import_chunk_HHQDDCTP.__commonJS)({
26499
+ var require_pump = (0, import_chunk_QFQPBQSO.__commonJS)({
25507
26500
  "node_modules/pump/index.js"(exports, module2) {
25508
26501
  var once = require_once();
25509
26502
  var eos = require_end_of_stream();
25510
- var fs9 = (0, import_chunk_HHQDDCTP.__require)("fs");
26503
+ var fs9 = (0, import_chunk_QFQPBQSO.__require)("fs");
25511
26504
  var noop = function() {
25512
26505
  };
25513
26506
  var ancient = /^v?\.0/.test(process.version);
@@ -25585,10 +26578,10 @@ var require_pump = (0, import_chunk_HHQDDCTP.__commonJS)({
25585
26578
  module2.exports = pump;
25586
26579
  }
25587
26580
  });
25588
- var require_buffer_stream = (0, import_chunk_HHQDDCTP.__commonJS)({
26581
+ var require_buffer_stream = (0, import_chunk_QFQPBQSO.__commonJS)({
25589
26582
  "node_modules/get-stream/buffer-stream.js"(exports, module2) {
25590
26583
  "use strict";
25591
- var { PassThrough: PassThroughStream } = (0, import_chunk_HHQDDCTP.__require)("stream");
26584
+ var { PassThrough: PassThroughStream } = (0, import_chunk_QFQPBQSO.__require)("stream");
25592
26585
  module2.exports = (options) => {
25593
26586
  options = { ...options };
25594
26587
  const { array } = options;
@@ -25628,10 +26621,10 @@ var require_buffer_stream = (0, import_chunk_HHQDDCTP.__commonJS)({
25628
26621
  };
25629
26622
  }
25630
26623
  });
25631
- var require_get_stream = (0, import_chunk_HHQDDCTP.__commonJS)({
26624
+ var require_get_stream = (0, import_chunk_QFQPBQSO.__commonJS)({
25632
26625
  "node_modules/get-stream/index.js"(exports, module2) {
25633
26626
  "use strict";
25634
- var { constants: BufferConstants } = (0, import_chunk_HHQDDCTP.__require)("buffer");
26627
+ var { constants: BufferConstants } = (0, import_chunk_QFQPBQSO.__require)("buffer");
25635
26628
  var pump = require_pump();
25636
26629
  var bufferStream = require_buffer_stream();
25637
26630
  var MaxBufferError = class extends Error {
@@ -25679,14 +26672,14 @@ var require_get_stream = (0, import_chunk_HHQDDCTP.__commonJS)({
25679
26672
  module2.exports.MaxBufferError = MaxBufferError;
25680
26673
  }
25681
26674
  });
25682
- var require_extract_zip = (0, import_chunk_HHQDDCTP.__commonJS)({
26675
+ var require_extract_zip = (0, import_chunk_QFQPBQSO.__commonJS)({
25683
26676
  "node_modules/extract-zip/index.js"(exports, module2) {
25684
26677
  var debug = require_src()("extract-zip");
25685
- var { createWriteStream: createWriteStream2, promises: fs9 } = (0, import_chunk_HHQDDCTP.__require)("fs");
26678
+ var { createWriteStream: createWriteStream2, promises: fs9 } = (0, import_chunk_QFQPBQSO.__require)("fs");
25686
26679
  var getStream = require_get_stream();
25687
- var path7 = (0, import_chunk_HHQDDCTP.__require)("path");
25688
- var { promisify } = (0, import_chunk_HHQDDCTP.__require)("util");
25689
- var stream = (0, import_chunk_HHQDDCTP.__require)("stream");
26680
+ var path7 = (0, import_chunk_QFQPBQSO.__require)("path");
26681
+ var { promisify } = (0, import_chunk_QFQPBQSO.__require)("util");
26682
+ var stream = (0, import_chunk_QFQPBQSO.__require)("stream");
25690
26683
  var yauzl2 = require_yauzl();
25691
26684
  var openZip = promisify(yauzl2.open);
25692
26685
  var pipeline = promisify(stream.pipeline);
@@ -27307,7 +28300,7 @@ function peg$parse2(input, options) {
27307
28300
  );
27308
28301
  }
27309
28302
  }
27310
- var init_jungle = (0, import_chunk_HHQDDCTP.__esm)({
28303
+ var init_jungle = (0, import_chunk_QFQPBQSO.__esm)({
27311
28304
  "src/jungle.peggy"() {
27312
28305
  "use strict";
27313
28306
  peg$subclass2(peg$SyntaxError2, Error);
@@ -27532,7 +28525,7 @@ async function checkManifest(manifest, products) {
27532
28525
  });
27533
28526
  return ok;
27534
28527
  }
27535
- var init_manifest = (0, import_chunk_HHQDDCTP.__esm)({
28528
+ var init_manifest = (0, import_chunk_QFQPBQSO.__esm)({
27536
28529
  "src/manifest.ts"() {
27537
28530
  "use strict";
27538
28531
  init_sdk_util();
@@ -27788,7 +28781,7 @@ async function resolve_literals(qualifier, default_source, deviceInfo, cache) {
27788
28781
  );
27789
28782
  if (!hasProperty(cache.resolvedPaths, resolved)) {
27790
28783
  if (/[*?[\]{}]/.test(resolved)) {
27791
- cache.resolvedPaths[resolved] = (0, import_chunk_HHQDDCTP.globSome)(resolved, () => true);
28784
+ cache.resolvedPaths[resolved] = (0, import_chunk_QFQPBQSO.globSome)(resolved, () => true);
27792
28785
  } else {
27793
28786
  cache.resolvedPaths[resolved] = fs5.stat(resolved).then(() => true).catch(() => false);
27794
28787
  }
@@ -27857,12 +28850,12 @@ async function read_resource_files(targets, cache) {
27857
28850
  if (!hasProperty(resourceGroupPromises, key)) {
27858
28851
  resourceGroupPromises[key] = Promise.all(
27859
28852
  p.qualifier.resourcePath.map(
27860
- (pattern) => (0, import_chunk_HHQDDCTP.globa)(pattern, { mark: true })
28853
+ (pattern) => (0, import_chunk_QFQPBQSO.globa)(pattern, { mark: true })
27861
28854
  )
27862
28855
  ).then(
27863
28856
  (patterns) => Promise.all(
27864
28857
  patterns.flat().map(
27865
- (path7) => path7.endsWith("/") ? (0, import_chunk_HHQDDCTP.globa)(`${path7}**/*.xml`, { mark: true }) : path7
28858
+ (path7) => path7.endsWith("/") ? (0, import_chunk_QFQPBQSO.globa)(`${path7}**/*.xml`, { mark: true }) : path7
27866
28859
  )
27867
28860
  ).then(
27868
28861
  (paths) => Promise.all(
@@ -27926,7 +28919,7 @@ async function find_build_instructions_in_resource(file, rez, buildDependencies)
27926
28919
  const sourceExcludes = excludes.map((e) => e.file?.value.value).filter((f) => f != null).map((f) => path2.resolve(dir, f).replace(/\\/g, "/"));
27927
28920
  const filePatterns = excludes.map((e) => e.dir?.value.value).filter((f) => f != null).map((f) => path2.join(dir, f, "**", "*.mc").replace(/\\/g, "/"));
27928
28921
  if (filePatterns.length) {
27929
- const files = (await Promise.all(filePatterns.map((p) => (0, import_chunk_HHQDDCTP.globa)(p)))).flat();
28922
+ const files = (await Promise.all(filePatterns.map((p) => (0, import_chunk_QFQPBQSO.globa)(p)))).flat();
27930
28923
  sourceExcludes.push(...files);
27931
28924
  }
27932
28925
  const excludeAnnotations = excludes.map((e) => e.annotation?.value.value).filter((f) => f != null);
@@ -28077,15 +29070,15 @@ function identify_optimizer_groups(targets, options) {
28077
29070
  function find_barrels(barrelPath) {
28078
29071
  if (Array.isArray(barrelPath)) {
28079
29072
  return Promise.all(
28080
- barrelPath.map((path7) => (0, import_chunk_HHQDDCTP.globa)(path7, { mark: true }))
29073
+ barrelPath.map((path7) => (0, import_chunk_QFQPBQSO.globa)(path7, { mark: true }))
28081
29074
  ).then((paths) => [
28082
29075
  paths.flat().filter((path7) => path7.endsWith(".jungle")).join(";")
28083
29076
  ]);
28084
29077
  }
28085
- return (0, import_chunk_HHQDDCTP.globa)(barrelPath, { mark: true }).then(
29078
+ return (0, import_chunk_QFQPBQSO.globa)(barrelPath, { mark: true }).then(
28086
29079
  (paths) => Promise.all(
28087
29080
  paths.map(
28088
- (path7) => path7.endsWith("/") ? (0, import_chunk_HHQDDCTP.globa)(`${path7}**/*.barrel`) : path7
29081
+ (path7) => path7.endsWith("/") ? (0, import_chunk_QFQPBQSO.globa)(`${path7}**/*.barrel`) : path7
28089
29082
  )
28090
29083
  )
28091
29084
  ).then(
@@ -28333,15 +29326,15 @@ async function get_jungle(jungles, options, resources) {
28333
29326
  return result;
28334
29327
  }
28335
29328
  var import_extract_zip;
28336
- var init_jungles = (0, import_chunk_HHQDDCTP.__esm)({
29329
+ var init_jungles = (0, import_chunk_QFQPBQSO.__esm)({
28337
29330
  "src/jungles.ts"() {
28338
29331
  "use strict";
28339
- import_extract_zip = (0, import_chunk_HHQDDCTP.__toESM)(require_extract_zip());
29332
+ import_extract_zip = (0, import_chunk_QFQPBQSO.__toESM)(require_extract_zip());
28340
29333
  init_jungle();
28341
29334
  init_api();
28342
29335
  init_manifest();
28343
29336
  init_sdk_util();
28344
- (0, import_chunk_HHQDDCTP.init_util)();
29337
+ (0, import_chunk_QFQPBQSO.init_util)();
28345
29338
  }
28346
29339
  });
28347
29340
  async function launchSimulator(force = true) {
@@ -28399,7 +29392,7 @@ function simulateProgram(prg, device, test = false, logger2) {
28399
29392
  }
28400
29393
  }
28401
29394
  return getSdkPath().then(
28402
- (sdk) => (0, import_chunk_HHQDDCTP.spawnByLine)(
29395
+ (sdk) => (0, import_chunk_QFQPBQSO.spawnByLine)(
28403
29396
  path3.resolve(sdk, "bin", isWin ? "monkeydo.bat" : "monkeydo"),
28404
29397
  args,
28405
29398
  logger2 || ((line) => console.log(line))
@@ -28408,11 +29401,11 @@ function simulateProgram(prg, device, test = false, logger2) {
28408
29401
  })
28409
29402
  );
28410
29403
  }
28411
- var init_launch = (0, import_chunk_HHQDDCTP.__esm)({
29404
+ var init_launch = (0, import_chunk_QFQPBQSO.__esm)({
28412
29405
  "src/launch.ts"() {
28413
29406
  "use strict";
28414
29407
  init_sdk_util();
28415
- (0, import_chunk_HHQDDCTP.init_util)();
29408
+ (0, import_chunk_QFQPBQSO.init_util)();
28416
29409
  }
28417
29410
  });
28418
29411
  function relative_path_no_dotdot(relative2) {
@@ -28531,7 +29524,7 @@ async function createLocalBarrels(targets, options) {
28531
29524
  optBarrelDir
28532
29525
  };
28533
29526
  return promise2.then(
28534
- () => (0, import_chunk_HHQDDCTP.copyRecursiveAsNeeded)(
29527
+ () => (0, import_chunk_QFQPBQSO.copyRecursiveAsNeeded)(
28535
29528
  rawBarrelDir,
28536
29529
  optBarrelDir,
28537
29530
  (src) => !src.endsWith(".mc")
@@ -28809,12 +29802,12 @@ async function generateOptimizedProject(options) {
28809
29802
  async function fileInfoFromConfig(workspace, output, buildConfig, extraExcludes) {
28810
29803
  const paths = (await Promise.all(
28811
29804
  buildConfig.sourcePath?.map(
28812
- (pattern) => (0, import_chunk_HHQDDCTP.globa)(pattern, { cwd: workspace, mark: true })
29805
+ (pattern) => (0, import_chunk_QFQPBQSO.globa)(pattern, { cwd: workspace, mark: true })
28813
29806
  ) || []
28814
29807
  )).flat();
28815
29808
  const files = (await Promise.all(
28816
29809
  paths.map(
28817
- (path7) => path7.endsWith("/") ? (0, import_chunk_HHQDDCTP.globa)(`${path7}**/*.mc`, { cwd: workspace, mark: true }) : path7
29810
+ (path7) => path7.endsWith("/") ? (0, import_chunk_QFQPBQSO.globa)(`${path7}**/*.mc`, { cwd: workspace, mark: true }) : path7
28818
29811
  )
28819
29812
  )).flat().filter(
28820
29813
  (file) => file.endsWith(".mc") && !path4.relative(workspace, file).startsWith("bin") && (!buildConfig.sourceExcludes || !buildConfig.sourceExcludes.includes(file))
@@ -28897,7 +29890,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
28897
29890
  );
28898
29891
  barrelFnMaps.forEach((barrelFnMap) => Object.assign(fnMap, barrelFnMap));
28899
29892
  }
28900
- const actualOptimizedFiles = (await (0, import_chunk_HHQDDCTP.globa)(path4.join(output, "**", "*.mc"), { mark: true })).filter((file) => !file.endsWith("/")).sort();
29893
+ const actualOptimizedFiles = (await (0, import_chunk_QFQPBQSO.globa)(path4.join(output, "**", "*.mc"), { mark: true })).filter((file) => !file.endsWith("/")).sort();
28901
29894
  const {
28902
29895
  hasTests,
28903
29896
  diagnostics: prevDiagnostics,
@@ -28908,13 +29901,13 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
28908
29901
  if (hasTests != null && !config.checkBuildPragmas && configOptionsToCheck.every(
28909
29902
  (option) => prevOptions[option] === config[option]
28910
29903
  ) && actualOptimizedFiles.length === Object.values(fnMap).length && Object.values(fnMap).map((v) => v.output).sort().every((f, i) => f === actualOptimizedFiles[i])) {
28911
- const source_time = await (0, import_chunk_HHQDDCTP.last_modified)(
29904
+ const source_time = await (0, import_chunk_QFQPBQSO.last_modified)(
28912
29905
  Object.keys(fnMap).concat(dependencyFiles)
28913
29906
  );
28914
- const opt_time = await (0, import_chunk_HHQDDCTP.first_modified)(
29907
+ const opt_time = await (0, import_chunk_QFQPBQSO.first_modified)(
28915
29908
  Object.values(fnMap).map((v) => v.output)
28916
29909
  );
28917
- if (source_time < opt_time && 1680120250138 < opt_time) {
29910
+ if (source_time < opt_time && 1680477048993 < opt_time) {
28918
29911
  return { hasTests, diagnostics: prevDiagnostics };
28919
29912
  }
28920
29913
  }
@@ -28946,7 +29939,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
28946
29939
  JSON.stringify({
28947
29940
  hasTests: hasTests2,
28948
29941
  diagnostics,
28949
- optimizerVersion: "1.1.23",
29942
+ optimizerVersion: "1.1.25",
28950
29943
  ...Object.fromEntries(
28951
29944
  configOptionsToCheck.map((option) => [option, config[option]])
28952
29945
  )
@@ -29091,7 +30084,7 @@ async function generateApiMirTests(options) {
29091
30084
  return fs6.writeFile(`${workspace}/source/apiTest.mc`, source);
29092
30085
  }
29093
30086
  var defaultConfig, configOptionsToCheck;
29094
- var init_optimizer = (0, import_chunk_HHQDDCTP.__esm)({
30087
+ var init_optimizer = (0, import_chunk_QFQPBQSO.__esm)({
29095
30088
  "src/optimizer.ts"() {
29096
30089
  init_api();
29097
30090
  init_build();
@@ -29104,7 +30097,7 @@ var init_optimizer = (0, import_chunk_HHQDDCTP.__esm)({
29104
30097
  init_could_be();
29105
30098
  init_interp();
29106
30099
  init_sub_type();
29107
- (0, import_chunk_HHQDDCTP.init_util)();
30100
+ (0, import_chunk_QFQPBQSO.init_util)();
29108
30101
  init_worker_pool();
29109
30102
  init_optimizer_types();
29110
30103
  init_types();
@@ -29145,7 +30138,7 @@ async function performTask(task) {
29145
30138
  return handler(task.data);
29146
30139
  }
29147
30140
  var workerTaskHandlers;
29148
- var init_worker_task = (0, import_chunk_HHQDDCTP.__esm)({
30141
+ var init_worker_task = (0, import_chunk_QFQPBQSO.__esm)({
29149
30142
  "src/worker-task.ts"() {
29150
30143
  "use strict";
29151
30144
  init_optimizer();
@@ -29225,7 +30218,7 @@ function runTaskInPool(task) {
29225
30218
  return performTask(task);
29226
30219
  }
29227
30220
  var kTaskInfo, kWorkerFreedEvent, WorkerPoolTaskInfo, WorkerPool, pool;
29228
- var init_worker_pool = (0, import_chunk_HHQDDCTP.__esm)({
30221
+ var init_worker_pool = (0, import_chunk_QFQPBQSO.__esm)({
29229
30222
  "src/worker-pool.ts"() {
29230
30223
  "use strict";
29231
30224
  init_worker_task();
@@ -29368,7 +30361,7 @@ async function optimizeProgram(filepath, devKey, output, config) {
29368
30361
  }
29369
30362
  function optimizeProgramBuffer(filepath, view, debugXml, key, config) {
29370
30363
  const { sections } = readPrgWithOffsets(view);
29371
- (0, import_chunk_HHQDDCTP.logger)("readprg", 5, sections);
30364
+ (0, import_chunk_QFQPBQSO.logger)("readprg", 5, sections);
29372
30365
  const symbolTable = new SymbolTable();
29373
30366
  if (hasProperty(sections, 1461170197 .toString())) {
29374
30367
  symbolTable.parse(sections[
@@ -29410,7 +30403,8 @@ function optimizeProgramBuffer(filepath, view, debugXml, key, config) {
29410
30403
  exceptionsMap,
29411
30404
  key,
29412
30405
  debugXml,
29413
- nextOffset: (bytecodes[bytecodes.length - 1]?.offset ?? 0) + (bytecodes[bytecodes.length - 1]?.size ?? 0)
30406
+ nextOffset: (bytecodes[bytecodes.length - 1]?.offset ?? 0) + (bytecodes[bytecodes.length - 1]?.size ?? 0),
30407
+ nextLocalId: 0
29414
30408
  };
29415
30409
  optimizeBytecode(context);
29416
30410
  const signature = getPrgSignature(context);
@@ -29640,11 +30634,11 @@ function optimizePrgAndDebug(prgName, prgBuffer, prgOffset, prgLength, xmlName,
29640
30634
  });
29641
30635
  }
29642
30636
  var yauzl, yazl;
29643
- var init_readprg = (0, import_chunk_HHQDDCTP.__esm)({
30637
+ var init_readprg = (0, import_chunk_QFQPBQSO.__esm)({
29644
30638
  "src/readprg.ts"() {
29645
30639
  "use strict";
29646
- yauzl = (0, import_chunk_HHQDDCTP.__toESM)(require_yauzl());
29647
- yazl = (0, import_chunk_HHQDDCTP.__toESM)(require_yazl());
30640
+ yauzl = (0, import_chunk_QFQPBQSO.__toESM)(require_yauzl());
30641
+ yazl = (0, import_chunk_QFQPBQSO.__toESM)(require_yazl());
29648
30642
  init_ast();
29649
30643
  init_bytecode();
29650
30644
  init_data();
@@ -29655,7 +30649,7 @@ var init_readprg = (0, import_chunk_HHQDDCTP.__esm)({
29655
30649
  init_signer();
29656
30650
  init_symbols();
29657
30651
  init_sdk_util();
29658
- (0, import_chunk_HHQDDCTP.init_util)();
30652
+ (0, import_chunk_QFQPBQSO.init_util)();
29659
30653
  init_worker_pool();
29660
30654
  }
29661
30655
  });
@@ -29667,7 +30661,7 @@ function getSdkPath() {
29667
30661
  });
29668
30662
  }
29669
30663
  async function getDeviceInfo() {
29670
- const files = await (0, import_chunk_HHQDDCTP.globa)(`${connectiq}/Devices/*/compiler.json`);
30664
+ const files = await (0, import_chunk_QFQPBQSO.globa)(`${connectiq}/Devices/*/compiler.json`);
29671
30665
  if (!files.length) {
29672
30666
  throw new Error(
29673
30667
  `No devices found at '${connectiq}/Devices'. Check your sdk is correctly installed`
@@ -29732,9 +30726,9 @@ async function getFunctionDocumentation() {
29732
30726
  return entries;
29733
30727
  }
29734
30728
  var isWin, appSupport, connectiq;
29735
- var init_sdk_util = (0, import_chunk_HHQDDCTP.__esm)({
30729
+ var init_sdk_util = (0, import_chunk_QFQPBQSO.__esm)({
29736
30730
  "src/sdk-util.ts"() {
29737
- (0, import_chunk_HHQDDCTP.init_util)();
30731
+ (0, import_chunk_QFQPBQSO.init_util)();
29738
30732
  init_xml_util();
29739
30733
  init_readprg();
29740
30734
  init_bytecode();