Ejemplo n.º 1
1
 public static Exception/*!*/ NonBlockingError(RubyContext/*!*/ context, Exception/*!*/ exception, bool isRead) {
     RubyModule waitReadable;
     if (context.TryGetModule(isRead ? typeof(WaitReadable) : typeof(WaitWritable), out waitReadable)) {
         ModuleOps.ExtendObject(waitReadable, exception);
     }
     return exception;
 }
Ejemplo n.º 2
1
        // TODO: hack
        public RubyIO(RubyContext/*!*/ context, StreamReader reader, StreamWriter writer, string/*!*/ modeString)
            : this(context) {
            _mode = ParseIOMode(modeString, out _preserveEndOfLines);
            _stream = new DuplexStream(reader, writer);

            ResetLineNumbersForReadOnlyFiles(context);
        }
Ejemplo n.º 3
0
 /*!*/
 public static IEnumerable<MutableString> GetMatches(RubyContext/*!*/ context, MutableString/*!*/ pattern, int flags)
 {
     string strPattern = context.DecodePath(pattern);
     foreach (string strFileName in GetMatches(context.Platform, strPattern, flags)) {
         yield return context.EncodePath(strFileName).TaintBy(pattern);
     }
 }
Ejemplo n.º 4
0
 internal static Stream/*!*/ GetDescriptorStream(RubyContext/*!*/ context, int descriptor) {
     Stream stream = context.GetStream(descriptor);
     if (stream == null) {
         throw RubyExceptions.CreateEBADF();
     }
     return stream;
 }
Ejemplo n.º 5
0
 private static object Each(RubyContext/*!*/ context, object self, Proc/*!*/ block) {
     if (self is Enumerator) {
         return ((Enumerator)self).Each(context, block);
     } else {
         return RubySites.Each(context, self, block);
     }
 }
Ejemplo n.º 6
0
 public static object Clear(RubyContext/*!*/ context, object/*!*/ self) {
     PlatformAdaptationLayer pal = context.DomainManager.Platform;
     foreach (DictionaryEntry entry in pal.GetEnvironmentVariables()) {
         pal.SetEnvironmentVariable(entry.Key.ToString(), null);
     }
     return self;
 }
Ejemplo n.º 7
0
        public TestRuntime(Driver/*!*/ driver, TestCase/*!*/ testCase) {
            _driver = driver;
            _testName = testCase.Name;

            if (_driver.SaveToAssemblies) {
                Environment.SetEnvironmentVariable("DLR_AssembliesFileName", _testName);
            }

            var runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            LanguageSetup languageSetup = null;
            foreach (var language in runtimeSetup.LanguageSetups) {
                if (language.TypeName == typeof(RubyContext).AssemblyQualifiedName) {
                    languageSetup = language;
                    break;
                }
            }

            runtimeSetup.DebugMode = _driver.IsDebug;
            languageSetup.Options["InterpretedMode"] = _driver.Interpret;
            languageSetup.Options["Verbosity"] = 2;
            languageSetup.Options["Compatibility"] = testCase.Compatibility;

            _env = Ruby.CreateRuntime(runtimeSetup);
            _engine = Ruby.GetEngine(_env);
            _context = Ruby.GetExecutionContext(_engine);
        }
Ejemplo n.º 8
0
 public static object Delete(RubyContext/*!*/ context, object/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ name) {
     MutableString result = GetVariable(context, self, name);
     if (result != null) {
         SetVariable(context, self, name, null);
     }
     return result;
 }
Ejemplo n.º 9
0
 internal static RubyMemberInfo/*!*/ SelectOverload(RubyContext/*!*/ context, RubyMemberInfo/*!*/ info, string/*!*/ name, object[]/*!*/ typeArgs) {
     RubyMemberInfo result = info.TrySelectOverload(Protocols.ToTypes(context, typeArgs));
     if (result == null) {
         throw RubyExceptions.CreateArgumentError("no overload of `{0}' matches given parameter types", name);
     }
     return result;
 }
Ejemplo n.º 10
0
        public static object PrecInteger(
            CallSiteStorage<Func<CallSite, RubyContext, object, RubyClass, object>>/*!*/ precStorage,
            RubyContext/*!*/ context, object self) {

            var prec = precStorage.GetCallSite("prec", 1);
            return prec.Target(prec, context, self, context.GetClass(typeof(Integer)));
        }
Ejemplo n.º 11
0
        public TestRuntime(Driver/*!*/ driver, TestCase/*!*/ testCase) {
            _driver = driver;
            _testName = testCase.Name;

            if (testCase.Options.NoRuntime) {
                return;
            }

            if (_driver.SaveToAssemblies) {
                Environment.SetEnvironmentVariable("DLR_AssembliesFileName", _testName);
            }

            var runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = runtimeSetup.AddRubySetup();

            runtimeSetup.DebugMode = _driver.IsDebug;
            runtimeSetup.PrivateBinding = testCase.Options.PrivateBinding;
            languageSetup.Options["NoAdaptiveCompilation"] = _driver.NoAdaptiveCompilation;
            languageSetup.Options["Verbosity"] = 2;
            languageSetup.Options["Compatibility"] = testCase.Options.Compatibility;

            _runtime = Ruby.CreateRuntime(runtimeSetup);
            _engine = Ruby.GetEngine(_runtime);
            _context = Ruby.GetExecutionContext(_engine);
        }
Ejemplo n.º 12
0
 internal static RubyMemberInfo/*!*/ BindGenericParameters(RubyContext/*!*/ context, RubyMemberInfo/*!*/ info, string/*!*/ name, object[]/*!*/ typeArgs) {
     RubyMemberInfo result = info.TryBindGenericParameters(Protocols.ToTypes(context, typeArgs));
     if (result == null) {
         throw RubyExceptions.CreateArgumentError("wrong number of generic arguments for `{0}'", name);
     }
     return result;
 }
Ejemplo n.º 13
0
 public static RubyClass ToClass(RubyContext/*!*/ context, Type/*!*/ self)
 {
     if (self.IsInterface()) {
         RubyExceptions.CreateTypeError("Cannot convert a CLR interface to a Ruby class");
     }
     return context.GetClass(self);
 }
Ejemplo n.º 14
0
 internal SuperCallAction(RubyContext context, RubyCallSignature signature, int lexicalScopeId)
     : base(context)
 {
     Debug.Assert(signature.HasImplicitSelf && signature.HasScope && (signature.HasBlock || signature.ResolveOnly));
     _signature = signature;
     _lexicalScopeId = lexicalScopeId;
 }
Ejemplo n.º 15
0
        private void initRuby()
        {
            ScriptRuntimeSetup runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = IronRuby.RubyHostingExtensions.AddRubySetup(runtimeSetup);

            runtimeSetup.DebugMode = false;
            runtimeSetup.PrivateBinding = false;
            runtimeSetup.HostType = typeof(RhoHost);

            languageSetup.Options["NoAdaptiveCompilation"] = false;
            languageSetup.Options["CompilationThreshold"] = 0;
            languageSetup.Options["Verbosity"] = 2;

            m_runtime = IronRuby.Ruby.CreateRuntime(runtimeSetup);
            m_engine = IronRuby.Ruby.GetEngine(m_runtime);
            m_context = (RubyContext)Microsoft.Scripting.Hosting.Providers.HostingHelpers.GetLanguageContext(m_engine);

            m_context.ObjectClass.SetConstant("RHO_WP7", 1);
            m_context.Loader.LoadAssembly("RhoRubyLib", "rho.rubyext.rubyextLibraryInitializer", true, true);

            System.Collections.ObjectModel.Collection<string> paths = new System.Collections.ObjectModel.Collection<string>();
            paths.Add("lib");
            paths.Add("apps/app");
            m_engine.SetSearchPaths(paths);
        }
Ejemplo n.º 16
0
 private static Hash CreateDefaultTagMapping(RubyContext/*!*/ context) {
     Hash taggedClasses = new Hash(context.EqualityComparer);
     taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:array"), context.GetClass(typeof(RubyArray)));
     taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:exception"), context.GetClass(typeof(Exception)));
     taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:hash"), context.GetClass(typeof(Hash)));
     taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:object"), context.GetClass(typeof(object)));
     taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:range"), context.GetClass(typeof(Range)));
     taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:regexp"), context.GetClass(typeof(RubyRegex)));
     taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:string"), context.GetClass(typeof(MutableString)));
     taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:struct"), context.GetClass(typeof(RubyStruct)));
     taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:sym"), context.GetClass(typeof(SymbolId)));
     taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:symbol"), context.GetClass(typeof(SymbolId)));
     taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:time"), context.GetClass(typeof(DateTime)));
     taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:binary"), context.GetClass(typeof(MutableString)));
     taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:bool#no"), context.FalseClass);
     taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:bool#yes"), context.TrueClass);
     taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:float"), context.GetClass(typeof(Double)));
     taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:int"), context.GetClass(typeof(Integer)));
     taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:map"), context.GetClass(typeof(Hash)));
     taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:null"), context.NilClass);            
     taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:seq"), context.GetClass(typeof(RubyArray)));            
     taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:str"), context.GetClass(typeof(MutableString)));
     taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:timestamp"), context.GetClass(typeof(DateTime)));
     //Currently not supported
     //taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:omap"), ec.GetClass(typeof()));
     //taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:pairs"),//    ec.GetClass(typeof()));
     //taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:set"),//    ec.GetClass(typeof()));
     //taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:timestamp#ymd'"), );
     return taggedClasses;
 }
Ejemplo n.º 17
0
        public static MutableString ToJson(RubyContext context, IList self, GeneratorState state, int? depth)
        {
            MutableString result;

            if (state == null) {
                result = MutableString.CreateMutable(2 + Math.Max(self.Count * 4, 0), RubyEncoding.UTF8);
                result.Append('[');
                context.TaintObjectBy<Object>(result, self);
                if (self.Count > 0) {
                    for (int i = 0; i < self.Count; i++) {
                        Object element = self[i];
                        result.Append(Generator.ToJson(context, element, null, 0));
                        context.TaintObjectBy<Object>(result, element);
                        if (i < self.Count - 1) {
                            result.Append(',');
                        }
                    }
                }
                result.Append(']');
            }
            else {
                result = Transform(context, self, state, depth.HasValue ? depth.Value : 0);
            }

            return context.TaintObjectBy<MutableString>(result, self);
        }
Ejemplo n.º 18
0
        public void Initialize(BinaryOpStorage/*!*/ comparisonStorage,
            RubyContext/*!*/ context, object begin, object end, bool excludeEnd) {

            if (_initialized) {
                throw RubyExceptions.CreateNameError("`initialize' called twice");
            }

            // Range tests whether the items can be compared, and uses that to determine if the range is valid
            // Only a non-existent <=> method or a result of nil seems to trigger the exception.
            object compareResult;

            var site = comparisonStorage.GetCallSite("<=>");
            try {
                compareResult = site.Target(site, begin, end);
            } catch (Exception) {
                compareResult = null;
            }

            if (compareResult == null) {
                throw RubyExceptions.CreateArgumentError("bad value for range");
            }

            _begin = begin;
            _end = end;
            _excludeEnd = excludeEnd;
            _initialized = true;
        }
Ejemplo n.º 19
0
        public IOWrapper(RubyContext/*!*/ context, object io, bool canRead, bool canWrite, bool canSeek, bool canFlush, bool canBeClosed, int bufferSize) {
            Assert.NotNull(context);

            _writeSite = CallSite<Func<CallSite, object, object, object>>.Create(
                RubyCallAction.Make(context, "write", RubyCallSignature.WithImplicitSelf(1))
            );
            _readSite = CallSite<Func<CallSite, object, object, object>>.Create(
                RubyCallAction.Make(context, "read", RubyCallSignature.WithImplicitSelf(1))
            );
            _seekSite = CallSite<Func<CallSite, object, object, object, object>>.Create(
                RubyCallAction.Make(context, "seek", RubyCallSignature.WithImplicitSelf(2))
            );
            _tellSite = CallSite<Func<CallSite, object, object>>.Create(
                RubyCallAction.Make(context, "tell", RubyCallSignature.WithImplicitSelf(0))
            );

            _obj = io;

            _canRead = canRead;
            _canWrite = canWrite;
            _canSeek = canSeek;
            _canFlush = canFlush;
            _canBeClosed = canBeClosed;
            _buffer = new byte[bufferSize];
            _writePos = 0;
            _readPos = 0;
            _readLen = 0;
        }
Ejemplo n.º 20
0
 internal RubyArray/*!*/ GetMembers(RubyContext/*!*/ context) {
     RubyArray list = new RubyArray(_names.Length);
     foreach (string id in _names) {
         list.Add(context.StringifyIdentifier(id));
     }
     return list;
 }
Ejemplo n.º 21
0
        public RubyRepresenter(RubyContext/*!*/ context, Serializer/*!*/ serializer, YamlOptions/*!*/ opts)
            : base(serializer, opts) {
            _context = context;
            _objectToYamlMethod = context.GetClass(typeof(object)).ResolveMethod("to_yaml", VisibilityContext.AllVisible).Info;

             _TagUri =
                CallSite<Func<CallSite, object, object>>.Create(
                RubyCallAction.Make(context, "taguri", RubyCallSignature.WithImplicitSelf(0))
            );

            _ToYamlStyle =
                CallSite<Func<CallSite, object, object>>.Create(
                RubyCallAction.Make(context, "to_yaml_style", RubyCallSignature.WithImplicitSelf(0))
            );

            _ToYamlNode =
                CallSite<Func<CallSite, object, RubyRepresenter, object>>.Create(
                RubyCallAction.Make(context, "to_yaml_node", RubyCallSignature.WithImplicitSelf(1))
            );

            _ToYaml =
                CallSite<Func<CallSite, object, RubyRepresenter, object>>.Create(
                RubyCallAction.Make(context, "to_yaml", RubyCallSignature.WithImplicitSelf(0))
            );

            _ToYamlProperties = 
                CallSite<Func<CallSite, object, object>>.Create(
                RubyCallAction.Make(context, "to_yaml_properties", RubyCallSignature.WithImplicitSelf(0))
            );
        }
Ejemplo n.º 22
0
 public static MutableString/*!*/ ToChr(RubyContext/*!*/ context, object self) {
     int intSelf = Protocols.CastToFixnum(context, self);
     if (intSelf < 0 || intSelf > 255) {
         throw RubyExceptions.CreateRangeError(String.Format("{0} out of char range", intSelf));
     }
     return MutableString.CreateBinary(new byte[] { (byte)intSelf });
 }
Ejemplo n.º 23
0
 public XmlDeclaration(RubyContext context)
     : base(context, new AttributeData())
 {
     _encoding = context.CreateAsciiSymbol("encoding");
     _standalone = context.CreateAsciiSymbol("standalone");
     _version = context.CreateAsciiSymbol("version");
 }
Ejemplo n.º 24
0
        public static RubyArray/*!*/ CreateBacktrace(RubyContext/*!*/ context, int skipFrames) {
#if FEATURE_STACK_TRACE
            return new RubyStackTraceBuilder(context, skipFrames).RubyTrace;
#else
            return new RubyArray();
#endif
        }
Ejemplo n.º 25
0
        public static CompositeConversionAction Make(RubyContext context, CompositeConversion conversion) {
            switch (conversion) {
                case CompositeConversion.ToFixnumToStr:
                    return new CompositeConversionAction(conversion,
                        typeof(Union<int, MutableString>), ConvertToFixnumAction.Make(context), ConvertToStrAction.Make(context)
                    );

                case CompositeConversion.ToStrToFixnum:
                    return new CompositeConversionAction(conversion,
                        typeof(Union<MutableString, int>), ConvertToStrAction.Make(context), ConvertToFixnumAction.Make(context)
                    );

                case CompositeConversion.ToIntToI:
                    return new CompositeConversionAction(conversion,
                        typeof(IntegerValue), ConvertToIntAction.Make(context), ConvertToIAction.Make(context)
                    );

                case CompositeConversion.ToAryToInt:
                    return new CompositeConversionAction(conversion,
                        typeof(Union<IList, int>), ConvertToArrayAction.Make(context), ConvertToFixnumAction.Make(context)
                    );

                default:
                    throw Assert.Unreachable;
            }
        }
Ejemplo n.º 26
0
        private static Stream/*!*/ OpenFileStream(RubyContext/*!*/ context, string/*!*/ path, RubyFileMode mode) {
            FileMode fileMode;
            FileAccess access = FileAccess.Read;
            FileShare share = FileShare.ReadWrite;

            RubyFileMode readWriteFlags = mode & RubyFileMode.ReadWriteMask;

            if (readWriteFlags == RubyFileMode.WRONLY) {
                access = FileAccess.Write;
            } else if (readWriteFlags == RubyFileMode.RDONLY) {
                access = FileAccess.Read;
            } else if (readWriteFlags == RubyFileMode.RDWR) {
                access = FileAccess.ReadWrite;
            } else {
                throw new ArgumentException("file open mode must be one of RDONLY WRONLY or RDWR");
            }

            if ((mode & RubyFileMode.APPEND) != 0) {
                fileMode = FileMode.Append;
            } else if ((mode & RubyFileMode.CREAT) != 0) {
                fileMode = FileMode.Create;
            } else if ((mode & RubyFileMode.TRUNC) != 0) {
                fileMode = FileMode.Truncate;
            } else {
                fileMode = FileMode.Open;
            }

            if ((mode & RubyFileMode.EXCL) != 0) {
                share = FileShare.None;
            }

            return context.DomainManager.Platform.OpenInputFileStream(path, fileMode, access, share);
        }
Ejemplo n.º 27
0
        public static RubyArray GetAllNames(RubyContext/*!*/ context, RubyEncoding/*!*/ self)
        {
            var result = new RubyArray();

            string name = self.Name;
            result.Add(MutableString.Create(name));

            foreach (var alias in RubyEncoding.Aliases) {
                if (StringComparer.OrdinalIgnoreCase.Equals(alias.Value, name)) {
                    result.Add(MutableString.CreateAscii(alias.Key));
                }
            }

            if (self == context.RubyOptions.LocaleEncoding) {
                result.Add(MutableString.CreateAscii("locale"));
            }

            if (self == context.DefaultExternalEncoding) {
                result.Add(MutableString.CreateAscii("external"));
            }

            if (self == context.GetPathEncoding()) {
                result.Add(MutableString.CreateAscii("filesystem"));
            }

            return result;
        }
Ejemplo n.º 28
0
        private void initRuby()
        {
            ScriptRuntimeSetup runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = IronRuby.RubyHostingExtensions.AddRubySetup(runtimeSetup);

            runtimeSetup.DebugMode = false;
            runtimeSetup.PrivateBinding = false;
            runtimeSetup.HostType = typeof(RhoHost);

            languageSetup.Options["NoAdaptiveCompilation"] = false;
            languageSetup.Options["CompilationThreshold"] = 0;
            languageSetup.Options["Verbosity"] = 2;

            m_runtime = IronRuby.Ruby.CreateRuntime(runtimeSetup);
            m_engine = IronRuby.Ruby.GetEngine(m_runtime);
            m_context = (RubyContext)Microsoft.Scripting.Hosting.Providers.HostingHelpers.GetLanguageContext(m_engine);

            m_context.ObjectClass.SetConstant("RHO_WP7", 1);
            m_context.ObjectClass.AddMethod(m_context, "__rhoGetCallbackObject", new RubyLibraryMethodInfo(
                new[] { LibraryOverload.Create(new Func<System.Object, System.Int32, System.Object>(RhoKernelOps.__rhoGetCallbackObject), false, 0, 0) },
                RubyMethodVisibility.Public,
                m_context.ObjectClass
            ));
            m_context.Loader.LoadAssembly("RhoRubyLib", "rho.rubyext.rubyextLibraryInitializer", true, true);

            System.Collections.ObjectModel.Collection<string> paths = new System.Collections.ObjectModel.Collection<string>();
            paths.Add("lib");
            paths.Add("apps/app");
            m_engine.SetSearchPaths(paths);
        }
Ejemplo n.º 29
0
 public static RubyArray GetGroup(RubyContext/*!*/ context, MatchData/*!*/ self, [NotNull]Range/*!*/ range) {
     int begin, count;
     if (!IListOps.NormalizeRange(context, self.Groups.Count, range, out begin, out count)) {
         return null;
     }
     return GetGroup(context, self, begin, count);
 }
Ejemplo n.º 30
0
 public AssertTokenizer(Tests/*!*/ tests) {
     _log = new LoggingErrorSink();
     _tests = tests;
     _context = tests.Context;
     DefaultEncoding = RubyEncoding.UTF8;
     Compatibility = tests.Context.RubyOptions.Compatibility;
 }
Ejemplo n.º 31
0
 public static Enumerator /*!*/ Select(RubyContext /*!*/ context, IDictionary <object, object> /*!*/ self)
 {
     return(new Enumerator((_, block) => Select(context, block, self)));
 }
Ejemplo n.º 32
0
Archivo: Proc.cs Proyecto: ltwlf/IronSP
 public static Proc /*!*/ Create(RubyContext /*!*/ context, BlockCallTarget1 /*!*/ clrMethod)
 {
     return(Create(context, 1, BlockDispatcher.MakeAttributes(BlockSignatureAttributes.HasSingleCompoundParameter, -1), clrMethod));
 }
Ejemplo n.º 33
0
 public static object Each(RubyContext /*!*/ context, BlockParam block, RubyIO /*!*/ self, [DefaultProtocol, DefaultParameterValue(-1)] int limit)
 {
     return(Each(context, block, self, context.InputSeparator, limit));
 }
Ejemplo n.º 34
0
 public static RubyArray /*!*/ ReadLines(RubyContext /*!*/ context, RubyIO /*!*/ self, [DefaultProtocol, DefaultParameterValue(-1)] int limit)
 {
     return(ReadLines(context, self, context.InputSeparator, limit));
 }
Ejemplo n.º 35
0
 internal static Encoding /*!*/ GetEncoding(RubyContext /*!*/ context)
 {
     // MRI 1.9: UTF8 is used regardless of the string ending
     return((context.RubyOptions.Compatibility < RubyCompatibility.Ruby19 ? RubyEncoding.Binary : RubyEncoding.UTF8).Encoding);
 }
Ejemplo n.º 36
0
 internal VariableDebugView(RubyContext /*!*/ context, RubyInstanceData /*!*/ data, string /*!*/ name)
 {
     _context = context;
     _data    = data;
     _name    = name;
 }
Ejemplo n.º 37
0
 public static object GetDocument(RubyContext /*!*/ context, YamlStream /*!*/ self, [DefaultProtocol] int index)
 {
     return(IListOps.GetElement(self._documents, index));
 }
Ejemplo n.º 38
0
Archivo: Proc.cs Proyecto: ltwlf/IronSP
 public static Proc /*!*/ Create(RubyContext /*!*/ context, BlockCallTarget3 /*!*/ clrMethod)
 {
     return(Create(context, 3, BlockSignatureAttributes.None, clrMethod));
 }
Ejemplo n.º 39
0
 public override object GetValue(RubyContext /*!*/ context, RubyScope scope)
 {
     return(_value);
 }
Ejemplo n.º 40
0
 public override void SetValue(RubyContext /*!*/ context, RubyScope scope, string /*!*/ name, object value)
 {
     _value     = value;
     _isDefined = true;
 }
Ejemplo n.º 41
0
 public static Base /*!*/ Reset(RubyContext /*!*/ context, Base /*!*/ self)
 {
     self._buffer = MutableString.CreateBinary();
     self._algorithm.Initialize();
     return(self);
 }
Ejemplo n.º 42
0
 public override void SetValue(RubyContext /*!*/ context, RubyScope scope, string /*!*/ name, object value)
 {
     throw ReadOnlyError(name);
 }
Ejemplo n.º 43
0
 public static Base /*!*/ Update(RubyContext /*!*/ context, Base /*!*/ self, MutableString str)
 {
     self._buffer.Append(str);
     return(self);
 }
Ejemplo n.º 44
0
 public static MutableString /*!*/ Finish(RubyContext /*!*/ context, Base /*!*/ self)
 {
     byte[] input = self._buffer.ConvertToBytes();
     byte[] hash  = self._algorithm.ComputeHash(input);
     return(MutableString.CreateBinary(hash));
 }
 public static RubyArray /*!*/ CreateBacktrace(RubyContext /*!*/ context, int skipFrames)
 {
     return(new RubyStackTraceBuilder(context, skipFrames).RubyTrace);
 }
Ejemplo n.º 46
0
 public static Proc /*!*/ Create(RubyContext /*!*/ context, BlockCallTarget1 /*!*/ clrMethod)
 {
     return(Create(context, 1, BlockDispatcher.MakeAttributes(BlockSignatureAttributes.None, -1), clrMethod));
 }
Ejemplo n.º 47
0
        public static Stream /*!*/ OpenFileStream(RubyContext /*!*/ context, string /*!*/ path, IOMode mode)
        {
            ContractUtils.RequiresNotNull(path, "path");
            FileAccess access = mode.ToFileAccess();

            FileMode fileMode;

            if ((mode & IOMode.CreateIfNotExists) != 0)
            {
                if ((mode & IOMode.ErrorIfExists) != 0)
                {
                    access  |= FileAccess.Write;
                    fileMode = FileMode.CreateNew;
                }
                else
                {
                    fileMode = FileMode.OpenOrCreate;
                }
            }
            else
            {
                fileMode = FileMode.Open;
            }

            if ((mode & IOMode.Truncate) != 0 && (access & FileAccess.Write) == 0)
            {
                throw RubyExceptions.CreateEINVAL("cannot truncate a file opened for reading only");
            }

            if ((mode & IOMode.WriteAppends) != 0 && (access & FileAccess.Write) == 0)
            {
                throw RubyExceptions.CreateEINVAL("cannot append to a file opened for reading only");
            }

            if (String.IsNullOrEmpty(path))
            {
                throw RubyExceptions.CreateEINVAL();
            }

            Stream stream;

            if (path == "NUL")
            {
                stream = Stream.Null;
            }
            else
            {
                try {
                    stream = context.DomainManager.Platform.OpenInputFileStream(path, fileMode, access, FileShare.ReadWrite);
                } catch (FileNotFoundException) {
                    throw RubyExceptions.CreateENOENT(String.Format("No such file or directory - {0}", path));
                } catch (DirectoryNotFoundException e) {
                    throw RubyExceptions.CreateENOENT(e.Message, e);
                } catch (PathTooLongException e) {
                    throw RubyExceptions.CreateENOENT(e.Message, e);
                } catch (IOException) {
                    if ((mode & IOMode.ErrorIfExists) != 0)
                    {
                        throw RubyExceptions.CreateEEXIST(path);
                    }
                    else
                    {
                        throw;
                    }
                } catch (ArgumentException e) {
                    throw RubyExceptions.CreateEINVAL(e.Message, e);
                }
            }

            if ((mode & IOMode.Truncate) != 0)
            {
                stream.SetLength(0);
            }

            return(stream);
        }
 public static string /*!*/ GetClrMessage(RubyContext /*!*/ context, object message)
 {
     return(Protocols.ToClrStringNoThrow(context, message));
 }
Ejemplo n.º 49
0
 public RubyFile(RubyContext /*!*/ context, MutableString /*!*/ path, IOMode mode)
     : this(context, context.DecodePath(path), mode)
 {
 }
Ejemplo n.º 50
0
 public RubyFile(RubyContext /*!*/ context, Stream /*!*/ stream, int descriptor, IOMode mode)
     : base(context, stream, descriptor, mode)
 {
     Path = null;
 }
Ejemplo n.º 51
0
 public RubyFile(RubyContext /*!*/ context)
     : base(context)
 {
     Path = null;
 }
Ejemplo n.º 52
0
 public RubyFile(RubyContext /*!*/ context, string /*!*/ path, IOMode mode)
     : base(context, OpenFileStream(context, path, mode), mode)
 {
     Path = path;
 }
Ejemplo n.º 53
0
 public static object OpenPipe(RubyContext /*!*/ context, BlockParam block, RubyClass /*!*/ self,
                               [DefaultProtocol, NotNull] MutableString /*!*/ command, [DefaultProtocol, Optional, NotNull] MutableString modeString)
 {
     return(TryInvokeOpenBlock(context, block, OpenPipe(context, self, command, modeString)));
 }
Ejemplo n.º 54
0
 public static object Each(RubyContext /*!*/ context, BlockParam block, RubyDir /*!*/ self)
 {
     return(self.EnumerateEntries(context, block, self));
 }
Ejemplo n.º 55
0
 public static object SetElement(RubyContext /*!*/ context, Hash /*!*/ self, object key, object value)
 {
     self.RequireNotFrozen();
     return(RubyUtils.SetHashElement(context, self, key, value));
 }
Ejemplo n.º 56
0
 public static object GetDefaultValue(RubyContext /*!*/ context, IDictionary <object, object> /*!*/ self, [Optional] object key)
 {
     return(null);
 }
Ejemplo n.º 57
0
 public static RubyModule /*!*/ AliasMethod(RubyContext /*!*/ context, RubyModule /*!*/ self,
                                            [DefaultProtocol, NotNull] string /*!*/ newName, [DefaultProtocol, NotNull] string /*!*/ oldName)
 {
     self.AddMethodAlias(newName, oldName);
     return(self);
 }
Ejemplo n.º 58
0
 public static Hash /*!*/ Replace(RubyContext /*!*/ context, Hash /*!*/ self, [DefaultProtocol, NotNull] IDictionary <object, object> /*!*/ other)
 {
     self.RequireNotFrozen();
     return(IDictionaryOps.ReplaceData(self, other));
 }
Ejemplo n.º 59
0
 public static RubyModule /*!*/ Freeze(RubyContext /*!*/ context, RubyModule /*!*/ self)
 {
     self.Freeze();
     return(self);
 }
Ejemplo n.º 60
0
 public static object SetElement(RubyContext /*!*/ context, IDictionary <object, object> /*!*/ self, object key, object value)
 {
     return(RubyUtils.SetHashElement(context, self, key, value));
 }