public CallSite <TCallSiteFunc> /*!*/ GetCallSite(string /*!*/ methodName, int argumentCount)
 {
     return(RubyUtils.GetCallSite(ref Site, Context, methodName, argumentCount));
 }
 public CallSite <TCallSiteFunc> /*!*/ GetCallSite(string /*!*/ methodName, RubyCallSignature signature)
 {
     return(RubyUtils.GetCallSite(ref Site, Context, methodName, signature));
 }
 public CallSite <Func <CallSite, object, TResult> > /*!*/ GetSite(RubyConversionAction /*!*/ conversion)
 {
     return(RubyUtils.GetCallSite(ref Site, conversion));
 }
 internal CallSite <Func <CallSite, object, TResult> > /*!*/ GetDefaultConversionSite()
 {
     return(RubyUtils.GetCallSite(ref Site, ProtocolConversionAction.GetConversionAction(Context, typeof(TResult), true)));
 }
Пример #5
0
 private bool AlreadyLoaded(string /*!*/ path, string fullPath, LoadFlags flags, string[] /*!*/ sourceFileExtensions)
 {
     Debug.Assert(fullPath == null || RubyUtils.GetExtension(path) == RubyUtils.GetExtension(fullPath));
     return((flags & LoadFlags.LoadOnce) != 0 && AnyFileLoaded(GetPathsToTestLoaded(path, fullPath, flags, sourceFileExtensions)));
 }
Пример #6
0
        /// <summary>
        /// Searches file in load directories and then appends extensions.
        /// </summary>
        private IList <ResolvedFile> FindFile(string /*!*/ path, bool appendExtensions, string[] sourceFileExtensions)
        {
            Assert.NotNull(path);
            bool isAbsolutePath;

#if SILVERLIGHT
            {
#else
            if (path.StartsWith("~/", StringComparison.Ordinal) || path.StartsWith("~\\", StringComparison.Ordinal))
            {
                path           = RubyUtils.ExpandPath(_context.Platform, path);
                isAbsolutePath = true;
            }
            else
            {
#endif
                try {
                    isAbsolutePath = Platform.IsAbsolutePath(path);
                } catch (ArgumentException e) {
                    throw RubyExceptions.CreateLoadError(e);
                }
            }

            string extension = RubyUtils.GetExtension(path);

            // Absolute path -> load paths not consulted.
            if (isAbsolutePath)
            {
                var file = ResolveFile(path, extension, appendExtensions, sourceFileExtensions);
                return(file != null ? new[] { file } : new ResolvedFile[0]);
            }

            string[] loadPaths = GetLoadPathStrings();

            if (loadPaths.Length == 0)
            {
                return(new ResolvedFile[0]);
            }

            // If load paths are non-empty and the path starts with .\ or ..\ then MRI also ignores the load paths.
            if (path.StartsWith("./", StringComparison.Ordinal) ||
                path.StartsWith("../", StringComparison.Ordinal) ||
                path.StartsWith(".\\", StringComparison.Ordinal) ||
                path.StartsWith("..\\", StringComparison.Ordinal))
            {
                var file = ResolveFile(path, extension, appendExtensions, sourceFileExtensions);
                return(file != null ? new[] { file } : new ResolvedFile[0]);
            }

            var result = new List <ResolvedFile>();
            foreach (var dir in loadPaths)
            {
                ResolvedFile file = ResolveFile(RubyUtils.CombinePaths(dir, path), extension, appendExtensions, sourceFileExtensions);
                if (file != null)
                {
                    result.Add(file);

                    //RHO
                    break;
                    //RHO
                }
            }

            return(result);
        }
Пример #7
0
        private ResolvedFile FindFile(string /*!*/ path, bool appendExtensions, string[] sourceFileExtensions)
        {
            Assert.NotNull(path);
            bool   isAbsolutePath;
            string extension;
            string home = null;

#if !SILVERLIGHT
            if (path.StartsWith("~/", StringComparison.Ordinal) || path.StartsWith("~\\", StringComparison.Ordinal))
            {
                try {
                    home = Environment.GetEnvironmentVariable("HOME");
                } catch (SecurityException) {
                    home = null;
                }

                if (home == null)
                {
                    throw RubyExceptions.CreateArgumentError(String.Format("couldn't find HOME environment -- expanding `{0}'", path));
                }
            }
#endif
            try {
                if (home != null)
                {
                    path = RubyUtils.CombinePaths(home, path.Substring(2));
                }

                isAbsolutePath = Platform.IsAbsolutePath(path);
                extension      = Path.GetExtension(path);
            } catch (ArgumentException e) {
                throw RubyExceptions.CreateLoadError(e);
            }

            // Absolute path -> load paths not consulted.
            if (isAbsolutePath)
            {
                return(ResolveFile(path, extension, appendExtensions, sourceFileExtensions));
            }

            string[] loadPaths = GetLoadPathStrings();

            if (loadPaths.Length == 0)
            {
                return(null);
            }

            // If load paths are non-empty and the path starts with .\ or ..\ then MRI also ignores the load paths.
            if (path.StartsWith("./", StringComparison.Ordinal) ||
                path.StartsWith("../", StringComparison.Ordinal) ||
                path.StartsWith(".\\", StringComparison.Ordinal) ||
                path.StartsWith("..\\", StringComparison.Ordinal))
            {
                return(ResolveFile(path, extension, appendExtensions, sourceFileExtensions));
            }

            foreach (var dir in loadPaths)
            {
                try {
                    ResolvedFile result = ResolveFile(RubyUtils.CombinePaths(dir, path), extension, appendExtensions, sourceFileExtensions);
                    if (result != null)
                    {
                        return(result);
                    }
                } catch (ArgumentException) {
                    // invalid characters in path
                }
            }

            return(null);
        }
Пример #8
0
        static PropertyDescriptor[] GetPropertiesImpl(object self, Attribute[] attributes)
        {
            bool ok = true;

            foreach (var attr in attributes)
            {
                if (attr.GetType() != typeof(BrowsableAttribute))
                {
                    ok = false;
                    break;
                }
            }
            if (!ok)
            {
                return(new PropertyDescriptor[0]);
            }

            RubyClass   immediateClass = GetImmediateClass(self);
            RubyContext context        = immediateClass.Context;

            const int readable = 0x01;
            const int writable = 0x02;

            var properties = new Dictionary <string, int>();

            using (context.ClassHierarchyLocker()) {
                immediateClass.ForEachMember(true, RubyMethodAttributes.DefaultVisibility, delegate(string /*!*/ name, RubyModule /*!*/ module, RubyMemberInfo /*!*/ member) {
                    ExpressionType operatorType;

                    int flag = 0;
                    if (member is RubyAttributeReaderInfo)
                    {
                        flag = readable;
                    }
                    else if (member is RubyAttributeWriterInfo)
                    {
                        flag = writable;
                    }
                    else if (name == "initialize" || RubyUtils.TryMapOperator(name, out operatorType) != 0)
                    {
                        // Special case; never a property
                    }
                    else
                    {
                        int arity = member.GetArity();
                        if (arity == 0)
                        {
                            flag = readable;
                        }
                        else if (arity == 1 && name.LastCharacter() == '=')
                        {
                            flag = writable;
                        }
                    }
                    if (flag != 0)
                    {
                        if (flag == writable)
                        {
                            name = name.Substring(0, name.Length - 1);
                        }
                        int oldFlag;
                        properties.TryGetValue(name, out oldFlag);
                        properties[name] = oldFlag | flag;
                    }
                });
            }

            var result = new List <PropertyDescriptor>(properties.Count);

            foreach (var pair in properties)
            {
                if (pair.Value == (readable | writable))
                {
                    result.Add(new RubyPropertyDescriptor(context, pair.Key, self, immediateClass.GetUnderlyingSystemType()));
                }
            }
            return(result.ToArray());
        }
        private object RequireWriteProtocol(RubyContext /*!*/ context, object value, string /*!*/ variableName)
        {
            if (!RubySites.RespondTo(context, value, "write"))
            {
                throw RubyExceptions.CreateTypeError(String.Format("${0} must have write method, {1} given", variableName, RubyUtils.GetClassName(context, value)));
            }

            return(value);
        }
Пример #10
0
 public static Exception /*!*/ CannotConvertTypeToTargetType(RubyContext /*!*/ context, object param, string /*!*/ toType)
 {
     Assert.NotNull(context, toType);
     return(CreateTypeConversionError(RubyUtils.GetClassName(context, param), toType));
 }
Пример #11
0
 public static Exception /*!*/ CreateUnexpectedTypeError(RubyContext /*!*/ context, object param, string /*!*/ type)
 {
     return(CreateTypeError(String.Format("wrong argument type {0} (expected {1})", RubyUtils.GetClassName(context, param), type)));
 }