1
0
mirror of https://github.com/HybridDog/pdisc.git synced 2025-07-01 07:40:39 +02:00

Fix exit and show source line numbers

This commit is contained in:
Hybrid Dog
2017-04-13 23:05:50 +02:00
parent ee0859ce94
commit adc39aeb7f
2 changed files with 38 additions and 10 deletions

View File

@ -4,9 +4,13 @@ local function befehl_ausfuhren(faden)
local vars = faden.vars
local anw = faden.liste[faden.ip]
if not anw then
return false, "Invalid instruction pointer"
return false, "Invalid instruction pointer, previous line: " ..
faden.previous_line_number
end
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
local bfunk = is[i][befehl]
if bfunk then
@ -25,7 +29,8 @@ local function befehl_ausfuhren(faden)
end
local weiter, ergebnis = bfunk(fa, faden)
if not weiter then
return false, "Command " .. befehl .. ": " .. ergebnis
return false, "Command " .. befehl ..
" (" .. line_number .. "): " .. ergebnis
end
if args
and ergebnis ~= nil then
@ -43,16 +48,18 @@ local function befehl_ausfuhren(faden)
if faden.ip > #faden.liste then
return false, "Done"
end
faden.previous_line_number = line_number
return true
end
end
return false, 'Unknown command "' .. befehl .. '"'
return false, 'Unknown command "' .. befehl .. '" (' .. line_number .. ")"
end
local function programm_ausfuhren(faden)
local weiter,msg = befehl_ausfuhren(faden)
if not weiter then
faden.log = faden.log .. "Aborted (" .. faden.ip .. "): " .. msg .. "\n"
faden.log = faden.log ..
"Aborted (." .. faden.ip .. "): " .. msg .. "\n"
faden:exit()
return
end
@ -64,25 +71,26 @@ return function(faden_manip, parsed)
log = "",
vars = {pi = math.pi},
ip = 1,
last_line_number = 1,
sp = 3500,
sb = 3500,
strlen_max = 2000,
stack = {},
is = {pdisc.standard_befehlssatz},
suscitate = programm_ausfuhren,
suscitate = programm_ausfuhren, -- beim ersten Start
flush = function(self)
print(self.log)
self.log = ""
return true
end,
stop = function(self)
stop = function(self) -- beim vorrübergehenden Anhalten
self.stopped = true
end,
continue = function(self)
self.stopped = false
self:suscitate()
end,
try_rebirth = function(self)
try_rebirth = function(self) -- bei weiteren Starts
if minetest.get_us_time() >= self.rebirth then
self:continue()
return true
@ -90,6 +98,7 @@ return function(faden_manip, parsed)
return false
end,
exit = function(self)
self.stopped = false
self:flush()
end,
}