Created
October 19, 2011 06:27
-
-
Save ErisianArchitect/1297608 to your computer and use it in GitHub Desktop.
XScript Tokenizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Reflection; | |
namespace XScript.Helpers | |
{ | |
public sealed class EvalHelper | |
{ | |
#region Types | |
static readonly Type INT8 = typeof(sbyte); | |
static readonly Type UINT8 = typeof(byte); | |
static readonly Type INT16 = typeof(short); | |
static readonly Type UINT16 = typeof(ushort); | |
static readonly Type INT32 = typeof(int); | |
static readonly Type UINT32 = typeof(uint); | |
static readonly Type INT64 = typeof(long); | |
static readonly Type UINT64 = typeof(ulong); | |
static readonly Type SINGLE = typeof(float); | |
static readonly Type DOUBLE = typeof(double); | |
static readonly Type DECIMAL = typeof(decimal); | |
static readonly Type CHAR = typeof(char); | |
static readonly Type BOOLEAN = typeof(bool); | |
static readonly Type STRING = typeof(string); | |
#endregion | |
#region Operations | |
public static void Add(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a + (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a + (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a + (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a + (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a + (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a + (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a + (long)b); | |
else if (bt == SINGLE) stack.Push((sbyte)a + (float)b); | |
else if (bt == DOUBLE) stack.Push((sbyte)a + (double)b); | |
else if (bt == DECIMAL) stack.Push((sbyte)a + (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a + (char)b); | |
else if (bt == STRING) stack.Push((sbyte)a + (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a + (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a + (byte)b); | |
else if (bt == INT16) stack.Push((byte)a + (short)b); | |
else if (bt == UINT16) stack.Push((byte)a + (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a + (int)b); | |
else if (bt == UINT32) stack.Push((byte)a + (uint)b); | |
else if (bt == INT64) stack.Push((byte)a + (long)b); | |
else if (bt == UINT64) stack.Push((byte)a + (ulong)b); | |
else if (bt == SINGLE) stack.Push((byte)a + (float)b); | |
else if (bt == DOUBLE) stack.Push((byte)a + (double)b); | |
else if (bt == DECIMAL) stack.Push((byte)a + (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a + (char)b); | |
else if (bt == STRING) stack.Push((byte)a + (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a + (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a + (byte)b); | |
else if (bt == INT16) stack.Push((short)a + (short)b); | |
else if (bt == UINT16) stack.Push((short)a + (ushort)b); | |
else if (bt == INT32) stack.Push((short)a + (int)b); | |
else if (bt == UINT32) stack.Push((short)a + (uint)b); | |
else if (bt == INT64) stack.Push((short)a + (long)b); | |
else if (bt == SINGLE) stack.Push((short)a + (float)b); | |
else if (bt == DOUBLE) stack.Push((short)a + (double)b); | |
else if (bt == DECIMAL) stack.Push((short)a + (decimal)b); | |
else if (bt == CHAR) stack.Push((short)a + (char)b); | |
else if (bt == STRING) stack.Push((short)a + (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a + (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a + (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a + (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a + (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a + (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a + (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a + (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a + (ulong)b); | |
else if (bt == SINGLE) stack.Push((ushort)a + (float)b); | |
else if (bt == DOUBLE) stack.Push((ushort)a + (double)b); | |
else if (bt == DECIMAL) stack.Push((ushort)a + (decimal)b); | |
else if (bt == CHAR) stack.Push((ushort)a + (char)b); | |
else if (bt == STRING) stack.Push((ushort)a + (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a + (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a + (byte)b); | |
else if (bt == INT16) stack.Push((int)a + (short)b); | |
else if (bt == UINT16) stack.Push((int)a + (ushort)b); | |
else if (bt == INT32) stack.Push((int)a + (int)b); | |
else if (bt == UINT32) stack.Push((int)a + (uint)b); | |
else if (bt == INT64) stack.Push((int)a + (long)b); | |
else if (bt == SINGLE) stack.Push((int)a + (float)b); | |
else if (bt == DOUBLE) stack.Push((int)a + (double)b); | |
else if (bt == DECIMAL) stack.Push((int)a + (decimal)b); | |
else if (bt == CHAR) stack.Push((int)a + (char)b); | |
else if (bt == STRING) stack.Push((int)a + (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a + (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a + (byte)b); | |
else if (bt == INT16) stack.Push((uint)a + (short)b); | |
else if (bt == UINT16) stack.Push((uint)a + (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a + (int)b); | |
else if (bt == UINT32) stack.Push((uint)a + (uint)b); | |
else if (bt == INT64) stack.Push((uint)a + (long)b); | |
else if (bt == UINT64) stack.Push((uint)a + (ulong)b); | |
else if (bt == SINGLE) stack.Push((uint)a + (float)b); | |
else if (bt == DOUBLE) stack.Push((uint)a + (double)b); | |
else if (bt == DECIMAL) stack.Push((uint)a + (decimal)b); | |
else if (bt == CHAR) stack.Push((uint)a + (char)b); | |
else if (bt == STRING) stack.Push((uint)a + (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a + (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a + (byte)b); | |
else if (bt == INT16) stack.Push((long)a + (short)b); | |
else if (bt == UINT16) stack.Push((long)a + (ushort)b); | |
else if (bt == INT32) stack.Push((long)a + (int)b); | |
else if (bt == UINT32) stack.Push((long)a + (uint)b); | |
else if (bt == INT64) stack.Push((long)a + (long)b); | |
else if (bt == SINGLE) stack.Push((long)a + (float)b); | |
else if (bt == DOUBLE) stack.Push((long)a + (double)b); | |
else if (bt == DECIMAL) stack.Push((long)a + (decimal)b); | |
else if (bt == CHAR) stack.Push((long)a + (char)b); | |
else if (bt == STRING) stack.Push((long)a + (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a + (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a + (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a + (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a + (ulong)b); | |
else if (bt == SINGLE) stack.Push((ulong)a + (float)b); | |
else if (bt == DOUBLE) stack.Push((ulong)a + (double)b); | |
else if (bt == DECIMAL) stack.Push((ulong)a + (decimal)b); | |
else if (bt == CHAR) stack.Push((ulong)a + (char)b); | |
else if (bt == STRING) stack.Push((ulong)a + (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
if (bt == INT8) stack.Push((float)a + (sbyte)b); | |
else if (bt == UINT8) stack.Push((float)a + (byte)b); | |
else if (bt == INT16) stack.Push((float)a + (short)b); | |
else if (bt == UINT16) stack.Push((float)a + (ushort)b); | |
else if (bt == INT32) stack.Push((float)a + (int)b); | |
else if (bt == UINT32) stack.Push((float)a + (uint)b); | |
else if (bt == INT64) stack.Push((float)a + (long)b); | |
else if (bt == UINT64) stack.Push((float)a + (ulong)b); | |
else if (bt == SINGLE) stack.Push((float)a + (float)b); | |
else if (bt == DOUBLE) stack.Push((float)a + (double)b); | |
else if (bt == CHAR) stack.Push((float)a + (char)b); | |
else if (bt == STRING) stack.Push((float)a + (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
if (bt == INT8) stack.Push((double)a + (sbyte)b); | |
else if (bt == UINT8) stack.Push((double)a + (byte)b); | |
else if (bt == INT16) stack.Push((double)a + (short)b); | |
else if (bt == UINT16) stack.Push((double)a + (ushort)b); | |
else if (bt == INT32) stack.Push((double)a + (int)b); | |
else if (bt == UINT32) stack.Push((double)a + (uint)b); | |
else if (bt == INT64) stack.Push((double)a + (long)b); | |
else if (bt == UINT64) stack.Push((double)a + (ulong)b); | |
else if (bt == SINGLE) stack.Push((double)a + (float)b); | |
else if (bt == DOUBLE) stack.Push((double)a + (double)b); | |
else if (bt == CHAR) stack.Push((double)a + (char)b); | |
else if (bt == STRING) stack.Push((double)a + (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
if (bt == INT8) stack.Push((decimal)a + (sbyte)b); | |
else if (bt == UINT8) stack.Push((decimal)a + (byte)b); | |
else if (bt == INT16) stack.Push((decimal)a + (short)b); | |
else if (bt == UINT16) stack.Push((decimal)a + (ushort)b); | |
else if (bt == INT32) stack.Push((decimal)a + (int)b); | |
else if (bt == UINT32) stack.Push((decimal)a + (uint)b); | |
else if (bt == INT64) stack.Push((decimal)a + (long)b); | |
else if (bt == UINT64) stack.Push((decimal)a + (ulong)b); | |
else if (bt == DECIMAL) stack.Push((decimal)a + (decimal)b); | |
else if (bt == CHAR) stack.Push((decimal)a + (char)b); | |
else if (bt == STRING) stack.Push((decimal)a + (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a + (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a + (byte)b); | |
else if (bt == INT16) stack.Push((char)a + (short)b); | |
else if (bt == UINT16) stack.Push((char)a + (ushort)b); | |
else if (bt == INT32) stack.Push((char)a + (int)b); | |
else if (bt == UINT32) stack.Push((char)a + (uint)b); | |
else if (bt == INT64) stack.Push((char)a + (long)b); | |
else if (bt == UINT64) stack.Push((char)a + (ulong)b); | |
else if (bt == SINGLE) stack.Push((char)a + (float)b); | |
else if (bt == DOUBLE) stack.Push((char)a + (double)b); | |
else if (bt == DECIMAL) stack.Push((char)a + (decimal)b); | |
else if (bt == CHAR) stack.Push((char)a + (char)b); | |
else if (bt == STRING) stack.Push((char)a + (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
if (bt == STRING) stack.Push((bool)a + (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
if (bt == INT8) stack.Push((string)a + (sbyte)b); | |
else if (bt == UINT8) stack.Push((string)a + (byte)b); | |
else if (bt == INT16) stack.Push((string)a + (short)b); | |
else if (bt == UINT16) stack.Push((string)a + (ushort)b); | |
else if (bt == INT32) stack.Push((string)a + (int)b); | |
else if (bt == UINT32) stack.Push((string)a + (uint)b); | |
else if (bt == INT64) stack.Push((string)a + (long)b); | |
else if (bt == UINT64) stack.Push((string)a + (ulong)b); | |
else if (bt == SINGLE) stack.Push((string)a + (float)b); | |
else if (bt == DOUBLE) stack.Push((string)a + (double)b); | |
else if (bt == DECIMAL) stack.Push((string)a + (decimal)b); | |
else if (bt == CHAR) stack.Push((string)a + (char)b); | |
else if (bt == BOOLEAN) stack.Push((string)a + (bool)b); | |
else if (bt == STRING) stack.Push(string.Concat(a, b)); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
stack.Push(string.Concat(a, b)); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_Addition", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void Sub(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a - (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a - (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a - (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a - (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a - (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a - (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a - (long)b); | |
else if (bt == SINGLE) stack.Push((sbyte)a - (float)b); | |
else if (bt == DOUBLE) stack.Push((sbyte)a - (double)b); | |
else if (bt == DECIMAL) stack.Push((sbyte)a - (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a - (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a - (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a - (byte)b); | |
else if (bt == INT16) stack.Push((byte)a - (short)b); | |
else if (bt == UINT16) stack.Push((byte)a - (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a - (int)b); | |
else if (bt == UINT32) stack.Push((byte)a - (uint)b); | |
else if (bt == INT64) stack.Push((byte)a - (long)b); | |
else if (bt == UINT64) stack.Push((byte)a - (ulong)b); | |
else if (bt == SINGLE) stack.Push((byte)a - (float)b); | |
else if (bt == DOUBLE) stack.Push((byte)a - (double)b); | |
else if (bt == DECIMAL) stack.Push((byte)a - (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a - (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a - (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a - (byte)b); | |
else if (bt == INT16) stack.Push((short)a - (short)b); | |
else if (bt == UINT16) stack.Push((short)a - (ushort)b); | |
else if (bt == INT32) stack.Push((short)a - (int)b); | |
else if (bt == UINT32) stack.Push((short)a - (uint)b); | |
else if (bt == INT64) stack.Push((short)a - (long)b); | |
else if (bt == SINGLE) stack.Push((short)a - (float)b); | |
else if (bt == DOUBLE) stack.Push((short)a - (double)b); | |
else if (bt == DECIMAL) stack.Push((short)a - (decimal)b); | |
else if (bt == CHAR) stack.Push((short)a - (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a - (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a - (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a - (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a - (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a - (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a - (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a - (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a - (ulong)b); | |
else if (bt == SINGLE) stack.Push((ushort)a - (float)b); | |
else if (bt == DOUBLE) stack.Push((ushort)a - (double)b); | |
else if (bt == DECIMAL) stack.Push((ushort)a - (decimal)b); | |
else if (bt == CHAR) stack.Push((ushort)a - (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a - (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a - (byte)b); | |
else if (bt == INT16) stack.Push((int)a - (short)b); | |
else if (bt == UINT16) stack.Push((int)a - (ushort)b); | |
else if (bt == INT32) stack.Push((int)a - (int)b); | |
else if (bt == UINT32) stack.Push((int)a - (uint)b); | |
else if (bt == INT64) stack.Push((int)a - (long)b); | |
else if (bt == SINGLE) stack.Push((int)a - (float)b); | |
else if (bt == DOUBLE) stack.Push((int)a - (double)b); | |
else if (bt == DECIMAL) stack.Push((int)a - (decimal)b); | |
else if (bt == CHAR) stack.Push((int)a - (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a - (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a - (byte)b); | |
else if (bt == INT16) stack.Push((uint)a - (short)b); | |
else if (bt == UINT16) stack.Push((uint)a - (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a - (int)b); | |
else if (bt == UINT32) stack.Push((uint)a - (uint)b); | |
else if (bt == INT64) stack.Push((uint)a - (long)b); | |
else if (bt == UINT64) stack.Push((uint)a - (ulong)b); | |
else if (bt == SINGLE) stack.Push((uint)a - (float)b); | |
else if (bt == DOUBLE) stack.Push((uint)a - (double)b); | |
else if (bt == DECIMAL) stack.Push((uint)a - (decimal)b); | |
else if (bt == CHAR) stack.Push((uint)a - (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a - (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a - (byte)b); | |
else if (bt == INT16) stack.Push((long)a - (short)b); | |
else if (bt == UINT16) stack.Push((long)a - (ushort)b); | |
else if (bt == INT32) stack.Push((long)a - (int)b); | |
else if (bt == UINT32) stack.Push((long)a - (uint)b); | |
else if (bt == INT64) stack.Push((long)a - (long)b); | |
else if (bt == SINGLE) stack.Push((long)a - (float)b); | |
else if (bt == DOUBLE) stack.Push((long)a - (double)b); | |
else if (bt == DECIMAL) stack.Push((long)a - (decimal)b); | |
else if (bt == CHAR) stack.Push((long)a - (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a - (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a - (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a - (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a - (ulong)b); | |
else if (bt == SINGLE) stack.Push((ulong)a - (float)b); | |
else if (bt == DOUBLE) stack.Push((ulong)a - (double)b); | |
else if (bt == DECIMAL) stack.Push((ulong)a - (decimal)b); | |
else if (bt == CHAR) stack.Push((ulong)a - (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
if (bt == INT8) stack.Push((float)a - (sbyte)b); | |
else if (bt == UINT8) stack.Push((float)a - (byte)b); | |
else if (bt == INT16) stack.Push((float)a - (short)b); | |
else if (bt == UINT16) stack.Push((float)a - (ushort)b); | |
else if (bt == INT32) stack.Push((float)a - (int)b); | |
else if (bt == UINT32) stack.Push((float)a - (uint)b); | |
else if (bt == INT64) stack.Push((float)a - (long)b); | |
else if (bt == UINT64) stack.Push((float)a - (ulong)b); | |
else if (bt == SINGLE) stack.Push((float)a - (float)b); | |
else if (bt == DOUBLE) stack.Push((float)a - (double)b); | |
else if (bt == CHAR) stack.Push((float)a - (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
if (bt == INT8) stack.Push((double)a - (sbyte)b); | |
else if (bt == UINT8) stack.Push((double)a - (byte)b); | |
else if (bt == INT16) stack.Push((double)a - (short)b); | |
else if (bt == UINT16) stack.Push((double)a - (ushort)b); | |
else if (bt == INT32) stack.Push((double)a - (int)b); | |
else if (bt == UINT32) stack.Push((double)a - (uint)b); | |
else if (bt == INT64) stack.Push((double)a - (long)b); | |
else if (bt == UINT64) stack.Push((double)a - (ulong)b); | |
else if (bt == SINGLE) stack.Push((double)a - (float)b); | |
else if (bt == DOUBLE) stack.Push((double)a - (double)b); | |
else if (bt == CHAR) stack.Push((double)a - (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
if (bt == INT8) stack.Push((decimal)a - (sbyte)b); | |
else if (bt == UINT8) stack.Push((decimal)a - (byte)b); | |
else if (bt == INT16) stack.Push((decimal)a - (short)b); | |
else if (bt == UINT16) stack.Push((decimal)a - (ushort)b); | |
else if (bt == INT32) stack.Push((decimal)a - (int)b); | |
else if (bt == UINT32) stack.Push((decimal)a - (uint)b); | |
else if (bt == INT64) stack.Push((decimal)a - (long)b); | |
else if (bt == UINT64) stack.Push((decimal)a - (ulong)b); | |
else if (bt == DECIMAL) stack.Push((decimal)a - (decimal)b); | |
else if (bt == CHAR) stack.Push((decimal)a - (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a - (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a - (byte)b); | |
else if (bt == INT16) stack.Push((char)a - (short)b); | |
else if (bt == UINT16) stack.Push((char)a - (ushort)b); | |
else if (bt == INT32) stack.Push((char)a - (int)b); | |
else if (bt == UINT32) stack.Push((char)a - (uint)b); | |
else if (bt == INT64) stack.Push((char)a - (long)b); | |
else if (bt == UINT64) stack.Push((char)a - (ulong)b); | |
else if (bt == SINGLE) stack.Push((char)a - (float)b); | |
else if (bt == DOUBLE) stack.Push((char)a - (double)b); | |
else if (bt == DECIMAL) stack.Push((char)a - (decimal)b); | |
else if (bt == CHAR) stack.Push((char)a - (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
{ | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_Subtraction", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void Mul(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a * (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a * (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a * (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a * (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a * (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a * (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a * (long)b); | |
else if (bt == SINGLE) stack.Push((sbyte)a * (float)b); | |
else if (bt == DOUBLE) stack.Push((sbyte)a * (double)b); | |
else if (bt == DECIMAL) stack.Push((sbyte)a * (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a * (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a * (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a * (byte)b); | |
else if (bt == INT16) stack.Push((byte)a * (short)b); | |
else if (bt == UINT16) stack.Push((byte)a * (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a * (int)b); | |
else if (bt == UINT32) stack.Push((byte)a * (uint)b); | |
else if (bt == INT64) stack.Push((byte)a * (long)b); | |
else if (bt == UINT64) stack.Push((byte)a * (ulong)b); | |
else if (bt == SINGLE) stack.Push((byte)a * (float)b); | |
else if (bt == DOUBLE) stack.Push((byte)a * (double)b); | |
else if (bt == DECIMAL) stack.Push((byte)a * (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a * (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a * (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a * (byte)b); | |
else if (bt == INT16) stack.Push((short)a * (short)b); | |
else if (bt == UINT16) stack.Push((short)a * (ushort)b); | |
else if (bt == INT32) stack.Push((short)a * (int)b); | |
else if (bt == UINT32) stack.Push((short)a * (uint)b); | |
else if (bt == INT64) stack.Push((short)a * (long)b); | |
else if (bt == SINGLE) stack.Push((short)a * (float)b); | |
else if (bt == DOUBLE) stack.Push((short)a * (double)b); | |
else if (bt == DECIMAL) stack.Push((short)a * (decimal)b); | |
else if (bt == CHAR) stack.Push((short)a * (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a * (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a * (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a * (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a * (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a * (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a * (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a * (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a * (ulong)b); | |
else if (bt == SINGLE) stack.Push((ushort)a * (float)b); | |
else if (bt == DOUBLE) stack.Push((ushort)a * (double)b); | |
else if (bt == DECIMAL) stack.Push((ushort)a * (decimal)b); | |
else if (bt == CHAR) stack.Push((ushort)a * (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a * (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a * (byte)b); | |
else if (bt == INT16) stack.Push((int)a * (short)b); | |
else if (bt == UINT16) stack.Push((int)a * (ushort)b); | |
else if (bt == INT32) stack.Push((int)a * (int)b); | |
else if (bt == UINT32) stack.Push((int)a * (uint)b); | |
else if (bt == INT64) stack.Push((int)a * (long)b); | |
else if (bt == SINGLE) stack.Push((int)a * (float)b); | |
else if (bt == DOUBLE) stack.Push((int)a * (double)b); | |
else if (bt == DECIMAL) stack.Push((int)a * (decimal)b); | |
else if (bt == CHAR) stack.Push((int)a * (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a * (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a * (byte)b); | |
else if (bt == INT16) stack.Push((uint)a * (short)b); | |
else if (bt == UINT16) stack.Push((uint)a * (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a * (int)b); | |
else if (bt == UINT32) stack.Push((uint)a * (uint)b); | |
else if (bt == INT64) stack.Push((uint)a * (long)b); | |
else if (bt == UINT64) stack.Push((uint)a * (ulong)b); | |
else if (bt == SINGLE) stack.Push((uint)a * (float)b); | |
else if (bt == DOUBLE) stack.Push((uint)a * (double)b); | |
else if (bt == DECIMAL) stack.Push((uint)a * (decimal)b); | |
else if (bt == CHAR) stack.Push((uint)a * (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a * (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a * (byte)b); | |
else if (bt == INT16) stack.Push((long)a * (short)b); | |
else if (bt == UINT16) stack.Push((long)a * (ushort)b); | |
else if (bt == INT32) stack.Push((long)a * (int)b); | |
else if (bt == UINT32) stack.Push((long)a * (uint)b); | |
else if (bt == INT64) stack.Push((long)a * (long)b); | |
else if (bt == SINGLE) stack.Push((long)a * (float)b); | |
else if (bt == DOUBLE) stack.Push((long)a * (double)b); | |
else if (bt == DECIMAL) stack.Push((long)a * (decimal)b); | |
else if (bt == CHAR) stack.Push((long)a * (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a * (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a * (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a * (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a * (ulong)b); | |
else if (bt == SINGLE) stack.Push((ulong)a * (float)b); | |
else if (bt == DOUBLE) stack.Push((ulong)a * (double)b); | |
else if (bt == DECIMAL) stack.Push((ulong)a * (decimal)b); | |
else if (bt == CHAR) stack.Push((ulong)a * (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
if (bt == INT8) stack.Push((float)a * (sbyte)b); | |
else if (bt == UINT8) stack.Push((float)a * (byte)b); | |
else if (bt == INT16) stack.Push((float)a * (short)b); | |
else if (bt == UINT16) stack.Push((float)a * (ushort)b); | |
else if (bt == INT32) stack.Push((float)a * (int)b); | |
else if (bt == UINT32) stack.Push((float)a * (uint)b); | |
else if (bt == INT64) stack.Push((float)a * (long)b); | |
else if (bt == UINT64) stack.Push((float)a * (ulong)b); | |
else if (bt == SINGLE) stack.Push((float)a * (float)b); | |
else if (bt == DOUBLE) stack.Push((float)a * (double)b); | |
else if (bt == CHAR) stack.Push((float)a * (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
if (bt == INT8) stack.Push((double)a * (sbyte)b); | |
else if (bt == UINT8) stack.Push((double)a * (byte)b); | |
else if (bt == INT16) stack.Push((double)a * (short)b); | |
else if (bt == UINT16) stack.Push((double)a * (ushort)b); | |
else if (bt == INT32) stack.Push((double)a * (int)b); | |
else if (bt == UINT32) stack.Push((double)a * (uint)b); | |
else if (bt == INT64) stack.Push((double)a * (long)b); | |
else if (bt == UINT64) stack.Push((double)a * (ulong)b); | |
else if (bt == SINGLE) stack.Push((double)a * (float)b); | |
else if (bt == DOUBLE) stack.Push((double)a * (double)b); | |
else if (bt == CHAR) stack.Push((double)a * (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
if (bt == INT8) stack.Push((decimal)a * (sbyte)b); | |
else if (bt == UINT8) stack.Push((decimal)a * (byte)b); | |
else if (bt == INT16) stack.Push((decimal)a * (short)b); | |
else if (bt == UINT16) stack.Push((decimal)a * (ushort)b); | |
else if (bt == INT32) stack.Push((decimal)a * (int)b); | |
else if (bt == UINT32) stack.Push((decimal)a * (uint)b); | |
else if (bt == INT64) stack.Push((decimal)a * (long)b); | |
else if (bt == UINT64) stack.Push((decimal)a * (ulong)b); | |
else if (bt == DECIMAL) stack.Push((decimal)a * (decimal)b); | |
else if (bt == CHAR) stack.Push((decimal)a * (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a * (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a * (byte)b); | |
else if (bt == INT16) stack.Push((char)a * (short)b); | |
else if (bt == UINT16) stack.Push((char)a * (ushort)b); | |
else if (bt == INT32) stack.Push((char)a * (int)b); | |
else if (bt == UINT32) stack.Push((char)a * (uint)b); | |
else if (bt == INT64) stack.Push((char)a * (long)b); | |
else if (bt == UINT64) stack.Push((char)a * (ulong)b); | |
else if (bt == SINGLE) stack.Push((char)a * (float)b); | |
else if (bt == DOUBLE) stack.Push((char)a * (double)b); | |
else if (bt == DECIMAL) stack.Push((char)a * (decimal)b); | |
else if (bt == CHAR) stack.Push((char)a * (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
{ | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_Multiply", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void Div(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a / (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a / (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a / (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a / (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a / (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a / (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a / (long)b); | |
else if (bt == SINGLE) stack.Push((sbyte)a / (float)b); | |
else if (bt == DOUBLE) stack.Push((sbyte)a / (double)b); | |
else if (bt == DECIMAL) stack.Push((sbyte)a / (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a / (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a / (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a / (byte)b); | |
else if (bt == INT16) stack.Push((byte)a / (short)b); | |
else if (bt == UINT16) stack.Push((byte)a / (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a / (int)b); | |
else if (bt == UINT32) stack.Push((byte)a / (uint)b); | |
else if (bt == INT64) stack.Push((byte)a / (long)b); | |
else if (bt == UINT64) stack.Push((byte)a / (ulong)b); | |
else if (bt == SINGLE) stack.Push((byte)a / (float)b); | |
else if (bt == DOUBLE) stack.Push((byte)a / (double)b); | |
else if (bt == DECIMAL) stack.Push((byte)a / (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a / (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a / (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a / (byte)b); | |
else if (bt == INT16) stack.Push((short)a / (short)b); | |
else if (bt == UINT16) stack.Push((short)a / (ushort)b); | |
else if (bt == INT32) stack.Push((short)a / (int)b); | |
else if (bt == UINT32) stack.Push((short)a / (uint)b); | |
else if (bt == INT64) stack.Push((short)a / (long)b); | |
else if (bt == SINGLE) stack.Push((short)a / (float)b); | |
else if (bt == DOUBLE) stack.Push((short)a / (double)b); | |
else if (bt == DECIMAL) stack.Push((short)a / (decimal)b); | |
else if (bt == CHAR) stack.Push((short)a / (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a / (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a / (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a / (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a / (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a / (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a / (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a / (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a / (ulong)b); | |
else if (bt == SINGLE) stack.Push((ushort)a / (float)b); | |
else if (bt == DOUBLE) stack.Push((ushort)a / (double)b); | |
else if (bt == DECIMAL) stack.Push((ushort)a / (decimal)b); | |
else if (bt == CHAR) stack.Push((ushort)a / (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a / (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a / (byte)b); | |
else if (bt == INT16) stack.Push((int)a / (short)b); | |
else if (bt == UINT16) stack.Push((int)a / (ushort)b); | |
else if (bt == INT32) stack.Push((int)a / (int)b); | |
else if (bt == UINT32) stack.Push((int)a / (uint)b); | |
else if (bt == INT64) stack.Push((int)a / (long)b); | |
else if (bt == SINGLE) stack.Push((int)a / (float)b); | |
else if (bt == DOUBLE) stack.Push((int)a / (double)b); | |
else if (bt == DECIMAL) stack.Push((int)a / (decimal)b); | |
else if (bt == CHAR) stack.Push((int)a / (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a / (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a / (byte)b); | |
else if (bt == INT16) stack.Push((uint)a / (short)b); | |
else if (bt == UINT16) stack.Push((uint)a / (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a / (int)b); | |
else if (bt == UINT32) stack.Push((uint)a / (uint)b); | |
else if (bt == INT64) stack.Push((uint)a / (long)b); | |
else if (bt == UINT64) stack.Push((uint)a / (ulong)b); | |
else if (bt == SINGLE) stack.Push((uint)a / (float)b); | |
else if (bt == DOUBLE) stack.Push((uint)a / (double)b); | |
else if (bt == DECIMAL) stack.Push((uint)a / (decimal)b); | |
else if (bt == CHAR) stack.Push((uint)a / (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a / (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a / (byte)b); | |
else if (bt == INT16) stack.Push((long)a / (short)b); | |
else if (bt == UINT16) stack.Push((long)a / (ushort)b); | |
else if (bt == INT32) stack.Push((long)a / (int)b); | |
else if (bt == UINT32) stack.Push((long)a / (uint)b); | |
else if (bt == INT64) stack.Push((long)a / (long)b); | |
else if (bt == SINGLE) stack.Push((long)a / (float)b); | |
else if (bt == DOUBLE) stack.Push((long)a / (double)b); | |
else if (bt == DECIMAL) stack.Push((long)a / (decimal)b); | |
else if (bt == CHAR) stack.Push((long)a / (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a / (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a / (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a / (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a / (ulong)b); | |
else if (bt == SINGLE) stack.Push((ulong)a / (float)b); | |
else if (bt == DOUBLE) stack.Push((ulong)a / (double)b); | |
else if (bt == DECIMAL) stack.Push((ulong)a / (decimal)b); | |
else if (bt == CHAR) stack.Push((ulong)a / (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
if (bt == INT8) stack.Push((float)a / (sbyte)b); | |
else if (bt == UINT8) stack.Push((float)a / (byte)b); | |
else if (bt == INT16) stack.Push((float)a / (short)b); | |
else if (bt == UINT16) stack.Push((float)a / (ushort)b); | |
else if (bt == INT32) stack.Push((float)a / (int)b); | |
else if (bt == UINT32) stack.Push((float)a / (uint)b); | |
else if (bt == INT64) stack.Push((float)a / (long)b); | |
else if (bt == UINT64) stack.Push((float)a / (ulong)b); | |
else if (bt == SINGLE) stack.Push((float)a / (float)b); | |
else if (bt == DOUBLE) stack.Push((float)a / (double)b); | |
else if (bt == CHAR) stack.Push((float)a / (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
if (bt == INT8) stack.Push((double)a / (sbyte)b); | |
else if (bt == UINT8) stack.Push((double)a / (byte)b); | |
else if (bt == INT16) stack.Push((double)a / (short)b); | |
else if (bt == UINT16) stack.Push((double)a / (ushort)b); | |
else if (bt == INT32) stack.Push((double)a / (int)b); | |
else if (bt == UINT32) stack.Push((double)a / (uint)b); | |
else if (bt == INT64) stack.Push((double)a / (long)b); | |
else if (bt == UINT64) stack.Push((double)a / (ulong)b); | |
else if (bt == SINGLE) stack.Push((double)a / (float)b); | |
else if (bt == DOUBLE) stack.Push((double)a / (double)b); | |
else if (bt == CHAR) stack.Push((double)a / (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
if (bt == INT8) stack.Push((decimal)a / (sbyte)b); | |
else if (bt == UINT8) stack.Push((decimal)a / (byte)b); | |
else if (bt == INT16) stack.Push((decimal)a / (short)b); | |
else if (bt == UINT16) stack.Push((decimal)a / (ushort)b); | |
else if (bt == INT32) stack.Push((decimal)a / (int)b); | |
else if (bt == UINT32) stack.Push((decimal)a / (uint)b); | |
else if (bt == INT64) stack.Push((decimal)a / (long)b); | |
else if (bt == UINT64) stack.Push((decimal)a / (ulong)b); | |
else if (bt == DECIMAL) stack.Push((decimal)a / (decimal)b); | |
else if (bt == CHAR) stack.Push((decimal)a / (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a / (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a / (byte)b); | |
else if (bt == INT16) stack.Push((char)a / (short)b); | |
else if (bt == UINT16) stack.Push((char)a / (ushort)b); | |
else if (bt == INT32) stack.Push((char)a / (int)b); | |
else if (bt == UINT32) stack.Push((char)a / (uint)b); | |
else if (bt == INT64) stack.Push((char)a / (long)b); | |
else if (bt == UINT64) stack.Push((char)a / (ulong)b); | |
else if (bt == SINGLE) stack.Push((char)a / (float)b); | |
else if (bt == DOUBLE) stack.Push((char)a / (double)b); | |
else if (bt == DECIMAL) stack.Push((char)a / (decimal)b); | |
else if (bt == CHAR) stack.Push((char)a / (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
{ | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_Division", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void Rem(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a % (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a % (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a % (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a % (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a % (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a % (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a % (long)b); | |
else if (bt == SINGLE) stack.Push((sbyte)a % (float)b); | |
else if (bt == DOUBLE) stack.Push((sbyte)a % (double)b); | |
else if (bt == DECIMAL) stack.Push((sbyte)a % (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a % (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a % (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a % (byte)b); | |
else if (bt == INT16) stack.Push((byte)a % (short)b); | |
else if (bt == UINT16) stack.Push((byte)a % (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a % (int)b); | |
else if (bt == UINT32) stack.Push((byte)a % (uint)b); | |
else if (bt == INT64) stack.Push((byte)a % (long)b); | |
else if (bt == UINT64) stack.Push((byte)a % (ulong)b); | |
else if (bt == SINGLE) stack.Push((byte)a % (float)b); | |
else if (bt == DOUBLE) stack.Push((byte)a % (double)b); | |
else if (bt == DECIMAL) stack.Push((byte)a % (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a % (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a % (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a % (byte)b); | |
else if (bt == INT16) stack.Push((short)a % (short)b); | |
else if (bt == UINT16) stack.Push((short)a % (ushort)b); | |
else if (bt == INT32) stack.Push((short)a % (int)b); | |
else if (bt == UINT32) stack.Push((short)a % (uint)b); | |
else if (bt == INT64) stack.Push((short)a % (long)b); | |
else if (bt == SINGLE) stack.Push((short)a % (float)b); | |
else if (bt == DOUBLE) stack.Push((short)a % (double)b); | |
else if (bt == DECIMAL) stack.Push((short)a % (decimal)b); | |
else if (bt == CHAR) stack.Push((short)a % (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a % (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a % (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a % (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a % (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a % (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a % (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a % (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a % (ulong)b); | |
else if (bt == SINGLE) stack.Push((ushort)a % (float)b); | |
else if (bt == DOUBLE) stack.Push((ushort)a % (double)b); | |
else if (bt == DECIMAL) stack.Push((ushort)a % (decimal)b); | |
else if (bt == CHAR) stack.Push((ushort)a % (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a % (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a % (byte)b); | |
else if (bt == INT16) stack.Push((int)a % (short)b); | |
else if (bt == UINT16) stack.Push((int)a % (ushort)b); | |
else if (bt == INT32) stack.Push((int)a % (int)b); | |
else if (bt == UINT32) stack.Push((int)a % (uint)b); | |
else if (bt == INT64) stack.Push((int)a % (long)b); | |
else if (bt == SINGLE) stack.Push((int)a % (float)b); | |
else if (bt == DOUBLE) stack.Push((int)a % (double)b); | |
else if (bt == DECIMAL) stack.Push((int)a % (decimal)b); | |
else if (bt == CHAR) stack.Push((int)a % (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a % (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a % (byte)b); | |
else if (bt == INT16) stack.Push((uint)a % (short)b); | |
else if (bt == UINT16) stack.Push((uint)a % (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a % (int)b); | |
else if (bt == UINT32) stack.Push((uint)a % (uint)b); | |
else if (bt == INT64) stack.Push((uint)a % (long)b); | |
else if (bt == UINT64) stack.Push((uint)a % (ulong)b); | |
else if (bt == SINGLE) stack.Push((uint)a % (float)b); | |
else if (bt == DOUBLE) stack.Push((uint)a % (double)b); | |
else if (bt == DECIMAL) stack.Push((uint)a % (decimal)b); | |
else if (bt == CHAR) stack.Push((uint)a % (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a % (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a % (byte)b); | |
else if (bt == INT16) stack.Push((long)a % (short)b); | |
else if (bt == UINT16) stack.Push((long)a % (ushort)b); | |
else if (bt == INT32) stack.Push((long)a % (int)b); | |
else if (bt == UINT32) stack.Push((long)a % (uint)b); | |
else if (bt == INT64) stack.Push((long)a % (long)b); | |
else if (bt == SINGLE) stack.Push((long)a % (float)b); | |
else if (bt == DOUBLE) stack.Push((long)a % (double)b); | |
else if (bt == DECIMAL) stack.Push((long)a % (decimal)b); | |
else if (bt == CHAR) stack.Push((long)a % (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a % (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a % (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a % (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a % (ulong)b); | |
else if (bt == SINGLE) stack.Push((ulong)a % (float)b); | |
else if (bt == DOUBLE) stack.Push((ulong)a % (double)b); | |
else if (bt == DECIMAL) stack.Push((ulong)a % (decimal)b); | |
else if (bt == CHAR) stack.Push((ulong)a % (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
if (bt == INT8) stack.Push((float)a % (sbyte)b); | |
else if (bt == UINT8) stack.Push((float)a % (byte)b); | |
else if (bt == INT16) stack.Push((float)a % (short)b); | |
else if (bt == UINT16) stack.Push((float)a % (ushort)b); | |
else if (bt == INT32) stack.Push((float)a % (int)b); | |
else if (bt == UINT32) stack.Push((float)a % (uint)b); | |
else if (bt == INT64) stack.Push((float)a % (long)b); | |
else if (bt == UINT64) stack.Push((float)a % (ulong)b); | |
else if (bt == SINGLE) stack.Push((float)a % (float)b); | |
else if (bt == DOUBLE) stack.Push((float)a % (double)b); | |
else if (bt == CHAR) stack.Push((float)a % (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
if (bt == INT8) stack.Push((double)a % (sbyte)b); | |
else if (bt == UINT8) stack.Push((double)a % (byte)b); | |
else if (bt == INT16) stack.Push((double)a % (short)b); | |
else if (bt == UINT16) stack.Push((double)a % (ushort)b); | |
else if (bt == INT32) stack.Push((double)a % (int)b); | |
else if (bt == UINT32) stack.Push((double)a % (uint)b); | |
else if (bt == INT64) stack.Push((double)a % (long)b); | |
else if (bt == UINT64) stack.Push((double)a % (ulong)b); | |
else if (bt == SINGLE) stack.Push((double)a % (float)b); | |
else if (bt == DOUBLE) stack.Push((double)a % (double)b); | |
else if (bt == CHAR) stack.Push((double)a % (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
if (bt == INT8) stack.Push((decimal)a % (sbyte)b); | |
else if (bt == UINT8) stack.Push((decimal)a % (byte)b); | |
else if (bt == INT16) stack.Push((decimal)a % (short)b); | |
else if (bt == UINT16) stack.Push((decimal)a % (ushort)b); | |
else if (bt == INT32) stack.Push((decimal)a % (int)b); | |
else if (bt == UINT32) stack.Push((decimal)a % (uint)b); | |
else if (bt == INT64) stack.Push((decimal)a % (long)b); | |
else if (bt == UINT64) stack.Push((decimal)a % (ulong)b); | |
else if (bt == DECIMAL) stack.Push((decimal)a % (decimal)b); | |
else if (bt == CHAR) stack.Push((decimal)a % (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a % (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a % (byte)b); | |
else if (bt == INT16) stack.Push((char)a % (short)b); | |
else if (bt == UINT16) stack.Push((char)a % (ushort)b); | |
else if (bt == INT32) stack.Push((char)a % (int)b); | |
else if (bt == UINT32) stack.Push((char)a % (uint)b); | |
else if (bt == INT64) stack.Push((char)a % (long)b); | |
else if (bt == UINT64) stack.Push((char)a % (ulong)b); | |
else if (bt == SINGLE) stack.Push((char)a % (float)b); | |
else if (bt == DOUBLE) stack.Push((char)a % (double)b); | |
else if (bt == DECIMAL) stack.Push((char)a % (decimal)b); | |
else if (bt == CHAR) stack.Push((char)a % (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
{ | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_Modulus", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void XOR(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a ^ (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a ^ (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a ^ (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a ^ (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a ^ (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a ^ (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a ^ (long)b); | |
else if (bt == CHAR) stack.Push((sbyte)a ^ (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a ^ (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a ^ (byte)b); | |
else if (bt == INT16) stack.Push((byte)a ^ (short)b); | |
else if (bt == UINT16) stack.Push((byte)a ^ (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a ^ (int)b); | |
else if (bt == UINT32) stack.Push((byte)a ^ (uint)b); | |
else if (bt == INT64) stack.Push((byte)a ^ (long)b); | |
else if (bt == UINT64) stack.Push((byte)a ^ (ulong)b); | |
else if (bt == CHAR) stack.Push((sbyte)a ^ (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a ^ (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a ^ (byte)b); | |
else if (bt == INT16) stack.Push((short)a ^ (short)b); | |
else if (bt == UINT16) stack.Push((short)a ^ (ushort)b); | |
else if (bt == INT32) stack.Push((short)a ^ (int)b); | |
else if (bt == UINT32) stack.Push((short)a ^ (uint)b); | |
else if (bt == INT64) stack.Push((short)a ^ (long)b); | |
else if (bt == CHAR) stack.Push((short)a ^ (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a ^ (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a ^ (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a ^ (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a ^ (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a ^ (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a ^ (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a ^ (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a ^ (ulong)b); | |
else if (bt == CHAR) stack.Push((ushort)a ^ (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a ^ (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a ^ (byte)b); | |
else if (bt == INT16) stack.Push((int)a ^ (short)b); | |
else if (bt == UINT16) stack.Push((int)a ^ (ushort)b); | |
else if (bt == INT32) stack.Push((int)a ^ (int)b); | |
else if (bt == UINT32) stack.Push((int)a ^ (uint)b); | |
else if (bt == INT64) stack.Push((int)a ^ (long)b); | |
else if (bt == CHAR) stack.Push((int)a ^ (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a ^ (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a ^ (byte)b); | |
else if (bt == INT16) stack.Push((uint)a ^ (short)b); | |
else if (bt == UINT16) stack.Push((uint)a ^ (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a ^ (int)b); | |
else if (bt == UINT32) stack.Push((uint)a ^ (uint)b); | |
else if (bt == INT64) stack.Push((uint)a ^ (long)b); | |
else if (bt == UINT64) stack.Push((uint)a ^ (ulong)b); | |
else if (bt == CHAR) stack.Push((uint)a ^ (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a ^ (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a ^ (byte)b); | |
else if (bt == INT16) stack.Push((long)a ^ (short)b); | |
else if (bt == UINT16) stack.Push((long)a ^ (ushort)b); | |
else if (bt == INT32) stack.Push((long)a ^ (int)b); | |
else if (bt == UINT32) stack.Push((long)a ^ (uint)b); | |
else if (bt == INT64) stack.Push((long)a ^ (long)b); | |
else if (bt == CHAR) stack.Push((long)a ^ (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a ^ (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a ^ (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a ^ (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a ^ (ulong)b); | |
else if (bt == CHAR) stack.Push((ulong)a ^ (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a ^ (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a ^ (byte)b); | |
else if (bt == INT16) stack.Push((char)a ^ (short)b); | |
else if (bt == UINT16) stack.Push((char)a ^ (ushort)b); | |
else if (bt == INT32) stack.Push((char)a ^ (int)b); | |
else if (bt == UINT32) stack.Push((char)a ^ (uint)b); | |
else if (bt == INT64) stack.Push((char)a ^ (long)b); | |
else if (bt == UINT64) stack.Push((char)a ^ (ulong)b); | |
else if (bt == CHAR) stack.Push((char)a ^ (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
if (bt == BOOLEAN) stack.Push((bool)a ^ (bool)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
{ | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_ExclusiveOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void AND(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a & (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a & (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a & (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a & (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a & (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a & (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a & (long)b); | |
else if (bt == CHAR) stack.Push((sbyte)a & (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a & (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a & (byte)b); | |
else if (bt == INT16) stack.Push((byte)a & (short)b); | |
else if (bt == UINT16) stack.Push((byte)a & (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a & (int)b); | |
else if (bt == UINT32) stack.Push((byte)a & (uint)b); | |
else if (bt == INT64) stack.Push((byte)a & (long)b); | |
else if (bt == UINT64) stack.Push((byte)a & (ulong)b); | |
else if (bt == CHAR) stack.Push((sbyte)a & (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a & (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a & (byte)b); | |
else if (bt == INT16) stack.Push((short)a & (short)b); | |
else if (bt == UINT16) stack.Push((short)a & (ushort)b); | |
else if (bt == INT32) stack.Push((short)a & (int)b); | |
else if (bt == UINT32) stack.Push((short)a & (uint)b); | |
else if (bt == INT64) stack.Push((short)a & (long)b); | |
else if (bt == CHAR) stack.Push((short)a & (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a & (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a & (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a & (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a & (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a & (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a & (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a & (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a & (ulong)b); | |
else if (bt == CHAR) stack.Push((ushort)a & (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a & (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a & (byte)b); | |
else if (bt == INT16) stack.Push((int)a & (short)b); | |
else if (bt == UINT16) stack.Push((int)a & (ushort)b); | |
else if (bt == INT32) stack.Push((int)a & (int)b); | |
else if (bt == UINT32) stack.Push((int)a & (uint)b); | |
else if (bt == INT64) stack.Push((int)a & (long)b); | |
else if (bt == CHAR) stack.Push((int)a & (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a & (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a & (byte)b); | |
else if (bt == INT16) stack.Push((uint)a & (short)b); | |
else if (bt == UINT16) stack.Push((uint)a & (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a & (int)b); | |
else if (bt == UINT32) stack.Push((uint)a & (uint)b); | |
else if (bt == INT64) stack.Push((uint)a & (long)b); | |
else if (bt == UINT64) stack.Push((uint)a & (ulong)b); | |
else if (bt == CHAR) stack.Push((uint)a & (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a & (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a & (byte)b); | |
else if (bt == INT16) stack.Push((long)a & (short)b); | |
else if (bt == UINT16) stack.Push((long)a & (ushort)b); | |
else if (bt == INT32) stack.Push((long)a & (int)b); | |
else if (bt == UINT32) stack.Push((long)a & (uint)b); | |
else if (bt == INT64) stack.Push((long)a & (long)b); | |
else if (bt == CHAR) stack.Push((long)a & (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a & (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a & (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a & (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a & (ulong)b); | |
else if (bt == CHAR) stack.Push((ulong)a & (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a & (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a & (byte)b); | |
else if (bt == INT16) stack.Push((char)a & (short)b); | |
else if (bt == UINT16) stack.Push((char)a & (ushort)b); | |
else if (bt == INT32) stack.Push((char)a & (int)b); | |
else if (bt == UINT32) stack.Push((char)a & (uint)b); | |
else if (bt == INT64) stack.Push((char)a & (long)b); | |
else if (bt == UINT64) stack.Push((char)a & (ulong)b); | |
else if (bt == CHAR) stack.Push((char)a & (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
if (bt == BOOLEAN) stack.Push((bool)a & (bool)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_BitwiseAnd", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void OR(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a | (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a | (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a | (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a | (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a | (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a | (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a | (long)b); | |
else if (bt == CHAR) stack.Push((sbyte)a | (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a | (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a | (byte)b); | |
else if (bt == INT16) stack.Push((byte)a | (short)b); | |
else if (bt == UINT16) stack.Push((byte)a | (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a | (int)b); | |
else if (bt == UINT32) stack.Push((byte)a | (uint)b); | |
else if (bt == INT64) stack.Push((byte)a | (long)b); | |
else if (bt == UINT64) stack.Push((byte)a | (ulong)b); | |
else if (bt == CHAR) stack.Push((sbyte)a | (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a | (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a | (byte)b); | |
else if (bt == INT16) stack.Push((short)a | (short)b); | |
else if (bt == UINT16) stack.Push((short)a | (ushort)b); | |
else if (bt == INT32) stack.Push((short)a | (int)b); | |
else if (bt == UINT32) stack.Push((short)a | (uint)b); | |
else if (bt == INT64) stack.Push((short)a | (long)b); | |
else if (bt == CHAR) stack.Push((short)a | (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a | (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a | (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a | (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a | (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a | (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a | (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a | (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a | (ulong)b); | |
else if (bt == CHAR) stack.Push((ushort)a | (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a | (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a | (byte)b); | |
else if (bt == INT16) stack.Push((int)a | (short)b); | |
else if (bt == UINT16) stack.Push((int)a | (ushort)b); | |
else if (bt == INT32) stack.Push((int)a | (int)b); | |
else if (bt == UINT32) stack.Push((int)a | (uint)b); | |
else if (bt == INT64) stack.Push((int)a | (long)b); | |
else if (bt == CHAR) stack.Push((int)a | (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a | (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a | (byte)b); | |
else if (bt == INT16) stack.Push((uint)a | (short)b); | |
else if (bt == UINT16) stack.Push((uint)a | (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a | (int)b); | |
else if (bt == UINT32) stack.Push((uint)a | (uint)b); | |
else if (bt == INT64) stack.Push((uint)a | (long)b); | |
else if (bt == UINT64) stack.Push((uint)a | (ulong)b); | |
else if (bt == CHAR) stack.Push((uint)a | (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a | (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a | (byte)b); | |
else if (bt == INT16) stack.Push((long)a | (short)b); | |
else if (bt == UINT16) stack.Push((long)a | (ushort)b); | |
else if (bt == INT32) stack.Push((long)a | (int)b); | |
else if (bt == UINT32) stack.Push((long)a | (uint)b); | |
else if (bt == INT64) stack.Push((long)a | (long)b); | |
else if (bt == CHAR) stack.Push((long)a | (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a | (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a | (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a | (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a | (ulong)b); | |
else if (bt == CHAR) stack.Push((ulong)a | (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a | (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a | (byte)b); | |
else if (bt == INT16) stack.Push((char)a | (short)b); | |
else if (bt == UINT16) stack.Push((char)a | (ushort)b); | |
else if (bt == INT32) stack.Push((char)a | (int)b); | |
else if (bt == UINT32) stack.Push((char)a | (uint)b); | |
else if (bt == INT64) stack.Push((char)a | (long)b); | |
else if (bt == UINT64) stack.Push((char)a | (ulong)b); | |
else if (bt == CHAR) stack.Push((char)a | (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
if (bt == BOOLEAN) stack.Push((bool)a | (bool)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
{ | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_BitwiseOr", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void Lt(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a < (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a < (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a < (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a < (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a < (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a < (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a < (long)b); | |
else if (bt == SINGLE) stack.Push((sbyte)a < (float)b); | |
else if (bt == DOUBLE) stack.Push((sbyte)a < (double)b); | |
else if (bt == DECIMAL) stack.Push((sbyte)a < (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a < (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a < (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a < (byte)b); | |
else if (bt == INT16) stack.Push((byte)a < (short)b); | |
else if (bt == UINT16) stack.Push((byte)a < (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a < (int)b); | |
else if (bt == UINT32) stack.Push((byte)a < (uint)b); | |
else if (bt == INT64) stack.Push((byte)a < (long)b); | |
else if (bt == UINT64) stack.Push((byte)a < (ulong)b); | |
else if (bt == SINGLE) stack.Push((byte)a < (float)b); | |
else if (bt == DOUBLE) stack.Push((byte)a < (double)b); | |
else if (bt == DECIMAL) stack.Push((byte)a < (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a < (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a < (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a < (byte)b); | |
else if (bt == INT16) stack.Push((short)a < (short)b); | |
else if (bt == UINT16) stack.Push((short)a < (ushort)b); | |
else if (bt == INT32) stack.Push((short)a < (int)b); | |
else if (bt == UINT32) stack.Push((short)a < (uint)b); | |
else if (bt == INT64) stack.Push((short)a < (long)b); | |
else if (bt == SINGLE) stack.Push((short)a < (float)b); | |
else if (bt == DOUBLE) stack.Push((short)a < (double)b); | |
else if (bt == DECIMAL) stack.Push((short)a < (decimal)b); | |
else if (bt == CHAR) stack.Push((short)a < (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a < (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a < (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a < (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a < (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a < (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a < (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a < (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a < (ulong)b); | |
else if (bt == SINGLE) stack.Push((ushort)a < (float)b); | |
else if (bt == DOUBLE) stack.Push((ushort)a < (double)b); | |
else if (bt == DECIMAL) stack.Push((ushort)a < (decimal)b); | |
else if (bt == CHAR) stack.Push((ushort)a < (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a < (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a < (byte)b); | |
else if (bt == INT16) stack.Push((int)a < (short)b); | |
else if (bt == UINT16) stack.Push((int)a < (ushort)b); | |
else if (bt == INT32) stack.Push((int)a < (int)b); | |
else if (bt == UINT32) stack.Push((int)a < (uint)b); | |
else if (bt == INT64) stack.Push((int)a < (long)b); | |
else if (bt == SINGLE) stack.Push((int)a < (float)b); | |
else if (bt == DOUBLE) stack.Push((int)a < (double)b); | |
else if (bt == DECIMAL) stack.Push((int)a < (decimal)b); | |
else if (bt == CHAR) stack.Push((int)a < (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a < (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a < (byte)b); | |
else if (bt == INT16) stack.Push((uint)a < (short)b); | |
else if (bt == UINT16) stack.Push((uint)a < (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a < (int)b); | |
else if (bt == UINT32) stack.Push((uint)a < (uint)b); | |
else if (bt == INT64) stack.Push((uint)a < (long)b); | |
else if (bt == UINT64) stack.Push((uint)a < (ulong)b); | |
else if (bt == SINGLE) stack.Push((uint)a < (float)b); | |
else if (bt == DOUBLE) stack.Push((uint)a < (double)b); | |
else if (bt == DECIMAL) stack.Push((uint)a < (decimal)b); | |
else if (bt == CHAR) stack.Push((uint)a < (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a < (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a < (byte)b); | |
else if (bt == INT16) stack.Push((long)a < (short)b); | |
else if (bt == UINT16) stack.Push((long)a < (ushort)b); | |
else if (bt == INT32) stack.Push((long)a < (int)b); | |
else if (bt == UINT32) stack.Push((long)a < (uint)b); | |
else if (bt == INT64) stack.Push((long)a < (long)b); | |
else if (bt == SINGLE) stack.Push((long)a < (float)b); | |
else if (bt == DOUBLE) stack.Push((long)a < (double)b); | |
else if (bt == DECIMAL) stack.Push((long)a < (decimal)b); | |
else if (bt == CHAR) stack.Push((long)a < (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a < (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a < (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a < (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a < (ulong)b); | |
else if (bt == SINGLE) stack.Push((ulong)a < (float)b); | |
else if (bt == DOUBLE) stack.Push((ulong)a < (double)b); | |
else if (bt == DECIMAL) stack.Push((ulong)a < (decimal)b); | |
else if (bt == CHAR) stack.Push((ulong)a < (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
if (bt == INT8) stack.Push((float)a < (sbyte)b); | |
else if (bt == UINT8) stack.Push((float)a < (byte)b); | |
else if (bt == INT16) stack.Push((float)a < (short)b); | |
else if (bt == UINT16) stack.Push((float)a < (ushort)b); | |
else if (bt == INT32) stack.Push((float)a < (int)b); | |
else if (bt == UINT32) stack.Push((float)a < (uint)b); | |
else if (bt == INT64) stack.Push((float)a < (long)b); | |
else if (bt == UINT64) stack.Push((float)a < (ulong)b); | |
else if (bt == SINGLE) stack.Push((float)a < (float)b); | |
else if (bt == DOUBLE) stack.Push((float)a < (double)b); | |
else if (bt == CHAR) stack.Push((float)a < (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
if (bt == INT8) stack.Push((double)a < (sbyte)b); | |
else if (bt == UINT8) stack.Push((double)a < (byte)b); | |
else if (bt == INT16) stack.Push((double)a < (short)b); | |
else if (bt == UINT16) stack.Push((double)a < (ushort)b); | |
else if (bt == INT32) stack.Push((double)a < (int)b); | |
else if (bt == UINT32) stack.Push((double)a < (uint)b); | |
else if (bt == INT64) stack.Push((double)a < (long)b); | |
else if (bt == UINT64) stack.Push((double)a < (ulong)b); | |
else if (bt == SINGLE) stack.Push((double)a < (float)b); | |
else if (bt == DOUBLE) stack.Push((double)a < (double)b); | |
else if (bt == CHAR) stack.Push((double)a < (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
if (bt == INT8) stack.Push((decimal)a < (sbyte)b); | |
else if (bt == UINT8) stack.Push((decimal)a < (byte)b); | |
else if (bt == INT16) stack.Push((decimal)a < (short)b); | |
else if (bt == UINT16) stack.Push((decimal)a < (ushort)b); | |
else if (bt == INT32) stack.Push((decimal)a < (int)b); | |
else if (bt == UINT32) stack.Push((decimal)a < (uint)b); | |
else if (bt == INT64) stack.Push((decimal)a < (long)b); | |
else if (bt == UINT64) stack.Push((decimal)a < (ulong)b); | |
else if (bt == DECIMAL) stack.Push((decimal)a < (decimal)b); | |
else if (bt == CHAR) stack.Push((decimal)a < (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a < (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a < (byte)b); | |
else if (bt == INT16) stack.Push((char)a < (short)b); | |
else if (bt == UINT16) stack.Push((char)a < (ushort)b); | |
else if (bt == INT32) stack.Push((char)a < (int)b); | |
else if (bt == UINT32) stack.Push((char)a < (uint)b); | |
else if (bt == INT64) stack.Push((char)a < (long)b); | |
else if (bt == UINT64) stack.Push((char)a < (ulong)b); | |
else if (bt == SINGLE) stack.Push((char)a < (float)b); | |
else if (bt == DOUBLE) stack.Push((char)a < (double)b); | |
else if (bt == DECIMAL) stack.Push((char)a < (decimal)b); | |
else if (bt == CHAR) stack.Push((char)a < (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
{ | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_LessThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void Gt(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a > (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a > (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a > (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a > (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a > (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a > (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a > (long)b); | |
else if (bt == SINGLE) stack.Push((sbyte)a > (float)b); | |
else if (bt == DOUBLE) stack.Push((sbyte)a > (double)b); | |
else if (bt == DECIMAL) stack.Push((sbyte)a > (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a > (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a > (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a > (byte)b); | |
else if (bt == INT16) stack.Push((byte)a > (short)b); | |
else if (bt == UINT16) stack.Push((byte)a > (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a > (int)b); | |
else if (bt == UINT32) stack.Push((byte)a > (uint)b); | |
else if (bt == INT64) stack.Push((byte)a > (long)b); | |
else if (bt == UINT64) stack.Push((byte)a > (ulong)b); | |
else if (bt == SINGLE) stack.Push((byte)a > (float)b); | |
else if (bt == DOUBLE) stack.Push((byte)a > (double)b); | |
else if (bt == DECIMAL) stack.Push((byte)a > (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a > (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a > (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a > (byte)b); | |
else if (bt == INT16) stack.Push((short)a > (short)b); | |
else if (bt == UINT16) stack.Push((short)a > (ushort)b); | |
else if (bt == INT32) stack.Push((short)a > (int)b); | |
else if (bt == UINT32) stack.Push((short)a > (uint)b); | |
else if (bt == INT64) stack.Push((short)a > (long)b); | |
else if (bt == SINGLE) stack.Push((short)a > (float)b); | |
else if (bt == DOUBLE) stack.Push((short)a > (double)b); | |
else if (bt == DECIMAL) stack.Push((short)a > (decimal)b); | |
else if (bt == CHAR) stack.Push((short)a > (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a > (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a > (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a > (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a > (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a > (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a > (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a > (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a > (ulong)b); | |
else if (bt == SINGLE) stack.Push((ushort)a > (float)b); | |
else if (bt == DOUBLE) stack.Push((ushort)a > (double)b); | |
else if (bt == DECIMAL) stack.Push((ushort)a > (decimal)b); | |
else if (bt == CHAR) stack.Push((ushort)a > (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a > (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a > (byte)b); | |
else if (bt == INT16) stack.Push((int)a > (short)b); | |
else if (bt == UINT16) stack.Push((int)a > (ushort)b); | |
else if (bt == INT32) stack.Push((int)a > (int)b); | |
else if (bt == UINT32) stack.Push((int)a > (uint)b); | |
else if (bt == INT64) stack.Push((int)a > (long)b); | |
else if (bt == SINGLE) stack.Push((int)a > (float)b); | |
else if (bt == DOUBLE) stack.Push((int)a > (double)b); | |
else if (bt == DECIMAL) stack.Push((int)a > (decimal)b); | |
else if (bt == CHAR) stack.Push((int)a > (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a > (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a > (byte)b); | |
else if (bt == INT16) stack.Push((uint)a > (short)b); | |
else if (bt == UINT16) stack.Push((uint)a > (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a > (int)b); | |
else if (bt == UINT32) stack.Push((uint)a > (uint)b); | |
else if (bt == INT64) stack.Push((uint)a > (long)b); | |
else if (bt == UINT64) stack.Push((uint)a > (ulong)b); | |
else if (bt == SINGLE) stack.Push((uint)a > (float)b); | |
else if (bt == DOUBLE) stack.Push((uint)a > (double)b); | |
else if (bt == DECIMAL) stack.Push((uint)a > (decimal)b); | |
else if (bt == CHAR) stack.Push((uint)a > (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a > (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a > (byte)b); | |
else if (bt == INT16) stack.Push((long)a > (short)b); | |
else if (bt == UINT16) stack.Push((long)a > (ushort)b); | |
else if (bt == INT32) stack.Push((long)a > (int)b); | |
else if (bt == UINT32) stack.Push((long)a > (uint)b); | |
else if (bt == INT64) stack.Push((long)a > (long)b); | |
else if (bt == SINGLE) stack.Push((long)a > (float)b); | |
else if (bt == DOUBLE) stack.Push((long)a > (double)b); | |
else if (bt == DECIMAL) stack.Push((long)a > (decimal)b); | |
else if (bt == CHAR) stack.Push((long)a > (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a > (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a > (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a > (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a > (ulong)b); | |
else if (bt == SINGLE) stack.Push((ulong)a > (float)b); | |
else if (bt == DOUBLE) stack.Push((ulong)a > (double)b); | |
else if (bt == DECIMAL) stack.Push((ulong)a > (decimal)b); | |
else if (bt == CHAR) stack.Push((ulong)a > (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
if (bt == INT8) stack.Push((float)a > (sbyte)b); | |
else if (bt == UINT8) stack.Push((float)a > (byte)b); | |
else if (bt == INT16) stack.Push((float)a > (short)b); | |
else if (bt == UINT16) stack.Push((float)a > (ushort)b); | |
else if (bt == INT32) stack.Push((float)a > (int)b); | |
else if (bt == UINT32) stack.Push((float)a > (uint)b); | |
else if (bt == INT64) stack.Push((float)a > (long)b); | |
else if (bt == UINT64) stack.Push((float)a > (ulong)b); | |
else if (bt == SINGLE) stack.Push((float)a > (float)b); | |
else if (bt == DOUBLE) stack.Push((float)a > (double)b); | |
else if (bt == CHAR) stack.Push((float)a > (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
if (bt == INT8) stack.Push((double)a > (sbyte)b); | |
else if (bt == UINT8) stack.Push((double)a > (byte)b); | |
else if (bt == INT16) stack.Push((double)a > (short)b); | |
else if (bt == UINT16) stack.Push((double)a > (ushort)b); | |
else if (bt == INT32) stack.Push((double)a > (int)b); | |
else if (bt == UINT32) stack.Push((double)a > (uint)b); | |
else if (bt == INT64) stack.Push((double)a > (long)b); | |
else if (bt == UINT64) stack.Push((double)a > (ulong)b); | |
else if (bt == SINGLE) stack.Push((double)a > (float)b); | |
else if (bt == DOUBLE) stack.Push((double)a > (double)b); | |
else if (bt == CHAR) stack.Push((double)a > (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
if (bt == INT8) stack.Push((decimal)a > (sbyte)b); | |
else if (bt == UINT8) stack.Push((decimal)a > (byte)b); | |
else if (bt == INT16) stack.Push((decimal)a > (short)b); | |
else if (bt == UINT16) stack.Push((decimal)a > (ushort)b); | |
else if (bt == INT32) stack.Push((decimal)a > (int)b); | |
else if (bt == UINT32) stack.Push((decimal)a > (uint)b); | |
else if (bt == INT64) stack.Push((decimal)a > (long)b); | |
else if (bt == UINT64) stack.Push((decimal)a > (ulong)b); | |
else if (bt == DECIMAL) stack.Push((decimal)a > (decimal)b); | |
else if (bt == CHAR) stack.Push((decimal)a > (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a > (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a > (byte)b); | |
else if (bt == INT16) stack.Push((char)a > (short)b); | |
else if (bt == UINT16) stack.Push((char)a > (ushort)b); | |
else if (bt == INT32) stack.Push((char)a > (int)b); | |
else if (bt == UINT32) stack.Push((char)a > (uint)b); | |
else if (bt == INT64) stack.Push((char)a > (long)b); | |
else if (bt == UINT64) stack.Push((char)a > (ulong)b); | |
else if (bt == SINGLE) stack.Push((char)a > (float)b); | |
else if (bt == DOUBLE) stack.Push((char)a > (double)b); | |
else if (bt == DECIMAL) stack.Push((char)a > (decimal)b); | |
else if (bt == CHAR) stack.Push((char)a > (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_GreaterThan", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void Lte(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a <= (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a <= (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a <= (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a <= (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a <= (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a <= (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a <= (long)b); | |
else if (bt == SINGLE) stack.Push((sbyte)a <= (float)b); | |
else if (bt == DOUBLE) stack.Push((sbyte)a <= (double)b); | |
else if (bt == DECIMAL) stack.Push((sbyte)a <= (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a <= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a <= (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a <= (byte)b); | |
else if (bt == INT16) stack.Push((byte)a <= (short)b); | |
else if (bt == UINT16) stack.Push((byte)a <= (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a <= (int)b); | |
else if (bt == UINT32) stack.Push((byte)a <= (uint)b); | |
else if (bt == INT64) stack.Push((byte)a <= (long)b); | |
else if (bt == UINT64) stack.Push((byte)a <= (ulong)b); | |
else if (bt == SINGLE) stack.Push((byte)a <= (float)b); | |
else if (bt == DOUBLE) stack.Push((byte)a <= (double)b); | |
else if (bt == DECIMAL) stack.Push((byte)a <= (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a <= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a <= (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a <= (byte)b); | |
else if (bt == INT16) stack.Push((short)a <= (short)b); | |
else if (bt == UINT16) stack.Push((short)a <= (ushort)b); | |
else if (bt == INT32) stack.Push((short)a <= (int)b); | |
else if (bt == UINT32) stack.Push((short)a <= (uint)b); | |
else if (bt == INT64) stack.Push((short)a <= (long)b); | |
else if (bt == SINGLE) stack.Push((short)a <= (float)b); | |
else if (bt == DOUBLE) stack.Push((short)a <= (double)b); | |
else if (bt == DECIMAL) stack.Push((short)a <= (decimal)b); | |
else if (bt == CHAR) stack.Push((short)a <= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a <= (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a <= (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a <= (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a <= (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a <= (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a <= (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a <= (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a <= (ulong)b); | |
else if (bt == SINGLE) stack.Push((ushort)a <= (float)b); | |
else if (bt == DOUBLE) stack.Push((ushort)a <= (double)b); | |
else if (bt == DECIMAL) stack.Push((ushort)a <= (decimal)b); | |
else if (bt == CHAR) stack.Push((ushort)a <= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a <= (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a <= (byte)b); | |
else if (bt == INT16) stack.Push((int)a <= (short)b); | |
else if (bt == UINT16) stack.Push((int)a <= (ushort)b); | |
else if (bt == INT32) stack.Push((int)a <= (int)b); | |
else if (bt == UINT32) stack.Push((int)a <= (uint)b); | |
else if (bt == INT64) stack.Push((int)a <= (long)b); | |
else if (bt == SINGLE) stack.Push((int)a <= (float)b); | |
else if (bt == DOUBLE) stack.Push((int)a <= (double)b); | |
else if (bt == DECIMAL) stack.Push((int)a <= (decimal)b); | |
else if (bt == CHAR) stack.Push((int)a <= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a <= (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a <= (byte)b); | |
else if (bt == INT16) stack.Push((uint)a <= (short)b); | |
else if (bt == UINT16) stack.Push((uint)a <= (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a <= (int)b); | |
else if (bt == UINT32) stack.Push((uint)a <= (uint)b); | |
else if (bt == INT64) stack.Push((uint)a <= (long)b); | |
else if (bt == UINT64) stack.Push((uint)a <= (ulong)b); | |
else if (bt == SINGLE) stack.Push((uint)a <= (float)b); | |
else if (bt == DOUBLE) stack.Push((uint)a <= (double)b); | |
else if (bt == DECIMAL) stack.Push((uint)a <= (decimal)b); | |
else if (bt == CHAR) stack.Push((uint)a <= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a <= (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a <= (byte)b); | |
else if (bt == INT16) stack.Push((long)a <= (short)b); | |
else if (bt == UINT16) stack.Push((long)a <= (ushort)b); | |
else if (bt == INT32) stack.Push((long)a <= (int)b); | |
else if (bt == UINT32) stack.Push((long)a <= (uint)b); | |
else if (bt == INT64) stack.Push((long)a <= (long)b); | |
else if (bt == SINGLE) stack.Push((long)a <= (float)b); | |
else if (bt == DOUBLE) stack.Push((long)a <= (double)b); | |
else if (bt == DECIMAL) stack.Push((long)a <= (decimal)b); | |
else if (bt == CHAR) stack.Push((long)a <= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a <= (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a <= (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a <= (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a <= (ulong)b); | |
else if (bt == SINGLE) stack.Push((ulong)a <= (float)b); | |
else if (bt == DOUBLE) stack.Push((ulong)a <= (double)b); | |
else if (bt == DECIMAL) stack.Push((ulong)a <= (decimal)b); | |
else if (bt == CHAR) stack.Push((ulong)a <= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
if (bt == INT8) stack.Push((float)a <= (sbyte)b); | |
else if (bt == UINT8) stack.Push((float)a <= (byte)b); | |
else if (bt == INT16) stack.Push((float)a <= (short)b); | |
else if (bt == UINT16) stack.Push((float)a <= (ushort)b); | |
else if (bt == INT32) stack.Push((float)a <= (int)b); | |
else if (bt == UINT32) stack.Push((float)a <= (uint)b); | |
else if (bt == INT64) stack.Push((float)a <= (long)b); | |
else if (bt == UINT64) stack.Push((float)a <= (ulong)b); | |
else if (bt == SINGLE) stack.Push((float)a <= (float)b); | |
else if (bt == DOUBLE) stack.Push((float)a <= (double)b); | |
else if (bt == CHAR) stack.Push((float)a <= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
if (bt == INT8) stack.Push((double)a <= (sbyte)b); | |
else if (bt == UINT8) stack.Push((double)a <= (byte)b); | |
else if (bt == INT16) stack.Push((double)a <= (short)b); | |
else if (bt == UINT16) stack.Push((double)a <= (ushort)b); | |
else if (bt == INT32) stack.Push((double)a <= (int)b); | |
else if (bt == UINT32) stack.Push((double)a <= (uint)b); | |
else if (bt == INT64) stack.Push((double)a <= (long)b); | |
else if (bt == UINT64) stack.Push((double)a <= (ulong)b); | |
else if (bt == SINGLE) stack.Push((double)a <= (float)b); | |
else if (bt == DOUBLE) stack.Push((double)a <= (double)b); | |
else if (bt == CHAR) stack.Push((double)a <= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
if (bt == INT8) stack.Push((decimal)a <= (sbyte)b); | |
else if (bt == UINT8) stack.Push((decimal)a <= (byte)b); | |
else if (bt == INT16) stack.Push((decimal)a <= (short)b); | |
else if (bt == UINT16) stack.Push((decimal)a <= (ushort)b); | |
else if (bt == INT32) stack.Push((decimal)a <= (int)b); | |
else if (bt == UINT32) stack.Push((decimal)a <= (uint)b); | |
else if (bt == INT64) stack.Push((decimal)a <= (long)b); | |
else if (bt == UINT64) stack.Push((decimal)a <= (ulong)b); | |
else if (bt == DECIMAL) stack.Push((decimal)a <= (decimal)b); | |
else if (bt == CHAR) stack.Push((decimal)a <= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a <= (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a <= (byte)b); | |
else if (bt == INT16) stack.Push((char)a <= (short)b); | |
else if (bt == UINT16) stack.Push((char)a <= (ushort)b); | |
else if (bt == INT32) stack.Push((char)a <= (int)b); | |
else if (bt == UINT32) stack.Push((char)a <= (uint)b); | |
else if (bt == INT64) stack.Push((char)a <= (long)b); | |
else if (bt == UINT64) stack.Push((char)a <= (ulong)b); | |
else if (bt == SINGLE) stack.Push((char)a <= (float)b); | |
else if (bt == DOUBLE) stack.Push((char)a <= (double)b); | |
else if (bt == DECIMAL) stack.Push((char)a <= (decimal)b); | |
else if (bt == CHAR) stack.Push((char)a <= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
{ | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_LessThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void Gte(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a >= (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a >= (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a >= (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a >= (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a >= (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a >= (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a >= (long)b); | |
else if (bt == SINGLE) stack.Push((sbyte)a >= (float)b); | |
else if (bt == DOUBLE) stack.Push((sbyte)a >= (double)b); | |
else if (bt == DECIMAL) stack.Push((sbyte)a >= (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a >= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a >= (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a >= (byte)b); | |
else if (bt == INT16) stack.Push((byte)a >= (short)b); | |
else if (bt == UINT16) stack.Push((byte)a >= (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a >= (int)b); | |
else if (bt == UINT32) stack.Push((byte)a >= (uint)b); | |
else if (bt == INT64) stack.Push((byte)a >= (long)b); | |
else if (bt == UINT64) stack.Push((byte)a >= (ulong)b); | |
else if (bt == SINGLE) stack.Push((byte)a >= (float)b); | |
else if (bt == DOUBLE) stack.Push((byte)a >= (double)b); | |
else if (bt == DECIMAL) stack.Push((byte)a >= (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a >= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a >= (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a >= (byte)b); | |
else if (bt == INT16) stack.Push((short)a >= (short)b); | |
else if (bt == UINT16) stack.Push((short)a >= (ushort)b); | |
else if (bt == INT32) stack.Push((short)a >= (int)b); | |
else if (bt == UINT32) stack.Push((short)a >= (uint)b); | |
else if (bt == INT64) stack.Push((short)a >= (long)b); | |
else if (bt == SINGLE) stack.Push((short)a >= (float)b); | |
else if (bt == DOUBLE) stack.Push((short)a >= (double)b); | |
else if (bt == DECIMAL) stack.Push((short)a >= (decimal)b); | |
else if (bt == CHAR) stack.Push((short)a >= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a >= (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a >= (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a >= (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a >= (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a >= (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a >= (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a >= (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a >= (ulong)b); | |
else if (bt == SINGLE) stack.Push((ushort)a >= (float)b); | |
else if (bt == DOUBLE) stack.Push((ushort)a >= (double)b); | |
else if (bt == DECIMAL) stack.Push((ushort)a >= (decimal)b); | |
else if (bt == CHAR) stack.Push((ushort)a >= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a >= (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a >= (byte)b); | |
else if (bt == INT16) stack.Push((int)a >= (short)b); | |
else if (bt == UINT16) stack.Push((int)a >= (ushort)b); | |
else if (bt == INT32) stack.Push((int)a >= (int)b); | |
else if (bt == UINT32) stack.Push((int)a >= (uint)b); | |
else if (bt == INT64) stack.Push((int)a >= (long)b); | |
else if (bt == SINGLE) stack.Push((int)a >= (float)b); | |
else if (bt == DOUBLE) stack.Push((int)a >= (double)b); | |
else if (bt == DECIMAL) stack.Push((int)a >= (decimal)b); | |
else if (bt == CHAR) stack.Push((int)a >= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a >= (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a >= (byte)b); | |
else if (bt == INT16) stack.Push((uint)a >= (short)b); | |
else if (bt == UINT16) stack.Push((uint)a >= (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a >= (int)b); | |
else if (bt == UINT32) stack.Push((uint)a >= (uint)b); | |
else if (bt == INT64) stack.Push((uint)a >= (long)b); | |
else if (bt == UINT64) stack.Push((uint)a >= (ulong)b); | |
else if (bt == SINGLE) stack.Push((uint)a >= (float)b); | |
else if (bt == DOUBLE) stack.Push((uint)a >= (double)b); | |
else if (bt == DECIMAL) stack.Push((uint)a >= (decimal)b); | |
else if (bt == CHAR) stack.Push((uint)a >= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a >= (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a >= (byte)b); | |
else if (bt == INT16) stack.Push((long)a >= (short)b); | |
else if (bt == UINT16) stack.Push((long)a >= (ushort)b); | |
else if (bt == INT32) stack.Push((long)a >= (int)b); | |
else if (bt == UINT32) stack.Push((long)a >= (uint)b); | |
else if (bt == INT64) stack.Push((long)a >= (long)b); | |
else if (bt == SINGLE) stack.Push((long)a >= (float)b); | |
else if (bt == DOUBLE) stack.Push((long)a >= (double)b); | |
else if (bt == DECIMAL) stack.Push((long)a >= (decimal)b); | |
else if (bt == CHAR) stack.Push((long)a >= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a >= (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a >= (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a >= (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a >= (ulong)b); | |
else if (bt == SINGLE) stack.Push((ulong)a >= (float)b); | |
else if (bt == DOUBLE) stack.Push((ulong)a >= (double)b); | |
else if (bt == DECIMAL) stack.Push((ulong)a >= (decimal)b); | |
else if (bt == CHAR) stack.Push((ulong)a >= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
if (bt == INT8) stack.Push((float)a >= (sbyte)b); | |
else if (bt == UINT8) stack.Push((float)a >= (byte)b); | |
else if (bt == INT16) stack.Push((float)a >= (short)b); | |
else if (bt == UINT16) stack.Push((float)a >= (ushort)b); | |
else if (bt == INT32) stack.Push((float)a >= (int)b); | |
else if (bt == UINT32) stack.Push((float)a >= (uint)b); | |
else if (bt == INT64) stack.Push((float)a >= (long)b); | |
else if (bt == UINT64) stack.Push((float)a >= (ulong)b); | |
else if (bt == SINGLE) stack.Push((float)a >= (float)b); | |
else if (bt == DOUBLE) stack.Push((float)a >= (double)b); | |
else if (bt == CHAR) stack.Push((float)a >= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
if (bt == INT8) stack.Push((double)a >= (sbyte)b); | |
else if (bt == UINT8) stack.Push((double)a >= (byte)b); | |
else if (bt == INT16) stack.Push((double)a >= (short)b); | |
else if (bt == UINT16) stack.Push((double)a >= (ushort)b); | |
else if (bt == INT32) stack.Push((double)a >= (int)b); | |
else if (bt == UINT32) stack.Push((double)a >= (uint)b); | |
else if (bt == INT64) stack.Push((double)a >= (long)b); | |
else if (bt == UINT64) stack.Push((double)a >= (ulong)b); | |
else if (bt == SINGLE) stack.Push((double)a >= (float)b); | |
else if (bt == DOUBLE) stack.Push((double)a >= (double)b); | |
else if (bt == CHAR) stack.Push((double)a >= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
if (bt == INT8) stack.Push((decimal)a >= (sbyte)b); | |
else if (bt == UINT8) stack.Push((decimal)a >= (byte)b); | |
else if (bt == INT16) stack.Push((decimal)a >= (short)b); | |
else if (bt == UINT16) stack.Push((decimal)a >= (ushort)b); | |
else if (bt == INT32) stack.Push((decimal)a >= (int)b); | |
else if (bt == UINT32) stack.Push((decimal)a >= (uint)b); | |
else if (bt == INT64) stack.Push((decimal)a >= (long)b); | |
else if (bt == UINT64) stack.Push((decimal)a >= (ulong)b); | |
else if (bt == DECIMAL) stack.Push((decimal)a >= (decimal)b); | |
else if (bt == CHAR) stack.Push((decimal)a >= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a >= (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a >= (byte)b); | |
else if (bt == INT16) stack.Push((char)a >= (short)b); | |
else if (bt == UINT16) stack.Push((char)a >= (ushort)b); | |
else if (bt == INT32) stack.Push((char)a >= (int)b); | |
else if (bt == UINT32) stack.Push((char)a >= (uint)b); | |
else if (bt == INT64) stack.Push((char)a >= (long)b); | |
else if (bt == UINT64) stack.Push((char)a >= (ulong)b); | |
else if (bt == SINGLE) stack.Push((char)a >= (float)b); | |
else if (bt == DOUBLE) stack.Push((char)a >= (double)b); | |
else if (bt == DECIMAL) stack.Push((char)a >= (decimal)b); | |
else if (bt == CHAR) stack.Push((char)a >= (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
{ | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_GreaterThanOrEqual", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void Equal(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a == (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a == (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a == (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a == (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a == (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a == (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a == (long)b); | |
else if (bt == SINGLE) stack.Push((sbyte)a == (float)b); | |
else if (bt == DOUBLE) stack.Push((sbyte)a == (double)b); | |
else if (bt == DECIMAL) stack.Push((sbyte)a == (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a == (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a == (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a == (byte)b); | |
else if (bt == INT16) stack.Push((byte)a == (short)b); | |
else if (bt == UINT16) stack.Push((byte)a == (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a == (int)b); | |
else if (bt == UINT32) stack.Push((byte)a == (uint)b); | |
else if (bt == INT64) stack.Push((byte)a == (long)b); | |
else if (bt == UINT64) stack.Push((byte)a == (ulong)b); | |
else if (bt == SINGLE) stack.Push((byte)a == (float)b); | |
else if (bt == DOUBLE) stack.Push((byte)a == (double)b); | |
else if (bt == DECIMAL) stack.Push((byte)a == (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a == (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a == (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a == (byte)b); | |
else if (bt == INT16) stack.Push((short)a == (short)b); | |
else if (bt == UINT16) stack.Push((short)a == (ushort)b); | |
else if (bt == INT32) stack.Push((short)a == (int)b); | |
else if (bt == UINT32) stack.Push((short)a == (uint)b); | |
else if (bt == INT64) stack.Push((short)a == (long)b); | |
else if (bt == SINGLE) stack.Push((short)a == (float)b); | |
else if (bt == DOUBLE) stack.Push((short)a == (double)b); | |
else if (bt == DECIMAL) stack.Push((short)a == (decimal)b); | |
else if (bt == CHAR) stack.Push((short)a == (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a == (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a == (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a == (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a == (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a == (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a == (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a == (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a == (ulong)b); | |
else if (bt == SINGLE) stack.Push((ushort)a == (float)b); | |
else if (bt == DOUBLE) stack.Push((ushort)a == (double)b); | |
else if (bt == DECIMAL) stack.Push((ushort)a == (decimal)b); | |
else if (bt == CHAR) stack.Push((ushort)a == (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a == (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a == (byte)b); | |
else if (bt == INT16) stack.Push((int)a == (short)b); | |
else if (bt == UINT16) stack.Push((int)a == (ushort)b); | |
else if (bt == INT32) stack.Push((int)a == (int)b); | |
else if (bt == UINT32) stack.Push((int)a == (uint)b); | |
else if (bt == INT64) stack.Push((int)a == (long)b); | |
else if (bt == SINGLE) stack.Push((int)a == (float)b); | |
else if (bt == DOUBLE) stack.Push((int)a == (double)b); | |
else if (bt == DECIMAL) stack.Push((int)a == (decimal)b); | |
else if (bt == CHAR) stack.Push((int)a == (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a == (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a == (byte)b); | |
else if (bt == INT16) stack.Push((uint)a == (short)b); | |
else if (bt == UINT16) stack.Push((uint)a == (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a == (int)b); | |
else if (bt == UINT32) stack.Push((uint)a == (uint)b); | |
else if (bt == INT64) stack.Push((uint)a == (long)b); | |
else if (bt == UINT64) stack.Push((uint)a == (ulong)b); | |
else if (bt == SINGLE) stack.Push((uint)a == (float)b); | |
else if (bt == DOUBLE) stack.Push((uint)a == (double)b); | |
else if (bt == DECIMAL) stack.Push((uint)a == (decimal)b); | |
else if (bt == CHAR) stack.Push((uint)a == (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a == (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a == (byte)b); | |
else if (bt == INT16) stack.Push((long)a == (short)b); | |
else if (bt == UINT16) stack.Push((long)a == (ushort)b); | |
else if (bt == INT32) stack.Push((long)a == (int)b); | |
else if (bt == UINT32) stack.Push((long)a == (uint)b); | |
else if (bt == INT64) stack.Push((long)a == (long)b); | |
else if (bt == SINGLE) stack.Push((long)a == (float)b); | |
else if (bt == DOUBLE) stack.Push((long)a == (double)b); | |
else if (bt == DECIMAL) stack.Push((long)a == (decimal)b); | |
else if (bt == CHAR) stack.Push((long)a == (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a == (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a == (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a == (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a == (ulong)b); | |
else if (bt == SINGLE) stack.Push((ulong)a == (float)b); | |
else if (bt == DOUBLE) stack.Push((ulong)a == (double)b); | |
else if (bt == DECIMAL) stack.Push((ulong)a == (decimal)b); | |
else if (bt == CHAR) stack.Push((ulong)a == (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
if (bt == INT8) stack.Push((float)a == (sbyte)b); | |
else if (bt == UINT8) stack.Push((float)a == (byte)b); | |
else if (bt == INT16) stack.Push((float)a == (short)b); | |
else if (bt == UINT16) stack.Push((float)a == (ushort)b); | |
else if (bt == INT32) stack.Push((float)a == (int)b); | |
else if (bt == UINT32) stack.Push((float)a == (uint)b); | |
else if (bt == INT64) stack.Push((float)a == (long)b); | |
else if (bt == UINT64) stack.Push((float)a == (ulong)b); | |
else if (bt == SINGLE) stack.Push((float)a == (float)b); | |
else if (bt == DOUBLE) stack.Push((float)a == (double)b); | |
else if (bt == CHAR) stack.Push((float)a == (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
if (bt == INT8) stack.Push((double)a == (sbyte)b); | |
else if (bt == UINT8) stack.Push((double)a == (byte)b); | |
else if (bt == INT16) stack.Push((double)a == (short)b); | |
else if (bt == UINT16) stack.Push((double)a == (ushort)b); | |
else if (bt == INT32) stack.Push((double)a == (int)b); | |
else if (bt == UINT32) stack.Push((double)a == (uint)b); | |
else if (bt == INT64) stack.Push((double)a == (long)b); | |
else if (bt == UINT64) stack.Push((double)a == (ulong)b); | |
else if (bt == SINGLE) stack.Push((double)a == (float)b); | |
else if (bt == DOUBLE) stack.Push((double)a == (double)b); | |
else if (bt == CHAR) stack.Push((double)a == (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
if (bt == INT8) stack.Push((decimal)a == (sbyte)b); | |
else if (bt == UINT8) stack.Push((decimal)a == (byte)b); | |
else if (bt == INT16) stack.Push((decimal)a == (short)b); | |
else if (bt == UINT16) stack.Push((decimal)a == (ushort)b); | |
else if (bt == INT32) stack.Push((decimal)a == (int)b); | |
else if (bt == UINT32) stack.Push((decimal)a == (uint)b); | |
else if (bt == INT64) stack.Push((decimal)a == (long)b); | |
else if (bt == UINT64) stack.Push((decimal)a == (ulong)b); | |
else if (bt == DECIMAL) stack.Push((decimal)a == (decimal)b); | |
else if (bt == CHAR) stack.Push((decimal)a == (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a == (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a == (byte)b); | |
else if (bt == INT16) stack.Push((char)a == (short)b); | |
else if (bt == UINT16) stack.Push((char)a == (ushort)b); | |
else if (bt == INT32) stack.Push((char)a == (int)b); | |
else if (bt == UINT32) stack.Push((char)a == (uint)b); | |
else if (bt == INT64) stack.Push((char)a == (long)b); | |
else if (bt == UINT64) stack.Push((char)a == (ulong)b); | |
else if (bt == SINGLE) stack.Push((char)a == (float)b); | |
else if (bt == DOUBLE) stack.Push((char)a == (double)b); | |
else if (bt == DECIMAL) stack.Push((char)a == (decimal)b); | |
else if (bt == CHAR) stack.Push((char)a == (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
if (bt == BOOLEAN) stack.Push((bool)a == (bool)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
if (bt == STRING) stack.Push((string)a == (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_Equality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void Inequal(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a != (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a != (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a != (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a != (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a != (int)b); | |
else if (bt == UINT32) stack.Push((sbyte)a != (uint)b); | |
else if (bt == INT64) stack.Push((sbyte)a != (long)b); | |
else if (bt == SINGLE) stack.Push((sbyte)a != (float)b); | |
else if (bt == DOUBLE) stack.Push((sbyte)a != (double)b); | |
else if (bt == DECIMAL) stack.Push((sbyte)a != (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a != (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a != (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a != (byte)b); | |
else if (bt == INT16) stack.Push((byte)a != (short)b); | |
else if (bt == UINT16) stack.Push((byte)a != (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a != (int)b); | |
else if (bt == UINT32) stack.Push((byte)a != (uint)b); | |
else if (bt == INT64) stack.Push((byte)a != (long)b); | |
else if (bt == UINT64) stack.Push((byte)a != (ulong)b); | |
else if (bt == SINGLE) stack.Push((byte)a != (float)b); | |
else if (bt == DOUBLE) stack.Push((byte)a != (double)b); | |
else if (bt == DECIMAL) stack.Push((byte)a != (decimal)b); | |
else if (bt == CHAR) stack.Push((sbyte)a != (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a != (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a != (byte)b); | |
else if (bt == INT16) stack.Push((short)a != (short)b); | |
else if (bt == UINT16) stack.Push((short)a != (ushort)b); | |
else if (bt == INT32) stack.Push((short)a != (int)b); | |
else if (bt == UINT32) stack.Push((short)a != (uint)b); | |
else if (bt == INT64) stack.Push((short)a != (long)b); | |
else if (bt == SINGLE) stack.Push((short)a != (float)b); | |
else if (bt == DOUBLE) stack.Push((short)a != (double)b); | |
else if (bt == DECIMAL) stack.Push((short)a != (decimal)b); | |
else if (bt == CHAR) stack.Push((short)a != (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a != (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a != (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a != (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a != (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a != (int)b); | |
else if (bt == UINT32) stack.Push((ushort)a != (uint)b); | |
else if (bt == INT64) stack.Push((ushort)a != (long)b); | |
else if (bt == UINT64) stack.Push((ushort)a != (ulong)b); | |
else if (bt == SINGLE) stack.Push((ushort)a != (float)b); | |
else if (bt == DOUBLE) stack.Push((ushort)a != (double)b); | |
else if (bt == DECIMAL) stack.Push((ushort)a != (decimal)b); | |
else if (bt == CHAR) stack.Push((ushort)a != (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a != (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a != (byte)b); | |
else if (bt == INT16) stack.Push((int)a != (short)b); | |
else if (bt == UINT16) stack.Push((int)a != (ushort)b); | |
else if (bt == INT32) stack.Push((int)a != (int)b); | |
else if (bt == UINT32) stack.Push((int)a != (uint)b); | |
else if (bt == INT64) stack.Push((int)a != (long)b); | |
else if (bt == SINGLE) stack.Push((int)a != (float)b); | |
else if (bt == DOUBLE) stack.Push((int)a != (double)b); | |
else if (bt == DECIMAL) stack.Push((int)a != (decimal)b); | |
else if (bt == CHAR) stack.Push((int)a != (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a != (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a != (byte)b); | |
else if (bt == INT16) stack.Push((uint)a != (short)b); | |
else if (bt == UINT16) stack.Push((uint)a != (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a != (int)b); | |
else if (bt == UINT32) stack.Push((uint)a != (uint)b); | |
else if (bt == INT64) stack.Push((uint)a != (long)b); | |
else if (bt == UINT64) stack.Push((uint)a != (ulong)b); | |
else if (bt == SINGLE) stack.Push((uint)a != (float)b); | |
else if (bt == DOUBLE) stack.Push((uint)a != (double)b); | |
else if (bt == DECIMAL) stack.Push((uint)a != (decimal)b); | |
else if (bt == CHAR) stack.Push((uint)a != (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a != (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a != (byte)b); | |
else if (bt == INT16) stack.Push((long)a != (short)b); | |
else if (bt == UINT16) stack.Push((long)a != (ushort)b); | |
else if (bt == INT32) stack.Push((long)a != (int)b); | |
else if (bt == UINT32) stack.Push((long)a != (uint)b); | |
else if (bt == INT64) stack.Push((long)a != (long)b); | |
else if (bt == SINGLE) stack.Push((long)a != (float)b); | |
else if (bt == DOUBLE) stack.Push((long)a != (double)b); | |
else if (bt == DECIMAL) stack.Push((long)a != (decimal)b); | |
else if (bt == CHAR) stack.Push((long)a != (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == UINT8) stack.Push((ulong)a != (byte)b); | |
else if (bt == UINT16) stack.Push((ulong)a != (ushort)b); | |
else if (bt == UINT32) stack.Push((ulong)a != (uint)b); | |
else if (bt == UINT64) stack.Push((ulong)a != (ulong)b); | |
else if (bt == SINGLE) stack.Push((ulong)a != (float)b); | |
else if (bt == DOUBLE) stack.Push((ulong)a != (double)b); | |
else if (bt == DECIMAL) stack.Push((ulong)a != (decimal)b); | |
else if (bt == CHAR) stack.Push((ulong)a != (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
if (bt == INT8) stack.Push((float)a != (sbyte)b); | |
else if (bt == UINT8) stack.Push((float)a != (byte)b); | |
else if (bt == INT16) stack.Push((float)a != (short)b); | |
else if (bt == UINT16) stack.Push((float)a != (ushort)b); | |
else if (bt == INT32) stack.Push((float)a != (int)b); | |
else if (bt == UINT32) stack.Push((float)a != (uint)b); | |
else if (bt == INT64) stack.Push((float)a != (long)b); | |
else if (bt == UINT64) stack.Push((float)a != (ulong)b); | |
else if (bt == SINGLE) stack.Push((float)a != (float)b); | |
else if (bt == DOUBLE) stack.Push((float)a != (double)b); | |
else if (bt == CHAR) stack.Push((float)a != (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
if (bt == INT8) stack.Push((double)a != (sbyte)b); | |
else if (bt == UINT8) stack.Push((double)a != (byte)b); | |
else if (bt == INT16) stack.Push((double)a != (short)b); | |
else if (bt == UINT16) stack.Push((double)a != (ushort)b); | |
else if (bt == INT32) stack.Push((double)a != (int)b); | |
else if (bt == UINT32) stack.Push((double)a != (uint)b); | |
else if (bt == INT64) stack.Push((double)a != (long)b); | |
else if (bt == UINT64) stack.Push((double)a != (ulong)b); | |
else if (bt == SINGLE) stack.Push((double)a != (float)b); | |
else if (bt == DOUBLE) stack.Push((double)a != (double)b); | |
else if (bt == CHAR) stack.Push((double)a != (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
if (bt == INT8) stack.Push((decimal)a != (sbyte)b); | |
else if (bt == UINT8) stack.Push((decimal)a != (byte)b); | |
else if (bt == INT16) stack.Push((decimal)a != (short)b); | |
else if (bt == UINT16) stack.Push((decimal)a != (ushort)b); | |
else if (bt == INT32) stack.Push((decimal)a != (int)b); | |
else if (bt == UINT32) stack.Push((decimal)a != (uint)b); | |
else if (bt == INT64) stack.Push((decimal)a != (long)b); | |
else if (bt == UINT64) stack.Push((decimal)a != (ulong)b); | |
else if (bt == DECIMAL) stack.Push((decimal)a != (decimal)b); | |
else if (bt == CHAR) stack.Push((decimal)a != (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a != (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a != (byte)b); | |
else if (bt == INT16) stack.Push((char)a != (short)b); | |
else if (bt == UINT16) stack.Push((char)a != (ushort)b); | |
else if (bt == INT32) stack.Push((char)a != (int)b); | |
else if (bt == UINT32) stack.Push((char)a != (uint)b); | |
else if (bt == INT64) stack.Push((char)a != (long)b); | |
else if (bt == UINT64) stack.Push((char)a != (ulong)b); | |
else if (bt == SINGLE) stack.Push((char)a != (float)b); | |
else if (bt == DOUBLE) stack.Push((char)a != (double)b); | |
else if (bt == DECIMAL) stack.Push((char)a != (decimal)b); | |
else if (bt == CHAR) stack.Push((char)a != (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
if (bt == BOOLEAN) stack.Push((bool)a != (bool)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
if (bt == STRING) stack.Push((string)a != (string)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_Inequality", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void Increment(Stack<object> stack) | |
{ | |
if (stack.Count > 0) | |
{ | |
object a = stack.Pop(); | |
Type t = a.GetType(); | |
if (t == INT8) stack.Push(((sbyte)a + 1)); | |
else if (t == UINT8) stack.Push((byte)a + 1); | |
else if (t == INT16) stack.Push((short)a + 1); | |
else if (t == UINT16) stack.Push((ushort)a + 1); | |
else if (t == INT32) stack.Push((int)a + 1); | |
else if (t == UINT32) stack.Push((uint)a + 1); | |
else if (t == INT64) stack.Push((long)a + 1); | |
else if (t == UINT64) stack.Push((ulong)a + 1); | |
else if (t == SINGLE) stack.Push((float)a + 1f); | |
else if (t == DOUBLE) stack.Push((double)a + 1d); | |
else if (t == DECIMAL) stack.Push((decimal)a + 1m); | |
else if (t == CHAR) stack.Push((char)a + 1); | |
else | |
{ | |
MethodInfo m = t.GetMethod("op_Increment", new Type[] { t }); | |
if (m != null && m.ReturnType != typeof(void)) | |
stack.Push(m.Invoke(null, new object[] { a })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Empty!"); | |
} | |
public static void Decrement(Stack<object> stack) | |
{ | |
if (stack.Count > 0) | |
{ | |
object a = stack.Pop(); | |
Type t = a.GetType(); | |
if (t == INT8) stack.Push(((sbyte)a - 1)); | |
else if (t == UINT8) stack.Push((byte)a - 1); | |
else if (t == INT16) stack.Push((short)a - 1); | |
else if (t == UINT16) stack.Push((ushort)a - 1); | |
else if (t == INT32) stack.Push((int)a - 1); | |
else if (t == UINT32) stack.Push((uint)a - 1); | |
else if (t == INT64) stack.Push((long)a - 1); | |
else if (t == UINT64) stack.Push((ulong)a - 1); | |
else if (t == SINGLE) stack.Push((float)a - 1f); | |
else if (t == DOUBLE) stack.Push((double)a - 1d); | |
else if (t == DECIMAL) stack.Push((decimal)a - 1m); | |
else if (t == CHAR) stack.Push((char)a - 1); | |
else | |
{ | |
MethodInfo m = t.GetMethod("op_Decrement", new Type[] { t }); | |
if (m != null && m.ReturnType != typeof(void)) | |
stack.Push(m.Invoke(null, new object[] { a })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Empty!"); | |
} | |
public static void Not(Stack<object> stack) | |
{ | |
if (stack.Count > 0) | |
{ | |
object a = stack.Pop(); | |
Type t = a.GetType(); | |
if (t == BOOLEAN) stack.Push(!((bool)a)); | |
else | |
{ | |
MethodInfo m = t.GetMethod("op_LogicalNot", new Type[] { t }); | |
if (m != null && m.ReturnType != typeof(void)) | |
stack.Push(m.Invoke(null, new object[] { a })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Empty!"); | |
} | |
public static void Complement(Stack<object> stack) | |
{ | |
if (stack.Count > 0) | |
{ | |
object a = stack.Pop(); | |
Type t = a.GetType(); | |
if (t == INT8) stack.Push(~((sbyte)a)); | |
else if (t == UINT8) stack.Push(~((byte)a)); | |
else if (t == INT16) stack.Push(~((short)a)); | |
else if (t == UINT16) stack.Push(~((ushort)a)); | |
else if (t == INT32) stack.Push((~(int)a)); | |
else if (t == UINT32) stack.Push(~((uint)a)); | |
else if (t == INT64) stack.Push((~(long)a)); | |
else if (t == UINT64) stack.Push(~((ulong)a)); | |
else if (t == CHAR) stack.Push(~((char)a)); | |
else | |
{ | |
MethodInfo m = t.GetMethod("op_OnesComplement", new Type[] { t }); | |
if (m != null && m.ReturnType != typeof(void)) | |
stack.Push(m.Invoke(null, new object[] { a })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Empty!"); | |
} | |
public static void Negate(Stack<object> stack) | |
{ | |
if (stack.Count > 0) | |
{ | |
object a = stack.Pop(); | |
Type t = a.GetType(); | |
if (t == INT8) stack.Push(-((sbyte)a)); | |
else if (t == UINT8) stack.Push(-((byte)a)); | |
else if (t == INT16) stack.Push(-((short)a)); | |
else if (t == UINT16) stack.Push(-((ushort)a)); | |
else if (t == INT32) stack.Push(-((int)a)); | |
else if (t == UINT32) stack.Push(-((uint)a)); | |
else if (t == INT64) stack.Push((-(long)a)); | |
else if (t == SINGLE) stack.Push(-((float)a)); | |
else if (t == DOUBLE) stack.Push(-((double)a)); | |
else if (t == DECIMAL) stack.Push(-((decimal)a)); | |
else if (t == CHAR) stack.Push(-((char)a)); | |
else | |
{ | |
MethodInfo m = t.GetMethod("op_UnaryNegate", new Type[] { t }); | |
if (m != null && m.ReturnType != typeof(void)) | |
stack.Push(m.Invoke(null, new object[] { a })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Empty!"); | |
} | |
public static void Plus(Stack<object> stack) | |
{ | |
if (stack.Count > 0) | |
{ | |
object a = stack.Pop(); | |
Type t = a.GetType(); | |
if (t == INT8) stack.Push(+((sbyte)a)); | |
else if (t == UINT8) stack.Push(+((byte)a)); | |
else if (t == INT16) stack.Push(+((short)a)); | |
else if (t == UINT16) stack.Push(+((ushort)a)); | |
else if (t == INT32) stack.Push(+((int)a)); | |
else if (t == UINT32) stack.Push(+((uint)a)); | |
else if (t == INT64) stack.Push((+(long)a)); | |
else if (t == UINT64) stack.Push(+((ulong)a)); | |
else if (t == SINGLE) stack.Push(+((float)a)); | |
else if (t == DOUBLE) stack.Push(+((double)a)); | |
else if (t == DECIMAL) stack.Push(+((decimal)a)); | |
else if (t == CHAR) stack.Push(+((char)a)); | |
else | |
{ | |
MethodInfo m = t.GetMethod("op_UnaryPlus", new Type[] { t }); | |
if (m != null && m.ReturnType != typeof(void)) | |
stack.Push(m.Invoke(null, new object[] { a })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Empty!"); | |
} | |
public static void Shl(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a << (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a << (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a << (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a << (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a << (int)b); | |
else if (bt == CHAR) stack.Push((sbyte)a << (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a << (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a << (byte)b); | |
else if (bt == INT16) stack.Push((byte)a << (short)b); | |
else if (bt == UINT16) stack.Push((byte)a << (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a << (int)b); | |
else if (bt == CHAR) stack.Push((sbyte)a << (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a << (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a << (byte)b); | |
else if (bt == INT16) stack.Push((short)a << (short)b); | |
else if (bt == UINT16) stack.Push((short)a << (ushort)b); | |
else if (bt == INT32) stack.Push((short)a << (int)b); | |
else if (bt == CHAR) stack.Push((short)a << (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a << (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a << (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a << (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a << (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a << (int)b); | |
else if (bt == CHAR) stack.Push((ushort)a << (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a << (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a << (byte)b); | |
else if (bt == INT16) stack.Push((int)a << (short)b); | |
else if (bt == UINT16) stack.Push((int)a << (ushort)b); | |
else if (bt == INT32) stack.Push((int)a << (int)b); | |
else if (bt == CHAR) stack.Push((int)a << (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a << (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a << (byte)b); | |
else if (bt == INT16) stack.Push((uint)a << (short)b); | |
else if (bt == UINT16) stack.Push((uint)a << (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a << (int)b); | |
else if (bt == CHAR) stack.Push((uint)a << (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a << (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a << (byte)b); | |
else if (bt == INT16) stack.Push((long)a << (short)b); | |
else if (bt == UINT16) stack.Push((long)a << (ushort)b); | |
else if (bt == INT32) stack.Push((long)a << (int)b); | |
else if (bt == CHAR) stack.Push((long)a << (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == INT8) stack.Push((ulong)a << (sbyte)b); | |
else if (bt == UINT8) stack.Push((ulong)a << (byte)b); | |
else if (bt == INT16) stack.Push((ulong)a << (short)b); | |
else if (bt == UINT16) stack.Push((ulong)a << (ushort)b); | |
else if (bt == INT32) stack.Push((ulong)a << (int)b); | |
else if (bt == CHAR) stack.Push((ulong)a << (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a << (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a << (byte)b); | |
else if (bt == INT16) stack.Push((char)a << (short)b); | |
else if (bt == UINT16) stack.Push((char)a << (ushort)b); | |
else if (bt == INT32) stack.Push((char)a << (int)b); | |
else if (bt == CHAR) stack.Push((char)a << (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
{ | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_LeftShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
public static void Shr(Stack<object> stack) | |
{ | |
if (stack.Count >= 2) | |
{ | |
object b = stack.Pop(); | |
object a = stack.Pop(); | |
Type at = a.GetType(); | |
Type bt = b.GetType(); | |
MethodInfo tmp = null; | |
if (at == INT8) | |
if (bt == INT8) stack.Push((sbyte)a >> (sbyte)b); | |
else if (bt == UINT8) stack.Push((sbyte)a >> (byte)b); | |
else if (bt == INT16) stack.Push((sbyte)a >> (short)b); | |
else if (bt == UINT16) stack.Push((sbyte)a >> (ushort)b); | |
else if (bt == INT32) stack.Push((sbyte)a >> (int)b); | |
else if (bt == CHAR) stack.Push((sbyte)a >> (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT8) | |
if (bt == INT8) stack.Push((byte)a >> (sbyte)b); | |
else if (bt == UINT8) stack.Push((byte)a >> (byte)b); | |
else if (bt == INT16) stack.Push((byte)a >> (short)b); | |
else if (bt == UINT16) stack.Push((byte)a >> (ushort)b); | |
else if (bt == INT32) stack.Push((byte)a >> (int)b); | |
else if (bt == CHAR) stack.Push((sbyte)a >> (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT16) | |
if (bt == INT8) stack.Push((short)a >> (sbyte)b); | |
else if (bt == UINT8) stack.Push((short)a >> (byte)b); | |
else if (bt == INT16) stack.Push((short)a >> (short)b); | |
else if (bt == UINT16) stack.Push((short)a >> (ushort)b); | |
else if (bt == INT32) stack.Push((short)a >> (int)b); | |
else if (bt == CHAR) stack.Push((short)a >> (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT16) | |
if (bt == INT8) stack.Push((ushort)a >> (sbyte)b); | |
else if (bt == UINT8) stack.Push((ushort)a >> (byte)b); | |
else if (bt == INT16) stack.Push((ushort)a >> (short)b); | |
else if (bt == UINT16) stack.Push((ushort)a >> (ushort)b); | |
else if (bt == INT32) stack.Push((ushort)a >> (int)b); | |
else if (bt == CHAR) stack.Push((ushort)a >> (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT32) | |
if (bt == INT8) stack.Push((int)a >> (sbyte)b); | |
else if (bt == UINT8) stack.Push((int)a >> (byte)b); | |
else if (bt == INT16) stack.Push((int)a >> (short)b); | |
else if (bt == UINT16) stack.Push((int)a >> (ushort)b); | |
else if (bt == INT32) stack.Push((int)a >> (int)b); | |
else if (bt == CHAR) stack.Push((int)a >> (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT32) | |
if (bt == INT8) stack.Push((uint)a >> (sbyte)b); | |
else if (bt == UINT8) stack.Push((uint)a >> (byte)b); | |
else if (bt == INT16) stack.Push((uint)a >> (short)b); | |
else if (bt == UINT16) stack.Push((uint)a >> (ushort)b); | |
else if (bt == INT32) stack.Push((uint)a >> (int)b); | |
else if (bt == CHAR) stack.Push((uint)a >> (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == INT64) | |
if (bt == INT8) stack.Push((long)a >> (sbyte)b); | |
else if (bt == UINT8) stack.Push((long)a >> (byte)b); | |
else if (bt == INT16) stack.Push((long)a >> (short)b); | |
else if (bt == UINT16) stack.Push((long)a >> (ushort)b); | |
else if (bt == INT32) stack.Push((long)a >> (int)b); | |
else if (bt == CHAR) stack.Push((long)a >> (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == UINT64) | |
if (bt == INT8) stack.Push((ulong)a >> (sbyte)b); | |
else if (bt == UINT8) stack.Push((ulong)a >> (byte)b); | |
else if (bt == INT16) stack.Push((ulong)a >> (short)b); | |
else if (bt == UINT16) stack.Push((ulong)a >> (ushort)b); | |
else if (bt == INT32) stack.Push((ulong)a >> (int)b); | |
else if (bt == CHAR) stack.Push((ulong)a >> (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == SINGLE) | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DOUBLE) | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == DECIMAL) | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == CHAR) | |
if (bt == INT8) stack.Push((char)a >> (sbyte)b); | |
else if (bt == UINT8) stack.Push((char)a >> (byte)b); | |
else if (bt == INT16) stack.Push((char)a >> (short)b); | |
else if (bt == UINT16) stack.Push((char)a >> (ushort)b); | |
else if (bt == INT32) stack.Push((char)a >> (int)b); | |
else if (bt == CHAR) stack.Push((char)a >> (char)b); | |
else | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == BOOLEAN) | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else if (at == STRING) | |
{ | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
tmp.Invoke(null, new object[] { a, b }); | |
else | |
throw new Exception("Error"); | |
} | |
else | |
{ | |
tmp = a.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp == null) | |
tmp = b.GetType().GetMethod("op_RightShift", new Type[] { at, bt }); | |
if (tmp != null && tmp.ReturnType != typeof(void)) | |
stack.Push(tmp.Invoke(null, new object[] { a, b })); | |
else | |
throw new Exception("Error"); | |
} | |
} | |
else | |
throw new Exception("Not enough objects on the stack."); | |
} | |
#endregion | |
public static void DoOperation(Stack<object> stack, Operator op) | |
{ | |
switch (op) | |
{ | |
case Operator.Add: | |
Add(stack); | |
break; | |
case Operator.Sub: | |
Sub(stack); | |
break; | |
case Operator.Mul: | |
Mul(stack); | |
break; | |
case Operator.Div: | |
Div(stack); | |
break; | |
case Operator.Rem: | |
Rem(stack); | |
break; | |
case Operator.Equal: | |
Equal(stack); | |
break; | |
case Operator.Unequal: | |
Inequal(stack); | |
break; | |
case Operator.XOR: | |
XOR(stack); | |
break; | |
case Operator.NOT: | |
Not(stack); | |
break; | |
case Operator.Lt: | |
Lt(stack); | |
break; | |
case Operator.Gt: | |
Gt(stack); | |
break; | |
case Operator.Lte: | |
Lte(stack); | |
break; | |
case Operator.Gte: | |
Gte(stack); | |
break; | |
case Operator.Shl: | |
Shl(stack); | |
break; | |
case Operator.Shr: | |
Shr(stack); | |
break; | |
case Operator.BitAND: | |
AND(stack); | |
break; | |
case Operator.BitOR: | |
OR(stack); | |
break; | |
case Operator.BitNot: | |
Complement(stack); | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Diagnostics; | |
using XScript.Evaluators; | |
using XScript.CodeGen; | |
namespace XScript.Helpers | |
{ | |
public sealed class TokenHelper | |
{ | |
#region Token Reading | |
internal delegate bool Check(); | |
public static Queue<Stmt> ReadStatements(string source, BIO bio) | |
{ | |
Queue<Token> tokens = ReadCompressedTokens(source, bio); | |
return StatementHelper.Convert(tokens); | |
} | |
public static Queue<Token> ReadCompressedTokens(string source,BIO bio) | |
{ | |
Queue<Token> tokens = ReadTokens(source); | |
Queue<Token> finalTokens = Compress(tokens, bio); | |
return finalTokens; | |
} | |
public static Queue<Token> ReadTokens(string source) | |
{ | |
int p = 0; | |
int i = 0; | |
Queue<Token> tokens = new Queue<Token>(); | |
Check lt = new Check(() => { return p < source.Length; }); | |
Func<char> Peek = new Func<char>(() => { return lt() ? source[p + 1] : '\0'; }); | |
Action N = new Action(() => { p++; }); | |
Func<char> Read = new Func<char>(() => { return source[p++]; }); | |
Func<char> Current = new Func<char>(() => { return source[p]; }); | |
if (!string.IsNullOrEmpty(source)) | |
{ | |
char c; | |
string s = string.Empty; | |
while (lt()) | |
{ | |
c = Current(); | |
if (char.IsWhiteSpace(c)) | |
{ | |
p++; | |
} | |
else if (c == '\'') | |
{ | |
i = p; | |
ScriptHelper.ParseSingleQuote(source, ref p, out s); | |
if (s.Length > 0) | |
tokens.Enqueue(new CharacterToken(s, p)); | |
} | |
else if (c == '"') | |
{ | |
i = p; | |
ScriptHelper.ParseDoubleQuote(source, ref p, out s); | |
if (s.Length > 0) | |
tokens.Enqueue(new StringToken(s, i)); | |
} | |
else if (char.IsLetter(c) || c == '_') | |
{ | |
i = p; | |
ScriptHelper.ParseName(source, ref p, out s); | |
if (s.Length > 0) | |
{ | |
if (ScriptHelper.IsKeyword(s)) | |
tokens.Enqueue(new KeywordToken(s, i)); | |
else if (ScriptHelper.IsModifier(s)) | |
tokens.Enqueue(ModifierToken.Get(s, i)); | |
else | |
tokens.Enqueue(new NameToken(s, i)); | |
} | |
} | |
else if (c == '#') | |
{ | |
i = p; | |
p++; | |
ScriptHelper.ParseName(source, ref p, out s); | |
s = "#" + s; | |
if (s.Length > 0) | |
tokens.Enqueue(new CompilerDirective(s, i)); | |
} | |
else if (c == '/' && p < source.Length - 1 && (Peek() == '/' || Peek() == '*')) | |
{ | |
ScriptHelper.ParseComment(source, ref p, out s); | |
} | |
else if (c == '<' || c == '>') | |
{ | |
tokens.Enqueue(new LtGtToken(c.ToString(), p)); | |
p++; | |
} | |
else if (ScriptHelper.IsOperatorChar(c)) | |
{ | |
i = p; | |
ScriptHelper.ParseOperator(source, ref p, out s); | |
if (s.Length > 0) | |
tokens.Enqueue(OperatorToken.Get(s, i)); | |
} | |
else if (char.IsNumber(c)) | |
{ | |
i = p; | |
ScriptHelper.ParseDecimal(source, ref p, out s); | |
if (s.Length > 0) | |
tokens.Enqueue(NumberToken.Get(s, i)); | |
} | |
else if (ScriptHelper.IsBracket(c)) | |
{ | |
tokens.Enqueue(new BracketToken(c, p)); | |
p++; | |
} | |
else if (c == '.' || c == ',') | |
{ | |
tokens.Enqueue(new SeparatorToken(c, p)); | |
p++; | |
} | |
else if (c == ';') | |
{ | |
tokens.Enqueue(new SemiColonToken(p)); | |
p++; | |
} | |
else | |
throw new SourceCodeException(p, 1, "Invalid token \"" + c + "\" at index:" + p.ToString()); | |
} | |
} | |
return tokens; | |
} | |
public static Queue<string> ConvertToStringTokens(IEnumerable<Token> collection) | |
{ | |
return new Queue<string>(from t in collection select t.Value); | |
} | |
#endregion | |
#region Compression | |
public static Queue<Token> FinalizeOperators(IEnumerable<Token> tokenData, BIO bio) | |
{ | |
Queue<Token> tokens = new Queue<Token>(tokenData); | |
Queue<Token> result = new Queue<Token>(); | |
Token t; | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is LtGtToken) | |
{ | |
string op = string.Empty; | |
int ind = t.Index; | |
if (t.Value == "<" || t.Value == ">") | |
{ | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is LtGtToken || t is OperatorToken) | |
{ | |
op += t.Value; | |
tokens.Dequeue(); | |
} | |
else | |
break; | |
} | |
if (ScriptHelper.IsOperator(op)) | |
{ | |
result.Enqueue(OperatorToken.Get(op, ind)); | |
} | |
} | |
else | |
throw t.Error; | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
return result; | |
} | |
public static Queue<Token> Compress(IEnumerable<Token> tokenData, BIO bio) | |
{ | |
//CompressTypes(...) parses types from the tokens. | |
Queue<Token> compressed = CompressTypes(tokenData, bio); | |
//Turns the LtGtToken into the BooleanOperator token | |
compressed = FinalizeOperators(compressed, bio); | |
//Turns "(" "true" "||" "false" ")" into "true || false" | |
compressed = CompressGroups(compressed, bio); | |
//Turns "WriteLine" "(" "0" ")" into "WriteLine(0)" | |
compressed = CompressCalls(compressed, bio); | |
//Turns things like "System.String" "." "Empty" into "System.String.Empty" | |
compressed = CompressPaths(compressed, bio); | |
//Checks definitions and #if #elif #else and #endif compiler directives | |
return FinalizeCompilerDirectives(compressed, bio); | |
} | |
private static Queue<Token> CompressGroups(IEnumerable<Token> tokenData, BIO bio) | |
{ | |
Queue<Token> tokens = new Queue<Token>(tokenData); | |
Queue<Token> result = new Queue<Token>(); | |
Token t; | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is BracketToken && t.Value == "(") | |
{ | |
tokens.Dequeue(); | |
result.Enqueue(ReadTokenGroup(tokens)); | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
return result; | |
} | |
private static TokenGroup ReadTokenGroup(Queue<Token> tokens) | |
{ | |
Queue<Token> result = new Queue<Token>(); | |
Token t; | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is BracketToken && t.Value == ")") | |
{ | |
tokens.Dequeue(); | |
return new TokenGroup(result, -1); | |
} | |
else if (t is BracketToken && t.Value == "(") | |
{ | |
tokens.Dequeue(); | |
result.Enqueue(ReadTokenGroup(tokens)); | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
throw new SourceCodeException(-1, 0, "Code ended unexpectedly"); | |
} | |
private static Queue<Token> FinalizeCompilerDirectives(IEnumerable<Token> tokenData, BIO bio) | |
{ | |
Queue<Token> tokens = new Queue<Token>(tokenData); | |
Queue<Token> result = new Queue<Token>(); | |
Token t; | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is CompilerDirective) | |
{ | |
if (t.Value == "#print" || t.Value == "#trace") | |
{ | |
CompilerPrint(tokens); | |
} | |
else if (t.Value == "#if") | |
{ | |
CompilerIf(tokens, bio, result); | |
} | |
else if (t.Value == "#define") | |
{ | |
tokens.Dequeue(); | |
if (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is NameToken) | |
{ | |
tokens.Dequeue(); | |
bio.AddDefinition(t.Value); | |
} | |
else if (t is PathToken) | |
{ | |
tokens.Dequeue(); | |
string str = string.Empty; | |
Queue<Token> pt = new Queue<Token>((t as PathToken).Tokens); | |
while (pt.Count > 0) | |
{ | |
if (pt.Peek() is NameToken) | |
{ | |
str += pt.Dequeue().Value; | |
if (pt.Count > 0) | |
str += "."; | |
} | |
else throw pt.Peek().Error; | |
} | |
if (str.Length > 0) | |
{ | |
bio.AddDefinition(str); | |
} | |
else | |
throw t.Error; | |
} | |
else | |
throw t.Error; | |
} | |
else throw new SourceCodeException(-1, 0, "Code ended unexpectedly"); | |
} | |
else if (t.Value == "#undef") | |
{ | |
tokens.Dequeue(); | |
if (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is NameToken) | |
{ | |
tokens.Dequeue(); | |
bio.RemoveDefinition(t.Value); | |
} | |
else if (t is PathToken) | |
{ | |
tokens.Dequeue(); | |
string str = string.Empty; | |
Queue<Token> pt = new Queue<Token>((t as PathToken).Tokens); | |
while (pt.Count > 0) | |
{ | |
if (pt.Peek() is NameToken) | |
{ | |
str += pt.Dequeue().Value; | |
if (pt.Count > 0) | |
str += "."; | |
} | |
else throw pt.Peek().Error; | |
} | |
if (str.Length > 0) | |
{ | |
bio.RemoveDefinition(str); | |
} | |
else | |
throw t.Error; | |
} | |
else | |
throw t.Error; | |
} | |
else throw new SourceCodeException(-1, 0, "Code ended unexpectedly"); | |
} | |
else | |
throw t.Error; | |
} | |
else if (t is NewLineToken) | |
{ | |
tokens.Dequeue(); | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
return result; | |
} | |
public static Queue<Token> CompressPaths(IEnumerable<Token> tokenData, BIO bio) | |
{ | |
Queue<Token> tokens = new Queue<Token>(tokenData); | |
Queue<Token> result = new Queue<Token>(); | |
Token t; | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is NameToken || t is CallToken || t is ctorToken || t is StringToken || t is CharacterToken || t is TypeToken) | |
{ | |
int ind = t.Index; | |
Queue<Token> path = new Queue<Token>(); | |
path.Enqueue(tokens.Dequeue()); | |
bool sep = false; | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is SeparatorToken && t.Value == ".") | |
{ | |
tokens.Dequeue(); | |
sep = true; | |
} | |
else if ((t is NameToken || t is CallToken) && sep) | |
{ | |
path.Enqueue(tokens.Dequeue()); | |
sep = false; | |
} | |
else | |
break; | |
} | |
if (path.Count > 1) | |
result.Enqueue(new PathToken(path, ind)); | |
else | |
result.Enqueue(path.Dequeue()); | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
return result; | |
} | |
public static Queue<Token> CompressCalls(IEnumerable<Token> tokenData, BIO bio) | |
{ | |
Queue<Token> tokens = new Queue<Token>(tokenData); | |
Queue<Token> result = new Queue<Token>(); | |
Token t; | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is NameToken) | |
{ | |
tokens.Dequeue(); | |
if (tokens.Count > 0 && tokens.Peek() is TokenGroup) | |
{ | |
result.Enqueue(new CallToken(t.Value, Compress((tokens.Peek() as TokenGroup).Tokens, bio), t.Index)); | |
tokens.Dequeue(); | |
} | |
else | |
result.Enqueue(t); | |
} | |
else if (t is TypeToken) | |
{ | |
tokens.Dequeue(); | |
if (tokens.Count > 0 && tokens.Peek() is TokenGroup) | |
{ | |
result.Enqueue(new ctorToken((t as TypeToken).Type, Compress((tokens.Peek() as TokenGroup).Tokens, bio), t.Index)); | |
tokens.Dequeue(); | |
} | |
else | |
result.Enqueue(t); | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
return result; | |
} | |
public static Queue<Token> CompressTypes(IEnumerable<Token> tokenData, BIO bio) | |
{ | |
Queue<Token> tokens = new Queue<Token>(tokenData); | |
Queue<Token> result = new Queue<Token>(); | |
Token t; | |
bool wasDec = false; | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is NameToken && !wasDec) | |
{ | |
int i; | |
Type type; | |
if (TypeHelper.TryGetType(tokens, bio, out i, out type)) | |
{ | |
while (i > 0 && tokens.Count > 0) | |
{ | |
tokens.Dequeue(); | |
i--; | |
} | |
result.Enqueue(new TypeToken(type, t.Index)); | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
else if (t is CompilerDirective) | |
{ | |
if (t.Value == "#use") | |
{ | |
InsertUsing(tokens, bio); | |
} | |
else if (t.Value == "#unuse") | |
{ | |
RemoveUsing(tokens, bio); | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
wasDec = t.Value == "."; | |
} | |
return result; | |
} | |
#endregion | |
#region Extras | |
public static Queue<Token> ReadIndexerBody(Queue<Token> tokens) | |
{ | |
Queue<Token> result = new Queue<Token>(); | |
Token t = null; | |
if (tokens.Count > 0) | |
{ | |
if (tokens.Peek() is BracketToken && tokens.Peek().Value == "[") | |
result.Enqueue(tokens.Dequeue()); | |
else | |
throw tokens.Peek().Error; | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is BracketToken) | |
{ | |
if (t.Value == "[") | |
{ | |
Queue<Token> pBody = ReadIndexerBody(tokens); | |
while (pBody.Count > 0) | |
{ | |
result.Enqueue(pBody.Dequeue()); | |
} | |
} | |
else if (t.Value == "]") | |
{ | |
result.Enqueue(tokens.Dequeue()); | |
return result; | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
} | |
else | |
throw new Exception("Empty"); | |
throw new SourceCodeException(t != null ? t.Index : -1, 0, "Code ended unexpectedly"); | |
} | |
public static Queue<Token> ReadExecutionBody(Queue<Token> tokens) | |
{ | |
Queue<Token> result = new Queue<Token>(); | |
Token t = null; | |
if (tokens.Count > 0) | |
{ | |
if (tokens.Peek() is BracketToken && tokens.Peek().Value == "{") | |
result.Enqueue(tokens.Dequeue()); | |
else | |
throw tokens.Peek().Error; | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is BracketToken) | |
{ | |
if (t.Value == "{") | |
{ | |
Queue<Token> pBody = ReadExecutionBody(tokens); | |
while (pBody.Count > 0) | |
{ | |
result.Enqueue(pBody.Dequeue()); | |
} | |
} | |
else if (t.Value == "}") | |
{ | |
result.Enqueue(tokens.Dequeue()); | |
return result; | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
} | |
else | |
throw new Exception("Empty"); | |
throw new SourceCodeException(t != null ? t.Index : -1, 0, "Code ended unexpectedly"); | |
} | |
public static void ReadParameterBody(Queue<Token> tokens, Queue<Token> result) | |
{ | |
Token t = null; | |
if (tokens.Count > 0) | |
{ | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is BracketToken) | |
{ | |
if (t.Value == "(") | |
{ | |
tokens.Dequeue(); | |
ReadParameterBody(tokens, result); | |
} | |
else if (t.Value == ")") | |
{ | |
tokens.Dequeue(); | |
return; | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
else | |
result.Enqueue(tokens.Dequeue()); | |
} | |
} | |
else | |
throw new Exception("Empty"); | |
throw new SourceCodeException(t != null ? t.Index : -1, 0, "Code ended unexpectedly"); | |
} | |
public static Queue<Token> ReadParameterBody(Queue<Token> tokens) | |
{ | |
Queue<Token> result = new Queue<Token>(); | |
ReadParameterBody(tokens, result); | |
return result; | |
} | |
public static Queue<Token> ReadToSemicolon(Queue<Token> tokens) | |
{ | |
Queue<Token> result = new Queue<Token>(); | |
while (tokens.Count > 0) | |
{ | |
if (tokens.Peek() is SemiColonToken) | |
{ | |
tokens.Dequeue(); | |
return result; | |
} | |
else | |
{ | |
result.Enqueue(tokens.Dequeue()); | |
} | |
} | |
return result; | |
} | |
private static void CompilerPrint(Queue<Token> tokens) | |
{ | |
Token t = tokens.Peek(); | |
if (t is CompilerDirective) | |
{ | |
if (t.Value == "#print") | |
{ | |
tokens.Dequeue(); | |
Queue<Token> tks = ReadToSemicolon(tokens); | |
if (GroupHelper.IsStringConcat(tks)) | |
{ | |
Console.WriteLine(GroupHelper.ConcatString(tks)); | |
} | |
else if (GroupHelper.IsArithmetic(tks)) | |
{ | |
Console.WriteLine(Eval.Double(tks)); | |
} | |
else if (GroupHelper.IsBooleanCheck(tks)) | |
{ | |
Console.WriteLine(Eval.Boolean(tks)); | |
} | |
else | |
Console.WriteLine("Incorrect print format"); | |
} | |
else if (t.Value == "#trace") | |
{ | |
tokens.Dequeue(); | |
Queue<Token> tks = ReadToSemicolon(tokens); | |
if (GroupHelper.IsStringConcat(tks)) | |
{ | |
Trace.WriteLine(GroupHelper.ConcatString(tks)); | |
} | |
else if (GroupHelper.IsArithmetic(tks)) | |
{ | |
Trace.WriteLine(Eval.Double(tks)); | |
} | |
else if (GroupHelper.IsBooleanCheck(tks)) | |
{ | |
Trace.WriteLine(Eval.Boolean(tks)); | |
} | |
else | |
Trace.WriteLine("Incorrect print format"); | |
} | |
else | |
throw t.Error; | |
} | |
else | |
throw t.Error; | |
} | |
private static void CompilerIf(Queue<Token> tokens, BIO bio, Queue<Token> result) | |
{ | |
Token t = tokens.Peek(); | |
if (t is CompilerDirective) | |
{ | |
Stack<bool> eval = new Stack<bool>(); | |
if (t.Value == "#if" || t.Value == "#elif") | |
{ | |
tokens.Dequeue(); | |
Queue<Token> statement = ReadToSemicolon(tokens); | |
statement = GroupHelper.InfixToPostfix(statement); | |
while (statement.Count > 0) | |
{ | |
t = statement.Peek(); | |
if (t is NameToken) | |
{ | |
eval.Push(bio.ContainsDefinition(t.Value)); | |
} | |
else if (t is PathToken) | |
{ | |
string str = string.Empty; | |
Queue<Token> pt = new Queue<Token>((t as PathToken).Tokens); | |
while (pt.Count > 0) | |
{ | |
if (pt.Peek() is NameToken) | |
{ | |
str += pt.Dequeue().Value; | |
if (pt.Count > 0) | |
str += "."; | |
} | |
else throw pt.Peek().Error; | |
} | |
if (str.Length > 0) | |
{ | |
eval.Push(bio.ContainsDefinition(str)); | |
} | |
else | |
throw t.Error; | |
} | |
else if (t is BooleanOperatorToken && eval.Count > 0) | |
{ | |
if (t.Value == "!") | |
{ | |
eval.Push(!eval.Pop()); | |
} | |
else if (t.Value == "||" && eval.Count > 1) | |
{ | |
bool a = eval.Pop(); | |
bool b = eval.Pop(); | |
eval.Push(a || b); | |
} | |
else if (t.Value == "&&" && eval.Count > 1) | |
{ | |
bool a = eval.Pop(); | |
bool b = eval.Pop(); | |
eval.Push(a && b); | |
} | |
else | |
throw t.Error; | |
} | |
else | |
throw t.Error; | |
statement.Dequeue(); | |
} | |
} | |
if (eval.Count == 1) | |
{ | |
ReadToENDIF(tokens, bio, result, eval.Pop()); | |
} | |
else | |
throw new Exception("Invalid #if compiler directive"); | |
} | |
else | |
throw t.Error; | |
} | |
private static void ReadToENDIF(Queue<Token> tokens,BIO bio, Queue<Token> result,bool wasTrue) | |
{ | |
Token t; | |
if (!wasTrue) | |
{ | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t.Value == "#endif") | |
{ | |
tokens.Dequeue(); | |
return; | |
} | |
else if (t.Value == "#if") | |
{ | |
tokens.Dequeue(); | |
ReadToENDIF(tokens,bio, result, false); | |
} | |
else if (t.Value == "#elif") | |
{ | |
CompilerIf(tokens, bio, result); | |
} | |
else if (t.Value == "#else") | |
{ | |
tokens.Dequeue(); | |
ReadToENDIF(tokens, bio, result, true); | |
} | |
else | |
{ | |
tokens.Dequeue(); | |
} | |
} | |
} | |
else | |
{ | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t.Value == "#endif") | |
{ | |
tokens.Dequeue(); | |
return; | |
} | |
else if (t.Value == "#if") | |
{ | |
tokens.Dequeue(); | |
CompilerIf(tokens, bio, result); | |
} | |
else if (t.Value == "#else") | |
{ | |
tokens.Dequeue(); | |
ReadToENDIF(tokens, bio, result, false); | |
} | |
else if (t.Value == "#elif") | |
{ | |
tokens.Dequeue(); | |
ReadToENDIF(tokens, bio, result, false); | |
} | |
else if (!(t is NewLineToken)) | |
result.Enqueue(tokens.Dequeue()); | |
else | |
tokens.Dequeue(); | |
} | |
} | |
} | |
#endregion | |
#region Usings | |
public static void InsertUsing(Queue<Token> tokens, BIO bio) | |
{ | |
Token t = tokens.Peek(); | |
string key = string.Empty; | |
if (t is CompilerDirective && t.Value == "#use") | |
{ | |
tokens.Dequeue(); | |
string sb = string.Empty; | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is NameToken) | |
{ | |
sb += t.Value; | |
tokens.Dequeue(); | |
} | |
else if (t is SeparatorToken) | |
{ | |
if (t.Value == ".") | |
{ | |
sb += '.'; | |
tokens.Dequeue(); | |
} | |
else | |
throw t.Error; | |
} | |
else if (t is OperatorToken) | |
{ | |
if (t.Value == "=") | |
{ | |
key = sb; | |
sb = string.Empty; | |
tokens.Dequeue(); | |
} | |
else | |
throw t.Error; | |
} | |
else if (t is SemiColonToken) | |
{ | |
tokens.Dequeue(); | |
break; | |
} | |
else | |
throw t.Error; | |
} | |
if (key.Length > 0) | |
{ | |
bio.AddUsing(key, sb); | |
} | |
else | |
{ | |
bio.AddUsing(sb); | |
} | |
} | |
} | |
public static void InsertUsing(Queue<string> tokens, BIO bio) | |
{ | |
string s = tokens.Peek(); | |
string key = string.Empty; | |
bool def = false; | |
if (s == "#use") | |
{ | |
tokens.Dequeue(); | |
StringBuilder sb = new StringBuilder(); | |
while (tokens.Count > 0) | |
{ | |
s = tokens.Peek(); | |
if (s == "%DEFAULT%") | |
{ | |
tokens.Dequeue(); | |
def = true; | |
bio.AddBasicKeywords(); | |
} | |
else if (s == ";") | |
{ | |
tokens.Dequeue(); | |
break; | |
} | |
else if (s == "=" && !def) | |
{ | |
tokens.Dequeue(); | |
key = sb.ToString(); | |
sb = sb.Remove(0, sb.Length); | |
} | |
else | |
{ | |
sb.Append(tokens.Dequeue()); | |
} | |
} | |
if (!def) | |
{ | |
s = sb.ToString(); | |
if (!string.IsNullOrEmpty(key)) | |
{ | |
bio.AddUsing(key, s); | |
} | |
else | |
bio.AddUsing(s); | |
} | |
} | |
} | |
public static void RemoveUsing(Queue<Token> tokens, BIO bio) | |
{ | |
Token t = tokens.Peek(); | |
string key = string.Empty; | |
if (t is CompilerDirective && t.Value == "#unuse") | |
{ | |
tokens.Dequeue(); | |
string sb = string.Empty; | |
while (tokens.Count > 0) | |
{ | |
t = tokens.Peek(); | |
if (t is NameToken) | |
{ | |
sb += t.Value; | |
tokens.Dequeue(); | |
} | |
else if (t is SeparatorToken) | |
{ | |
if (t.Value == ".") | |
{ | |
sb += '.'; | |
tokens.Dequeue(); | |
} | |
else | |
throw t.Error; | |
} | |
else if (t is OperatorToken) | |
{ | |
if (t.Value == "=") | |
{ | |
key = sb; | |
sb = string.Empty; | |
tokens.Dequeue(); | |
} | |
else | |
throw t.Error; | |
} | |
else if (t is SemiColonToken) | |
{ | |
tokens.Dequeue(); | |
break; | |
} | |
else | |
throw t.Error; | |
} | |
if (key.Length > 0) | |
{ | |
bio.RemoveUsing(key, sb); | |
} | |
else | |
{ | |
bio.RemoveUsing(sb); | |
} | |
} | |
} | |
public static void RemoveUsing(Queue<string> tokens, BIO bio) | |
{ | |
string s = tokens.Peek(); | |
string key = string.Empty; | |
bool def = false; | |
if (s == "#unuse") | |
{ | |
tokens.Dequeue(); | |
StringBuilder sb = new StringBuilder(); | |
while (tokens.Count > 0) | |
{ | |
s = tokens.Peek(); | |
if (s == ";") | |
{ | |
tokens.Dequeue(); | |
break; | |
} | |
else if (s == "%DEFAULT%") | |
{ | |
tokens.Dequeue(); | |
bio.RemoveBasicKeywords(); | |
def = true; | |
} | |
else if (s == "=") | |
{ | |
tokens.Dequeue(); | |
key = sb.ToString(); | |
sb = sb.Remove(0, sb.Length); | |
} | |
else | |
{ | |
sb.Append(tokens.Dequeue()); | |
} | |
} | |
if (!def) | |
{ | |
s = sb.ToString(); | |
if (!string.IsNullOrEmpty(key)) | |
{ | |
bio.RemoveUsing(key, s); | |
} | |
else | |
bio.RemoveUsing(s); | |
} | |
} | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nope, I don't bother refactoring, I like to start fresh.