Compare commits
3 Commits
105a4eed8b
...
9840269ab7
Author | SHA1 | Date | |
---|---|---|---|
9840269ab7 | |||
613b57f40f | |||
4a0e23c193 |
@ -3,3 +3,5 @@ export * from "./ast.ts";
|
||||
export * from "./arch.ts";
|
||||
export * from "./lexer.ts";
|
||||
export * from "./token.ts";
|
||||
|
||||
export * from "./temputils.ts";
|
||||
|
31
compiler/temputils.ts
Normal file
31
compiler/temputils.ts
Normal file
@ -0,0 +1,31 @@
|
||||
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.parseStmts();
|
||||
|
||||
new Resolver(reporter).resolve(ast);
|
||||
new Checker(reporter).check(ast);
|
||||
|
||||
if (reporter.errorOccured()) {
|
||||
console.error("Errors occurred, stopping compilation.");
|
||||
}
|
||||
|
||||
const lowerer = new Lowerer();
|
||||
lowerer.lower(ast);
|
||||
lowerer.printProgram();
|
||||
const program = lowerer.finish();
|
||||
return program;
|
||||
}
|
@ -15,7 +15,8 @@ auto sliger::rpc::action::FlameGraph::perform_action(
|
||||
{
|
||||
auto json = vm.flame_graph_json();
|
||||
if (json) {
|
||||
writer->write(json.value());
|
||||
writer->write(
|
||||
std::format("{{ ok: true, flameGraph: \"{}\" }}", json.value()));
|
||||
} else {
|
||||
writer->write("null");
|
||||
}
|
||||
@ -28,9 +29,10 @@ auto sliger::rpc::action::CodeCoverage::perform_action(
|
||||
{
|
||||
auto json = vm.code_coverage_json();
|
||||
if (json) {
|
||||
writer->write(json.value());
|
||||
writer->write(
|
||||
std::format("{{ ok: true, codeCoverage: \"{}\" }}", json.value()));
|
||||
} else {
|
||||
writer->write("null");
|
||||
writer->write("{ ok: false }");
|
||||
}
|
||||
writer->flush();
|
||||
};
|
||||
|
@ -20,6 +20,7 @@ const runtime = new Runtime(13370);
|
||||
|
||||
async function compileProgram(filepath: string) {
|
||||
const result = await compiler.compileWithDebug(filepath);
|
||||
return result;
|
||||
}
|
||||
|
||||
async function runProgramWithDebug(program: number[]) {
|
||||
@ -37,6 +38,8 @@ async function runProgramWithDebug(program: number[]) {
|
||||
}
|
||||
}
|
||||
|
||||
await compileProgram(filepath).then(runProgramWithDebug);
|
||||
|
||||
const router = new Router();
|
||||
|
||||
router.get("/api/source", (ctx) => {
|
||||
|
Loading…
Reference in New Issue
Block a user