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