diff --git a/src/sixtypical/analyzer.py b/src/sixtypical/analyzer.py index c0b4e02..656bf2b 100644 --- a/src/sixtypical/analyzer.py +++ b/src/sixtypical/analyzer.py @@ -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(): diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index be5b5a8..9b48d80 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -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) diff --git a/src/sixtypical/parser.py b/src/sixtypical/parser.py index da59040..d5b1b2c 100644 --- a/src/sixtypical/parser.py +++ b/src/sixtypical/parser.py @@ -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 diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index bdf7b4c..8888508 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -143,4 +143,4 @@ Compiling `if` without `else`. | ld y, 1 | } | } - = 00c0a900d005a0014c0bc0a00260 + = 00c0a900d002a00160