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