/// <summary> /// Called when the item is a while item. /// </summary> /// <param name="target">The object that was passed to IParseItem.Visit.</param> /// <returns>The passed target or a modification of it.</returns> /// <exception cref="System.ArgumentNullException">If target is null.</exception> public IParseItem Visit(WhileItem target) { if (target == null) { throw new ArgumentNullException(nameof(target)); } ILGenerator gen = compiler.CurrentGenerator; target.Break.UserData = target.Break.UserData ?? gen.DefineLabel(); Label start = gen.DefineLabel(); Label end = (Label)target.Break.UserData; // start: gen.MarkLabel(start); // if (!{Exp}.IsTrue) goto end; target.Exp.Accept(this); gen.Emit(OpCodes.Callvirt, typeof(ILuaValue).GetProperty(nameof(ILuaValue.IsTrue)).GetGetMethod()); gen.Emit(OpCodes.Brfalse, end); // {Block} target.Block.Accept(this); // goto start; gen.Emit(OpCodes.Br, start); // end: gen.MarkLabel(end); return(target); }
public IParseItem Visit(WhileItem target) { if (target == null) { throw new ArgumentNullException(nameof(target)); } target.Expression.Accept(this); using (_tree.Block(true)) { _tree.DefineLabel(target.Break); target.Block.Accept(this); } return(target); }