From 6b2a065cb71afd1896d3ac679c7be1e974cde4ce Mon Sep 17 00:00:00 2001 From: otya128 Date: Wed, 7 Dec 2016 20:12:58 +0900 Subject: [PATCH] Fix Goto/GosubExpr --- SMILEBASIC/VM.d | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/SMILEBASIC/VM.d b/SMILEBASIC/VM.d index 5c49534..a76f48a 100644 --- a/SMILEBASIC/VM.d +++ b/SMILEBASIC/VM.d @@ -837,12 +837,20 @@ class GotoExpr : Code vm.pop(label); if(label.isString) { + int pc; if (sc && sc.func) { - vm.pc = sc.func.label[label.castString] - 1; - return; + pc = sc.func.label.get(label.castString, int.min); } - vm.pc = vm.currentSlot.globalLabel[label.castString] - 1; + else + { + pc = vm.currentSlot.globalLabel.get(label.castString, int.min); + } + if (pc == int.min) + { + throw new UndefinedLabel(); + } + vm.pc = pc - 1; } else { @@ -896,13 +904,21 @@ class GosubExpr : Code vm.pop(label); if(label.isString) { - vm.pushpc;//vm.push(Value(vm.pc)); + vm.pushpc; + int pc; if (sc && sc.func) { - vm.pc = sc.func.label[label.castString] - 1; - return; + pc = sc.func.label.get(label.castString, int.min); } - vm.pc = vm.currentSlot.globalLabel[label.castString] - 1; + else + { + pc = vm.currentSlot.globalLabel.get(label.castString, int.min); + } + if (pc == int.min) + { + throw new UndefinedLabel(); + } + vm.pc = pc - 1; } else {