1
0

Add program.d

This commit is contained in:
otya128
2016-12-27 17:16:54 +09:00
parent e1888d5032
commit 3ab1c8e6c8
5 changed files with 74 additions and 19 deletions

55
SMILEBASIC/program.d Normal file
View File

@@ -0,0 +1,55 @@
module otya.smilebasic.program;
import std.container;
struct Slot
{
DList!wstring program;
void load(wstring data)
{
import std.algorithm;
program.clear();
foreach(l; splitter(data, "\n"))
{
program.insertBack(l ~ '\n');
}
}
wchar[] text()
{
import std.algorithm.iteration, std.outbuffer;
auto buffer = new OutBuffer();
buffer.reserve(program.opSlice.map!"(a.length + 1) * 2".sum);
foreach(line; program)
{
buffer.write(line);
}
ubyte[] progbuff = buffer.toBytes;
wchar[] progbuff2 = (cast(wchar*)progbuff.ptr)[0..progbuff.length / 2];
return progbuff2;
}
import otya.smilebasic.token;
wstring getLine(SourceLocation loc)
{
import std.string;
int i;
foreach (line; program)
{
i++;
if (i == loc.line)
return line;
}
return "";
}
}
class Program
{
Slot[] slot;
int currentSlot;
int currentLine = 1;
int slotSize = 4;
this()
{
slot = new Slot[5];
}
}