Fix DATA
This commit is contained in:
@@ -37,7 +37,7 @@ class VMSlot
|
|||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
bool isUsed;
|
bool isUsed;
|
||||||
DataTable globalDataTable;
|
otya.smilebasic.type.Data globalData;
|
||||||
//2MBらしい
|
//2MBらしい
|
||||||
//Code code[2 * 1024 * 1024 / Code.sizeof];
|
//Code code[2 * 1024 * 1024 / Code.sizeof];
|
||||||
Code[] code;
|
Code[] code;
|
||||||
@@ -132,7 +132,7 @@ class VM
|
|||||||
f.slot = s;
|
f.slot = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.globalDataTable = gdt;
|
s.globalData = otya.smilebasic.type.Data(gdt, 0);
|
||||||
s.globalLabel = globalLabel;
|
s.globalLabel = globalLabel;
|
||||||
s.debugInfo = dinfo;
|
s.debugInfo = dinfo;
|
||||||
}
|
}
|
||||||
@@ -162,6 +162,7 @@ class VM
|
|||||||
this.petitcomputer = petitcomputer;
|
this.petitcomputer = petitcomputer;
|
||||||
traceI = 0;
|
traceI = 0;
|
||||||
bp = 0;//globalを実行なのでbaseは0(グローバル変数をスタックに取るようにしない限り)(挙動的にスタックに確保していなさそう)
|
bp = 0;//globalを実行なのでbaseは0(グローバル変数をスタックに取るようにしない限り)(挙動的にスタックに確保していなさそう)
|
||||||
|
currentData = this.currentSlot.globalData;
|
||||||
}
|
}
|
||||||
void processBreakPoint()
|
void processBreakPoint()
|
||||||
{
|
{
|
||||||
@@ -274,24 +275,25 @@ class VM
|
|||||||
}
|
}
|
||||||
return "undefined variable";
|
return "undefined variable";
|
||||||
}
|
}
|
||||||
|
otya.smilebasic.type.Data currentData;//DATAの位置は全スロット共通
|
||||||
Value readData()
|
Value readData()
|
||||||
{
|
{
|
||||||
Value value;
|
Value value;
|
||||||
this.currentSlot.globalDataTable.read(value, this);
|
currentData.read(value, this);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
void restoreData(wstring label)
|
void restoreData(wstring label)
|
||||||
{
|
{
|
||||||
this.currentSlot.globalDataTable.dataIndex = this.currentSlot.globalDataTable.label[label];
|
currentData.index = currentData.table.label[label];
|
||||||
}
|
}
|
||||||
int olddti;
|
int olddti;
|
||||||
void pushDataIndex()
|
void pushDataIndex()
|
||||||
{
|
{
|
||||||
olddti = this.currentSlot.globalDataTable.dataIndex;
|
olddti = this.currentSlot.globalData.index;
|
||||||
}
|
}
|
||||||
void popDataIndex()
|
void popDataIndex()
|
||||||
{
|
{
|
||||||
this.currentSlot.globalDataTable.dataIndex = olddti;
|
this.currentSlot.globalData.index = olddti;
|
||||||
}
|
}
|
||||||
void pushBackTrace(wstring name)
|
void pushBackTrace(wstring name)
|
||||||
{
|
{
|
||||||
@@ -1339,6 +1341,14 @@ class ReturnFunction : Code
|
|||||||
vm.pop(bp);
|
vm.pop(bp);
|
||||||
Value hae;
|
Value hae;
|
||||||
vm.pop(hae);
|
vm.pop(hae);
|
||||||
|
if (hae.type != ValueType.Data)
|
||||||
|
{
|
||||||
|
throw new TypeMismatch();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vm.currentData = hae.data;
|
||||||
|
}
|
||||||
vm.stacki -= func.argCount;
|
vm.stacki -= func.argCount;
|
||||||
if(func.returnExpr)
|
if(func.returnExpr)
|
||||||
{
|
{
|
||||||
@@ -1409,7 +1419,7 @@ class CallFunctionCode : Code
|
|||||||
vm.pushBackTrace(name);
|
vm.pushBackTrace(name);
|
||||||
//TODO:args
|
//TODO:args
|
||||||
auto bp = vm.stacki;
|
auto bp = vm.stacki;
|
||||||
vm.push(Value());
|
vm.push(Value(vm.currentData));
|
||||||
vm.push(Value(vm.bp));
|
vm.push(Value(vm.bp));
|
||||||
vm.pushpc;//vm.push(Value(vm.pc));
|
vm.pushpc;//vm.push(Value(vm.pc));
|
||||||
vm.bp = bp;
|
vm.bp = bp;
|
||||||
@@ -1482,7 +1492,7 @@ class CallFunctionS : Code
|
|||||||
}
|
}
|
||||||
//TODO:args
|
//TODO:args
|
||||||
auto bp = vm.stacki;
|
auto bp = vm.stacki;
|
||||||
vm.push(Value());
|
vm.push(Value(vm.currentData));
|
||||||
vm.push(Value(vm.bp));
|
vm.push(Value(vm.bp));
|
||||||
vm.pushpc;//vm.push(Value(vm.pc));
|
vm.pushpc;//vm.push(Value(vm.pc));
|
||||||
vm.bp = bp;
|
vm.bp = bp;
|
||||||
@@ -1765,7 +1775,7 @@ class ReadCode : Code
|
|||||||
for(int i = 0; i < count; i++)
|
for(int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
Value data;
|
Value data;
|
||||||
vm.currentSlot.globalDataTable.read(data, vm);
|
vm.currentData.read(data, vm);
|
||||||
vm.push(data);
|
vm.push(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1800,7 +1810,8 @@ class RestoreCode : Code
|
|||||||
}
|
}
|
||||||
override void execute(VM vm)
|
override void execute(VM vm)
|
||||||
{
|
{
|
||||||
datatable.dataIndex = label;
|
vm.currentData.table = datatable;
|
||||||
|
vm.currentData.index = label;
|
||||||
}
|
}
|
||||||
override string toString(VM vm)
|
override string toString(VM vm)
|
||||||
{
|
{
|
||||||
@@ -1838,11 +1849,13 @@ class RestoreExprCode : Code
|
|||||||
throw new TypeMismatch();
|
throw new TypeMismatch();
|
||||||
if (label.castDString in datatable.label)
|
if (label.castDString in datatable.label)
|
||||||
{
|
{
|
||||||
datatable.dataIndex = datatable.label[label.castDString];
|
vm.currentData.table = datatable;
|
||||||
|
vm.currentData.index = datatable.label[label.castDString];
|
||||||
}
|
}
|
||||||
else if (label.castDString in vm.currentSlot.globalDataTable.label)
|
else if (label.castDString in vm.currentSlot.globalData.table.label)
|
||||||
{
|
{
|
||||||
datatable.dataIndex = vm.currentSlot.globalDataTable.label[label.castDString];
|
vm.currentData.table = vm.currentSlot.globalData.table;
|
||||||
|
vm.currentData.index = vm.currentSlot.globalData.table.label[label.castDString];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,8 +73,6 @@ class DataTable
|
|||||||
{
|
{
|
||||||
Value[] data;
|
Value[] data;
|
||||||
int[wstring] label;
|
int[wstring] label;
|
||||||
//dataIndexは関数ごとに別じゃないといけない
|
|
||||||
int dataIndex;
|
|
||||||
void addData(Value data)
|
void addData(Value data)
|
||||||
{
|
{
|
||||||
this.data ~= data;
|
this.data ~= data;
|
||||||
@@ -83,13 +81,6 @@ class DataTable
|
|||||||
{
|
{
|
||||||
this.label[label] = cast(int)data.length;
|
this.label[label] = cast(int)data.length;
|
||||||
}
|
}
|
||||||
void read(out Value value, VM vm)
|
|
||||||
{
|
|
||||||
if(dataIndex >= data.length)
|
|
||||||
throw new OutOfDATA();
|
|
||||||
value = data[dataIndex];
|
|
||||||
dataIndex++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
class Function
|
class Function
|
||||||
{
|
{
|
||||||
@@ -1153,7 +1144,7 @@ class Compiler
|
|||||||
break;
|
break;
|
||||||
case NodeType.Data:
|
case NodeType.Data:
|
||||||
{
|
{
|
||||||
auto data = cast(Data)i;
|
auto data = cast(otya.smilebasic.node.Data)i;
|
||||||
foreach(j; data.data)
|
foreach(j; data.data)
|
||||||
s.data.addData(j.toSBImm);
|
s.data.addData(j.toSBImm);
|
||||||
}
|
}
|
||||||
@@ -1309,7 +1300,7 @@ class Compiler
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
code[i] = new RestoreCode(label, s.data);
|
code[i] = new RestoreCode(label, restore.scope_.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1272,9 +1272,9 @@ class Parser
|
|||||||
} while(token.type == TokenType.Comma);
|
} while(token.type == TokenType.Comma);
|
||||||
return on;
|
return on;
|
||||||
}
|
}
|
||||||
Data dataStatement()
|
otya.smilebasic.node.Data dataStatement()
|
||||||
{
|
{
|
||||||
Data data = new Data(lex.location);
|
otya.smilebasic.node.Data data = new otya.smilebasic.node.Data(lex.location);
|
||||||
lex.popFront();
|
lex.popFront();
|
||||||
auto token = lex.front();
|
auto token = lex.front();
|
||||||
while(true)
|
while(true)
|
||||||
|
|||||||
@@ -17,6 +17,21 @@ enum ValueType : byte
|
|||||||
DoubleReference,
|
DoubleReference,
|
||||||
StringReference,
|
StringReference,
|
||||||
StringArrayReference,
|
StringArrayReference,
|
||||||
|
Data,
|
||||||
|
}
|
||||||
|
import otya.smilebasic.compiler;
|
||||||
|
import otya.smilebasic.vm;
|
||||||
|
struct Data
|
||||||
|
{
|
||||||
|
DataTable table;
|
||||||
|
int index;
|
||||||
|
void read(out Value value, VM vm)
|
||||||
|
{
|
||||||
|
if(index >= table.data.length)
|
||||||
|
throw new OutOfDATA();
|
||||||
|
value = table.data[index];
|
||||||
|
index++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
struct VMAddress
|
struct VMAddress
|
||||||
{
|
{
|
||||||
@@ -40,6 +55,7 @@ struct Value
|
|||||||
ArrayReference!double doubleReference;
|
ArrayReference!double doubleReference;
|
||||||
ArrayReference!wchar stringReference;
|
ArrayReference!wchar stringReference;
|
||||||
ArrayReference!(Array!wchar) stringArrayReference;
|
ArrayReference!(Array!wchar) stringArrayReference;
|
||||||
|
Data data;
|
||||||
}
|
}
|
||||||
this(int value)
|
this(int value)
|
||||||
{
|
{
|
||||||
@@ -108,6 +124,11 @@ struct Value
|
|||||||
this.type = ValueType.StringArrayReference;
|
this.type = ValueType.StringArrayReference;
|
||||||
stringArrayReference = r;
|
stringArrayReference = r;
|
||||||
}
|
}
|
||||||
|
this(Data data)
|
||||||
|
{
|
||||||
|
this.type = ValueType.Data;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
void castOp(ValueType type)
|
void castOp(ValueType type)
|
||||||
{
|
{
|
||||||
switch(type)
|
switch(type)
|
||||||
|
|||||||
Reference in New Issue
Block a user