/// <summary> /// Removes top three stack items and converts them to <see cref="long"/>s: value, Min, Max. /// Pushes 1 if value was in range, otherwise 0. /// Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 3) { error = "Invalid number of elements in stack."; return(false); } // Stack is: x then min then max so we pop max first if (!OpHelper.TryConvertByteArrayToInt(opData.Pop(), out long max, true)) { error = "Couldn't convert to number."; return(false); } if (!OpHelper.TryConvertByteArrayToInt(opData.Pop(), out long min, true)) { error = "Couldn't convert to number."; return(false); } if (!OpHelper.TryConvertByteArrayToInt(opData.Pop(), out long x, true)) { error = "Couldn't convert to number."; return(false); } int c = (x >= min && x < max) ? 1 : 0; opData.Push(OpHelper.IntToByteArray(c)); error = null; return(true); }
/// <summary> /// Pushes the number of stack items onto the stack. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { opData.Push(OpHelper.IntToByteArray(opData.ItemCount)); error = null; return(true); }
/// <summary> /// Replaces top two stack items interpreted as <see cref="long"/>s with their subtract result. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (!TrySetValues(opData, out error)) { return(false); } opData.Push(OpHelper.IntToByteArray(a - b)); error = null; return(true); }
/// <summary> /// Replaces top two stack items interpreted as <see cref="long"/>s with 1 if either one is not 0, otherwise with 0. /// Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (!TrySetValues(opData, out error)) { return(false); } int c = (a != 0 || b != 0) ? 1 : 0; opData.Push(OpHelper.IntToByteArray(c)); error = null; return(true); }
/// <summary> /// Pushes the size of the top stack item to the stack. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public bool Run(IOpData opData, out string error) { if (opData.ItemCount < 1) { error = "There was not enough items left in the stack."; return(false); } byte[] temp = opData.Peek(); opData.Push(OpHelper.IntToByteArray(temp.Length)); error = null; return(true); }