Click here to Skip to main content
15,884,298 members
Articles / High Performance Computing / Vectorization

Bird Programming Language: Part 1

Rate me:
Please Sign up or sign in to vote.
4.92/5 (129 votes)
1 Jan 2013GPL312 min read 375.4K   2.7K   153  
A new general purpose language that aims to be fast, high level and simple to use.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Anonymus
{
	public enum ConstDataType
	{
		Signed,
		Unsigned,
		Double,
		String,
	}

	public unsafe class ConstData
	{
		public const int BuffSize = 8;

		public ConstDataType Type;
		public byte[] Bytes;
		public string String;

		public ConstData(long Data)
		{
			Bytes = new byte[BuffSize + 8];
			SignedData = Data;
			Type = ConstDataType.Signed;
		}

		public ConstData(ulong Data)
		{
			Bytes = new byte[BuffSize + 8];
			UnsignedData = Data;
			Type = ConstDataType.Unsigned;
		}

		public ConstData(double Data)
		{
			Bytes = new byte[BuffSize + 8];
			DoubleData = Data;
			Type = ConstDataType.Double;
		}

		public ConstData(string String)
		{
			this.String = String;
			this.Type = ConstDataType.String;
		}

		public byte* GetPtr(int Offset, int Size)
		{
			if (Offset + Size > BuffSize)
				throw new Exception("ERROR");

			fixed (byte* pBytes = Bytes)
				return pBytes + Offset;
		}

		public ulong GetUnsigned(int Offset, int Size)
		{
			var Ptr = GetPtr(Offset, Size);
			if (Size == 1) return (byte)(*(long*)Ptr);
			else if (Size == 2) return (ushort)(*(long*)Ptr);
			else if (Size == 4) return (uint)(*(long*)Ptr);
			else if (Size == 8) return (*(ulong*)Ptr);
			else throw new Exception("ERROR");
		}

		public long GetSigned(int Offset, int Size)
		{
			var Ptr = GetPtr(Offset, Size);
			if (Size == 1) return (sbyte)(*(long*)Ptr);
			else if (Size == 2) return(short)(*(long*)Ptr);
			else if (Size == 4) return (int)(*(long*)Ptr);
			else if (Size == 8) return (*(long*)Ptr);
			else throw new Exception("ERROR");
		}

		public ulong UnsignedData
		{
			get { return *(ulong*)GetPtr(0, sizeof(ulong)); }
			set { *(ulong*)GetPtr(0, sizeof(ulong)) = value; }
		}

		public string GetDefString(int Offset = 0, int Size = 8)
		{
			if (Type == ConstDataType.Signed)
				return GetSigned(Offset, Size).ToString();
			else return GetUnsigned(Offset, Size).ToString();
		}

		public long SignedData
		{
			get { return *(long*)GetPtr(0, sizeof(long)); }
			set { *(long*)GetPtr(0, sizeof(long)) = value; }
		}

		public double DoubleData
		{
			get { return * (double*)GetPtr(0, sizeof(double)); }
			set { *(double*)GetPtr(0, sizeof(double)) = value; }
		}

		public double CDoubleData
		{
			get
			{
				if (Type == ConstDataType.Signed) return (double)SignedData;
				else if (Type == ConstDataType.Unsigned) return (double)UnsignedData;
				else if (Type == ConstDataType.String) return Convert.ToInt64(String);
				else return *(double*)GetPtr(0, sizeof(double));
			}

			set
			{
				if (Type == ConstDataType.Signed) SignedData = (long)value;
				else if (Type == ConstDataType.Unsigned) UnsignedData = (ulong)value;
				else if (Type == ConstDataType.String) String = value.ToString();
				else *(double*)GetPtr(0, sizeof(double)) = value;
			}
		}

		public override string ToString()
		{
			if (Type == ConstDataType.Unsigned) return UnsignedData.ToString();
			else if (Type == ConstDataType.Signed) return SignedData.ToString();
			else if (Type == ConstDataType.Double) return DoubleData.ToString();
			else if (Type == ConstDataType.String) return String;
			else throw new Exception("ERROR");
		}

		public bool IsEqual(ConstData Data)
		{
			if (Type != Data.Type) return false;

			if (Type == ConstDataType.String)
			{
				return Data.String == String;
			}
			else
			{
				if (Data.Bytes.Length != Bytes.Length)
					throw new Exception("ERROR");

				for (var i = 0; i < Bytes.Length; i++)
					if (Data.Bytes[i] != Bytes[i]) return false;

				return true;
			}
		}
	}

	public class ConstExpressionNode : ExpressionNode
	{
		public ConstData Value;
		public ulong Unsigned { get { return Value.UnsignedData; } }
		public long Signed { get { return Value.SignedData; } }
		public double Double { get { return Value.DoubleData; } }
		public double CDouble { get { return Value.CDoubleData; } }
		public string String { get { return Value.String; } }

		public override ConditionRes ConditionResult
		{ get { return Bool ? ConditionRes.True : ConditionRes.False; } }

		public bool Bool
		{
			get
			{
				if (Type is BoolType) return Unsigned != (Type as BoolType).FalseVal;
				else throw new Exception("Not boolean type");
			}
		}

		public ConstExpressionNode(Type Type, ConstData Value, PString Code)
			: base(Code)
		{
			this.Type = Type;
			this.Value = Value;
		}

		public ConstExpressionNode(Type Type, ulong Value, PString Code)
			: base(Code)
		{
			this.Type = Type;
			this.Value = new ConstData(Value);
		}

		public ConstExpressionNode(Type Type, long Value, PString Code)
			: base(Code)
		{
			this.Type = Type;
			this.Value = new ConstData(Value);
		}

		public ConstExpressionNode(Type Type, double Value, PString Code)
			: base(Code)
		{
			this.Type = Type;
			this.Value = new ConstData(Value);
		}

		public ConstExpressionNode(Type Type, string Value, PString Code)
			: base(Code)
		{
			this.Type = Type;
			this.Value = new ConstData(Value);
		}

		public ConstExpressionNode(Type Type, bool Value, PString Code)
			: base(Code)
		{
			if (Type is BoolType)
			{
				var bType = Type as BoolType;
				this.Type = Type;
				this.Value = Value ? bType.TrueData : bType.FalseData;
			}
			else
			{
				throw new Exception("Not boolean type");
			}
		}

		public override ExpressionNode Copy(CompilerState State, PString Code, ReplaceNodeFunc Func)
		{
			if (Code == null) Code = this.Code;
			if (Value != null) return Func(new ConstExpressionNode(Type, Value, Code));
			else if (String != null) return Func(new ConstExpressionNode(Type, String, Code));
			else throw new Exception("Unknown constant type");
		}

		public override string ToString()
		{
			if (Type is SignedType) return Signed.ToString();
			else if (Type is UnsignedType) return Unsigned.ToString();
			else if (Type is FloatType) return Double.ToString();
			else if (Type is BoolType) return ((Type as BoolType).FalseVal != Unsigned).ToString();
			else if (Type is EnumType) return (Type as EnumType).GetValue(Unsigned).Name;
			else if (Type is ConstStringType) return String;
			else if (Type is AutomaticType) return Unsigned == 0 ? "null" : Unsigned.ToString();
			else if (Type is PointerType) return Unsigned.ToString();
			else throw new NotImplementedException();
		}

		public ConstExpressionNode ConvertTo(CompilerState State, Type To)
		{
#warning WARNING
			// pl -1 -> Unsinged, Enum

			ConstExpressionNode Ret;
			if (Type is EnumType) Ret = ConvertEnum(To);
			else if (Type is SignedType) Ret = ConvertSigned(To);
			else if (Type is UnsignedType) Ret = ConvertUnsigned(To);
			else if (Type is FloatType) Ret = ConvertFloat(To);
			else if (Type is BoolType) Ret = ConvertBool(To);
			else if (Type is ConstStringType) Ret = ConvertConstStr(State, To);
			else if (Type is AutomaticType) Ret = ConvertAuto(To);
			else return this;

			if (Ret == null)
			{
				State.Messages.Add(MessageId.CannotConvertConst,
					Code, ToString(), To.Name.String);
			}

			return Ret;
		}

		private ConstExpressionNode ConvertAuto(Type To)
		{
			return new ConstExpressionNode(To, Unsigned, Code);
		}

		private ConstExpressionNode ConvertConstStr(CompilerState State, Type To)
		{
			if (To is BoolType)
			{
				var BoolTo = To as BoolType;
				if (String == "true") return Expressions.GetBoolValue(BoolTo, true, Code);
				else if (String == "false") return Expressions.GetBoolValue(BoolTo, true, Code);
			}
			else if (String.Length > 0)
			{
				var Str = String;
				var Neg = Str[0] == '-';
				if (Neg) Str = Str.Substring(1);
				return Expressions.ConvStrToConst(State, null, Str, To, Negative: Neg);
			}

			return null;
		}

		private ConstExpressionNode ConvertBool(Type To)
		{
			if (To is BoolType) return new ConstExpressionNode(To, Bool, Code);
			else if (To is ConstStringType) return new ConstExpressionNode(To, Bool.ToString(), Code);

			return null;
		}

		private ConstExpressionNode ConvertFloat(Type To)
		{
			if (To is SignedType) return new ConstExpressionNode(To, (long)Double, Code);
			else if (To is UnsignedType) return new ConstExpressionNode(To, (ulong)Double, Code);
			else if (To is FloatType)
			{
				var FType = To as FloatType;
				if (FType.Size == 8) return new ConstExpressionNode(To, Double, Code);
				else if (FType.Size == 4) return new ConstExpressionNode(To, (float)Double, Code);
				else throw new NotImplementedException();
			}
			else if (To is ConstStringType) return new ConstExpressionNode(To, Double.ToString(), Code);

			return null;
		}

		private ConstExpressionNode ConvertUnsigned(Type To)
		{
			if (To is SignedType) return new ConstExpressionNode(To, (long)Unsigned, Code);
			else if (To is UnsignedType) return new ConstExpressionNode(To, (ulong)Unsigned, Code);
			else if (To is FloatType)
			{
				var FType = To as FloatType;
				if (FType.Size == 8) return new ConstExpressionNode(To, (double)Unsigned, Code);
				else if (FType.Size == 4) return new ConstExpressionNode(To, (float)Unsigned, Code);
				else throw new NotImplementedException();
			}
			else if (To is ConstStringType) return new ConstExpressionNode(To, Unsigned.ToString(), Code);
			else if (To is EnumType)
			{
				var ValType = (To as EnumType).TypeOfValues;
				if (ValType is SignedType) return new ConstExpressionNode(To, (long)Unsigned, Code);
				else if (ValType is UnsignedType) return new ConstExpressionNode(To, Unsigned, Code);
			}

			return null;
		}

		private ConstExpressionNode ConvertSigned(Type To)
		{
			if (To is SignedType) return new ConstExpressionNode(To, (long)Signed, Code);
			else if (To is UnsignedType) return new ConstExpressionNode(To, (ulong)Signed, Code);
			else if (To is FloatType)
			{
				var FType = To as FloatType;
				if (FType.Size == 8) return new ConstExpressionNode(To, (double)Signed, Code);
				else if (FType.Size == 4) return new ConstExpressionNode(To, (float)Signed, Code);
				else throw new NotImplementedException();
			}
			else if (To is ConstStringType) return new ConstExpressionNode(To, Signed.ToString(), Code);
			else if (To is EnumType)
			{
				var ValType = (To as EnumType).TypeOfValues;
				if (ValType is SignedType) return new ConstExpressionNode(To, Signed, Code);
				else if (ValType is UnsignedType) return new ConstExpressionNode(To, (ulong)Signed, Code);
			}

			return null;
		}

		private ConstExpressionNode ConvertEnum(Type To)
		{
			if (To is NumberType)
			{
				var ValType = (Type as EnumType).TypeOfValues;
				if (ValType is UnsignedType) return new ConstExpressionNode(To, Unsigned, Code);
				else if (ValType is SignedType) return new ConstExpressionNode(To, Signed, Code);
			}

			return null;
		}

		public static ConstExpressionNode DoOps(IdContainer Container, OpExpressionNode OpNode)
		{
			var Ch = OpNode.Children;
			var Op = OpNode.Operator;
			var Dst = Ch[0] as ConstExpressionNode;
			var Src = Ch.Count > 0 ? Ch[1] as ConstExpressionNode : null;

			if (Op == Operator.Condition)
			{
				if (Dst.Bool) return Ch[1] as ConstExpressionNode;
				else return Ch[2] as ConstExpressionNode;
			}

			if (Dst.Type is SignedType) return SignedOps(Container, OpNode, Dst, Src);
			else if (Dst.Type is UnsignedType) return UnsignedOps(Container, OpNode, Dst, Src);
			else if (Dst.Type is FloatType) return FloatOps(Container, OpNode, Dst, Src);
			else if (Dst.Type is BoolType) return BoolOps(OpNode, Dst, Src);
			else if (Dst.Type is ConstStringType) return ConstStrOps(Container, OpNode, Dst, Src);
			else if (Dst.Type is EnumType) return EnumOps(Container, OpNode, Dst, Src);
			else throw new NotImplementedException();
		}

		private static ConstExpressionNode EnumOps(IdContainer Container, OpExpressionNode OpNode, ConstExpressionNode Dst, ConstExpressionNode Src)
		{
			var Op = OpNode.Operator;
			if (Op == Operator.Equal) return Expressions.GetBoolValue(Container, Dst.Unsigned == Src.Unsigned, OpNode.Code);
			else if (Op == Operator.Nonequal) return Expressions.GetBoolValue(Container, Dst.Unsigned != Src.Unsigned, OpNode.Code);

			else if (Op == Operator.BitwiseAnd) return new ConstExpressionNode(Dst.Type, Dst.Unsigned & Src.Unsigned, OpNode.Code);
			else if (Op == Operator.BitwiseOr) return new ConstExpressionNode(Dst.Type, Dst.Unsigned | Src.Unsigned, OpNode.Code);
			else if (Op == Operator.BitwiseXor) return new ConstExpressionNode(Dst.Type, (Dst.Unsigned | Src.Unsigned) & ~(Dst.Unsigned & Src.Unsigned), OpNode.Code);
			else throw new NotImplementedException();
		}

		private static ConstExpressionNode ConstStrOps(IdContainer Container, OpExpressionNode OpNode, ConstExpressionNode Dst, ConstExpressionNode Src)
		{
			var Op = OpNode.Operator;
			if (Op == Operator.Add) return new ConstExpressionNode(Dst.Type, Dst.String + Src.String, OpNode.Code);
			else if (Op == Operator.Equal) return Expressions.GetBoolValue(Container, Dst.String == Src.String, OpNode.Code);
			else if (Op == Operator.Nonequal) return Expressions.GetBoolValue(Container, Dst.String != Src.String, OpNode.Code);
			else throw new NotImplementedException();
		}

		private static ConstExpressionNode BoolOps(OpExpressionNode OpNode, ConstExpressionNode Dst, ConstExpressionNode Src)
		{
			var Op = OpNode.Operator;
			var BType = Dst.Type as BoolType;
			if (Op == Operator.Equal) return Expressions.GetBoolValue(BType, Dst.Bool == Src.Bool, OpNode.Code);
			else if (Op == Operator.Nonequal) return Expressions.GetBoolValue(BType, Dst.Bool != Src.Bool, OpNode.Code);

			else if (Op == Operator.Add) return Expressions.GetBoolValue(BType, Dst.Bool && Src.Bool, OpNode.Code);
			else if (Op == Operator.Or) return Expressions.GetBoolValue(BType, Dst.Bool || Src.Bool, OpNode.Code);
			else if (Op == Operator.Xor) return Expressions.GetBoolValue(BType, (Dst.Bool || Src.Bool) && !(Dst.Bool && Src.Bool), OpNode.Code);

			else if (Op == Operator.Not) return new ConstExpressionNode(Dst.Type, !Dst.Bool, OpNode.Code);
			else throw new NotImplementedException();
		}

		private static ConstExpressionNode FloatOps(IdContainer Container, OpExpressionNode OpNode, ConstExpressionNode Dst, ConstExpressionNode Src)
		{
			var Op = OpNode.Operator;
			if (Op == Operator.Add) return new ConstExpressionNode(Dst.Type, Dst.Double + Src.Double, OpNode.Code);
			else if (Op == Operator.Subract) return new ConstExpressionNode(Dst.Type, Dst.Double - Src.Double, OpNode.Code);
			else if (Op == Operator.Multiply) return new ConstExpressionNode(Dst.Type, Dst.Double * Src.Double, OpNode.Code);
			else if (Op == Operator.Divide) return new ConstExpressionNode(Dst.Type, Dst.Double / Src.Double, OpNode.Code);
			else if (Op == Operator.Modolus) return new ConstExpressionNode(Dst.Type, Dst.Double % Src.Double, OpNode.Code);

			else if (Op == Operator.Equal) return Expressions.GetBoolValue(Container, Dst.Double == Src.Double, OpNode.Code);
			else if (Op == Operator.Nonequal) return Expressions.GetBoolValue(Container, Dst.Double != Src.Double, OpNode.Code);
			else if (Op == Operator.Greater) return Expressions.GetBoolValue(Container, Dst.Double > Src.Double, OpNode.Code);
			else if (Op == Operator.GreaterEqual) return Expressions.GetBoolValue(Container, Dst.Double >= Src.Double, OpNode.Code);
			else if (Op == Operator.Less) return Expressions.GetBoolValue(Container, Dst.Double < Src.Double, OpNode.Code);
			else if (Op == Operator.LessEqual) return Expressions.GetBoolValue(Container, Dst.Double <= Src.Double, OpNode.Code);

			else if (Op == Operator.Neg) return new ConstExpressionNode(Dst.Type, -Dst.Double, OpNode.Code);
			else if (Op == Operator.Abs) return new ConstExpressionNode(Dst.Type, Dst.Double < 0 ? -Dst.Double : Dst.Double, OpNode.Code);

			else if (Op == Operator.Sqrt) return new ConstExpressionNode(Dst.Type, Math.Sqrt(Dst.Double), OpNode.Code);
			else if (Op == Operator.Sin) return new ConstExpressionNode(Dst.Type, Math.Sin(Dst.Double), OpNode.Code);
			else if (Op == Operator.Cos) return new ConstExpressionNode(Dst.Type, Math.Cos(Dst.Double), OpNode.Code);
			else if (Op == Operator.Tan) return new ConstExpressionNode(Dst.Type, Math.Tan(Dst.Double), OpNode.Code);
			else if (Op == Operator.ATan) return new ConstExpressionNode(Dst.Type, Math.Atan(Dst.Double), OpNode.Code);
			else if (Op == Operator.ATan2) return new ConstExpressionNode(Dst.Type, Math.Atan2(Dst.Double, Src.CDouble), OpNode.Code);
			else if (Op == Operator.ASin) return new ConstExpressionNode(Dst.Type, Math.Asin(Dst.Double), OpNode.Code);
			else if (Op == Operator.ACos) return new ConstExpressionNode(Dst.Type, Math.Acos(Dst.Double), OpNode.Code);
			else throw new NotImplementedException();
		}

		private static ConstExpressionNode UnsignedOps(IdContainer Container, OpExpressionNode OpNode, ConstExpressionNode Dst, ConstExpressionNode Src)
		{
			var Op = OpNode.Operator;
			if (Op == Operator.Add) return new ConstExpressionNode(Dst.Type, Dst.Unsigned + Src.Unsigned, OpNode.Code);
			else if (Op == Operator.Subract) return new ConstExpressionNode(Dst.Type, Dst.Unsigned - Src.Unsigned, OpNode.Code);
			else if (Op == Operator.Multiply) return new ConstExpressionNode(Dst.Type, Dst.Unsigned * Src.Unsigned, OpNode.Code);
			else if (Op == Operator.Divide) return new ConstExpressionNode(Dst.Type, Dst.Unsigned / Src.Unsigned, OpNode.Code);
			else if (Op == Operator.Modolus) return new ConstExpressionNode(Dst.Type, Dst.Unsigned % Src.Unsigned, OpNode.Code);
			else if (Op == Operator.ShiftLeft) return new ConstExpressionNode(Dst.Type, Dst.Unsigned * Helper.Pow(Src.Unsigned, 2), OpNode.Code);
			else if (Op == Operator.ShiftRight) return new ConstExpressionNode(Dst.Type, Dst.Unsigned / Helper.Pow(Src.Unsigned, 2), OpNode.Code);

			else if (Op == Operator.Equal) return Expressions.GetBoolValue(Container, Dst.Unsigned == Src.Unsigned, OpNode.Code);
			else if (Op == Operator.Nonequal) return Expressions.GetBoolValue(Container, Dst.Unsigned != Src.Unsigned, OpNode.Code);
			else if (Op == Operator.Greater) return Expressions.GetBoolValue(Container, Dst.Unsigned > Src.Unsigned, OpNode.Code);
			else if (Op == Operator.GreaterEqual) return Expressions.GetBoolValue(Container, Dst.Unsigned >= Src.Unsigned, OpNode.Code);
			else if (Op == Operator.Less) return Expressions.GetBoolValue(Container, Dst.Unsigned < Src.Unsigned, OpNode.Code);
			else if (Op == Operator.LessEqual) return Expressions.GetBoolValue(Container, Dst.Unsigned <= Src.Unsigned, OpNode.Code);

			else if (Op == Operator.Complement) return new ConstExpressionNode(Dst.Type, ~Dst.Unsigned, OpNode.Code);

			else if (Op == Operator.BitwiseAnd) return new ConstExpressionNode(Dst.Type, Dst.Unsigned & Src.Unsigned, OpNode.Code);
			else if (Op == Operator.BitwiseOr) return new ConstExpressionNode(Dst.Type, Dst.Unsigned | Src.Unsigned, OpNode.Code);
			else if (Op == Operator.BitwiseXor) return new ConstExpressionNode(Dst.Type, (Dst.Unsigned | Src.Unsigned) & ~(Dst.Unsigned & Src.Unsigned), OpNode.Code);

			else if (Op == Operator.Sqrt) return Expressions.GetFloatValue(Container, Math.Sqrt(Dst.CDouble), OpNode.Code);
			else if (Op == Operator.Sin) return Expressions.GetFloatValue(Container, Math.Sin(Dst.CDouble), OpNode.Code);
			else if (Op == Operator.Cos) return Expressions.GetFloatValue(Container, Math.Cos(Dst.CDouble), OpNode.Code);
			else if (Op == Operator.Tan) return Expressions.GetFloatValue(Container, Math.Tan(Dst.CDouble), OpNode.Code);
			else if (Op == Operator.ATan) return Expressions.GetFloatValue(Container, Math.Atan(Dst.CDouble), OpNode.Code);
			else if (Op == Operator.ATan2) return Expressions.GetFloatValue(Container, Math.Atan2(Dst.CDouble, Src.CDouble), OpNode.Code);
			else if (Op == Operator.ASin) return Expressions.GetFloatValue(Container, Math.Asin(Dst.CDouble), OpNode.Code);
			else if (Op == Operator.ACos) return Expressions.GetFloatValue(Container, Math.Acos(Dst.CDouble), OpNode.Code);
			else throw new NotImplementedException();
		}

		private static ConstExpressionNode SignedOps(IdContainer Container, OpExpressionNode OpNode, ConstExpressionNode Dst, ConstExpressionNode Src)
		{
			var Op = OpNode.Operator;
			if (Op == Operator.Add) return new ConstExpressionNode(Dst.Type, Dst.Signed + Src.Signed, OpNode.Code);
			else if (Op == Operator.Subract) return new ConstExpressionNode(Dst.Type, Dst.Signed - Src.Signed, OpNode.Code);
			else if (Op == Operator.Multiply) return new ConstExpressionNode(Dst.Type, Dst.Signed * Src.Signed, OpNode.Code);
			else if (Op == Operator.Divide) return new ConstExpressionNode(Dst.Type, Dst.Signed / Src.Signed, OpNode.Code);
			else if (Op == Operator.Modolus) return new ConstExpressionNode(Dst.Type, Dst.Signed % Src.Signed, OpNode.Code);
			else if (Op == Operator.ShiftLeft) return new ConstExpressionNode(Dst.Type, Dst.Signed * Helper.Pow(Src.Signed, 2), OpNode.Code);
			else if (Op == Operator.ShiftRight) return new ConstExpressionNode(Dst.Type, Dst.Signed / Helper.Pow(Src.Signed, 2), OpNode.Code);

			else if (Op == Operator.Equal) return Expressions.GetBoolValue(Container, Dst.Signed == Src.Signed, OpNode.Code);
			else if (Op == Operator.Nonequal) return Expressions.GetBoolValue(Container, Dst.Signed != Src.Signed, OpNode.Code);
			else if (Op == Operator.Greater) return Expressions.GetBoolValue(Container, Dst.Signed > Src.Signed, OpNode.Code);
			else if (Op == Operator.GreaterEqual) return Expressions.GetBoolValue(Container, Dst.Signed >= Src.Signed, OpNode.Code);
			else if (Op == Operator.Less) return Expressions.GetBoolValue(Container, Dst.Signed < Src.Signed, OpNode.Code);
			else if (Op == Operator.LessEqual) return Expressions.GetBoolValue(Container, Dst.Signed <= Src.Signed, OpNode.Code);

			else if (Op == Operator.Complement) return new ConstExpressionNode(Dst.Type, ~Dst.Signed, OpNode.Code);
			else if (Op == Operator.Neg) return new ConstExpressionNode(Dst.Type, -Dst.Signed, OpNode.Code);

			else if (Op == Operator.BitwiseAnd) return new ConstExpressionNode(Dst.Type, Dst.Signed & Src.Signed, OpNode.Code);
			else if (Op == Operator.BitwiseOr) return new ConstExpressionNode(Dst.Type, Dst.Signed | Src.Signed, OpNode.Code);
			else if (Op == Operator.BitwiseXor) return new ConstExpressionNode(Dst.Type, (Dst.Signed | Src.Signed) & ~(Dst.Signed & Src.Signed), OpNode.Code);
			
			else if (Op == Operator.Abs) return new ConstExpressionNode(Dst.Type, Dst.Signed < 0 ? -Dst.Signed : Dst.Signed, OpNode.Code);
			else if (Op == Operator.Sqrt) return Expressions.GetFloatValue(Container, Math.Sqrt(Dst.CDouble), OpNode.Code);

			else if (Op == Operator.Sin) return Expressions.GetFloatValue(Container, Math.Sin(Dst.CDouble), OpNode.Code);
			else if (Op == Operator.Cos) return Expressions.GetFloatValue(Container, Math.Cos(Dst.CDouble), OpNode.Code);
			else if (Op == Operator.Tan) return Expressions.GetFloatValue(Container, Math.Tan(Dst.CDouble), OpNode.Code);
			else if (Op == Operator.ATan) return Expressions.GetFloatValue(Container, Math.Atan(Dst.CDouble), OpNode.Code);
			else if (Op == Operator.ATan2) return Expressions.GetFloatValue(Container, Math.Atan2(Dst.CDouble, Src.CDouble), OpNode.Code);
			else if (Op == Operator.ASin) return Expressions.GetFloatValue(Container, Math.Asin(Dst.CDouble), OpNode.Code);
			else if (Op == Operator.ACos) return Expressions.GetFloatValue(Container, Math.Acos(Dst.CDouble), OpNode.Code);
			else throw new NotImplementedException();
		}
	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer
Hungary Hungary
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions