From 0fd1c75b3d2654c9131bfb0c61b9da7d3eeedfba Mon Sep 17 00:00:00 2001 From: otya128 Date: Fri, 2 Sep 2016 22:47:21 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=96=E3=83=AC=E3=83=BC=E3=82=AF=E3=83=9D?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=83=88=E3=82=92=E4=BB=98=E3=81=91=E3=82=89?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SMILEBASIC/VM.d | 11 +++++++++++ SMILEBASIC/compiler.d | 24 +++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/SMILEBASIC/VM.d b/SMILEBASIC/VM.d index 75ed204..a2ac9fe 100644 --- a/SMILEBASIC/VM.d +++ b/SMILEBASIC/VM.d @@ -110,6 +110,7 @@ class VM bp = 0;//globalを実行なのでbaseは0(グローバル変数をスタックに取るようにしない限り)(挙動的にスタックに確保していなさそう) for(pc = 0; pc < this.currentSlot.code.length; pc++) { + processBreakPoint; currentSlot.code[pc].execute(this); } if(stacki != 0) @@ -126,10 +127,20 @@ class VM this.petitcomputer = petitcomputer; bp = 0;//globalを実行なのでbaseは0(グローバル変数をスタックに取るようにしない限り)(挙動的にスタックに確保していなさそう) } + void processBreakPoint() + { + if (currentSlot.debugInfo.location[pc].isBreakPoint) + { + //TODO:まともにする + writefln("break point\nslot:%d,pc:%d,line:%d", currentSlotNumber, pc, currentSlot.debugInfo.location[pc].location.line); + readln(); + } + } bool runStep() { if(pc < this.currentSlot.code.length) { + processBreakPoint; currentSlot.code[pc].execute(this); pc++; return true; diff --git a/SMILEBASIC/compiler.d b/SMILEBASIC/compiler.d index 2cad417..b3f38f8 100644 --- a/SMILEBASIC/compiler.d +++ b/SMILEBASIC/compiler.d @@ -6,25 +6,43 @@ import otya.smilebasic.type; import otya.smilebasic.error; import otya.smilebasic.systemvariable; import std.stdio; +struct DebugData +{ + SourceLocation location; + bool isBreakPoint; +} class DebugInfo { sizediff_t old; - std.container.Array!SourceLocation location; + std.container.Array!DebugData location; + std.container.Array!int line; this() { } void addLocation(SourceLocation loc, Code[] code) { + while (line.length < loc.line) + { + line ~= location.length; + } for(int i = 0; i < code.length - old; i++) { - location ~= loc; + location ~= DebugData (loc, false); } old = location.length; } SourceLocation getLocationByAddress(int addr) { if(location.length <= addr) return SourceLocation(0, 0, 0); - return location[addr]; + return location[addr].location; + } + void setBreakPoint(int line) + { + location[this.line[line - 1]].isBreakPoint = true; + } + bool isBreakPoint(int line) + { + return location[this.line[line - 1]].isBreakPoint; } } class Scope