@markw65/monkeyc-optimizer 1.1.40 → 1.1.41

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/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  All notable changes to the "monkeyc-optimizer" package will be documented in this file.
4
4
 
5
+ ### 1.1.41
6
+
7
+ - Add proper support for tuple types (Sdk-7.x)
8
+ - Fix a bug with the signature of the initialize method of resource-generated menus
9
+
5
10
  ### 1.1.40
6
11
 
7
12
  - Update the bytecode optimizer to be compatible with Sdk-7.x
package/build/api.cjs CHANGED
@@ -18,47 +18,47 @@ 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_Z2SLP4FQ.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_Z2SLP4FQ.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_Z2SLP4FQ.createDocumentationMap,
24
- diagnostic: () => import_chunk_Z2SLP4FQ.diagnostic,
25
- diagnosticHelper: () => import_chunk_Z2SLP4FQ.diagnosticHelper,
26
- findNamesInScope: () => import_chunk_Z2SLP4FQ.findNamesInScope,
27
- findUsingForNode: () => import_chunk_Z2SLP4FQ.findUsingForNode,
28
- formatAst: () => import_chunk_Z2SLP4FQ.formatAst,
29
- formatAstLongLines: () => import_chunk_Z2SLP4FQ.formatAstLongLines,
30
- formatScopedName: () => import_chunk_Z2SLP4FQ.formatScopedName,
31
- getApiFunctionInfo: () => import_chunk_Z2SLP4FQ.getApiFunctionInfo,
32
- getApiMapping: () => import_chunk_Z2SLP4FQ.getApiMapping,
33
- getSuperClasses: () => import_chunk_Z2SLP4FQ.getSuperClasses,
21
+ checkCompilerVersion: () => import_chunk_BJHWDTEM.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_BJHWDTEM.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_BJHWDTEM.createDocumentationMap,
24
+ diagnostic: () => import_chunk_BJHWDTEM.diagnostic,
25
+ diagnosticHelper: () => import_chunk_BJHWDTEM.diagnosticHelper,
26
+ findNamesInScope: () => import_chunk_BJHWDTEM.findNamesInScope,
27
+ findUsingForNode: () => import_chunk_BJHWDTEM.findUsingForNode,
28
+ formatAst: () => import_chunk_BJHWDTEM.formatAst,
29
+ formatAstLongLines: () => import_chunk_BJHWDTEM.formatAstLongLines,
30
+ formatScopedName: () => import_chunk_BJHWDTEM.formatScopedName,
31
+ getApiFunctionInfo: () => import_chunk_BJHWDTEM.getApiFunctionInfo,
32
+ getApiMapping: () => import_chunk_BJHWDTEM.getApiMapping,
33
+ getSuperClasses: () => import_chunk_BJHWDTEM.getSuperClasses,
34
34
  hasProperty: () => import_chunk_MBTLUWXR.hasProperty,
35
- isClassVariable: () => import_chunk_Z2SLP4FQ.isClassVariable,
36
- isLocal: () => import_chunk_Z2SLP4FQ.isLocal,
37
- isLookupCandidate: () => import_chunk_Z2SLP4FQ.isLookupCandidate,
38
- isStateNode: () => import_chunk_Z2SLP4FQ.isStateNode,
39
- lookupByFullName: () => import_chunk_Z2SLP4FQ.lookupByFullName,
40
- lookupNext: () => import_chunk_Z2SLP4FQ.lookupNext,
41
- lookupResultContains: () => import_chunk_Z2SLP4FQ.lookupResultContains,
42
- lookupWithType: () => import_chunk_Z2SLP4FQ.lookupWithType,
43
- makeToyboxLink: () => import_chunk_Z2SLP4FQ.makeToyboxLink,
44
- mapVarDeclsByType: () => import_chunk_Z2SLP4FQ.mapVarDeclsByType,
45
- markInvokeClassMethod: () => import_chunk_Z2SLP4FQ.markInvokeClassMethod,
46
- parseSdkVersion: () => import_chunk_Z2SLP4FQ.parseSdkVersion,
47
- resolveDiagnostics: () => import_chunk_Z2SLP4FQ.resolveDiagnostics,
48
- resolveDiagnosticsMap: () => import_chunk_Z2SLP4FQ.resolveDiagnosticsMap,
49
- sameLookupResult: () => import_chunk_Z2SLP4FQ.sameLookupResult,
35
+ isClassVariable: () => import_chunk_BJHWDTEM.isClassVariable,
36
+ isLocal: () => import_chunk_BJHWDTEM.isLocal,
37
+ isLookupCandidate: () => import_chunk_BJHWDTEM.isLookupCandidate,
38
+ isStateNode: () => import_chunk_BJHWDTEM.isStateNode,
39
+ lookupByFullName: () => import_chunk_BJHWDTEM.lookupByFullName,
40
+ lookupNext: () => import_chunk_BJHWDTEM.lookupNext,
41
+ lookupResultContains: () => import_chunk_BJHWDTEM.lookupResultContains,
42
+ lookupWithType: () => import_chunk_BJHWDTEM.lookupWithType,
43
+ makeToyboxLink: () => import_chunk_BJHWDTEM.makeToyboxLink,
44
+ mapVarDeclsByType: () => import_chunk_BJHWDTEM.mapVarDeclsByType,
45
+ markInvokeClassMethod: () => import_chunk_BJHWDTEM.markInvokeClassMethod,
46
+ parseSdkVersion: () => import_chunk_BJHWDTEM.parseSdkVersion,
47
+ resolveDiagnostics: () => import_chunk_BJHWDTEM.resolveDiagnostics,
48
+ resolveDiagnosticsMap: () => import_chunk_BJHWDTEM.resolveDiagnosticsMap,
49
+ sameLookupResult: () => import_chunk_BJHWDTEM.sameLookupResult,
50
50
  traverseAst: () => import_chunk_MBTLUWXR.traverseAst,
51
- variableDeclarationName: () => import_chunk_Z2SLP4FQ.variableDeclarationName,
52
- visitReferences: () => import_chunk_Z2SLP4FQ.visitReferences,
53
- visit_resources: () => import_chunk_Z2SLP4FQ.visit_resources,
54
- visitorNode: () => import_chunk_Z2SLP4FQ.visitorNode
51
+ variableDeclarationName: () => import_chunk_BJHWDTEM.variableDeclarationName,
52
+ visitReferences: () => import_chunk_BJHWDTEM.visitReferences,
53
+ visit_resources: () => import_chunk_BJHWDTEM.visit_resources,
54
+ visitorNode: () => import_chunk_BJHWDTEM.visitorNode
55
55
  });
56
56
  module.exports = __toCommonJS(api_exports);
57
- var import_chunk_Z2SLP4FQ = require("./chunk-Z2SLP4FQ.cjs");
57
+ var import_chunk_BJHWDTEM = require("./chunk-BJHWDTEM.cjs");
58
58
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
59
59
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
60
60
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
61
- (0, import_chunk_Z2SLP4FQ.init_api)();
61
+ (0, import_chunk_BJHWDTEM.init_api)();
62
62
  // Annotate the CommonJS export names for ESM import in node:
63
63
  0 && (module.exports = {
64
64
  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_Z2SLP4FQ_exports = {};
30
- __export(chunk_Z2SLP4FQ_exports, {
29
+ var chunk_BJHWDTEM_exports = {};
30
+ __export(chunk_BJHWDTEM_exports, {
31
31
  EnumTagsConst: () => EnumTagsConst,
32
32
  LastTypeTag: () => LastTypeTag,
33
33
  ObjectLikeTagsConst: () => ObjectLikeTagsConst,
@@ -86,6 +86,7 @@ __export(chunk_Z2SLP4FQ_exports, {
86
86
  init_union_type: () => init_union_type,
87
87
  init_worker_pool: () => init_worker_pool,
88
88
  init_worker_task: () => init_worker_task,
89
+ init_xml_util: () => init_xml_util,
89
90
  intersection: () => intersection,
90
91
  isClassVariable: () => isClassVariable,
91
92
  isCondBranch: () => isCondBranch,
@@ -108,8 +109,10 @@ __export(chunk_Z2SLP4FQ_exports, {
108
109
  mustBeTrue: () => mustBeTrue,
109
110
  opcodeSize: () => opcodeSize,
110
111
  optimizeFunc: () => optimizeFunc,
112
+ optimizeMonkeyC: () => optimizeMonkeyC,
111
113
  optimizeProgram: () => optimizeProgram,
112
114
  parseSdkVersion: () => parseSdkVersion,
115
+ parseXml: () => parseXml,
113
116
  performTask: () => performTask,
114
117
  readPrg: () => readPrg,
115
118
  readPrgWithOffsets: () => readPrgWithOffsets,
@@ -130,7 +133,7 @@ __export(chunk_Z2SLP4FQ_exports, {
130
133
  visitorNode: () => visitorNode,
131
134
  xml_util_exports: () => xml_util_exports
132
135
  });
133
- module.exports = __toCommonJS(chunk_Z2SLP4FQ_exports);
136
+ module.exports = __toCommonJS(chunk_BJHWDTEM_exports);
134
137
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
135
138
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
136
139
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
@@ -7291,7 +7294,7 @@ function mergeSingle(pair) {
7291
7294
  case 1:
7292
7295
  case 2:
7293
7296
  case 4:
7294
- throw new Error("Unexpected typetag in mergeSingle");
7297
+ throw new Error("Unexpected TypeTag in mergeSingle");
7295
7298
  case 8:
7296
7299
  case 16:
7297
7300
  case 32:
@@ -7304,8 +7307,24 @@ function mergeSingle(pair) {
7304
7307
  }
7305
7308
  return [null, true];
7306
7309
  case 512: {
7307
- const merged = tryUnion(pair.avalue, pair.bvalue);
7308
- return [merged || pair.avalue, merged != null];
7310
+ if (Array.isArray(pair.avalue)) {
7311
+ const bv = pair.bvalue;
7312
+ if (Array.isArray(bv)) {
7313
+ if (pair.avalue.length === bv.length) {
7314
+ let changed = false;
7315
+ const u = pair.avalue.map((a, i) => {
7316
+ const merged2 = tryUnion(a, bv[i]);
7317
+ if (merged2)
7318
+ changed = true;
7319
+ return merged2 || a;
7320
+ });
7321
+ return [u, changed];
7322
+ }
7323
+ }
7324
+ }
7325
+ const av = reducedType(pair.avalue);
7326
+ const merged = tryUnion(av, reducedType(pair.bvalue));
7327
+ return [merged || av, merged != null];
7309
7328
  }
7310
7329
  case 1024: {
7311
7330
  const avalue = pair.avalue;
@@ -7556,11 +7575,29 @@ function widenTypeHelper(t, depth) {
7556
7575
  result = cloneType(t);
7557
7576
  clearValuesUnder(result, ac.type);
7558
7577
  } else {
7559
- const v = widenTypeHelper(ac.value, depth + 1);
7560
- if (v) {
7561
- if (!result)
7562
- result = cloneType(t);
7563
- setUnionComponent(result, ac.type, v);
7578
+ if (Array.isArray(ac.value)) {
7579
+ let newAData = ac.value;
7580
+ ac.value.forEach((avalue, index) => {
7581
+ const data = widenTypeHelper(avalue, depth + 1);
7582
+ if (data) {
7583
+ if (newAData === ac.value) {
7584
+ newAData = newAData.slice();
7585
+ }
7586
+ newAData[index] = data;
7587
+ }
7588
+ });
7589
+ if (newAData !== ac.value) {
7590
+ if (!result)
7591
+ result = cloneType(t);
7592
+ setUnionComponent(result, ac.type, newAData);
7593
+ }
7594
+ } else {
7595
+ const v = widenTypeHelper(ac.value, depth + 1);
7596
+ if (v) {
7597
+ if (!result)
7598
+ result = cloneType(t);
7599
+ setUnionComponent(result, ac.type, v);
7600
+ }
7564
7601
  }
7565
7602
  }
7566
7603
  return;
@@ -7754,6 +7791,31 @@ function intersectionValue(pair) {
7754
7791
  case 131072:
7755
7792
  return pair.avalue === pair.bvalue ? pair.avalue : null;
7756
7793
  case 512: {
7794
+ if (Array.isArray(pair.avalue)) {
7795
+ const bv = pair.bvalue;
7796
+ if (Array.isArray(bv)) {
7797
+ if (pair.avalue.length !== bv.length) {
7798
+ return null;
7799
+ }
7800
+ const isect2 = pair.avalue.map((t, i) => intersection(t, bv[i]));
7801
+ return isect2.some(
7802
+ (t) => t.type === 0
7803
+ /* Never */
7804
+ ) ? null : isect2;
7805
+ }
7806
+ const isect = pair.avalue.map((t) => intersection(t, bv));
7807
+ return isect.some(
7808
+ (t) => t.type === 0
7809
+ /* Never */
7810
+ ) ? null : isect;
7811
+ } else if (Array.isArray(pair.bvalue)) {
7812
+ const av = pair.avalue;
7813
+ const isect = pair.bvalue.map((t) => intersection(av, t));
7814
+ return isect.some(
7815
+ (t) => t.type === 0
7816
+ /* Never */
7817
+ ) ? null : isect;
7818
+ }
7757
7819
  const atype = intersection(pair.avalue, pair.bvalue);
7758
7820
  return atype.type === 0 ? null : atype;
7759
7821
  }
@@ -8197,8 +8259,21 @@ function subtypeOfValue(pair) {
8197
8259
  case 128:
8198
8260
  case 131072:
8199
8261
  return pair.avalue === pair.bvalue;
8200
- case 512:
8262
+ case 512: {
8263
+ if (Array.isArray(pair.avalue)) {
8264
+ const bv = pair.bvalue;
8265
+ if (Array.isArray(bv)) {
8266
+ if (pair.avalue.length !== bv.length) {
8267
+ return false;
8268
+ }
8269
+ return pair.avalue.every((t, i) => subtypeOf(t, bv[i]));
8270
+ }
8271
+ return pair.avalue.every((t) => subtypeOf(t, bv));
8272
+ } else if (Array.isArray(pair.bvalue)) {
8273
+ return false;
8274
+ }
8201
8275
  return subtypeOf(pair.avalue, pair.bvalue);
8276
+ }
8202
8277
  case 1024: {
8203
8278
  const adict = pair.avalue;
8204
8279
  const bdict = pair.bvalue;
@@ -9012,10 +9087,12 @@ function checkCallArgs(istate, node, callees, args) {
9012
9087
  512
9013
9088
  /* Array */
9014
9089
  );
9015
- if (!ptype || !subtypeOf(ptype, atype)) {
9090
+ if (!ptype || Array.isArray(ptype) || Array.isArray(atype) || !subtypeOf(ptype, atype)) {
9016
9091
  curDiags.push([
9017
9092
  node.arguments[i],
9018
- `Argument ${i + 1} to ${cur.fullName}: passing Array<${display(atype)}> to parameter Array${ptype ? `<${display(ptype)}>` : ""} is not type safe`
9093
+ `Argument ${i + 1} to ${cur.fullName}: passing ${display(
9094
+ arg
9095
+ )} to parameter ${display(paramType)} is not type safe`
9019
9096
  ]);
9020
9097
  }
9021
9098
  }
@@ -9139,7 +9216,13 @@ function getSystemCallTable(state) {
9139
9216
  if (args.length === 1) {
9140
9217
  const arg = args[0];
9141
9218
  if (callee.name === "add") {
9142
- if (!subtypeOf(arg, adata)) {
9219
+ if (Array.isArray(adata)) {
9220
+ const relaxed = relaxType(arg);
9221
+ const newAData = [...adata, relaxed];
9222
+ ret.returnType.value = newAData;
9223
+ ret.argTypes = [relaxed];
9224
+ ret.calleeObj = ret.returnType;
9225
+ } else if (!subtypeOf(arg, adata)) {
9143
9226
  const newAData = cloneType(adata);
9144
9227
  unionInto(newAData, arg);
9145
9228
  const newObj = cloneType(calleeObj);
@@ -9148,6 +9231,23 @@ function getSystemCallTable(state) {
9148
9231
  ret.argTypes = [adata];
9149
9232
  }
9150
9233
  } else {
9234
+ if (Array.isArray(adata)) {
9235
+ if (arg.type & 512) {
9236
+ const argSubtypes = getUnionComponent(
9237
+ arg,
9238
+ 512
9239
+ /* Array */
9240
+ );
9241
+ if (argSubtypes && Array.isArray(argSubtypes)) {
9242
+ const newAData = [...adata, ...argSubtypes];
9243
+ ret.returnType.value = newAData;
9244
+ ret.argTypes = [arg];
9245
+ ret.calleeObj = ret.returnType;
9246
+ return ret;
9247
+ }
9248
+ }
9249
+ ret.returnType.value = reducedType(adata);
9250
+ }
9151
9251
  if (!subtypeOf(arg, ret.returnType)) {
9152
9252
  ret.argTypes = [ret.returnType];
9153
9253
  const newObj = cloneType(calleeObj);
@@ -9823,6 +9923,24 @@ function deEnumerate(t) {
9823
9923
  }
9824
9924
  return t;
9825
9925
  }
9926
+ function arrayTypeAtIndex(arr, elemType) {
9927
+ if (Array.isArray(arr)) {
9928
+ if (elemType && isExact(elemType) && elemType.type === 8 && elemType.value != null && arr[elemType.value] != null) {
9929
+ return arr[elemType.value];
9930
+ }
9931
+ return arr.reduce(
9932
+ (p, v) => {
9933
+ unionInto(p, v);
9934
+ return p;
9935
+ },
9936
+ {
9937
+ type: 0
9938
+ /* Never */
9939
+ }
9940
+ );
9941
+ }
9942
+ return arr;
9943
+ }
9826
9944
  function getLhsConstraint(istate, node) {
9827
9945
  if (istate.localLvals?.has(node)) {
9828
9946
  return null;
@@ -9851,7 +9969,7 @@ function getLhsConstraint(istate, node) {
9851
9969
  /* Array */
9852
9970
  );
9853
9971
  if (arr) {
9854
- result = arr;
9972
+ result = arrayTypeAtIndex(arr, istate.typeMap.get(node.property));
9855
9973
  }
9856
9974
  }
9857
9975
  const updateResult = (value2) => {
@@ -10154,23 +10272,9 @@ function evaluateNode(istate, node) {
10154
10272
  node
10155
10273
  });
10156
10274
  } else {
10157
- const value2 = relaxType(
10158
- args.reduce(
10159
- (cur, next) => {
10160
- unionInto(cur, next.value);
10161
- return cur;
10162
- },
10163
- {
10164
- type: 0
10165
- /* Never */
10166
- }
10167
- )
10168
- );
10275
+ const value2 = args.map((arg) => relaxType(arg.value));
10169
10276
  push({
10170
- value: value2.type === 0 ? {
10171
- type: 512
10172
- /* Array */
10173
- } : { type: 512, value: value2 },
10277
+ value: { type: 512, value: value2 },
10174
10278
  embeddedEffects,
10175
10279
  node
10176
10280
  });
@@ -10329,10 +10433,11 @@ function evaluateNode(istate, node) {
10329
10433
  type: 524287
10330
10434
  /* Any */
10331
10435
  };
10436
+ const atype = arrayTypeAtIndex(avalue, property.value);
10332
10437
  if (result) {
10333
- unionInto(result = cloneType(result), avalue);
10438
+ unionInto(result = cloneType(result), atype);
10334
10439
  } else {
10335
- result = avalue;
10440
+ result = atype;
10336
10441
  }
10337
10442
  }
10338
10443
  if (objectType.type & 1024) {
@@ -11005,6 +11110,20 @@ function typeFromTypeStateNodes(state, sns, classVsObj) {
11005
11110
  }
11006
11111
  );
11007
11112
  }
11113
+ function arrayLiteralKeyFromType(k) {
11114
+ if (k && k.value != null) {
11115
+ if (k.type === 8 || k.type === 16) {
11116
+ return Number(k.value);
11117
+ }
11118
+ }
11119
+ return null;
11120
+ }
11121
+ function arrayLiteralKeyFromExpr(key) {
11122
+ if (key.type === "Literal") {
11123
+ return arrayLiteralKeyFromType(typeFromLiteral(key));
11124
+ }
11125
+ return null;
11126
+ }
11008
11127
  function objectLiteralKeyFromExpr(key) {
11009
11128
  switch (key.type) {
11010
11129
  case "Literal": {
@@ -11080,18 +11199,8 @@ function typeFromSingleTypeSpec(state, type, stack) {
11080
11199
  case "ArrayExpression": {
11081
11200
  return {
11082
11201
  type: 512,
11083
- value: type.elements.reduce(
11084
- (prev, cur) => {
11085
- unionInto(
11086
- prev,
11087
- typeFromTypespec(state, cur)
11088
- );
11089
- return prev;
11090
- },
11091
- {
11092
- type: 0
11093
- /* Never */
11094
- }
11202
+ value: type.elements.map(
11203
+ (cur) => typeFromTypespec(state, cur)
11095
11204
  )
11096
11205
  };
11097
11206
  }
@@ -11394,6 +11503,21 @@ function castType(type, target) {
11394
11503
  }
11395
11504
  return result;
11396
11505
  }
11506
+ function reducedType(elems) {
11507
+ if (!Array.isArray(elems)) {
11508
+ return elems;
11509
+ }
11510
+ return elems.reduce(
11511
+ (p, t) => {
11512
+ unionInto(p, t);
11513
+ return p;
11514
+ },
11515
+ {
11516
+ type: 0
11517
+ /* Never */
11518
+ }
11519
+ );
11520
+ }
11397
11521
  function mustBeTrue(arg) {
11398
11522
  return (arg.type === 8 || arg.type === 16) && arg.value != null && Number(arg.value) !== 0 || (arg.type & TruthyTypes) !== 0 && (arg.type & ~TruthyTypes) === 0;
11399
11523
  }
@@ -11419,7 +11543,7 @@ function display(type) {
11419
11543
  case 256:
11420
11544
  return JSON.stringify(tv.value);
11421
11545
  case 512:
11422
- return display(tv.value);
11546
+ return Array.isArray(tv.value) ? `[${tv.value.map((t) => display(t)).join(", ")}]` : `Array<${display(tv.value)}>`;
11423
11547
  case 1024:
11424
11548
  return tv.value.value ? `Dictionary<${display(tv.value.key)}, ${display(tv.value.value)}>` : `{ ${Array.from(tv.value).map(
11425
11549
  ([key, value2]) => `${display(typeFromObjectLiteralKey(key))} as ${display(
@@ -11470,7 +11594,7 @@ function display(type) {
11470
11594
  const valueStr = value2 != null && displayOne({ type: bit, value: value2 });
11471
11595
  if (!valueStr) {
11472
11596
  parts.push(name);
11473
- } else if (bit & (32768 | 65536 | 262144 | 131072 | 2048 | 256 | 1024)) {
11597
+ } else if (bit & (32768 | 65536 | 262144 | 131072 | 2048 | 256 | 512 | 1024)) {
11474
11598
  parts.push(valueStr);
11475
11599
  } else {
11476
11600
  parts.push(`${name}<${valueStr}${valueStr.endsWith(">") ? " " : ""}>`);
@@ -11704,9 +11828,30 @@ function couldBeValue(pair, shallow) {
11704
11828
  case 131072:
11705
11829
  return pair.avalue === pair.bvalue;
11706
11830
  case 512:
11707
- return shallow || couldBe(pair.avalue, pair.bvalue);
11831
+ if (shallow)
11832
+ return true;
11833
+ if (Array.isArray(pair.avalue)) {
11834
+ const bv = pair.bvalue;
11835
+ if (Array.isArray(bv)) {
11836
+ if (pair.avalue.length !== bv.length) {
11837
+ return false;
11838
+ }
11839
+ return pair.avalue.every((a, i) => couldBe(a, bv[i]));
11840
+ }
11841
+ return pair.avalue.every((a) => couldBe(a, bv));
11842
+ }
11843
+ if (Array.isArray(pair.bvalue)) {
11844
+ const av = pair.avalue;
11845
+ return pair.bvalue.every((b) => couldBe(av, b));
11846
+ }
11847
+ return couldBe(pair.avalue, pair.bvalue);
11708
11848
  case 1024: {
11709
- return shallow || !pair.avalue.value || !pair.bvalue.value || couldBe(pair.avalue.key, pair.bvalue.key) && couldBe(pair.avalue.value, pair.bvalue.value);
11849
+ if (shallow)
11850
+ return true;
11851
+ if (!pair.avalue.value || !pair.bvalue.value) {
11852
+ return true;
11853
+ }
11854
+ return couldBe(pair.avalue.key, pair.bvalue.key) && couldBe(pair.avalue.value, pair.bvalue.value);
11710
11855
  }
11711
11856
  case 2048: {
11712
11857
  return pair.avalue.args.length === pair.bvalue.args.length && couldBe(pair.avalue.result, pair.bvalue.result) && pair.avalue.args.every((arg, i) => couldBe(arg, pair.bvalue.args[i]));
@@ -12507,7 +12652,11 @@ function updateAffected(blockState, objectType, baseDecl, assignedPath, affected
12507
12652
  /* Array */
12508
12653
  );
12509
12654
  if (atype) {
12510
- unionInto(newType, atype);
12655
+ if (Array.isArray(atype)) {
12656
+ atype.forEach((value2) => unionInto(newType, value2));
12657
+ } else {
12658
+ unionInto(newType, atype);
12659
+ }
12511
12660
  }
12512
12661
  }
12513
12662
  if (type.type & 1024) {
@@ -12632,7 +12781,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
12632
12781
  next = t;
12633
12782
  }
12634
12783
  if (cur.type & 512) {
12635
- const avalue = getUnionComponent(
12784
+ let avalue = getUnionComponent(
12636
12785
  cur,
12637
12786
  512
12638
12787
  /* Array */
@@ -12640,10 +12789,28 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
12640
12789
  type: 524287
12641
12790
  /* Any */
12642
12791
  };
12643
- if (next) {
12644
- unionInto(next = cloneType(next), avalue);
12792
+ if (Array.isArray(avalue)) {
12793
+ const index = arrayLiteralKeyFromExpr(me.property);
12794
+ if (index != null && avalue[index] != null) {
12795
+ if (!next) {
12796
+ assocValue[i].keyStr = index;
12797
+ }
12798
+ avalue = avalue[index];
12799
+ }
12800
+ if (next || i !== l || !newValue) {
12801
+ const n = next ? cloneType(next) : {
12802
+ type: 0
12803
+ /* Never */
12804
+ };
12805
+ (0, import_chunk_SG7ODKRM.forEach)(avalue, (v) => unionInto(n, v));
12806
+ next = n;
12807
+ }
12645
12808
  } else {
12646
- next = avalue;
12809
+ if (next) {
12810
+ unionInto(next = cloneType(next), avalue);
12811
+ } else {
12812
+ next = avalue;
12813
+ }
12647
12814
  }
12648
12815
  }
12649
12816
  let isExact2 = false;
@@ -12669,6 +12836,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
12669
12836
  };
12670
12837
  }
12671
12838
  } else {
12839
+ delete assocValue[i].keyStr;
12672
12840
  if (n) {
12673
12841
  unionInto(next = cloneType(next), n);
12674
12842
  next.type |= 1;
@@ -13899,16 +14067,29 @@ function updateByAssocPath(path7, property, update) {
13899
14067
  }
13900
14068
  } else if (update) {
13901
14069
  if (object.type & 512) {
13902
- object = cloneType(object);
13903
- setUnionComponent(
14070
+ let avalue = getUnionComponent(
13904
14071
  object,
13905
- 512,
13906
- valueToStore(getUnionComponent(
13907
- object,
13908
- 512
13909
- /* Array */
13910
- ))
14072
+ 512
14073
+ /* Array */
13911
14074
  );
14075
+ if (Array.isArray(avalue)) {
14076
+ const key = pathElem.keyStr;
14077
+ const relaxed = relaxType(property);
14078
+ if (typeof key === "number" && key >= 0 && key < avalue.length) {
14079
+ avalue = avalue.slice();
14080
+ avalue[key] = relaxed;
14081
+ } else {
14082
+ avalue = avalue.map((v) => {
14083
+ v = cloneType(v);
14084
+ unionInto(v, relaxed);
14085
+ return v;
14086
+ });
14087
+ }
14088
+ } else {
14089
+ avalue = valueToStore(avalue);
14090
+ }
14091
+ object = cloneType(object);
14092
+ setUnionComponent(object, 512, avalue);
13912
14093
  }
13913
14094
  if (object.type & 1024) {
13914
14095
  const dvalue = getUnionComponent(
@@ -13927,7 +14108,7 @@ function updateByAssocPath(path7, property, update) {
13927
14108
  value: valueToStore(dvalue.value)
13928
14109
  });
13929
14110
  } else {
13930
- if (pathElem.keyStr) {
14111
+ if (typeof pathElem.keyStr === "string") {
13931
14112
  object = cloneType(object);
13932
14113
  const relaxed = cloneType(relaxType(property));
13933
14114
  relaxed.type &= ~1;
@@ -17454,6 +17635,16 @@ function add_one_resource(state, doc, module2, e) {
17454
17635
  loc: e.loc
17455
17636
  }
17456
17637
  ] : [];
17638
+ items.push({
17639
+ type: "ClassElement",
17640
+ item: {
17641
+ type: "FunctionDeclaration",
17642
+ id: (0, import_chunk_MBTLUWXR.makeIdentifier)("initialize", loc),
17643
+ body: null,
17644
+ params: [],
17645
+ loc: e.loc
17646
+ }
17647
+ });
17457
17648
  return {
17458
17649
  type: "ClassDeclaration",
17459
17650
  body: { type: "ClassBody", body: items, loc: e.loc },
@@ -28118,7 +28309,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
28118
28309
  const opt_time = await (0, import_chunk_SG7ODKRM.first_modified)(
28119
28310
  Object.values(fnMap).map((v) => v.output)
28120
28311
  );
28121
- if (source_time < opt_time && 1706315973765 < opt_time) {
28312
+ if (source_time < opt_time && 1707701537178 < opt_time) {
28122
28313
  return {
28123
28314
  hasTests,
28124
28315
  diagnostics: prevDiagnostics,
@@ -28157,7 +28348,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
28157
28348
  hasTests: hasTests2,
28158
28349
  diagnostics,
28159
28350
  sdkVersion,
28160
- optimizerVersion: "1.1.40",
28351
+ optimizerVersion: "1.1.41",
28161
28352
  ...Object.fromEntries(
28162
28353
  configOptionsToCheck.map((option) => [option, config[option]])
28163
28354
  )
@@ -29044,6 +29235,7 @@ var init_sdk_util = (0, import_chunk_ABYVSU2C.__esm)({
29044
29235
  init_union_type,
29045
29236
  init_worker_pool,
29046
29237
  init_worker_task,
29238
+ init_xml_util,
29047
29239
  intersection,
29048
29240
  isClassVariable,
29049
29241
  isCondBranch,
@@ -29066,8 +29258,10 @@ var init_sdk_util = (0, import_chunk_ABYVSU2C.__esm)({
29066
29258
  mustBeTrue,
29067
29259
  opcodeSize,
29068
29260
  optimizeFunc,
29261
+ optimizeMonkeyC,
29069
29262
  optimizeProgram,
29070
29263
  parseSdkVersion,
29264
+ parseXml,
29071
29265
  performTask,
29072
29266
  readPrg,
29073
29267
  readPrgWithOffsets,
@@ -18,28 +18,28 @@ 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_Z2SLP4FQ.StateNodeAttributes,
22
- buildOptimizedProject: () => import_chunk_Z2SLP4FQ.buildOptimizedProject,
21
+ StateNodeAttributes: () => import_chunk_BJHWDTEM.StateNodeAttributes,
22
+ buildOptimizedProject: () => import_chunk_BJHWDTEM.buildOptimizedProject,
23
23
  copyRecursiveAsNeeded: () => import_chunk_SG7ODKRM.copyRecursiveAsNeeded,
24
- defaultConfig: () => import_chunk_Z2SLP4FQ.defaultConfig,
25
- display: () => import_chunk_Z2SLP4FQ.display,
26
- generateOneConfig: () => import_chunk_Z2SLP4FQ.generateOneConfig,
27
- generateOptimizedProject: () => import_chunk_Z2SLP4FQ.generateOptimizedProject,
28
- getConfig: () => import_chunk_Z2SLP4FQ.getConfig,
29
- getProjectAnalysis: () => import_chunk_Z2SLP4FQ.getProjectAnalysis,
30
- get_jungle: () => import_chunk_Z2SLP4FQ.get_jungle,
31
- isErrorWithLocation: () => import_chunk_Z2SLP4FQ.isErrorWithLocation,
32
- launchSimulator: () => import_chunk_Z2SLP4FQ.launchSimulator,
33
- manifestProducts: () => import_chunk_Z2SLP4FQ.manifestProducts,
34
- mctree: () => import_chunk_Z2SLP4FQ.mctree,
35
- simulateProgram: () => import_chunk_Z2SLP4FQ.simulateProgram
24
+ defaultConfig: () => import_chunk_BJHWDTEM.defaultConfig,
25
+ display: () => import_chunk_BJHWDTEM.display,
26
+ generateOneConfig: () => import_chunk_BJHWDTEM.generateOneConfig,
27
+ generateOptimizedProject: () => import_chunk_BJHWDTEM.generateOptimizedProject,
28
+ getConfig: () => import_chunk_BJHWDTEM.getConfig,
29
+ getProjectAnalysis: () => import_chunk_BJHWDTEM.getProjectAnalysis,
30
+ get_jungle: () => import_chunk_BJHWDTEM.get_jungle,
31
+ isErrorWithLocation: () => import_chunk_BJHWDTEM.isErrorWithLocation,
32
+ launchSimulator: () => import_chunk_BJHWDTEM.launchSimulator,
33
+ manifestProducts: () => import_chunk_BJHWDTEM.manifestProducts,
34
+ mctree: () => import_chunk_BJHWDTEM.mctree,
35
+ simulateProgram: () => import_chunk_BJHWDTEM.simulateProgram
36
36
  });
37
37
  module.exports = __toCommonJS(optimizer_exports);
38
- var import_chunk_Z2SLP4FQ = require("./chunk-Z2SLP4FQ.cjs");
38
+ var import_chunk_BJHWDTEM = require("./chunk-BJHWDTEM.cjs");
39
39
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
40
40
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
41
41
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
42
- (0, import_chunk_Z2SLP4FQ.init_optimizer)();
42
+ (0, import_chunk_BJHWDTEM.init_optimizer)();
43
43
  // Annotate the CommonJS export names for ESM import in node:
44
44
  0 && (module.exports = {
45
45
  StateNodeAttributes,
@@ -18,25 +18,25 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var sdk_util_exports = {};
20
20
  __export(sdk_util_exports, {
21
- SectionKinds: () => import_chunk_Z2SLP4FQ.SectionKinds,
22
- appSupport: () => import_chunk_Z2SLP4FQ.appSupport,
23
- connectiq: () => import_chunk_Z2SLP4FQ.connectiq,
24
- getDeviceInfo: () => import_chunk_Z2SLP4FQ.getDeviceInfo,
25
- getFunctionDocumentation: () => import_chunk_Z2SLP4FQ.getFunctionDocumentation,
26
- getLanguages: () => import_chunk_Z2SLP4FQ.getLanguages,
27
- getSdkPath: () => import_chunk_Z2SLP4FQ.getSdkPath,
28
- isWin: () => import_chunk_Z2SLP4FQ.isWin,
29
- optimizeProgram: () => import_chunk_Z2SLP4FQ.optimizeProgram,
30
- readPrg: () => import_chunk_Z2SLP4FQ.readPrg,
31
- readPrgWithOffsets: () => import_chunk_Z2SLP4FQ.readPrgWithOffsets,
32
- xmlUtil: () => import_chunk_Z2SLP4FQ.xml_util_exports
21
+ SectionKinds: () => import_chunk_BJHWDTEM.SectionKinds,
22
+ appSupport: () => import_chunk_BJHWDTEM.appSupport,
23
+ connectiq: () => import_chunk_BJHWDTEM.connectiq,
24
+ getDeviceInfo: () => import_chunk_BJHWDTEM.getDeviceInfo,
25
+ getFunctionDocumentation: () => import_chunk_BJHWDTEM.getFunctionDocumentation,
26
+ getLanguages: () => import_chunk_BJHWDTEM.getLanguages,
27
+ getSdkPath: () => import_chunk_BJHWDTEM.getSdkPath,
28
+ isWin: () => import_chunk_BJHWDTEM.isWin,
29
+ optimizeProgram: () => import_chunk_BJHWDTEM.optimizeProgram,
30
+ readPrg: () => import_chunk_BJHWDTEM.readPrg,
31
+ readPrgWithOffsets: () => import_chunk_BJHWDTEM.readPrgWithOffsets,
32
+ xmlUtil: () => import_chunk_BJHWDTEM.xml_util_exports
33
33
  });
34
34
  module.exports = __toCommonJS(sdk_util_exports);
35
- var import_chunk_Z2SLP4FQ = require("./chunk-Z2SLP4FQ.cjs");
35
+ var import_chunk_BJHWDTEM = require("./chunk-BJHWDTEM.cjs");
36
36
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
37
37
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
38
38
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
39
- (0, import_chunk_Z2SLP4FQ.init_sdk_util)();
39
+ (0, import_chunk_BJHWDTEM.init_sdk_util)();
40
40
  // Annotate the CommonJS export names for ESM import in node:
41
41
  0 && (module.exports = {
42
42
  SectionKinds,
@@ -102,7 +102,7 @@ export interface StringType extends AbstractValue {
102
102
  }
103
103
  export interface ArrayType extends AbstractValue {
104
104
  type: TypeTag.Array;
105
- value?: ExactOrUnion | undefined;
105
+ value?: ExactOrUnion | ExactOrUnion[] | undefined;
106
106
  }
107
107
  export interface DictionaryType extends AbstractValue {
108
108
  type: TypeTag.Dictionary;
@@ -190,6 +190,8 @@ export declare function cloneType<T extends ExactOrUnion>(t: T): T;
190
190
  export declare function relaxType(type: ExactOrUnion): ExactOrUnion;
191
191
  export declare function typeFromTypeStateNode(state: ProgramStateAnalysis, sn: StateNodeDecl, classVsObj?: boolean): ExactOrUnion;
192
192
  export declare function typeFromTypeStateNodes(state: ProgramStateAnalysis, sns: StateNodeDecl[], classVsObj?: boolean): ExactOrUnion;
193
+ export declare function arrayLiteralKeyFromType(k: ExactOrUnion | null | undefined): number | null;
194
+ export declare function arrayLiteralKeyFromExpr(key: mctree.Expression): number | null;
193
195
  export declare function objectLiteralKeyFromExpr(key: mctree.Expression): string | null;
194
196
  export declare function objectLiteralKeyFromType(key: ExactOrUnion): string | null;
195
197
  export declare function typeFromObjectLiteralKey(key: string): ValueTypes;
@@ -198,6 +200,7 @@ export declare function typeFromTypespec(state: ProgramStateAnalysis, ts: mctree
198
200
  export declare function typeFromLiteral(literal: mctree.Literal): ExactTypes;
199
201
  export declare function mcExprFromType(type: ValueTypes): mctree.Expression | null;
200
202
  export declare function castType(type: ExactOrUnion, target: UnionTypeTags): ExactOrUnion;
203
+ export declare function reducedType(elems: ExactOrUnion[] | ExactOrUnion): ExactOrUnion;
201
204
  export declare const TruthyTypes: number;
202
205
  export declare function mustBeTrue(arg: ExactOrUnion): boolean;
203
206
  export declare function mustBeFalse(arg: ExactOrUnion): boolean;
@@ -21,17 +21,17 @@ __export(worker_thread_exports, {
21
21
  default: () => worker_thread_default
22
22
  });
23
23
  module.exports = __toCommonJS(worker_thread_exports);
24
- var import_chunk_Z2SLP4FQ = require("./chunk-Z2SLP4FQ.cjs");
24
+ var import_chunk_BJHWDTEM = require("./chunk-BJHWDTEM.cjs");
25
25
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
26
26
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
27
27
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
28
28
  var import_node_worker_threads = require("node:worker_threads");
29
29
  var require_worker_thread = (0, import_chunk_ABYVSU2C.__commonJS)({
30
30
  "src/worker-thread.ts"() {
31
- (0, import_chunk_Z2SLP4FQ.init_worker_task)();
31
+ (0, import_chunk_BJHWDTEM.init_worker_task)();
32
32
  if (import_node_worker_threads.parentPort) {
33
33
  import_node_worker_threads.parentPort.on("message", async (task) => {
34
- return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_Z2SLP4FQ.performTask)(task));
34
+ return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_BJHWDTEM.performTask)(task));
35
35
  });
36
36
  }
37
37
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "commonjs",
4
- "version": "1.1.40",
4
+ "version": "1.1.41",
5
5
  "description": "Source to source optimizer for Garmin Monkey C code",
6
6
  "main": "build/optimizer.cjs",
7
7
  "types": "build/src/optimizer.d.ts",
@@ -22,7 +22,7 @@
22
22
  "build-debug": "node esbuild.mjs",
23
23
  "build-release": "node esbuild.mjs --release",
24
24
  "prepack": "node esbuild.mjs --release && mkdir -p bin && cp test/cft-font-info.js bin",
25
- "test": "npm run test-mocha && npm run test-optimized && npm run test-unopt && npm run test-post-only && npm run test-remote && npm run test-remote-tests && npm run test-personality",
25
+ "test": "npm run test-mocha && npm run test-analysis && npm run test-optimized && npm run test-unopt && npm run test-post-only && npm run test-remote && npm run test-remote-tests && npm run test-personality",
26
26
  "test-mocha": "npx mocha --timeout 999999 build/mocha.cjs",
27
27
  "test-remote": "node ./test/test.js --showInfo --postOptimize --product=pick-one --github",
28
28
  "test-remote-tests": "node ./test/test.js --showInfo --postOptimize --product=pick-one --run-tests --github",
@@ -31,6 +31,7 @@
31
31
  "test-post-only": "node test/test.js --showInfo --typeCheckLevel Strict --skipOptimization --postOptimize --run-tests --product=fenix5 --product=fr235 --jungle ./test/OptimizerTests/monkey.jungle",
32
32
  "test-garmin-opt": "node test/test.js --typeCheckLevel Strict --skipOptimization --garminOptLevel=2 --run-tests --product=fenix5 --product=fr235 --jungle ./test/OptimizerTests/monkey.jungle",
33
33
  "test-personality": "node test/test-personality.js",
34
+ "test-analysis": "node test/test.js --showInfo --typeCheckLevel Strict --product=fr955 --sourceFile 'test/analysis/*.mc'",
34
35
  "eslint": "npx eslint ."
35
36
  },
36
37
  "bin": {