ダイレクトモードを実装
This commit is contained in:
@@ -27,6 +27,8 @@ class VMSlot
|
|||||||
{
|
{
|
||||||
bool isUsed;
|
bool isUsed;
|
||||||
DataTable globalDataTable;
|
DataTable globalDataTable;
|
||||||
|
//2MBらしい
|
||||||
|
//Code code[2 * 1024 * 1024 / Code.sizeof];
|
||||||
Code[] code;
|
Code[] code;
|
||||||
SourceLocation[] location;
|
SourceLocation[] location;
|
||||||
Value[] global;
|
Value[] global;
|
||||||
@@ -34,6 +36,7 @@ class VMSlot
|
|||||||
Function[wstring] functions;
|
Function[wstring] functions;
|
||||||
int[wstring] globalLabel;
|
int[wstring] globalLabel;
|
||||||
DebugInfo debugInfo;
|
DebugInfo debugInfo;
|
||||||
|
Value[wstring] directModeVariable;
|
||||||
}
|
}
|
||||||
class VM
|
class VM
|
||||||
{
|
{
|
||||||
@@ -57,11 +60,22 @@ class VM
|
|||||||
{
|
{
|
||||||
currentSlot = slots[slot];
|
currentSlot = slots[slot];
|
||||||
}
|
}
|
||||||
void directSlot(Code[] code, int len, VMVariable[wstring] globalTable, Function[wstring] functions, DataTable gdt/*GNU Debugging Tools*/,
|
void directSlot(int start, Code[] code, int len, VMVariable[wstring] globalTable, Function[wstring] functions, DataTable gdt/*GNU Debugging Tools*/,
|
||||||
int[wstring] globalLabel, DebugInfo dinfo)
|
int[wstring] globalLabel, DebugInfo dinfo)
|
||||||
{
|
{
|
||||||
this.pc = currentSlot.code.length;
|
this.pc = start;
|
||||||
this.currentSlot.code ~= code;
|
auto c = this.currentSlot;
|
||||||
|
c.globalTable = globalTable;
|
||||||
|
c.code = code;
|
||||||
|
sizediff_t oldlen = c.global.length;
|
||||||
|
sizediff_t addedvarcount = len - oldlen;
|
||||||
|
for(sizediff_t i = 0; i < addedvarcount; i++)
|
||||||
|
c.global ~= Value(ValueType.Void);
|
||||||
|
foreach(wstring k, VMVariable v ; globalTable)
|
||||||
|
{
|
||||||
|
if(v.index >= 0 && v.index >= oldlen)
|
||||||
|
c.global[v.index] = Value(v.type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void loadSlot(int slot, Code[] code, int len, VMVariable[wstring] globalTable, Function[wstring] functions, DataTable gdt/*GNU Debugging Tools*/,
|
void loadSlot(int slot, Code[] code, int len, VMVariable[wstring] globalTable, Function[wstring] functions, DataTable gdt/*GNU Debugging Tools*/,
|
||||||
int[wstring] globalLabel, DebugInfo dinfo)
|
int[wstring] globalLabel, DebugInfo dinfo)
|
||||||
|
|||||||
@@ -690,6 +690,10 @@ class Compiler
|
|||||||
}
|
}
|
||||||
void compileDefineFunction(DefineFunction node)
|
void compileDefineFunction(DefineFunction node)
|
||||||
{
|
{
|
||||||
|
if(isDirectMode)
|
||||||
|
{
|
||||||
|
throw new CantUseFromDirectMode();
|
||||||
|
}
|
||||||
auto skip = genCodeGoto();
|
auto skip = genCodeGoto();
|
||||||
Function func = new Function(cast(int)this.code.length, node.name, node.returnExpr, cast(int)node.arguments.length);
|
Function func = new Function(cast(int)this.code.length, node.name, node.returnExpr, cast(int)node.arguments.length);
|
||||||
Scope sc = new Scope(func);
|
Scope sc = new Scope(func);
|
||||||
@@ -1054,8 +1058,12 @@ class Compiler
|
|||||||
void compileDirectMode(VM vm)
|
void compileDirectMode(VM vm)
|
||||||
{
|
{
|
||||||
isDirectMode = true;
|
isDirectMode = true;
|
||||||
|
global = vm.currentSlot.globalTable;
|
||||||
|
auto start = vm.currentSlot.code.length;
|
||||||
|
this.code = vm.currentSlot.code;
|
||||||
|
globalIndex = vm.currentSlot.global.length;
|
||||||
compileProgram();
|
compileProgram();
|
||||||
vm.directSlot(code, globalIndex + 1, global, functions, globalScope.data, globalLabel, debugInfo);
|
vm.directSlot(start, code, globalIndex + 1, global, functions, globalScope.data, globalLabel, debugInfo);
|
||||||
}
|
}
|
||||||
VM compile()
|
VM compile()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -104,4 +104,14 @@ class SubscriptOutOfRange : SmileBasicError
|
|||||||
super("Subscript out of range");
|
super("Subscript out of range");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class CantUseFromDirectMode : SmileBasicError
|
||||||
|
{
|
||||||
|
this()
|
||||||
|
{
|
||||||
|
this.errnum = 43;
|
||||||
|
this.errprg = 0;//always 0
|
||||||
|
this.errline = 0;
|
||||||
|
super("Can't use from direct mode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1185,8 +1185,43 @@ class PetitComputer
|
|||||||
}
|
}
|
||||||
auto prg = input("", true);
|
auto prg = input("", true);
|
||||||
parser = new Parser(prg);
|
parser = new Parser(prg);
|
||||||
|
try
|
||||||
|
{
|
||||||
auto cc = parser.compiler;
|
auto cc = parser.compiler;
|
||||||
cc.compileDirectMode(vm);
|
cc.compileDirectMode(vm);
|
||||||
|
}
|
||||||
|
catch(SmileBasicError sbe)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
printConsole(sbe.getErrorMessage, "\n");
|
||||||
|
printConsole(sbe.getErrorMessage2, "\n");
|
||||||
|
//printConsole(sbe.to!string);
|
||||||
|
writeln(sbe.to!string);
|
||||||
|
writeln(sbe.getErrorMessage2);
|
||||||
|
auto loc = vm.currentLocation;
|
||||||
|
printConsole(loc.line, ":", loc.pos, ":", parser.getLine(loc));
|
||||||
|
}
|
||||||
|
catch(Throwable t)
|
||||||
|
{
|
||||||
|
writeln(t);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
catch(Throwable t)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
printConsole(t.to!string);
|
||||||
|
writeln(t);
|
||||||
|
printConsole(parser.getLine(vm.currentLocation));
|
||||||
|
}
|
||||||
|
catch(Throwable t)
|
||||||
|
{
|
||||||
|
writeln(t);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
vm.dump();
|
vm.dump();
|
||||||
running = true;
|
running = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user