@markw65/monkeyc-optimizer 1.0.11 → 1.0.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 +36 -0
- package/build/api.cjs +362 -142
- package/build/optimizer.cjs +439 -343
- package/build/sdk-util.cjs +21 -5
- package/build/src/api.d.ts +5 -4
- package/build/src/build.d.ts +2 -2
- package/build/src/jungles.d.ts +1 -1
- package/build/src/manifest.d.ts +3 -3
- package/build/src/mc-rewrite.d.ts +3 -3
- package/build/src/optimizer.d.ts +25 -16
- package/build/src/sdk-util.d.ts +5 -2
- package/build/src/util.d.ts +2 -3
- package/build/util.cjs +13 -18
- package/package.json +10 -4
package/build/sdk-util.cjs
CHANGED
|
@@ -7195,18 +7195,34 @@ const external_util_cjs_namespaceObject = require("./util.cjs");
|
|
|
7195
7195
|
const isWin = process.platform == "win32";
|
|
7196
7196
|
const appSupport = isWin
|
|
7197
7197
|
? `${process.env.APPDATA}`.replace(/\\/g, "/")
|
|
7198
|
-
:
|
|
7199
|
-
|
|
7198
|
+
: process.platform == "linux"
|
|
7199
|
+
? `${process.env.HOME}/.config`
|
|
7200
|
+
: `${process.env.HOME}/Library/Application Support`;
|
|
7201
|
+
const connectiq = process.platform == "linux"
|
|
7202
|
+
? `${process.env.HOME}/.Garmin/ConnectIQ`
|
|
7203
|
+
: `${appSupport}/Garmin/ConnectIQ`;
|
|
7200
7204
|
function getSdkPath() {
|
|
7201
7205
|
return promises_namespaceObject.readFile(connectiq + "/current-sdk.cfg")
|
|
7202
|
-
.then((contents) => contents.toString().replace(/^\s*(.*?)\s*$/s, "$1"))
|
|
7206
|
+
.then((contents) => contents.toString().replace(/^\s*(.*?)\s*$/s, "$1"))
|
|
7207
|
+
.catch(() => {
|
|
7208
|
+
throw new Error(`No sdk found at '${connectiq}'. Check your sdk is correctly installed`);
|
|
7209
|
+
});
|
|
7203
7210
|
}
|
|
7204
7211
|
async function getDeviceInfo() {
|
|
7205
7212
|
const files = await (0,external_util_cjs_namespaceObject.globa)(`${connectiq}/Devices/*/compiler.json`);
|
|
7213
|
+
if (!files.length) {
|
|
7214
|
+
throw new Error(`No devices found at '${connectiq}/Devices'. Check your sdk is correctly installed`);
|
|
7215
|
+
}
|
|
7206
7216
|
return Promise.all(files.map((file) => {
|
|
7207
7217
|
return promises_namespaceObject.readFile(file).then((data) => {
|
|
7208
|
-
const { deviceId, appTypes, deviceFamily } = JSON.parse(data.toString());
|
|
7209
|
-
|
|
7218
|
+
const { deviceId, appTypes, deviceFamily, displayName, partNumbers } = JSON.parse(data.toString());
|
|
7219
|
+
const languages = Object.fromEntries(partNumbers
|
|
7220
|
+
.map((part) => part.languages.map((lang) => [lang.code, true]))
|
|
7221
|
+
.flat(1));
|
|
7222
|
+
return [
|
|
7223
|
+
deviceId,
|
|
7224
|
+
{ appTypes, deviceFamily, displayName, languages },
|
|
7225
|
+
];
|
|
7210
7226
|
});
|
|
7211
7227
|
})).then((info) => {
|
|
7212
7228
|
return Object.fromEntries(info);
|
package/build/src/api.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
export declare function getApiMapping(state?: ProgramState): Promise<ProgramStateNode | null>;
|
|
3
|
-
export declare function hasProperty(obj:
|
|
3
|
+
export declare function hasProperty<T extends null extends T ? unknown : undefined extends T ? unknown : never>(obj: T, prop: string): obj is NonNullable<T>;
|
|
4
|
+
export declare function hasProperty<T>(obj: T, prop: string): boolean;
|
|
4
5
|
export declare function isStateNode(node: StateNodeDecl): node is StateNode;
|
|
5
6
|
export declare function variableDeclarationName(node: mctree.TypedIdentifier): string;
|
|
6
|
-
export declare function collectNamespaces(ast: mctree.Program,
|
|
7
|
-
export declare function traverseAst(node: mctree.Node, pre?: (node: mctree.Node) => void | null | false | (keyof mctree.NodeAll)[], post?: (node: mctree.Node) => void | null | false | mctree.Node): false | void | null | mctree.Node;
|
|
8
|
-
export declare function formatAst(node: mctree.Node, monkeyCSource?: string): string;
|
|
7
|
+
export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
|
|
8
|
+
export declare function traverseAst(node: mctree.Node, pre?: null | ((node: mctree.Node) => void | null | false | (keyof mctree.NodeAll)[]), post?: (node: mctree.Node) => void | null | false | mctree.Node): false | void | null | mctree.Node;
|
|
9
|
+
export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null): string;
|
package/build/src/build.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare function build_project(product: string, options: BuildConfig, lineCallback?: (line: string) => void): Promise<{
|
|
1
|
+
export declare function build_project(product: string | null, options: BuildConfig, lineCallback?: (line: string) => void): Promise<{
|
|
2
2
|
exe: string;
|
|
3
3
|
args: string[];
|
|
4
4
|
program: string;
|
|
5
|
-
product: string;
|
|
5
|
+
product: string | null;
|
|
6
6
|
}>;
|
package/build/src/jungles.d.ts
CHANGED
package/build/src/manifest.d.ts
CHANGED
|
@@ -56,8 +56,8 @@ export declare type ManifestXML = {
|
|
|
56
56
|
$: {
|
|
57
57
|
"xmlns:iq": string;
|
|
58
58
|
};
|
|
59
|
-
"iq:application"
|
|
60
|
-
"iq:barrel"
|
|
59
|
+
"iq:application"?: Array<iqApplication>;
|
|
60
|
+
"iq:barrel"?: Array<iqBarrel>;
|
|
61
61
|
};
|
|
62
62
|
};
|
|
63
63
|
export declare function readManifest(manifest: string): Promise<ManifestXML>;
|
|
@@ -66,6 +66,6 @@ export declare function manifestProducts(manifest: ManifestXML): string[];
|
|
|
66
66
|
export declare function manifestBarrels(manifest: ManifestXML): string[];
|
|
67
67
|
export declare function manifestDropBarrels(manifest: ManifestXML): void;
|
|
68
68
|
export declare function manifestBarrelName(manifestName: string, manifest: ManifestXML): string;
|
|
69
|
-
export declare function manifestAnnotations(manifest: ManifestXML): string[];
|
|
69
|
+
export declare function manifestAnnotations(manifest: ManifestXML): string[] | undefined;
|
|
70
70
|
export declare function checkManifest(manifest: ManifestXML, products: string[]): Promise<boolean>;
|
|
71
71
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
export declare function getFileSources(fnMap: FilesToOptimizeMap): Promise<void>;
|
|
3
3
|
export declare function getFileASTs(fnMap: FilesToOptimizeMap): Promise<boolean>;
|
|
4
|
-
export declare function analyze(fnMap: FilesToOptimizeMap): Promise<
|
|
5
|
-
export declare function getLiteralFromDecls(decls: StateNodeDecl[]):
|
|
6
|
-
export declare function getLiteralNode(node: mctree.Node): null | mctree.Literal | mctree.AsExpression;
|
|
4
|
+
export declare function analyze(fnMap: FilesToOptimizeMap): Promise<ProgramStateAnalysis>;
|
|
5
|
+
export declare function getLiteralFromDecls(decls: StateNodeDecl[]): null;
|
|
6
|
+
export declare function getLiteralNode(node: mctree.Node | null | undefined): null | mctree.Literal | mctree.AsExpression;
|
|
7
7
|
export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap): Promise<void>;
|
package/build/src/optimizer.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { get_jungle, ResolvedJungle, Target } from "./jungles";
|
|
2
3
|
import { launchSimulator, simulateProgram } from "./launch";
|
|
4
|
+
import { manifestProducts } from "./manifest";
|
|
3
5
|
import { copyRecursiveAsNeeded } from "./util";
|
|
4
|
-
|
|
5
|
-
export { copyRecursiveAsNeeded, launchSimulator, simulateProgram, get_jungle, ResolvedJungle, mctree, };
|
|
6
|
+
export { copyRecursiveAsNeeded, get_jungle, launchSimulator, manifestProducts, mctree, ResolvedJungle, simulateProgram, };
|
|
6
7
|
export declare const defaultConfig: {
|
|
7
8
|
outputPath: string;
|
|
8
9
|
workspace: string;
|
|
9
10
|
};
|
|
11
|
+
export interface ErrorWithLocation extends Error {
|
|
12
|
+
location?: NonNullable<mctree.Node["loc"]>;
|
|
13
|
+
}
|
|
14
|
+
export declare function isErrorWithLocation(e: Error): e is ErrorWithLocation;
|
|
10
15
|
declare global {
|
|
11
16
|
type BuildConfig = {
|
|
12
17
|
workspace?: string;
|
|
@@ -85,11 +90,12 @@ declare global {
|
|
|
85
90
|
allFunctions?: FunctionStateNode[];
|
|
86
91
|
allClasses?: ClassStateNode[];
|
|
87
92
|
stack?: ProgramStateStack;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
removeNodeComments?: (node: mctree.Node, ast: mctree.Program) => void;
|
|
94
|
+
shouldExclude?: (node: mctree.Node) => boolean;
|
|
95
|
+
pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
|
|
96
|
+
post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node;
|
|
97
|
+
lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
|
|
98
|
+
traverse?: (node: mctree.Node) => void | null | false | mctree.Node;
|
|
93
99
|
exposed?: {
|
|
94
100
|
[key: string]: true;
|
|
95
101
|
};
|
|
@@ -112,6 +118,12 @@ declare global {
|
|
|
112
118
|
[key: string]: mctree.Literal;
|
|
113
119
|
};
|
|
114
120
|
};
|
|
121
|
+
type Finalized<T, Keys extends keyof T> = T & {
|
|
122
|
+
[key in Keys]-?: NonNullable<T[key]>;
|
|
123
|
+
};
|
|
124
|
+
export type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "traverse" | "index" | "constants" | "removeNodeComments">;
|
|
125
|
+
export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions">;
|
|
126
|
+
export type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions">;
|
|
115
127
|
type ExcludeAnnotationsMap = {
|
|
116
128
|
[key: string]: boolean;
|
|
117
129
|
};
|
|
@@ -137,20 +149,17 @@ export declare function buildOptimizedProject(product: string | null, options: B
|
|
|
137
149
|
exe: string;
|
|
138
150
|
args: string[];
|
|
139
151
|
program: string;
|
|
140
|
-
product: string;
|
|
141
|
-
hasTests: boolean;
|
|
152
|
+
product: string | null;
|
|
153
|
+
hasTests: boolean | undefined;
|
|
142
154
|
}>;
|
|
143
|
-
/**
|
|
144
|
-
*
|
|
145
|
-
* @param {BuildConfig} options
|
|
146
|
-
* @returns
|
|
147
|
-
*/
|
|
148
155
|
export declare function generateOptimizedProject(options: BuildConfig): Promise<{
|
|
149
|
-
jungleFiles: string;
|
|
156
|
+
jungleFiles: string | undefined;
|
|
150
157
|
program: string;
|
|
158
|
+
xml?: undefined;
|
|
151
159
|
hasTests?: undefined;
|
|
152
160
|
} | {
|
|
153
161
|
jungleFiles: string;
|
|
162
|
+
xml: import("./manifest").ManifestXML;
|
|
154
163
|
program: string;
|
|
155
164
|
hasTests: boolean;
|
|
156
165
|
}>;
|
package/build/src/sdk-util.d.ts
CHANGED
|
@@ -2,13 +2,16 @@ export declare const isWin: boolean;
|
|
|
2
2
|
export declare const appSupport: string;
|
|
3
3
|
export declare const connectiq: string;
|
|
4
4
|
export declare function getSdkPath(): Promise<string>;
|
|
5
|
-
export declare
|
|
5
|
+
export declare type DeviceInfo = {
|
|
6
6
|
[key: string]: {
|
|
7
7
|
appTypes: {
|
|
8
8
|
memoryLimit: number;
|
|
9
9
|
type: string;
|
|
10
10
|
}[];
|
|
11
11
|
deviceFamily: string;
|
|
12
|
+
displayName: string;
|
|
13
|
+
languages: Record<string, true>;
|
|
12
14
|
};
|
|
13
|
-
}
|
|
15
|
+
};
|
|
16
|
+
export declare function getDeviceInfo(): Promise<DeviceInfo>;
|
|
14
17
|
export declare function getLanguages(): Promise<any>;
|
package/build/src/util.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}): Promise<Array<string>>;
|
|
1
|
+
import * as glob from "glob";
|
|
2
|
+
export declare function globa(pattern: string, options?: glob.IOptions): Promise<Array<string>>;
|
|
4
3
|
export declare function last_modified(inputs: string[]): Promise<number>;
|
|
5
4
|
export declare function first_modified(inputs: string[]): Promise<number>;
|
|
6
5
|
export declare function pushUnique<T>(arr: T[], value: T): void;
|
package/build/util.cjs
CHANGED
|
@@ -1303,6 +1303,8 @@ function setopts (self, pattern, options) {
|
|
|
1303
1303
|
// Note that they are not supported in Glob itself anyway.
|
|
1304
1304
|
options.nonegate = true
|
|
1305
1305
|
options.nocomment = true
|
|
1306
|
+
// always treat \ in patterns as escapes, not path separators
|
|
1307
|
+
options.allowWindowsEscape = false
|
|
1306
1308
|
|
|
1307
1309
|
self.minimatch = new Minimatch(pattern, options)
|
|
1308
1310
|
self.options = self.minimatch.options
|
|
@@ -1778,7 +1780,10 @@ Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
|
|
|
1778
1780
|
var read
|
|
1779
1781
|
if (prefix === null)
|
|
1780
1782
|
read = '.'
|
|
1781
|
-
else if (isAbsolute(prefix) ||
|
|
1783
|
+
else if (isAbsolute(prefix) ||
|
|
1784
|
+
isAbsolute(pattern.map(function (p) {
|
|
1785
|
+
return typeof p === 'string' ? p : '[*]'
|
|
1786
|
+
}).join('/'))) {
|
|
1782
1787
|
if (!prefix || !isAbsolute(prefix))
|
|
1783
1788
|
prefix = '/' + prefix
|
|
1784
1789
|
read = prefix
|
|
@@ -2278,7 +2283,7 @@ function GlobSync (pattern, options) {
|
|
|
2278
2283
|
}
|
|
2279
2284
|
|
|
2280
2285
|
GlobSync.prototype._finish = function () {
|
|
2281
|
-
assert(this instanceof GlobSync)
|
|
2286
|
+
assert.ok(this instanceof GlobSync)
|
|
2282
2287
|
if (this.realpath) {
|
|
2283
2288
|
var self = this
|
|
2284
2289
|
this.matches.forEach(function (matchset, index) {
|
|
@@ -2302,7 +2307,7 @@ GlobSync.prototype._finish = function () {
|
|
|
2302
2307
|
|
|
2303
2308
|
|
|
2304
2309
|
GlobSync.prototype._process = function (pattern, index, inGlobStar) {
|
|
2305
|
-
assert(this instanceof GlobSync)
|
|
2310
|
+
assert.ok(this instanceof GlobSync)
|
|
2306
2311
|
|
|
2307
2312
|
// Get the first [n] parts of pattern that are all strings.
|
|
2308
2313
|
var n = 0
|
|
@@ -2339,7 +2344,10 @@ GlobSync.prototype._process = function (pattern, index, inGlobStar) {
|
|
|
2339
2344
|
var read
|
|
2340
2345
|
if (prefix === null)
|
|
2341
2346
|
read = '.'
|
|
2342
|
-
else if (isAbsolute(prefix) ||
|
|
2347
|
+
else if (isAbsolute(prefix) ||
|
|
2348
|
+
isAbsolute(pattern.map(function (p) {
|
|
2349
|
+
return typeof p === 'string' ? p : '[*]'
|
|
2350
|
+
}).join('/'))) {
|
|
2343
2351
|
if (!prefix || !isAbsolute(prefix))
|
|
2344
2352
|
prefix = '/' + prefix
|
|
2345
2353
|
read = prefix
|
|
@@ -3940,18 +3948,6 @@ module.exports = require("util");
|
|
|
3940
3948
|
/******/ }
|
|
3941
3949
|
/******/
|
|
3942
3950
|
/************************************************************************/
|
|
3943
|
-
/******/ /* webpack/runtime/compat get default export */
|
|
3944
|
-
/******/ (() => {
|
|
3945
|
-
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
3946
|
-
/******/ __webpack_require__.n = (module) => {
|
|
3947
|
-
/******/ var getter = module && module.__esModule ?
|
|
3948
|
-
/******/ () => (module['default']) :
|
|
3949
|
-
/******/ () => (module);
|
|
3950
|
-
/******/ __webpack_require__.d(getter, { a: getter });
|
|
3951
|
-
/******/ return getter;
|
|
3952
|
-
/******/ };
|
|
3953
|
-
/******/ })();
|
|
3954
|
-
/******/
|
|
3955
3951
|
/******/ /* webpack/runtime/define property getters */
|
|
3956
3952
|
/******/ (() => {
|
|
3957
3953
|
/******/ // define getter functions for harmony exports
|
|
@@ -4020,7 +4016,6 @@ var external_fs_ = __webpack_require__(6231);
|
|
|
4020
4016
|
const promises_namespaceObject = require("fs/promises");
|
|
4021
4017
|
// EXTERNAL MODULE: ./node_modules/glob/glob.js
|
|
4022
4018
|
var glob = __webpack_require__(2884);
|
|
4023
|
-
var glob_default = /*#__PURE__*/__webpack_require__.n(glob);
|
|
4024
4019
|
// EXTERNAL MODULE: external "path"
|
|
4025
4020
|
var external_path_ = __webpack_require__(1423);
|
|
4026
4021
|
;// CONCATENATED MODULE: external "readline"
|
|
@@ -4038,7 +4033,7 @@ const external_readline_namespaceObject = require("readline");
|
|
|
4038
4033
|
__webpack_require__.g["lastModifiedSource" + ""] = 0;
|
|
4039
4034
|
function globa(pattern, options) {
|
|
4040
4035
|
return new Promise((resolve, reject) => {
|
|
4041
|
-
|
|
4036
|
+
glob.glob(pattern, options || {}, (er, files) => {
|
|
4042
4037
|
if (er) {
|
|
4043
4038
|
reject(files);
|
|
4044
4039
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markw65/monkeyc-optimizer",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.14",
|
|
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",
|
|
8
8
|
"exports": {
|
|
9
|
-
".":
|
|
10
|
-
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./build/src/optimizer.d.ts",
|
|
11
|
+
"default": "./build/optimizer.cjs"
|
|
12
|
+
},
|
|
13
|
+
"./*.js": {
|
|
14
|
+
"types": "./build/src/*.d.ts",
|
|
15
|
+
"default": "./build/*.cjs"
|
|
16
|
+
}
|
|
11
17
|
},
|
|
12
18
|
"scripts": {
|
|
13
19
|
"watch": "webpack --mode development --watch",
|
|
@@ -27,7 +33,7 @@
|
|
|
27
33
|
"author": "markw65",
|
|
28
34
|
"license": "MIT",
|
|
29
35
|
"dependencies": {
|
|
30
|
-
"@markw65/prettier-plugin-monkeyc": "^1.0.
|
|
36
|
+
"@markw65/prettier-plugin-monkeyc": "^1.0.21"
|
|
31
37
|
},
|
|
32
38
|
"devDependencies": {
|
|
33
39
|
"@types/glob": "^7.2.0",
|