diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 144635d..d0f6e07 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -3182,6 +3182,18 @@ class BuiltinFunction { p.program.insert(line, cast(bool)isBack); } + static void PRGDEL(PetitComputer p) + { + PRGDEL(p, 1); + } + static void PRGDEL(PetitComputer p, int count) + { + if (count == 0) + { + throw new OutOfRange("PRGDEL", 1); + } + p.program.delete_(count); + } //alias void function(PetitComputer, Value[], Value[]) BuiltinFunc; static BuiltinFunctions[wstring] builtinFunctions; static wstring getBasicName(BFD)(const wstring def) diff --git a/SMILEBASIC/program.d b/SMILEBASIC/program.d index b45e0ed..e85f8f6 100644 --- a/SMILEBASIC/program.d +++ b/SMILEBASIC/program.d @@ -120,6 +120,45 @@ unittest assert(slot.get() == "\n"); assert(slot.get() == ""); + //PRGDEL + slot.currentLine = 1; + slot.delete_(1); + assert(slot.get() == "5\n"); + assert(slot.get() == "6\n"); + assert(slot.get() == "4\n"); + assert(slot.get() == "A\n"); + assert(slot.get() == "I\n"); + assert(slot.get() == "J\n"); + assert(slot.get() == "\n"); + assert(slot.get() == ""); + slot.currentLine = 1; + assert(slot.get() == "5\n"); + assert(slot.get() == "6\n"); + assert(slot.get() == "4\n"); + assert(slot.get() == "A\n"); + assert(slot.get() == "I\n"); + assert(slot.get() == "J\n"); + assert(slot.get() == "\n"); + assert(slot.get() == ""); + slot.currentLine = 2; + slot.delete_(2); + assert(slot.get() == "A\n"); + assert(slot.get() == "I\n"); + assert(slot.get() == "J\n"); + assert(slot.get() == "\n"); + assert(slot.get() == ""); + slot.currentLine = 1; + assert(slot.get() == "5\n"); + assert(slot.get() == "A\n"); + assert(slot.get() == "I\n"); + assert(slot.get() == "J\n"); + assert(slot.get() == "\n"); + assert(slot.get() == ""); + slot.delete_(-1); + assert(slot.get() == ""); + slot.currentLine = 1; + assert(slot.get() == "\n"); + assert(slot.get() == ""); } struct Slot @@ -261,6 +300,18 @@ struct Slot range.popFront(); } } + void delete_(int count) + { + if (count < 0) + { + init(); + range.popFront(); + } + else + { + range = program.linearRemove(range.take(count)); + } + } } class Program @@ -301,4 +352,10 @@ class Program throw new UsePRGEDITBeforeAnyPRGFunction("PRGINS"); this.slot[currentSlot].insert(line, isBack); } + void delete_(int count) + { + if (!PRGEDITused) + throw new UsePRGEDITBeforeAnyPRGFunction("PRGDEL"); + this.slot[currentSlot].delete_(count); + } }