1
0

REPEAT~UNTILを実装

This commit is contained in:
otya128
2016-09-02 20:39:31 +09:00
parent 3e2cb7b8a7
commit 2f50fc5ba9
5 changed files with 103 additions and 22 deletions

View File

@@ -656,28 +656,6 @@ class Compiler
compileStatements(node.then, sc);
//もしelseもあるのならば、endifに飛ぶ
GotoAddr then;
/*
if 0 then
elseif 0 then
elseif 1 then
else
endif
push 0
gotofalse else
goto endif
else:
push 0
gototrue elif1else
push 1
gototrue elif2
goto else
elif1:
goto endif
elif2:
goto endif
else:
endif:
*/
if (node.hasElseif)
{
then = genCodeGoto();
@@ -765,6 +743,17 @@ class Compiler
s.breakAddr.address = cast(int)code.length;
breakAddr.address = cast(int)code.length;
}
void compileRepeat(RepeatUntil node, Scope s)
{
auto start = cast(int)code.length;
s = new Scope(new GotoAddr(-1), new GotoAddr(-1), s);
compileStatements(node.statements, s);
s.continueAddr.address = cast(int)code.length;
compileExpression(node.condExpression, s);
auto a = genCodeGotoFalse();
a.address = start;
s.breakAddr.address = cast(int)code.length;
}
void compileVar(Var node, Scope sc)
{
foreach(Statement v ; node.define)
@@ -1096,6 +1085,9 @@ class Compiler
case NodeType.Input:
compileInput(cast(Input)i, s);
break;
case NodeType.RepeatUntil:
compileRepeat(cast(RepeatUntil)i, s);
break;
default:
stderr.writeln("Compile:NotImpl ", i.type);
}