forked from mtcontrib/pdisc
Fix exit and show source line numbers
This commit is contained in:
parent
ee0859ce94
commit
adc39aeb7f
23
faden.lua
23
faden.lua
|
@ -4,9 +4,13 @@ local function befehl_ausfuhren(faden)
|
||||||
local vars = faden.vars
|
local vars = faden.vars
|
||||||
local anw = faden.liste[faden.ip]
|
local anw = faden.liste[faden.ip]
|
||||||
if not anw then
|
if not anw then
|
||||||
return false, "Invalid instruction pointer"
|
return false, "Invalid instruction pointer, previous line: " ..
|
||||||
|
faden.previous_line_number
|
||||||
end
|
end
|
||||||
local befehl, args = unpack(anw)
|
local befehl, args = unpack(anw)
|
||||||
|
local line_number = anw[3] or -1
|
||||||
|
-- enable this line for tracing:
|
||||||
|
--~ print(line_number, befehl, args and table.concat(args, ", "))
|
||||||
for i = 1,#is do
|
for i = 1,#is do
|
||||||
local bfunk = is[i][befehl]
|
local bfunk = is[i][befehl]
|
||||||
if bfunk then
|
if bfunk then
|
||||||
|
@ -25,7 +29,8 @@ local function befehl_ausfuhren(faden)
|
||||||
end
|
end
|
||||||
local weiter, ergebnis = bfunk(fa, faden)
|
local weiter, ergebnis = bfunk(fa, faden)
|
||||||
if not weiter then
|
if not weiter then
|
||||||
return false, "Command " .. befehl .. ": " .. ergebnis
|
return false, "Command " .. befehl ..
|
||||||
|
" (" .. line_number .. "): " .. ergebnis
|
||||||
end
|
end
|
||||||
if args
|
if args
|
||||||
and ergebnis ~= nil then
|
and ergebnis ~= nil then
|
||||||
|
@ -43,16 +48,18 @@ local function befehl_ausfuhren(faden)
|
||||||
if faden.ip > #faden.liste then
|
if faden.ip > #faden.liste then
|
||||||
return false, "Done"
|
return false, "Done"
|
||||||
end
|
end
|
||||||
|
faden.previous_line_number = line_number
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false, 'Unknown command "' .. befehl .. '"'
|
return false, 'Unknown command "' .. befehl .. '" (' .. line_number .. ")"
|
||||||
end
|
end
|
||||||
|
|
||||||
local function programm_ausfuhren(faden)
|
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 (" .. faden.ip .. "): " .. msg .. "\n"
|
faden.log = faden.log ..
|
||||||
|
"Aborted (." .. faden.ip .. "): " .. msg .. "\n"
|
||||||
faden:exit()
|
faden:exit()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -64,25 +71,26 @@ return function(faden_manip, parsed)
|
||||||
log = "",
|
log = "",
|
||||||
vars = {pi = math.pi},
|
vars = {pi = math.pi},
|
||||||
ip = 1,
|
ip = 1,
|
||||||
|
last_line_number = 1,
|
||||||
sp = 3500,
|
sp = 3500,
|
||||||
sb = 3500,
|
sb = 3500,
|
||||||
strlen_max = 2000,
|
strlen_max = 2000,
|
||||||
stack = {},
|
stack = {},
|
||||||
is = {pdisc.standard_befehlssatz},
|
is = {pdisc.standard_befehlssatz},
|
||||||
suscitate = programm_ausfuhren,
|
suscitate = programm_ausfuhren, -- beim ersten Start
|
||||||
flush = function(self)
|
flush = function(self)
|
||||||
print(self.log)
|
print(self.log)
|
||||||
self.log = ""
|
self.log = ""
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
stop = function(self)
|
stop = function(self) -- beim vorrübergehenden Anhalten
|
||||||
self.stopped = true
|
self.stopped = true
|
||||||
end,
|
end,
|
||||||
continue = function(self)
|
continue = function(self)
|
||||||
self.stopped = false
|
self.stopped = false
|
||||||
self:suscitate()
|
self:suscitate()
|
||||||
end,
|
end,
|
||||||
try_rebirth = function(self)
|
try_rebirth = function(self) -- bei weiteren Starts
|
||||||
if minetest.get_us_time() >= self.rebirth then
|
if minetest.get_us_time() >= self.rebirth then
|
||||||
self:continue()
|
self:continue()
|
||||||
return true
|
return true
|
||||||
|
@ -90,6 +98,7 @@ return function(faden_manip, parsed)
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
exit = function(self)
|
exit = function(self)
|
||||||
|
self.stopped = false
|
||||||
self:flush()
|
self:flush()
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
25
parser.lua
25
parser.lua
|
@ -56,20 +56,39 @@ local function parse_zeile(marken, imms, z, ip)
|
||||||
return {befehl, args}
|
return {befehl, args}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function zeileniter(text)
|
||||||
|
return function()
|
||||||
|
if not text then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local umbruch = text:find"\n"
|
||||||
|
if not umbruch then
|
||||||
|
local rv = text
|
||||||
|
text = nil
|
||||||
|
return rv
|
||||||
|
end
|
||||||
|
local rv = text:sub(1, umbruch-1)
|
||||||
|
text = text:sub(umbruch+1)
|
||||||
|
return rv
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return function(programm)
|
return function(programm)
|
||||||
local imms = {}
|
local imms = {}
|
||||||
local marken = {}
|
local marken = {}
|
||||||
|
|
||||||
-- Programm erkennen
|
-- Programm erkennen
|
||||||
local zeilen = programm:split"\n"
|
|
||||||
local anz = 0
|
local anz = 0
|
||||||
local liste = {}
|
local liste = {}
|
||||||
for i = 1,#zeilen do
|
local zn = 1
|
||||||
local befehl = parse_zeile(marken, imms, zeilen[i], anz + 1)
|
for zeile in zeileniter(programm) do
|
||||||
|
local befehl = parse_zeile(marken, imms, zeile, anz + 1)
|
||||||
if befehl[1] then
|
if befehl[1] then
|
||||||
|
befehl[3] = zn -- Zeilennummer für Fehlernachrichten
|
||||||
anz = anz + 1
|
anz = anz + 1
|
||||||
liste[anz] = befehl
|
liste[anz] = befehl
|
||||||
end
|
end
|
||||||
|
zn = zn+1
|
||||||
end
|
end
|
||||||
local immn = #imms+1
|
local immn = #imms+1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user