Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
lua-until EOL dict["::lua"] = function() local w = getword("::lua newword") local bulk = getuntilre(";;", "::lua bulk", "::lua delim") dict[w] = dostring(format("return function() %s\nend", bulk)) end stack = {n=0} pock = function(dep, data) stack[stack.n-dep] = data end pick = function(dep) return stack[stack.n-dep] end pop = function() tremove(stack) end push = function(data) tinsert(stack, data) end npop = function(n) local i; for i=1,n do pop() end end bury = function(n) pock(n, pick(0)); npop(n) end untreenode = function() if keeptree then pick(0).pre1 = pick(1) end end bintreenode = function() if keeptree then pick(0).pre1 = pick(2); pick(0).pre2 = pick(1) end end binop = function(newnode) push(newnode); bintreenode(); bury(2) end unop = function(newnode) push(newnode); untreenode(); bury(1) end -- (find-angg "LUA/miniforth.lua") EOL ::lua %: getline("comment") ;; ::lua pstack print("pstack on label", getword()); p(stack) ;; ::lua p local code = getword(); print(code); px(eval(code)) ;; ::lua p p(eval(getword("p luacode"))) ;; ::lua px px(eval(getword("px luacode"))) ;; ::lua push push(eval(getword("push luacode"))) ;; %: \O[a] \O[x] %: ------------ %: a->x x^F %: -------- ------- %: \E[a->x] \E[x^F] %: ----------------- %: \O[x] \O[x^F] \O[x] (a->x)->x^F %: ------------- ------------------ %: x=>x^F x-.>((a->x)->x^F) a^F %: ---------- --------------------- ------- %: \O[a] \O[x=>x^F] \E[x-.>((a->x)->x^F)] \E[a^F] %: ----------------- -------------------------------- %: \O[(a;x=>x^F)] (x-.>((a->x)->x^F))<->a^F %: ------------------------------------------- %: (a;x=>x^F)-.>((x-.>((a->x)->x^F))<->a^F) ::lua -> binop({name = pick(1).peel.name.. "->"..pick(0).peel.name}) ;; ::lua <-> binop({name = pick(1).peel.name.."<->"..pick(0).peel.name}) ;; ::lua => binop({name = pick(1).peel.name.. "=>"..pick(0).peel.name}) ;; ::lua -.>() binop({name = pick(1).peel.name.."-.>("..pick(0).name..")"}) ;; ::lua ()<-> binop({name ="("..pick(1).peel.name..")<->"..pick(0).peel.name}) ;; ::lua \E unop({name = "\\E["..pick(0).name.."]", peel = pick(0)}) ;; ::lua \O unop({name = "\\O["..pick(0).name.."]", peel = pick(0)}) ;; ::lua () unop({name = "("..pick(0).name..")"}) ;; ::lua \O(;) local pname1, pname0 = pick(1).peel.name, pick(0).peel.name local p = "("..pname1..";"..pname0..")" binop({name = "\\O["..p.."]", peel = {name = p}}) ;; ::lua $ push({name = getword("$ newword")}) ;; $ a \O $ x \O $ x^F \O => \O \O(;) $ x \O $ a \O $ x \O -> \E $ x^F \E -> -.>() \E $ a^F \E ()<-> -.>() %: p stack lua-until EOL print(pick(0).name) exit() EOL #* cd ~/miniforth/ mylua -f miniforth1.lua yoneda.mflua #*