Implement PRGINS
This commit is contained in:
@@ -3178,6 +3178,10 @@ class BuiltinFunction
|
|||||||
{
|
{
|
||||||
p.program.set(x.dup);
|
p.program.set(x.dup);
|
||||||
}
|
}
|
||||||
|
static void PRGINS(PetitComputer p, wstring line, int isBack)
|
||||||
|
{
|
||||||
|
p.program.insert(line, cast(bool)isBack);
|
||||||
|
}
|
||||||
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
|
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
|
||||||
static BuiltinFunctions[wstring] builtinFunctions;
|
static BuiltinFunctions[wstring] builtinFunctions;
|
||||||
static wstring getBasicName(BFD)(const wstring def)
|
static wstring getBasicName(BFD)(const wstring def)
|
||||||
|
|||||||
@@ -5,13 +5,130 @@ import std.container;
|
|||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
Slot slot;
|
||||||
|
slot.init();
|
||||||
|
slot.currentLine = 1;
|
||||||
|
assert(slot.get() == "\n");
|
||||||
|
slot.currentLine = 1;
|
||||||
|
slot.set("1");
|
||||||
|
assert(slot.get() == "\n");
|
||||||
|
assert(slot.get() == "");
|
||||||
|
slot.currentLine = 1;
|
||||||
|
assert(slot.get() == "1\n");
|
||||||
|
assert(slot.get() == "\n");
|
||||||
|
assert(slot.get() == "");
|
||||||
|
slot.currentLine = 2;
|
||||||
|
slot.set("2");
|
||||||
|
assert(slot.get() == "\n");
|
||||||
|
assert(slot.get() == "");
|
||||||
|
slot.currentLine = 1;
|
||||||
|
assert(slot.get() == "1\n");
|
||||||
|
assert(slot.get() == "2\n");
|
||||||
|
assert(slot.get() == "\n");
|
||||||
|
assert(slot.get() == "");
|
||||||
|
slot.currentLine = 1;
|
||||||
|
slot.set("A");
|
||||||
|
assert(slot.get() == "2\n");
|
||||||
|
assert(slot.get() == "\n");
|
||||||
|
assert(slot.get() == "");
|
||||||
|
slot.currentLine = 1;
|
||||||
|
assert(slot.get() == "A\n");
|
||||||
|
assert(slot.get() == "2\n");
|
||||||
|
assert(slot.get() == "\n");
|
||||||
|
assert(slot.get() == "");
|
||||||
|
slot.currentLine = 2;
|
||||||
|
slot.set("I\nJ");
|
||||||
|
assert(slot.get() == "\n");
|
||||||
|
assert(slot.get() == "");
|
||||||
|
slot.currentLine = 1;
|
||||||
|
assert(slot.get() == "A\n");
|
||||||
|
assert(slot.get() == "I\n");
|
||||||
|
assert(slot.get() == "J\n");
|
||||||
|
assert(slot.get() == "\n");
|
||||||
|
assert(slot.get() == "");
|
||||||
|
|
||||||
|
//PRGINS
|
||||||
|
slot.currentLine = 1;
|
||||||
|
slot.insert("3", false);
|
||||||
|
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() == "3\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;
|
||||||
|
slot.insert("4", true);
|
||||||
|
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() == "3\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.insert("5", false);
|
||||||
|
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() == "3\n");
|
||||||
|
assert(slot.get() == "5\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.insert("6", true);
|
||||||
|
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() == "3\n");
|
||||||
|
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() == "");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
struct Slot
|
struct Slot
|
||||||
{
|
{
|
||||||
DList!wstring program;
|
DList!wstring program;
|
||||||
DList!wstring.Range range;
|
DList!wstring.Range range;
|
||||||
this(T)(T)
|
void init()
|
||||||
{
|
{
|
||||||
program = make!(DList!wstring);
|
program = make!(DList!wstring)(["\n"w]);
|
||||||
range = program[];
|
range = program[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,9 +209,18 @@ struct Slot
|
|||||||
foreach(l; splitter(v, "\n"))
|
foreach(l; splitter(v, "\n"))
|
||||||
{
|
{
|
||||||
if (!range.empty && i == 0)
|
if (!range.empty && i == 0)
|
||||||
|
{
|
||||||
|
auto b = range.save;
|
||||||
|
b.popFront();
|
||||||
|
if (b.empty)
|
||||||
|
{
|
||||||
|
program.insertBefore(range, l ~ "\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
range.put(l ~ "\n");
|
range.put(l ~ "\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (range.empty)
|
if (range.empty)
|
||||||
@@ -109,6 +235,32 @@ struct Slot
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void insert(wstring line, bool isBack)
|
||||||
|
{
|
||||||
|
typeof(range) backup;
|
||||||
|
if (isBack)
|
||||||
|
{
|
||||||
|
backup = range.save;
|
||||||
|
range.popFront();
|
||||||
|
}
|
||||||
|
foreach(l; splitter(line, "\n"))
|
||||||
|
{
|
||||||
|
if (isBack)
|
||||||
|
{
|
||||||
|
//backup = range.save;
|
||||||
|
program.insertBefore(range, l ~ "\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
program.insertBefore(range, l ~ "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isBack)
|
||||||
|
{
|
||||||
|
range = backup;
|
||||||
|
range.popFront();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
@@ -122,7 +274,7 @@ class Program
|
|||||||
slot = new Slot[5];
|
slot = new Slot[5];
|
||||||
foreach(ref s; slot)
|
foreach(ref s; slot)
|
||||||
{
|
{
|
||||||
s = Slot(slot);
|
s.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void edit(int slot, int line)
|
void edit(int slot, int line)
|
||||||
@@ -143,4 +295,10 @@ class Program
|
|||||||
throw new UsePRGEDITBeforeAnyPRGFunction("PRGSET");
|
throw new UsePRGEDITBeforeAnyPRGFunction("PRGSET");
|
||||||
this.slot[currentSlot].set = v;
|
this.slot[currentSlot].set = v;
|
||||||
}
|
}
|
||||||
|
void insert(wstring line, bool isBack)
|
||||||
|
{
|
||||||
|
if (!PRGEDITused)
|
||||||
|
throw new UsePRGEDITBeforeAnyPRGFunction("PRGINS");
|
||||||
|
this.slot[currentSlot].insert(line, isBack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user