MakeTryGetTypeMember() статический приватный Метод

static private MakeTryGetTypeMember ( PythonContext PythonContext, PythonTypeSlot dts, Expression self, System.Linq.Expressions.ParameterExpression tmp ) : MethodCallExpression
PythonContext PythonContext
dts IronPython.Runtime.Types.PythonTypeSlot
self Expression
tmp System.Linq.Expressions.ParameterExpression
Результат MethodCallExpression
Пример #1
0
        private static DynamicMetaObject MakeGetItemIterable(DynamicMetaObject metaUserObject, PythonContext state, PythonTypeSlot pts, string method)
        {
            ParameterExpression tmp = Ast.Parameter(typeof(object), "getitemVal");

            return(new DynamicMetaObject(
                       Expression.Block(
                           new[] { tmp },
                           Expression.Call(
                               typeof(PythonOps).GetMethod(method),
                               Ast.Block(
                                   MetaPythonObject.MakeTryGetTypeMember(
                                       state,
                                       pts,
                                       tmp,
                                       metaUserObject.Expression,
                                       Ast.Call(
                                           typeof(DynamicHelpers).GetMethod("GetPythonType"),
                                           AstUtils.Convert(
                                               metaUserObject.Expression,
                                               typeof(object)
                                               )
                                           )
                                       ),
                                   tmp
                                   ),
                               AstUtils.Constant(
                                   CallSite <Func <CallSite, CodeContext, object, int, object> > .Create(
                                       new PythonInvokeBinder(state, new CallSignature(1))
                                       )
                                   )
                               )
                           ),
                       metaUserObject.Restrictions
                       ));
        }
Пример #2
0
        public static SlotOrFunction /*!*/ GetSlotOrFunction(PythonContext /*!*/ state, string op, params DynamicMetaObject[] types)
        {
            PythonTypeSlot slot;
            SlotOrFunction res;

            if (TryGetBinder(state, types, op, null, out res))
            {
                if (res != SlotOrFunction.Empty)
                {
                    return(res);
                }
            }
            else if (MetaUserObject.GetPythonType(types[0]).TryResolveSlot(state.SharedContext, op, out slot))
            {
                ParameterExpression tmp = Ast.Variable(typeof(object), "slotVal");

                Expression[] args = new Expression[types.Length - 1];
                for (int i = 1; i < types.Length; i++)
                {
                    args[i - 1] = types[i].Expression;
                }
                return(new SlotOrFunction(
                           new DynamicMetaObject(
                               Ast.Block(
                                   new ParameterExpression[] { tmp },
                                   MetaPythonObject.MakeTryGetTypeMember(
                                       state,
                                       slot,
                                       tmp,
                                       types[0].Expression,
                                       Ast.Call(
                                           typeof(DynamicHelpers).GetMethod("GetPythonType"),
                                           types[0].Expression
                                           )
                                       ),
                                   DynamicExpression.Dynamic(
                                       state.Invoke(
                                           new CallSignature(args.Length)
                                           ),
                                       typeof(object),
                                       ArrayUtils.Insert <Expression>(
                                           AstUtils.Constant(state.SharedContext),
                                           tmp,
                                           args
                                           )
                                       )
                                   ),
                               BindingRestrictions.Combine(types).Merge(BindingRestrictionsHelpers.GetRuntimeTypeRestriction(types[0].Expression, types[0].GetLimitType()))
                               ),
                           slot
                           ));
            }

            return(SlotOrFunction.Empty);
        }
Пример #3
0
        internal static DynamicMetaObject ConvertToIEnumerator(DynamicMetaObjectBinder /*!*/ conversion, DynamicMetaObject /*!*/ metaUserObject)
        {
            PythonType     pt      = MetaPythonObject.GetPythonType(metaUserObject);
            PythonContext  state   = PythonContext.GetPythonContext(conversion);
            CodeContext    context = state.SharedContext;
            PythonTypeSlot pts;


            if (pt.TryResolveSlot(context, "__iter__", out pts))
            {
                ParameterExpression tmp = Ast.Parameter(typeof(object), "iterVal");

                return(new DynamicMetaObject(
                           Expression.Block(
                               new[] { tmp },
                               Expression.Call(
                                   typeof(PythonOps).GetMethod("CreatePythonEnumerator"),
                                   Ast.Block(
                                       MetaPythonObject.MakeTryGetTypeMember(
                                           state,
                                           pts,
                                           metaUserObject.Expression,
                                           tmp
                                           ),
                                       Ast.Dynamic(
                                           new PythonInvokeBinder(
                                               state,
                                               new CallSignature(0)
                                               ),
                                           typeof(object),
                                           AstUtils.Constant(context),
                                           tmp
                                           )
                                       )
                                   )
                               ),
                           metaUserObject.Restrictions
                           ));
            }
            else if (pt.TryResolveSlot(context, "__getitem__", out pts))
            {
                return(MakeGetItemIterable(metaUserObject, state, pts, "CreateItemEnumerator"));
            }

            return(null);
        }