35 lines
882 B
TypeScript
35 lines
882 B
TypeScript
import * as front from "./front.ts";
|
|
import * as ast from "./ast.ts";
|
|
|
|
const filename = Deno.args[0];
|
|
const text = await Deno.readTextFile(filename);
|
|
|
|
const fileAst = front.parse(filename, text);
|
|
const resols = front.resolve(filename, text, fileAst);
|
|
const checker = new front.Checker(filename, text, fileAst, resols);
|
|
|
|
let mainFn: ast.NodeWithKind<"FnStmt"> | null = null;
|
|
|
|
fileAst.visit({
|
|
visit(node) {
|
|
if (node.kind.tag === "FnStmt" && node.kind.ident === "main") {
|
|
if (mainFn) {
|
|
console.error("error: multiple 'main' functions");
|
|
Deno.exit(1);
|
|
}
|
|
|
|
ast.assertNodeWithKind(node, "FnStmt");
|
|
mainFn = node;
|
|
}
|
|
},
|
|
});
|
|
|
|
if (!mainFn) {
|
|
console.error("error: no 'main' function");
|
|
Deno.exit(1);
|
|
}
|
|
|
|
const mainTy = checker.check(mainFn);
|
|
|
|
console.log({ ast: fileAst, resols });
|