1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-25 23:49:17 +00:00

Correctly analyze repeat { ... } forever loops.

This commit is contained in:
Chris Pressey 2017-12-12 15:18:59 +00:00
parent 0145c6d34f
commit 4854077cce
6 changed files with 27 additions and 7 deletions

View File

@ -9,6 +9,7 @@ History of SixtyPical
in a `copy` to a vector is a routine that is defined further down in the source. 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, * Fixed bug which was preventing `if` branches to diverge in what they initialized,
if it was already initialized when going into the `if`. 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 0.9
--- ---

View File

@ -240,8 +240,6 @@ routine main
copy cinv, save_cinv copy cinv, save_cinv
copy our_cinv, cinv copy our_cinv, cinv
} }
// FIXME: find out why `repeat { } forever` does not analyze OK
repeat { repeat { } forever
ld a, 0
} until not z
} }

View File

@ -324,12 +324,14 @@ class Analyzer(object):
# it will always be executed at least once, so analyze it having # it will always be executed at least once, so analyze it having
# been executed the first time. # been executed the first time.
self.analyze_block(instr.block, context) 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 # now analyze it having been executed a second time, with the context
# of it having already been executed. # of it having already been executed.
self.analyze_block(instr.block, context) self.analyze_block(instr.block, context)
context.assert_meaningful(src) if src is not None:
context.assert_meaningful(src)
elif opcode == 'copy': elif opcode == 'copy':
# 1. check that their types are compatible # 1. check that their types are compatible

View File

@ -307,7 +307,7 @@ class Compiler(object):
elif opcode == 'repeat': elif opcode == 'repeat':
top_label = self.emitter.make_label() top_label = self.emitter.make_label()
self.compile_block(instr.block) self.compile_block(instr.block)
if src is None: if src is None: # indicates 'repeat forever'
self.emitter.emit(JMP(Absolute(top_label))) self.emitter.emit(JMP(Absolute(top_label)))
else: else:
cls = { cls = {

View File

@ -1195,6 +1195,15 @@ this is an error too.
| } | }
? UnmeaningfulReadError: z in main ? UnmeaningfulReadError: z in main
The body of `repeat forever` can be empty.
| routine main
| {
| repeat {
| } forever
| }
= ok
### copy ### ### copy ###
Can't `copy` from a memory location that isn't initialized. Can't `copy` from a memory location that isn't initialized.

View File

@ -297,6 +297,16 @@ Compiling `repeat forever`.
= $0810 JMP $080F = $0810 JMP $080F
= $0813 RTS = $0813 RTS
The body of `repeat forever` can be empty.
| routine main
| {
| repeat {
| } forever
| }
= $080D JMP $080D
= $0810 RTS
Indexed access. Indexed access.
| byte one | byte one