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:
parent
0145c6d34f
commit
4854077cce
@ -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
|
||||||
---
|
---
|
||||||
|
@ -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
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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 = {
|
||||||
|
@ -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.
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user