From bd352d81f37deee1d1a4b88d5b0eeba153d15964 Mon Sep 17 00:00:00 2001 From: otya128 Date: Sun, 4 Dec 2016 16:30:31 +0900 Subject: [PATCH] Add Undefined Label Error --- SMILEBASIC/compiler.d | 14 ++++++++++++-- SMILEBASIC/error.d | 12 ++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/SMILEBASIC/compiler.d b/SMILEBASIC/compiler.d index ab53a6e..5b3d6cd 100644 --- a/SMILEBASIC/compiler.d +++ b/SMILEBASIC/compiler.d @@ -1167,11 +1167,21 @@ class Compiler auto label = cast(GotoS)c; if(label.sc.func) { - code[i] = new GotoAddr(label.sc.func.label[label.label]); + int addr = label.sc.func.label.get(label.label, int.min); + if (addr == int.min) + { + throw new UndefinedLabel(label.label); + } + code[i] = new GotoAddr(addr); } else { - code[i] = new GotoAddr(globalLabel[label.label]); + int addr = globalLabel.get(label.label, int.min); + if (addr == int.min) + { + throw new UndefinedLabel(label.label); + } + code[i] = new GotoAddr(addr); } } if(c.type == CodeType.GosubS) diff --git a/SMILEBASIC/error.d b/SMILEBASIC/error.d index 2a24483..f4c622a 100644 --- a/SMILEBASIC/error.d +++ b/SMILEBASIC/error.d @@ -96,6 +96,18 @@ class OutOfDATA : SmileBasicError super("Out of DATA"); } } +class UndefinedLabel : SmileBasicError +{ + this() + { + this.errnum = 14; + super("Undefined label"); + } + this(wstring label) + { + this(); + } +} class UndefinedVariable : SmileBasicError { this()