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 _entryFile?: File;
private reports: Report[] = []; private reports: Report[] = [];
private maxSeverity: number = severityCode.none;
public fileHasChildWithIdent(file: File, childIdent: string): boolean { public fileHasChildWithIdent(file: File, childIdent: string): boolean {
return this.files.get(file)! return this.files.get(file)!
@ -108,9 +109,16 @@ export class Ctx {
public report(rep: Report) { public report(rep: Report) {
this.reports.push(rep); this.reports.push(rep);
if (this.maxSeverity < severityCode[rep.severity]) {
this.maxSeverity = severityCode[rep.severity];
}
this.reportImmediately(rep); this.reportImmediately(rep);
} }
public errorOccured(): boolean {
return this.maxSeverity >= severityCode.error;
}
public enableReportImmediately = false; public enableReportImmediately = false;
public enableStacktrace = false; public enableStacktrace = false;
private reportImmediately(rep: Report) { 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 = { export type FileInfo = {
ident: string; ident: string;
absPath: string; absPath: string;

View File

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