@markw65/monkeyc-optimizer 1.1.92 → 1.1.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/api.cjs CHANGED
@@ -18,52 +18,52 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var api_exports = {};
20
20
  __export(api_exports, {
21
- checkCompilerVersion: () => import_chunk_VAV4N2CL.checkCompilerVersion,
22
- clearDiagnostics: () => import_chunk_VAV4N2CL.clearDiagnostics,
23
- collectNamespaces: () => import_chunk_VAV4N2CL.collectNamespaces,
24
- createDocumentationMap: () => import_chunk_VAV4N2CL.createDocumentationMap,
25
- declKey: () => import_chunk_VAV4N2CL.declKey,
26
- diagnostic: () => import_chunk_VAV4N2CL.diagnostic,
27
- diagnosticHelper: () => import_chunk_VAV4N2CL.diagnosticHelper,
28
- findNamesInScope: () => import_chunk_VAV4N2CL.findNamesInScope,
29
- findUsingForNode: () => import_chunk_VAV4N2CL.findUsingForNode,
30
- formatAst: () => import_chunk_VAV4N2CL.formatAst,
31
- formatAstLongLines: () => import_chunk_VAV4N2CL.formatAstLongLines,
32
- formatScopedName: () => import_chunk_VAV4N2CL.formatScopedName,
33
- getApiFunctionInfo: () => import_chunk_VAV4N2CL.getApiFunctionInfo,
34
- getApiMapping: () => import_chunk_VAV4N2CL.getApiMapping,
35
- getSuperClasses: () => import_chunk_VAV4N2CL.getSuperClasses,
36
- handleImportUsing: () => import_chunk_VAV4N2CL.handleImportUsing,
21
+ checkCompilerVersion: () => import_chunk_5SB3QASN.checkCompilerVersion,
22
+ clearDiagnostics: () => import_chunk_5SB3QASN.clearDiagnostics,
23
+ collectNamespaces: () => import_chunk_5SB3QASN.collectNamespaces,
24
+ createDocumentationMap: () => import_chunk_5SB3QASN.createDocumentationMap,
25
+ declKey: () => import_chunk_5SB3QASN.declKey,
26
+ diagnostic: () => import_chunk_5SB3QASN.diagnostic,
27
+ diagnosticHelper: () => import_chunk_5SB3QASN.diagnosticHelper,
28
+ findNamesInScope: () => import_chunk_5SB3QASN.findNamesInScope,
29
+ findUsingForNode: () => import_chunk_5SB3QASN.findUsingForNode,
30
+ formatAst: () => import_chunk_5SB3QASN.formatAst,
31
+ formatAstLongLines: () => import_chunk_5SB3QASN.formatAstLongLines,
32
+ formatScopedName: () => import_chunk_5SB3QASN.formatScopedName,
33
+ getApiFunctionInfo: () => import_chunk_5SB3QASN.getApiFunctionInfo,
34
+ getApiMapping: () => import_chunk_5SB3QASN.getApiMapping,
35
+ getSuperClasses: () => import_chunk_5SB3QASN.getSuperClasses,
36
+ handleImportUsing: () => import_chunk_5SB3QASN.handleImportUsing,
37
37
  hasProperty: () => import_chunk_UBAYZSM3.hasProperty,
38
- isClassVariable: () => import_chunk_VAV4N2CL.isClassVariable,
39
- isLocal: () => import_chunk_VAV4N2CL.isLocal,
40
- isLookupCandidate: () => import_chunk_VAV4N2CL.isLookupCandidate,
41
- isStateNode: () => import_chunk_VAV4N2CL.isStateNode,
42
- lookupByFullName: () => import_chunk_VAV4N2CL.lookupByFullName,
43
- lookupNext: () => import_chunk_VAV4N2CL.lookupNext,
44
- lookupResultContains: () => import_chunk_VAV4N2CL.lookupResultContains,
45
- lookupWithType: () => import_chunk_VAV4N2CL.lookupWithType,
46
- makeToyboxLink: () => import_chunk_VAV4N2CL.makeToyboxLink,
47
- mapVarDeclsByType: () => import_chunk_VAV4N2CL.mapVarDeclsByType,
48
- markInvokeClassMethod: () => import_chunk_VAV4N2CL.markInvokeClassMethod,
49
- parseSdkVersion: () => import_chunk_VAV4N2CL.parseSdkVersion,
50
- popRootNode: () => import_chunk_VAV4N2CL.popRootNode,
51
- pushRootNode: () => import_chunk_VAV4N2CL.pushRootNode,
52
- resolveDiagnostics: () => import_chunk_VAV4N2CL.resolveDiagnostics,
53
- resolveDiagnosticsMap: () => import_chunk_VAV4N2CL.resolveDiagnosticsMap,
54
- sameLookupResult: () => import_chunk_VAV4N2CL.sameLookupResult,
38
+ isClassVariable: () => import_chunk_5SB3QASN.isClassVariable,
39
+ isLocal: () => import_chunk_5SB3QASN.isLocal,
40
+ isLookupCandidate: () => import_chunk_5SB3QASN.isLookupCandidate,
41
+ isStateNode: () => import_chunk_5SB3QASN.isStateNode,
42
+ lookupByFullName: () => import_chunk_5SB3QASN.lookupByFullName,
43
+ lookupNext: () => import_chunk_5SB3QASN.lookupNext,
44
+ lookupResultContains: () => import_chunk_5SB3QASN.lookupResultContains,
45
+ lookupWithType: () => import_chunk_5SB3QASN.lookupWithType,
46
+ makeToyboxLink: () => import_chunk_5SB3QASN.makeToyboxLink,
47
+ mapVarDeclsByType: () => import_chunk_5SB3QASN.mapVarDeclsByType,
48
+ markInvokeClassMethod: () => import_chunk_5SB3QASN.markInvokeClassMethod,
49
+ parseSdkVersion: () => import_chunk_5SB3QASN.parseSdkVersion,
50
+ popRootNode: () => import_chunk_5SB3QASN.popRootNode,
51
+ pushRootNode: () => import_chunk_5SB3QASN.pushRootNode,
52
+ resolveDiagnostics: () => import_chunk_5SB3QASN.resolveDiagnostics,
53
+ resolveDiagnosticsMap: () => import_chunk_5SB3QASN.resolveDiagnosticsMap,
54
+ sameLookupResult: () => import_chunk_5SB3QASN.sameLookupResult,
55
55
  traverseAst: () => import_chunk_UBAYZSM3.traverseAst,
56
- variableDeclarationName: () => import_chunk_VAV4N2CL.variableDeclarationName,
57
- visitReferences: () => import_chunk_VAV4N2CL.visitReferences,
58
- visit_resources: () => import_chunk_VAV4N2CL.visit_resources,
59
- visitorNode: () => import_chunk_VAV4N2CL.visitorNode
56
+ variableDeclarationName: () => import_chunk_5SB3QASN.variableDeclarationName,
57
+ visitReferences: () => import_chunk_5SB3QASN.visitReferences,
58
+ visit_resources: () => import_chunk_5SB3QASN.visit_resources,
59
+ visitorNode: () => import_chunk_5SB3QASN.visitorNode
60
60
  });
61
61
  module.exports = __toCommonJS(api_exports);
62
- var import_chunk_VAV4N2CL = require("./chunk-VAV4N2CL.cjs");
62
+ var import_chunk_5SB3QASN = require("./chunk-5SB3QASN.cjs");
63
63
  var import_chunk_IJS7AYMN = require("./chunk-IJS7AYMN.cjs");
64
64
  var import_chunk_UBAYZSM3 = require("./chunk-UBAYZSM3.cjs");
65
65
  var import_chunk_VS2QQHAK = require("./chunk-VS2QQHAK.cjs");
66
- (0, import_chunk_VAV4N2CL.init_api)();
66
+ (0, import_chunk_5SB3QASN.init_api)();
67
67
  // Annotate the CommonJS export names for ESM import in node:
68
68
  0 && (module.exports = {
69
69
  checkCompilerVersion,
@@ -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_VAV4N2CL_exports = {};
30
- __export(chunk_VAV4N2CL_exports, {
29
+ var chunk_5SB3QASN_exports = {};
30
+ __export(chunk_5SB3QASN_exports, {
31
31
  EnumTagsConst: () => EnumTagsConst,
32
32
  LastTypeTag: () => LastTypeTag,
33
33
  ObjectLikeTagsConst: () => ObjectLikeTagsConst,
@@ -140,7 +140,7 @@ __export(chunk_VAV4N2CL_exports, {
140
140
  visitorNode: () => visitorNode,
141
141
  xml_util_exports: () => xml_util_exports
142
142
  });
143
- module.exports = __toCommonJS(chunk_VAV4N2CL_exports);
143
+ module.exports = __toCommonJS(chunk_5SB3QASN_exports);
144
144
  var import_chunk_IJS7AYMN = require("./chunk-IJS7AYMN.cjs");
145
145
  var import_chunk_UBAYZSM3 = require("./chunk-UBAYZSM3.cjs");
146
146
  var import_chunk_VS2QQHAK = require("./chunk-VS2QQHAK.cjs");
@@ -3392,9 +3392,8 @@ function skipClassDef(view, current, symbols, code) {
3392
3392
  const type = isVariableSized ? view.getUint8(current++) : f1 & 15;
3393
3393
  const addr = view.getUint32((current += 4) - 4);
3394
3394
  if (type !== 6) continue;
3395
- const section = addr >>> 28;
3396
- if (section === 1) {
3397
- const pc = addr & 16777215;
3395
+ if ((addr & SECTION_PC_MASK) === TEXT_SECTION_PC) {
3396
+ const pc = addr & PC_OFFSET_MASK;
3398
3397
  const method = symbols.methods.get(pc);
3399
3398
  if (method) {
3400
3399
  if (method.id != null) {
@@ -3447,9 +3446,8 @@ function fixupClassDef(view, current, offsetMap, code) {
3447
3446
  const type = isVariableSized ? view.getUint8(current++) : f1 & 15;
3448
3447
  const addr = view.getUint32((current += 4) - 4);
3449
3448
  if (type !== 6) continue;
3450
- const section = addr >>> 28;
3451
- if (section === 1) {
3452
- const pc = addr & 16777215;
3449
+ if ((addr & SECTION_PC_MASK) === TEXT_SECTION_PC) {
3450
+ const pc = addr & PC_OFFSET_MASK;
3453
3451
  const newPc = offsetMap.get(pc);
3454
3452
  (0, import_node_assert.default)(newPc != null);
3455
3453
  view.setUint32(current - 4, addr - pc + newPc);
@@ -3508,7 +3506,7 @@ function recordCalledFunc(func, callee) {
3508
3506
  return null;
3509
3507
  }
3510
3508
  function recordCalledFuncs(func, callees) {
3511
- callees.forEach((callee) => {
3509
+ (0, import_chunk_IJS7AYMN.forEach)(callees, (callee) => {
3512
3510
  recordCalledFunc(func, callee);
3513
3511
  });
3514
3512
  }
@@ -3596,6 +3594,7 @@ var init_function_info = (0, import_chunk_VS2QQHAK.__esm)({
3596
3594
  "src/function-info.ts"() {
3597
3595
  "use strict";
3598
3596
  (0, import_chunk_UBAYZSM3.init_ast)();
3597
+ (0, import_chunk_IJS7AYMN.init_util)();
3599
3598
  }
3600
3599
  });
3601
3600
  var buildConfigDescription;
@@ -11655,6 +11654,10 @@ function updateAffected(blockState, objectType, baseDecl, assignedPath, affected
11655
11654
  function propagateTypes(state, root, graph, optimizeEquivalencies, copyPropStores, logThisRun) {
11656
11655
  const order = getPostOrder(graph).reverse();
11657
11656
  const queue = new DataflowQueue();
11657
+ const rootFunc = root.type === "FunctionDeclaration" ? root : null;
11658
+ if (rootFunc) {
11659
+ delete rootFunc.next_info;
11660
+ }
11658
11661
  const isStatic = !!(root.attributes & 8);
11659
11662
  const klass = root.stack?.[root.stack?.length - 1].sn;
11660
11663
  const selfClassDecl = klass && klass.type === "ClassDeclaration" ? klass : null;
@@ -12031,10 +12034,32 @@ function propagateTypes(state, root, graph, optimizeEquivalencies, copyPropStore
12031
12034
  root,
12032
12035
  dependencies
12033
12036
  };
12034
- const modifiableDecl = (decls, callees) => (0, import_chunk_IJS7AYMN.some)(
12035
- decls,
12036
- (decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" && !isLocal(decl) && (!callees || (0, import_chunk_IJS7AYMN.some)(callees, (callee) => functionMayModify(state, callee, decl)))
12037
- );
12037
+ const modifiableDecl = (decls, callees, node) => {
12038
+ if (!callees) {
12039
+ const lv = node.type === "AssignmentExpression" ? node.left : node.type === "UpdateExpression" ? node.argument : null;
12040
+ if (!lv) return true;
12041
+ if (lv.type === "MemberExpression") {
12042
+ if (lv.computed) {
12043
+ if (lv.property.type === "Literal") {
12044
+ return false;
12045
+ }
12046
+ if ((lv.property.type !== "UnaryExpression" || lv.property.operator !== ":") && !couldBe(
12047
+ {
12048
+ type: 131072
12049
+ /* Symbol */
12050
+ },
12051
+ evaluate(istate, lv.property).value
12052
+ )) {
12053
+ return false;
12054
+ }
12055
+ }
12056
+ }
12057
+ }
12058
+ return (0, import_chunk_IJS7AYMN.some)(
12059
+ decls,
12060
+ (decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" && !isLocal(decl) && (0, import_chunk_IJS7AYMN.some)(callees, (callee) => functionMayModify(state, callee, decl))
12061
+ );
12062
+ };
12038
12063
  const mergeSuccState = (top, curState) => {
12039
12064
  top.succs?.forEach((succ) => {
12040
12065
  if (succ.order == null) {
@@ -12459,6 +12484,13 @@ function propagateTypes(state, root, graph, optimizeEquivalencies, copyPropStore
12459
12484
  (0, import_chunk_IJS7AYMN.log)(describeEvent(event).then((eventStr) => ` ${eventStr}`));
12460
12485
  }
12461
12486
  modInterference(curState, event, true, (callees, calleeObj) => {
12487
+ if (rootFunc) {
12488
+ if (callees) {
12489
+ recordCalledFuncs(rootFunc, callees);
12490
+ } else {
12491
+ recordModifiedUnknown(rootFunc);
12492
+ }
12493
+ }
12462
12494
  clearRelatedCopyPropEvents(curState, null, nodeCopyProp);
12463
12495
  if (calleeObj) {
12464
12496
  const objType = getStateType(curState, calleeObj);
@@ -12487,7 +12519,7 @@ function propagateTypes(state, root, graph, optimizeEquivalencies, copyPropStore
12487
12519
  if ((type.value == null || !(type.type & (32768 | 512 | 1024))) && !(0, import_chunk_IJS7AYMN.some)(decl, (d) => d.type === "VariableDeclarator" && !isLocal(d))) {
12488
12520
  return;
12489
12521
  }
12490
- if (modifiableDecl(decl, callees)) {
12522
+ if (modifiableDecl(decl, callees, event.node)) {
12491
12523
  if (tsv.equivSet) {
12492
12524
  removeEquiv(curState.map, decl);
12493
12525
  }
@@ -12521,6 +12553,26 @@ function propagateTypes(state, root, graph, optimizeEquivalencies, copyPropStore
12521
12553
  break;
12522
12554
  }
12523
12555
  case "def": {
12556
+ if (rootFunc) {
12557
+ (0, import_chunk_IJS7AYMN.forEach)(event.decl, (decl) => {
12558
+ if (decl.type === "VariableDeclarator") {
12559
+ if (decl.node.kind !== "var") return;
12560
+ if (isLocal(decl)) return;
12561
+ recordModifiedDecl(rootFunc, decl);
12562
+ return;
12563
+ }
12564
+ if (decl.type === "MemberDecl") {
12565
+ const name = isLookupCandidate(decl.node);
12566
+ if (name) {
12567
+ recordModifiedName(rootFunc, name.name);
12568
+ return;
12569
+ }
12570
+ } else if (decl.type !== "Unknown") {
12571
+ return;
12572
+ }
12573
+ recordModifiedUnknown(rootFunc);
12574
+ });
12575
+ }
12524
12576
  const lval = event.node.type === "UpdateExpression" ? event.node.argument : event.node.type === "AssignmentExpression" ? event.node.left : null;
12525
12577
  if (lval) {
12526
12578
  if (nodeCopyProp.size && lval.type === "MemberExpression") {
@@ -13091,6 +13143,9 @@ function propagateTypes(state, root, graph, optimizeEquivalencies, copyPropStore
13091
13143
  }
13092
13144
  );
13093
13145
  }
13146
+ if (rootFunc) {
13147
+ rootFunc.info = rootFunc.next_info ?? false;
13148
+ }
13094
13149
  return {
13095
13150
  istate,
13096
13151
  nodeEquivs,
@@ -15321,7 +15376,6 @@ function getFileASTs(fnMap) {
15321
15376
  try {
15322
15377
  value2.ast = import_prettier_plugin_monkeyc2.default.parsers.monkeyc.parse(
15323
15378
  value2.monkeyCSource,
15324
- null,
15325
15379
  options
15326
15380
  );
15327
15381
  } catch (e) {
@@ -16675,7 +16729,7 @@ function visit_resource_refs(state, doc, e, barrelNames) {
16675
16729
  }
16676
16730
  const startPos = (0, import_chunk_UBAYZSM3.adjustLoc)(loc, -1, 0).start;
16677
16731
  try {
16678
- const expr = import_prettier_plugin_monkeyc3.default.parsers.monkeyc.parse(`(${name})`, null, {
16732
+ const expr = import_prettier_plugin_monkeyc3.default.parsers.monkeyc.parse(`(${name})`, {
16679
16733
  filepath: loc.source || void 0,
16680
16734
  singleExpression: true
16681
16735
  });
@@ -16720,30 +16774,33 @@ function visit_resource_refs(state, doc, e, barrelNames) {
16720
16774
  }
16721
16775
  if (id === "personality") {
16722
16776
  const elems = dotted.match(/\s+|\S+/g);
16723
- elems?.reduce((loc, name) => {
16724
- if (/\s/.test(name)) {
16725
- const newLines = name.match(/\r\n|[\r\n]/g);
16726
- if (newLines?.length) {
16727
- loc.start.line += newLines.length;
16728
- loc.start.column = 1;
16729
- loc.start.offset += name.length;
16730
- name = name.replace(/^.*(\r\n|[\r\n])(.*)$/, "$2");
16731
- loc.start.offset -= name.length;
16777
+ elems?.reduce(
16778
+ (loc, name) => {
16779
+ if (/\s/.test(name)) {
16780
+ const newLines = name.match(/\r\n|[\r\n]/g);
16781
+ if (newLines?.length) {
16782
+ loc.start.line += newLines.length;
16783
+ loc.start.column = 1;
16784
+ loc.start.offset += name.length;
16785
+ name = name.replace(/^.*(\r\n|[\r\n])(.*)$/, "$2");
16786
+ loc.start.offset -= name.length;
16787
+ }
16788
+ } else {
16789
+ const colonPos = name.indexOf(":");
16790
+ const barrel = colonPos < 0 ? "" : name.slice(0, colonPos) + ".";
16791
+ name = name.slice(colonPos + 1);
16792
+ const base = (0, import_chunk_UBAYZSM3.makeScopedName)(`${barrel}Rez.Styles`);
16793
+ const idLoc = (0, import_chunk_UBAYZSM3.adjustLoc)(loc, colonPos + 1, 0);
16794
+ idLoc.end = { ...idLoc.start };
16795
+ idLoc.end.column += name.length;
16796
+ idLoc.end.offset += name.length;
16797
+ const id2 = (0, import_chunk_UBAYZSM3.makeIdentifier)(name, idLoc);
16798
+ result.push((0, import_chunk_UBAYZSM3.makeMemberExpression)((0, import_chunk_UBAYZSM3.withLoc)(base, id2, false), id2));
16732
16799
  }
16733
- } else {
16734
- const colonPos = name.indexOf(":");
16735
- const barrel = colonPos < 0 ? "" : name.slice(0, colonPos) + ".";
16736
- name = name.slice(colonPos + 1);
16737
- const base = (0, import_chunk_UBAYZSM3.makeScopedName)(`${barrel}Rez.Styles`);
16738
- const idLoc = (0, import_chunk_UBAYZSM3.adjustLoc)(loc, colonPos + 1, 0);
16739
- idLoc.end = { ...idLoc.start };
16740
- idLoc.end.column += name.length;
16741
- idLoc.end.offset += name.length;
16742
- const id2 = (0, import_chunk_UBAYZSM3.makeIdentifier)(name, idLoc);
16743
- result.push((0, import_chunk_UBAYZSM3.makeMemberExpression)((0, import_chunk_UBAYZSM3.withLoc)(base, id2, false), id2));
16744
- }
16745
- return (0, import_chunk_UBAYZSM3.adjustLoc)(loc, name.length, 0);
16746
- }, (0, import_chunk_UBAYZSM3.adjustLoc)(l, 0, 0));
16800
+ return (0, import_chunk_UBAYZSM3.adjustLoc)(loc, name.length, 0);
16801
+ },
16802
+ (0, import_chunk_UBAYZSM3.adjustLoc)(l, 0, 0)
16803
+ );
16747
16804
  return;
16748
16805
  }
16749
16806
  if (/^\s*(true|false|null|NaN|(0x|#)[0-9a-f]+|[-+]?\d+%?)\s*$/i.test(dotted)) {
@@ -17286,9 +17343,7 @@ function checkCompilerVersion(version, sdkVer) {
17286
17343
  }
17287
17344
  function pushRootNode(state, stack, root) {
17288
17345
  if (root.type === "Program") return;
17289
- const sn = root.stack?.at(-1)?.sn?.decls?.[root.name]?.find(
17290
- (sn2) => sn2.type === root.type && (root.nodes != null || sn2.node === root.node)
17291
- ) ?? state.nestedClasses[root.name]?.find((d) => d.node === root.node);
17346
+ const sn = root.stack?.at(-1)?.sn?.decls?.[root.name]?.find((sn2) => sn2.type === root.type && (root.nodes != null || sn2.node === root.node)) ?? state.nestedClasses[root.name]?.find((d) => d.node === root.node);
17292
17347
  if (!sn) {
17293
17348
  throw new Error(`Invalid stack for node ${root.fullName}`);
17294
17349
  }
@@ -17315,7 +17370,7 @@ async function getApiMapping(state, resourcesMap, manifestXML) {
17315
17370
  }
17316
17371
  }
17317
17372
  const api = (await fs2.readFile(`${sdk}bin/api.mir`)).toString().replace(/\r\n/g, "\n").replace(/^(\s*static)?\s*<init>\s*\{\s*\}\s*?\n/gm, "").replace(/^(\s*type)\s/gm, "$1def ");
17318
- const ast = parser.parse(api, null, {
17373
+ const ast = parser.parse(api, {
17319
17374
  filepath: "api.mir"
17320
17375
  });
17321
17376
  if (resourcesMap) {
@@ -18697,6 +18752,7 @@ function buildDataFlowGraph(state, root, wantsLiteral, trackInsertionPoints, wan
18697
18752
  };
18698
18753
  const findDecl = (node) => {
18699
18754
  const path8 = [];
18755
+ const root2 = node;
18700
18756
  while (node.type === "MemberExpression" && (wantsAllRefs || !node.computed)) {
18701
18757
  path8.unshift(node);
18702
18758
  node = node.object;
@@ -18726,7 +18782,7 @@ function buildDataFlowGraph(state, root, wantsLiteral, trackInsertionPoints, wan
18726
18782
  )) {
18727
18783
  return {
18728
18784
  type: "MemberDecl",
18729
- node,
18785
+ node: root2,
18730
18786
  base: decl,
18731
18787
  path: path8
18732
18788
  };
@@ -19263,7 +19319,7 @@ function parseCode(view, lineTable) {
19263
19319
  const results = [];
19264
19320
  while (current < view.byteLength) {
19265
19321
  const nextOp = parseOne();
19266
- const lineNum = lineTable.get(nextOp.offset | 268435456);
19322
+ const lineNum = lineTable.get(nextOp.offset | TEXT_SECTION_PC);
19267
19323
  if (lineNum) {
19268
19324
  nextOp.lineNum = lineNum;
19269
19325
  }
@@ -19737,6 +19793,7 @@ var init_opcodes = (0, import_chunk_VS2QQHAK.__esm)({
19737
19793
  "src/readprg/opcodes.ts"() {
19738
19794
  "use strict";
19739
19795
  init_data_flow();
19796
+ init_bytecode();
19740
19797
  Opcodes = /* @__PURE__ */ ((Opcodes2) => {
19741
19798
  Opcodes2[Opcodes2["nop"] = 0] = "nop";
19742
19799
  Opcodes2[Opcodes2["incsp"] = 1] = "incsp";
@@ -22736,7 +22793,7 @@ function emitFunc(func, view, start, updateInfo, context) {
22736
22793
  if (bytecode.lineNum) {
22737
22794
  if (!lineNum || !compareLineInfo(lineNum, bytecode.lineNum)) {
22738
22795
  lineNum = { ...bytecode.lineNum };
22739
- lineNum.pc = offset | 268435456;
22796
+ lineNum.pc = offset | TEXT_SECTION_PC;
22740
22797
  updateInfo.lineMap.push(lineNum);
22741
22798
  }
22742
22799
  }
@@ -22946,6 +23003,7 @@ var init_emit = (0, import_chunk_VS2QQHAK.__esm)({
22946
23003
  "src/readprg/emit.ts"() {
22947
23004
  "use strict";
22948
23005
  (0, import_chunk_UBAYZSM3.init_ast)();
23006
+ init_bytecode();
22949
23007
  init_cflow();
22950
23008
  init_opcodes();
22951
23009
  init_optimize2();
@@ -23110,7 +23168,14 @@ function parseLineNum(view, debugXml) {
23110
23168
  return results;
23111
23169
  }
23112
23170
  function fixupLineNum(context, updateInfo) {
23113
- const symLineTable = updateInfo.lineMap.filter(
23171
+ const newLineTable = updateInfo.lineMap.concat(
23172
+ Array.from(context.lineTable.values()).filter(
23173
+ (lineNum) => (lineNum.pc & SECTION_PC_MASK) !== TEXT_SECTION_PC
23174
+ )
23175
+ );
23176
+ newLineTable.sort((a, b) => a.pc - b.pc);
23177
+ context.lineTable = new Map(newLineTable.map((l) => [l.pc, l]));
23178
+ const symLineTable = newLineTable.filter(
23114
23179
  (lineNum) => lineNum.file != null
23115
23180
  );
23116
23181
  const sectionLength = 2 + symLineTable.length * 16;
@@ -23142,7 +23207,7 @@ function fixupLineNum(context, updateInfo) {
23142
23207
  8,
23143
23208
  sectionLength
23144
23209
  );
23145
- const strLineTable = updateInfo.lineMap.filter(
23210
+ const strLineTable = newLineTable.filter(
23146
23211
  (lineNum) => lineNum.fileStr != null
23147
23212
  );
23148
23213
  if (context.debugXml.body instanceof Error) return;
@@ -23198,8 +23263,8 @@ function markLocals(context) {
23198
23263
  context.debugXml.body.children("localVars").children("entry").elements.forEach((entry) => {
23199
23264
  const { startPc, endPc, stackId, name, arg } = entry.attr;
23200
23265
  (0, import_node_assert16.default)(startPc && endPc && stackId && name);
23201
- const spc = Number(startPc.value.value) & 16777215;
23202
- const epc = (Number(endPc.value.value) & 16777215) + 1;
23266
+ const spc = Number(startPc.value.value) & PC_OFFSET_MASK;
23267
+ const epc = (Number(endPc.value.value) & PC_OFFSET_MASK) + 1;
23203
23268
  const sid = Number(stackId.value.value);
23204
23269
  let locals = localMap.get(spc);
23205
23270
  if (!locals) {
@@ -23332,7 +23397,7 @@ function optimizeBytecode(context) {
23332
23397
  funcArray.push({ offset: code.byteLength, blocks: /* @__PURE__ */ new Map() });
23333
23398
  const funcIndex = (pc) => {
23334
23399
  let lo = 0, hi = funcArray.length;
23335
- pc = pc & 16777215;
23400
+ pc = pc & PC_OFFSET_MASK;
23336
23401
  while (hi - lo > 1) {
23337
23402
  const mid = hi + lo >>> 1;
23338
23403
  if (funcArray[mid].offset > pc) {
@@ -23346,29 +23411,33 @@ function optimizeBytecode(context) {
23346
23411
  const funcRange = (pc) => {
23347
23412
  const index = funcIndex(pc);
23348
23413
  (0, import_node_assert16.default)(
23349
- funcArray[index].offset <= (pc & 16777215) && funcArray[index + 1].offset > (pc & 16777215)
23414
+ funcArray[index].offset <= (pc & PC_OFFSET_MASK) && funcArray[index + 1].offset > (pc & PC_OFFSET_MASK)
23350
23415
  );
23351
23416
  const s = offsetMap.get(funcArray[index].offset);
23352
23417
  const e = offsetMap.get(funcArray[index + 1].offset);
23353
23418
  if (s == null || e == null) {
23354
23419
  (0, import_node_assert16.default)(s != null && e != null);
23355
23420
  }
23356
- return [s + 268435456, e + 268435456];
23421
+ return [s + TEXT_SECTION_PC, e + TEXT_SECTION_PC];
23357
23422
  };
23358
23423
  const localVars = context.debugXml.body.children("localVars");
23359
23424
  const addAttr = (element, attrName, attrValue) => {
23360
23425
  element.attr[attrName] = xml_util_exports.makeAttribute(attrName, attrValue);
23361
23426
  };
23362
23427
  localVars.elements.forEach((element, i) => {
23428
+ const original = element.children;
23363
23429
  delete element.children;
23364
23430
  if (i) return;
23365
- element.children = [];
23366
- const children = element.children;
23431
+ const children = original?.filter((elt) => {
23432
+ if (elt.type !== "element") return false;
23433
+ if (!elt.attr?.startPc) return false;
23434
+ const spc = Number(elt.attr.startPc.value.value);
23435
+ return (spc & SECTION_PC_MASK) !== TEXT_SECTION_PC;
23436
+ }) ?? [];
23367
23437
  updateInfo.localRanges.forEach((localRange) => {
23368
23438
  if (localRange.endPc === localRange.startPc) {
23369
23439
  return;
23370
23440
  }
23371
- children.push({ type: "chardata", value: "\n" });
23372
23441
  const element2 = {
23373
23442
  type: "element",
23374
23443
  name: "entry",
@@ -23378,18 +23447,34 @@ function optimizeBytecode(context) {
23378
23447
  if (localRange.isParam) {
23379
23448
  addAttr(element2, "arg", "true");
23380
23449
  }
23381
- addAttr(element2, "startPc", (localRange.startPc + 268435456).toString());
23382
- addAttr(element2, "endPc", (localRange.endPc + 268435456).toString());
23450
+ addAttr(
23451
+ element2,
23452
+ "startPc",
23453
+ (localRange.startPc + TEXT_SECTION_PC).toString()
23454
+ );
23455
+ addAttr(
23456
+ element2,
23457
+ "endPc",
23458
+ (localRange.endPc + TEXT_SECTION_PC).toString()
23459
+ );
23383
23460
  addAttr(element2, "stackId", localRange.slot.toString());
23384
23461
  children.push(element2);
23385
23462
  });
23386
- children.push({ type: "chardata", value: "\n" });
23463
+ element.children = children.sort(
23464
+ (a, b) => Number(a.attr.startPc?.value.value ?? 0) - Number(b.attr.startPc?.value.value ?? 0)
23465
+ ).flatMap((e) => [{ type: "chardata", value: "\n" }, e]);
23466
+ element.children.push({ type: "chardata", value: "\n" });
23387
23467
  });
23388
23468
  context.debugXml.body.children("functions").children("functionEntry").elements.forEach((entry) => {
23389
23469
  const { startPc, endPc } = entry.attr;
23390
23470
  if (!startPc || !endPc) return;
23391
- const range = funcRange(Number(startPc.value.value));
23392
- (0, import_node_assert16.default)(funcRange(Number(endPc.value.value))[0] === range[0]);
23471
+ const spc = Number(startPc.value.value);
23472
+ const epc = Number(endPc.value.value);
23473
+ if ((spc & SECTION_PC_MASK) !== TEXT_SECTION_PC) {
23474
+ return;
23475
+ }
23476
+ const range = funcRange(spc);
23477
+ (0, import_node_assert16.default)(funcRange(epc)[0] === range[0]);
23393
23478
  startPc.value.value = range[0].toString();
23394
23479
  endPc.value.value = (range[1] - 1).toString();
23395
23480
  });
@@ -23823,7 +23908,7 @@ function countFallthroughPreds(func, block) {
23823
23908
  return count;
23824
23909
  }, 0);
23825
23910
  }
23826
- var SectionKinds;
23911
+ var SectionKinds, TEXT_SECTION_PC, SECTION_PC_MASK, PC_OFFSET_MASK;
23827
23912
  var init_bytecode = (0, import_chunk_VS2QQHAK.__esm)({
23828
23913
  "src/readprg/bytecode.ts"() {
23829
23914
  "use strict";
@@ -23841,6 +23926,7 @@ var init_bytecode = (0, import_chunk_VS2QQHAK.__esm)({
23841
23926
  SectionKinds2[SectionKinds2["HEADER"] = -805253120] = "HEADER";
23842
23927
  SectionKinds2[SectionKinds2["HEADER_VERSIONED"] = -805253107] = "HEADER_VERSIONED";
23843
23928
  SectionKinds2[SectionKinds2["TEXT"] = -1059145026] = "TEXT";
23929
+ SectionKinds2[SectionKinds2["EXTENDED"] = -1059188563] = "EXTENDED";
23844
23930
  SectionKinds2[SectionKinds2["DATA"] = -629491010] = "DATA";
23845
23931
  SectionKinds2[SectionKinds2["SYMBOLS"] = 1461170197] = "SYMBOLS";
23846
23932
  SectionKinds2[SectionKinds2["LINENUM"] = -1059161423] = "LINENUM";
@@ -23849,6 +23935,9 @@ var init_bytecode = (0, import_chunk_VS2QQHAK.__esm)({
23849
23935
  SectionKinds2[SectionKinds2["STORE_SIG"] = 20833] = "STORE_SIG";
23850
23936
  return SectionKinds2;
23851
23937
  })(SectionKinds || {});
23938
+ TEXT_SECTION_PC = 268435456;
23939
+ SECTION_PC_MASK = 4026531840;
23940
+ PC_OFFSET_MASK = 16777215;
23852
23941
  }
23853
23942
  });
23854
23943
  function getPrgSignature(context) {
@@ -23969,6 +24058,7 @@ var SymbolTable;
23969
24058
  var init_symbols = (0, import_chunk_VS2QQHAK.__esm)({
23970
24059
  "src/readprg/symbols.ts"() {
23971
24060
  "use strict";
24061
+ init_bytecode();
23972
24062
  SymbolTable = class {
23973
24063
  // given a symbol id, symbolToLabelMap.get(id) gives the
23974
24064
  // label offset, then symbols.get(label) gives us the symbol
@@ -23999,7 +24089,7 @@ var init_symbols = (0, import_chunk_VS2QQHAK.__esm)({
23999
24089
  const { startPc, name, parent } = functionEntry.attr;
24000
24090
  if (!startPc || !name) return;
24001
24091
  const fullPc = Number(startPc.value.value);
24002
- if (fullPc >>> 28 !== 1) {
24092
+ if ((fullPc & SECTION_PC_MASK) !== TEXT_SECTION_PC) {
24003
24093
  return;
24004
24094
  }
24005
24095
  const pc = fullPc & 16777215;
@@ -27355,7 +27445,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
27355
27445
  const opt_time = await (0, import_chunk_IJS7AYMN.first_modified)(
27356
27446
  Object.values(fnMap).map((v) => v.output)
27357
27447
  );
27358
- if (source_time < opt_time && 1767144581089 < opt_time) {
27448
+ if (source_time < opt_time && 1769823563413 < opt_time) {
27359
27449
  return {
27360
27450
  hasTests,
27361
27451
  diagnostics: prevDiagnostics,
@@ -27393,7 +27483,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
27393
27483
  hasTests: hasTests2,
27394
27484
  diagnostics,
27395
27485
  sdkVersion,
27396
- optimizerVersion: "1.1.92",
27486
+ optimizerVersion: "1.1.94",
27397
27487
  ...Object.fromEntries(
27398
27488
  configOptionsToCheck.map((option) => [option, config[option]])
27399
27489
  )
@@ -18,30 +18,30 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var optimizer_exports = {};
20
20
  __export(optimizer_exports, {
21
- StateNodeAttributes: () => import_chunk_VAV4N2CL.StateNodeAttributes,
22
- buildConfigDescription: () => import_chunk_VAV4N2CL.buildConfigDescription,
23
- buildOptimizedProject: () => import_chunk_VAV4N2CL.buildOptimizedProject,
21
+ StateNodeAttributes: () => import_chunk_5SB3QASN.StateNodeAttributes,
22
+ buildConfigDescription: () => import_chunk_5SB3QASN.buildConfigDescription,
23
+ buildOptimizedProject: () => import_chunk_5SB3QASN.buildOptimizedProject,
24
24
  copyRecursiveAsNeeded: () => import_chunk_IJS7AYMN.copyRecursiveAsNeeded,
25
- defaultConfig: () => import_chunk_VAV4N2CL.defaultConfig,
26
- display: () => import_chunk_VAV4N2CL.display,
27
- generateOneConfig: () => import_chunk_VAV4N2CL.generateOneConfig,
28
- generateOptimizedProject: () => import_chunk_VAV4N2CL.generateOptimizedProject,
29
- getConfig: () => import_chunk_VAV4N2CL.getConfig,
30
- getFnMapAnalysis: () => import_chunk_VAV4N2CL.getFnMapAnalysis,
31
- getProjectAnalysis: () => import_chunk_VAV4N2CL.getProjectAnalysis,
32
- get_jungle: () => import_chunk_VAV4N2CL.get_jungle,
33
- isErrorWithLocation: () => import_chunk_VAV4N2CL.isErrorWithLocation,
34
- launchSimulator: () => import_chunk_VAV4N2CL.launchSimulator,
35
- manifestProducts: () => import_chunk_VAV4N2CL.manifestProducts,
36
- mctree: () => import_chunk_VAV4N2CL.mctree,
37
- simulateProgram: () => import_chunk_VAV4N2CL.simulateProgram
25
+ defaultConfig: () => import_chunk_5SB3QASN.defaultConfig,
26
+ display: () => import_chunk_5SB3QASN.display,
27
+ generateOneConfig: () => import_chunk_5SB3QASN.generateOneConfig,
28
+ generateOptimizedProject: () => import_chunk_5SB3QASN.generateOptimizedProject,
29
+ getConfig: () => import_chunk_5SB3QASN.getConfig,
30
+ getFnMapAnalysis: () => import_chunk_5SB3QASN.getFnMapAnalysis,
31
+ getProjectAnalysis: () => import_chunk_5SB3QASN.getProjectAnalysis,
32
+ get_jungle: () => import_chunk_5SB3QASN.get_jungle,
33
+ isErrorWithLocation: () => import_chunk_5SB3QASN.isErrorWithLocation,
34
+ launchSimulator: () => import_chunk_5SB3QASN.launchSimulator,
35
+ manifestProducts: () => import_chunk_5SB3QASN.manifestProducts,
36
+ mctree: () => import_chunk_5SB3QASN.mctree,
37
+ simulateProgram: () => import_chunk_5SB3QASN.simulateProgram
38
38
  });
39
39
  module.exports = __toCommonJS(optimizer_exports);
40
- var import_chunk_VAV4N2CL = require("./chunk-VAV4N2CL.cjs");
40
+ var import_chunk_5SB3QASN = require("./chunk-5SB3QASN.cjs");
41
41
  var import_chunk_IJS7AYMN = require("./chunk-IJS7AYMN.cjs");
42
42
  var import_chunk_UBAYZSM3 = require("./chunk-UBAYZSM3.cjs");
43
43
  var import_chunk_VS2QQHAK = require("./chunk-VS2QQHAK.cjs");
44
- (0, import_chunk_VAV4N2CL.init_optimizer)();
44
+ (0, import_chunk_5SB3QASN.init_optimizer)();
45
45
  // Annotate the CommonJS export names for ESM import in node:
46
46
  0 && (module.exports = {
47
47
  StateNodeAttributes,