Наследование: IDuplicable
Пример #1
1
 public static object Load(RubyScope/*!*/ scope, RubyModule/*!*/ self, MutableString/*!*/ libraryName)
 {
     object loaded;
     scope.RubyContext.Loader.LoadFile(null, self, libraryName, LoadFlags.ResolveLoaded | LoadFlags.AnyLanguage, out loaded);
     Debug.Assert(loaded != null);
     return loaded;
 }
Пример #2
1
        public static object EachObject(BlockParam block, RubyModule/*!*/ self, [NotNull]RubyClass/*!*/ theClass) {
            Type classType = theClass.GetType();
            bool isClass = (classType == typeof(RubyClass));
            if (!isClass && classType != typeof(RubyModule)) {
                throw new NotSupportedException("each_object only supported for objects of type Class or Module");
            }
            if (block == null) {
                throw RubyExceptions.NoBlockGiven();
            }

            Dictionary<RubyModule, object> visited = new Dictionary<RubyModule, object>();
            Stack<RubyModule> modules = new Stack<RubyModule>();
            modules.Push(theClass.Context.ObjectClass);
            while (modules.Count > 0) {
                RubyModule next = modules.Pop();
                RubyClass asClass = next as RubyClass;

                if (!isClass || asClass != null) {
                    object result;
                    if (block.Yield(next, out result)) {
                        return result;
                    }
                }
                next.EnumerateConstants(delegate(RubyModule module, string name, object value) {
                    RubyModule constAsModule = (value as RubyModule);
                    if (constAsModule != null && !visited.ContainsKey(constAsModule)) {
                        modules.Push(constAsModule);
                        visited[module] = null;
                    }
                    return false;
                });
            }
            return visited.Count;
        }
Пример #3
1
 public static object Dump(WriterSites/*!*/ sites, RubyModule/*!*/ self, object obj, [NotNull]RubyIO/*!*/ io, [Optional]int? limit)
 {
     BinaryWriter writer = io.GetBinaryWriter();
     MarshalWriter dumper = new MarshalWriter(sites, writer, self.Context, limit);
     dumper.Dump(obj);
     return io;
 }
Пример #4
1
        public static void choose(RubyModule/*!*/ self, params object[] args)
        {
            try
            {
                if (args != null && args.Length != 4 && args.Length != 5)
                    throw RubyExceptionData.InitializeException(new RuntimeError("wrong number of arguments"), "wrong number of arguments");

                if (args.Length == 5)
                    m_opaque = args[4].ToString();

                m_fmt = int.Parse(args[3].ToString());

                m_callback = args[0].ToString();
                m_title = args[1].ToString();
                //long init = args[2].toRubyTime().getTime();

                RHODESAPP().MainPage.Dispatcher.BeginInvoke(() =>
                {
                    OpenPickerPage();
                });
            }
            catch (Exception ex)
            {
                Exception rubyEx = self.Context.CurrentException;
                if (rubyEx == null)
                {
                    rubyEx = RubyExceptionData.InitializeException(new RuntimeError(ex.Message.ToString()), ex.Message);
                }
                LOG.ERROR("choose", ex);
                throw rubyEx;
            }
        }
Пример #5
1
        public static bool AreIdentical(ConversionStorage<MutableString>/*!*/ toPath, RubyModule/*!*/ self, object path1, object path2) {
            FileSystemInfo info1, info2;

            return RubyFileOps.RubyStatOps.TryCreate(self.Context, self.Context.DecodePath(Protocols.CastToPath(toPath, path1)), out info1)
                && RubyFileOps.RubyStatOps.TryCreate(self.Context, self.Context.DecodePath(Protocols.CastToPath(toPath, path2)), out info2)
                && RubyFileOps.RubyStatOps.AreIdentical(self.Context, info1, info2);
        }
Пример #6
1
     public static bool AreIdentical(RubyModule/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path1, [DefaultProtocol, NotNull]MutableString/*!*/ path2) {
         FileSystemInfo info1, info2;
 
         return RubyFileOps.RubyStatOps.TryCreate(self.Context, self.Context.DecodePath(path1), out info1) 
             && RubyFileOps.RubyStatOps.TryCreate(self.Context, self.Context.DecodePath(path2), out info2)
             && RubyFileOps.RubyStatOps.AreIdentical(self.Context, info1, info2);
     }
Пример #7
1
 public RubyEventInfo(EventTracker/*!*/ tracker, RubyMemberFlags flags, RubyModule/*!*/ declaringModule, bool isDetached)
     : base(flags, declaringModule)
 {
     Assert.NotNull(tracker, declaringModule);
     _tracker = tracker;
     _isDetached = isDetached;
 }
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo/*!*/ info, RubyMemberFlags flags, RubyModule/*!*/ module)
     : base(info.MethodBases, flags, module) {
     _isStatic = info._isStatic;
     _hasVirtuals = info._hasVirtuals;
     _staticDispatchMethods = info._staticDispatchMethods;
     // Note: overloadOwners and maxCachedOverloadLevel are cleared whenever the group is copied.
 }
Пример #9
1
 internal RubyLambdaMethodInfo(Proc/*!*/ block, string/*!*/ definitionName, RubyMemberFlags flags, RubyModule/*!*/ declaringModule) 
     : base(flags, declaringModule) {
     Assert.NotNull(block, definitionName, declaringModule);
     _lambda = block.ToLambda(this);
     _definitionName = definitionName;
     _id = Interlocked.Increment(ref _Id);
 }
Пример #10
1
        internal UnboundMethod(RubyModule/*!*/ targetConstraint, string/*!*/ name, RubyMemberInfo/*!*/ info) {
            Assert.NotNull(targetConstraint, name, info);

            _name = name;
            _info = info;
            _targetConstraint = targetConstraint;
        }
Пример #11
1
 public MethodResolutionResult(RubyMemberInfo/*!*/ info, RubyModule/*!*/ owner, bool visible)
 {
     Assert.NotNull(info, owner);
     _info = info;
     _owner = owner;
     _visible = visible;
 }
Пример #12
1
 public static Object get_property_by_name(RubyModule/*!*/ self, [NotNull]String/*!*/ name)
 {
     if(name == "platform") return "WP7";
     else if(name == "os_version") return "7.0";
     else if(name == "country") return "us";
     else return "";
 }
Пример #13
1
        protected RubyClass/*!*/ DefineGlobalClass(string/*!*/ name, Type/*!*/ type, RubyClass/*!*/ super, 
            Action<RubyModule> instanceTrait, Action<RubyModule> classTrait, RubyModule[]/*!*/ mixins, Delegate[] factories) {

            RubyClass result = _context.DefineLibraryClass(name, type, instanceTrait, classTrait, super, mixins, factories, _builtin);
            _context.ObjectClass.SetConstant(result.Name, result);
            return result;
        }
Пример #14
1
 protected RubyMethodGroupBase(OverloadInfo/*!*/[] methods, RubyMemberFlags flags, RubyModule/*!*/ declaringModule)
     : base(flags, declaringModule)
 {
     if (methods != null) {
         SetMethodBasesNoLock(methods);
     }
 }
Пример #15
1
        internal RubyOverloadGroupInfo(OverloadInfo/*!*/[]/*!*/ methods, RubyModule/*!*/ declaringModule,
            RubyOverloadGroupInfo/*!*/[] overloadOwners, bool isStatic)
            : base(methods, declaringModule, isStatic) {
            Debug.Assert(overloadOwners == null || methods.Length == overloadOwners.Length);

            _overloadOwners = overloadOwners;
        }
Пример #16
1
 protected RubyAttributeAccessorInfo(RubyMemberFlags flags, RubyModule/*!*/ declaringModule, string/*!*/ variableName)
     : base(flags, declaringModule)
 {
     Assert.NotEmpty(variableName);
     Debug.Assert(variableName.StartsWith("@"));
     _instanceVariableName = variableName;
 }
Пример #17
1
        public static object dosync_source(RubyModule/*!*/ self, [NotNull]object/*!*/ srcID)
        {
            object res = null;
            try
            {
                int nSrcID = 0;
                String strName = "";
                if (srcID is long)
                    nSrcID = (int)(long)srcID;
                else if (srcID is int)
                    nSrcID = (int)srcID;
                else
                    strName = srcID.ToString();

                SyncThread.getInstance().addQueueCommand(new SyncThread.SyncCommand(SyncThread.scSyncOne, strName, nSrcID, true));

                res = SyncThread.getInstance().getRetValue();
            }
            catch (Exception ex)
            {
                Exception rubyEx = self.Context.CurrentException;
                if (rubyEx == null)
                {
                    rubyEx = RubyExceptionData.InitializeException(new RuntimeError(ex.Message.ToString()), ex.Message);
                }
                LOG.ERROR("dosync_source", ex);
                throw rubyEx;
            }

            return res;
        }
Пример #18
1
 public RubyFieldInfo(FieldInfo/*!*/ fieldInfo, RubyMemberFlags flags, RubyModule/*!*/ declaringModule, bool isSetter, bool isDetached)
     : base(flags, declaringModule) {
     Assert.NotNull(fieldInfo, declaringModule);
     _fieldInfo = fieldInfo;
     _isSetter = isSetter;
     _isDetached = isDetached;
 }
Пример #19
1
        public static object dosync(RubyModule/*!*/ self, RubyArray args)
        {
            object res = null;
            try
            {
                boolean bShowStatus = true;	
                String query_params = "";
                if ( args != null && args.Count > 0 )	
                {
                    String str = ((MutableString)args[0]).ToString();	
                    //bShowStatus = args[0].Equals(RubyConstant.QTRUE)||"true".equalsIgnoreCase(str);	
                    bShowStatus = "true".equalsIgnoreCase(str);	
                }
        
                if (args != null && args.Count > 1)
                    query_params = ((MutableString)args[1]).ToString();
                
                SyncThread.getInstance().addQueueCommand(new SyncThread.SyncCommand(SyncThread.scSyncAll, bShowStatus, query_params));

                res = SyncThread.getInstance().getRetValue();
            }
            catch (Exception ex)
            {
                Exception rubyEx = self.Context.CurrentException;
                if (rubyEx == null)
                {
                    rubyEx = RubyExceptionData.InitializeException(new RuntimeError(ex.Message.ToString()), ex.Message);
                }
                LOG.ERROR("dosync", ex);
                throw rubyEx;
            }

            return res;
        }
Пример #20
1
 /// <summary>
 /// Creates a Ruby method implemented by a method group of CLR methods.
 /// </summary>
 internal RubyLibraryMethodInfo(LibraryOverload/*!*/[]/*!*/ overloads, RubyMemberFlags flags, RubyModule/*!*/ declaringModule)
     : base(null, flags, declaringModule)
 {
     Assert.NotNullItems(overloads);
     Assert.NotEmpty(overloads);
     _overloads = overloads;
 }
Пример #21
1
 public static decimal InducedFrom(RubyModule/*!*/ self, [NotNull]BigInteger value) {
     try {
         return (decimal)value;
     } catch (OverflowException) {
         throw RubyExceptions.CreateRangeError("number too big to convert into System::Decimal");
     }
 }
Пример #22
0
        // method:
        internal RubyMethodInfo(RubyMethodBody/*!*/ body, RubyScope/*!*/ declaringScope, RubyModule/*!*/ declaringModule, RubyMemberFlags flags)
            : base(flags, declaringModule) {
            Assert.NotNull(body, declaringModule);

            _body = body;
            _declaringScope = declaringScope;
        }
Пример #23
0
 public static object GetClassVariable(RubyModule/*!*/ self, [DefaultProtocol]string/*!*/ variableName) {
     object value;
     if (self.TryResolveClassVariable(variableName, out value) == null) {
         RubyUtils.CheckClassVariableName(variableName);
         throw RubyExceptions.CreateNameError(String.Format("uninitialized class variable {0} in {1}", variableName, self.Name));
     }
     return value;
 }
Пример #24
0
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo/*!*/ info, RubyMemberFlags flags, RubyModule/*!*/ module)
     : base(info.MethodBases, flags, module) {
     _isStatic = info._isStatic;
     _hasVirtuals = info._hasVirtuals;
     _staticDispatchMethods = info._staticDispatchMethods;
     // Note: overloadOwners and maxCachedOverloadLevel are cleared whenever the group is copied
     // The resulting group captures an immutable set of underlying CLR members.
 }
Пример #25
0
 public static object GetTaggedClasses(RubyModule/*!*/ self) {
     object taggedClasses;
     if (!self.TryGetClassVariable(_TaggedClasses, out taggedClasses)) {
         taggedClasses = CreateDefaultTagMapping(self.Context);
         self.SetClassVariable(_TaggedClasses, taggedClasses);                                
     }            
     return taggedClasses;
 }
Пример #26
0
 public static object AddBuiltinType(
     [NotNull]BlockParam/*!*/ block, 
     RubyModule/*!*/ self, 
     [DefaultProtocol, NotNull]MutableString/*!*/ typeTag) {
     // Add a stub implementation to unblock Rails 3
     Console.WriteLine("WARNING: YAML.add_builtin_type is not implemented");
     return null;
 }
Пример #27
0
        protected RubyModule/*!*/ DefineGlobalModule(string/*!*/ name, Type/*!*/ type, int restrictions,
            Action<RubyModule> instanceTrait, Action<RubyModule> classTrait, Action<RubyModule> constantsInitializer,
            RubyModule/*!*/[]/*!*/ mixins) {

            RubyModule result = _context.DefineLibraryModule(name, type, instanceTrait, classTrait, constantsInitializer, mixins, (ModuleRestrictions)restrictions, _builtin);
            PublishModule(name, result);
            return result;
        }
Пример #28
0
        /// <summary>
        /// Creates a CLR method group.
        /// </summary>
        internal RubyMethodGroupInfo(MethodBase/*!*/[]/*!*/ methods, RubyModule/*!*/ declaringModule,
            RubyMethodGroupInfo/*!*/[] overloadOwners, bool isStatic)
            : base(methods, RubyMemberFlags.Public, declaringModule) {
            Debug.Assert(overloadOwners == null || methods.Length == overloadOwners.Length);

            _isStatic = isStatic;
            _overloadOwners = overloadOwners;
        }
Пример #29
0
        internal RubyMemberInfo(RubyMemberFlags flags, RubyModule/*!*/ declaringModule)
        {
            Assert.NotNull(declaringModule);
            Debug.Assert(flags != RubyMemberFlags.Invalid);

            _flags = flags;
            _declaringModule = declaringModule;
        }
Пример #30
0
        protected RubyClass/*!*/ DefineGlobalClass(string/*!*/ name, Type/*!*/ type, int restrictions, RubyClass/*!*/ super,
            Action<RubyModule> instanceTrait, Action<RubyModule> classTrait, Action<RubyModule> constantsInitializer,
            RubyModule/*!*/[]/*!*/ mixins, params Delegate[] factories) {

            RubyClass result = _context.DefineLibraryClass(name, type, instanceTrait, classTrait, constantsInitializer, super, mixins, factories, (ModuleRestrictions)restrictions, _builtin);
            PublishModule(name, result);
            return result;
        }
Пример #31
0
 public static object Evaluate([NotNull] BlockParam /*!*/ block, RubyModule /*!*/ self)
 {
     return(RubyUtils.EvaluateInModule(self, block, null));
 }
Пример #32
0
 public static object Execute([NotNull] BlockParam /*!*/ block, RubyModule /*!*/ self, params object[] /*!*/ args)
 {
     return(RubyUtils.EvaluateInModule(self, block, args));
 }
Пример #33
0
 public static object ClassVariableSet(RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ variableName, object value)
 {
     self.Context.CheckClassVariableName(variableName);
     self.SetClassVariable(variableName, value);
     return(value);
 }
Пример #34
0
 public static RubyArray /*!*/ GetProtectedInstanceMethods(RubyModule /*!*/ self)
 {
     return(GetProtectedInstanceMethods(self, true));
 }
Пример #35
0
 public static RubyModule /*!*/ AliasMethod(RubyContext /*!*/ context, RubyModule /*!*/ self,
                                            [DefaultProtocol, NotNull] string /*!*/ newName, [DefaultProtocol, NotNull] string /*!*/ oldName)
 {
     self.AddMethodAlias(newName, oldName);
     return(self);
 }
Пример #36
0
 public static bool CaseEquals(RubyModule /*!*/ self, object other)
 {
     return(self.Context.IsKindOf(other, self));
 }
Пример #37
0
 public static object ConstantMissing(RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ name)
 {
     return(self.Context.ResolveMissingConstant(self, name));
 }
Пример #38
0
        public static object InducedFrom(UnaryOpStorage /*!*/ tofStorage, RubyModule /*!*/ self, [NotNull] BigInteger /*!*/ value)
        {
            var site = tofStorage.GetCallSite("to_f");

            return(site.Target(site, value));
        }
Пример #39
0
 public static double InducedFrom(RubyModule /*!*/ self, object value)
 {
     throw RubyExceptions.CreateTypeError("failed to convert {0} into Float", self.Context.GetClassDisplayName(value));
 }
Пример #40
0
 public static void AttrWriter(RubyScope /*!*/ scope, RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ name)
 {
     DefineAccessor(scope, self, name, false, true);
 }
Пример #41
0
 public static object SetConstantValue(RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ constantName, object value)
 {
     self.Context.CheckConstantName(constantName);
     RubyUtils.SetConstant(self, constantName, value);
     return(value);
 }
Пример #42
0
        internal static MutableString /*!*/ ToS(RubyContext /*!*/ context, string /*!*/ methodName, RubyModule /*!*/ declaringModule, RubyModule /*!*/ targetModule,
                                                string /*!*/ classDisplayName)
        {
            MutableString result = MutableString.CreateMutable(context.GetIdentifierEncoding());

            result.Append("#<");
            result.Append(classDisplayName);
            result.Append(": ");

            if (ReferenceEquals(targetModule, declaringModule))
            {
                result.Append(declaringModule.GetDisplayName(context, true));
            }
            else
            {
                result.Append(targetModule.GetDisplayName(context, true));
                result.Append('(');
                result.Append(declaringModule.GetDisplayName(context, true));
                result.Append(')');
            }

            result.Append('#');
            result.Append(methodName);
            result.Append('>');
            return(result);
        }
Пример #43
0
 public static object ExtendObject(RubyModule /*!*/ self, object extendedObject)
 {
     // include self into extendedObject's singleton
     self.Context.GetOrCreateSingletonClass(extendedObject).IncludeModules(self);
     return(extendedObject);
 }
Пример #44
0
 protected RubyClass /*!*/ GetClass(Type /*!*/ type)
 {
     Debug.Assert(type != null && !RubyModule.IsModuleType(type));
     // TODO: CLR class vs library class:
     return(_context.GetOrCreateClass(type));
 }
Пример #45
0
 private static bool SkipDefinition(RubyModule /*!*/ module, int attributes)
 {
     return((RubyCompatibility)(attributes >> RubyMethodAttribute.CompatibilityEncodingShift) > module.Context.RubyOptions.Compatibility);
 }
Пример #46
0
 public static object Included(RubyContext /*!*/ context, RubyModule /*!*/ self, RubyModule /*!*/ includedIn)
 {
     includedIn.SingletonClass.DefineLibraryMethod("induced_from", (int)RubyMethodAttributes.PublicSingleton, new Func <RubyModule, object, object>(InducedFrom));
     return(self);
 }
Пример #47
0
 public static object InvalidComparison(RubyModule /*!*/ self, object module)
 {
     throw RubyExceptions.CreateTypeError("compared with non class/module");
 }
Пример #48
0
 // thread-safe:
 public static void SetConstant(RubyModule /*!*/ module, string /*!*/ name, object value)
 {
     module.SetConstant(name, value);
 }
Пример #49
0
 public static object GetConstantValue(RubyScope /*!*/ scope, RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ constantName)
 {
     return(RubyUtils.GetConstant(scope.GlobalScope, self, constantName, true));
 }
Пример #50
0
 public static RubyArray /*!*/ GetProtectedInstanceMethods(RubyModule /*!*/ self, bool inherited)
 {
     return(GetMethods(self, inherited, RubyMethodAttributes.ProtectedInstance));
 }
Пример #51
0
 public static RubyArray /*!*/ GetGlobalConstants(RubyModule /*!*/ self)
 {
     return(GetDefinedConstants(self.Context.ObjectClass));
 }
Пример #52
0
        public static object Included(RubyContext /*!*/ context, RubyModule /*!*/ self, RubyModule /*!*/ includedIn)
        {
            var singleton = includedIn.GetOrCreateSingletonClass();

            singleton.AddMethod(
                context,
                "induced_from",
                new RubyLibraryMethodInfo(
                    new[] { LibraryOverload.Create(new Func <RubyModule, object, object>(InducedFrom), false, 0, 0) },
                    RubyMethodVisibility.Public,
                    singleton
                    )
                );
            return(self);
        }
Пример #53
0
 public static object Comparison(RubyModule /*!*/ self, object module)
 {
     return(null);
 }
Пример #54
0
 private static object InducedFrom(RubyModule /*!*/ rubyClass, object other)
 {
     throw RubyExceptions.CreateTypeError("undefined conversion from {0} into {1}",
                                          rubyClass.Context.GetClassOf(other).Name, rubyClass.Name);
 }
Пример #55
0
 public static bool Equals(RubyModule /*!*/ self, object other)
 {
     return(ReferenceEquals(self, other));
 }
Пример #56
0
 public static void ObjectExtended(RubyModule /*!*/ self, object extendedObject)
 {
     // extendedObject has been extended by self, i.e. self has been included into extendedObject's singleton class
 }
Пример #57
0
 public static double InducedFrom(RubyModule /*!*/ self, double value)
 {
     return(value);
 }
Пример #58
0
 public static MutableString GetAutoloadedConstantPath(RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ constantName)
 {
     return(self.GetAutoloadedConstantPath(constantName));
 }
Пример #59
0
        public static object InducedFrom(UnaryOpStorage /*!*/ tofStorage, RubyModule /*!*/ self, int value)
        {
            var site = tofStorage.GetCallSite("to_f");

            return(site.Target(site, ScriptingRuntimeHelpers.Int32ToObject(value)));
        }
Пример #60
0
 public static void Attr(RubyScope /*!*/ scope, RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ name, [Optional] bool writable)
 {
     DefineAccessor(scope, self, name, true, writable);
 }