@markw65/monkeyc-optimizer 1.0.33 → 1.0.34
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 +11 -0
- package/build/api.cjs +2 -1
- package/build/optimizer.cjs +26 -16
- package/build/sdk-util.cjs +31 -2
- package/build/src/api.d.ts +1 -1
- package/build/src/driver.d.ts +2 -0
- package/build/src/mc-rewrite.d.ts +1 -1
- package/build/src/optimizer-types.d.ts +2 -1
- package/build/src/optimizer.d.ts +2 -2
- package/build/src/projects.d.ts +21 -0
- package/build/src/readprg.d.ts +5 -0
- package/build/src/sdk-util.d.ts +1 -0
- package/build/src/util.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -393,3 +393,14 @@ Bug Fixes
|
|
|
393
393
|
|
|
394
394
|
- Bug fixes
|
|
395
395
|
- Fix PRE to not merge values with different types. ie Number, Long, Float and Double literals should all be treated separately, even when the compare the same.
|
|
396
|
+
|
|
397
|
+
### 1.0.34
|
|
398
|
+
|
|
399
|
+
- Bug fixes
|
|
400
|
+
|
|
401
|
+
- Fix parser to allow white space to separate attributes, in addition to comma
|
|
402
|
+
- Fix optimizer to respect prettier options when formatting the optimized code
|
|
403
|
+
|
|
404
|
+
- Testing
|
|
405
|
+
- rewrite test harness in typescript
|
|
406
|
+
- fix up tests to work with compiler2 again, and also with compiler2 at -O0
|
package/build/api.cjs
CHANGED
|
@@ -5059,7 +5059,7 @@ function api_collectNamespaces(ast, stateIn) {
|
|
|
5059
5059
|
}
|
|
5060
5060
|
return state.stack[0];
|
|
5061
5061
|
}
|
|
5062
|
-
function api_formatAst(node, monkeyCSource = null) {
|
|
5062
|
+
function api_formatAst(node, monkeyCSource = null, options = null) {
|
|
5063
5063
|
/*
|
|
5064
5064
|
* The estree printer sometimes looks at the parent node without
|
|
5065
5065
|
* checking that there *is* a parent node (eg it assumes all
|
|
@@ -5087,6 +5087,7 @@ function api_formatAst(node, monkeyCSource = null) {
|
|
|
5087
5087
|
// looking for in the source.
|
|
5088
5088
|
const source = (monkeyCSource || "") + "\n" + (0,prettier_plugin_monkeyc_namespaceObject.serializeMonkeyC)(node);
|
|
5089
5089
|
return external_prettier_namespaceObject.format(source, {
|
|
5090
|
+
...(options || {}),
|
|
5090
5091
|
parser: "monkeyc-json",
|
|
5091
5092
|
plugins: [(prettier_plugin_monkeyc_default())],
|
|
5092
5093
|
endOfLine: "lf",
|
package/build/optimizer.cjs
CHANGED
|
@@ -10024,6 +10024,8 @@ const external_crypto_namespaceObject = require("crypto");
|
|
|
10024
10024
|
const promises_namespaceObject = require("fs/promises");
|
|
10025
10025
|
// EXTERNAL MODULE: external "path"
|
|
10026
10026
|
var external_path_ = __webpack_require__(1423);
|
|
10027
|
+
;// CONCATENATED MODULE: external "prettier"
|
|
10028
|
+
const external_prettier_namespaceObject = require("prettier");
|
|
10027
10029
|
;// CONCATENATED MODULE: external "./api.cjs"
|
|
10028
10030
|
const external_api_cjs_namespaceObject = require("./api.cjs");
|
|
10029
10031
|
;// CONCATENATED MODULE: external "./sdk-util.cjs"
|
|
@@ -15047,6 +15049,7 @@ function optimizeCall(state, node, context) {
|
|
|
15047
15049
|
|
|
15048
15050
|
|
|
15049
15051
|
|
|
15052
|
+
|
|
15050
15053
|
function relative_path_no_dotdot(relative) {
|
|
15051
15054
|
return relative.replace(/^(\.\.[\\/])+/, (str) => `__${"dot".repeat(str.length / 3)}__${str.slice(-1)}`);
|
|
15052
15055
|
}
|
|
@@ -15469,28 +15472,35 @@ async function generateOneConfig(buildConfig, dependencyFiles, config) {
|
|
|
15469
15472
|
// the oldest optimized file, we don't need to regenerate
|
|
15470
15473
|
const source_time = await (0,external_util_cjs_namespaceObject.last_modified)(Object.keys(fnMap).concat(dependencyFiles));
|
|
15471
15474
|
const opt_time = await (0,external_util_cjs_namespaceObject.first_modified)(Object.values(fnMap).map((v) => v.output));
|
|
15472
|
-
if (source_time < opt_time &&
|
|
15475
|
+
if (source_time < opt_time && 1659827507288 < opt_time) {
|
|
15473
15476
|
return { hasTests, diagnostics: prevDiagnostics };
|
|
15474
15477
|
}
|
|
15475
15478
|
}
|
|
15476
15479
|
await promises_namespaceObject.rm(output, { recursive: true, force: true });
|
|
15477
15480
|
await promises_namespaceObject.mkdir(output, { recursive: true });
|
|
15478
15481
|
const diagnostics = await optimizeMonkeyC(fnMap, Object.keys(buildConfig.barrelMap || {}), config);
|
|
15479
|
-
return
|
|
15480
|
-
|
|
15481
|
-
|
|
15482
|
-
|
|
15483
|
-
const
|
|
15484
|
-
|
|
15485
|
-
|
|
15486
|
-
|
|
15487
|
-
|
|
15488
|
-
|
|
15489
|
-
|
|
15490
|
-
|
|
15491
|
-
|
|
15492
|
-
}))
|
|
15493
|
-
.
|
|
15482
|
+
return external_prettier_namespaceObject.resolveConfig(config.workspace, {
|
|
15483
|
+
useCache: false,
|
|
15484
|
+
editorconfig: true,
|
|
15485
|
+
}).then((prettierConfig) => {
|
|
15486
|
+
const options = { ...prettierConfig, ...(config.prettier || {}) };
|
|
15487
|
+
return Promise.all(Object.values(fnMap).map(async (info) => {
|
|
15488
|
+
const name = info.output;
|
|
15489
|
+
const dir = external_path_.dirname(name);
|
|
15490
|
+
await promises_namespaceObject.mkdir(dir, { recursive: true });
|
|
15491
|
+
options.filepath = name;
|
|
15492
|
+
const opt_source = (0,external_api_cjs_namespaceObject.formatAst)(info.ast, info.monkeyCSource, options);
|
|
15493
|
+
await promises_namespaceObject.writeFile(name, opt_source);
|
|
15494
|
+
return info.hasTests;
|
|
15495
|
+
})).then((results) => {
|
|
15496
|
+
const hasTests = results.some((v) => v);
|
|
15497
|
+
return promises_namespaceObject.writeFile(external_path_.join(output, "build-info.json"), JSON.stringify({
|
|
15498
|
+
hasTests,
|
|
15499
|
+
diagnostics,
|
|
15500
|
+
...Object.fromEntries(configOptionsToCheck.map((option) => [option, config[option]])),
|
|
15501
|
+
}))
|
|
15502
|
+
.then(() => ({ hasTests, diagnostics }));
|
|
15503
|
+
});
|
|
15494
15504
|
});
|
|
15495
15505
|
}
|
|
15496
15506
|
async function getProjectAnalysis(targets, analysis, options) {
|
package/build/sdk-util.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
0 && (module.exports = {appSupport,connectiq,getDeviceInfo,getLanguages,getSdkPath,isWin});
|
|
1
|
+
0 && (module.exports = {SectionKinds,appSupport,connectiq,getDeviceInfo,getLanguages,getSdkPath,isWin,readPrg});
|
|
2
2
|
/******/ (() => { // webpackBootstrap
|
|
3
3
|
/******/ var __webpack_modules__ = ({
|
|
4
4
|
|
|
@@ -7171,12 +7171,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
7171
7171
|
|
|
7172
7172
|
// EXPORTS
|
|
7173
7173
|
__webpack_require__.d(__webpack_exports__, {
|
|
7174
|
+
"SectionKinds": () => (/* reexport */ SectionKinds),
|
|
7174
7175
|
"appSupport": () => (/* binding */ appSupport),
|
|
7175
7176
|
"connectiq": () => (/* binding */ connectiq),
|
|
7176
7177
|
"getDeviceInfo": () => (/* binding */ getDeviceInfo),
|
|
7177
7178
|
"getLanguages": () => (/* binding */ getLanguages),
|
|
7178
7179
|
"getSdkPath": () => (/* binding */ getSdkPath),
|
|
7179
|
-
"isWin": () => (/* binding */ isWin)
|
|
7180
|
+
"isWin": () => (/* binding */ isWin),
|
|
7181
|
+
"readPrg": () => (/* reexport */ readPrg)
|
|
7180
7182
|
});
|
|
7181
7183
|
|
|
7182
7184
|
;// CONCATENATED MODULE: external "fs/promises"
|
|
@@ -7187,11 +7189,38 @@ const external_path_namespaceObject = require("path");
|
|
|
7187
7189
|
var xml2js = __webpack_require__(5055);
|
|
7188
7190
|
;// CONCATENATED MODULE: external "./util.cjs"
|
|
7189
7191
|
const external_util_cjs_namespaceObject = require("./util.cjs");
|
|
7192
|
+
;// CONCATENATED MODULE: ./src/readprg.ts
|
|
7193
|
+
|
|
7194
|
+
var SectionKinds;
|
|
7195
|
+
(function (SectionKinds) {
|
|
7196
|
+
SectionKinds[SectionKinds["TEXT"] = -1059145026] = "TEXT";
|
|
7197
|
+
SectionKinds[SectionKinds["DATA"] = -629491010] = "DATA";
|
|
7198
|
+
})(SectionKinds || (SectionKinds = {}));
|
|
7199
|
+
async function readPrg(path) {
|
|
7200
|
+
const data = await promises_namespaceObject.readFile(path);
|
|
7201
|
+
const view = new DataView(data.buffer);
|
|
7202
|
+
const sections = {};
|
|
7203
|
+
let offset = 0;
|
|
7204
|
+
while (view.byteLength - offset > 8) {
|
|
7205
|
+
const type = view.getInt32(offset);
|
|
7206
|
+
offset += 4;
|
|
7207
|
+
const length = view.getInt32(offset);
|
|
7208
|
+
offset += 4;
|
|
7209
|
+
if (length > view.byteLength - offset) {
|
|
7210
|
+
throw new Error(`Invalid length for section ${type}`);
|
|
7211
|
+
}
|
|
7212
|
+
sections[type] = length;
|
|
7213
|
+
offset += length;
|
|
7214
|
+
}
|
|
7215
|
+
return sections;
|
|
7216
|
+
}
|
|
7217
|
+
|
|
7190
7218
|
;// CONCATENATED MODULE: ./src/sdk-util.ts
|
|
7191
7219
|
|
|
7192
7220
|
|
|
7193
7221
|
|
|
7194
7222
|
|
|
7223
|
+
|
|
7195
7224
|
const isWin = process.platform == "win32";
|
|
7196
7225
|
const appSupport = isWin
|
|
7197
7226
|
? `${process.env.APPDATA}`.replace(/\\/g, "/")
|
package/build/src/api.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare function variableDeclarationName(node: mctree.TypedIdentifier | m
|
|
|
9
9
|
export declare function sameLookupResult(a: LookupDefinition[], b: LookupDefinition[]): boolean;
|
|
10
10
|
export declare function isLookupCandidate(node: mctree.MemberExpression): false | mctree.Identifier;
|
|
11
11
|
export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
|
|
12
|
-
export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null): string;
|
|
12
|
+
export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null, options?: Record<string, unknown> | null): string;
|
|
13
13
|
export declare function findUsingForNode(state: ProgramStateLive, stack: ProgramStateStack, i: number, node: mctree.Identifier, isType: boolean): StateNodeDecl[] | null;
|
|
14
14
|
export declare function getApiFunctionInfo(func: FunctionStateNode): FunctionInfo;
|
|
15
15
|
export declare function markInvokeClassMethod(func: FunctionStateNode): void;
|
|
@@ -6,7 +6,7 @@ export declare function analyze(fnMap: FilesToOptimizeMap, barrelList?: string[]
|
|
|
6
6
|
export declare function getLiteralFromDecls(lookupDefns: LookupDefinition[]): mctree.Literal | mctree.AsExpression | null;
|
|
7
7
|
export declare function getLiteralNode(node: mctree.Node | null | undefined): null | mctree.Literal | mctree.AsExpression;
|
|
8
8
|
export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, barrelList?: string[], config?: BuildConfig): Promise<Record<string, {
|
|
9
|
-
type: "
|
|
9
|
+
type: import("./optimizer-types").DiagnosticType;
|
|
10
10
|
loc: {
|
|
11
11
|
start: mctree.Position;
|
|
12
12
|
end: mctree.Position;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
import { ResolvedJungle } from "./jungles";
|
|
3
|
-
declare type DiagnosticType = "ERROR" | "WARNING" | "INFO";
|
|
3
|
+
export declare type DiagnosticType = "ERROR" | "WARNING" | "INFO";
|
|
4
4
|
export declare type BuildConfig = {
|
|
5
5
|
workspace?: string;
|
|
6
6
|
jungleFiles?: string;
|
|
@@ -25,6 +25,7 @@ export declare type BuildConfig = {
|
|
|
25
25
|
checkBuildPragmas?: boolean;
|
|
26
26
|
checkInvalidSymbols?: DiagnosticType | "OFF";
|
|
27
27
|
sizeBasedPRE?: boolean | string;
|
|
28
|
+
prettier?: Record<string, unknown>;
|
|
28
29
|
_cache?: {
|
|
29
30
|
barrels?: Record<string, ResolvedJungle>;
|
|
30
31
|
barrelMap?: Record<string, Record<string, ResolvedJungle>>;
|
package/build/src/optimizer.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare function buildOptimizedProject(product: string | null, options: B
|
|
|
30
30
|
product: string | null;
|
|
31
31
|
hasTests: boolean;
|
|
32
32
|
diagnostics: Record<string, {
|
|
33
|
-
type: "
|
|
33
|
+
type: import("./optimizer-types").DiagnosticType;
|
|
34
34
|
loc: {
|
|
35
35
|
start: mctree.Position;
|
|
36
36
|
end: mctree.Position;
|
|
@@ -50,7 +50,7 @@ export declare function generateOptimizedProject(options: BuildConfig): Promise<
|
|
|
50
50
|
program: string;
|
|
51
51
|
hasTests: boolean;
|
|
52
52
|
diagnostics: Record<string, {
|
|
53
|
-
type: "
|
|
53
|
+
type: import("./optimizer-types").DiagnosticType;
|
|
54
54
|
loc: {
|
|
55
55
|
start: mctree.Position;
|
|
56
56
|
end: mctree.Position;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BuildConfig } from "./optimizer-types";
|
|
2
|
+
export declare type RemoteProject = string | {
|
|
3
|
+
root: string;
|
|
4
|
+
options?: BuildConfig;
|
|
5
|
+
rename?: {
|
|
6
|
+
from: string;
|
|
7
|
+
to: string;
|
|
8
|
+
}[];
|
|
9
|
+
build?: boolean;
|
|
10
|
+
comment?: string;
|
|
11
|
+
exclude?: string;
|
|
12
|
+
include?: string;
|
|
13
|
+
sourcePath?: string;
|
|
14
|
+
jungleContent?: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare const githubProjects: RemoteProject[];
|
|
17
|
+
export declare function fetchGitProjects(projects: RemoteProject[]): Promise<(string | {
|
|
18
|
+
jungle: string;
|
|
19
|
+
build: boolean | null;
|
|
20
|
+
options: BuildConfig | null;
|
|
21
|
+
})[]>;
|
package/build/src/sdk-util.d.ts
CHANGED
package/build/src/util.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export declare function spawnByLine(command: string, args: string[], lineHandler
|
|
|
9
9
|
[key: string]: unknown;
|
|
10
10
|
}): Promise<void>;
|
|
11
11
|
export declare function readByLine(file: string, lineHandler: LineHandler): Promise<unknown>;
|
|
12
|
-
export declare function promiseAll<T>(promiseFn: (i: number) => Promise<T
|
|
12
|
+
export declare function promiseAll<T>(promiseFn: (i: number) => Promise<T> | null, parallelism: number): Promise<T[]>;
|
|
13
13
|
export declare function copyRecursiveAsNeeded(source: string, target: string, filter?: (src: string, tgt: string) => boolean): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markw65/monkeyc-optimizer",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.34",
|
|
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",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"author": "markw65",
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@markw65/prettier-plugin-monkeyc": "^1.0.
|
|
40
|
+
"@markw65/prettier-plugin-monkeyc": "^1.0.34"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/glob": "^7.2.0",
|