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