Esempio n. 1
0
 /// <summary>
 /// Gets the call instruction prototype for a particular callee.
 /// </summary>
 /// <param name="callee">The method to call.</param>
 /// <param name="lookup">The method lookup strategy for the call.</param>
 /// <returns>A call instruction prototype.</returns>
 public static CallPrototype Create(IMethod callee, MethodLookup lookup)
 {
     ContractHelpers.Assert(
         lookup == MethodLookup.Static || !callee.IsStatic,
         "A static callee method cannot be resolved via virtual lookup.");
     return(instanceCache.Intern(new CallPrototype(callee, lookup)));
 }
 /// <summary>
 /// Creates an instruction that calls a particular method.
 /// </summary>
 /// <param name="callee">The method to call.</param>
 /// <param name="lookup">
 /// The method implementation lookup technique to use for calling the method.
 /// </param>
 /// <param name="arguments">
 /// The extended argument list: a list of arguments prefixed with a 'this'
 /// argument, if applicable.
 /// </param>
 /// <returns>
 /// A call instruction.
 /// </returns>
 public static Instruction CreateCall(
     IMethod callee,
     MethodLookup lookup,
     IReadOnlyList <ValueTag> arguments)
 {
     return(CallPrototype.Create(callee, lookup).Instantiate(arguments));
 }
 /// <summary>
 /// Creates a new-delegate instruction.
 /// </summary>
 /// <param name="delegateType">
 /// The type of the resulting delegate or function pointer.
 /// </param>
 /// <param name="callee">
 /// The method called by the resulting delegate or function
 /// pointer.
 /// </param>
 /// <param name="thisArgument">
 /// The 'this' argument, if any. A <c>null</c> value means that
 /// there is no 'this' argument.
 /// </param>
 /// <param name="lookup">
 /// The method implementation lookup technique to use.
 /// </param>
 /// <returns>
 /// A new-delegate instruction.
 /// </returns>
 public static Instruction CreateNewDelegate(
     IType delegateType,
     IMethod callee,
     ValueTag thisArgument,
     MethodLookup lookup)
 {
     return(NewDelegatePrototype
            .Create(delegateType, callee, thisArgument != null, lookup)
            .Instantiate(thisArgument));
 }
Esempio n. 4
0
        public static void Start(string server, int port = 443)
        {
            var proxyType = typeof(InfoMethod);
            var methods   = new MethodLookup(proxyType);
            var piggProxy = new PiggInfoProxy();

            piggProxy.Methods        = methods;
            piggProxy.WebSocketProxy = new TransparentProxy(
                piggProxy.SendHandle, piggProxy.RecvHandle);
            piggProxy.WebSocketProxy.Start(port, server);
        }
 private NewDelegatePrototype(
     IType delegateType,
     IMethod callee,
     bool hasThisArgument,
     MethodLookup lookup)
 {
     this.delegateType    = delegateType;
     this.Callee          = callee;
     this.HasThisArgument = hasThisArgument;
     this.Lookup          = lookup;
 }
Esempio n. 6
0
        private static ExtensionRegistry GetOrCreateRegistry(Type target, MethodLookup lookup)
        {
            switch (lookup)
            {
            case MethodLookup.Instance:
                return(target.GetUserData().GetOrSet(InstanceMethods, () => new ExtensionRegistry()));

            case MethodLookup.Static:
                return(target.GetUserData().GetOrSet(StaticMethods, () => new ExtensionRegistry()));

            default:
                return(null);
            }
        }
Esempio n. 7
0
        internal static IEnumerable <MethodInfo> GetMethods(Type target, MethodLookup lookup)
        {
            switch (lookup)
            {
            case MethodLookup.Static:
                return(GetStaticMethods(target));

            case MethodLookup.Instance:
                return(GetInstanceMethods(target));

            default:
                return(Enumerable.Empty <MethodInfo>());
            }
        }
Esempio n. 8
0
        public TdlMethod AddMethod(string identifier)
        {
            if (MethodIdentifierLookup.ContainsKey(identifier))
            {
                return(null);
            }
            TdlMethod method = new TdlMethod(identifier, this);

            _Methods.Add(method);
            MethodLookup.Add(method.FieldId, method);
            MethodIdentifierLookup.Add(identifier, method);
            AddField(method);
            return(method);
        }
Esempio n. 9
0
        internal static void SetMethodAttributes(RubyModule /*!*/ module, string /*!*/[] /*!*/ methodNames, RubyMethodAttributes attributes)
        {
            var context = module.Context;

            bool isModuleFunction   = (attributes & RubyMethodAttributes.ModuleFunction) == RubyMethodAttributes.ModuleFunction;
            var  instanceVisibility = isModuleFunction ? RubyMethodVisibility.Private :
                                      (RubyMethodVisibility)(attributes & RubyMethodAttributes.VisibilityMask);

            foreach (string methodName in methodNames)
            {
                RubyMemberInfo method;

                // we need to define new methods one by one since the method_added events can define a new method that might be used here:
                using (context.ClassHierarchyLocker()) {
                    MethodLookup options = MethodLookup.FallbackToObject;
                    if (!isModuleFunction)
                    {
                        options |= MethodLookup.ReturnForwarder;
                    }

                    method = module.ResolveMethodNoLock(methodName, VisibilityContext.AllVisible, options).Info;
                    if (method == null)
                    {
                        throw RubyExceptions.CreateUndefinedMethodError(module, methodName);
                    }

                    // MRI only adds method to the target module if visibility differs:
                    if (method.Visibility != instanceVisibility)
                    {
                        module.SetVisibilityNoEventNoLock(context, methodName, method, instanceVisibility);
                    }

                    if (isModuleFunction)
                    {
                        module.SetModuleFunctionNoEventNoLock(context, methodName, method);
                    }
                }

                if (method.Visibility != instanceVisibility)
                {
                    module.MethodAdded(methodName);
                }

                if (isModuleFunction)
                {
                    module.GetOrCreateSingletonClass().MethodAdded(methodName);
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Encodes a method lookup strategy as an LNode.
        /// </summary>
        /// <param name="lookup">A method lookup strategy.</param>
        /// <returns>
        /// An LNode that represents <paramref name="lookup"/>.
        /// </returns>
        public LNode Encode(MethodLookup lookup)
        {
            switch (lookup)
            {
            case MethodLookup.Static:
                return(Factory.Id("static"));

            case MethodLookup.Virtual:
                return(Factory.Id("virtual"));

            default:
                throw new NotSupportedException(
                          "Cannot encode unknown method lookup type '" + lookup.ToString() + "'.");
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Resolves a function instance via the .NET stack.
        /// </summary>
        private static UserDefinedFunction ResolveFunctionInstance(int count)
        {
            // First, get the stack:
            System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(5 + count, true);

            for (int i = 0; i < trace.FrameCount; i++)
            {
                System.Diagnostics.StackFrame frame = trace.GetFrame(i);

                UserDefinedFunction func = MethodLookup.Search(frame.GetMethod() as MethodInfo);

                if (func != null)
                {
                    return(func);
                }
            }

            return(null);
        }
Esempio n. 12
0
        private static void RegisterMethod <T>(EventType e, MethodLookup <T> lookup, T method, bool scheduled) where T : FlowMethod
        {
            FlowMethodSet <T> methods;

            if (!lookup.TryGetValue(e, out methods))
            {
                methods = new FlowMethodSet <T>();

                lookup.Add(e, methods);
            }

            if (scheduled)
            {
                methods.ScheduledMethods.Write.Add(method);
            }
            else
            {
                methods.Methods.Write.Add(method);
            }
        }
        /// <summary>
        /// Gets or creates a new-delegate instruction prototype.
        /// </summary>
        /// <param name="delegateType">
        /// The type of delegate produced by instances of the prototype.
        /// </param>
        /// <param name="callee">
        /// The method that is invoked when the delegates produced by instances
        /// of the prototype are called.
        /// </param>
        /// <param name="hasThisArgument">
        /// Tells if a 'this' argument is included in the delegate.
        /// </param>
        /// <param name="lookup">
        /// The method lookup strategy for the prototype.
        /// </param>
        /// <returns>A new-delegate instruction prototype.</returns>
        public static NewDelegatePrototype Create(
            IType delegateType,
            IMethod callee,
            bool hasThisArgument,
            MethodLookup lookup)
        {
            if (hasThisArgument)
            {
                ContractHelpers.Assert(
                    !callee.IsStatic || callee.Parameters.Count >= 1,
                    "A callee that is provided a 'this' argument must " +
                    "be an instance method or take at least one parameter.");
            }
            ContractHelpers.Assert(
                lookup == MethodLookup.Static || !callee.IsStatic,
                "A static callee method cannot be resolved via virtual lookup.");

            return(instanceCache.Intern(
                       new NewDelegatePrototype(
                           delegateType,
                           callee,
                           hasThisArgument,
                           lookup)));
        }
Esempio n. 14
0
        public MethodResolutionResult ResolveMethodNoLock(string/*!*/ name, VisibilityContext visibility, MethodLookup options) {
            Context.RequiresClassHierarchyLock();
            Assert.NotNull(name);

            InitializeMethodsNoLock();
            RubyMemberInfo info = null;
            RubyModule owner = null;
            bool skipHidden = false;
            bool foundCallerSelf = false;
            MethodResolutionResult result;

            if (ForEachAncestor((module) => {
                owner = module;
                foundCallerSelf |= module == visibility.Class;
                return module.TryGetMethod(name, ref skipHidden, (options & MethodLookup.Virtual) != 0, out info);
            })) {
                if (info == null || info.IsUndefined) {
                    result = MethodResolutionResult.NotFound;
                } else if (!IsMethodVisible(info, owner, visibility, foundCallerSelf)) {
                    result = new MethodResolutionResult(info, owner, false);
                } else if (info.IsSuperForwarder) {
                    if ((options & MethodLookup.ReturnForwarder) != 0) {
                        result = new MethodResolutionResult(info, owner, true);
                    } else {
                        // start again with owner's super ancestor and ignore visibility:
                        result = owner.ResolveSuperMethodNoLock(((SuperForwarderInfo)info).SuperName, owner);
                    }
                } else {
                    result = new MethodResolutionResult(info, owner, true);
                }
            } else {
                result = MethodResolutionResult.NotFound;
            }

            // Note: all classes include Object in ancestors, so we don't need to search it again:
            if (!result.Found && (options & MethodLookup.FallbackToObject) != 0 && !IsClass) {
                return _context.ObjectClass.ResolveMethodNoLock(name, visibility, options & ~MethodLookup.FallbackToObject);
            }

            return result;
        }
Esempio n. 15
0
 internal MethodResolutionResult ResolveMethodForSiteNoLock(string/*!*/ name, VisibilityContext visibility, MethodLookup options) {
     return ResolveMethodNoLock(name, visibility, options).InvalidateSitesOnOverride();
 }
Esempio n. 16
0
 private CallPrototype(IMethod callee, MethodLookup lookup)
 {
     this.Callee = callee;
     this.Lookup = lookup;
 }
Esempio n. 17
0
 /// <summary>
 /// Creates a new instance of a user-defined function.
 /// </summary>
 /// <param name="prototype"> The next object in the prototype chain. </param>
 /// <param name="name"> The name of the function. </param>
 /// <param name="args"> The names of the arguments. </param>
 /// <param name="bodyText"> The source code for the function body. </param>
 /// <param name="body"> A delegate which represents the body of the function. </param>
 /// <param name="strictMode"> <c>true</c> if the function body is strict mode; <c>false</c> otherwise. </param>
 public HoistFunctionReference(ScriptEngine engine, long methodID, object[] hoistValues)
 {
     Host        = MethodLookup.LoadGenerator(methodID);
     HoistValues = hoistValues;
 }
Esempio n. 18
0
 internal static IEnumerable <MethodInfo> GetMethods(Type target, MethodLookup lookup) => lookup switch
 {