A Dynamic Call Site base class. This type is used as a parameter type to the dynamic site targets. The first parameter of the delegate (T) below must be of this type.
Beispiel #1
0
        public RubyRepresenter(RubyContext/*!*/ context, Serializer/*!*/ serializer, YamlOptions/*!*/ opts)
            : base(serializer, opts) {
            _context = context;
            _objectToYamlMethod = context.GetClass(typeof(object)).ResolveMethod("to_yaml", VisibilityContext.AllVisible).Info;

             _TagUri =
                CallSite<Func<CallSite, object, object>>.Create(
                RubyCallAction.Make(context, "taguri", RubyCallSignature.WithImplicitSelf(0))
            );

            _ToYamlStyle =
                CallSite<Func<CallSite, object, object>>.Create(
                RubyCallAction.Make(context, "to_yaml_style", RubyCallSignature.WithImplicitSelf(0))
            );

            _ToYamlNode =
                CallSite<Func<CallSite, object, RubyRepresenter, object>>.Create(
                RubyCallAction.Make(context, "to_yaml_node", RubyCallSignature.WithImplicitSelf(1))
            );

            _ToYaml =
                CallSite<Func<CallSite, object, RubyRepresenter, object>>.Create(
                RubyCallAction.Make(context, "to_yaml", RubyCallSignature.WithImplicitSelf(0))
            );

            _ToYamlProperties = 
                CallSite<Func<CallSite, object, object>>.Create(
                RubyCallAction.Make(context, "to_yaml_properties", RubyCallSignature.WithImplicitSelf(0))
            );
        }
 public DynamicInstructionN(Type delegateType, CallSite site) {
     var methodInfo = delegateType.GetMethod("Invoke");
     _target = ReflectedCaller.Create(methodInfo);
     _targetField = site.GetType().GetField("Target");
     _site = site;
     _argCount = methodInfo.GetParameters().Length;
 }
Beispiel #3
0
        public IOWrapper(RubyContext/*!*/ context, object io, bool canRead, bool canWrite, bool canSeek, bool canFlush, bool canBeClosed, int bufferSize) {
            Assert.NotNull(context);

            _writeSite = CallSite<Func<CallSite, object, object, object>>.Create(
                RubyCallAction.Make(context, "write", RubyCallSignature.WithImplicitSelf(1))
            );
            _readSite = CallSite<Func<CallSite, object, object, object>>.Create(
                RubyCallAction.Make(context, "read", RubyCallSignature.WithImplicitSelf(1))
            );
            _seekSite = CallSite<Func<CallSite, object, object, object, object>>.Create(
                RubyCallAction.Make(context, "seek", RubyCallSignature.WithImplicitSelf(2))
            );
            _tellSite = CallSite<Func<CallSite, object, object>>.Create(
                RubyCallAction.Make(context, "tell", RubyCallSignature.WithImplicitSelf(0))
            );

            _obj = io;

            _canRead = canRead;
            _canWrite = canWrite;
            _canSeek = canSeek;
            _canFlush = canFlush;
            _canBeClosed = canBeClosed;
            _buffer = new byte[bufferSize];
            _writePos = 0;
            _readPos = 0;
            _readLen = 0;
        }
        public DynamicInstructionN(Type delegateType, CallSite site) {
            var methodInfo = delegateType.GetMethod("Invoke");
            var parameters = methodInfo.GetParameters();

            _target = CallInstruction.Create(methodInfo, parameters);
            _targetField = site.GetType().GetField("Target");
            _site = site;
            _argCount = parameters.Length;
        }
Beispiel #5
0
 public DynamicInstructionN(Type delegateType, CallSite site)
 {
     MethodInfo method = delegateType.GetMethod("Invoke");
     ParameterInfo[] parameters = method.GetParameters();
     this._target = CallInstruction.Create(method, parameters);
     this._site = site;
     this._argumentCount = parameters.Length - 1;
     this._targetDelegate = site.GetType().GetField("Target").GetValue(site);
 }
Beispiel #6
0
        public DynamicInstructionN(Type delegateType, CallSite site) {
            var methodInfo = delegateType.GetMethod("Invoke");
            var parameters = methodInfo.GetParameters();

            // <Delegate>.Invoke is ok to target by a delegate in partial trust (SecurityException is not thrown):
            _targetInvocationInstruction = CallInstruction.Create(methodInfo, parameters);
            _site = site;
            _argumentCount = parameters.Length - 1;
            _targetDelegate = site.GetType().GetInheritedFields("Target").First().GetValue(site);
        }
Beispiel #7
0
        public RubyConstructor(RubyGlobalScope/*!*/ scope, NodeProvider/*!*/ nodeProvider)
            : base(nodeProvider, scope) {
            
            _newSite = CallSite<Func<CallSite, RubyModule, object, object, object, object>>.Create(
                RubyCallAction.Make(scope.Context, "new", RubyCallSignature.WithImplicitSelf(3))
            ); 

            _yamlInitializeSite = CallSite<Func<CallSite, object, object, Hash, object>>.Create(
                RubyCallAction.Make(scope.Context, "yaml_initialize", RubyCallSignature.WithImplicitSelf(3))
            );
        }
Beispiel #8
0
        internal object Invoke(object[] args) {
            Debug.Assert(args != null);

            // If it is a delegate, just let DynamicInvoke do the binding.
            var d = _callable as Delegate;
            if (d != null) {
                return d.DynamicInvoke(args);
            }

            // Otherwise, create a CallSite and invoke it.
            if (_site == null) {
                _site = CallSite<Func<CallSite, object, object[], object>>.Create(SplatInvokeBinder.Instance);
            }

            return _site.Target(_site, _callable, args);
        }
		public static object LessThanObjUInt (CallSite site, object a, uint b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			if (a is uint)
			{
				return (uint)a < b;
			}
			if ((a == null) || (a == PlayScript.Undefined._undefined))
			{
				return false;
			}
			return Convert.ToDouble(a) < (double)b;
		}
		public static object MulDoubleObj (CallSite site, double a, object b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			if ((b == null) || (b == PlayScript.Undefined._undefined))
			{
				return (double)0;
			}
			return a * Convert.ToDouble(b);
		}
Beispiel #11
0
 public static T[] GetRules <T>(CallSite <T> site)
 {
     throw new NotImplementedException();
 }
		public static object XorObjObj (CallSite site, object a, object b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			if (a is int) {
				return XorIntObj (site, (int)a, b);
			} else if (a is double) {
				return XorDoubleObj (site, (double)a, b);
			} else if (a is float) {
				return XorDoubleObj (site, (float)a, b);
			} else if (a is bool) {
				return XorBoolObj (site, (bool)a, b);
			} else if (a is uint) {
				return XorUIntObj (site, (uint)a, b);
			} else {
				ThrowOnInvalidOp (b, XOR);
				return null;
			}
		}
		public static object AddObjString (CallSite site, object a, string b)
		{
			return a.ToString() + b;
		}
Beispiel #14
0
 public static bool GetMatch(CallSite site)
 {
     throw new NotImplementedException();
 }
		public static object XorObjBool (CallSite site, object a, bool b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			return Dynamic.CastObjectToBool(a) ^ b;
		}
Beispiel #16
0
 public static RuleCache <T> GetRuleCache <T>(CallSite <T> site) where T : class
 {
     return(site.Binder.GetRuleCache <T>());
 }
Beispiel #17
0
 public static T[] GetRules <T>(CallSite <T> site) where T : class
 {
     return(site.Rules);
 }
Beispiel #18
0
 public static T Bind <T>(CallSiteBinder binder, CallSite <T> site, object[] args) where T : class
 {
     return(binder.BindCore(site, args));
 }
Beispiel #19
0
 public static bool GetMatch(CallSite site)
 {
     return(site.Match);
 }
Beispiel #20
0
 /// <summary>
 ///     Provides low-level runtime binding support.  Classes can override this and provide a direct
 ///     delegate for the implementation of rule.  This can enable saving rules to disk, having
 ///     specialized rules available at runtime, or providing a different caching policy.
 /// </summary>
 /// <typeparam name="T">The target type of the CallSite.</typeparam>
 /// <param name="site">The CallSite the bind is being performed for.</param>
 /// <param name="args">The arguments for the binder.</param>
 /// <returns>A new delegate which replaces the CallSite Target.</returns>
 public virtual T BindDelegate <T>(CallSite <T> site, object[] args) where T : class
 {
     No.Op(site);
     No.Op(args);
     return(null);
 }
Beispiel #21
0
 public static T Bind <T>(CallSiteBinder binder, CallSite <T> site, object[] args)
 {
     throw new NotImplementedException();
 }
Beispiel #22
0
 public static RuleCache <T> GetRuleCache <T>(CallSite <T> site)
 {
     throw new NotImplementedException();
 }
Beispiel #23
0
 public static void AddRule <T>(CallSite <T> site, T rule)
 {
     throw new NotImplementedException();
 }
Beispiel #24
0
 public static void AddRule <T>(CallSite <T> site, T rule) where T : class
 {
     site.AddRule(rule);
 }
Beispiel #25
0
 public FinalizerInvoker(CallSite<Func<CallSite, object, object, object>>/*!*/ callSite, object finalizer)
 {
     Assert.NotNull(callSite);
     _callSite = callSite;
     _finalizer = finalizer;
 }
Beispiel #26
0
 public static void ClearMatch(CallSite site)
 {
     site.Match = true;
 }
		public static object XorUIntObj (CallSite site, uint a, object b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			if ((b == null) || (b == PlayScript.Undefined._undefined))
			{
				return a;
			}
			return a ^ Convert.ToUInt32(b);
		}
Beispiel #28
0
 public extern T BindDelegate <T>(CallSite <T> site, object[] args) where T : class;
		public static object XorBoolObj (CallSite site, bool a, object b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			return a ^ Dynamic.CastObjectToBool(b);
		}
Beispiel #30
0
 public T BindDelegate <T>(CallSite <T> site, object[] args) where T : class
 {
     return(null);
 }
		public static object AddStringObj (CallSite site, string a, object b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			return a + b;
		}
		public static object ModDoubleObj (CallSite site, double a, object b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			if ((b == null) || (b == PlayScript.Undefined._undefined))
			{
				return Double.NaN;		// Should probably also use Positive and Negative Infinity
			}
			return a % Convert.ToDouble(b);
		}
		public static object AddObjObj (CallSite site, object a, object b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			if (a is int) {
				return AddIntObj (site, (int)a, b);
			} else if (a is double) {
				return AddDoubleObj (site, (double)a, b);
			} else if (a is float) {
				return AddDoubleObj (site, (float)a, b);
			} else if (a is String) {
				return AddStringObj (site, (string)a, b);
			} else if (a is uint) {
				return AddUIntObj (site, (uint)a, b);
			} else {
				ThrowOnInvalidOp (a, ADD);
				return null;
			}
		}
		public static object ShiftRightDoubleObj (CallSite site, double a, object b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			if ((b == null) || (b == PlayScript.Undefined._undefined))
			{
				return a;
			}
			return (int)a >> Convert.ToInt32(b);
		}
		public static object ModObjInt (CallSite site, object a, int b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			if (a is int)
			{
				return (int)a % b;
			}
			if ((a == null) || (a == PlayScript.Undefined._undefined))
			{
				return (int)0;
			}
			return Convert.ToDouble(a) % (double)b;
		}
Beispiel #36
0
 public static void UpdateRules <T>(CallSite <T> @this, int matched)
 {
     throw new NotImplementedException();
 }
		public static object ShiftRightObjDouble (CallSite site, object a, double b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			if ((a == null) || (a == PlayScript.Undefined._undefined))
			{
				return (int)0;
			}
			return Convert.ToInt32(a) >> (int)b;
		}
 public virtual T BindDelegate <T>(CallSite <T> site, object[] args) where T : class
 {
     return(default(T));
 }
		public static object ShiftRightObjObj (CallSite site, object a, object b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			if (a is int) {
				return ShiftRightIntObj (site, (int)a, b);
			} else if (a is uint) {
				return ShiftRightUIntObj (site, (uint)a, b);
			} else if (a is double) {
				return ShiftRightDoubleObj (site, (double)a, b);
			} else if (a is float) {
				return ShiftRightDoubleObj (site, (float)a, b);
			} else {
				ThrowOnInvalidOp (a, SHR);
				return null;
			}
		}
Beispiel #40
0
 public defaultdict(CodeContext/*!*/ context) {
     _missingSite = CallSite<Func<CallSite, CodeContext, object, object>>.Create(
         new PythonInvokeBinder(
             PythonContext.GetContext(context),
             new CallSignature(0)
         )
     );
 }
		public static object LessThanUIntObj (CallSite site, uint a, object b)
		{
#if BINDERS_RUNTIME_STATS
			Stats.Increment(StatsCounter.BinaryOperationBinderInvoked);
#endif
			if (b is uint)
			{
				return a < (uint)b;
			}
			if ((b == null) || (b == PlayScript.Undefined._undefined))
			{
				return false;
			}
			return (double)a < Convert.ToDouble(b);
		}
Beispiel #42
0
 public static void ClearMatch(CallSite site)
 {
     throw new NotImplementedException();
 }
 private void AssignSiteDelegates(CallSite<Func<CallSite, object, int>> hashSite, CallSite<Func<CallSite, object, object, bool>> equalSite) {
     _hashFunc = (o) => hashSite.Target(hashSite, o);
     _eqFunc = (o1, o2) => equalSite.Target(equalSite, o1, o2);
 }
Beispiel #44
0
 /// <summary>
 /// Converts an object to string using to_path-to_str protocol.
 /// Protocol:
 /// ? to_path => to_path() and to_str conversion on the result
 /// ? to_str => to_str()
 /// </summary>
 public static MutableString/*!*/ CastToPath(CallSite<Func<CallSite, object, MutableString>>/*!*/ toPath, object obj) {
     MutableString result = toPath.Target(toPath, obj);
     if (result == null) {
         throw RubyExceptions.CreateTypeConversionError("nil", "String");
     }
     return result;
 }
 internal DynamicSplatInstruction(int argumentCount, CallSite<Func<CallSite, ArgumentArray, object>> site) {
     _site = site;
     _argumentCount = argumentCount;
 }
 private Dictionary <IEnumerator, IDisposable> GetListEnumerator(SRC.CallSite site, Object value)
 {
     return(new Dictionary <IEnumerator, IDisposable>());
 }
Beispiel #47
0
 internal static int IndexOf(CallSite<Func<CallSite, object, object, object>>/*!*/ equalitySite, IList/*!*/ self, object item) {
     for (int i = 0; i < self.Count; i++) {
         if (Protocols.IsTrue(equalitySite.Target(equalitySite, item, self[i]))) {
             return i;
         }
     }
     return -1;
 }
Beispiel #48
0
 public static CallSite <T> CreateMatchmaker <T>(CallSite <T> site)
 {
     throw new NotImplementedException();
 }
Beispiel #49
0
 /// <summary>
 /// Protocol for determining value equality in Ruby (uses IsTrue protocol on result of == call)
 /// </summary>
 public static bool IsEqual(CallSite<Func<CallSite, object, object, object>>/*!*/ site, object lhs, object rhs) {
     // check reference equality first:
     if (lhs == rhs) {
         return true;
     }
     return IsTrue(site.Target(site, lhs, rhs));
 }
 private KeyValuePair <IEnumerator, IDisposable> GetListEnumerator(SRC.CallSite site, Object value)
 {
     return(new KeyValuePair <IEnumerator, IDisposable>(new List <Object> {
         value
     }.GetEnumerator(), null));
 }