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