Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
LanguageRuntime_Init.cs
Go to the documentation of this file.
1 #region License
2 /* **********************************************************************************
3  * Copyright (c) Roman Ivantsov
4  * This source code is subject to terms and conditions of the MIT License
5  * for Irony. A copy of the license can be found in the License.txt file
6  * at the root of this distribution.
7  * By using this source code in any fashion, you are agreeing to be bound by the terms of the
8  * MIT License.
9  * You must not remove this notice from this software.
10  * **********************************************************************************/
11 #endregion
12 
13 using System;
14 using System.Collections.Generic;
15 using System.Linq;
16 using System.Text;
17 //using Irony.Compiler;
18 
19 namespace Irony.Interpreter {
21  using Complex = Microsoft.Scripting.Math.Complex64;
22 
23  //Initialization of Runtime
24  public partial class LanguageRuntime {
25 
26  public virtual void Init() {
27  InitBaseTypeList();
28  InitTypeConverters();
29  InitOperatorImplementations();
30  }
31 
32  public virtual void InitBaseTypeList() {
33  BaseTypeSequence.Clear();
34  BaseTypeSequence.AddRange(new Type[] {
35  typeof(string), typeof(Complex), typeof(Double), typeof(Single), typeof(Decimal),
36  typeof(BigInteger),
37  typeof(UInt64), typeof(Int64), typeof(UInt32), typeof(Int32), typeof(UInt16), typeof(Int16), typeof(byte), typeof(sbyte), typeof(bool)
38  });
39  }
40 
41  public virtual void InitTypeConverters() {
42  bool useComplex = BaseTypeSequence.Contains(typeof(Complex));
43  bool useBigInt = BaseTypeSequence.Contains(typeof(BigInteger));
44  //->string
45  Type T = typeof(string);
46  foreach (Type t in BaseTypeSequence)
47  if (t != T)
48  TypeConverters.Add(t, T, ConvertAnyToString);
49  //->Complex
50  if (useComplex) {
51  TypeConverters.Add(typeof(sbyte), typeof(Complex), ConvertAnyToComplex);
52  TypeConverters.Add(typeof(byte), typeof(Complex), ConvertAnyToComplex);
53  TypeConverters.Add(typeof(Int16), typeof(Complex), ConvertAnyToComplex);
54  TypeConverters.Add(typeof(UInt16), typeof(Complex), ConvertAnyToComplex);
55  TypeConverters.Add(typeof(Int32), typeof(Complex), ConvertAnyToComplex);
56  TypeConverters.Add(typeof(UInt32), typeof(Complex), ConvertAnyToComplex);
57  TypeConverters.Add(typeof(Int64), typeof(Complex), ConvertAnyToComplex);
58  TypeConverters.Add(typeof(UInt64), typeof(Complex), ConvertAnyToComplex);
59  TypeConverters.Add(typeof(Single), typeof(Complex), ConvertAnyToComplex);
60  if (useBigInt)
61  TypeConverters.Add(typeof(BigInteger), typeof(Complex), ConvertBigIntToComplex);
62  }
63  //->BigInteger
64  if (useBigInt) {
65  TypeConverters.Add(typeof(sbyte), typeof(BigInteger), ConvertAnyIntToBigInteger);
66  TypeConverters.Add(typeof(byte), typeof(BigInteger), ConvertAnyIntToBigInteger);
67  TypeConverters.Add(typeof(Int16), typeof(BigInteger), ConvertAnyIntToBigInteger);
68  TypeConverters.Add(typeof(UInt16), typeof(BigInteger), ConvertAnyIntToBigInteger);
69  TypeConverters.Add(typeof(Int32), typeof(BigInteger), ConvertAnyIntToBigInteger);
70  TypeConverters.Add(typeof(UInt32), typeof(BigInteger), ConvertAnyIntToBigInteger);
71  TypeConverters.Add(typeof(Int64), typeof(BigInteger), ConvertAnyIntToBigInteger);
72  TypeConverters.Add(typeof(UInt64), typeof(BigInteger), ConvertAnyIntToBigInteger);
73  }
74 
75  //->Double
76  TypeConverters.Add(typeof(sbyte), typeof(double), value => (double)(sbyte)value);
77  TypeConverters.Add(typeof(byte), typeof(double), value => (double)(byte)value);
78  TypeConverters.Add(typeof(Int16), typeof(double), value => (double)(Int16)value);
79  TypeConverters.Add(typeof(UInt16), typeof(double), value => (double)(UInt16)value);
80  TypeConverters.Add(typeof(Int32), typeof(double), value => (double)(Int32)value);
81  TypeConverters.Add(typeof(UInt32), typeof(double), value => (double)(UInt32)value);
82  TypeConverters.Add(typeof(Int64), typeof(double), value => (double)(Int64)value);
83  TypeConverters.Add(typeof(UInt64), typeof(double), value => (double)(UInt64)value);
84  TypeConverters.Add(typeof(Single), typeof(double), value => (double)(Single)value);
85  if (useBigInt)
86  TypeConverters.Add(typeof(BigInteger), typeof(double), value => ((BigInteger)value).ToDouble(null));
87  //->Single
88  TypeConverters.Add(typeof(sbyte), typeof(Single), value => (Single)(sbyte)value);
89  TypeConverters.Add(typeof(byte), typeof(Single), value => (Single)(byte)value);
90  TypeConverters.Add(typeof(Int16), typeof(Single), value => (Single)(Int16)value);
91  TypeConverters.Add(typeof(UInt16), typeof(Single), value => (Single)(UInt16)value);
92  TypeConverters.Add(typeof(Int32), typeof(Single), value => (Single)(Int32)value);
93  TypeConverters.Add(typeof(UInt32), typeof(Single), value => (Single)(UInt32)value);
94  TypeConverters.Add(typeof(Int64), typeof(Single), value => (Single)(Int64)value);
95  TypeConverters.Add(typeof(UInt64), typeof(Single), value => (Single)(UInt64)value);
96  if (useBigInt)
97  TypeConverters.Add(typeof(BigInteger), typeof(Single), value => (Single)((BigInteger)value).ToDouble(null));
98 
99  //->UInt64
100  TypeConverters.Add(typeof(sbyte), typeof(UInt64), value => (UInt64)(sbyte)value);
101  TypeConverters.Add(typeof(byte), typeof(UInt64), value => (UInt64)(byte)value);
102  TypeConverters.Add(typeof(Int16), typeof(UInt64), value => (UInt64)(Int16)value);
103  TypeConverters.Add(typeof(UInt16), typeof(UInt64), value => (UInt64)(UInt16)value);
104  TypeConverters.Add(typeof(Int32), typeof(UInt64), value => (UInt64)(Int32)value);
105  TypeConverters.Add(typeof(UInt32), typeof(UInt64), value => (UInt64)(UInt32)value);
106  TypeConverters.Add(typeof(Int64), typeof(UInt64), value => (UInt64)(Int64)value);
107  //->Int64
108  TypeConverters.Add(typeof(sbyte), typeof(Int64), value => (Int64)(sbyte)value);
109  TypeConverters.Add(typeof(byte), typeof(Int64), value => (Int64)(byte)value);
110  TypeConverters.Add(typeof(Int16), typeof(Int64), value => (Int64)(Int16)value);
111  TypeConverters.Add(typeof(UInt16), typeof(Int64), value => (Int64)(UInt16)value);
112  TypeConverters.Add(typeof(Int32), typeof(Int64), value => (Int64)(Int32)value);
113  TypeConverters.Add(typeof(UInt32), typeof(Int64), value => (Int64)(UInt32)value);
114  //->UInt32
115  TypeConverters.Add(typeof(sbyte), typeof(UInt32), value => (UInt32)(sbyte)value);
116  TypeConverters.Add(typeof(byte), typeof(UInt32), value => (UInt32)(byte)value);
117  TypeConverters.Add(typeof(Int16), typeof(UInt32), value => (UInt32)(Int16)value);
118  TypeConverters.Add(typeof(UInt16), typeof(UInt32), value => (UInt32)(UInt16)value);
119  TypeConverters.Add(typeof(Int32), typeof(UInt32), value => (UInt32)(Int32)value);
120  //->Int32
121  TypeConverters.Add(typeof(sbyte), typeof(Int32), value => (Int32)(sbyte)value);
122  TypeConverters.Add(typeof(byte), typeof(Int32), value => (Int32)(byte)value);
123  TypeConverters.Add(typeof(Int16), typeof(Int32), value => (Int32)(Int16)value);
124  TypeConverters.Add(typeof(UInt16), typeof(Int32), value => (Int32)(UInt16)value);
125  //->UInt16
126  TypeConverters.Add(typeof(sbyte), typeof(UInt16), value => (UInt16)(sbyte)value);
127  TypeConverters.Add(typeof(byte), typeof(UInt16), value => (UInt16)(byte)value);
128  TypeConverters.Add(typeof(Int16), typeof(UInt16), value => (UInt16)(Int16)value);
129  //->Int16
130  TypeConverters.Add(typeof(sbyte), typeof(Int16), value => (Int16)(sbyte)value);
131  TypeConverters.Add(typeof(byte), typeof(Int16), value => (Int16)(byte)value);
132  //->byte
133  TypeConverters.Add(typeof(sbyte), typeof(byte), value => (byte)(sbyte)value);
134  }
135 
136  public static object ConvertAnyToString(object value) {
137  return value == null ? string.Empty : value.ToString();
138  }
139 
140  public static object ConvertBigIntToComplex(object value) {
141  BigInteger bi = (BigInteger) value;
142  return new Complex(bi.ToFloat64());
143  }
144 
145  public static object ConvertAnyToComplex(object value) {
146  double d = Convert.ToDouble(value);
147  return new Complex(d);
148  }
149  public static object ConvertAnyIntToBigInteger(object value) {
150  long l = Convert.ToInt64(value);
151  return BigInteger.Create(l);
152  }
153 
154  public virtual void InitOperatorImplementations() {
155  _baseOperatorImplementations = new OperatorImplementationTable();
156 
157  // note that arithmetics on byte, sbyte, int16, uint16 are performed in Int32 format (the way it's done in c# I guess)
158  // so the result is always Int32
159  // we don't force the result back to original type - I don't think it's necessary
160  // For each operator, we add a series of implementation methods for same-type operands. They are saved as DispatchRecords in
161  // operator dispatchers. This happens at initialization time. Dispatch records for mismatched argument types (ex: int + double)
162  // are created on-the-fly at execution time.
163  string op;
164 
165  op = "+";
166  AddImplementation(op, typeof(sbyte), (x, y) => (sbyte)x + (sbyte)y);
167  AddImplementation(op, typeof(byte), (x, y) => (byte)x + (byte)y);
168  AddImplementation(op, typeof(Int16), (x, y) => (Int16)x + (Int16)y);
169  AddImplementation(op, typeof(UInt16), (x, y) => (UInt16)x + (UInt16)y);
170  AddImplementation(op, typeof(Int32), (x, y) => checked((Int32)x + (Int32)y));
171  AddImplementation(op, typeof(UInt32), (x, y) => checked((UInt32)x + (UInt32)y));
172  AddImplementation(op, typeof(Int64), (x, y) => checked((Int64)x + (Int64)y));
173  AddImplementation(op, typeof(UInt64), (x, y) => checked((UInt64)x + (UInt64)y));
174  AddImplementation(op, typeof(Single), (x, y) => (Single)x + (Single)y);
175  AddImplementation(op, typeof(double), (x, y) => (double)x + (double)y);
176  AddImplementation(op, typeof(BigInteger), (x, y) => (BigInteger)x + (BigInteger)y);
177  AddImplementation(op, typeof(Complex), (x, y) => (Complex)x + (Complex)y);
178  AddImplementation(op, typeof(string), (x, y) => (string)x + (string)y);
179 
180  op = "-";
181  AddImplementation(op, typeof(sbyte), (x, y) => (sbyte)x - (sbyte)y);
182  AddImplementation(op, typeof(byte), (x, y) => (byte)x - (byte)y);
183  AddImplementation(op, typeof(Int16), (x, y) => (Int16)x - (Int16)y);
184  AddImplementation(op, typeof(UInt16), (x, y) => (UInt16)x - (UInt16)y);
185  AddImplementation(op, typeof(Int32), (x, y) => checked((Int32)x - (Int32)y));
186  AddImplementation(op, typeof(UInt32), (x, y) => checked((UInt32)x - (UInt32)y));
187  AddImplementation(op, typeof(Int64), (x, y) => checked((Int64)x - (Int64)y));
188  AddImplementation(op, typeof(UInt64), (x, y) => checked((UInt64)x - (UInt64)y));
189  AddImplementation(op, typeof(Single), (x, y) => (Single)x - (Single)y);
190  AddImplementation(op, typeof(double), (x, y) => (double)x - (double)y);
191  AddImplementation(op, typeof(BigInteger), (x, y) => (BigInteger)x - (BigInteger)y);
192  AddImplementation(op, typeof(Complex), (x, y) => (Complex)x - (Complex)y);
193 
194  op = "*";
195  AddImplementation(op, typeof(sbyte), (x, y) => (sbyte)x * (sbyte)y);
196  AddImplementation(op, typeof(byte), (x, y) => (byte)x * (byte)y);
197  AddImplementation(op, typeof(Int16), (x, y) => checked((Int16)x * (Int16)y));
198  AddImplementation(op, typeof(UInt16), (x, y) => checked((UInt16)x * (UInt16)y));
199  AddImplementation(op, typeof(Int32), (x, y) => checked((Int32)x * (Int32)y));
200  AddImplementation(op, typeof(UInt32), (x, y) => checked((UInt32)x * (UInt32)y));
201  AddImplementation(op, typeof(Int64), (x, y) => checked((Int64)x * (Int64)y));
202  AddImplementation(op, typeof(UInt64), (x, y) => checked((UInt64)x * (UInt64)y));
203  AddImplementation(op, typeof(Single), (x, y) => (Single)x * (Single)y);
204  AddImplementation(op, typeof(double), (x, y) => (double)x * (double)y);
205  AddImplementation(op, typeof(BigInteger), (x, y) => (BigInteger)x * (BigInteger)y);
206  AddImplementation(op, typeof(Complex), (x, y) => (Complex)x * (Complex)y);
207 
208  op = "/";
209  AddImplementation(op, typeof(sbyte), (x, y) => (sbyte)x / (sbyte)y);
210  AddImplementation(op, typeof(byte), (x, y) => (byte)x / (byte)y);
211  AddImplementation(op, typeof(Int16), (x, y) => checked((Int16)x / (Int16)y));
212  AddImplementation(op, typeof(UInt16), (x, y) => checked((UInt16)x / (UInt16)y));
213  AddImplementation(op, typeof(Int32), (x, y) => checked((Int32)x / (Int32)y));
214  AddImplementation(op, typeof(UInt32), (x, y) => checked((UInt32)x / (UInt32)y));
215  AddImplementation(op, typeof(Int64), (x, y) => checked((Int64)x / (Int64)y));
216  AddImplementation(op, typeof(UInt64), (x, y) => checked((UInt64)x / (UInt64)y));
217  AddImplementation(op, typeof(Single), (x, y) => (Single)x / (Single)y);
218  AddImplementation(op, typeof(double), (x, y) => (double)x / (double)y);
219  AddImplementation(op, typeof(BigInteger), (x, y) => (BigInteger)x / (BigInteger)y);
220  AddImplementation(op, typeof(Complex), (x, y) => (Complex)x / (Complex)y);
221 
222  op = "&";
223  AddImplementation(op, typeof(bool), (x, y) => (bool)x & (bool)y);
224  AddImplementation(op, typeof(sbyte), (x, y) => (sbyte)x & (sbyte)y);
225  AddImplementation(op, typeof(byte), (x, y) => (byte)x & (byte)y);
226  AddImplementation(op, typeof(Int16), (x, y) => (Int16)x & (Int16)y);
227  AddImplementation(op, typeof(UInt16), (x, y) => (UInt16)x & (UInt16)y);
228  AddImplementation(op, typeof(Int32), (x, y) => (Int32)x & (Int32)y);
229  AddImplementation(op, typeof(UInt32), (x, y) => (UInt32)x & (UInt32)y);
230  AddImplementation(op, typeof(Int64), (x, y) => (Int64)x & (Int64)y);
231  AddImplementation(op, typeof(UInt64), (x, y) => (UInt64)x & (UInt64)y);
232 
233  op = "|";
234  AddImplementation(op, typeof(bool), (x, y) => (bool)x | (bool)y);
235  AddImplementation(op, typeof(sbyte), (x, y) => (sbyte)x | (sbyte)y);
236  AddImplementation(op, typeof(byte), (x, y) => (byte)x | (byte)y);
237  AddImplementation(op, typeof(Int16), (x, y) => (Int16)x | (Int16)y);
238  AddImplementation(op, typeof(UInt16), (x, y) => (UInt16)x | (UInt16)y);
239  AddImplementation(op, typeof(Int32), (x, y) => (Int32)x | (Int32)y);
240  AddImplementation(op, typeof(UInt32), (x, y) => (UInt32)x | (UInt32)y);
241  AddImplementation(op, typeof(Int64), (x, y) => (Int64)x | (Int64)y);
242  AddImplementation(op, typeof(UInt64), (x, y) => (UInt64)x | (UInt64)y);
243 
244  op = "^"; //XOR
245  AddImplementation(op, typeof(bool), (x, y) => (bool)x ^ (bool)y);
246  AddImplementation(op, typeof(sbyte), (x, y) => (sbyte)x ^ (sbyte)y);
247  AddImplementation(op, typeof(byte), (x, y) => (byte)x ^ (byte)y);
248  AddImplementation(op, typeof(Int16), (x, y) => (Int16)x ^ (Int16)y);
249  AddImplementation(op, typeof(UInt16), (x, y) => (UInt16)x ^ (UInt16)y);
250  AddImplementation(op, typeof(Int32), (x, y) => (Int32)x ^ (Int32)y);
251  AddImplementation(op, typeof(UInt32), (x, y) => (UInt32)x ^ (UInt32)y);
252  AddImplementation(op, typeof(Int64), (x, y) => (Int64)x ^ (Int64)y);
253  AddImplementation(op, typeof(UInt64), (x, y) => (UInt64)x ^ (UInt64)y);
254 
255  //Note that && and || are special forms, not binary operators
256 
257  op = "<";
258  AddImplementation(op, typeof(sbyte), (x, y) => (sbyte)x < (sbyte)y, BoolResultConverter);
259  AddImplementation(op, typeof(byte), (x, y) => (byte)x < (byte)y, BoolResultConverter);
260  AddImplementation(op, typeof(Int16), (x, y) => (Int16)x < (Int16)y, BoolResultConverter);
261  AddImplementation(op, typeof(UInt16), (x, y) => (UInt16)x < (UInt16)y, BoolResultConverter);
262  AddImplementation(op, typeof(Int32), (x, y) => checked((Int32)x < (Int32)y), BoolResultConverter);
263  AddImplementation(op, typeof(UInt32), (x, y) => checked((UInt32)x < (UInt32)y), BoolResultConverter);
264  AddImplementation(op, typeof(Int64), (x, y) => checked((Int64)x < (Int64)y), BoolResultConverter);
265  AddImplementation(op, typeof(UInt64), (x, y) => checked((UInt64)x < (UInt64)y), BoolResultConverter);
266  AddImplementation(op, typeof(Single), (x, y) => (Single)x < (Single)y, BoolResultConverter);
267  AddImplementation(op, typeof(double), (x, y) => (double)x < (double)y, BoolResultConverter);
268  AddImplementation(op, typeof(BigInteger), (x, y) => (BigInteger)x < (BigInteger)y, BoolResultConverter);
269 
270  op = ">";
271  AddImplementation(op, typeof(sbyte), (x, y) => (sbyte)x > (sbyte)y, BoolResultConverter);
272  AddImplementation(op, typeof(byte), (x, y) => (byte)x > (byte)y, BoolResultConverter);
273  AddImplementation(op, typeof(Int16), (x, y) => (Int16)x > (Int16)y, BoolResultConverter);
274  AddImplementation(op, typeof(UInt16), (x, y) => (UInt16)x > (UInt16)y, BoolResultConverter);
275  AddImplementation(op, typeof(Int32), (x, y) => checked((Int32)x > (Int32)y), BoolResultConverter);
276  AddImplementation(op, typeof(UInt32), (x, y) => checked((UInt32)x > (UInt32)y), BoolResultConverter);
277  AddImplementation(op, typeof(Int64), (x, y) => checked((Int64)x > (Int64)y), BoolResultConverter);
278  AddImplementation(op, typeof(UInt64), (x, y) => checked((UInt64)x > (UInt64)y), BoolResultConverter);
279  AddImplementation(op, typeof(Single), (x, y) => (Single)x > (Single)y, BoolResultConverter);
280  AddImplementation(op, typeof(double), (x, y) => (double)x > (double)y, BoolResultConverter);
281  AddImplementation(op, typeof(BigInteger), (x, y) => (BigInteger)x > (BigInteger)y, BoolResultConverter);
282 
283  op = "<=";
284  AddImplementation(op, typeof(sbyte), (x, y) => (sbyte)x <= (sbyte)y, BoolResultConverter);
285  AddImplementation(op, typeof(byte), (x, y) => (byte)x <= (byte)y, BoolResultConverter);
286  AddImplementation(op, typeof(Int16), (x, y) => (Int16)x <= (Int16)y, BoolResultConverter);
287  AddImplementation(op, typeof(UInt16), (x, y) => (UInt16)x <= (UInt16)y, BoolResultConverter);
288  AddImplementation(op, typeof(Int32), (x, y) => checked((Int32)x <= (Int32)y), BoolResultConverter);
289  AddImplementation(op, typeof(UInt32), (x, y) => checked((UInt32)x <= (UInt32)y), BoolResultConverter);
290  AddImplementation(op, typeof(Int64), (x, y) => checked((Int64)x <= (Int64)y), BoolResultConverter);
291  AddImplementation(op, typeof(UInt64), (x, y) => checked((UInt64)x <= (UInt64)y), BoolResultConverter);
292  AddImplementation(op, typeof(Single), (x, y) => (Single)x <= (Single)y, BoolResultConverter);
293  AddImplementation(op, typeof(double), (x, y) => (double)x <= (double)y, BoolResultConverter);
294  AddImplementation(op, typeof(BigInteger), (x, y) => (BigInteger)x <= (BigInteger)y, BoolResultConverter);
295 
296  op = ">=";
297  AddImplementation(op, typeof(sbyte), (x, y) => (sbyte)x >= (sbyte)y, BoolResultConverter);
298  AddImplementation(op, typeof(byte), (x, y) => (byte)x >= (byte)y, BoolResultConverter);
299  AddImplementation(op, typeof(Int16), (x, y) => (Int16)x >= (Int16)y, BoolResultConverter);
300  AddImplementation(op, typeof(UInt16), (x, y) => (UInt16)x >= (UInt16)y, BoolResultConverter);
301  AddImplementation(op, typeof(Int32), (x, y) => checked((Int32)x >= (Int32)y), BoolResultConverter);
302  AddImplementation(op, typeof(UInt32), (x, y) => checked((UInt32)x >= (UInt32)y), BoolResultConverter);
303  AddImplementation(op, typeof(Int64), (x, y) => checked((Int64)x >= (Int64)y), BoolResultConverter);
304  AddImplementation(op, typeof(UInt64), (x, y) => checked((UInt64)x >= (UInt64)y), BoolResultConverter);
305  AddImplementation(op, typeof(Single), (x, y) => (Single)x >= (Single)y, BoolResultConverter);
306  AddImplementation(op, typeof(double), (x, y) => (double)x >= (double)y, BoolResultConverter);
307  AddImplementation(op, typeof(BigInteger), (x, y) => (BigInteger)x >= (BigInteger)y, BoolResultConverter);
308 
309  op = "==";
310  AddImplementation(op, typeof(sbyte), (x, y) => (sbyte)x == (sbyte)y, BoolResultConverter);
311  AddImplementation(op, typeof(byte), (x, y) => (byte)x == (byte)y, BoolResultConverter);
312  AddImplementation(op, typeof(Int16), (x, y) => (Int16)x == (Int16)y, BoolResultConverter);
313  AddImplementation(op, typeof(UInt16), (x, y) => (UInt16)x == (UInt16)y, BoolResultConverter);
314  AddImplementation(op, typeof(Int32), (x, y) => checked((Int32)x == (Int32)y), BoolResultConverter);
315  AddImplementation(op, typeof(UInt32), (x, y) => checked((UInt32)x == (UInt32)y), BoolResultConverter);
316  AddImplementation(op, typeof(Int64), (x, y) => checked((Int64)x == (Int64)y), BoolResultConverter);
317  AddImplementation(op, typeof(UInt64), (x, y) => checked((UInt64)x == (UInt64)y), BoolResultConverter);
318  AddImplementation(op, typeof(Single), (x, y) => (Single)x == (Single)y, BoolResultConverter);
319  AddImplementation(op, typeof(double), (x, y) => (double)x == (double)y, BoolResultConverter);
320  AddImplementation(op, typeof(BigInteger), (x, y) => (BigInteger)x == (BigInteger)y, BoolResultConverter);
321 
322  op = "!=";
323  AddImplementation(op, typeof(sbyte), (x, y) => (sbyte)x != (sbyte)y, BoolResultConverter);
324  AddImplementation(op, typeof(byte), (x, y) => (byte)x != (byte)y, BoolResultConverter);
325  AddImplementation(op, typeof(Int16), (x, y) => (Int16)x != (Int16)y, BoolResultConverter);
326  AddImplementation(op, typeof(UInt16), (x, y) => (UInt16)x != (UInt16)y, BoolResultConverter);
327  AddImplementation(op, typeof(Int32), (x, y) => checked((Int32)x != (Int32)y), BoolResultConverter);
328  AddImplementation(op, typeof(UInt32), (x, y) => checked((UInt32)x != (UInt32)y), BoolResultConverter);
329  AddImplementation(op, typeof(Int64), (x, y) => checked((Int64)x != (Int64)y), BoolResultConverter);
330  AddImplementation(op, typeof(UInt64), (x, y) => checked((UInt64)x != (UInt64)y), BoolResultConverter);
331  AddImplementation(op, typeof(Single), (x, y) => (Single)x != (Single)y, BoolResultConverter);
332  AddImplementation(op, typeof(double), (x, y) => (double)x != (double)y, BoolResultConverter);
333  AddImplementation(op, typeof(BigInteger), (x, y) => (BigInteger)x != (BigInteger)y, BoolResultConverter);
334 
335  }//method
336 
337  protected void AddImplementation(string op, Type baseType, BinaryOperatorMethod baseMethod) {
338  AddImplementation(op, baseType, baseMethod, null);
339  }
340  protected void AddImplementation(string op, Type baseType, BinaryOperatorMethod baseMethod, TypeConverter resultConverter) {
341  var key = OperatorDispatchKey.CreateFromTypes(op, baseType, baseType);
342  var imp = new OperatorImplementation(key, baseType, baseMethod, null, null, resultConverter);
343  _baseOperatorImplementations.Add(key, imp);
344  }
345 
346  }//class
347 
348 
349 
350 }//namespace
static object ConvertAnyToComplex(object value)
void AddImplementation(string op, Type baseType, BinaryOperatorMethod baseMethod)
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
Definition: DirectXTexP.h:191
static object ConvertBigIntToComplex(object value)
static object ConvertAnyIntToBigInteger(object value)
delegate object BinaryOperatorMethod(object arg1, object arg2)
Microsoft.Scripting.Math.Complex64 Complex
Microsoft.Scripting.Math.BigInteger BigInteger
delegate object TypeConverter(object arg)
void AddImplementation(string op, Type baseType, BinaryOperatorMethod baseMethod, TypeConverter resultConverter)
static object ConvertAnyToString(object value)