Add function data to stack frame
This commit is contained in:
@@ -276,6 +276,7 @@ class VM
|
|||||||
return "undefined variable";
|
return "undefined variable";
|
||||||
}
|
}
|
||||||
otya.smilebasic.type.Data currentData;//DATAの位置は全スロット共通
|
otya.smilebasic.type.Data currentData;//DATAの位置は全スロット共通
|
||||||
|
Function currentFunction;
|
||||||
Value readData()
|
Value readData()
|
||||||
{
|
{
|
||||||
Value value;
|
Value value;
|
||||||
@@ -1342,6 +1343,8 @@ class ReturnFunction : Code
|
|||||||
vm.pop(bp);
|
vm.pop(bp);
|
||||||
Value hae;
|
Value hae;
|
||||||
vm.pop(hae);
|
vm.pop(hae);
|
||||||
|
Value cfunc;
|
||||||
|
vm.pop(cfunc);
|
||||||
if (hae.type != ValueType.Data)
|
if (hae.type != ValueType.Data)
|
||||||
{
|
{
|
||||||
throw new TypeMismatch();
|
throw new TypeMismatch();
|
||||||
@@ -1350,6 +1353,14 @@ class ReturnFunction : Code
|
|||||||
{
|
{
|
||||||
vm.currentData = hae.data;
|
vm.currentData = hae.data;
|
||||||
}
|
}
|
||||||
|
if (cfunc.type != ValueType.Function)
|
||||||
|
{
|
||||||
|
throw new TypeMismatch();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vm.currentFunction = cfunc.func;
|
||||||
|
}
|
||||||
vm.stacki -= func.argCount;
|
vm.stacki -= func.argCount;
|
||||||
if(func.returnExpr)
|
if(func.returnExpr)
|
||||||
{
|
{
|
||||||
@@ -1420,6 +1431,8 @@ 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.currentFunction));
|
||||||
|
vm.currentFunction = func;
|
||||||
vm.push(Value(vm.currentData));
|
vm.push(Value(vm.currentData));
|
||||||
vm.currentData.index = 0;
|
vm.currentData.index = 0;
|
||||||
vm.currentData.table = func.scope_.data;
|
vm.currentData.table = func.scope_.data;
|
||||||
@@ -1495,6 +1508,8 @@ class CallFunctionS : Code
|
|||||||
}
|
}
|
||||||
//TODO:args
|
//TODO:args
|
||||||
auto bp = vm.stacki;
|
auto bp = vm.stacki;
|
||||||
|
vm.push(Value(vm.currentFunction));
|
||||||
|
vm.currentFunction = func;
|
||||||
vm.push(Value(vm.currentData));
|
vm.push(Value(vm.currentData));
|
||||||
vm.currentData.index = 0;
|
vm.currentData.index = 0;
|
||||||
vm.currentData.table = func.scope_.data;
|
vm.currentData.table = func.scope_.data;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class DataTable
|
|||||||
}
|
}
|
||||||
class Function
|
class Function
|
||||||
{
|
{
|
||||||
static const frameSize = 3;
|
static const frameSize = 4;
|
||||||
int address;
|
int address;
|
||||||
wstring name;
|
wstring name;
|
||||||
int argCount;
|
int argCount;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ enum ValueType : byte
|
|||||||
StringReference,
|
StringReference,
|
||||||
StringArrayReference,
|
StringArrayReference,
|
||||||
Data,
|
Data,
|
||||||
|
Function,
|
||||||
}
|
}
|
||||||
import otya.smilebasic.compiler;
|
import otya.smilebasic.compiler;
|
||||||
import otya.smilebasic.vm;
|
import otya.smilebasic.vm;
|
||||||
@@ -56,6 +57,7 @@ struct Value
|
|||||||
ArrayReference!wchar stringReference;
|
ArrayReference!wchar stringReference;
|
||||||
ArrayReference!(Array!wchar) stringArrayReference;
|
ArrayReference!(Array!wchar) stringArrayReference;
|
||||||
Data data;
|
Data data;
|
||||||
|
Function func;
|
||||||
}
|
}
|
||||||
this(int value)
|
this(int value)
|
||||||
{
|
{
|
||||||
@@ -129,6 +131,11 @@ struct Value
|
|||||||
this.type = ValueType.Data;
|
this.type = ValueType.Data;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
this(Function func)
|
||||||
|
{
|
||||||
|
this.type = ValueType.Function;
|
||||||
|
this.func = func;
|
||||||
|
}
|
||||||
void castOp(ValueType type)
|
void castOp(ValueType type)
|
||||||
{
|
{
|
||||||
switch(type)
|
switch(type)
|
||||||
|
|||||||
Reference in New Issue
Block a user