ラベルとGOTOを実�
This commit is contained in:
@@ -15,6 +15,7 @@ class Compiler
|
||||
|
||||
Code[] code;
|
||||
int[wstring] global;
|
||||
int[wstring] globalLabel;
|
||||
int globalIndex = 0;
|
||||
void genCodeImm(Value value)
|
||||
{
|
||||
@@ -32,6 +33,10 @@ class Compiler
|
||||
{
|
||||
code ~= new Operate(op);
|
||||
}
|
||||
void genCodeGoto(wstring label)
|
||||
{
|
||||
code ~= new GotoS(label);
|
||||
}
|
||||
int defineGlobalVarIndex(wstring name)
|
||||
{
|
||||
int global = this.global.get(name, 0);
|
||||
@@ -129,10 +134,28 @@ class Compiler
|
||||
genCodePopGlobal(getGlobalVarIndex(assign.name));
|
||||
}
|
||||
break;
|
||||
case NodeType.Label:
|
||||
{
|
||||
auto label = cast(Label)i;
|
||||
globalLabel[label.label] = code.length;
|
||||
}
|
||||
break;
|
||||
case NodeType.Goto:
|
||||
{
|
||||
genCodeGoto((cast(Goto)i).label);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
stderr.writeln("Compile:NotImpl ", i.type);
|
||||
}
|
||||
}
|
||||
foreach(int i, Code c; code)
|
||||
{
|
||||
if(c.type == CodeType.GotoS)
|
||||
{
|
||||
code[i] = new GotoAddr(globalLabel[(cast(GotoS)c).label]);
|
||||
}
|
||||
}
|
||||
return new VM(code, globalIndex + 1, global);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user