// We don't define "dup" here because "dup" shouldn't show up on builtin types like Hash // (Kernel#dup just works for these types) private static IDictionary <object, object> /*!*/ Duplicate(RubyContext /*!*/ context, IDictionary <object, object> /*!*/ self) { // Call Kernel#dup, then copy items var copy = (IDictionary <object, object>)KernelOps.Duplicate(context, self); return(ReplaceData(copy, self)); }
public static void PrintFormatted( StringFormatterSiteStorage /*!*/ storage, ConversionStorage <MutableString> /*!*/ stringCast, BinaryOpStorage /*!*/ writeStorage, object /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ format, params object[] /*!*/ args) { KernelOps.PrintFormatted(storage, stringCast, writeStorage, null, self, format, args); }
public static object MethodMissing(RubyScope /*!*/ scope, BlockParam block, string /*!*/ self, [NotNull] RubySymbol /*!*/ name, params object[] /*!*/ args) { if (name.EndsWith('=') || name.EndsWith('!')) { throw RubyExceptions.CreateTypeError("Mutating method `{0}' called for an immutable string (System::String)", name); } // TODO: forward to MutableString until we implement the methods here: return(KernelOps.SendMessageOpt(scope, block, ToStr(self), name.ToString(), args)); }
// We don't define "dup" here because "dup" shouldn't show up on builtin types like Hash // (Kernel#dup just works for these types) private static IDictionary <object, object> /*!*/ Duplicate( CallSiteStorage <Func <CallSite, object, object, object> > /*!*/ initializeCopyStorage, CallSiteStorage <Func <CallSite, RubyClass, object> > /*!*/ allocateStorage, IDictionary <object, object> /*!*/ self) { // Call Kernel#dup, then copy items var copy = (IDictionary <object, object>)KernelOps.Duplicate(initializeCopyStorage, allocateStorage, self); return(ReplaceData(copy, self)); }
public static MutableString Gets(RubyScope /*!*/ scope, RubyIO /*!*/ self, [DefaultProtocol] MutableString separator) { MutableString result = self.ReadLineOrParagraph(separator); KernelOps.Taint(scope.RubyContext, result); scope.GetInnerMostClosureScope().LastInputLine = result; scope.RubyContext.InputProvider.IncrementLastInputLineNumber(); return(result); }
private void AppendString() { MutableString /*!*/ str = _siteStorage.ConvertToString(_opts.Value); if (KernelOps.Tainted(_context, str)) { _tainted = true; } AppendString(str); }
private void AppendInspect() { MutableString inspect = RubySites.Inspect(_context, _opts.Value); if (KernelOps.Tainted(_context, inspect)) { _tainted = true; } AppendString(inspect); }
private void AppendInspect() { MutableString result = _context.Inspect(_opts.Value); if (KernelOps.Tainted(_context, result)) { _tainted = true; } AppendString(result); }
public void InitializeLibrary(RubyScope scope) { KernelOps.Require(scope, this, MutableString.CreateAscii("json/common")); _maxNesting = scope.RubyContext.CreateAsciiSymbol("max_nesting"); _allowNan = scope.RubyContext.CreateAsciiSymbol("allow_nan"); _jsonCreatable = scope.RubyContext.CreateAsciiSymbol("json_creatable?"); _jsonCreate = scope.RubyContext.CreateAsciiSymbol("json_create"); _createId = scope.RubyContext.CreateAsciiSymbol("create_id"); _createAdditions = scope.RubyContext.CreateAsciiSymbol("create_additions"); _chr = scope.RubyContext.CreateAsciiSymbol("chr"); }
internal static void AddYamlProperties(RubyContext /*!*/ context, object self, Hash map, RubyArray props) { foreach (object prop in props) { string p = prop.ToString(); IDictionaryOps.SetElement( context, map, MutableString.Create(p.Substring(1)), KernelOps.InstanceVariableGet(context, self, p) ); } }
public static RubyIO /*!*/ OpenPipe(RubyContext /*!*/ context, RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ command, [DefaultProtocol, Optional, NotNull] MutableString modeString) { bool preserveEndOfLines; IOMode mode = RubyIO.ParseIOMode(modeString.ConvertToString(), out preserveEndOfLines); ProcessStartInfo startInfo = KernelOps.GetShell(context, command); startInfo.UseShellExecute = false; if (mode == IOMode.ReadOnlyFromStart) { startInfo.RedirectStandardOutput = true; } else if (mode == IOMode.WriteOnlyAppend || mode == IOMode.WriteOnlyTruncate) { startInfo.RedirectStandardInput = true; } else { startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardInput = true; } Process process; try { process = Process.Start(startInfo); } catch (Exception e) { throw new Errno.NoEntryError(startInfo.FileName, e); } context.ChildProcessExitStatus = new RubyProcess.Status(process); StreamReader reader = null; StreamWriter writer = null; if (startInfo.RedirectStandardOutput) { reader = process.StandardOutput; } if (startInfo.RedirectStandardInput) { writer = process.StandardInput; } return(new RubyIO(context, reader, writer, modeString.ConvertToString())); }
public static void RaiseException(Thread /*!*/ self, [NotNull] MutableString /*!*/ message) { if (self == Thread.CurrentThread) { KernelOps.RaiseException(self, message); return; } #if SILVERLIGHT throw new NotImplementedError("Thread#raise is not implemented on Silverlight"); #else Exception e = RubyExceptionData.InitializeException(new RuntimeError(message.ToString()), message); RaiseAsyncException(self, e); #endif }
public static void RaiseException(Thread /*!*/ self, [NotNull] MutableString /*!*/ message) { if (self == Thread.CurrentThread) { KernelOps.RaiseException(self, message); return; } #if FEATURE_EXCEPTION_STATE Exception e = RubyExceptionData.InitializeException(new RuntimeError(message.ToString()), message); RaiseAsyncException(self, e); #else throw new NotImplementedError("Thread#raise not supported on this platform"); #endif }
public static void RaiseException(RespondToStorage /*!*/ respondToStorage, UnaryOpStorage /*!*/ storage0, BinaryOpStorage /*!*/ storage1, CallSiteStorage <Action <CallSite, Exception, RubyArray> > /*!*/ setBackTraceStorage, Thread /*!*/ self, object /*!*/ obj, [Optional] object arg, [Optional] RubyArray backtrace) { if (self == Thread.CurrentThread) { KernelOps.RaiseException(respondToStorage, storage0, storage1, setBackTraceStorage, self, obj, arg, backtrace); return; } #if FEATURE_EXCEPTION_STATE Exception e = KernelOps.CreateExceptionToRaise(respondToStorage, storage0, storage1, setBackTraceStorage, obj, arg, backtrace); RaiseAsyncException(self, e); #else throw new NotImplementedError("Thread#raise not supported on this platform"); #endif }
public static void RaiseException(RubyContext /*!*/ context, Thread /*!*/ self) { if (self == Thread.CurrentThread) { KernelOps.RaiseException(context, self); return; } #if FEATURE_EXCEPTION_STATE // TODO: RubyContext.CurrentException is a thread-local static, and cannot be accessed from other threads // To fix this, it would have to be stored somehow without using ThreadStaticAttribute // For now, we just throw a RuntimeError RaiseAsyncException(self, new RuntimeError()); #else throw new NotImplementedError("Thread#raise not supported on this platform"); #endif }
public static void RaiseException(RespondToStorage /*!*/ respondToStorage, UnaryOpStorage /*!*/ storage0, BinaryOpStorage /*!*/ storage1, CallSiteStorage <Action <CallSite, Exception, RubyArray> > /*!*/ setBackTraceStorage, Thread /*!*/ self, object /*!*/ obj, [Optional] object arg, [Optional] RubyArray backtrace) { if (self == Thread.CurrentThread) { KernelOps.RaiseException(respondToStorage, storage0, storage1, setBackTraceStorage, self, obj, arg, backtrace); return; } #if SILVERLIGHT throw new NotImplementedError("Thread#raise is not implemented on Silverlight"); #else Exception e = KernelOps.CreateExceptionToRaise(respondToStorage, storage0, storage1, setBackTraceStorage, obj, arg, backtrace); RaiseAsyncException(self, e); #endif }
public static void RaiseException(RubyContext /*!*/ context, Thread /*!*/ self) { if (self == Thread.CurrentThread) { KernelOps.RaiseException(context, self); return; } #if SILVERLIGHT throw new NotImplementedError("Thread#raise is not implemented on Silverlight"); #else // TODO: RubyContext.CurrentException is a thread-local static, and cannot be accessed from other threads // To fix this, it would have to be stored somehow without using ThreadStaticAttribute // For now, we just throw a RuntimeError RaiseAsyncException(self, new RuntimeError()); #endif }
/// <summary> /// Convert to string using to_s /// /// The behavior is different from the typical conversion protocol: /// * it assumes that to to_s is defined, and just calls it /// * if to_s returns a non-string value, we fall back to Kernel.ToString /// </summary> public static MutableString /*!*/ ConvertToString(RubyContext /*!*/ context, object obj) { MutableString str = obj as MutableString; if (str != null) { return(str); } str = _ToS.Target(_ToS, context, obj) as MutableString; if (str != null) { return(str); } // fallback to Kernel#to_s if to_s returned a non-string return(KernelOps.ToS(context, obj)); }
public static MutableString /*!*/ Inspect(RubyContext /*!*/ context, Exception /*!*/ self) { object message = RubyExceptionData.GetInstance(self).Message; string className = RubyUtils.GetClassName(context, self); MutableString result = MutableString.CreateMutable(); result.Append("#<"); result.Append(className); result.Append(": "); if (message != null) { result.Append(KernelOps.Inspect(context, message)); } else { result.Append(className); } result.Append('>'); return(result); }
public static MutableString /*!*/ Inspect(UnaryOpStorage /*!*/ inspectStorage, ConversionStorage <MutableString> /*!*/ tosConversion, Exception /*!*/ self) { object message = RubyExceptionData.GetInstance(self).Message; string className = inspectStorage.Context.GetClassDisplayName(self); MutableString result = MutableString.CreateMutable(inspectStorage.Context.GetIdentifierEncoding()); result.Append("#<"); result.Append(className); result.Append(": "); if (message != null) { result.Append(KernelOps.Inspect(inspectStorage, tosConversion, message)); } else { result.Append(className); } result.Append('>'); return(result); }
internal void AddYamlProperties(Dictionary <object, object> /*!*/ propertyMap, object obj, IList /*!*/ instanceVariableNames, bool plainNames) { foreach (object name in instanceVariableNames) { RubySymbol symbol; MutableString mstr; // MRI doesn't use a dynamic conversion: if ((symbol = name as RubySymbol) != null) { propertyMap[plainNames ? (object)symbol.GetSlice(1) : symbol] = KernelOps.InstanceVariableGet(Context, obj, symbol.ToString()); } else if ((mstr = name as MutableString) != null) { propertyMap[plainNames ? mstr.GetSlice(1) : mstr] = KernelOps.InstanceVariableGet(Context, obj, mstr.ToString()); } else { throw RubyExceptions.CreateTypeError("unexpected type {0}, expected Symbol or String", Context.GetClassDisplayName(name)); } } }
public static object Each(BlockParam block, RubyIO /*!*/ self, [DefaultProtocol] MutableString separator) { self.AssertOpenedForReading(); MutableString line; while ((line = self.ReadLineOrParagraph(separator)) != null) { if (block == null) { throw RubyExceptions.NoBlockGiven(); } KernelOps.Taint(block.RubyContext, line); object result; if (block.Yield(line, out result)) { return(result); } } return(self); }
public MutableString /*!*/ Format() { _index = 0; _buf = new StringBuilder(); _tainted = false; int modIndex; while ((modIndex = _format.IndexOf('%', _index)) != -1) { _buf.Append(_format, _index, modIndex - _index); _index = modIndex + 1; DoFormatCode(); } _buf.Append(_format, _index, _format.Length - _index); MutableString result = MutableString.Create(_buf.ToString()); if (_tainted) { KernelOps.Taint(_context, result); } return(result); }
public static object Each(RubyScope /*!*/ scope, BlockParam /*!*/ block, Enumerator /*!*/ self) { // MRI doesn't send "send" message: return(KernelOps.SendMessageOpt(scope, block, self._targetObject, self._targetName, self._targetArguments)); }
private static string GetMessage(object arg2, object arg3) { return(string.Format(CultureInfo.InvariantCulture, "{0} {1}", KernelOps.ToS(arg2), KernelOps.ToS(arg3))); }
public object Each(RubyScope /*!*/ scope, BlockParam /*!*/ block) { return(KernelOps.SendMessageOpt(scope, block, _targetObject, _targetName, _targetArguments)); }
public static object ToRational(CallSiteStorage <Func <CallSite, object, object, object, object> > /*!*/ toRational, RubyScope /*!*/ scope, object /*!*/ self) { // TODO: reimplement Rational return(KernelOps.ToRational(toRational, scope, self, self, ClrInteger.One)); }
public static void PrintFormatted(RubyContext /*!*/ context, RubyIO /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ format, [NotNull] params object[] /*!*/ args) { KernelOps.PrintFormatted(context, null, self, format, args); }
public static RubyArray /*!*/ ToYamlProperties(RubyContext /*!*/ context, object self) { return(ArrayOps.SortInPlace(context, null, KernelOps.InstanceVariables(context, self))); }
public static MutableString SetString(RubyContext /*!*/ context, StringScanner /*!*/ self, [NotNull] MutableString /*!*/ str) { self.ScanString = (MutableString)KernelOps.Freeze(context, MutableString.Create(str)); self.Reset(); return(str); }