1
0

変数を実�

This commit is contained in:
otya128
2015-06-05 19:57:35 +09:00
parent 9b36cd2961
commit 04f35b3801
3 changed files with 49 additions and 7 deletions

View File

@@ -14,10 +14,16 @@ class Compiler
}
Code[] code;
int[wstring] global;
int globalIndex = 0;
void genCodeImm(Value value)
{
code ~= new Push(value);
}
void genCodePushGlobal(int ind)
{
code ~= new PushG(ind);
}
void genCodeOP(TokenType op)
{
code ~= new Operate(op);
@@ -39,6 +45,15 @@ class Compiler
}
break;
case NodeType.Variable:
auto var = cast(Variable)exp;
int global = this.global.get(var.name, 0);
if(global == 0)
{
//local変数をあたる
//それでもだめならOPTION STRICTならエラー
this.global[var.name] = ++globalIndex = global;
}
genCodePushGlobal(global);
break;
case NodeType.CallFunction:
{
@@ -89,6 +104,6 @@ class Compiler
stderr.writeln("Compile:NotImpl ", i.type);
}
}
return new VM(code);
return new VM(code, globalIndex + 1);
}
}