buxfixes and more instructions

M  README.md
M  faden.lua
M  parser.lua
M  standardbefehlssatz.lua
This commit is contained in:
Hybrid Dog 2016-12-28 18:27:41 +01:00
parent d57e096706
commit 53c47b17ab
4 changed files with 115 additions and 13 deletions

View File

@ -26,12 +26,12 @@ local function mystart(parsed_code)
return true return true
end end
end, parsed_code) end, parsed_code)
mykeepalive() mykeepalive(thread)
end end
mystart(parsed_code) mystart(parsed_code)
local function mykeepalive() local function mykeepalive(thread)
thread:suscitate() thread:suscitate()
if not thread.stopped then if not thread.stopped then
return return

View File

@ -4,7 +4,7 @@ local function befehl_ausfuhren(faden)
local vars = faden.vars local vars = faden.vars
local befehl, args = unpack(faden.liste[faden.ip]) local befehl, args = unpack(faden.liste[faden.ip])
for i = 1,#is do for i = 1,#is do
local bfunk = is[i] local bfunk = is[i][befehl]
if bfunk then if bfunk then
local fa = {} local fa = {}
local ersetzbar = {} local ersetzbar = {}
@ -31,6 +31,10 @@ local function befehl_ausfuhren(faden)
if not ersetzbar[i] then if not ersetzbar[i] then
return false, "Attempt on changing an immediate" return false, "Attempt on changing an immediate"
end end
if not args[i] then
-- FIXME
error"[pdisc] instruction set attempt to write in void"
end
vars[args[i]] = v vars[args[i]] = v
end end
end end
@ -48,7 +52,7 @@ local function programm_ausfuhren(faden)
local weiter,msg = befehl_ausfuhren(faden) local weiter,msg = befehl_ausfuhren(faden)
if not weiter then if not weiter then
faden.log = faden.log .. "Aborted: " .. msg .. "\n" faden.log = faden.log .. "Aborted: " .. msg .. "\n"
faden.exit() faden:exit()
return return
end end
return not faden.stopped and programm_ausfuhren(faden) return not faden.stopped and programm_ausfuhren(faden)
@ -57,6 +61,7 @@ end
return function(faden_manip, parsed) return function(faden_manip, parsed)
local faden = { local faden = {
log = "", log = "",
vars = {pi = math.pi},
ip = 1, ip = 1,
sp = 50, sp = 50,
sb = 50, sb = 50,
@ -76,7 +81,7 @@ return function(faden_manip, parsed)
self:suscitate() self:suscitate()
end, end,
try_rebirth = function(self) try_rebirth = function(self)
if minetest.get_gametime() < self.rebirth then if minetest.get_gametime() >= self.rebirth then
self:continue() self:continue()
end end
end, end,

View File

@ -13,7 +13,7 @@ local function parse_zeile(marken, imms, z, zn)
-- Marke erkennen -- Marke erkennen
local marke = z:find":" local marke = z:find":"
if marke then if marke then
mname = z:sub(1, marke - 1) local mname = z:sub(1, marke - 1)
marken[mname] = zn marken[mname] = zn
z = z:sub(marke+1):trim() z = z:sub(marke+1):trim()
@ -61,15 +61,20 @@ return function(programm)
local marken = {} local marken = {}
-- Programm erkennen -- Programm erkennen
local liste = programm:split"\n" local zeilen = programm:split"\n"
local zn = #liste local anz = 0
for i = 1,zn do local liste = {}
liste[i] = parse_zeile(marken, imms, liste[i], i) for i = 1,#zeilen do
local befehl = parse_zeile(marken, imms, zeilen[i], i)
if befehl[1] then
anz = anz + 1
liste[anz] = befehl
end
end end
local immn = #imms+1 local immn = #imms+1
-- Marken durch immediates ersetzen -- Marken durch immediates ersetzen
for i = 1,zn do for i = 1,anz do
local args = liste[i][2] local args = liste[i][2]
if args then if args then
for i = 1,#args do for i = 1,#args do

View File

@ -25,12 +25,73 @@ s = {
if t1 == "number" then if t1 == "number" then
return true, p1 + p2 return true, p1 + p2
end end
if t1 == "string" then if t1 == "boolean" then
return true, p1 .. p2 return true, p1 and p2
end
return true, p1 .. p2
end,
mul = function(params)
if #params ~= 2 then
return false, WNOA
end
local p1,p2 = unpack(params)
local t1 = type(p1)
local t2 = type(p2)
if t1 == "string"
and t2 == "number" then
return true, p1:rep(p2)
end
if t1 ~= t2 then
return false, "different argument types"
end
if t1 == "number" then
return true, p1 * p2
end
if t1 == "boolean" then
return true, p1 or p2
end end
return false, UAT return false, UAT
end, end,
neg = function(params)
if #params ~= 1 then
return false, WNOA
end
local v = params[1]
local t = type(v)
if t == "number" then
return true, -v
end
if t == "boolean" then
return true, not v
end
return true, v:rev()
end,
inv = function(params)
if #params ~= 1 then
return false, WNOA
end
local p = params[1]
if type(p) ~= "number" then
return false, UAT
end
return true, 1 / p
end,
mod = function(params)
if #params ~= 2 then
return false, WNOA
end
local p1,p2 = unpack(params)
if type(p1) ~= "number" or type(p2) ~= "number" then
return false, UAT
end
return true, p1 % p2
end,
jmp = function(params, faden) jmp = function(params, faden)
if #params ~= 1 then if #params ~= 1 then
return false, WNOA return false, WNOA
@ -131,8 +192,39 @@ s = {
return true return true
end, end,
tostring = function(params)
if #params ~= 1 then
return false, WNOA
end
return true, tostring(params[1])
end,
print = function(params, faden)
for i = 1,#params do
params[i] = tostring(params[i])
end
faden.log = faden.log .. table.concat(params, "\t") .. "\n"
return true
end,
flush = function(params, faden) flush = function(params, faden)
return faden:flush(params) return faden:flush(params)
end, end,
} }
local so_math_fcts = {"sin", "asin", "cos", "acos", "tan", "atan",
"abs", "sign", "floor", "ceil"}
for i = 1,#so_math_fcts do
i = so_math_fcts[i]
s[i] = function(params)
if #params ~= 1 then
return false, WNOA
end
local p = params[1]
if type(p) ~= "number" then
return false, UAT
end
return true, math[i](p)
end
end
return s return s