Inheritance: IDuplicable
Exemplo n.º 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;
 }
Exemplo n.º 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;
        }
Exemplo n.º 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;
 }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
     }
Exemplo n.º 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.
 }
Exemplo n.º 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);
 }
Exemplo n.º 10
1
        internal UnboundMethod(RubyModule/*!*/ targetConstraint, string/*!*/ name, RubyMemberInfo/*!*/ info) {
            Assert.NotNull(targetConstraint, name, info);

            _name = name;
            _info = info;
            _targetConstraint = targetConstraint;
        }
Exemplo n.º 11
1
 public MethodResolutionResult(RubyMemberInfo/*!*/ info, RubyModule/*!*/ owner, bool visible)
 {
     Assert.NotNull(info, owner);
     _info = info;
     _owner = owner;
     _visible = visible;
 }
Exemplo n.º 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 "";
 }
Exemplo n.º 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;
        }
Exemplo n.º 14
1
 protected RubyMethodGroupBase(OverloadInfo/*!*/[] methods, RubyMemberFlags flags, RubyModule/*!*/ declaringModule)
     : base(flags, declaringModule)
 {
     if (methods != null) {
         SetMethodBasesNoLock(methods);
     }
 }
Exemplo n.º 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;
        }
Exemplo n.º 16
1
 protected RubyAttributeAccessorInfo(RubyMemberFlags flags, RubyModule/*!*/ declaringModule, string/*!*/ variableName)
     : base(flags, declaringModule)
 {
     Assert.NotEmpty(variableName);
     Debug.Assert(variableName.StartsWith("@"));
     _instanceVariableName = variableName;
 }
Exemplo n.º 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;
        }
Exemplo n.º 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;
 }
Exemplo n.º 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;
        }
Exemplo n.º 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;
 }
Exemplo n.º 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");
     }
 }
Exemplo n.º 22
0
        // method:
        internal RubyMethodInfo(RubyMethodBody/*!*/ body, RubyScope/*!*/ declaringScope, RubyModule/*!*/ declaringModule, RubyMemberFlags flags)
            : base(flags, declaringModule) {
            Assert.NotNull(body, declaringModule);

            _body = body;
            _declaringScope = declaringScope;
        }
Exemplo n.º 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;
 }
Exemplo n.º 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.
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 29
0
        internal RubyMemberInfo(RubyMemberFlags flags, RubyModule/*!*/ declaringModule)
        {
            Assert.NotNull(declaringModule);
            Debug.Assert(flags != RubyMemberFlags.Invalid);

            _flags = flags;
            _declaringModule = declaringModule;
        }
Exemplo n.º 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;
        }
Exemplo n.º 31
0
 public static object Evaluate([NotNull] BlockParam /*!*/ block, RubyModule /*!*/ self)
 {
     return(RubyUtils.EvaluateInModule(self, block, null));
 }
Exemplo n.º 32
0
 public static object Execute([NotNull] BlockParam /*!*/ block, RubyModule /*!*/ self, params object[] /*!*/ args)
 {
     return(RubyUtils.EvaluateInModule(self, block, args));
 }
Exemplo n.º 33
0
 public static object ClassVariableSet(RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ variableName, object value)
 {
     self.Context.CheckClassVariableName(variableName);
     self.SetClassVariable(variableName, value);
     return(value);
 }
Exemplo n.º 34
0
 public static RubyArray /*!*/ GetProtectedInstanceMethods(RubyModule /*!*/ self)
 {
     return(GetProtectedInstanceMethods(self, true));
 }
Exemplo n.º 35
0
 public static RubyModule /*!*/ AliasMethod(RubyContext /*!*/ context, RubyModule /*!*/ self,
                                            [DefaultProtocol, NotNull] string /*!*/ newName, [DefaultProtocol, NotNull] string /*!*/ oldName)
 {
     self.AddMethodAlias(newName, oldName);
     return(self);
 }
Exemplo n.º 36
0
 public static bool CaseEquals(RubyModule /*!*/ self, object other)
 {
     return(self.Context.IsKindOf(other, self));
 }
Exemplo n.º 37
0
 public static object ConstantMissing(RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ name)
 {
     return(self.Context.ResolveMissingConstant(self, name));
 }
Exemplo n.º 38
0
        public static object InducedFrom(UnaryOpStorage /*!*/ tofStorage, RubyModule /*!*/ self, [NotNull] BigInteger /*!*/ value)
        {
            var site = tofStorage.GetCallSite("to_f");

            return(site.Target(site, value));
        }
Exemplo n.º 39
0
 public static double InducedFrom(RubyModule /*!*/ self, object value)
 {
     throw RubyExceptions.CreateTypeError("failed to convert {0} into Float", self.Context.GetClassDisplayName(value));
 }
Exemplo n.º 40
0
 public static void AttrWriter(RubyScope /*!*/ scope, RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ name)
 {
     DefineAccessor(scope, self, name, false, true);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 43
0
 public static object ExtendObject(RubyModule /*!*/ self, object extendedObject)
 {
     // include self into extendedObject's singleton
     self.Context.GetOrCreateSingletonClass(extendedObject).IncludeModules(self);
     return(extendedObject);
 }
Exemplo n.º 44
0
 protected RubyClass /*!*/ GetClass(Type /*!*/ type)
 {
     Debug.Assert(type != null && !RubyModule.IsModuleType(type));
     // TODO: CLR class vs library class:
     return(_context.GetOrCreateClass(type));
 }
Exemplo n.º 45
0
 private static bool SkipDefinition(RubyModule /*!*/ module, int attributes)
 {
     return((RubyCompatibility)(attributes >> RubyMethodAttribute.CompatibilityEncodingShift) > module.Context.RubyOptions.Compatibility);
 }
Exemplo n.º 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);
 }
Exemplo n.º 47
0
 public static object InvalidComparison(RubyModule /*!*/ self, object module)
 {
     throw RubyExceptions.CreateTypeError("compared with non class/module");
 }
Exemplo n.º 48
0
 // thread-safe:
 public static void SetConstant(RubyModule /*!*/ module, string /*!*/ name, object value)
 {
     module.SetConstant(name, value);
 }
Exemplo n.º 49
0
 public static object GetConstantValue(RubyScope /*!*/ scope, RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ constantName)
 {
     return(RubyUtils.GetConstant(scope.GlobalScope, self, constantName, true));
 }
Exemplo n.º 50
0
 public static RubyArray /*!*/ GetProtectedInstanceMethods(RubyModule /*!*/ self, bool inherited)
 {
     return(GetMethods(self, inherited, RubyMethodAttributes.ProtectedInstance));
 }
Exemplo n.º 51
0
 public static RubyArray /*!*/ GetGlobalConstants(RubyModule /*!*/ self)
 {
     return(GetDefinedConstants(self.Context.ObjectClass));
 }
Exemplo n.º 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);
        }
Exemplo n.º 53
0
 public static object Comparison(RubyModule /*!*/ self, object module)
 {
     return(null);
 }
Exemplo n.º 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);
 }
Exemplo n.º 55
0
 public static bool Equals(RubyModule /*!*/ self, object other)
 {
     return(ReferenceEquals(self, other));
 }
Exemplo n.º 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
 }
Exemplo n.º 57
0
 public static double InducedFrom(RubyModule /*!*/ self, double value)
 {
     return(value);
 }
Exemplo n.º 58
0
 public static MutableString GetAutoloadedConstantPath(RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ constantName)
 {
     return(self.GetAutoloadedConstantPath(constantName));
 }
Exemplo n.º 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)));
        }
Exemplo n.º 60
0
 public static void Attr(RubyScope /*!*/ scope, RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ name, [Optional] bool writable)
 {
     DefineAccessor(scope, self, name, true, writable);
 }