14 using System.Collections.Generic;
18 using Irony.Interpreter.Ast;
20 namespace Irony.Interpreter {
22 using Complex = Microsoft.Scripting.Math.Complex64;
84 public virtual bool IsTrue(
object value) {
85 return value != NullObject;
88 public virtual object NullObject {
93 foreach (var entry
in _baseOperatorImplementations)
94 table.Add(entry.Key, entry.Value);
112 #region Operator implementations
117 if (baseType == null)
return null;
121 var baseKey = OperatorDispatchKey.CreateFromTypes(forKey.OpSymbol, baseType, baseType);
123 if (! _baseOperatorImplementations.TryGetValue(baseKey, out baseImpl))
125 var impl =
new OperatorImplementation(forKey, baseType, baseImpl.BaseMethod, arg1Converter, arg2Converter, baseImpl.ResultConverter);
126 implementations[forKey] = impl;
140 var allowSwitchToSigned = op ==
"-";
141 var isBoolOp = op ==
"&" || op ==
"|";
145 if (isBoolOp || IsOneOf(t, type1, type2))
return t;
148 if (IsOneOf(t, type1, type2))
return t;
150 if (IsOneOf(t, type1, type2))
return t;
152 if (IsOneOf(t, type1, type2))
return t;
154 if (IsOneOf(t, type1, type2))
return t;
156 if (IsOneOf(t, type1, type2))
return t;
159 if (IsOneOf(t, type1, type2))
return t;
161 if (IsOneOf(t, type1, type2))
163 return allowSwitchToSigned ? typeof(Int64) : t;
166 if (IsOneOf(t, type1, type2))
return t;
168 if (IsOneOf(t, type1, type2))
170 return allowSwitchToSigned ? typeof(Int32) : t;
173 if (IsOneOf(t, type1, type2))
return t;
175 if (IsOneOf(t, type1, type2))
177 return allowSwitchToSigned ? typeof(Int16) : t;
180 if (IsOneOf(t, type1, type2))
return t;
182 if (IsOneOf(t, type1, type2))
184 return allowSwitchToSigned ? typeof(sbyte) : t;
189 private static bool IsOneOf(Type type, Type type1, Type type2) {
190 return type == type1 || type == type2;
209 return typeof(Int64);
214 return typeof(
double);
225 if (fromType == toType)
return null;
226 var result = TypeConverters.Find(fromType, toType);
227 if (result != null)
return result;
236 if (ConsoleWrite != null) {
238 ConsoleWrite(
this, args);
244 public static void Check(
bool condition,
string message, params
object[] args) {
245 if (condition)
return;
247 message = string.Format(message, args);
readonly LanguageData Language
The struct is used as a key for the dictionary of operator implementations. Contains types of argumen...
bool IsAssigned(object value)
A strongly-typed resource class, for looking up localized strings, etc.
OperatorImplementationTable CreateOperatorImplementationsTable()
virtual OperatorImplementation AddOperatorImplementation(OperatorImplementationTable implementations, OperatorDispatchKey forKey)
override string ToString()
void OnConsoleWrite(EvaluationContext context, string text)
EventHandler< ConsoleWriteEventArgs > ConsoleWrite
static string LabelUnassigned
Looks up a localized string similar to (unassigned).
The DynamicCallDispatcher class is responsible for fast dispatching to the implementation based on ar...
static string ErrOpNotDefinedForTypes
Looks up a localized string similar to Operator '{0}' is not defined for types {1} and {2}...
static string ErrCannotConvertValue
Looks up a localized string similar to Cannot convert value from type {0} to type {1}...
static void Check(bool condition, string message, params object[] args)
virtual Type GetBaseTypeForExpression(string op, Type type1, Type type2)
Returns the type to which arguments should be converted to perform the operation for a given operator...
virtual bool IsTrue(object value)
virtual TypeConverter GetConverter(Type fromType, Type toType)
Microsoft.Scripting.Math.Complex64 Complex
ConsoleWriteEventArgs(string text)
LanguageRuntime(LanguageData language)
Microsoft.Scripting.Math.BigInteger BigInteger
virtual Type GetUpType(Type type)
Returns the "up-type" to use in operation instead of the type that caused overflow.
Unassigned(string toString)
virtual bool HandleException(Exception ex, DynamicCallDispatcher dispatcher, OperatorImplementation failedTarget, EvaluationContext context)