@shapeshift-labs/frontier-lang-compiler 0.2.0 → 0.2.2
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/bench/smoke.mjs +25 -0
- package/benchmarks/package-bench.mjs +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +51 -2
- package/package.json +13 -7
package/bench/smoke.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { performance } from 'node:perf_hooks';
|
|
2
|
+
import { compileFrontierSource } from '../dist/index.js';
|
|
3
|
+
|
|
4
|
+
const source = `
|
|
5
|
+
module Bench @id("mod_bench")
|
|
6
|
+
type TodoInput @id("type_input") {
|
|
7
|
+
title: Text
|
|
8
|
+
}
|
|
9
|
+
entity Todo @id("ent_todo") {
|
|
10
|
+
title @id("field_title"): Text
|
|
11
|
+
}
|
|
12
|
+
action addTodo @id("action_add") {
|
|
13
|
+
input TodoInput
|
|
14
|
+
writes field_title
|
|
15
|
+
returns Patch
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
const targets = ['typescript', 'javascript', 'rust', 'python', 'c'];
|
|
20
|
+
const start = performance.now();
|
|
21
|
+
let bytes = 0;
|
|
22
|
+
for (let index = 0; index < 250; index += 1) {
|
|
23
|
+
bytes += compileFrontierSource(source, { target: targets[index % targets.length] }).output.length;
|
|
24
|
+
}
|
|
25
|
+
console.log(JSON.stringify({ compiles: 250, bytes, durationMs: Number((performance.now() - start).toFixed(2)) }));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '../bench/smoke.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,14 @@ import type {
|
|
|
4
4
|
CompileTarget,
|
|
5
5
|
EvidenceRecord,
|
|
6
6
|
FrontierLangDocument,
|
|
7
|
+
FrontierUniversalAstEnvelope,
|
|
7
8
|
FrontierSourceLanguage,
|
|
8
9
|
LanguageImportResult,
|
|
9
10
|
NativeAstLossRecord,
|
|
10
11
|
NativeAstNode,
|
|
11
12
|
NativeAstRecord,
|
|
12
13
|
NativeSourceNode,
|
|
14
|
+
SemanticIndexRecord,
|
|
13
15
|
SemanticNode,
|
|
14
16
|
SemanticPatchBundle
|
|
15
17
|
} from '@shapeshift-labs/frontier-lang-kernel';
|
|
@@ -97,11 +99,16 @@ export interface ImportNativeSourceOptions {
|
|
|
97
99
|
readonly patchId?: string;
|
|
98
100
|
readonly author?: string;
|
|
99
101
|
readonly target?: CompileTarget;
|
|
102
|
+
readonly semanticIndex?: SemanticIndexRecord;
|
|
103
|
+
readonly universalAstId?: string;
|
|
104
|
+
readonly universalAstMetadata?: Record<string, unknown>;
|
|
100
105
|
readonly metadata?: Record<string, unknown>;
|
|
101
106
|
}
|
|
102
107
|
|
|
103
108
|
export type NativeSourceImportResult = LanguageImportResult & {
|
|
104
109
|
readonly nativeSource: NativeSourceNode;
|
|
110
|
+
readonly semanticIndex?: SemanticIndexRecord;
|
|
111
|
+
readonly universalAst: FrontierUniversalAstEnvelope;
|
|
105
112
|
};
|
|
106
113
|
|
|
107
114
|
export declare const FrontierCompileTargets: readonly FrontierCompileTarget[];
|
|
@@ -112,4 +119,12 @@ export declare function projectFrontierAst(document: FrontierLangDocument, targe
|
|
|
112
119
|
export declare function renderTargetAst(ast: FrontierTargetAst, target?: FrontierCompileOptions['target']): string;
|
|
113
120
|
export declare function resolveCapabilityAdapters(document: FrontierLangDocument, target?: FrontierCompileOptions['target'], options?: { readonly platform?: string }): readonly CapabilityResolution[];
|
|
114
121
|
export declare function importNativeSource(input: ImportNativeSourceOptions): NativeSourceImportResult;
|
|
122
|
+
export declare function createUniversalAstFromDocument(document: FrontierLangDocument, input?: {
|
|
123
|
+
readonly id?: string;
|
|
124
|
+
readonly semanticIndex?: SemanticIndexRecord;
|
|
125
|
+
readonly evidence?: readonly EvidenceRecord[];
|
|
126
|
+
readonly metadata?: Record<string, unknown>;
|
|
127
|
+
}): FrontierUniversalAstEnvelope;
|
|
128
|
+
export declare function readUniversalAstJson(source: string): FrontierUniversalAstEnvelope;
|
|
129
|
+
export declare function writeUniversalAstJson(envelope: FrontierUniversalAstEnvelope): string;
|
|
115
130
|
export declare function emitForTarget(document: FrontierLangDocument, target?: FrontierCompileOptions['target'], options?: FrontierCompileEmitOptions): string;
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,12 @@ import {
|
|
|
3
3
|
createImportResult,
|
|
4
4
|
createNativeAstRecord,
|
|
5
5
|
createPatch,
|
|
6
|
+
createUniversalAstEnvelope,
|
|
6
7
|
hashDocumentBase,
|
|
7
8
|
hashSemanticValue,
|
|
8
|
-
nativeSourceNode
|
|
9
|
+
nativeSourceNode,
|
|
10
|
+
stableUniversalAstJson,
|
|
11
|
+
validateUniversalAstEnvelope
|
|
9
12
|
} from '@shapeshift-labs/frontier-lang-kernel';
|
|
10
13
|
import { parseFrontierFile, parseFrontierSource } from '@shapeshift-labs/frontier-lang-parser';
|
|
11
14
|
import { checkDocument } from '@shapeshift-labs/frontier-lang-checker';
|
|
@@ -202,6 +205,21 @@ export function importNativeSource(input) {
|
|
|
202
205
|
semanticStatus: input.semanticStatus ?? (semanticNodes.length ? 'mapped' : 'native-only')
|
|
203
206
|
}
|
|
204
207
|
}];
|
|
208
|
+
const semanticIndex = input.semanticIndex;
|
|
209
|
+
const universalAst = createUniversalAstEnvelope({
|
|
210
|
+
id: input.universalAstId ?? `universal_ast_${importIdPart}`,
|
|
211
|
+
document,
|
|
212
|
+
nativeSources: [nativeSource],
|
|
213
|
+
semanticIndex,
|
|
214
|
+
losses,
|
|
215
|
+
evidence,
|
|
216
|
+
metadata: {
|
|
217
|
+
sourceLanguage: language,
|
|
218
|
+
sourcePath,
|
|
219
|
+
semanticStatus: input.semanticStatus ?? (semanticNodes.length ? 'mapped' : 'native-only'),
|
|
220
|
+
...input.universalAstMetadata
|
|
221
|
+
}
|
|
222
|
+
});
|
|
205
223
|
const patch = input.patch ?? createPatch({
|
|
206
224
|
id: input.patchId ?? `patch_${importIdPart}_import`,
|
|
207
225
|
author: input.author ?? '@shapeshift-labs/frontier-lang-compiler/importNativeSource',
|
|
@@ -212,7 +230,7 @@ export function importNativeSource(input) {
|
|
|
212
230
|
touches: [{ id: node.id, access: node.kind === 'nativeSource' ? 'evidence' : 'schema' }]
|
|
213
231
|
})),
|
|
214
232
|
evidence,
|
|
215
|
-
metadata: { sourceLanguage: language, sourcePath }
|
|
233
|
+
metadata: { sourceLanguage: language, sourcePath, semanticIndexId: semanticIndex?.id, universalAstId: universalAst.id }
|
|
216
234
|
});
|
|
217
235
|
return {
|
|
218
236
|
...createImportResult({
|
|
@@ -222,10 +240,14 @@ export function importNativeSource(input) {
|
|
|
222
240
|
document,
|
|
223
241
|
patch,
|
|
224
242
|
nativeAst,
|
|
243
|
+
semanticIndex,
|
|
244
|
+
universalAst,
|
|
225
245
|
losses,
|
|
226
246
|
evidence,
|
|
227
247
|
metadata: {
|
|
228
248
|
nativeSourceId: nativeSource.id,
|
|
249
|
+
semanticIndexId: semanticIndex?.id,
|
|
250
|
+
universalAstId: universalAst.id,
|
|
229
251
|
semanticStatus: input.semanticStatus ?? (semanticNodes.length ? 'mapped' : 'native-only'),
|
|
230
252
|
mappings: input.mappings ?? [],
|
|
231
253
|
...input.metadata
|
|
@@ -235,6 +257,33 @@ export function importNativeSource(input) {
|
|
|
235
257
|
};
|
|
236
258
|
}
|
|
237
259
|
|
|
260
|
+
export function createUniversalAstFromDocument(document, input = {}) {
|
|
261
|
+
return createUniversalAstEnvelope({
|
|
262
|
+
id: input.id ?? `universal_ast_${idFragment(document.id)}`,
|
|
263
|
+
document,
|
|
264
|
+
semanticIndex: input.semanticIndex,
|
|
265
|
+
evidence: input.evidence ?? [],
|
|
266
|
+
metadata: input.metadata
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export function readUniversalAstJson(source) {
|
|
271
|
+
const envelope = JSON.parse(source);
|
|
272
|
+
const issues = validateUniversalAstEnvelope(envelope);
|
|
273
|
+
if (issues.length > 0) {
|
|
274
|
+
throw new Error(`Invalid Frontier universal AST JSON: ${issues.join('; ')}`);
|
|
275
|
+
}
|
|
276
|
+
return envelope;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function writeUniversalAstJson(envelope) {
|
|
280
|
+
const issues = validateUniversalAstEnvelope(envelope);
|
|
281
|
+
if (issues.length > 0) {
|
|
282
|
+
throw new Error(`Invalid Frontier universal AST envelope: ${issues.join('; ')}`);
|
|
283
|
+
}
|
|
284
|
+
return stableUniversalAstJson(envelope);
|
|
285
|
+
}
|
|
286
|
+
|
|
238
287
|
export function emitForTarget(document, target = 'typescript', options = {}) {
|
|
239
288
|
return renderTargetAst(projectFrontierAst(document, target, options), target);
|
|
240
289
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshift-labs/frontier-lang-compiler",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Compiler facade for Frontier Lang source documents and language projection adapters.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,11 +16,14 @@
|
|
|
16
16
|
"dist",
|
|
17
17
|
"examples",
|
|
18
18
|
"README.md",
|
|
19
|
-
"LICENSE"
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"bench",
|
|
21
|
+
"benchmarks/package-bench.mjs"
|
|
20
22
|
],
|
|
21
23
|
"scripts": {
|
|
22
24
|
"build": "node scripts/build.mjs",
|
|
23
25
|
"test": "npm run build && node test/smoke.mjs",
|
|
26
|
+
"typecheck": "node ./node_modules/typescript/bin/tsc --noEmit -p test/tsconfig.json",
|
|
24
27
|
"fuzz": "npm run build && node fuzz/smoke.mjs",
|
|
25
28
|
"bench": "npm run build && node bench/smoke.mjs",
|
|
26
29
|
"prepare": "npm run build",
|
|
@@ -53,13 +56,16 @@
|
|
|
53
56
|
"access": "public"
|
|
54
57
|
},
|
|
55
58
|
"dependencies": {
|
|
56
|
-
"@shapeshift-labs/frontier-lang-
|
|
57
|
-
"@shapeshift-labs/frontier-lang-parser": "0.3.0",
|
|
59
|
+
"@shapeshift-labs/frontier-lang-c": "0.2.0",
|
|
58
60
|
"@shapeshift-labs/frontier-lang-checker": "0.3.0",
|
|
59
|
-
"@shapeshift-labs/frontier-lang-typescript": "0.3.0",
|
|
60
61
|
"@shapeshift-labs/frontier-lang-javascript": "0.2.0",
|
|
61
|
-
"@shapeshift-labs/frontier-lang-
|
|
62
|
+
"@shapeshift-labs/frontier-lang-kernel": "0.3.1",
|
|
63
|
+
"@shapeshift-labs/frontier-lang-parser": "0.3.0",
|
|
62
64
|
"@shapeshift-labs/frontier-lang-python": "0.2.0",
|
|
63
|
-
"@shapeshift-labs/frontier-lang-
|
|
65
|
+
"@shapeshift-labs/frontier-lang-rust": "0.2.0",
|
|
66
|
+
"@shapeshift-labs/frontier-lang-typescript": "0.3.0"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"typescript": "^5.9.3"
|
|
64
70
|
}
|
|
65
71
|
}
|