diff --git a/slige/compiler/common/ctx.ts b/slige/compiler/common/ctx.ts index 97e4511..efc3229 100644 --- a/slige/compiler/common/ctx.ts +++ b/slige/compiler/common/ctx.ts @@ -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; diff --git a/slige/compiler/main.ts b/slige/compiler/main.ts index ab36a1c..765a2de 100644 --- a/slige/compiler/main.ts +++ b/slige/compiler/main.ts @@ -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()); }