From a6866778f14fca0df8eb476cfc67faf2d8c305ec Mon Sep 17 00:00:00 2001 From: otya128 Date: Tue, 4 Jul 2017 15:43:16 +0900 Subject: [PATCH] Fix using local variable from direct mode --- SMILEBASIC/compiler.d | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/SMILEBASIC/compiler.d b/SMILEBASIC/compiler.d index a862e33..84f03c9 100644 --- a/SMILEBASIC/compiler.d +++ b/SMILEBASIC/compiler.d @@ -1276,7 +1276,11 @@ class Compiler Scope globalScope; Code[] compileProgram() { - Scope s = globalScope = new Scope(); + return compileProgram(new Scope()); + } + Code[] compileProgram(Scope scope_) + { + Scope s = globalScope = scope_; foreach(Statement i ; statements.statements) { if(i.type == NodeType.DefineFunction) @@ -1381,7 +1385,14 @@ class Compiler this.code = vm.currentSlot.code; globalIndex = cast(int)vm.currentSlot.global.length; functions = vm.currentSlot.functions; - compileProgram(); + if (vm.currentFunction) + { + auto sc = new Scope(vm.currentFunction); + sc.data = vm.currentData.table; + compileProgram(sc); + } + else + compileProgram(); registerSystemVariable(vm); vm.directSlot(start, code, globalIndex + 1, global, functions, globalScope.data, globalLabel, debugInfo); }