@markw65/monkeyc-optimizer 1.1.13 → 1.1.14

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/README.md CHANGED
@@ -715,3 +715,14 @@ Bug Fixes
715
715
  ### 1.1.13
716
716
 
717
717
  - Adds a new [Minimize Modules](https://github.com/markw65/monkeyc-optimizer/wiki/Optimizing-module-imports#minimize-modules) pass, which attempts to ensure that every module referenced by the program is imported.
718
+
719
+ ### 1.1.14
720
+
721
+ - Fixes a bug that could crash the optimizer if it tried to inline a function in a non-local variable's initializer.
722
+ - Adds a post build optimizer. This step takes the built .prg file, and optimizes the bytecode. Currently the optimizations are:
723
+ - Remove unreachable code
724
+ - simplify control flow by removing branches to branches
725
+ - Remove empty "finally" handlers (every try/catch gets an empty finally handler)
726
+ - Remove stores to dead locals
727
+ - Remove side-effect free code that produces an unused result
728
+ - Optimize shift left by constant to multiply, since the bytecode is smaller (this seems to be a bug in the garmin tools; they consider shift left and shift right to have an 8-bit argument, but its always zero, and the simulator and devices treat it as a one byte shift instruction, followed by a one byte nop).
package/build/api.cjs CHANGED
@@ -2161,8 +2161,9 @@ function inlineRequested(state, func) {
2161
2161
  return false;
2162
2162
  }
2163
2163
  function shouldInline(state, func, call, context) {
2164
- if (state.inlining)
2164
+ if (state.inlining || (state.localsStack?.length ?? 0) <= 1) {
2165
2165
  return false;
2166
+ }
2166
2167
  let autoInline = false;
2167
2168
  let inlineAsExpression = false;
2168
2169
  const args = call.arguments;
@@ -1,4 +1,4 @@
1
- 0 && (module.exports = {buildOptimizedProject,copyRecursiveAsNeeded,defaultConfig,display,generateApiMirTests,generateOptimizedProject,getProjectAnalysis,get_jungle,isErrorWithLocation,launchSimulator,manifestProducts,mctree,simulateProgram});
1
+ 0 && (module.exports = {buildOptimizedProject,copyRecursiveAsNeeded,defaultConfig,display,generateApiMirTests,generateOptimizedProject,getConfig,getProjectAnalysis,get_jungle,isErrorWithLocation,launchSimulator,manifestProducts,mctree,simulateProgram});
2
2
  /******/ (() => { // webpackBootstrap
3
3
  /******/ var __webpack_modules__ = ({
4
4
 
@@ -3416,6 +3416,7 @@ __webpack_require__.d(__webpack_exports__, {
3416
3416
  "display": () => (/* reexport */ display),
3417
3417
  "generateApiMirTests": () => (/* binding */ generateApiMirTests),
3418
3418
  "generateOptimizedProject": () => (/* binding */ generateOptimizedProject),
3419
+ "getConfig": () => (/* binding */ getConfig),
3419
3420
  "getProjectAnalysis": () => (/* binding */ getProjectAnalysis),
3420
3421
  "get_jungle": () => (/* reexport */ get_jungle),
3421
3422
  "isErrorWithLocation": () => (/* binding */ isErrorWithLocation),
@@ -4523,7 +4524,13 @@ async function launchSimulator(force = true) {
4523
4524
  if (!force && (await checkIfSimulatorRunning()))
4524
4525
  return;
4525
4526
  const sdk = await (0,external_sdk_util_cjs_namespaceObject.getSdkPath)();
4526
- const child = (0,external_child_process_namespaceObject.execFile)(external_path_.resolve(sdk, "bin", external_sdk_util_cjs_namespaceObject.isWin ? "simulator" : "connectiq"));
4527
+ const child = force || process.platform !== "darwin"
4528
+ ? (0,external_child_process_namespaceObject.execFile)(external_path_.resolve(sdk, "bin", external_sdk_util_cjs_namespaceObject.isWin ? "simulator" : "connectiq"))
4529
+ : (0,external_child_process_namespaceObject.execFile)("/usr/bin/open", [
4530
+ "-g",
4531
+ "-a",
4532
+ external_path_.resolve(sdk, "bin", "ConnectIQ.App", "Contents/MacOS/simulator"),
4533
+ ]);
4527
4534
  child.unref();
4528
4535
  for (let i = 0;; i++) {
4529
4536
  if (await checkIfSimulatorRunning())
@@ -5380,8 +5387,9 @@ function inlineRequested(state, func) {
5380
5387
  return false;
5381
5388
  }
5382
5389
  function shouldInline(state, func, call, context) {
5383
- if (state.inlining)
5390
+ if (state.inlining || (state.localsStack?.length ?? 0) <= 1) {
5384
5391
  return false;
5392
+ }
5385
5393
  let autoInline = false;
5386
5394
  let inlineAsExpression = false;
5387
5395
  const args = call.arguments;
@@ -16803,7 +16811,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
16803
16811
  // the oldest optimized file, we don't need to regenerate
16804
16812
  const source_time = await (0,external_util_cjs_namespaceObject.last_modified)(Object.keys(fnMap).concat(dependencyFiles));
16805
16813
  const opt_time = await (0,external_util_cjs_namespaceObject.first_modified)(Object.values(fnMap).map((v) => v.output));
16806
- if (source_time < opt_time && 1676335488374 < opt_time) {
16814
+ if (source_time < opt_time && 1676942537698 < opt_time) {
16807
16815
  return { hasTests, diagnostics: prevDiagnostics };
16808
16816
  }
16809
16817
  }
@@ -16830,7 +16838,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
16830
16838
  return promises_namespaceObject.writeFile(external_path_.join(output, "build-info.json"), JSON.stringify({
16831
16839
  hasTests,
16832
16840
  diagnostics,
16833
- optimizerVersion: "1.1.13",
16841
+ optimizerVersion: "1.1.14",
16834
16842
  ...Object.fromEntries(configOptionsToCheck.map((option) => [option, config[option]])),
16835
16843
  }))
16836
16844
  .then(() => ({ hasTests, diagnostics }));