Fix DATA
This commit is contained in:
@@ -533,9 +533,6 @@ class VM
|
|||||||
auto bp = vm.stacki;
|
auto bp = vm.stacki;
|
||||||
vm.push(Value(vm.currentFunction));
|
vm.push(Value(vm.currentFunction));
|
||||||
vm.currentFunction = func;
|
vm.currentFunction = func;
|
||||||
vm.push(Value(vm.currentData));
|
|
||||||
vm.currentData.index = 0;
|
|
||||||
vm.currentData.table = func.scope_.data;
|
|
||||||
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;
|
||||||
@@ -1585,18 +1582,8 @@ class ReturnFunction : Code
|
|||||||
Value bp, pc;
|
Value bp, pc;
|
||||||
vm.poppc;//(pc);
|
vm.poppc;//(pc);
|
||||||
vm.pop(bp);
|
vm.pop(bp);
|
||||||
Value hae;
|
|
||||||
vm.pop(hae);
|
|
||||||
Value cfunc;
|
Value cfunc;
|
||||||
vm.pop(cfunc);
|
vm.pop(cfunc);
|
||||||
if (hae.type != ValueType.Data)
|
|
||||||
{
|
|
||||||
throw new TypeMismatch();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vm.currentData = hae.data;
|
|
||||||
}
|
|
||||||
if (cfunc.type != ValueType.Function)
|
if (cfunc.type != ValueType.Function)
|
||||||
{
|
{
|
||||||
throw new TypeMismatch();
|
throw new TypeMismatch();
|
||||||
@@ -2571,6 +2558,7 @@ class Exec : Code
|
|||||||
vm.slots[slot].execData.backtrace = vm.traceI;
|
vm.slots[slot].execData.backtrace = vm.traceI;
|
||||||
}
|
}
|
||||||
vm.setCurrentSlot(slot);
|
vm.setCurrentSlot(slot);
|
||||||
|
vm.currentData = vm.slots[slot].globalData;
|
||||||
vm.pc = 0 - 1;
|
vm.pc = 0 - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,20 +72,45 @@ class Scope
|
|||||||
}
|
}
|
||||||
class DataTable
|
class DataTable
|
||||||
{
|
{
|
||||||
Value[] data;
|
public this()
|
||||||
int[wstring] label;
|
|
||||||
void addData(Value data)
|
|
||||||
{
|
{
|
||||||
this.data ~= data;
|
data = new Data();
|
||||||
}
|
}
|
||||||
void addLabel(wstring label)
|
public this(DataTable table)
|
||||||
{
|
{
|
||||||
this.label[label] = cast(int)data.length;
|
this.data = table.data;
|
||||||
|
}
|
||||||
|
public size_t length()
|
||||||
|
{
|
||||||
|
return data.data.length;
|
||||||
|
}
|
||||||
|
public Value read(size_t index)
|
||||||
|
{
|
||||||
|
return data.data[index];
|
||||||
|
}
|
||||||
|
Data data;
|
||||||
|
int[wstring] label;
|
||||||
|
public void addLabel(wstring label)
|
||||||
|
{
|
||||||
|
this.label[label] = cast(int)data.data.length;
|
||||||
|
}
|
||||||
|
public void addData(Value data)
|
||||||
|
{
|
||||||
|
this.data.addData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Data
|
||||||
|
{
|
||||||
|
Value[] data;
|
||||||
|
public void addData(Value data)
|
||||||
|
{
|
||||||
|
this.data ~= data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class Function
|
class Function
|
||||||
{
|
{
|
||||||
static const frameSize = 4;
|
static const frameSize = 3;
|
||||||
int address;
|
int address;
|
||||||
wstring name;
|
wstring name;
|
||||||
int argCount;
|
int argCount;
|
||||||
@@ -891,6 +916,7 @@ class Compiler
|
|||||||
auto skip = genCodeGoto();
|
auto skip = genCodeGoto();
|
||||||
Function func = new Function(cast(int)this.code.length, node.name, node.returnExpr, cast(int)node.arguments.length, node.isCommon);
|
Function func = new Function(cast(int)this.code.length, node.name, node.returnExpr, cast(int)node.arguments.length, node.isCommon);
|
||||||
Scope sc = new Scope(func);
|
Scope sc = new Scope(func);
|
||||||
|
sc.data = new DataTable(globalScope.data);
|
||||||
foreach(wstring arg; node.arguments)
|
foreach(wstring arg; node.arguments)
|
||||||
{
|
{
|
||||||
func.defineArgumentIndex(arg, this);
|
func.defineArgumentIndex(arg, this);
|
||||||
@@ -1364,6 +1390,10 @@ class Compiler
|
|||||||
auto restore = cast(RestoreCodeS)c;
|
auto restore = cast(RestoreCodeS)c;
|
||||||
auto label = restore.scope_.data.label.get(restore.label, int.min);
|
auto label = restore.scope_.data.label.get(restore.label, int.min);
|
||||||
if (label == int.min)
|
if (label == int.min)
|
||||||
|
{
|
||||||
|
label = globalScope.data.label.get(restore.label, int.min);
|
||||||
|
}
|
||||||
|
if (label == int.min)
|
||||||
{
|
{
|
||||||
code[i] = new RestoreUndefinedLabelCode(restore.label);
|
code[i] = new RestoreUndefinedLabelCode(restore.label);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ struct Data
|
|||||||
int index;
|
int index;
|
||||||
void read(out Value value, VM vm)
|
void read(out Value value, VM vm)
|
||||||
{
|
{
|
||||||
if(index >= table.data.length)
|
if(index >= table.length)
|
||||||
throw new OutOfDATA();
|
throw new OutOfDATA();
|
||||||
value = table.data[index];
|
value = table.read(index);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user