public sealed override T BindDelegate <T>(CallSite <T> site, object[] args) { object firstArg = args[0]; ArgumentArray argArray = firstArg as ArgumentArray; Type delegateType = typeof(T); T result; if (argArray != null) { firstArg = argArray.GetArgument(0); } else { object precompiled = BindPrecompiled(delegateType, args); if (precompiled != null) { result = (T)precompiled; CacheTarget(result); return(result); } } RubyContext context = _context ?? ((Signature.HasScope) ? ((RubyScope)firstArg).RubyContext : (RubyContext)firstArg); if (context.Options.NoAdaptiveCompilation) { return(null); } #if DEBUG if (RubyOptions.ShowRules) { var sb = new StringBuilder(); for (int i = 1; i < args.Length; i++) { sb.Append(RubyUtils.ObjectToMutableString(context, args[i])); sb.Append(", "); } Utils.Log(String.Format( "{0}: {1}; {2} <: {3}", this, sb, args.Length > 1 ? context.GetImmediateClassOf(args[1]).DebugName : null, args.Length > 1 ? context.GetImmediateClassOf(args[1]).SuperClass.DebugName : null ), "BIND"); } #endif result = this.LightBind <T>(args, context.Options.CompilationThreshold); CacheTarget(result); return(result); }
// Ruby binders: internal CallArguments(RubyContext context, DynamicMetaObject /*!*/ scopeOrContextOrTargetOrArgArray, DynamicMetaObject /*!*/[] /*!*/ args, RubyCallSignature signature) { Assert.NotNull(scopeOrContextOrTargetOrArgArray); Assert.NotNullItems(args); ArgumentArray argArray = scopeOrContextOrTargetOrArgArray.Value as ArgumentArray; if (argArray != null) { Debug.Assert(args.Length == 0 && argArray.Count >= 1); // build meta-objects for arguments wrapped in the array: args = new DynamicMetaObject[argArray.Count - 1]; for (int i = 0; i < args.Length; i++) { args[i] = argArray.GetMetaObject(scopeOrContextOrTargetOrArgArray.Expression, 1 + i); } scopeOrContextOrTargetOrArgArray = argArray.GetMetaObject(scopeOrContextOrTargetOrArgArray.Expression, 0); } Debug.Assert(signature.HasScope == scopeOrContextOrTargetOrArgArray.Value is RubyScope); Debug.Assert((context == null && !signature.HasScope) == scopeOrContextOrTargetOrArgArray.Value is RubyContext); if (context != null) { // bound site: _context = new DynamicMetaObject(AstUtils.Constant(context), BindingRestrictions.Empty, context); if (signature.HasScope) { _scope = scopeOrContextOrTargetOrArgArray; _hasScopeOrContextArg = true; } else { _target = scopeOrContextOrTargetOrArgArray; } } else if (signature.HasScope) { // unbound site with scope: _context = new DynamicMetaObject( Methods.GetContextFromScope.OpCall(scopeOrContextOrTargetOrArgArray.Expression), BindingRestrictions.Empty, ((RubyScope)scopeOrContextOrTargetOrArgArray.Value).RubyContext ); _scope = scopeOrContextOrTargetOrArgArray; _hasScopeOrContextArg = true; _target = null; } else { // unbound site with context: _context = scopeOrContextOrTargetOrArgArray; _hasScopeOrContextArg = true; _target = null; } Debug.Assert(_target != null || args.Length > 0); _args = args; _copyArgsOnWrite = true; _signature = signature; Debug.Assert(!signature.HasSplattedArgument || GetSplattedArgument() != null); }
// [CLSCompliant(false)] public static object GetArg(ArgumentArray array, int index) { return(array._arguments[array._first + index]); }