1
0

GOSUB実�

This commit is contained in:
otya128
2015-06-07 20:56:34 +09:00
parent 628b259caf
commit f7c4f06eae
6 changed files with 157 additions and 6 deletions

View File

@@ -42,6 +42,10 @@ class Compiler
{
code ~= new GotoS(label);
}
void genCodeGosub(wstring label)
{
code ~= new GosubS(label);
}
GotoAddr genCodeGoto()
{
auto c = new GotoAddr(-1);
@@ -258,6 +262,26 @@ class Compiler
case NodeType.For:
compileFor(cast(For)i);
break;
case NodeType.Gosub:
{
auto gosub = cast(Gosub)i;
genCodeGosub(gosub.label);
}
break;
case NodeType.Return:
{
auto ret = cast(Return)i;
if(ret.expression is null)
genCode(new ReturnSubroutine());
else
{
//関数未実装:error
}
}
break;
case NodeType.End:
genCode(new EndVM());
break;
default:
stderr.writeln("Compile:NotImpl ", i.type);
}
@@ -274,6 +298,10 @@ class Compiler
{
code[i] = new GotoAddr(globalLabel[(cast(GotoS)c).label]);
}
if(c.type == CodeType.GosubS)
{
code[i] = new GosubAddr(globalLabel[(cast(GosubS)c).label]);
}
}
return new VM(code, globalIndex + 1, global);
}