public static Expression/*!*/ Invoke(Expression codeContext, BinderState/*!*/ binder, Type/*!*/ resultType, CallSignature signature, params Expression/*!*/[]/*!*/ args) { return Ast.Dynamic( binder.Invoke( signature ), resultType, ArrayUtils.Insert(codeContext, args) ); }
private static void MakeSlotCallWorker(BinderState/*!*/ state, PythonTypeSlot/*!*/ slotTarget, Expression/*!*/ self, ConditionalBuilder/*!*/ bodyBuilder, params Expression/*!*/[]/*!*/ args) { // Generate: // // SlotTryGetValue(context, slot, selfType, out callable) && (tmp=callable(args)) != NotImplemented) ? // tmp : // RestOfOperation // ParameterExpression callable = Ast.Variable(typeof(object), "slot"); ParameterExpression tmp = Ast.Variable(typeof(object), "slot"); bodyBuilder.AddCondition( Ast.AndAlso( Ast.Call( typeof(PythonOps).GetMethod("SlotTryGetValue"), AstUtils.Constant(state.Context), AstUtils.Convert(Utils.WeakConstant(slotTarget), typeof(PythonTypeSlot)), AstUtils.Convert(self, typeof(object)), Ast.Call( typeof(DynamicHelpers).GetMethod("GetPythonType"), AstUtils.Convert(self, typeof(object)) ), callable ), Ast.NotEqual( Ast.Assign( tmp, Ast.Dynamic( state.Invoke( new CallSignature(args.Length) ), typeof(object), ArrayUtils.Insert(AstUtils.Constant(state.Context), (Expression)callable, args) ) ), Ast.Property(null, typeof(PythonOps).GetProperty("NotImplemented")) ) ), tmp ); bodyBuilder.AddVariable(callable); bodyBuilder.AddVariable(tmp); }
/// <summary> /// Creates a new InvokeBinder which will call with positional and keyword splatting. /// /// The signature of the target site should be object(function), object[], dictionary, retType /// </summary> public static PythonInvokeBinder/*!*/ InvokeKeywords(BinderState/*!*/ state) { return state.Invoke( new CallSignature(new Argument(ArgumentType.List), new Argument(ArgumentType.Dictionary)) ); }
/// <summary> /// Creates a new InvokeBinder which will call with positional splatting. /// /// The signature of the target site should be object(function), object[], retType /// </summary> /// <param name="state"></param> /// <returns></returns> public static PythonInvokeBinder/*!*/ InvokeSplat(BinderState/*!*/ state) { return state.Invoke( new CallSignature(new Argument(ArgumentType.List)) ); }
public static DynamicMetaObjectBinder/*!*/ InvokeAndConvert(BinderState/*!*/ state, int argCount, Type retType) { // +2 for the target object and CodeContext which InvokeBinder recevies ParameterMappingInfo[] args = new ParameterMappingInfo[argCount + 2]; for (int i = 0; i < argCount + 2; i++) { args[i] = ParameterMappingInfo.Parameter(i); } return new ComboBinder( new BinderMappingInfo( state.Invoke( new CallSignature(argCount) ), args ), new BinderMappingInfo( state.Convert(retType, ConversionResultKind.ExplicitCast), ParameterMappingInfo.Action(0) ) ); }
public static SlotOrFunction/*!*/ GetSlotOrFunction(BinderState/*!*/ state, SymbolId op, params DynamicMetaObject[] types) { PythonTypeSlot slot; SlotOrFunction res; if (TryGetBinder(state, types, op, SymbolId.Empty, out res)) { if (res != SlotOrFunction.Empty) { return res; } } else if (MetaUserObject.GetPythonType(types[0]).TryResolveSlot(state.Context, 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 ) ), Ast.Dynamic( state.Invoke( new CallSignature(args.Length) ), typeof(object), ArrayUtils.Insert<Expression>( AstUtils.Constant(state.Context), tmp, args ) ) ), BindingRestrictions.Combine(types).Merge(BindingRestrictionsHelpers.GetRuntimeTypeRestriction(types[0].Expression, types[0].GetLimitType())) ) ); } return SlotOrFunction.Empty; }