diff --git a/HISTORY.md b/HISTORY.md index becf069..f5dc81c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,6 +9,7 @@ History of SixtyPical in a `copy` to a vector is a routine that is defined further down in the source. * Fixed bug which was preventing `if` branches to diverge in what they initialized, if it was already initialized when going into the `if`. +* Fixed a bug which was making it crash when trying to analyze `repeat forever` loops. 0.9 --- diff --git a/eg/proto-game.60p b/eg/proto-game.60p index c1d73d5..bfa0cdc 100644 --- a/eg/proto-game.60p +++ b/eg/proto-game.60p @@ -240,8 +240,6 @@ routine main copy cinv, save_cinv copy our_cinv, cinv } - // FIXME: find out why `repeat { } forever` does not analyze OK - repeat { - ld a, 0 - } until not z + + repeat { } forever } diff --git a/src/sixtypical/analyzer.py b/src/sixtypical/analyzer.py index 8e55ae9..b678342 100644 --- a/src/sixtypical/analyzer.py +++ b/src/sixtypical/analyzer.py @@ -324,12 +324,14 @@ class Analyzer(object): # it will always be executed at least once, so analyze it having # been executed the first time. self.analyze_block(instr.block, context) - context.assert_meaningful(src) + if src is not None: # None indicates 'repeat forever' + context.assert_meaningful(src) # now analyze it having been executed a second time, with the context # of it having already been executed. self.analyze_block(instr.block, context) - context.assert_meaningful(src) + if src is not None: + context.assert_meaningful(src) elif opcode == 'copy': # 1. check that their types are compatible diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index 8ac674a..1bce2b9 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -307,7 +307,7 @@ class Compiler(object): elif opcode == 'repeat': top_label = self.emitter.make_label() self.compile_block(instr.block) - if src is None: + if src is None: # indicates 'repeat forever' self.emitter.emit(JMP(Absolute(top_label))) else: cls = { diff --git a/tests/SixtyPical Analysis.md b/tests/SixtyPical Analysis.md index 42e9f6b..0c0998b 100644 --- a/tests/SixtyPical Analysis.md +++ b/tests/SixtyPical Analysis.md @@ -1195,6 +1195,15 @@ this is an error too. | } ? UnmeaningfulReadError: z in main +The body of `repeat forever` can be empty. + + | routine main + | { + | repeat { + | } forever + | } + = ok + ### copy ### Can't `copy` from a memory location that isn't initialized. diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index 01b980e..2823eb8 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -297,6 +297,16 @@ Compiling `repeat forever`. = $0810 JMP $080F = $0813 RTS +The body of `repeat forever` can be empty. + + | routine main + | { + | repeat { + | } forever + | } + = $080D JMP $080D + = $0810 RTS + Indexed access. | byte one