compiler: stop on errors

This commit is contained in:
SimonFJ20 2025-02-10 17:53:47 +01:00
parent 21c737d06a
commit aa35b6f35d
2 changed files with 24 additions and 0 deletions

View File

@ -15,6 +15,7 @@ export class Ctx {
private _entryFile?: File;
private reports: Report[] = [];
private maxSeverity: number = severityCode.none;
public fileHasChildWithIdent(file: File, childIdent: string): boolean {
return this.files.get(file)!
@ -108,9 +109,16 @@ export class Ctx {
public report(rep: Report) {
this.reports.push(rep);
if (this.maxSeverity < severityCode[rep.severity]) {
this.maxSeverity = severityCode[rep.severity];
}
this.reportImmediately(rep);
}
public errorOccured(): boolean {
return this.maxSeverity >= severityCode.error;
}
public enableReportImmediately = false;
public enableStacktrace = false;
private reportImmediately(rep: Report) {
@ -130,6 +138,14 @@ export class Ctx {
}
}
const severityCode = {
"none": 0,
"info": 1,
"warning": 2,
"error": 3,
"fatal": 4,
} as const;
export type FileInfo = {
ident: string;
absPath: string;

View File

@ -49,6 +49,10 @@ export class PackCompiler {
new HirStringifyer(this.ctx, checker)
.file(entryFileAst),
);
if (this.ctx.errorOccured()) {
console.error("error(s) occurred.");
Deno.exit(1);
}
const astLowerer = new AstLowerer(
this.ctx,
resols,
@ -56,6 +60,10 @@ export class PackCompiler {
entryFileAst,
);
astLowerer.lower();
if (this.ctx.errorOccured()) {
console.error("error(s) occurred. stopping...");
Deno.exit(1);
}
console.log("=== MIR ===\n" + astLowerer.mirString());
}