@markw65/monkeyc-optimizer 1.1.25 → 1.1.27

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.
Files changed (43) hide show
  1. package/README.md +28 -0
  2. package/bin/cft-font-info.js +63 -0
  3. package/build/api.cjs +36 -34
  4. package/build/cftinfo.cjs +112 -0
  5. package/build/chunk-ABYVSU2C.cjs +74 -0
  6. package/build/{chunk-SNWJ2FZL.cjs → chunk-DD4VX53Y.cjs} +1052 -1160
  7. package/build/chunk-MBTLUWXR.cjs +375 -0
  8. package/build/{chunk-QFQPBQSO.cjs → chunk-PVBIKZYZ.cjs} +110 -153
  9. package/build/optimizer.cjs +21 -19
  10. package/build/sdk-util.cjs +17 -15
  11. package/build/src/api.d.ts +1 -1
  12. package/build/src/ast.d.ts +1 -1
  13. package/build/src/cftinfo.d.ts +32 -0
  14. package/build/src/control-flow.d.ts +3 -3
  15. package/build/src/data-flow.d.ts +5 -5
  16. package/build/src/inliner.d.ts +2 -2
  17. package/build/src/jungles.d.ts +16 -12
  18. package/build/src/manifest.d.ts +1 -1
  19. package/build/src/optimizer-types.d.ts +25 -22
  20. package/build/src/optimizer.d.ts +2 -2
  21. package/build/src/projects.d.ts +1 -1
  22. package/build/src/readprg/bytecode.d.ts +5 -5
  23. package/build/src/readprg/cflow.d.ts +3 -2
  24. package/build/src/readprg/emit.d.ts +3 -3
  25. package/build/src/readprg/exceptions.d.ts +2 -2
  26. package/build/src/readprg/header.d.ts +2 -2
  27. package/build/src/readprg/interp.d.ts +1 -1
  28. package/build/src/readprg/linenum.d.ts +1 -1
  29. package/build/src/readprg/opcodes.d.ts +2 -2
  30. package/build/src/resources.d.ts +2 -2
  31. package/build/src/sdk-util.d.ts +1 -1
  32. package/build/src/type-flow/dead-store.d.ts +1 -1
  33. package/build/src/type-flow/interp-call.d.ts +2 -2
  34. package/build/src/type-flow/interp.d.ts +4 -3
  35. package/build/src/type-flow/type-flow-util.d.ts +1 -1
  36. package/build/src/type-flow/types.d.ts +18 -18
  37. package/build/src/type-flow.d.ts +1 -1
  38. package/build/src/util.d.ts +1 -1
  39. package/build/src/worker-task.d.ts +3 -3
  40. package/build/src/xml-util.d.ts +9 -9
  41. package/build/util.cjs +25 -24
  42. package/build/worker-thread.cjs +7 -7
  43. package/package.json +14 -9
package/README.md CHANGED
@@ -848,3 +848,31 @@ No functional change, just fixes a typo that broke the typescript exports.
848
848
 
849
849
  - Bug fixes
850
850
  - fixes a copy paste error that could cause strange results in the interpreter, possibly leading to incorrect optimizations.
851
+
852
+ ### 1.1.26
853
+
854
+ - Bug fixes
855
+
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 some references not being reported to the extension (only affects `Goto References` and `Goto Definition`)
858
+ - fixes some issues converting the system function documentation to markdown (for the Hover, Completion and Signature providers in the extension).
859
+
860
+ - New features
861
+
862
+ - Update to [@markw65/prettier-plugin-monkeyc@1.0.49](https://github.com/markw65/prettier-plugin-monkeyc#1049) (including [#1.0.48](https://github.com/markw65/prettier-plugin-monkeyc#1048) and [#1.0.47](https://github.com/markw65/prettier-plugin-monkeyc#1047))
863
+ - adds support for parsing (but not formatting) .mss files
864
+ - Adds full support for personalities in `.jungle` and `.mss` files, including reading the per-device `personality.mss` files
865
+ - Adds support for `project.typecheck` in `.jungle` files
866
+ - Adds support for `project.optimization` in `.jungle` files
867
+
868
+ - Tests
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.
@@ -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_SNWJ2FZL.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_SNWJ2FZL.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_SNWJ2FZL.createDocumentationMap,
24
- diagnostic: () => import_chunk_SNWJ2FZL.diagnostic,
25
- diagnosticHelper: () => import_chunk_SNWJ2FZL.diagnosticHelper,
26
- findNamesInScope: () => import_chunk_SNWJ2FZL.findNamesInScope,
27
- findUsingForNode: () => import_chunk_SNWJ2FZL.findUsingForNode,
28
- formatAst: () => import_chunk_SNWJ2FZL.formatAst,
29
- formatAstLongLines: () => import_chunk_SNWJ2FZL.formatAstLongLines,
30
- getApiFunctionInfo: () => import_chunk_SNWJ2FZL.getApiFunctionInfo,
31
- getApiMapping: () => import_chunk_SNWJ2FZL.getApiMapping,
32
- getSuperClasses: () => import_chunk_SNWJ2FZL.getSuperClasses,
33
- hasProperty: () => import_chunk_SNWJ2FZL.hasProperty,
34
- isClassVariable: () => import_chunk_SNWJ2FZL.isClassVariable,
35
- isLocal: () => import_chunk_SNWJ2FZL.isLocal,
36
- isLookupCandidate: () => import_chunk_SNWJ2FZL.isLookupCandidate,
37
- isStateNode: () => import_chunk_SNWJ2FZL.isStateNode,
38
- lookupByFullName: () => import_chunk_SNWJ2FZL.lookupByFullName,
39
- lookupNext: () => import_chunk_SNWJ2FZL.lookupNext,
40
- lookupResultContains: () => import_chunk_SNWJ2FZL.lookupResultContains,
41
- lookupWithType: () => import_chunk_SNWJ2FZL.lookupWithType,
42
- makeToyboxLink: () => import_chunk_SNWJ2FZL.makeToyboxLink,
43
- mapVarDeclsByType: () => import_chunk_SNWJ2FZL.mapVarDeclsByType,
44
- markInvokeClassMethod: () => import_chunk_SNWJ2FZL.markInvokeClassMethod,
45
- parseSdkVersion: () => import_chunk_SNWJ2FZL.parseSdkVersion,
46
- sameLookupResult: () => import_chunk_SNWJ2FZL.sameLookupResult,
47
- traverseAst: () => import_chunk_SNWJ2FZL.traverseAst,
48
- variableDeclarationName: () => import_chunk_SNWJ2FZL.variableDeclarationName,
49
- visitReferences: () => import_chunk_SNWJ2FZL.visitReferences,
50
- visit_resources: () => import_chunk_SNWJ2FZL.visit_resources,
51
- visitorNode: () => import_chunk_SNWJ2FZL.visitorNode
21
+ checkCompilerVersion: () => import_chunk_DD4VX53Y.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_DD4VX53Y.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_DD4VX53Y.createDocumentationMap,
24
+ diagnostic: () => import_chunk_DD4VX53Y.diagnostic,
25
+ diagnosticHelper: () => import_chunk_DD4VX53Y.diagnosticHelper,
26
+ findNamesInScope: () => import_chunk_DD4VX53Y.findNamesInScope,
27
+ findUsingForNode: () => import_chunk_DD4VX53Y.findUsingForNode,
28
+ formatAst: () => import_chunk_DD4VX53Y.formatAst,
29
+ formatAstLongLines: () => import_chunk_DD4VX53Y.formatAstLongLines,
30
+ getApiFunctionInfo: () => import_chunk_DD4VX53Y.getApiFunctionInfo,
31
+ getApiMapping: () => import_chunk_DD4VX53Y.getApiMapping,
32
+ getSuperClasses: () => import_chunk_DD4VX53Y.getSuperClasses,
33
+ hasProperty: () => import_chunk_MBTLUWXR.hasProperty,
34
+ isClassVariable: () => import_chunk_DD4VX53Y.isClassVariable,
35
+ isLocal: () => import_chunk_DD4VX53Y.isLocal,
36
+ isLookupCandidate: () => import_chunk_DD4VX53Y.isLookupCandidate,
37
+ isStateNode: () => import_chunk_DD4VX53Y.isStateNode,
38
+ lookupByFullName: () => import_chunk_DD4VX53Y.lookupByFullName,
39
+ lookupNext: () => import_chunk_DD4VX53Y.lookupNext,
40
+ lookupResultContains: () => import_chunk_DD4VX53Y.lookupResultContains,
41
+ lookupWithType: () => import_chunk_DD4VX53Y.lookupWithType,
42
+ makeToyboxLink: () => import_chunk_DD4VX53Y.makeToyboxLink,
43
+ mapVarDeclsByType: () => import_chunk_DD4VX53Y.mapVarDeclsByType,
44
+ markInvokeClassMethod: () => import_chunk_DD4VX53Y.markInvokeClassMethod,
45
+ parseSdkVersion: () => import_chunk_DD4VX53Y.parseSdkVersion,
46
+ sameLookupResult: () => import_chunk_DD4VX53Y.sameLookupResult,
47
+ traverseAst: () => import_chunk_MBTLUWXR.traverseAst,
48
+ variableDeclarationName: () => import_chunk_DD4VX53Y.variableDeclarationName,
49
+ visitReferences: () => import_chunk_DD4VX53Y.visitReferences,
50
+ visit_resources: () => import_chunk_DD4VX53Y.visit_resources,
51
+ visitorNode: () => import_chunk_DD4VX53Y.visitorNode
52
52
  });
53
53
  module.exports = __toCommonJS(api_exports);
54
- var import_chunk_SNWJ2FZL = require("./chunk-SNWJ2FZL.cjs");
55
- var import_chunk_QFQPBQSO = require("./chunk-QFQPBQSO.cjs");
56
- (0, import_chunk_SNWJ2FZL.init_api)();
54
+ var import_chunk_DD4VX53Y = require("./chunk-DD4VX53Y.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_DD4VX53Y.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
+ });