COMMON DEF(WIP)
This commit is contained in:
@@ -42,6 +42,7 @@ class VMSlot
|
|||||||
class VM
|
class VM
|
||||||
{
|
{
|
||||||
VMSlot[5] slots;
|
VMSlot[5] slots;
|
||||||
|
Function[wstring] commonFunctions;
|
||||||
int slot;
|
int slot;
|
||||||
VMSlot currentSlot;
|
VMSlot currentSlot;
|
||||||
int stacki;
|
int stacki;
|
||||||
@@ -1264,12 +1265,18 @@ class CallFunctionCode : Code
|
|||||||
this.argCount = argCount;
|
this.argCount = argCount;
|
||||||
this.outArgCount = outArgCount;
|
this.outArgCount = outArgCount;
|
||||||
}
|
}
|
||||||
|
Function func;
|
||||||
|
void resolve(VM vm)
|
||||||
|
{
|
||||||
|
func = vm.currentSlot.functions.get(name, null);
|
||||||
|
throw new SyntaxError(name);
|
||||||
|
}
|
||||||
override void execute(VM vm)
|
override void execute(VM vm)
|
||||||
{
|
{
|
||||||
Function func = vm.currentSlot.functions.get(name, null);
|
|
||||||
if(!func)
|
if(!func)
|
||||||
{
|
{
|
||||||
throw new SyntaxError(name);
|
//楽だし実行時に解決させる
|
||||||
|
resolve(vm);
|
||||||
}
|
}
|
||||||
if(func.argCount != this.argCount)
|
if(func.argCount != this.argCount)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1227,6 +1227,7 @@ class Compiler
|
|||||||
genCode(new EndVM());
|
genCode(new EndVM());
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
VM vm;
|
||||||
void compileDirectMode(VM vm)
|
void compileDirectMode(VM vm)
|
||||||
{
|
{
|
||||||
isDirectMode = true;
|
isDirectMode = true;
|
||||||
@@ -1242,8 +1243,9 @@ class Compiler
|
|||||||
VM compile()
|
VM compile()
|
||||||
{
|
{
|
||||||
isDirectMode = false;
|
isDirectMode = false;
|
||||||
compileProgram();
|
|
||||||
VM vm = new VM();
|
VM vm = new VM();
|
||||||
|
this.vm = vm;
|
||||||
|
compileProgram();
|
||||||
vm.loadSlot(0, code, globalIndex + 1, global, functions, globalScope.data, globalLabel, debugInfo);
|
vm.loadSlot(0, code, globalIndex + 1, global, functions, globalScope.data, globalLabel, debugInfo);
|
||||||
vm.setCurrentSlot(0);
|
vm.setCurrentSlot(0);
|
||||||
registerSystemVariable(vm);
|
registerSystemVariable(vm);
|
||||||
|
|||||||
@@ -426,19 +426,22 @@ class DefineFunction : Statement
|
|||||||
wstring name;
|
wstring name;
|
||||||
Statements functionBody;
|
Statements functionBody;
|
||||||
bool returnExpr;
|
bool returnExpr;
|
||||||
this(wstring name, bool returnExpr, SourceLocation loc)
|
bool isCommon;
|
||||||
|
this(wstring name, bool returnExpr, bool isCommon, SourceLocation loc)
|
||||||
{
|
{
|
||||||
super.location = loc;
|
super.location = loc;
|
||||||
this.type = NodeType.DefineFunction;
|
this.type = NodeType.DefineFunction;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.returnExpr = returnExpr;
|
this.returnExpr = returnExpr;
|
||||||
|
this.isCommon = isCommon;
|
||||||
}
|
}
|
||||||
this(wstring name, SourceLocation loc)
|
this(wstring name, bool isCommon, SourceLocation loc)
|
||||||
{
|
{
|
||||||
super.location = loc;
|
super.location = loc;
|
||||||
this.type = NodeType.DefineFunction;
|
this.type = NodeType.DefineFunction;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.returnExpr = false;
|
this.returnExpr = false;
|
||||||
|
this.isCommon = isCommon;
|
||||||
}
|
}
|
||||||
void addArgument(wstring name)
|
void addArgument(wstring name)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -558,12 +558,12 @@ class Parser
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
statement = defineFunction();
|
statement = defineFunction(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(token.type == TokenType.Def)
|
else if(token.type == TokenType.Def)
|
||||||
{
|
{
|
||||||
statement = defineFunction();
|
statement = defineFunction(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -598,7 +598,7 @@ class Parser
|
|||||||
}
|
}
|
||||||
return token.value.stringValue;
|
return token.value.stringValue;
|
||||||
}
|
}
|
||||||
DefineFunction defineFunction()
|
DefineFunction defineFunction(bool isCommon)
|
||||||
{
|
{
|
||||||
lex.popFront();
|
lex.popFront();
|
||||||
auto token = lex.front();
|
auto token = lex.front();
|
||||||
@@ -607,7 +607,7 @@ class Parser
|
|||||||
syntaxError();
|
syntaxError();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
DefineFunction node = new DefineFunction(token.value.stringValue, lex.location);
|
DefineFunction node = new DefineFunction(token.value.stringValue, isCommon, lex.location);
|
||||||
lex.popFront();
|
lex.popFront();
|
||||||
token = lex.front();
|
token = lex.front();
|
||||||
if(token.type == TokenType.LParen)
|
if(token.type == TokenType.LParen)
|
||||||
|
|||||||
Reference in New Issue
Block a user