@thi.ng/pointfree-lang
Version:
Forth style syntax layer/compiler & CLI for the @thi.ng/pointfree DSL
53 lines (52 loc) • 1.02 kB
JavaScript
import * as pf from "@thi.ng/pointfree";
const ALIASES = {
"?drop": pf.dropif,
"?dup": pf.dupif,
"-rot": pf.invrot,
">r": pf.movdr,
">r2": pf.movdr2,
"r>": pf.movrd,
"r2>": pf.movrd2,
if: pf.condq,
when: pf.whenq,
switch: pf.casesq,
while: pf.loopq,
try: pf.$try,
"+": pf.add,
"-": pf.sub,
"*": pf.mul,
"/": pf.div,
"v+": pf.vadd,
"v-": pf.vsub,
"v*": pf.vmul,
"v/": pf.vdiv,
"=": pf.eq,
"not=": pf.neq,
"<=": pf.lteq,
">=": pf.gteq,
"<": pf.lt,
">": pf.gt,
"pos?": pf.ispos,
"neg?": pf.isneg,
"nil?": pf.isnull,
"zero?": pf.iszero,
"match?": pf.ismatch,
">json": pf.tojson,
"json>": pf.fromjson,
">word": (ctx) => {
const ds = ctx[0];
pf.ensureStack(ds, 2);
const name = ds.pop();
ctx[2].__words[name] = pf.defWord(ds.pop());
return ctx;
},
pi: pf.defPush(Math.PI),
tau: pf.defPush(2 * Math.PI),
".": pf.print,
".s": pf.printds,
".r": pf.printrs,
".e": (ctx) => (console.log(ctx[2]), ctx)
};
export {
ALIASES
};