1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-07 06:29:32 +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.
* 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
---

View File

@ -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
}

View File

@ -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

View File

@ -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 = {

View File

@ -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.

View File

@ -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