36 lines
996 B
C#
36 lines
996 B
C#
|
namespace tlang
|
||
|
{
|
||
|
internal class ForLoop : Node
|
||
|
{
|
||
|
public Node Init {get;set;}
|
||
|
public Node Condition {get;set;}
|
||
|
public Node Increment {get;set;}
|
||
|
public Node Body {get;set;}
|
||
|
|
||
|
public ForLoop(Node init, Node condition, Node inc, Node body)
|
||
|
{
|
||
|
Init = init;
|
||
|
Condition = condition;
|
||
|
Increment = inc;
|
||
|
Body = body;
|
||
|
}
|
||
|
|
||
|
public override TObject Execute(IScopeEnvironment nodeEnv)
|
||
|
{
|
||
|
var env = nodeEnv.SubEnv;
|
||
|
bool isRunning=true;
|
||
|
env["last_ittr"]= new TExternalMethod((args)=>{
|
||
|
isRunning=false;
|
||
|
return new TNumber(1);
|
||
|
});
|
||
|
Init.Execute(env);
|
||
|
TObject obj=new TUninit();
|
||
|
while(Condition.Execute(env).AsBoolean && isRunning)
|
||
|
{
|
||
|
obj=Body.Execute(env);
|
||
|
Increment.Execute(env);
|
||
|
}
|
||
|
return obj;
|
||
|
}
|
||
|
}
|
||
|
}
|