mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-18 19:36:32 +00:00
32 lines
923 B
TypeScript
32 lines
923 B
TypeScript
import { Checker } from "./checker.ts";
|
|
import { Reporter } from "./info.ts";
|
|
import { Lexer } from "./lexer.ts";
|
|
import { Lowerer } from "./lowerer.ts";
|
|
import { Parser } from "./parser.ts";
|
|
import { Resolver } from "./resolver.ts";
|
|
|
|
/// TODO: find a better place for this function
|
|
export async function compileWithDebug(path: string): Promise<number[]> {
|
|
const text = await Deno.readTextFile(path);
|
|
|
|
const reporter = new Reporter();
|
|
|
|
const lexer = new Lexer(text, reporter);
|
|
|
|
const parser = new Parser(lexer, reporter);
|
|
const ast = parser.parse();
|
|
|
|
new Resolver(reporter).resolve(ast);
|
|
new Checker(reporter).check(ast);
|
|
|
|
if (reporter.errorOccured()) {
|
|
console.error("Errors occurred, stopping compilation.");
|
|
}
|
|
|
|
const lowerer = new Lowerer(lexer.currentPos());
|
|
lowerer.lower(ast);
|
|
lowerer.printProgram();
|
|
const program = lowerer.finish();
|
|
return program;
|
|
}
|