Add program.d
This commit is contained in:
@@ -2334,7 +2334,7 @@ class Exec : Code
|
||||
}
|
||||
wstring content;
|
||||
if (vm.petitcomputer.project.loadFile(file.project, "TXT", file.name, content))
|
||||
vm.petitcomputer.slot[slot].load(content);
|
||||
vm.petitcomputer.program.slot[slot].load(content);
|
||||
else
|
||||
throw new LoadFailed();//TODO:DIALOG?
|
||||
}
|
||||
@@ -2347,7 +2347,7 @@ class Exec : Code
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
import otya.smilebasic.parser;
|
||||
auto parser = new Parser(cast(immutable)vm.petitcomputer.slot[slot].text);
|
||||
auto parser = new Parser(cast(immutable)vm.petitcomputer.program.slot[slot].text);
|
||||
auto compiler = parser.compiler;
|
||||
VMAddress retaddr;
|
||||
if (slot != vm.currentSlotNumber)
|
||||
@@ -2381,7 +2381,7 @@ class Use : Code
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
import otya.smilebasic.parser;
|
||||
auto parser = new Parser(cast(immutable)vm.petitcomputer.slot[slot].text);
|
||||
auto parser = new Parser(cast(immutable)vm.petitcomputer.program.slot[slot].text);
|
||||
auto compiler = parser.compiler;
|
||||
compiler.compile(vm, slot);
|
||||
}
|
||||
|
||||
@@ -2269,7 +2269,7 @@ class BuiltinFunction
|
||||
}
|
||||
if(resname == "" || resname.indexOf("PRG") == 0)
|
||||
{
|
||||
int lot = p.currentSlot;
|
||||
int lot = p.program.currentSlot;
|
||||
if(resname != "" && resname != "PRG")
|
||||
{
|
||||
auto num = resname[3..$];
|
||||
@@ -2280,7 +2280,7 @@ class BuiltinFunction
|
||||
//not exist
|
||||
return;
|
||||
}
|
||||
p.slot[lot].load(txt);
|
||||
p.program.slot[lot].load(txt);
|
||||
return;
|
||||
}
|
||||
if(resname.indexOf("GRP") == 0)
|
||||
@@ -2301,16 +2301,16 @@ class BuiltinFunction
|
||||
{
|
||||
throw new IllegalFunctionCall("SAVE"/*, 1*/);
|
||||
}
|
||||
auto slot = p.currentSlot;
|
||||
auto slot = p.program.currentSlot;
|
||||
if (file.hasResourceNumber)
|
||||
{
|
||||
slot = file.resourceNumber;
|
||||
}
|
||||
if (slot >= p.slotSize)
|
||||
if (slot >= p.program.slotSize)
|
||||
{
|
||||
throw new IllegalFunctionCall("SAVE"/*, 1*/);
|
||||
}
|
||||
auto str = cast(immutable)p.slot[slot].text;
|
||||
auto str = cast(immutable)p.program.slot[slot].text;
|
||||
p.project.saveTextFile(file, str);
|
||||
}
|
||||
static void SAVE(PetitComputer p, wstring name, Value data)
|
||||
|
||||
@@ -20,6 +20,7 @@ import otya.smilebasic.project;
|
||||
import otya.smilebasic.console;
|
||||
import otya.smilebasic.graphic;
|
||||
import otya.smilebasic.dialog;
|
||||
import otya.smilebasic.program;
|
||||
const static rot_test_deg = 45f;
|
||||
const static rot_test_x = 0f;
|
||||
const static rot_test_y = 1f;
|
||||
@@ -1067,7 +1068,6 @@ class PetitComputer
|
||||
}
|
||||
Console console;
|
||||
Object buttonLock;
|
||||
Slot[] slot;
|
||||
bool isRunningDirectMode = false;
|
||||
GLenum textureScaleMode;
|
||||
int maincnt;
|
||||
@@ -1082,7 +1082,7 @@ class PetitComputer
|
||||
textureScaleMode = GL_NEAREST;
|
||||
}
|
||||
buttonLock = new Object();
|
||||
slot = new Slot[5];
|
||||
program = new Program();
|
||||
keybuffer = new Key[128];
|
||||
init();
|
||||
graphic = new Graphic2(this);
|
||||
@@ -1109,7 +1109,7 @@ class PetitComputer
|
||||
int oldpc;
|
||||
void runSlot(int lot)
|
||||
{
|
||||
parser = new Parser(cast(wstring)slot[lot].text);
|
||||
parser = new Parser(cast(wstring)program.slot[lot].text);
|
||||
try
|
||||
{
|
||||
vm = parser.compile();
|
||||
@@ -1133,7 +1133,7 @@ class PetitComputer
|
||||
nodirectmode = true;
|
||||
if (nodirectmode)
|
||||
{
|
||||
slot[0].load(readText(inputfile).to!wstring);
|
||||
program.slot[0].load(readText(inputfile).to!wstring);
|
||||
runSlot(0);
|
||||
}
|
||||
else
|
||||
@@ -1209,7 +1209,7 @@ class PetitComputer
|
||||
writeln(sbe.to!string);
|
||||
writeln(sbe.getErrorMessage2);
|
||||
auto loc = vm.currentLocation;
|
||||
console.print(vm.currentSlotNumber, ":", loc.line, ":", loc.pos, ":", slot[vm.currentSlotNumber].getLine(loc));
|
||||
console.print(vm.currentSlotNumber, ":", loc.line, ":", loc.pos, ":", program.slot[vm.currentSlotNumber].getLine(loc));
|
||||
}
|
||||
catch(Throwable t)
|
||||
{
|
||||
@@ -1225,7 +1225,7 @@ class PetitComputer
|
||||
console.print("\n");
|
||||
writeln(t);
|
||||
auto loc = vm.currentLocation;
|
||||
console.print(vm.currentSlotNumber, ":", loc.line, ":", loc.pos, ":", slot[vm.currentSlotNumber].getLine(loc));
|
||||
console.print(vm.currentSlotNumber, ":", loc.line, ":", loc.pos, ":", program.slot[vm.currentSlotNumber].getLine(loc));
|
||||
}
|
||||
catch(Throwable t)
|
||||
{
|
||||
@@ -1278,7 +1278,7 @@ class PetitComputer
|
||||
writeln(sbe.getErrorMessage2);
|
||||
writeln(sbe.func);
|
||||
loc = vm.currentLocation;
|
||||
console.print(vm.currentSlotNumber, ":", loc.line, ":", loc.pos, ":", slot[vm.currentSlotNumber].getLine(loc));
|
||||
console.print(vm.currentSlotNumber, ":", loc.line, ":", loc.pos, ":", program.slot[vm.currentSlotNumber].getLine(loc));
|
||||
}
|
||||
catch(Throwable t)
|
||||
{
|
||||
@@ -1293,7 +1293,7 @@ class PetitComputer
|
||||
console.print(t.to!string);
|
||||
console.print("\n");
|
||||
writeln(t);
|
||||
console.print(vm.currentSlotNumber, ":", loc.line, ":", loc.pos, ":", slot[vm.currentSlotNumber].getLine(vm.currentLocation));
|
||||
console.print(vm.currentSlotNumber, ":", loc.line, ":", loc.pos, ":", program.slot[vm.currentSlotNumber].getLine(vm.currentLocation));
|
||||
}
|
||||
catch(Throwable t)
|
||||
{
|
||||
@@ -1672,8 +1672,8 @@ class PetitComputer
|
||||
updateWindowSize();
|
||||
}
|
||||
|
||||
int currentSlot;
|
||||
int slotSize = 4;
|
||||
Program program;
|
||||
|
||||
//プチコン内部表現はRGB5_A1
|
||||
static uint toGLColor(GLenum format, ubyte r, ubyte g, ubyte b, ubyte a)
|
||||
{
|
||||
|
||||
55
SMILEBASIC/program.d
Normal file
55
SMILEBASIC/program.d
Normal 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];
|
||||
}
|
||||
}
|
||||
2
dub.json
2
dub.json
@@ -4,7 +4,7 @@
|
||||
"derelict-sdl2": "~>1.9.7",
|
||||
"derelict-gl3": "*"
|
||||
},
|
||||
"sourceFiles": ["SMILEBASIC/bg.d","SMILEBASIC/builtinfunctions.d","SMILEBASIC/compiler.d","SMILEBASIC/error.d","SMILEBASIC/main.d","SMILEBASIC/node.d","SMILEBASIC/parser.d","SMILEBASIC/petitcomputer.d","SMILEBASIC/sprite.d","SMILEBASIC/systemvariable.d","SMILEBASIC/token.d","SMILEBASIC/type.d","SMILEBASIC/VM.d","SMILEBASIC/project.d","SMILEBASIC/console.d","SMILEBASIC/graphic.d","SMILEBASIC/dialog.d","SMILEBASIC/data.d"],
|
||||
"sourceFiles": ["SMILEBASIC/bg.d","SMILEBASIC/builtinfunctions.d","SMILEBASIC/compiler.d","SMILEBASIC/error.d","SMILEBASIC/main.d","SMILEBASIC/node.d","SMILEBASIC/parser.d","SMILEBASIC/petitcomputer.d","SMILEBASIC/sprite.d","SMILEBASIC/systemvariable.d","SMILEBASIC/token.d","SMILEBASIC/type.d","SMILEBASIC/VM.d","SMILEBASIC/project.d","SMILEBASIC/console.d","SMILEBASIC/graphic.d","SMILEBASIC/dialog.d","SMILEBASIC/data.d","SMILEBASIC/program.d"],
|
||||
"targetType": "executable",
|
||||
"buildRequirements": ["allowWarnings"],
|
||||
"targetPath": "out",
|
||||
|
||||
Reference in New Issue
Block a user