using System; using System.Collections.Generic; using System.Reflection.Emit; using System.Linq; using System.Text; using System.Threading.Tasks; using Sunweaver.Commands.Attributes; using Sunweaver.VM; namespace Sunweaver.Commands { /// /// /// [BasePair(@"""3 b loop"" is just a shorthand mneumonic for ""3 b call 2 b call 1 b call"". " + @"Negative loop counts preserve sign. eg: ""-3 b loop"" becomes " + @"""-3 b call -2 b call -1 b call""")] public class loop : Abstracts.BinaryOperation { public override void Operation(long loopCount, long coduleID) { LoopOperation(VM, loopCount, coduleID); } public static void LoopOperation(VirtualMachine VM, long loopCount, long coduleID) { for (long i = Math.Abs(loopCount); i >= 1; --i) { VM.Stack.Push(i * Math.Sign(loopCount)); if (!call.CallOperation(VM, coduleID)) { // Fizzles, so undo and terminate VM.Stack.Pop(); break; } } } public override void CompileOperation(ILGenerator il, Locals locals) { throw new NotImplementedException(); } } }