slige/compiler/main.ts

51 lines
1.3 KiB
TypeScript
Raw Normal View History

import { Ast, AstCreator, File } from "./ast.ts";
import { stmtToString } from "./ast_visitor.ts";
2024-12-10 20:42:15 +00:00
import { Checker } from "./checker.ts";
import { CompoundAssignDesugarer } from "./desugar/compound_assign.ts";
import { SpecialLoopDesugarer } from "./desugar/special_loop.ts";
2024-12-11 02:11:00 +00:00
import { Reporter } from "./info.ts";
2024-12-10 20:42:15 +00:00
import { Lexer } from "./lexer.ts";
import { Lowerer } from "./lowerer.ts";
import { Parser } from "./parser.ts";
import { Resolver } from "./resolver.ts";
2024-11-04 13:54:55 +00:00
2024-12-12 11:04:57 +00:00
class Compilation {
private files: File[] = [];
public constructor(private startFile: string) {}
public compile(): Ast {
throw new Error();
}
}
2024-12-11 02:11:00 +00:00
const text = await Deno.readTextFile(Deno.args[0]);
2024-11-04 13:54:55 +00:00
const astCreator = new AstCreator();
2024-12-11 02:11:00 +00:00
const reporter = new Reporter();
2024-11-20 14:41:20 +00:00
2024-12-11 02:11:00 +00:00
const lexer = new Lexer(text, reporter);
const parser = new Parser(lexer, astCreator, reporter);
2024-12-12 11:04:57 +00:00
const ast = parser.parse();
2024-12-11 12:03:01 +00:00
new SpecialLoopDesugarer(astCreator).desugar(ast);
2024-12-11 12:03:01 +00:00
2024-12-11 02:11:00 +00:00
new Resolver(reporter).resolve(ast);
new CompoundAssignDesugarer(astCreator).desugar(ast);
2024-12-11 02:11:00 +00:00
new Checker(reporter).check(ast);
if (reporter.errorOccured()) {
console.error("Errors occurred, stopping compilation.");
Deno.exit(1);
}
2024-12-13 08:55:09 +00:00
const lowerer = new Lowerer(lexer.currentPos());
2024-12-10 13:36:41 +00:00
lowerer.lower(ast);
2024-12-10 22:30:15 +00:00
lowerer.printProgram();
2024-12-10 13:36:41 +00:00
const program = lowerer.finish();
2024-12-11 02:11:00 +00:00
await Deno.writeTextFile("out.slgbc", JSON.stringify(program));