-- An implementation of "textual" colon words (more like macros) for -- miniforth. This is truly minimal, and will work on a system that -- doesn't even dream of having bytecodes. -- (find-miniforthfile "cube1.mflua") dstack = {} rstack = {program} dpush = function( val ) tinsert(dstack, 1, val) end dpop = function( ) return tremove(dstack, 1) end rpush = function( prog ) tinsert(rstack, 1, prog); program = prog end rpop = function( ) tremove(rstack, 1); program = rstack[1] end dict[""] = function( ) getline() if program.pos == strlen(program.string) then rpop() end end mf = function( code ) rpush({string=code, pos=0}) end re(res, ";;", "[ \t\n];;([ \t\n]|$)") dict["::"] = function( ) local word, code = getword(), getuntilre(";;") dict[word] = function( ) mf(%code) end end -- A cousin of "::" that treats its body as Lua code. It doesn't have -- anything to do with the textual colon words, but it's definition is -- very similar to "::". dict["::lua"] = function() local word, code = getword(), getuntilre(";;") dict[word] = dostring(format("return function() %s\nend", code)) end