51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { Ast, AstCreator, File } from "./ast.ts";
|
|
import { stmtToString } from "./ast_visitor.ts";
|
|
import { Checker } from "./checker.ts";
|
|
import { CompoundAssignDesugarer } from "./desugar/compound_assign.ts";
|
|
import { SpecialLoopDesugarer } from "./desugar/special_loop.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";
|
|
|
|
class Compilation {
|
|
private files: File[] = [];
|
|
|
|
public constructor(private startFile: string) {}
|
|
|
|
public compile(): Ast {
|
|
throw new Error();
|
|
}
|
|
}
|
|
|
|
const text = await Deno.readTextFile(Deno.args[0]);
|
|
|
|
const astCreator = new AstCreator();
|
|
const reporter = new Reporter();
|
|
|
|
const lexer = new Lexer(text, reporter);
|
|
|
|
const parser = new Parser(lexer, astCreator, reporter);
|
|
const ast = parser.parse();
|
|
|
|
new SpecialLoopDesugarer(astCreator).desugar(ast);
|
|
|
|
new Resolver(reporter).resolve(ast);
|
|
|
|
new CompoundAssignDesugarer(astCreator).desugar(ast);
|
|
|
|
new Checker(reporter).check(ast);
|
|
|
|
if (reporter.errorOccured()) {
|
|
console.error("Errors occurred, stopping compilation.");
|
|
Deno.exit(1);
|
|
}
|
|
|
|
const lowerer = new Lowerer(lexer.currentPos());
|
|
lowerer.lower(ast);
|
|
lowerer.printProgram();
|
|
const program = lowerer.finish();
|
|
|
|
await Deno.writeTextFile("out.slgbc", JSON.stringify(program));
|