@markw65/monkeyc-optimizer 1.1.26 → 1.1.28

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
@@ -854,7 +854,7 @@ No functional change, just fixes a typo that broke the typescript exports.
854
854
  - Bug fixes
855
855
 
856
856
  - fixes an issue in the post build optimizer which could cause pre variables to be inserted too late in a block that could throw (so that if the variable was used in, or after the catch block, it might not have been set).
857
- - fixes an issue with references in resource files, that could result in result in some references not being reported to the extension (only affects `Goto References` and `Goto Definition`)
857
+ - fixes an issue with references in resource files, that could result in some references not being reported to the extension (only affects `Goto References` and `Goto Definition`)
858
858
  - fixes some issues converting the system function documentation to markdown (for the Hover, Completion and Signature providers in the extension).
859
859
 
860
860
  - New features
@@ -867,3 +867,23 @@ No functional change, just fixes a typo that broke the typescript exports.
867
867
 
868
868
  - Tests
869
869
  - Adds a new project to test `.mss` files, and references to personalities from `.mc` files
870
+
871
+ ### 1.1.27
872
+
873
+ - Bug fixes
874
+
875
+ - Fixes an incorrect type check warning when an assignment to a local was incompatible with the type of a same-named non-local variable. This only affects the warning; it did not result in incorrect optimizations.
876
+
877
+ - New features
878
+ - Adds a [standalone script](https://github.com/markw65/monkeyc-optimizer/wiki/Garmin-Font-Analyzer) to analyze .cft (font) files.
879
+
880
+ ### 1.1.28
881
+
882
+ - Bug fixes
883
+
884
+ - Fixes an issue in the post build optimizer which could cause a pre-definition to be inserted just prior to an `frpush`, which could result in the wrong value of `self` being passed to a call
885
+ - Don't add personality paths to the generated jungle file if the sdk is prior to 4.2.1
886
+ - Fixes a bug in the source-to-source optimizer that could incorrectly infer that an `if` block was never entered when the if's comparison was between a primitive type, and a plain `Object`
887
+
888
+ - Improved optimizations
889
+ - Constant folding between `Char` and types other than `Number` is now handled (previously such comparisons were just left for Garmin's compiler to handle). This works around a [bug in Garmin's optimizer](https://forums.garmin.com/developer/connect-iq/i/bug-reports/the-optimizer-constant-folds-char-comparisons-incorrectly) by (correctly) resolving the comparisons before Garmin's optimizer can do the wrong thing.
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+
3
+ const cft = require("../build/cftinfo.cjs");
4
+ const sdkUtil = require("../build/sdk-util.cjs");
5
+ const { globa } = require("../build/util.cjs");
6
+ const path = require("node:path");
7
+
8
+ const fonts = new Set();
9
+ Promise.all(
10
+ process.argv.slice(2).map((filename) => {
11
+ if (/\.cft$/i.test(filename)) {
12
+ return globa(path.resolve(sdkUtil.connectiq, "Fonts", filename)).then(
13
+ (filenames) => {
14
+ filenames.forEach((fn) => fonts.add(fn));
15
+ return null;
16
+ }
17
+ );
18
+ }
19
+ return globa(path.resolve(sdkUtil.connectiq, "Devices", filename), {
20
+ mark: true,
21
+ }).then((devices) =>
22
+ Promise.all(
23
+ devices.map((device) => {
24
+ if (!device.endsWith("/")) return null;
25
+ return cft.getDeviceFontInfo(device).then((devInfo) => {
26
+ Object.values(devInfo.fontSets).forEach((fontSet) =>
27
+ Object.values(fontSet).forEach((file) =>
28
+ fonts.add(
29
+ path.resolve(sdkUtil.connectiq, "Fonts", `${file}.cft`)
30
+ )
31
+ )
32
+ );
33
+ return devInfo;
34
+ });
35
+ })
36
+ )
37
+ );
38
+ })
39
+ )
40
+ .then((results) =>
41
+ Promise.all(
42
+ Array.from(fonts).map((font) =>
43
+ cft.getCFTFontInfo(font).catch(() => null)
44
+ )
45
+ )
46
+ .then((fonts) =>
47
+ Object.fromEntries(
48
+ fonts
49
+ .filter((font) => font != null)
50
+ .map(({ name, ...rest }) => [name, rest])
51
+ )
52
+ )
53
+ .then((fonts) => ({
54
+ fonts,
55
+ devices: Object.fromEntries(
56
+ results
57
+ .flat()
58
+ .filter((result) => result != null)
59
+ .map(({ device, ...rest }) => [device, rest])
60
+ ),
61
+ }))
62
+ )
63
+ .then((results) => console.log(JSON.stringify(results)));
package/build/api.cjs CHANGED
@@ -18,42 +18,44 @@ 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_XO53WBWQ.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_XO53WBWQ.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_XO53WBWQ.createDocumentationMap,
24
- diagnostic: () => import_chunk_XO53WBWQ.diagnostic,
25
- diagnosticHelper: () => import_chunk_XO53WBWQ.diagnosticHelper,
26
- findNamesInScope: () => import_chunk_XO53WBWQ.findNamesInScope,
27
- findUsingForNode: () => import_chunk_XO53WBWQ.findUsingForNode,
28
- formatAst: () => import_chunk_XO53WBWQ.formatAst,
29
- formatAstLongLines: () => import_chunk_XO53WBWQ.formatAstLongLines,
30
- getApiFunctionInfo: () => import_chunk_XO53WBWQ.getApiFunctionInfo,
31
- getApiMapping: () => import_chunk_XO53WBWQ.getApiMapping,
32
- getSuperClasses: () => import_chunk_XO53WBWQ.getSuperClasses,
33
- hasProperty: () => import_chunk_XO53WBWQ.hasProperty,
34
- isClassVariable: () => import_chunk_XO53WBWQ.isClassVariable,
35
- isLocal: () => import_chunk_XO53WBWQ.isLocal,
36
- isLookupCandidate: () => import_chunk_XO53WBWQ.isLookupCandidate,
37
- isStateNode: () => import_chunk_XO53WBWQ.isStateNode,
38
- lookupByFullName: () => import_chunk_XO53WBWQ.lookupByFullName,
39
- lookupNext: () => import_chunk_XO53WBWQ.lookupNext,
40
- lookupResultContains: () => import_chunk_XO53WBWQ.lookupResultContains,
41
- lookupWithType: () => import_chunk_XO53WBWQ.lookupWithType,
42
- makeToyboxLink: () => import_chunk_XO53WBWQ.makeToyboxLink,
43
- mapVarDeclsByType: () => import_chunk_XO53WBWQ.mapVarDeclsByType,
44
- markInvokeClassMethod: () => import_chunk_XO53WBWQ.markInvokeClassMethod,
45
- parseSdkVersion: () => import_chunk_XO53WBWQ.parseSdkVersion,
46
- sameLookupResult: () => import_chunk_XO53WBWQ.sameLookupResult,
47
- traverseAst: () => import_chunk_XO53WBWQ.traverseAst,
48
- variableDeclarationName: () => import_chunk_XO53WBWQ.variableDeclarationName,
49
- visitReferences: () => import_chunk_XO53WBWQ.visitReferences,
50
- visit_resources: () => import_chunk_XO53WBWQ.visit_resources,
51
- visitorNode: () => import_chunk_XO53WBWQ.visitorNode
21
+ checkCompilerVersion: () => import_chunk_ZI7CGRJC.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_ZI7CGRJC.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_ZI7CGRJC.createDocumentationMap,
24
+ diagnostic: () => import_chunk_ZI7CGRJC.diagnostic,
25
+ diagnosticHelper: () => import_chunk_ZI7CGRJC.diagnosticHelper,
26
+ findNamesInScope: () => import_chunk_ZI7CGRJC.findNamesInScope,
27
+ findUsingForNode: () => import_chunk_ZI7CGRJC.findUsingForNode,
28
+ formatAst: () => import_chunk_ZI7CGRJC.formatAst,
29
+ formatAstLongLines: () => import_chunk_ZI7CGRJC.formatAstLongLines,
30
+ getApiFunctionInfo: () => import_chunk_ZI7CGRJC.getApiFunctionInfo,
31
+ getApiMapping: () => import_chunk_ZI7CGRJC.getApiMapping,
32
+ getSuperClasses: () => import_chunk_ZI7CGRJC.getSuperClasses,
33
+ hasProperty: () => import_chunk_MBTLUWXR.hasProperty,
34
+ isClassVariable: () => import_chunk_ZI7CGRJC.isClassVariable,
35
+ isLocal: () => import_chunk_ZI7CGRJC.isLocal,
36
+ isLookupCandidate: () => import_chunk_ZI7CGRJC.isLookupCandidate,
37
+ isStateNode: () => import_chunk_ZI7CGRJC.isStateNode,
38
+ lookupByFullName: () => import_chunk_ZI7CGRJC.lookupByFullName,
39
+ lookupNext: () => import_chunk_ZI7CGRJC.lookupNext,
40
+ lookupResultContains: () => import_chunk_ZI7CGRJC.lookupResultContains,
41
+ lookupWithType: () => import_chunk_ZI7CGRJC.lookupWithType,
42
+ makeToyboxLink: () => import_chunk_ZI7CGRJC.makeToyboxLink,
43
+ mapVarDeclsByType: () => import_chunk_ZI7CGRJC.mapVarDeclsByType,
44
+ markInvokeClassMethod: () => import_chunk_ZI7CGRJC.markInvokeClassMethod,
45
+ parseSdkVersion: () => import_chunk_ZI7CGRJC.parseSdkVersion,
46
+ sameLookupResult: () => import_chunk_ZI7CGRJC.sameLookupResult,
47
+ traverseAst: () => import_chunk_MBTLUWXR.traverseAst,
48
+ variableDeclarationName: () => import_chunk_ZI7CGRJC.variableDeclarationName,
49
+ visitReferences: () => import_chunk_ZI7CGRJC.visitReferences,
50
+ visit_resources: () => import_chunk_ZI7CGRJC.visit_resources,
51
+ visitorNode: () => import_chunk_ZI7CGRJC.visitorNode
52
52
  });
53
53
  module.exports = __toCommonJS(api_exports);
54
- var import_chunk_XO53WBWQ = require("./chunk-XO53WBWQ.cjs");
55
- var import_chunk_YZ44IUV6 = require("./chunk-YZ44IUV6.cjs");
56
- (0, import_chunk_XO53WBWQ.init_api)();
54
+ var import_chunk_ZI7CGRJC = require("./chunk-ZI7CGRJC.cjs");
55
+ var import_chunk_PVBIKZYZ = require("./chunk-PVBIKZYZ.cjs");
56
+ var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
57
+ var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
58
+ (0, import_chunk_ZI7CGRJC.init_api)();
57
59
  // Annotate the CommonJS export names for ESM import in node:
58
60
  0 && (module.exports = {
59
61
  checkCompilerVersion,
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var cftinfo_exports = {};
30
+ __export(cftinfo_exports, {
31
+ getCFTFontInfo: () => getCFTFontInfo,
32
+ getCFTFontInfoFromBuffer: () => getCFTFontInfoFromBuffer,
33
+ getDeviceFontInfo: () => getDeviceFontInfo
34
+ });
35
+ module.exports = __toCommonJS(cftinfo_exports);
36
+ var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
37
+ var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
38
+ var import_node_assert = __toESM(require("node:assert"));
39
+ var fs = __toESM(require("node:fs/promises"));
40
+ var path = __toESM(require("node:path"));
41
+ (0, import_chunk_MBTLUWXR.init_ast)();
42
+ function getCFTFontInfoFromBuffer(name, data) {
43
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
44
+ const cmapOffset = view.getUint32(8);
45
+ const glyphInfoOffset = view.getUint32(12);
46
+ const height = view.getUint16(22);
47
+ const ascent = view.getUint16(24);
48
+ const internalLeading = view.getUint16(26);
49
+ const cmapNGroups = view.getUint32(cmapOffset + 12);
50
+ const charInfo = [];
51
+ for (let i = 0, offset = cmapOffset + 16; i < cmapNGroups; i++) {
52
+ const startChar = view.getUint32(offset + 0);
53
+ const endChar = view.getUint32(offset + 4);
54
+ const startGlyph = view.getUint32(offset + 8);
55
+ offset += 12;
56
+ for (let code = startChar, g = startGlyph; code <= endChar; code++, g++) {
57
+ const width = view.getUint8(glyphInfoOffset + g * 4 + 3);
58
+ charInfo.push({ code, char: String.fromCharCode(code), width });
59
+ }
60
+ }
61
+ return {
62
+ name,
63
+ height,
64
+ ascent,
65
+ internalLeading,
66
+ charInfo
67
+ };
68
+ }
69
+ function getCFTFontInfo(filename) {
70
+ return fs.readFile(filename).then((data) => {
71
+ const name = path.basename(filename, ".cft");
72
+ return getCFTFontInfoFromBuffer(name, data);
73
+ });
74
+ }
75
+ function getDeviceFontInfo(dirname) {
76
+ return Promise.all([
77
+ fs.readFile(path.resolve(dirname, "compiler.json"), "utf-8"),
78
+ fs.readFile(path.resolve(dirname, "simulator.json"), "utf-8")
79
+ ]).then(([compiler, simulator]) => {
80
+ const fonts = JSON.parse(simulator).fonts;
81
+ const fontSets = Object.fromEntries(
82
+ fonts.map(({ fontSet, fonts: fonts2 }) => [
83
+ fontSet,
84
+ Object.fromEntries(
85
+ fonts2.map(({ filename, name }) => [
86
+ "FONT_" + name.replace(/([a-z])([A-Z])/g, "$1_$2").toUpperCase(),
87
+ filename
88
+ ])
89
+ )
90
+ ])
91
+ );
92
+ const partNumbers = JSON.parse(compiler).partNumbers;
93
+ const langMap = {};
94
+ partNumbers.map(
95
+ (part) => part.languages.map((lang) => {
96
+ (0, import_node_assert.default)((0, import_chunk_MBTLUWXR.hasProperty)(fontSets, lang.fontSet));
97
+ if ((0, import_chunk_MBTLUWXR.hasProperty)(langMap, lang.code)) {
98
+ (0, import_node_assert.default)(langMap[lang.code] === lang.fontSet);
99
+ } else {
100
+ langMap[lang.code] = lang.fontSet;
101
+ }
102
+ })
103
+ );
104
+ return { device: path.basename(dirname), fontSets, langMap };
105
+ });
106
+ }
107
+ // Annotate the CommonJS export names for ESM import in node:
108
+ 0 && (module.exports = {
109
+ getCFTFontInfo,
110
+ getCFTFontInfoFromBuffer,
111
+ getDeviceFontInfo
112
+ });
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var chunk_ABYVSU2C_exports = {};
20
+ __export(chunk_ABYVSU2C_exports, {
21
+ __commonJS: () => __commonJS,
22
+ __esm: () => __esm,
23
+ __export: () => __export2,
24
+ __require: () => __require,
25
+ __toESM: () => __toESM
26
+ });
27
+ module.exports = __toCommonJS(chunk_ABYVSU2C_exports);
28
+ var __create = Object.create;
29
+ var __defProp2 = Object.defineProperty;
30
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
31
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
32
+ var __getProtoOf = Object.getPrototypeOf;
33
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
34
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
35
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
36
+ }) : x)(function(x) {
37
+ if (typeof require !== "undefined")
38
+ return require.apply(this, arguments);
39
+ throw new Error('Dynamic require of "' + x + '" is not supported');
40
+ });
41
+ var __esm = (fn, res) => function __init() {
42
+ return fn && (res = (0, fn[__getOwnPropNames2(fn)[0]])(fn = 0)), res;
43
+ };
44
+ var __commonJS = (cb, mod) => function __require2() {
45
+ return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
46
+ };
47
+ var __export2 = (target, all) => {
48
+ for (var name in all)
49
+ __defProp2(target, name, { get: all[name], enumerable: true });
50
+ };
51
+ var __copyProps2 = (to, from, except, desc) => {
52
+ if (from && typeof from === "object" || typeof from === "function") {
53
+ for (let key of __getOwnPropNames2(from))
54
+ if (!__hasOwnProp2.call(to, key) && key !== except)
55
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
56
+ }
57
+ return to;
58
+ };
59
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps2(
60
+ // If the importer is in node compatibility mode or this is not an ESM
61
+ // file that has been converted to a CommonJS file using a Babel-
62
+ // compatible transform (i.e. "__esModule" has not been set), then set
63
+ // "default" to the CommonJS "module.exports" for node compatibility.
64
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
65
+ mod
66
+ ));
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ __commonJS,
70
+ __esm,
71
+ __export,
72
+ __require,
73
+ __toESM
74
+ });