diff --git a/eg/goto.60p b/eg/goto.60p new file mode 100644 index 0000000..5c8c0f8 --- /dev/null +++ b/eg/goto.60p @@ -0,0 +1,15 @@ +routine chrout + inputs a + trashes a + @ 65490 + +routine bar trashes a, z, n { + ld a, 66 + call chrout +} + +routine main trashes a, z, n { + ld a, 65 + call chrout + goto bar +} diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index da96c30..b47432b 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -203,6 +203,15 @@ class Compiler(object): self.emitter.emit(JMP(Indirect(label))) else: raise NotImplementedError + elif opcode == 'goto': + location = instr.location + label = self.labels[instr.location.name] + if isinstance(location.type, RoutineType): + self.emitter.emit(JMP(Absolute(label))) + elif isinstance(location.type, VectorType): + self.emitter.emit(JMP(Indirect(label))) + else: + raise NotImplementedError elif opcode == 'if': cls = { False: { diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index 156f110..a909849 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -274,4 +274,16 @@ Indirect call. | copy bar, foo | call foo | } - = 00c0 + = 00c0wewillfixthislater + +goto. + + | routine bar outputs x trashes z, n { + | ld x, 200 + | } + | + | routine main outputs x trashes a, z, n { + | ld y, 200 + | goto bar + | } + = 00c0a0c84c06c060a2c860