Skip to content

Commit b385c73

Browse files
committed
Add boolean return to next_instruction
1 parent 1f8a3b0 commit b385c73

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

examples/04_interpreter.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,5 @@ local result = asm:parse(tokenizer)
3131
-- 5. Execution
3232
local interpreter = LuASM:interpreter(result)
3333

34-
interpreter:next_instruction()
35-
interpreter:next_instruction()
36-
interpreter:next_instruction()
34+
while interpreter:next_instruction() do end
3735

src/luasm.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ local Tokenizer = {}
105105
--- Abstract method that must be overridden by a concrete tokenizer.
106106
function Tokenizer.get_next_line()
107107
error("This function has to be implemented!")
108-
return nil
108+
return false
109109
end
110110

111111
--- Creates a new tokenizer without a specific implementation.
@@ -442,7 +442,7 @@ function interpreter:next_instruction()
442442
::start::
443443

444444
if self.data.parsed_lines < self.ip then
445-
return nil
445+
return false
446446
end
447447

448448
local line = self.data.instructions[self.ip]
@@ -451,7 +451,9 @@ function interpreter:next_instruction()
451451
goto start
452452
end
453453

454-
line:run(self)
454+
local result = line:run(self)
455+
456+
return result == nil or result
455457
end
456458

457459
--- Creates a new interpreter instance.

0 commit comments

Comments
 (0)