public override IEnumerable <Position> Execute(UnreadableEnv env) { // Evaluate the condition foreach (var pos in _argCond.Execute(env)) { yield return(pos); } yield return(Position); var value = env.Pop(); if (value == null) { throw new Exception("If condition cannot be void."); } var codeToExecute = value.Value.IsZero ? _argNCode : _argYCode; // Execute the code foreach (var pos in codeToExecute.Execute(env)) { yield return(pos); } // Last result is now on the stack yield return(Position); }
public override IEnumerable <Position> Execute(UnreadableEnv env) { env.Push(null); again: // Evaluate the condition foreach (var pos in _argCond.Execute(env)) { yield return(pos); } yield return(Position); var value = env.Pop(); if (value == null) { throw new Exception("While condition cannot be void."); } if (!value.Value.IsZero) { // Discard result from previous iteration env.Pop(); // Execute the code foreach (var pos in _argCode.Execute(env)) { yield return(pos); } yield return(Position); goto again; } // Last result is now on the stack yield return(Position); }
public override IEnumerable<Position> Execute(UnreadableEnv env) { env.Push(null); again: // Evaluate the condition foreach (var pos in _argCond.Execute(env)) yield return pos; yield return Position; var value = env.Pop(); if (value == null) throw new Exception("While condition cannot be void."); if (!value.Value.IsZero) { // Discard result from previous iteration env.Pop(); // Execute the code foreach (var pos in _argCode.Execute(env)) yield return pos; yield return Position; goto again; } // Last result is now on the stack yield return Position; }
public override IEnumerable<Position> Execute(UnreadableEnv env) { // Evaluate the condition foreach (var pos in _argCond.Execute(env)) yield return pos; yield return Position; var value = env.Pop(); if (value == null) throw new Exception("If condition cannot be void."); var codeToExecute = value.Value.IsZero ? _argNCode : _argYCode; // Execute the code foreach (var pos in codeToExecute.Execute(env)) yield return pos; // Last result is now on the stack yield return Position; }