/// <summary> /// From control flow perspective it "calls" the proc. /// </summary> internal static void SetProcCallRule( MetaObjectBuilder /*!*/ metaBuilder, Expression /*!*/ procExpression, // proc object Expression /*!*/ selfExpression, // self passed to the proc Expression callingMethodExpression, // RubyLambdaMethodInfo passed to the proc via BlockParam CallArguments /*!*/ args // user arguments passed to the proc ) { var bfcVariable = metaBuilder.GetTemporary(typeof(BlockParam), "#bfc"); var resultVariable = metaBuilder.GetTemporary(typeof(object), "#result"); metaBuilder.Result = AstFactory.Block( Ast.Assign(bfcVariable, (callingMethodExpression != null) ? Methods.CreateBfcForMethodProcCall.OpCall( AstUtils.Convert(procExpression, typeof(Proc)), callingMethodExpression ) : Methods.CreateBfcForProcCall.OpCall( AstUtils.Convert(procExpression, typeof(Proc)) ) ), Ast.Assign(resultVariable, AstFactory.YieldExpression( args.GetSimpleArgumentExpressions(), args.GetSplattedArgumentExpression(), args.GetRhsArgumentExpression(), bfcVariable, selfExpression )), Methods.MethodProcCall.OpCall(bfcVariable, resultVariable), resultVariable ); }
private static void BuildOverriddenInitializerCall(MetaObjectBuilder /*!*/ metaBuilder, CallArguments /*!*/ args, RubyMemberInfo /*!*/ initializer) { var instanceExpr = metaBuilder.Result; metaBuilder.Result = null; var instanceVariable = metaBuilder.GetTemporary(instanceExpr.Type, "#instance"); // We know an exact type of the new instance and that there is no singleton for that instance. // We also have the exact method we need to call ("initialize" is a RubyMethodInfo). // => no tests are necessary: args.SetTarget(instanceVariable, null); if (initializer is RubyMethodInfo) { initializer.BuildCall(metaBuilder, args, Symbols.Initialize); } else { // TODO: we need more refactoring of RubyMethodGroupInfo.BuildCall to be able to inline this: metaBuilder.Result = Ast.Dynamic( RubyCallAction.Make("initialize", new RubyCallSignature(args.Signature.ArgumentCount, args.Signature.Flags | RubyCallFlags.HasImplicitSelf) ), typeof(object), args.GetCallSiteArguments(instanceVariable) ); } if (!metaBuilder.Error) { // PropagateRetrySingleton(instance = new <type>(), instance.initialize(<args>)) metaBuilder.Result = Methods.PropagateRetrySingleton.OpCall( Ast.Assign(instanceVariable, instanceExpr), metaBuilder.Result ); RubyMethodInfo.ApplyBlockFlowHandlingInternal(metaBuilder, args); } }
/// <summary> /// From control flow perspective it "calls" the proc. /// </summary> internal static void BuildCall( MetaObjectBuilder /*!*/ metaBuilder, Expression /*!*/ procExpression, // proc object Expression /*!*/ selfExpression, // self passed to the proc CallArguments /*!*/ args // user arguments passed to the proc ) { var bfcVariable = metaBuilder.GetTemporary(typeof(BlockParam), "#bfc"); metaBuilder.Result = Ast.Block( Ast.Assign(bfcVariable, Methods.CreateBfcForProcCall.OpCall(AstUtils.Convert(procExpression, typeof(Proc)))), Methods.MethodProcCall.OpCall(bfcVariable, AstFactory.YieldExpression( args.RubyContext, args.GetSimpleArgumentExpressions(), args.GetSplattedArgumentExpression(), args.GetRhsArgumentExpression(), bfcVariable, selfExpression ) ) ); }