Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
-- Forth VM?
local function vm(word, i, ...)
if type(word) ~= "table" then error("table expected") end
local _type = type(word[i])
local tco = word[i + 1] == nil
if _type == "table" then
-- definition
if tco then return vm(word[i], 1, ...) end
return vm(word, i + 1, vm(word[i], 1, ...))
elseif _type == "function" then
-- native code
return vm(word[i](word, i + 1, ...))
elseif _type == "number" or _type == "string" then
-- literal
return vm(word, i + 1, word[i], ...)
elseif _type == "nil" then
-- end of word / "EXIT"
return ...
end
end
return {vm=vm, run=function(w, ...) return vm(w, 1, ...) end}