mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-15 00:45:04 +01:00
generate more code
This commit is contained in:
parent
ccd8008731
commit
42bc96dbce
7 changed files with 306 additions and 51 deletions
33
src/index.ts
33
src/index.ts
|
|
@ -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`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue