generate more code

This commit is contained in:
nora 2023-07-26 20:50:48 +02:00
parent ccd8008731
commit 42bc96dbce
7 changed files with 306 additions and 51 deletions

View file

@ -6,13 +6,17 @@ import { printAst } from "./printer";
import { resolve } from "./resolve";
import { typeck } from "./typeck";
import { writeModuleWatToString } from "./wasm/wat";
import fs from "fs";
import { exec } from "child_process";
const input = `
function main(i: Int): Int = 0;
function main(i: Int, j: Int): Bool = false == (i == 0);
`;
function main() {
withErrorHandler(input, () => {
const start = Date.now();
const tokens = tokenize(input);
console.log("-----TOKENS------------");
console.log(tokens);
@ -34,11 +38,34 @@ function main() {
console.log("-----AST typecked------");
const typecked = typeck(resolved);
console.log("-----wasm--------------");
const wasmModule = lowerToWasm(typecked);
const moduleStringColor = writeModuleWatToString(wasmModule, true);
const moduleString = writeModuleWatToString(wasmModule);
console.log(moduleString);
console.log(moduleStringColor);
fs.writeFileSync("out.wat", moduleString);
console.log("--validate wasm-tools--");
exec("wasm-tools validate out.wat", (error, stdout, stderr) => {
if (error && error.code === 1) {
console.log(stderr);
} else if (error) {
console.error(`failed to spawn wasm-tools: ${error}`);
} else {
if (stderr) {
console.log(stderr);
}
if (stdout) {
console.log(stdout);
}
}
console.log(`finished in ${Date.now() - start}ms`);
});
});
}