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
end
end, parsed_code)
mykeepalive()
mykeepalive(thread)
end
mystart(parsed_code)
local function mykeepalive()
local function mykeepalive(thread)
thread:suscitate()
if not thread.stopped then
return

View File

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

View File

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

View File

@ -25,12 +25,73 @@ s = {
if t1 == "number" then
return true, p1 + p2
end
if t1 == "string" then
return true, p1 .. p2
if t1 == "boolean" then
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
return false, UAT
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)
if #params ~= 1 then
return false, WNOA
@ -131,8 +192,39 @@ s = {
return true
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)
return faden:flush(params)
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