Some checks failed
Deploy Landing Page to Storj / deploy (push) Failing after 2s
- Add speckl-compile.speckdl — compiler formally specified in SpeckDL - Generator: multi-enum detection, value→enum mapping, trailing comma cleanup - Emit blocks collapsed to single-line (parser limitation) - Generated artifacts: provenance, BOMs, WAT, TypeScript (2 known bugs → engineering#8)
153 lines
5.5 KiB
TypeScript
153 lines
5.5 KiB
TypeScript
// Auto-generated by speckl-compile from SpecklCompiler
|
|
// DO NOT EDIT MANUALLY — regenerate from .speckdl source
|
|
|
|
export const SpecklCompilerCompilerPhase = {
|
|
BOMsGenerated: 'bomsgenerated',
|
|
Idle: 'idle',
|
|
Parsed: 'parsed',
|
|
Parsing: 'parsing',
|
|
ProvenanceGenerated: 'provenancegenerated',
|
|
TypeScriptGenerated: 'typescriptgenerated',
|
|
WASMGenerated: 'wasmgenerated',
|
|
} as const;
|
|
export type SpecklCompilerCompilerPhase = typeof SpecklCompilerCompilerPhase[keyof typeof SpecklCompilerCompilerPhase];
|
|
|
|
export const SpecklCompilerArtifactKind = {
|
|
CycloneDX: 'cyclonedx',
|
|
Done: 'done',
|
|
Provenance: 'provenance',
|
|
SPDX: 'spdx',
|
|
TypeScript: 'typescript',
|
|
WebAssembly: 'webassembly',
|
|
} as const;
|
|
export type SpecklCompilerArtifactKind = typeof SpecklCompilerArtifactKind[keyof typeof SpecklCompilerArtifactKind];
|
|
|
|
export interface CompilationStarted {
|
|
source: string;
|
|
output: string;
|
|
at: string;
|
|
}
|
|
|
|
export interface PhaseCompleted {
|
|
phase: SpecklCompilerCompilerPhase;
|
|
durationMs: number;
|
|
at: string;
|
|
}
|
|
|
|
export interface ArtifactGenerated {
|
|
kind: SpecklCompilerArtifactKind;
|
|
path: string;
|
|
bytes: number;
|
|
at: string;
|
|
}
|
|
|
|
export interface ErrorEmitted {
|
|
phase: SpecklCompilerCompilerPhase;
|
|
message: string;
|
|
line: number;
|
|
col: number;
|
|
at: string;
|
|
}
|
|
|
|
|
|
export class SpecklCompilerMachine {
|
|
phase: SpecklCompilerCompilerPhase;
|
|
sourcePath: String;
|
|
outputDir: String;
|
|
ast: any;
|
|
errors: String[];
|
|
artifacts: any;
|
|
decisionLog: CompilationStarted[] = [];
|
|
|
|
constructor() {
|
|
this.phase = SpecklCompilerCompilerPhase.Idle;
|
|
this.sourcePath = "";
|
|
this.outputDir = "./out";
|
|
this.ast = {};
|
|
this.errors = [];
|
|
this.artifacts = {};
|
|
}
|
|
|
|
compile(sourcePath: string, outputDir: string) {
|
|
if (!(this.phase === SpecklCompilerCompilerPhase.Idle)) throw new Error('Guard failed: this.phase === SpecklCompilerCompilerPhase.Idle');
|
|
if (!(sourcePath.length > 0)) throw new Error('Guard failed: sourcePath.length > 0');
|
|
this.decisionLog.push({
|
|
source: sourcePath,
|
|
output: outputDir,
|
|
at: Date.now()
|
|
} as CompilationStarted);
|
|
}
|
|
|
|
parse() {
|
|
if (!(this.phase === SpecklCompilerCompilerPhase.Parsing)) throw new Error('Guard failed: this.phase === SpecklCompilerCompilerPhase.Parsing');
|
|
if (!(this.sourcePath.length > 0)) throw new Error('Guard failed: this.sourcePath.length > 0');
|
|
this.decisionLog.push({
|
|
phase: SpecklCompilerCompilerPhase.Parsing,
|
|
durationMs: 0,
|
|
at: Date.now()
|
|
} as PhaseCompleted);
|
|
}
|
|
|
|
generateProvenance() {
|
|
if (!(this.phase === SpecklCompilerCompilerPhase.Parsed || this.phase === SpecklCompilerCompilerPhase.TypeScriptGenerated || this.phase === SpecklCompilerCompilerPhase.WASMGenerated)) throw new Error('Guard failed: this.phase === SpecklCompilerCompilerPhase.Parsed || this.phase === SpecklCompilerCompilerPhase.TypeScriptGenerated || this.phase === SpecklCompilerCompilerPhase.WASMGenerated');
|
|
this.decisionLog.push({
|
|
kind: SpecklCompilerCompilerPhase.Provenance,
|
|
path: join(this.outputDir,
|
|
bytes: 0,
|
|
at: Date.now()
|
|
} as ArtifactGenerated);
|
|
}
|
|
|
|
generateBOMs() {
|
|
if (!(this.phase === SpecklCompilerCompilerPhase.ProvenanceGenerated || this.phase === SpecklCompilerCompilerPhase.Parsed)) throw new Error('Guard failed: this.phase === SpecklCompilerCompilerPhase.ProvenanceGenerated || this.phase === SpecklCompilerCompilerPhase.Parsed');
|
|
this.decisionLog.push({
|
|
kind: SpecklCompilerCompilerPhase.CycloneDX,
|
|
path: join(this.outputDir,
|
|
bytes: 0,
|
|
at: Date.now()
|
|
} as ArtifactGenerated);
|
|
this.decisionLog.push({
|
|
kind: SpecklCompilerCompilerPhase.SPDX,
|
|
path: join(this.outputDir,
|
|
bytes: 0,
|
|
at: Date.now()
|
|
} as ArtifactGenerated);
|
|
}
|
|
|
|
generateTypeScript() {
|
|
if (!(this.phase === SpecklCompilerCompilerPhase.BOMsGenerated || this.phase === SpecklCompilerCompilerPhase.Parsed)) throw new Error('Guard failed: this.phase === SpecklCompilerCompilerPhase.BOMsGenerated || this.phase === SpecklCompilerCompilerPhase.Parsed');
|
|
this.decisionLog.push({
|
|
kind: SpecklCompilerCompilerPhase.TypeScript,
|
|
path: join(this.outputDir,
|
|
bytes: 0,
|
|
at: Date.now()
|
|
} as ArtifactGenerated);
|
|
}
|
|
|
|
generateWASM() {
|
|
if (!(this.phase === SpecklCompilerCompilerPhase.TypeScriptGenerated || this.phase === SpecklCompilerCompilerPhase.BOMsGenerated || this.phase === SpecklCompilerCompilerPhase.Parsed)) throw new Error('Guard failed: this.phase === SpecklCompilerCompilerPhase.TypeScriptGenerated || this.phase === SpecklCompilerCompilerPhase.BOMsGenerated || this.phase === SpecklCompilerCompilerPhase.Parsed');
|
|
this.decisionLog.push({
|
|
kind: SpecklCompilerCompilerPhase.WebAssembly,
|
|
path: join(this.outputDir,
|
|
bytes: 0,
|
|
at: Date.now()
|
|
} as ArtifactGenerated);
|
|
}
|
|
|
|
report() {
|
|
if (!(this.phase === SpecklCompilerCompilerPhase.ProvenanceGenerated || this.phase === SpecklCompilerCompilerPhase.BOMsGenerated || this.phase === SpecklCompilerCompilerPhase.TypeScriptGenerated || this.phase === SpecklCompilerCompilerPhase.WASMGenerated)) throw new Error('Guard failed: this.phase === SpecklCompilerCompilerPhase.ProvenanceGenerated || this.phase === SpecklCompilerCompilerPhase.BOMsGenerated || this.phase === SpecklCompilerCompilerPhase.TypeScriptGenerated || this.phase === SpecklCompilerCompilerPhase.WASMGenerated');
|
|
this.decisionLog.push({
|
|
phase: SpecklCompilerCompilerPhase.Done,
|
|
durationMs: 0,
|
|
at: Date.now()
|
|
} as PhaseCompleted);
|
|
}
|
|
|
|
reset() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|