MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / compile

Function compile

scripts/fungrim/compile-properties.ts:62–109  ·  view source on GitHub ↗
(source: { generator?: string; entries: SourceEntry[] })

Source from the content-addressed store, hash-verified

60}
61
62function compile(source: { generator?: string; entries: SourceEntry[] }) {
63 const operators: Record<string, CompiledRecord[]> = {};
64 const byProperty: Record<string, number> = {};
65 let dropped = 0;
66
67 for (const e of source.entries) {
68 if (typeof e.operator !== 'string' || e.operator.length === 0) {
69 dropped += 1;
70 continue;
71 }
72 byProperty[e.property] = (byProperty[e.property] ?? 0) + 1;
73 const rec: CompiledRecord = {
74 id: e.id,
75 property: e.property,
76 var: e.var ?? null,
77 argIndex: argIndexOf(e.expr, e.var ?? null),
78 expr: e.expr ?? null,
79 domain: e.domain ?? null,
80 point: e.point ?? null,
81 condition: e.condition ?? null,
82 value: e.value ?? null,
83 assumptions: e.assumptions ?? null,
84 };
85 (operators[e.operator] ??= []).push(rec);
86 }
87
88 // Deterministic ordering.
89 const sortedOps: Record<string, CompiledRecord[]> = {};
90 for (const op of Object.keys(operators).sort())
91 sortedOps[op] = operators[op].sort((a, b) =>
92 a.id < b.id ? -1 : a.id > b.id ? 1 : 0
93 );
94
95 const manifest = {
96 schemaVersion: 1,
97 generator: 'scripts/fungrim/compile-properties.ts',
98 source: 'data/fungrim/properties.json',
99 translator: source.generator ?? null,
100 counts: {
101 entries: source.entries.length - dropped,
102 dropped,
103 operators: Object.keys(sortedOps).length,
104 byProperty,
105 },
106 };
107
108 return { manifest, operators: sortedOps };
109}
110
111function main(): void {
112 const check = process.argv.includes('--check');

Callers 1

mainFunction · 0.70

Calls 2

argIndexOfFunction · 0.85
keysMethod · 0.65

Tested by

no test coverage detected