slige/compiler/main.ts

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-12-12 12:04:57 +01:00
import { Ast, File } from "./ast.ts";
2024-12-10 21:42:15 +01:00
import { Checker } from "./checker.ts";
2024-12-11 03:11:00 +01:00
import { Reporter } from "./info.ts";
2024-12-10 21:42:15 +01:00
import { Lexer } from "./lexer.ts";
import { Lowerer } from "./lowerer.ts";
import { Parser } from "./parser.ts";
import { Resolver } from "./resolver.ts";
2024-11-04 14:54:55 +01:00
2024-12-12 12:04:57 +01:00
class Compilation {
private files: File[] = [];
public constructor(private startFile: string) {}
public compile(): Ast {
throw new Error();
}
}
2024-12-11 03:11:00 +01:00
//const text = await Deno.readTextFile("example.slg");
const text = await Deno.readTextFile(Deno.args[0]);
2024-11-04 14:54:55 +01:00
2024-12-11 03:11:00 +01:00
const reporter = new Reporter();
2024-11-20 15:41:20 +01:00
2024-12-11 03:11:00 +01:00
const lexer = new Lexer(text, reporter);
const parser = new Parser(lexer, reporter);
2024-12-12 12:04:57 +01:00
const ast = parser.parse();
2024-12-11 13:03:01 +01:00
2024-12-11 13:16:34 +01:00
// console.log(JSON.stringify(ast, null, 4));
2024-12-11 13:03:01 +01:00
2024-12-11 03:11:00 +01:00
new Resolver(reporter).resolve(ast);
new Checker(reporter).check(ast);
if (reporter.errorOccured()) {
console.error("Errors occurred, stopping compilation.");
Deno.exit(1);
}
2024-12-10 14:36:41 +01:00
const lowerer = new Lowerer();
lowerer.lower(ast);
2024-12-10 23:30:15 +01:00
lowerer.printProgram();
2024-12-10 14:36:41 +01:00
const program = lowerer.finish();
2024-12-11 00:03:19 +01:00
//console.log(JSON.stringify(program, null, 4));
2024-12-12 10:17:09 +01:00
// console.log(JSON.stringify(program));
2024-12-11 03:11:00 +01:00
await Deno.writeTextFile("out.slgbc", JSON.stringify(program));