|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
LForth - a minimal Forth-like language built on top of Lua-5.0-beta.
Author: Eduardo Ochs - see <http://angg.twu.net/>.
Version: 2003jan05.
This is an e-script file.
# «.build-lua» (to "build-lua")
# «.outer-mini» (to "outer-mini")
# «.outer-mini-test» (to "outer-mini-test")
# «.outer-mini-dbgtest» (to "outer-mini-dbgtest")
# «.outer-mini-deftest» (to "outer-mini-deftest")
# «.inner-mini» (to "inner-mini")
# «.inner-mini-test1» (to "inner-mini-test1")
# «.inner-mini-test2» (to "inner-mini-test2")
# «.kernel» (to "kernel")
# «.kernel-innertest1» (to "kernel-innertest1")
# «.kernel-innertestrsr» (to "kernel-innertestrsr")
# «.kernel-outertest1» (to "kernel-outertest1")
# «.kernel-outertest2» (to "kernel-outertest2")
# «.a2ps» (to "a2ps")
####
#
# Building Lua-5.0-beta
#
####
# «build-lua» (to ".build-lua")
# (find-angg "LUA/lua50init.lua" "build-lua")
#*
rm -Rv ~/tmp/lua-5.0-beta/
mkdir ~/tmp/lua-5.0-beta/
tar -xvzf $S/http/www.lua.org/ftp/lua-5.0-beta.tar.gz -C ~/tmp/
cd ~/tmp/lua-5.0-beta/
# (find-lua50file "INSTALL")
# (find-lua50file "config")
# (find-lua50file "etc/README")
# (find-lua50file "etc/loadlib.c")
cat >> config <<'%%%'
# --- Edrx's changes
# (find-fline "config" "\n#USERCONF=")
USERCONF=-DLUA_USERCONFIG='"$(LUA)/etc/config.c"' -DUSE_READLINE -DUSE_LOADLIB
EXTRA_LIBS= -lm -lreadline -ldl
%%%
make test
#*
####
#
# «outer-mini» (to ".outer-mini")
# The outer interpreter - minimal version
#
####
#*
# «outer-mini-test» (to ".outer-mini-test")
# (find-angg "LFORTH/outer-mini.lua")
cd ~/LFORTH/
lua50 -l outer-mini.lua -e 'outerloop [[
[lua print("hello") lua]
]]
'
#*
# «outer-mini-dbgtest» (to ".outer-mini-dbgtest")
# (find-angg "LFORTH/outer-mini.lua")
# (find-angg "LFORTH/dbg.lua")
cd ~/LFORTH/
lua50 -l outer-mini.lua -l dbg.lua -e 'outerloop [[
[lua print("hello") lua]
]]
'
#*
# «outer-mini-deftest» (to ".outer-mini-deftest")
# (find-angg "LFORTH/")
cd ~/LFORTH/
lua50 -l outer-mini.lua -e 'outerloop [[
[lua
dict[":lua"] = function ()
local word, code = getword(), getuntilluare(nil, "^(.-)lua;")
dict[word] = assert(loadstring(code))
end
lua]
:lua hello print("Hello!") lua;
hello
[lua
ds = {}
dspush = function (v) table.insert(ds, 1, v); return v end
dspop = function () return table.remove(ds, 1) end
lua]
:lua dup dspush(ds[1]) lua;
:lua drop dspop() lua;
:lua * dspush(dspop()*dspop()) lua;
:lua . print(dspop()) lua;
:lua n dspush(assert(tonumber(getword()))) lua;
n 5 dup . dup dup * * .
n 3 dup . dup dup * * .
]]'
#*
####
#
# «inner-mini» (to ".inner-mini")
# The inner interpreter - minimal version
#
####
# «inner-mini-test1» (to ".inner-mini-test1")
#*
# (find-angg "LFORTH/inner-mini.lua")
cd ~/LFORTH/
lua50 -l inner-mini.lua -l dbg.lua -e '
iiforths.dup = function () dspush(ds[1]) end
iiforths["*"] = function () ds[2] = ds[1]*ds[2]; dspop() end
iiforths.square = mem.here
mem.compile("h_forth", "dup", "*", "exit")
iiforths.cube = mem.here
mem.compile("h_forth", "dup", "square", "*", "exit")
dspush(5) -- we want the result of "5 cube"
ip = iiforths.cube
iistate = iistates.head
innerloop()
print(dspop())
'
#*
# «inner-mini-test2» (to ".inner-mini-test2")
# (find-angg "LFORTH/inner-mini.lua")
# (find-angg "LFORTH/inner.lua")
# (find-lua50ref "string.rep")
cd ~/LFORTH/
lua50 -l inner-mini.lua -l dbg.lua -e '
ss = {}
sspush = function (v) table.insert(ss, 1, v); return v end
sspop = function () return table.remove(ss, 1) end
iiheads.h_rsr = function ()
sspush(rspop())
rspush(function () ip = sspop() end)
end
prim = function (name, fun) iiforths[name] = fun end
compile = function (name, ...)
iiforths[name] = mem.here
mem.compile(unpack(arg))
end
rsrprim = function (rname, sname, fun)
prim(sname, fun)
compile(rname, "h_rsr", "h_forth", sname, "exit")
end
prim("dup", function () dspush(ds[1]) end)
prim("swap", function () ds[2], ds[1] = ds[1], ds[2] end)
prim(".", function () print(dspop()) end)
prim("..", function () ds[2] = ds[2]..ds[1]; dspop() end)
rsrprim("lit", "slit", function () dspush(mem[ss[1]]); ss[1] = ss[1] + 1 end)
compile("wrap", "h_rsr")
compile("swrap", "h_forth", "slit", "swap", "..", "slit", "..", "exit")
compile("test", "h_forth", "lit", "hey!", "wrap", "<", ">", ".", "exit")
ip = iiforths.test
iistate = iistates.head
innerloop()
'
#*
#####
#
# «kernel» (to ".kernel")
# The full LForth kernel: inner interpreter + outer interpreter
# 2003jan12
#
#####
# (find-angg "LFORTH/kernel.lua")
#*
# «kernel-innertest1» (to ".kernel-innertest1")
# (find-angg "LFORTH/kernel.lua" "invoke")
cd ~/LFORTH/
lua50 -l kernel.lua -l dbg.lua -e '
prim("dup", function () dspush(ds[1]) end)
prim("*", function () ds[2] = ds[2]*ds[1]; dspop() end)
compile("square", "h_forth", "dup", "*", "exit")
compile("cube", "h_forth", "dup", "square", "*", "exit")
dspush(5)
invoke("cube")
print(ds[1])
'
#*
# «kernel-innertestrsr» (to ".kernel-innertestrsr")
# (find-angg "LFORTH/kernel.lua" "invoke")
cd ~/LFORTH/
lua50 -l kernel.lua -l dbg.lua -e '
prim("dup", function () dspush(ds[1]) end)
prim("swap", function () ds[2], ds[1] = ds[1], ds[2] end)
prim(".", function () print(dspop()) end)
prim("..", function () ds[2] = ds[2]..ds[1]; dspop() end)
rsrprim("lit", "slit", function ()
dspush(mem[ss[1]]); ss[1] = ss[1] + 1
end)
compile("wrap", "h_rsr")
compile("swrap", "h_forth", "slit", "swap", "..", "slit", "..", "exit")
compile("rsrtest", "h_forth", "lit", "hey!", "wrap", "<", ">", ".", "exit")
invoke("rsrtest")
print("Ok!")
'
#*
# «kernel-outertest1» (to ".kernel-outertest1")
cd ~/LFORTH/
# (find-angg "LFORTH/kernel.lua" "interpret")
lua50 -l kernel.lua -e '
prim("dup", function () dspush(ds[1]) end)
prim("*", function () ds[2] = ds[2]*ds[1]; dspop() end)
prim(".", function () print(dspop()) end)
interpret("4 dup dup * * .")
interpret([[
: square dup * ;
: cube dup square * ;
5 cube .]])
'
#*
# «kernel-outertest2» (to ".kernel-outertest2")
lua50 -l kernel.lua -e 'interpret [[
:lua dup dspush(ds[1]) lua;
:lua * ds[2] = ds[2]*ds[1]; dspop() lua;
:lua . print(dspop()) lua;
4 dup dup * * .
: square dup * ;
: cube dup square * ;
5 cube .
]]'
#*
####
#
# Printing with a2ps
#
####
# «a2ps» (to ".a2ps")
#*
cd ~/LFORTH/
scp -v * edrx@boto:LFORTH/
#*
# (find-man "a2ps")
# (find-node "(a2ps)")
# (find-node "(a2ps)Basics for Printing")
# (find-node "(a2ps)Some Encodings")
# (find-fline "~/LFORTH/")
cd ~/LFORTH/
a2ps -o o.ps -Av -3 --print-anyway=yes \
outer.lua inner-mini.lua dbg.lua \
inner.lua README DNC
#*
# (find-angg "LFORTH/")
cd ~/LFORTH/
a2ps -o o.ps -Av -3 --print-anyway=yes \
kernel.lua stdlib.lforth lforth
rm -v /tmp/o.p*; make -f ~/LATEX/Makefile /tmp/o.pdj
#*
cd ~/LFORTH/
scp -v * edrx@mula:LFORTH/
#*
# (find-angg "LFORTH/outer.lua")
-- (find-angg "LUA/lua50init.lua")
# (find-angg "LFORTH/inner.lua")