37 lines
1013 B
C#
37 lines
1013 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 TObject.True;
|
|
});
|
|
Init.Execute(env);
|
|
TObject obj= TObject.Uninit;
|
|
while(Condition.Execute(env).AsBoolean && isRunning)
|
|
{
|
|
obj=Body.Execute(env);
|
|
Increment.Execute(env);
|
|
}
|
|
return obj;
|
|
}
|
|
}
|
|
} |