Ejemplo n.º 1
0
        public static object Fetch(RubyContext /*!*/ context, BlockParam block, IDictionary <object, object> /*!*/ self, object key, [Optional] object defaultValue)
        {
            object result;

            if (self.TryGetValue(CustomStringDictionary.NullToObj(key), out result))
            {
                return(result);
            }

            if (block != null)
            {
                if (defaultValue != Missing.Value)
                {
                    context.ReportWarning("block supersedes default value argument");
                }

                block.Yield(key, out result);
                return(result);
            }

            if (defaultValue == Missing.Value)
            {
                throw RubyExceptions.CreateIndexError("key not found");
            }

            return(defaultValue);
        }
Ejemplo n.º 2
0
        public static object Power(RubyContext /*!*/ context, BigInteger /*!*/ self, [NotNull] BigInteger /*!*/ exponent)
        {
            context.ReportWarning("in a**b, b may be too big");
            double result = Math.Pow(self.ToFloat64(), exponent.ToFloat64());

            return(result);
        }
Ejemplo n.º 3
0
 public static RubyEncoding TryParseEncoding(RubyContext /*!*/ context, string /*!*/ str)
 {
     try {
         return(context.GetRubyEncoding(str));
     } catch (ArgumentException) {
         context.ReportWarning(String.Format("Unsupported encoding {0} ignored", str));
         return(null);
     }
 }
Ejemplo n.º 4
0
 public static double ToFloat(RubyContext /*!*/ context, BigInteger /*!*/ self)
 {
     try {
         return(self.ToFloat64());
     } catch (OverflowException) {
         // If the BigInteger is too big for a float then we return infinity.
         context.ReportWarning("Bignum out of Float range");
         return(self.Sign > 0 ? Double.PositiveInfinity : Double.NegativeInfinity);
     }
 }
Ejemplo n.º 5
0
        public static double ConvertToDouble(RubyContext /*!*/ context, BigInteger /*!*/ bignum)
        {
            double result;

            if (bignum.TryToFloat64(out result))
            {
                return(result);
            }
            context.ReportWarning("Bignum out of Float range");
            return(bignum.Sign > 0 ? Double.PositiveInfinity : Double.NegativeInfinity);
        }
Ejemplo n.º 6
0
        public bool GetCurrentDst(RubyContext /*!*/ context)
        {
            var zone = _CurrentTimeZone;

            if (zone is TZ)
            {
                var stdName = zone.StandardName;
                zone = TimeZone.CurrentTimeZone;

                context.ReportWarning(String.Format(CultureInfo.InvariantCulture,
                                                    "Daylight savings rule not available for time zone `{0}'; using the default time zone `{1}'", stdName, zone.StandardName
                                                    ));
            }
            return(zone.IsDaylightSavingTime(_dateTime));
        }
Ejemplo n.º 7
0
        private static void SetEnvironmentVariable(RubyContext/*!*/ context, string/*!*/ name, string value) {
            context.DomainManager.Platform.SetEnvironmentVariable(name, value);
#if !SILVERLIGHT
            if (name == "TZ") {
                TimeZone zone;
                if (RubyTime.TryParseTimeZone(value, out zone)) {
                    RubyTime._CurrentTimeZone = zone;
                } else {
                    context.ReportWarning(String.Format(CultureInfo.InvariantCulture,
                        "`{0}' is not a valid time zone specification; using the current time zone `{1}'", 
                        value, 
                        RubyTime._CurrentTimeZone.StandardName
                    ));
                }
            }
#endif
        }
Ejemplo n.º 8
0
            private void CheckPreamble()
            {
                int major = _reader.ReadByte();
                int minor = _reader.ReadByte();

                if (major != MAJOR_VERSION || minor > MINOR_VERSION)
                {
                    string message = String.Format(
                        "incompatible marshal file format (can't be read)\n\tformat version {0}.{1} required; {2}.{3} given",
                        MAJOR_VERSION, MINOR_VERSION, major, minor);
                    throw RubyExceptions.CreateTypeError(message);
                }
                if (minor < MINOR_VERSION)
                {
                    string message = String.Format(
                        "incompatible marshal file format (can be read)\n\tformat version {0}.{1} required; {2}.{3} given",
                        MAJOR_VERSION, MINOR_VERSION, major, minor);
                    _context.ReportWarning(message);
                }
            }
Ejemplo n.º 9
0
        public IOInfo AddEncoding(RubyContext /*!*/ context, MutableString /*!*/ encoding)
        {
            if (!encoding.IsAscii())
            {
                context.ReportWarning(String.Format("Unsupported encoding {0} ignored", encoding.ToAsciiString()));
                return(this);
            }

            if (HasEncoding)
            {
                throw RubyExceptions.CreateArgumentError("encoding specified twice");
            }

            string[] parts = encoding.ToString().Split(':');
            return(new IOInfo(
                       _mode,
                       TryParseEncoding(context, parts[0]),
                       (parts.Length > 1) ? TryParseEncoding(context, parts[1]) : null
                       ));
        }
Ejemplo n.º 10
0
        private static void SetEnvironmentVariable(RubyContext /*!*/ context, string /*!*/ name, string value)
        {
            context.DomainManager.Platform.SetEnvironmentVariable(name, value);
#if !SILVERLIGHT
            if (name == "TZ")
            {
                TimeZone zone;
                if (RubyTime.TryParseTimeZone(value, out zone))
                {
                    RubyTime._CurrentTimeZone = zone;
                }
                else
                {
                    context.ReportWarning(String.Format(CultureInfo.InvariantCulture,
                                                        "`{0}' is not a valid time zone specification; using the current time zone `{1}'",
                                                        value,
                                                        RubyTime._CurrentTimeZone.StandardName
                                                        ));
                }
            }
#endif
        }
Ejemplo n.º 11
0
        public override void SetValue(RubyContext/*!*/ context, RubyScope scope, string/*!*/ name, object value) {
            switch (_id) {
                // regex:
                case GlobalVariableId.MatchData:
                    if (scope == null) {
                        throw ReadOnlyError(name);
                    }

                    scope.GetInnerMostClosureScope().CurrentMatch = (value != null) ? RequireType<MatchData>(value, name, "MatchData") : null;
                    return;

                case GlobalVariableId.MatchLastGroup:
                case GlobalVariableId.PreMatch:
                case GlobalVariableId.PostMatch:
                case GlobalVariableId.EntireMatch:
                    throw ReadOnlyError(name);
                
                
                // exceptions:
                case GlobalVariableId.CurrentException:
                    context.SetCurrentException(value);
                    return;

                case GlobalVariableId.CurrentExceptionBacktrace:
                    context.SetCurrentExceptionBacktrace(value);
                    return;


                // input:
                case GlobalVariableId.LastInputLine:
                    if (scope == null) {
                        throw ReadOnlyError(name);
                    }
                    scope.GetInnerMostClosureScope().LastInputLine = value;
                    return;

                case GlobalVariableId.LastInputLineNumber:
                    context.InputProvider.LastInputLineNumber = RequireType<int>(value, name, "Fixnum");
                    return;

                case GlobalVariableId.CommandLineArguments:
                case GlobalVariableId.InputFileName:
                    throw ReadOnlyError(name);

                // output:
                case GlobalVariableId.OutputStream:
                    context.StandardOutput = RequireWriteProtocol(context, value, name);
                    return;

                case GlobalVariableId.ErrorOutputStream:
                    context.StandardErrorOutput = RequireWriteProtocol(context, value, name);
                    break;

                case GlobalVariableId.InputStream:
                    context.StandardInput = value;
                    return;

                // separators:
                case GlobalVariableId.InputContent:
                    throw ReadOnlyError(name);

                case GlobalVariableId.InputSeparator:
                    context.InputSeparator = (value != null) ? RequireType<MutableString>(value, name, "String") : null;
                    return;

                case GlobalVariableId.OutputSeparator:
                    context.OutputSeparator = (value != null) ? RequireType<MutableString>(value, name, "String") : null;
                    return;

                case GlobalVariableId.StringSeparator:
                    // type not enforced:
                    context.StringSeparator = value;
                    return;

                case GlobalVariableId.ItemSeparator:
                    context.ItemSeparator = (value != null) ? RequireType<MutableString>(value, name, "String") : null;
                    return;


                // loader:
                case GlobalVariableId.LoadedFiles:
                case GlobalVariableId.LoadPath:
                    throw ReadOnlyError(name);


                // misc:
                case GlobalVariableId.SafeLevel:
                    context.SetSafeLevel(RequireType<int>(value, name, "Fixnum"));
                    return;

                case GlobalVariableId.Verbose:
                    context.Verbose = value;
                    return;

                case GlobalVariableId.CommandLineProgramPath:
                    context.CommandLineProgramPath = (value != null) ? RequireType<MutableString>(value, name, "String") : null;
                    return;
                
                case GlobalVariableId.KCode:
                    context.ReportWarning("variable $KCODE is no longer effective");
                    return;

                case GlobalVariableId.ChildProcessExitStatus:
                    throw ReadOnlyError(name);
                    
                default:
                    throw Assert.Unreachable;
            }
        }
Ejemplo n.º 12
0
 public static object GetId(RubyContext/*!*/ context, object self) {
     context.ReportWarning("Object#id will be deprecated; use Object#object_id");
     return GetObjectId(context, self);
 }
Ejemplo n.º 13
0
 public static object Power(RubyContext/*!*/ context, BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ exponent) {
     context.ReportWarning("in a**b, b may be too big");
     double result = System.Math.Pow(self.ToFloat64(), exponent.ToFloat64());
     return result;
 }
Ejemplo n.º 14
0
 public static double ToFloat(RubyContext/*!*/ context, BigInteger/*!*/ self) {
     try {
         return self.ToFloat64();
     } catch (OverflowException) {
         // If the BigInteger is too big for a float then we return infinity.
         context.ReportWarning("Bignum out of Float range");
         return self.Sign > 0 ? Double.PositiveInfinity : Double.NegativeInfinity;
     }
 }
Ejemplo n.º 15
0
 public static RubyArray/*!*/ Index(RubyContext/*!*/ context, object/*!*/ self, [NotNull]params object[]/*!*/ keys) {
     context.ReportWarning("ENV.indexes is deprecated; use ENV.values_at");
     return ValuesAt(context, self, keys);
 }
Ejemplo n.º 16
0
        [Emitted] // ProtocolConversionAction
        public static string/*!*/ ConvertFixnumToSymbol(RubyContext/*!*/ context, int value) {
            context.ReportWarning("do not use Fixnums as Symbols");

            SymbolId result;
            if (TryConvertFixnumToSymbol(value, out result)) {
                return SymbolTable.IdToString(result);
            } else {
                throw RubyExceptions.CreateArgumentError(String.Format("{0} is not a symbol", value));
            }
        }
Ejemplo n.º 17
0
        public override void SetValue(RubyContext /*!*/ context, RubyScope scope, string /*!*/ name, object value)
        {
            switch (_id)
            {
            // regex:
            case GlobalVariableId.MatchData:
                if (scope == null)
                {
                    throw ReadOnlyError(name);
                }

                scope.GetInnerMostClosureScope().CurrentMatch = (value != null) ? RequireType <MatchData>(value, name, "MatchData") : null;
                return;

            case GlobalVariableId.MatchLastGroup:
            case GlobalVariableId.PreMatch:
            case GlobalVariableId.PostMatch:
            case GlobalVariableId.EntireMatch:
                throw ReadOnlyError(name);


            // exceptions:
            case GlobalVariableId.CurrentException:
                context.SetCurrentException(value);
                return;

            case GlobalVariableId.CurrentExceptionBacktrace:
                context.SetCurrentExceptionBacktrace(value);
                return;


            // input:
            case GlobalVariableId.LastInputLine:
                if (scope == null)
                {
                    throw ReadOnlyError(name);
                }
                scope.GetInnerMostClosureScope().LastInputLine = value;
                return;

            case GlobalVariableId.LastInputLineNumber:
                context.InputProvider.LastInputLineNumber = RequireType <int>(value, name, "Fixnum");
                return;

            case GlobalVariableId.CommandLineArguments:
            case GlobalVariableId.InputFileName:
                throw ReadOnlyError(name);

            // output:
            case GlobalVariableId.OutputStream:
                context.StandardOutput = RequireWriteProtocol(context, value, name);
                return;

            case GlobalVariableId.ErrorOutputStream:
                context.StandardErrorOutput = RequireWriteProtocol(context, value, name);
                break;

            case GlobalVariableId.InputStream:
                context.StandardInput = value;
                return;

            // separators:
            case GlobalVariableId.InputContent:
                throw ReadOnlyError(name);

            case GlobalVariableId.InputSeparator:
                context.InputSeparator = (value != null) ? RequireType <MutableString>(value, name, "String") : null;
                return;

            case GlobalVariableId.OutputSeparator:
                context.OutputSeparator = (value != null) ? RequireType <MutableString>(value, name, "String") : null;
                return;

            case GlobalVariableId.StringSeparator:
                // type not enforced:
                context.StringSeparator = value;
                return;

            case GlobalVariableId.ItemSeparator:
                context.ItemSeparator = (value != null) ? RequireType <MutableString>(value, name, "String") : null;
                return;


            // loader:
            case GlobalVariableId.LoadedFiles:
            case GlobalVariableId.LoadPath:
                throw ReadOnlyError(name);


            // misc:
            case GlobalVariableId.SafeLevel:
                context.SetSafeLevel(RequireType <int>(value, name, "Fixnum"));
                return;

            case GlobalVariableId.Verbose:
                context.Verbose = value;
                return;

            case GlobalVariableId.CommandLineProgramPath:
                context.CommandLineProgramPath = (value != null) ? RequireType <MutableString>(value, name, "String") : null;
                return;

            case GlobalVariableId.KCode:
                context.ReportWarning("variable $KCODE is no longer effective");
                return;

            case GlobalVariableId.ChildProcessExitStatus:
                throw ReadOnlyError(name);

            default:
                throw Assert.Unreachable;
            }
        }
Ejemplo n.º 18
0
        public override object GetValue(RubyContext /*!*/ context, RubyScope scope)
        {
            switch (_id)
            {
            // regular expressions:
            case GlobalVariableId.MatchData:
                return((scope != null) ? scope.GetInnerMostClosureScope().CurrentMatch : null);

            case GlobalVariableId.MatchLastGroup:
                return((scope != null) ? scope.GetInnerMostClosureScope().GetCurrentMatchLastGroup() : null);

            case GlobalVariableId.PreMatch:
                return((scope != null) ? scope.GetInnerMostClosureScope().GetCurrentPreMatch() : null);

            case GlobalVariableId.PostMatch:
                return((scope != null) ? scope.GetInnerMostClosureScope().GetCurrentPostMatch() : null);

            case GlobalVariableId.EntireMatch:
                return((scope != null) ? scope.GetInnerMostClosureScope().GetCurrentMatchGroup(0) : null);


            // exceptions:
            case GlobalVariableId.CurrentException:
                return(context.CurrentException);

            case GlobalVariableId.CurrentExceptionBacktrace:
                return(context.GetCurrentExceptionBacktrace());


            // input:
            case GlobalVariableId.InputContent:
                return(context.InputProvider.Singleton);

            case GlobalVariableId.InputFileName:
                return(context.InputProvider.CurrentFileName);

            case GlobalVariableId.LastInputLine:
                return((scope != null) ? scope.GetInnerMostClosureScope().LastInputLine : null);

            case GlobalVariableId.LastInputLineNumber:
                return(context.InputProvider.LastInputLineNumber);

            case GlobalVariableId.CommandLineArguments:
                return(context.InputProvider.CommandLineArguments);


            // output:
            case GlobalVariableId.OutputStream:
                return(context.StandardOutput);

            case GlobalVariableId.ErrorOutputStream:
                return(context.StandardErrorOutput);

            case GlobalVariableId.InputStream:
                return(context.StandardInput);


            // separators:
            case GlobalVariableId.InputSeparator:
                return(context.InputSeparator);

            case GlobalVariableId.OutputSeparator:
                return(context.OutputSeparator);

            case GlobalVariableId.StringSeparator:
                return(context.StringSeparator);

            case GlobalVariableId.ItemSeparator:
                return(context.ItemSeparator);


            // loader:
            case GlobalVariableId.LoadPath:
                return(context.Loader.LoadPaths);

            case GlobalVariableId.LoadedFiles:
                return(context.Loader.LoadedFiles);


            // misc:
            case GlobalVariableId.SafeLevel:
                return(context.CurrentSafeLevel);

            case GlobalVariableId.Verbose:
                return(context.Verbose);

            case GlobalVariableId.KCode:
                if (context.RubyOptions.Compatibility < RubyCompatibility.Ruby19)
                {
                    var kcode = KCoding.GetKCodeName(context.KCode);
                    Utils.Log("KCODE set to " + kcode, "KCODE");
                    return(MutableString.CreateAscii(kcode));
                }

                context.ReportWarning("variable $KCODE is no longer effective");
                return(null);

            case GlobalVariableId.ChildProcessExitStatus:
                return(context.ChildProcessExitStatus);

            case GlobalVariableId.CommandLineProgramPath:
                return(context.CommandLineProgramPath);

            default:
                throw Assert.Unreachable;
            }
        }
Ejemplo n.º 19
0
        public IOInfo AddEncoding(RubyContext/*!*/ context, MutableString/*!*/ encoding) {
            if (!encoding.IsAscii()) {
                context.ReportWarning(String.Format("Unsupported encoding {0} ignored", encoding.ToAsciiString(false)));
                return this;
            }

            if (HasEncoding) {
                throw RubyExceptions.CreateArgumentError("encoding specified twice");
            }

            string[] parts = encoding.ToString().Split(':');
            return new IOInfo(
                _mode,
                TryParseEncoding(context, parts[0]),
                (parts.Length > 1) ? TryParseEncoding(context, parts[1]) : null
            );
        }
Ejemplo n.º 20
0
        public override void SetValue(RubyContext/*!*/ context, RubyScope scope, string/*!*/ name, object value) {
            switch (_id) {
                // regex:
                case GlobalVariableId.MatchData:
                    if (scope == null) {
                        throw ReadOnlyError(name);
                    }

                    scope.GetInnerMostClosureScope().CurrentMatch = (value != null) ? RequireType<MatchData>(value, name, "MatchData") : null;
                    return;

                case GlobalVariableId.MatchLastGroup:
                case GlobalVariableId.MatchPrefix:
                case GlobalVariableId.MatchSuffix:
                case GlobalVariableId.EntireMatch:
                    throw ReadOnlyError(name);
                
                
                // exceptions:
                case GlobalVariableId.CurrentException:
                    context.SetCurrentException(value);
                    return;

                case GlobalVariableId.CurrentExceptionBacktrace:
                    context.SetCurrentExceptionBacktrace(value);
                    return;


                // input:
                case GlobalVariableId.LastInputLine:
                    if (scope == null) {
                        throw ReadOnlyError(name);
                    }
                    scope.GetInnerMostClosureScope().LastInputLine = value;
                    return;

                case GlobalVariableId.LastInputLineNumber:
                    context.InputProvider.LastInputLineNumber = RequireType<int>(value, name, "Fixnum");
                    return;

                case GlobalVariableId.CommandLineArguments:
                case GlobalVariableId.InputFileName:
                    throw ReadOnlyError(name);

                // output:
                case GlobalVariableId.OutputStream:
                    context.StandardOutput = RequireWriteProtocol(context, value, name);
                    return;

                case GlobalVariableId.ErrorOutputStream:
                    context.StandardErrorOutput = RequireWriteProtocol(context, value, name);
                    break;

                case GlobalVariableId.InputStream:
                    context.StandardInput = value;
                    return;

                // separators:
                case GlobalVariableId.InputContent:
                    throw ReadOnlyError(name);

                case GlobalVariableId.InputSeparator:
                    context.InputSeparator = (value != null) ? RequireType<MutableString>(value, name, "String") : null;
                    return;

                case GlobalVariableId.OutputSeparator:
                    context.OutputSeparator = (value != null) ? RequireType<MutableString>(value, name, "String") : null;
                    return;

                case GlobalVariableId.StringSeparator:
                    // type not enforced:
                    context.StringSeparator = value;
                    return;

                case GlobalVariableId.ItemSeparator:
                    context.ItemSeparator = (value != null) ? RequireType<MutableString>(value, name, "String") : null;
                    return;


                // loader:
                case GlobalVariableId.LoadedFiles:
                case GlobalVariableId.LoadPath:
                    throw ReadOnlyError(name);


                // misc:
                case GlobalVariableId.SafeLevel:
                    context.SetSafeLevel(RequireType<int>(value, name, "Fixnum"));
                    return;

                case GlobalVariableId.Verbose:
                    context.Verbose = value;
                    return;

                case GlobalVariableId.CommandLineProgramPath:
                    context.CommandLineProgramPath = (value != null) ? RequireType<MutableString>(value, name, "String") : null;
                    return;
                
                case GlobalVariableId.KCode:
#if !SILVERLIGHT
                    if (context.RubyOptions.Compatibility == RubyCompatibility.Ruby18) {
                        // MRI calls to_str; we don't do that, it's inconsistent with other globals.
                        // If some app depends on this behavior, it will fail gracefully:
                        context.KCode = RubyEncoding.GetKCodingByNameInitial(RequireType<MutableString>(value, name, "String").GetFirstChar());
                        Utils.Log(String.Format("Set to {0}", context.KCode), "KCODE");
                        return;
                    }
#endif
                    context.ReportWarning("variable $KCODE is no longer effective");
                    return;

                case GlobalVariableId.ChildProcessExitStatus:
                    throw ReadOnlyError(name);
                    
                default:
                    throw Assert.Unreachable;
            }
        }
Ejemplo n.º 21
0
 public static RubyArray /*!*/ Index(RubyContext /*!*/ context, object /*!*/ self,
                                     [DefaultProtocol, NotNullItems] params MutableString /*!*/[] /*!*/ keys)
 {
     context.ReportWarning("ENV.indexes is deprecated; use ENV.values_at");
     return(ValuesAt(context, self, keys));
 }
Ejemplo n.º 22
0
 public static object Indexes(RubyContext/*!*/ context, IList/*!*/ self, [NotNull]params object[] args) {
     context.ReportWarning("Array#indexes and Array#indices are deprecated; use Array#values_at");
     return GetIndicesAsNestedArrays(context, self, args);
 }
Ejemplo n.º 23
0
        public static object ReadInputCharacter(UnaryOpStorage/*!*/ getcStorage, RubyContext/*!*/ context, object self) {

            context.ReportWarning("getc is obsolete; use STDIN.getc instead");
            var site = getcStorage.GetCallSite("getc", 0);
            return site.Target(site, context, context.StandardInput);
        }
Ejemplo n.º 24
0
 public static RubyClass/*!*/ GetClassObsolete(RubyContext/*!*/ context, object self) {
     context.ReportWarning("Object#type will be deprecated; use Object#class");
     return context.GetClassOf(self);
 }
Ejemplo n.º 25
0
 public static RubyArray /*!*/ Index(RubyContext /*!*/ context, object /*!*/ self, [NotNull] params object[] /*!*/ keys)
 {
     context.ReportWarning("ENV.indexes is deprecated; use ENV.values_at");
     return(ValuesAt(context, self, keys));
 }
Ejemplo n.º 26
0
        public override void SetValue(RubyContext /*!*/ context, RubyScope scope, string /*!*/ name, object value)
        {
            switch (_id)
            {
            // regex:
            case GlobalVariableId.MatchData:
                if (scope == null)
                {
                    throw ReadOnlyError(name);
                }

                scope.GetInnerMostClosureScope().CurrentMatch = (value != null) ? RequireType <MatchData>(value, name, "MatchData") : null;
                return;

            case GlobalVariableId.MatchLastGroup:
            case GlobalVariableId.PreMatch:
            case GlobalVariableId.PostMatch:
            case GlobalVariableId.EntireMatch:
                throw ReadOnlyError(name);


            // exceptions:
            case GlobalVariableId.CurrentException:
                context.SetCurrentException(value);
                return;

            case GlobalVariableId.CurrentExceptionBacktrace:
                context.SetCurrentExceptionBacktrace(value);
                return;


            // input:
            case GlobalVariableId.LastInputLine:
                if (scope == null)
                {
                    throw ReadOnlyError(name);
                }
                scope.GetInnerMostClosureScope().LastInputLine = value;
                return;

            case GlobalVariableId.LastInputLineNumber:
                context.InputProvider.LastInputLineNumber = RequireType <int>(value, name, "Fixnum");
                return;

            case GlobalVariableId.CommandLineArguments:
            case GlobalVariableId.InputFileName:
                throw ReadOnlyError(name);

            // output:
            case GlobalVariableId.OutputStream:
                context.StandardOutput = RequireWriteProtocol(context, value, name);
                return;

            case GlobalVariableId.ErrorOutputStream:
                context.StandardErrorOutput = RequireWriteProtocol(context, value, name);
                break;

            case GlobalVariableId.InputStream:
                context.StandardInput = value;
                return;

            // separators:
            case GlobalVariableId.InputContent:
                throw ReadOnlyError(name);

            case GlobalVariableId.InputSeparator:
                context.InputSeparator = (value != null) ? RequireType <MutableString>(value, name, "String") : null;
                return;

            case GlobalVariableId.OutputSeparator:
                context.OutputSeparator = (value != null) ? RequireType <MutableString>(value, name, "String") : null;
                return;

            case GlobalVariableId.StringSeparator:
                // type not enforced:
                context.StringSeparator = value;
                return;

            case GlobalVariableId.ItemSeparator:
                context.ItemSeparator = (value != null) ? RequireType <MutableString>(value, name, "String") : null;
                return;


            // loader:
            case GlobalVariableId.LoadedFiles:
            case GlobalVariableId.LoadPath:
                throw ReadOnlyError(name);


            // misc:
            case GlobalVariableId.SafeLevel:
                context.SetSafeLevel(RequireType <int>(value, name, "Fixnum"));
                return;

            case GlobalVariableId.Verbose:
                context.Verbose = value;
                return;

            case GlobalVariableId.CommandLineProgramPath:
                context.CommandLineProgramPath = (value != null) ? RequireType <MutableString>(value, name, "String") : null;
                return;

            case GlobalVariableId.KCode:
                if (context.RubyOptions.Compatibility < RubyCompatibility.Ruby19)
                {
                    // MRI calls to_str; we don't do that, it's inconsistent with other globals.
                    // If some app depends on this behavior, it will fail gracefully:
                    context.KCode = RubyEncoding.GetKCodingByNameInitial(RequireType <MutableString>(value, name, "String").GetFirstChar());
                    Utils.Log(String.Format("Set to {0}", context.KCode), "KCODE");
                    return;
                }

                context.ReportWarning("variable $KCODE is no longer effective");
                return;

            case GlobalVariableId.ChildProcessExitStatus:
                throw ReadOnlyError(name);

            default:
                throw Assert.Unreachable;
            }
        }
Ejemplo n.º 27
0
 private static void ReportParametersIgnoredWarning(RubyContext/*!*/ context, object encoding) {
     context.ReportWarning((encoding != Missing.Value) ? "flags and encoding ignored" : "flags ignored");
 }
Ejemplo n.º 28
0
        public static object Indexes(ConversionStorage<int>/*!*/ fixnumCast, 
            CallSiteStorage<Func<CallSite, RubyContext, RubyClass, object>>/*!*/ allocateStorage,
            RubyContext/*!*/ context, IList/*!*/ self, [NotNull]params object[]/*!*/ values) {
            context.ReportWarning("Array#indexes and Array#indices are deprecated; use Array#values_at");

            RubyArray result = new RubyArray();

            for (int i = 0; i < values.Length; ++i) {
                Range range = values[i] as Range;
                if (range != null) {
                    IList fragment = GetElement(fixnumCast, allocateStorage, context, self, range);
                    if (fragment != null) {
                        result.Add(fragment);
                    }
                } else {
                    result.Add(GetElement(self, Protocols.CastToFixnum(fixnumCast, context, values[i])));
                }
            }

            return result;

        }
Ejemplo n.º 29
0
        public static object Fetch(RubyContext/*!*/ context, BlockParam outOfRangeValueProvider, IList/*!*/ list, [DefaultProtocol]int index, [Optional]object defaultValue) {
            int oldIndex = index;
            if (InRangeNormalized(list, ref index)) {
                return list[index];
            }

            if (outOfRangeValueProvider != null) {
                if (defaultValue != Missing.Value) {
                    context.ReportWarning("block supersedes default value argument");
                }

                object result;
                outOfRangeValueProvider.Yield(oldIndex, out result);
                return result;
            }
            
            if (defaultValue == Missing.Value) {
                throw RubyExceptions.CreateIndexError("index " + index + " out of array");
            }
            return defaultValue;
        }
Ejemplo n.º 30
0
 public static RubyEncoding TryParseEncoding(RubyContext/*!*/ context, string/*!*/ str) {
     try {
         return context.GetRubyEncoding(str);
     } catch (ArgumentException) {
         context.ReportWarning(String.Format("Unsupported encoding {0} ignored", str));
         return null;
     }
 }
Ejemplo n.º 31
0
 public static RubyArray /*!*/ Indexes(RubyContext /*!*/ context, IDictionary <object, object> /*!*/ self, params object[] /*!*/ keys)
 {
     context.ReportWarning("Hash#indices is deprecated; use Hash#values_at");
     return(ValuesAt(context, self, keys));
 }
Ejemplo n.º 32
0
 public static double ConvertToDouble(RubyContext/*!*/ context, BigInteger/*!*/ bignum) {
     double result;
     if (bignum.TryToFloat64(out result)) {
         return result;
     }
     context.ReportWarning("Bignum out of Float range");
     return bignum.Sign > 0 ? Double.PositiveInfinity : Double.NegativeInfinity;
 }
Ejemplo n.º 33
0
 private static void ReportParametersIgnoredWarning(RubyContext /*!*/ context, object encoding)
 {
     context.ReportWarning((encoding != Missing.Value) ? "flags and encoding ignored" : "flags ignored");
 }
Ejemplo n.º 34
0
        public override object GetValue(RubyContext/*!*/ context, RubyScope scope) {
            switch (_id) {
                
                // regular expressions:
                case GlobalVariableId.MatchData:
                    return (scope != null) ? scope.GetInnerMostClosureScope().CurrentMatch : null;

                case GlobalVariableId.MatchLastGroup:
                    return (scope != null) ? scope.GetInnerMostClosureScope().GetCurrentMatchLastGroup() : null;

                case GlobalVariableId.MatchPrefix:
                    // TODO:
                    throw new NotImplementedException();

                case GlobalVariableId.MatchSuffix:
                    // TODO:
                    throw new NotImplementedException();

                case GlobalVariableId.EntireMatch:
                    return (scope != null) ? scope.GetInnerMostClosureScope().GetCurrentMatchGroup(0) : null;


                // exceptions:
                case GlobalVariableId.CurrentException:
                    return context.CurrentException;

                case GlobalVariableId.CurrentExceptionBacktrace:
                    return context.GetCurrentExceptionBacktrace();


                // input:
                case GlobalVariableId.InputContent:
                    return context.InputProvider.Singleton;

                case GlobalVariableId.InputFileName:
                    return context.InputProvider.CurrentFileName;

                case GlobalVariableId.LastInputLine:
                    return (scope != null) ? scope.GetInnerMostClosureScope().LastInputLine : null;

                case GlobalVariableId.LastInputLineNumber:
                    return context.InputProvider.LastInputLineNumber;

                case GlobalVariableId.CommandLineArguments:
                    return context.InputProvider.CommandLineArguments;


                // output:
                case GlobalVariableId.OutputStream:
                    return context.StandardOutput;

                case GlobalVariableId.ErrorOutputStream:
                    return context.StandardErrorOutput;

                case GlobalVariableId.InputStream:
                    return context.StandardInput;


                // separators:
                case GlobalVariableId.InputSeparator:
                    return context.InputSeparator;

                case GlobalVariableId.OutputSeparator:
                    return context.OutputSeparator;

                case GlobalVariableId.StringSeparator:
                    return context.StringSeparator;

                case GlobalVariableId.ItemSeparator:
                    return context.ItemSeparator;

                
                // loader:
                case GlobalVariableId.LoadPath:
                    return context.Loader.LoadPaths;

                case GlobalVariableId.LoadedFiles:
                    return context.Loader.LoadedFiles;


                // misc:
                case GlobalVariableId.SafeLevel:
                    return context.CurrentSafeLevel;

                case GlobalVariableId.Verbose:
                    return context.Verbose;

                case GlobalVariableId.KCode:
#if !SILVERLIGHT
                    if (context.RubyOptions.Compatibility == RubyCompatibility.Ruby18) {
                        return MutableString.Create(KCoding.GetKCodeName(context.KCode));
                    }
#endif
                    context.ReportWarning("variable $KCODE is no longer effective");
                    return null;

                case GlobalVariableId.ChildProcessExitStatus:
                    return context.ChildProcessExitStatus;

                case GlobalVariableId.CommandLineProgramPath:
                    return context.CommandLineProgramPath;

                default:
                    throw Assert.Unreachable;
            }
        }
Ejemplo n.º 35
0
 public static RubyArray/*!*/ Index(RubyContext/*!*/ context, object/*!*/ self,
     [DefaultProtocol, NotNull, NotNullItems]params MutableString[]/*!*/ keys) {
     context.ReportWarning("ENV.indexes is deprecated; use ENV.values_at");
     return ValuesAt(context, self, keys);
 }