mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-16 17:35:02 +01:00
print sexpr
This commit is contained in:
parent
74af407e47
commit
87b8b8eb28
1 changed files with 14 additions and 0 deletions
|
|
@ -30,6 +30,20 @@ type Sexpr = string | number | Sexpr[] | { inline: Symbol; items: Sexpr[] };
|
||||||
export function writeModuleWat(module: Module) {
|
export function writeModuleWat(module: Module) {
|
||||||
const sexprs = sexprModule(module);
|
const sexprs = sexprModule(module);
|
||||||
console.dir(sexprs, { depth: 100 });
|
console.dir(sexprs, { depth: 100 });
|
||||||
|
console.log(printSexpr(sexprs));
|
||||||
|
}
|
||||||
|
|
||||||
|
function printSexpr(sexpr: Sexpr): string {
|
||||||
|
if (typeof sexpr === "string") {
|
||||||
|
return sexpr;
|
||||||
|
} else if (typeof sexpr === "number") {
|
||||||
|
return String(sexpr);
|
||||||
|
} else if (typeof sexpr === "object" && "inline" in sexpr) {
|
||||||
|
return sexpr.items.map(printSexpr).join(" ");
|
||||||
|
} else {
|
||||||
|
const all = sexpr.map(printSexpr).join(" ");
|
||||||
|
return `(${all})`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function inline(items: Sexpr[]): Sexpr {
|
function inline(items: Sexpr[]): Sexpr {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue