@idlizer/arktscgen 2.1.10-arktscgen-5 → 2.1.10-arktscgen-6
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/build/libarkts-copy/generator/options.json5 +24 -47
- package/build/libarkts-copy/native/meson.build +25 -9
- package/build/libarkts-copy/native/meson_options.txt +9 -3
- package/build/libarkts-copy/native/mingw.cross +2 -0
- package/build/libarkts-copy/native/src/bridges.cc +20 -81
- package/build/libarkts-copy/native/src/common.cc +127 -49
- package/build/libarkts-copy/native/src/memoryTracker.cc +42 -35
- package/build/libarkts-copy/package.json +12 -10
- package/build/libarkts-copy/src/Es2pandaNativeModule.ts +10 -63
- package/build/libarkts-copy/src/arkts-api/AbstractVisitor.ts +9 -3
- package/build/libarkts-copy/src/arkts-api/ImportStorage.ts +2 -4
- package/build/libarkts-copy/src/arkts-api/ProgramProvider.ts +14 -5
- package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +19 -1
- package/build/libarkts-copy/src/arkts-api/index.ts +0 -1
- package/build/libarkts-copy/src/arkts-api/node-cache.ts +12 -3
- package/build/libarkts-copy/src/arkts-api/node-utilities/ObjectExpression.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/ScriptFunction.ts +4 -4
- package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +0 -16
- package/build/libarkts-copy/src/arkts-api/peers/Config.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/peers/Context.ts +10 -9
- package/build/libarkts-copy/src/arkts-api/plugins.ts +110 -5
- package/build/libarkts-copy/src/arkts-api/static/global.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/static/profiler.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/utilities/performance.ts +2 -1
- package/build/libarkts-copy/src/arkts-api/utilities/private.ts +4 -9
- package/build/libarkts-copy/src/arkts-api/utilities/public.ts +41 -9
- package/build/libarkts-copy/src/arkts-api/visitor.ts +4 -25
- package/build/libarkts-copy/src/checkSdk.ts +1 -1
- package/build/libarkts-copy/src/index.ts +1 -1
- package/build/libarkts-copy/src/memo-node-cache.ts +143 -0
- package/build/libarkts-copy/src/plugin-utils.ts +19 -12
- package/build/libarkts-copy/src/reexport-for-generated.ts +2 -0
- package/build/libarkts-copy/src/tracer.ts +2 -2
- package/build/libarkts-copy/src/ts-api/factory/nodeFactory.ts +2 -2
- package/build/libarkts-copy/src/ts-api/utilities/private.ts +2 -2
- package/build/libarkts-copy/src/utils.ts +10 -14
- package/lib/index.js +5316 -10427
- package/package.json +9 -7
- package/build/libarkts-copy/src/arkts-api/peers/DiagnosticKind.ts +0 -23
|
@@ -18,29 +18,29 @@
|
|
|
18
18
|
#include <cstdint>
|
|
19
19
|
#include <fstream>
|
|
20
20
|
#include <iostream>
|
|
21
|
-
#include <regex>
|
|
22
21
|
#include <sstream>
|
|
23
22
|
#include <system_error>
|
|
24
23
|
#include <vector>
|
|
24
|
+
#include <regex>
|
|
25
25
|
|
|
26
26
|
#ifdef _WIN32
|
|
27
|
-
#include <
|
|
28
|
-
#include <
|
|
27
|
+
#include <windows.h>
|
|
28
|
+
#include <psapi.h>
|
|
29
29
|
#elif defined(__APPLE__)
|
|
30
|
-
#include <mach/mach.h>
|
|
31
|
-
#include <sys/resource.h>
|
|
30
|
+
#include <mach/mach.h>
|
|
31
|
+
#include <sys/resource.h>
|
|
32
32
|
#elif defined(__linux__)
|
|
33
|
-
#include <sys/resource.h>
|
|
34
|
-
#include <unistd.h>
|
|
33
|
+
#include <sys/resource.h>
|
|
34
|
+
#include <unistd.h>
|
|
35
35
|
#endif
|
|
36
36
|
|
|
37
37
|
constexpr const char* UNIT_K = "kB";
|
|
38
38
|
constexpr size_t BYTES_PER_KB = 1024;
|
|
39
39
|
constexpr const char* MEMORY_STATUS_FILE = "/proc/self/status";
|
|
40
|
-
const std::regex VM_RSS_REGEX(
|
|
41
|
-
|
|
42
|
-
const std::regex VM_SIZE_REGEX(
|
|
43
|
-
|
|
40
|
+
const std::regex VM_RSS_REGEX(R"#(VmRSS:\s*(\d+)\s*([kKmMgG]?B))#",
|
|
41
|
+
std::regex_constants::ECMAScript | std::regex_constants::icase);
|
|
42
|
+
const std::regex VM_SIZE_REGEX(R"#(VmSize:\s*(\d+)\s*([kKmMgG]?B))#",
|
|
43
|
+
std::regex_constants::ECMAScript | std::regex_constants::icase);
|
|
44
44
|
|
|
45
45
|
constexpr int MATCH_GROUP_VALUE = 1;
|
|
46
46
|
constexpr int MATCH_GROUP_UNIT = 2;
|
|
@@ -49,9 +49,10 @@ constexpr int MATCH_GROUP_SIZE = 3;
|
|
|
49
49
|
#if defined(_WIN32)
|
|
50
50
|
MemoryStats GetMemoryStats()
|
|
51
51
|
{
|
|
52
|
-
MemoryStats stats = {
|
|
52
|
+
MemoryStats stats = {0, 0, 0, 0, 0};
|
|
53
53
|
PROCESS_MEMORY_COUNTERS_EX pmc;
|
|
54
|
-
if (GetProcessMemoryInfo(GetCurrentProcess(),
|
|
54
|
+
if (GetProcessMemoryInfo(GetCurrentProcess(),
|
|
55
|
+
reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmc), sizeof(pmc))) {
|
|
55
56
|
stats.currentRss = pmc.WorkingSetSize;
|
|
56
57
|
stats.peakRss = pmc.PeakWorkingSetSize;
|
|
57
58
|
stats.currentVss = pmc.PrivateUsage; // 私有内存使用量
|
|
@@ -65,18 +66,19 @@ MemoryStats GetMemoryStats()
|
|
|
65
66
|
#elif defined(__APPLE__)
|
|
66
67
|
MemoryStats GetMemoryStats()
|
|
67
68
|
{
|
|
68
|
-
MemoryStats stats = {
|
|
69
|
+
MemoryStats stats = {0, 0, 0, 0, 0};
|
|
69
70
|
struct rusage ru;
|
|
70
71
|
if (getrusage(RUSAGE_SELF, &ru) == 0) {
|
|
71
|
-
stats.currentRss = 0;
|
|
72
|
+
stats.currentRss = 0; // macOS需要专用API获取当前内存
|
|
72
73
|
stats.peakRss = ru.ru_maxrss; // macOS返回字节
|
|
73
74
|
stats.pageFaultsMinor = ru.ru_minflt;
|
|
74
75
|
stats.pageFaultsMajor = ru.ru_majflt;
|
|
75
|
-
|
|
76
|
+
|
|
76
77
|
// 获取当前内存使用 (macOS专用API)
|
|
77
78
|
task_basic_info info;
|
|
78
79
|
mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT;
|
|
79
|
-
if (task_info(mach_task_self(), TASK_BASIC_INFO_64,
|
|
80
|
+
if (task_info(mach_task_self(), TASK_BASIC_INFO_64,
|
|
81
|
+
(task_info_t)&info, &count) == KERN_SUCCESS) {
|
|
80
82
|
stats.currentRss = info.resident_size; // 物理内存使用量
|
|
81
83
|
stats.currentVss = info.virtual_size; // 虚拟内存总量
|
|
82
84
|
}
|
|
@@ -87,7 +89,7 @@ MemoryStats GetMemoryStats()
|
|
|
87
89
|
#elif defined(__linux__)
|
|
88
90
|
MemoryStats GetMemoryStats()
|
|
89
91
|
{
|
|
90
|
-
MemoryStats stats = {
|
|
92
|
+
MemoryStats stats = {0, 0, 0, 0, 0};
|
|
91
93
|
struct rusage ru;
|
|
92
94
|
if (getrusage(RUSAGE_SELF, &ru) == 0) {
|
|
93
95
|
stats.peakRss = static_cast<size_t>(ru.ru_maxrss) * BYTES_PER_KB; // KB -> 字节
|
|
@@ -127,9 +129,13 @@ void MemoryTracker::Reset()
|
|
|
127
129
|
MemoryStats MemoryTracker::GetDelta()
|
|
128
130
|
{
|
|
129
131
|
MemoryStats current = GetMemoryStats();
|
|
130
|
-
MemoryStats delta = {
|
|
131
|
-
current.
|
|
132
|
-
current.
|
|
132
|
+
MemoryStats delta = {
|
|
133
|
+
current.currentRss - baseline.currentRss,
|
|
134
|
+
current.peakRss - baseline.peakRss,
|
|
135
|
+
current.currentVss - baseline.currentVss,
|
|
136
|
+
current.pageFaultsMinor - baseline.pageFaultsMinor,
|
|
137
|
+
current.pageFaultsMajor - baseline.pageFaultsMajor
|
|
138
|
+
};
|
|
133
139
|
return delta;
|
|
134
140
|
}
|
|
135
141
|
|
|
@@ -141,9 +147,13 @@ MemoryStats MemoryTracker::MeasureMemory(Func&& func)
|
|
|
141
147
|
func();
|
|
142
148
|
auto postStats = GetMemoryStats();
|
|
143
149
|
|
|
144
|
-
return {
|
|
145
|
-
postStats.
|
|
146
|
-
postStats.
|
|
150
|
+
return {
|
|
151
|
+
postStats.currentRss - preStats.currentRss,
|
|
152
|
+
postStats.peakRss - preStats.peakRss,
|
|
153
|
+
postStats.currentVss - preStats.currentVss,
|
|
154
|
+
postStats.pageFaultsMinor - preStats.pageFaultsMinor,
|
|
155
|
+
postStats.pageFaultsMajor - preStats.pageFaultsMajor
|
|
156
|
+
};
|
|
147
157
|
}
|
|
148
158
|
|
|
149
159
|
void MemoryTracker::Report(MemoryStats stats)
|
|
@@ -153,19 +163,16 @@ void MemoryTracker::Report(MemoryStats stats)
|
|
|
153
163
|
const double mb = kb * BYTES_PER_KB;
|
|
154
164
|
const double gb = mb * BYTES_PER_KB;
|
|
155
165
|
|
|
156
|
-
if (bytes > gb)
|
|
157
|
-
|
|
158
|
-
if (bytes >
|
|
159
|
-
return std::to_string(bytes / mb) + " MB";
|
|
160
|
-
if (bytes > kb)
|
|
161
|
-
return std::to_string(bytes / kb) + " KB";
|
|
166
|
+
if (bytes > gb) return std::to_string(bytes / gb) + " GB";
|
|
167
|
+
if (bytes > mb) return std::to_string(bytes / mb) + " MB";
|
|
168
|
+
if (bytes > kb) return std::to_string(bytes / kb) + " KB";
|
|
162
169
|
return std::to_string(bytes) + " B";
|
|
163
170
|
};
|
|
164
171
|
|
|
165
|
-
std::cout << "Current RSS: " << formatBytes(stats.currentRss) << "\n";
|
|
166
|
-
std::cout << "Peak RSS : " << formatBytes(stats.peakRss) << "\n";
|
|
167
|
-
std::cout << "VSS : " << formatBytes(stats.currentVss) << "\n";
|
|
168
|
-
std::cout << "FaultsMinor: " << stats.pageFaultsMinor << "\n";
|
|
169
|
-
std::cout << "FaultsMajor: " << stats.pageFaultsMajor << "\n";
|
|
172
|
+
std::cout << "Current RSS: " << formatBytes(stats.currentRss) << "\n" << std::endl;
|
|
173
|
+
std::cout << "Peak RSS : " << formatBytes(stats.peakRss) << "\n" << std::endl;
|
|
174
|
+
std::cout << "VSS : " << formatBytes(stats.currentVss) << "\n" << std::endl;
|
|
175
|
+
std::cout << "FaultsMinor: " << stats.pageFaultsMinor << "\n" << std::endl;
|
|
176
|
+
std::cout << "FaultsMajor: " << stats.pageFaultsMajor << "\n" << std::endl;
|
|
170
177
|
return;
|
|
171
178
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koalaui/libarkts",
|
|
3
3
|
"version": "1.7.10+devel",
|
|
4
|
-
"
|
|
4
|
+
"main": "./lib/libarkts.js",
|
|
5
5
|
"typesVersions": {
|
|
6
6
|
"*": {
|
|
7
7
|
"./compat/*": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"./plugins/build/src/**/*"
|
|
24
24
|
],
|
|
25
25
|
"config": {
|
|
26
|
-
"panda_sdk_path": "
|
|
26
|
+
"panda_sdk_path": "../incremental/tools/panda/node_modules/@panda/sdk",
|
|
27
27
|
"panda_sdk_version": "next"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
@@ -33,14 +33,16 @@
|
|
|
33
33
|
"commander": "10.0.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
+
"tslib": "^2.3.1",
|
|
36
37
|
"rollup": "^4.13.0",
|
|
37
38
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
38
39
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
39
40
|
"@rollup/plugin-terser": "^0.4.4",
|
|
40
41
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
42
|
+
"tsconfig-paths": "^4.2.0",
|
|
41
43
|
"rimraf": "^6.0.1",
|
|
42
44
|
"@koalaui/fast-arktsc": "1.7.10+devel",
|
|
43
|
-
"@idlizer/arktscgen": "2.1.10-arktscgen-
|
|
45
|
+
"@idlizer/arktscgen": "2.1.10-arktscgen-5",
|
|
44
46
|
"mocha": "^9.2.2",
|
|
45
47
|
"@koalaui/harness": "1.7.10+devel",
|
|
46
48
|
"@koalaui/ets-tsc": "4.9.5-r6",
|
|
@@ -51,7 +53,7 @@
|
|
|
51
53
|
"scripts": {
|
|
52
54
|
"clean": "rimraf generated build native/build* ./.rollup.cache tsconfig.tsbuildinfo lib",
|
|
53
55
|
"clean:plugins": "rimraf plugins/build",
|
|
54
|
-
"compile:koala:interop": "npm run --prefix
|
|
56
|
+
"compile:koala:interop": "npm run --prefix ../interop compile",
|
|
55
57
|
"compile:meson": "cd native && meson setup build && meson compile -C build",
|
|
56
58
|
"compile:meson:mingw": "cd native && meson setup --cross-file ./mingw.cross mingw_build && meson compile -C mingw_build",
|
|
57
59
|
"crosscompile:meson": "cd native && CXX=clang++ meson setup -D cross_compile=true build && CXX=clang++ meson compile -C build",
|
|
@@ -63,8 +65,8 @@
|
|
|
63
65
|
"compile:release": "npm run regenerate && npm run crosscompile:native && npm run compile:js",
|
|
64
66
|
"compile:js": "rm -rf lib/ && rollup -c rollup.lib.mjs && rollup -c rollup.es2panda.mjs",
|
|
65
67
|
"compile:plugins": "rollup -c ./rollup.printer-plugin.mjs",
|
|
66
|
-
"direct": "fast-arktsc --config arktsconfig.json --compiler
|
|
67
|
-
"simultaneous": "mkdir -p build/abc && bash
|
|
68
|
+
"direct": "fast-arktsc --config arktsconfig.json --compiler ../incremental/tools/panda/arkts/ui2abc --link-name ./build/abc/main.abc && ninja -f build/abc/build.ninja",
|
|
69
|
+
"simultaneous": "mkdir -p build/abc && bash ../incremental/tools/panda/arkts/ui2abc --simultaneous --arktsconfig arktsconfig.json --output ./build/abc/main.abc:./build/abc/library.abc plugins/input/main.ets:plugins/input/library.ets",
|
|
68
70
|
"run": "npm run compile && npm run compile:plugins && npm run simultaneous",
|
|
69
71
|
"run:current": "npm run compile:current && npm run compile:plugins && npm run simultaneous",
|
|
70
72
|
"run:memo": "npm run compile && npm run compile:plugins && npm run compile --prefix ../memo-plugin-ng && npm run memo",
|
|
@@ -74,11 +76,11 @@
|
|
|
74
76
|
"test": "npm run compile:native && npm run test:light",
|
|
75
77
|
"test:golden": "npm run compile:native && TEST_GOLDEN=1 npm run test:light",
|
|
76
78
|
"compile:playground": "cd playground && meson setup build && meson compile -C build",
|
|
77
|
-
"run:playground": "npm run compile:playground && mkdir -p build && ./playground/build/playground _ --extension ets --stdlib
|
|
78
|
-
"panda:sdk:clean": "cd
|
|
79
|
-
"panda:sdk:install": "cd
|
|
79
|
+
"run:playground": "npm run compile:playground && mkdir -p build && ./playground/build/playground _ --extension ets --stdlib ../incremental/tools/panda/node_modules/@panda/sdk/ets/stdlib --output build/playground.abc ./playground/src/main.ets",
|
|
80
|
+
"panda:sdk:clean": "cd ../incremental/tools/panda && rimraf node_modules",
|
|
81
|
+
"panda:sdk:install": "cd ../incremental/tools/panda && echo \"Installing panda sdk $npm_package_config_panda_sdk_version\" && PANDA_SDK_VERSION=$npm_package_config_panda_sdk_version npm run panda:sdk:install",
|
|
80
82
|
"panda:sdk:reinstall": "npm run panda:sdk:clean && npm run panda:sdk:install",
|
|
81
|
-
"regenerate:current": "rimraf -rf ./generated && npm run compile -C
|
|
83
|
+
"regenerate:current": "rimraf -rf ./generated && npm run compile -C ../../arktscgen && node ../../arktscgen --panda-sdk-path $npm_package_config_panda_sdk_path --output-dir ../ --options-file ./generator/options.json5 --no-initialize --debug",
|
|
82
84
|
"regenerate": "rimraf -rf ./generated && arktscgen --panda-sdk-path ${PANDA_SDK_PATH:=$npm_package_config_panda_sdk_path} --output-dir ../ --options-file ./generator/options.json5 --no-initialize",
|
|
83
85
|
"reinstall:regenerate": "npm run panda:sdk:reinstall && npm run regenerate && git diff --shortstat",
|
|
84
86
|
"format:src:ts": "npx prettier --config .prettierrc --write \"./src/**/*.ts\"",
|
|
@@ -58,37 +58,12 @@ export class Es2pandaNativeModule {
|
|
|
58
58
|
_DestroyConfig(peer: KNativePointer): void {
|
|
59
59
|
throw new Error('Not implemented');
|
|
60
60
|
}
|
|
61
|
-
_CreateContextFromString(config: KPtr, source: String, filename: String): KPtr {
|
|
62
|
-
throw new Error('Not implemented');
|
|
63
|
-
}
|
|
64
|
-
_CreateContextFromFile(config: KPtr, filename: String): KPtr {
|
|
65
|
-
throw new Error('Not implemented');
|
|
66
|
-
}
|
|
67
|
-
_CreateCacheContextFromFile(
|
|
68
|
-
config: KNativePointer,
|
|
69
|
-
sourceFileName: String,
|
|
70
|
-
globalContext: KNativePointer,
|
|
71
|
-
isExternal: KBoolean
|
|
72
|
-
): KNativePointer {
|
|
73
|
-
throw new Error('Not implemented');
|
|
74
|
-
}
|
|
75
61
|
_InsertGlobalStructInfo(context: KNativePointer, str: String): void {
|
|
76
62
|
throw new Error('Not implemented');
|
|
77
63
|
}
|
|
78
64
|
_HasGlobalStructInfo(context: KNativePointer, str: String): KBoolean {
|
|
79
65
|
throw new Error('Not implemented');
|
|
80
66
|
}
|
|
81
|
-
_CreateGlobalContext(
|
|
82
|
-
config: KNativePointer,
|
|
83
|
-
externalFileList: KStringArrayPtr,
|
|
84
|
-
fileNum: KUInt,
|
|
85
|
-
lspUsage: KBoolean
|
|
86
|
-
): KNativePointer {
|
|
87
|
-
throw new Error('Not implemented');
|
|
88
|
-
}
|
|
89
|
-
_DestroyGlobalContext(context: KNativePointer): void {
|
|
90
|
-
throw new Error('Not implemented');
|
|
91
|
-
}
|
|
92
67
|
_DestroyContext(context: KPtr): void {
|
|
93
68
|
throw new Error('Not implemented');
|
|
94
69
|
}
|
|
@@ -157,10 +132,10 @@ export class Es2pandaNativeModule {
|
|
|
157
132
|
_ETSParserGetImportPathManager(context: KNativePointer): KPtr {
|
|
158
133
|
throw new Error('Not implemented');
|
|
159
134
|
}
|
|
160
|
-
|
|
135
|
+
_ConfigGetOptions(config: KNativePointer): KNativePointer {
|
|
161
136
|
throw new Error('Not implemented');
|
|
162
137
|
}
|
|
163
|
-
|
|
138
|
+
_SourcePositionCol(context: KNativePointer, instance: KNativePointer): KUInt {
|
|
164
139
|
throw new Error('Not implemented');
|
|
165
140
|
}
|
|
166
141
|
_OptionsArkTsConfig(context: KNativePointer, options: KNativePointer): KNativePointer {
|
|
@@ -223,7 +198,13 @@ export class Es2pandaNativeModule {
|
|
|
223
198
|
): void {
|
|
224
199
|
throw new Error('Not implemented');
|
|
225
200
|
}
|
|
226
|
-
_FilterNodes(context: KNativePointer, root: KNativePointer, filters: KStringPtr): KNativePointer {
|
|
201
|
+
_FilterNodes(context: KNativePointer, root: KNativePointer, filters: KStringPtr, deeperAfterMatch: KBoolean): KNativePointer {
|
|
202
|
+
throw new Error('Not implemented');
|
|
203
|
+
}
|
|
204
|
+
_FilterNodes2(context: KNativePointer, root: KNativePointer, type: KInt): KNativePointer {
|
|
205
|
+
throw new Error('Not implemented');
|
|
206
|
+
}
|
|
207
|
+
_FilterNodes3(context: KNativePointer, root: KNativePointer, types: Int32Array, typesSize: KInt): KNativePointer {
|
|
227
208
|
throw new Error('Not implemented');
|
|
228
209
|
}
|
|
229
210
|
|
|
@@ -241,26 +222,6 @@ export class Es2pandaNativeModule {
|
|
|
241
222
|
): KNativePointer {
|
|
242
223
|
throw new Error('Not implemented');
|
|
243
224
|
}
|
|
244
|
-
_CreateDiagnosticInfo(
|
|
245
|
-
context: KNativePointer,
|
|
246
|
-
kind: KNativePointer,
|
|
247
|
-
args: string[],
|
|
248
|
-
argc: number,
|
|
249
|
-
pos: KNativePointer
|
|
250
|
-
): KNativePointer {
|
|
251
|
-
throw new Error('Not implemented');
|
|
252
|
-
}
|
|
253
|
-
_CreateSuggestionInfo(
|
|
254
|
-
context: KNativePointer,
|
|
255
|
-
kind: KNativePointer,
|
|
256
|
-
args: string[],
|
|
257
|
-
argc: number,
|
|
258
|
-
substitutionCode: string,
|
|
259
|
-
title: string,
|
|
260
|
-
range: KNativePointer
|
|
261
|
-
): KNativePointer {
|
|
262
|
-
throw new Error('Not implemented');
|
|
263
|
-
}
|
|
264
225
|
_LogDiagnostic(
|
|
265
226
|
context: KNativePointer,
|
|
266
227
|
kind: KNativePointer,
|
|
@@ -279,26 +240,12 @@ export class Es2pandaNativeModule {
|
|
|
279
240
|
_MemFinalize(): void {
|
|
280
241
|
throw new Error('Not implemented');
|
|
281
242
|
}
|
|
282
|
-
_ProgramCanSkipPhases(context: KNativePointer, program: KNativePointer):
|
|
283
|
-
throw new Error('Not implemented');
|
|
284
|
-
}
|
|
285
|
-
_GenerateTsDeclarationsFromContext(
|
|
286
|
-
config: KPtr,
|
|
287
|
-
outputDeclEts: String,
|
|
288
|
-
outputEts: String,
|
|
289
|
-
exportAll: KBoolean,
|
|
290
|
-
isolated: KBoolean,
|
|
291
|
-
recordFile: String,
|
|
292
|
-
genAnnotations: KBoolean
|
|
293
|
-
): KPtr {
|
|
243
|
+
_ProgramCanSkipPhases(context: KNativePointer, program: KNativePointer): KBoolean {
|
|
294
244
|
throw new Error('Not implemented');
|
|
295
245
|
}
|
|
296
246
|
_AstNodeProgram(context: KNativePointer, instance: KNativePointer): KNativePointer {
|
|
297
247
|
throw new Error('Not implemented');
|
|
298
248
|
}
|
|
299
|
-
_CreateContextGenerateAbcForExternalSourceFiles(config: KPtr, fileCount: KInt, filenames: string[]): KPtr {
|
|
300
|
-
throw new Error('Not implemented');
|
|
301
|
-
}
|
|
302
249
|
|
|
303
250
|
_GetCompilationMode(config: KNativePointer): KInt {
|
|
304
251
|
throw new Error('Not implemented');
|
|
@@ -37,13 +37,19 @@ export abstract class AbstractVisitor {
|
|
|
37
37
|
return result;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
process(node: AstNode, options?:
|
|
40
|
+
process(node: AstNode, options?: any): AstNode {
|
|
41
41
|
return this.visitor(node, options);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
init(): void {}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
reset(): void {
|
|
47
|
+
this.indentation = 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
abstract visitor(node: AstNode, options?: any): AstNode;
|
|
51
|
+
|
|
52
|
+
visitEachChild(node: AstNode, options?: any): AstNode {
|
|
47
53
|
return this.withIndentation((): AstNode => visitEachChild(node, (it): AstNode => this.visitor(it, options)));
|
|
48
54
|
}
|
|
49
55
|
}
|
|
@@ -77,9 +77,7 @@ export class ImportStorage {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
// Drop import statements generated by compiler in the beginning of the ETSModule
|
|
80
|
-
const module = this.program.
|
|
81
|
-
|
|
82
|
-
factory.updateETSModule(module, newStatements, module.ident, module.getNamespaceFlag(), module.program)
|
|
83
|
-
);
|
|
80
|
+
const module = this.program.getAstCasted()
|
|
81
|
+
module.setStatements(newStatements)
|
|
84
82
|
}
|
|
85
83
|
}
|
|
@@ -18,16 +18,24 @@ import { defaultFilter, listPrograms } from './plugins';
|
|
|
18
18
|
import { Program } from '../../generated';
|
|
19
19
|
|
|
20
20
|
export class ProgramProvider {
|
|
21
|
-
|
|
21
|
+
static programListCache: Map<string, Program[]> = new Map();
|
|
22
|
+
programListFromCache?: Program[];
|
|
22
23
|
seenPrograms: Set<KNativePointer> = new Set<KNativePointer>();
|
|
23
24
|
queue: Program[] = [];
|
|
24
25
|
|
|
25
26
|
constructor(
|
|
26
|
-
private mainProgram: Program,
|
|
27
|
-
private readonly
|
|
27
|
+
private readonly mainProgram: Program,
|
|
28
|
+
private readonly stableDeps: boolean = false,
|
|
29
|
+
private readonly filter: (name: string) => boolean = defaultFilter,
|
|
28
30
|
) {
|
|
29
31
|
this.seenPrograms.add(mainProgram.peer);
|
|
30
|
-
|
|
32
|
+
if (!stableDeps || !ProgramProvider.programListCache.has(mainProgram.absoluteName)) {
|
|
33
|
+
this.programListFromCache = [mainProgram]
|
|
34
|
+
ProgramProvider.programListCache.set(mainProgram.absoluteName, this.programListFromCache)
|
|
35
|
+
} else {
|
|
36
|
+
this.programListFromCache = ProgramProvider.programListCache.get(mainProgram.absoluteName)
|
|
37
|
+
}
|
|
38
|
+
this.queue = [...this.programListFromCache!]
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
updateQueue(): void {
|
|
@@ -35,13 +43,14 @@ export class ProgramProvider {
|
|
|
35
43
|
for (const program of listed) {
|
|
36
44
|
if (!this.seenPrograms.has(program.peer)) {
|
|
37
45
|
this.seenPrograms.add(program.peer);
|
|
46
|
+
this.programListFromCache?.push(program)
|
|
38
47
|
this.queue.push(program);
|
|
39
48
|
}
|
|
40
49
|
}
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
next(): Program | undefined {
|
|
44
|
-
if (this.queue.length === 0) {
|
|
53
|
+
if (this.queue.length === 0 && (!this.stableDeps || this.programListFromCache?.length == 1)) {
|
|
45
54
|
this.updateQueue();
|
|
46
55
|
if (this.queue.length === 0) {
|
|
47
56
|
// console.log("PROGRAMS:", this.seenPrograms.size)
|
|
@@ -22,12 +22,30 @@ import { NodeCache } from './node-cache';
|
|
|
22
22
|
|
|
23
23
|
export const nodeByType = new Map<Es2pandaAstNodeType, (peer: KNativePointer) => AstNode>([]);
|
|
24
24
|
|
|
25
|
+
// TODO: These node types are "specially mapped" in the compiler, they don't have C++ classes
|
|
26
|
+
// See AST_NODE_REINTERPRET_MAPPING in the compiler source
|
|
27
|
+
// Do we need managed wrappers for them? Need to investigate.
|
|
28
|
+
export function nodeTypeFilter(type: Es2pandaAstNodeType): Es2pandaAstNodeType {
|
|
29
|
+
switch (type) {
|
|
30
|
+
case Es2pandaAstNodeType.AST_NODE_TYPE_REST_ELEMENT:
|
|
31
|
+
return Es2pandaAstNodeType.AST_NODE_TYPE_SPREAD_ELEMENT
|
|
32
|
+
case Es2pandaAstNodeType.AST_NODE_TYPE_OBJECT_PATTERN:
|
|
33
|
+
return Es2pandaAstNodeType.AST_NODE_TYPE_OBJECT_EXPRESSION
|
|
34
|
+
case Es2pandaAstNodeType.AST_NODE_TYPE_ASSIGNMENT_PATTERN:
|
|
35
|
+
return Es2pandaAstNodeType.AST_NODE_TYPE_ASSIGNMENT_EXPRESSION
|
|
36
|
+
case Es2pandaAstNodeType.AST_NODE_TYPE_ARRAY_PATTERN:
|
|
37
|
+
return Es2pandaAstNodeType.AST_NODE_TYPE_ARRAY_EXPRESSION
|
|
38
|
+
}
|
|
39
|
+
return type
|
|
40
|
+
}
|
|
41
|
+
|
|
25
42
|
export function nodeFrom<T extends AstNode>(peer: KNativePointer, typeHint?: Es2pandaAstNodeType): T {
|
|
26
43
|
const fromCache = NodeCache.get<T>(peer);
|
|
27
44
|
if (fromCache) {
|
|
28
45
|
return fromCache;
|
|
29
46
|
}
|
|
30
|
-
|
|
47
|
+
|
|
48
|
+
const type = nodeTypeFilter(typeHint ?? global.generatedEs2panda._AstNodeTypeConst(global.context, peer))
|
|
31
49
|
const create = nodeByType.get(type) ?? throwError(`unknown node type: ${type}`);
|
|
32
50
|
return create(peer) as T;
|
|
33
51
|
}
|
|
@@ -32,7 +32,6 @@ export * from './peers/Context';
|
|
|
32
32
|
export { GlobalContext } from './peers/Context';
|
|
33
33
|
export * from './peers/ExternalSource';
|
|
34
34
|
export * from './peers/Options';
|
|
35
|
-
export * from './peers/DiagnosticKind';
|
|
36
35
|
export * from './node-utilities/ArkTsConfig';
|
|
37
36
|
export * from './node-utilities/Program';
|
|
38
37
|
export * from './peers/ImportPathManager';
|
|
@@ -16,12 +16,17 @@
|
|
|
16
16
|
import { KNativePointer } from '@koalaui/interop';
|
|
17
17
|
import { AstNode } from './peers/AstNode';
|
|
18
18
|
|
|
19
|
+
const useCache = false;
|
|
20
|
+
|
|
19
21
|
export class NodeCache {
|
|
20
22
|
private static cache = new Map<KNativePointer, AstNode>();
|
|
21
23
|
|
|
22
24
|
static cached<T extends AstNode>(pointer: KNativePointer, factory: (pointer: KNativePointer) => AstNode): T {
|
|
25
|
+
if (!useCache) {
|
|
26
|
+
return factory(pointer) as T;
|
|
27
|
+
}
|
|
23
28
|
const cached = NodeCache.cache.get(pointer);
|
|
24
|
-
if (cached
|
|
29
|
+
if (!!cached) {
|
|
25
30
|
return cached as T;
|
|
26
31
|
}
|
|
27
32
|
const node = factory(pointer);
|
|
@@ -34,10 +39,14 @@ export class NodeCache {
|
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
public static addToCache(pointer: KNativePointer, node: AstNode): void {
|
|
37
|
-
|
|
42
|
+
if (useCache) {
|
|
43
|
+
NodeCache.cache.set(pointer, node);
|
|
44
|
+
}
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
public static clear(): void {
|
|
41
|
-
|
|
48
|
+
if (useCache) {
|
|
49
|
+
NodeCache.cache.clear();
|
|
50
|
+
}
|
|
42
51
|
}
|
|
43
52
|
}
|
|
@@ -41,7 +41,7 @@ export function updateObjectExpression(
|
|
|
41
41
|
): ObjectExpression {
|
|
42
42
|
if (
|
|
43
43
|
isSameNativeObject(properties, original.properties) &&
|
|
44
|
-
preferredReturnType
|
|
44
|
+
preferredReturnType === original.getPreferredTypePointer()
|
|
45
45
|
) {
|
|
46
46
|
return original;
|
|
47
47
|
}
|
|
@@ -83,8 +83,8 @@ export function updateScriptFunction(
|
|
|
83
83
|
isSameNativeObject(dataflags, original.modifierFlags) &&
|
|
84
84
|
isSameNativeObject(ident, original.id) &&
|
|
85
85
|
isSameNativeObject(annotations, original.annotations) &&
|
|
86
|
-
signaturePointer
|
|
87
|
-
preferredReturnTypePointer
|
|
86
|
+
signaturePointer === original.getSignaturePointer() &&
|
|
87
|
+
preferredReturnTypePointer === original.getPreferredReturnTypePointer()
|
|
88
88
|
) {
|
|
89
89
|
return original;
|
|
90
90
|
}
|
|
@@ -121,7 +121,6 @@ export function inplaceUpdateScriptFunction(
|
|
|
121
121
|
preferredReturnTypePointer?: KNativePointer
|
|
122
122
|
) {
|
|
123
123
|
if (
|
|
124
|
-
!isSameNativeObject(typeParams, original.typeParams) ||
|
|
125
124
|
!isSameNativeObject(hasReceiver, original.hasReceiver) ||
|
|
126
125
|
!isSameNativeObject(datafuncFlags, original.flags)
|
|
127
126
|
) {
|
|
@@ -145,9 +144,10 @@ export function inplaceUpdateScriptFunction(
|
|
|
145
144
|
}
|
|
146
145
|
original.setBody(databody);
|
|
147
146
|
original.setParams(params);
|
|
147
|
+
original.setTypeParams(typeParams);
|
|
148
148
|
original.setReturnTypeAnnotation(returnTypeAnnotation);
|
|
149
149
|
original.modifierFlags = dataflags;
|
|
150
|
-
|
|
150
|
+
original.setIdent(ident);
|
|
151
151
|
if (annotations) original.setAnnotations(annotations);
|
|
152
152
|
if (signaturePointer) original.setSignaturePointer(signaturePointer);
|
|
153
153
|
if (preferredReturnTypePointer) original.setPreferredReturnTypePointer(preferredReturnTypePointer);
|
|
@@ -97,22 +97,6 @@ export abstract class AstNode extends ArktsObject {
|
|
|
97
97
|
return unpackString(global.es2panda._AstNodeDumpModifiers(global.context, this.peer));
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
// public clone(): this {
|
|
101
|
-
// return unpackNonNullableNode(global.generatedEs2panda._AstNodeClone(global.context, this.peer, this.parent.peer));
|
|
102
|
-
// }
|
|
103
|
-
|
|
104
|
-
// public get parent(): AstNode {
|
|
105
|
-
// const parent = global.generatedEs2panda._AstNodeParent(global.context, this.peer)
|
|
106
|
-
// if (parent === nullptr) {
|
|
107
|
-
// throwError(`no parent`)
|
|
108
|
-
// }
|
|
109
|
-
// return unpackNonNullableNode(parent)
|
|
110
|
-
// }
|
|
111
|
-
|
|
112
|
-
// public set parent(node: AstNode) {
|
|
113
|
-
// global.generatedEs2panda._AstNodeSetParent(global.context, this.peer, node.peer)
|
|
114
|
-
// }
|
|
115
|
-
|
|
116
100
|
public clone(): this {
|
|
117
101
|
const clonedNode = unpackNonNullableNode(
|
|
118
102
|
global.generatedEs2panda._AstNodeClone(global.context, this.peer, this.parent?.peer ?? nullptr)
|
|
@@ -32,7 +32,7 @@ export class Context extends ArktsObject {
|
|
|
32
32
|
throw new Error(`Config not initialized`);
|
|
33
33
|
}
|
|
34
34
|
return new Context(
|
|
35
|
-
global.
|
|
35
|
+
global.generatedEs2panda._CreateContextFromString(global.config, passString(source), passString(global.filePath))
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -44,17 +44,18 @@ export class Context extends ArktsObject {
|
|
|
44
44
|
isExternal: KBoolean
|
|
45
45
|
): Context {
|
|
46
46
|
return new Context(
|
|
47
|
-
global.
|
|
47
|
+
global.generatedEs2panda._CreateCacheContextFromFile(configPtr, passString(fileName), globalContextPtr, isExternal)
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
static createFromFile(filePath: string): Context {
|
|
52
|
-
return new Context(global.
|
|
52
|
+
return new Context(global.generatedEs2panda._CreateContextFromStringWithHistory(global.config, passString(filePath), passString(filePath)));
|
|
53
|
+
return new Context(global.generatedEs2panda._CreateContextFromFile(global.config, passString(filePath)));
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
static createCacheFromFile(filePath: string, config: Config, globalContext: GlobalContext, isExternal: boolean) {
|
|
56
57
|
return new Context(
|
|
57
|
-
global.
|
|
58
|
+
global.generatedEs2panda._CreateCacheContextFromFile(
|
|
58
59
|
config.peer,
|
|
59
60
|
passString(filePath),
|
|
60
61
|
globalContext.peer,
|
|
@@ -68,7 +69,7 @@ export class Context extends ArktsObject {
|
|
|
68
69
|
throwError(`Config not initialized`);
|
|
69
70
|
}
|
|
70
71
|
return new Context(
|
|
71
|
-
global.
|
|
72
|
+
global.generatedEs2panda._CreateContextGenerateAbcForExternalSourceFiles(
|
|
72
73
|
global.config,
|
|
73
74
|
filenames.length,
|
|
74
75
|
passStringArray(filenames)
|
|
@@ -77,7 +78,7 @@ export class Context extends ArktsObject {
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
destroy() {
|
|
80
|
-
if (this.peer
|
|
81
|
+
if (this.peer !== nullptr) {
|
|
81
82
|
global.es2panda._DestroyContext(this.peer);
|
|
82
83
|
this.peer = nullptr;
|
|
83
84
|
}
|
|
@@ -101,7 +102,7 @@ export class Context extends ArktsObject {
|
|
|
101
102
|
export class GlobalContext extends ArktsObject {
|
|
102
103
|
static create(config: Config, externalFileList: string[]): GlobalContext {
|
|
103
104
|
return new GlobalContext(
|
|
104
|
-
global.
|
|
105
|
+
global.generatedEs2panda._CreateGlobalContext(
|
|
105
106
|
config.peer,
|
|
106
107
|
passStringArray(externalFileList),
|
|
107
108
|
externalFileList.length,
|
|
@@ -115,8 +116,8 @@ export class GlobalContext extends ArktsObject {
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
destroy() {
|
|
118
|
-
if (this.peer
|
|
119
|
-
global.
|
|
119
|
+
if (this.peer !== nullptr) {
|
|
120
|
+
global.generatedEs2panda._DestroyGlobalContext(this.peer);
|
|
120
121
|
this.peer = nullptr;
|
|
121
122
|
}
|
|
122
123
|
}
|