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("Call in to a codule given its slot number.")] public class call : Abstracts.UnaryOperation { public override void Operation(long coduleID) { CallOperation(VM, coduleID); } /// /// Returns true if success, false if we had to fizzle. /// public static bool CallOperation(VirtualMachine VM, long coduleID) { // Early out when there aren't any other codules to call or calling is turned off if (VM.CallingChromosome == null) { return false; } Int16 actualCoduleID = VM.CallingChromosome.FindCoduleSlot(coduleID); // Early out if the callstack already is calling this codule if (VM.CallStack.Contains(actualCoduleID)) { return false; } var codule = VM.CallingChromosome.Codules[actualCoduleID]; VM.CallStack.Push(actualCoduleID); codule.Execute(VM); VM.CallStack.Pop(); return true; } } }