1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-29 18:49:22 +00:00

Don't generate code for empty else blocks.

This commit is contained in:
Chris Pressey 2015-10-17 18:25:54 +01:00
parent b794d8d273
commit 070ffacf69
4 changed files with 4 additions and 5 deletions

View File

@ -178,7 +178,8 @@ def analyze_instr(instr, context, routines):
context1 = context.clone()
context2 = context.clone()
analyze_block(instr.block1, context1, routines)
analyze_block(instr.block2, context2, routines)
if instr.block2 is not None:
analyze_block(instr.block2, context2, routines)
for ref in context1.each_initialized():
context2.assert_initialized(ref, exception_class=InconsistentInitializationError)
for ref in context2.each_initialized():

View File

@ -176,7 +176,7 @@ class Compiler(object):
else_label = Label('else_label')
self.emitter.emit(cls(Relative(else_label)))
self.compile_block(instr.block1)
if instr.block2:
if instr.block2 is not None:
end_label = Label('end_label')
self.emitter.emit(JMP(Absolute(end_label)))
self.emitter.resolve_label(else_label)

View File

@ -172,8 +172,6 @@ class Parser(object):
block2 = None
if self.scanner.consume('else'):
block2 = self.block()
else:
block2 = Block(instrs=[])
return Instr(opcode='if', dest=None, src=src, block1=block1, block2=block2)
elif self.scanner.token in ("ld", "add", "sub", "cmp", "and", "or", "xor"):
opcode = self.scanner.token

View File

@ -143,4 +143,4 @@ Compiling `if` without `else`.
| ld y, 1
| }
| }
= 00c0a900d005a0014c0bc0a00260
= 00c0a900d002a00160