Exemplo n.º 1
0
        /// <summary>
        /// Creates a lambda Proc that has the same target, context and self object as this block.
        /// Doesn't preserve the class of the Proc.
        /// </summary>
        public Proc /*!*/ ToLambda(RubyLambdaMethodInfo method)
        {
            Proc result = new Proc(this);

            result.Kind    = ProcKind.Lambda;
            result._method = method;
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns
        /// -1 if there is no method or block-method scope,
        /// 0 if the target scope is a method scope,
        /// id > 0 of the target lambda for block-method scopes.
        /// </summary>
        internal int GetSuperCallTarget(out RubyModule declaringModule, out string /*!*/ methodName, out RubyScope targetScope)
        {
            RubyScope scope = this;

            while (true)
            {
                Debug.Assert(scope != null);

                switch (scope.Kind)
                {
                case ScopeKind.Method:
                    RubyMethodScope methodScope = (RubyMethodScope)scope;
                    // See RubyOps.DefineMethod for why we can use Method here.
                    declaringModule = methodScope.DeclaringModule;
                    methodName      = methodScope.DefinitionName;
                    targetScope     = scope;
                    return(0);

                case ScopeKind.BlockMethod:
                    RubyLambdaMethodInfo info = ((RubyBlockScope)scope).BlockFlowControl.Proc.Method;
                    Debug.Assert(info != null);
                    declaringModule = info.DeclaringModule;
                    methodName      = info.DefinitionName;
                    targetScope     = scope;
                    return(info.Id);

                case ScopeKind.TopLevel:
                    declaringModule = null;
                    methodName      = null;
                    targetScope     = null;
                    return(-1);
                }

                scope = scope.Parent;
            }
        }
Exemplo n.º 3
0
 public static BlockParam /*!*/ CreateBfcForMethodProcCall(Proc /*!*/ proc, RubyLambdaMethodInfo /*!*/ method)
 {
     Assert.NotNull(proc, method);
     return(new BlockParam(proc, BlockCallerKind.Call, false, method.DeclaringModule, method.DefinitionName));
 }