public static object Prec(CallSiteStorage <Func <CallSite, RubyClass, object, object> > /*!*/ inducedFromStorage, object self, [NotNull] RubyClass /*!*/ klass) { var inducedFrom = inducedFromStorage.GetCallSite("induced_from", 1); return(inducedFrom.Target(inducedFrom, klass, self)); }
public static object CreateNew(CallSiteStorage <Func <CallSite, object, object, object> > /*!*/ storage, BlockParam block, RubyClass /*!*/ self) { if (block == null) { throw RubyExceptions.CreateArgumentError("tried to create Proc object without a block"); } var proc = block.Proc; // an instance of Proc class, the identity is preserved: if (self.GetUnderlyingSystemType() == typeof(Proc)) { return(proc); } // an instance of a Proc subclass: var result = new Proc.Subclass(self, proc); // propagate retry and return control flow: var initialize = storage.GetCallSite("initialize", new RubyCallSignature(0, RubyCallFlags.HasImplicitSelf | RubyCallFlags.HasBlock)); object initResult = initialize.Target(initialize, result, block.Proc); if (initResult is BlockReturnResult) { return(initResult); } return(result); }
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))); }
public static object Match(CallSiteStorage <Func <CallSite, RubyScope, object, string, object> > /*!*/ storage, RubyScope /*!*/ scope, string /*!*/ self, object obj) { var site = storage.GetCallSite("=~", new RubyCallSignature(1, RubyCallFlags.HasScope | RubyCallFlags.HasImplicitSelf)); return(site.Target(site, scope, obj, self)); }
public static Proc /*!*/ CreateNew(CallSiteStorage <Func <CallSite, object, object> > /*!*/ storage, RubyScope /*!*/ scope, RubyClass /*!*/ self) { RubyMethodScope methodScope = scope.GetInnerMostMethodScope(); if (methodScope == null || methodScope.BlockParameter == null) { throw RubyExceptions.CreateArgumentError("tried to create Proc object without a block"); } var proc = methodScope.BlockParameter; // an instance of Proc class, the identity is preserved: if (self.GetUnderlyingSystemType() == typeof(Proc)) { return(proc); } // an instance of a Proc subclass: var result = new Proc.Subclass(self, proc); var initialize = storage.GetCallSite("initialize", new RubyCallSignature(0, RubyCallFlags.HasImplicitSelf)); initialize.Target(initialize, result); return(result); }
public static object Find(CallSiteStorage <EachSite> /*!*/ each, CallSiteStorage <Func <CallSite, object, object> > /*!*/ callStorage, [NotNull] BlockParam /*!*/ predicate, object self, [Optional] object ifNone) { object result = Missing.Value; Each(each, self, Proc.Create(each.Context, delegate(BlockParam /*!*/ selfBlock, object _, object item) { object blockResult; if (predicate.Yield(item, out blockResult)) { result = blockResult; return(selfBlock.PropagateFlow(predicate, blockResult)); } if (Protocols.IsTrue(blockResult)) { result = item; return(selfBlock.Break(item)); } return(null); })); if (result == Missing.Value) { if (ifNone == Missing.Value || ifNone == null) { return(null); } var site = callStorage.GetCallSite("call", 0); result = site.Target(site, ifNone); } return(result); }
public static object PrecInteger( CallSiteStorage <Func <CallSite, object, RubyClass, object> > /*!*/ precStorage, object self) { var prec = precStorage.GetCallSite("prec", 1); return(prec.Target(prec, self, precStorage.Context.GetClass(typeof(Integer)))); }
public static MutableString /*!*/ HexDigest(CallSiteStorage <Func <CallSite, object, MutableString, object> > /*!*/ storage, RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ str) { var site = storage.GetCallSite("digest", 1); MutableString result = (MutableString)site.Target(site, self, str); // TODO: check result != null return(HexEncode(result)); }
public static object GetDefaultValue(CallSiteStorage <Func <CallSite, Proc, Hash, object, object> > /*!*/ storage, Hash /*!*/ self, object key) { if (self.DefaultProc != null) { var site = storage.GetCallSite("call", 2); return(site.Target(site, self.DefaultProc, self, key)); } return(self.DefaultValue); }
private static object Each(CallSiteStorage<EachSite>/*!*/ each, RubyContext/*!*/ context, object self, Proc/*!*/ block) { var enumerator = self as Enumerator; if (enumerator != null) { return enumerator.Each(context, block); } else { var site = each.GetCallSite("each", RubyCallSignature.WithBlock(0)); return site.Target(site, context, self, block); } }
private static object New(string /*!*/ methodName, CallSiteStorage <Func <CallSite, object, object, object, object> > /*!*/ storage, BlockParam block, TypeGroup /*!*/ self, params object[] /*!*/ args) { var cls = GetNonGenericClass(storage.Context, self); var site = storage.GetCallSite(methodName, new RubyCallSignature(1, RubyCallFlags.HasImplicitSelf | RubyCallFlags.HasSplattedArgument | RubyCallFlags.HasBlock) ); return(site.Target(site, cls, block != null ? block.Proc : null, RubyOps.MakeArrayN(args))); }
public static object GetElement(CallSiteStorage <Func <CallSite, Hash, object, object> > /*!*/ storage, Hash /*!*/ self, object key) { object result; if (!self.TryGetValue(BaseSymbolDictionary.NullToObj(key), out result)) { var site = storage.GetCallSite("default", 1); return(site.Target(site, self, key)); } return(result); }
public static bool IsComplexYaml( CallSiteStorage <Func <CallSite, object, MutableString> > /*!*/ toYamlStyleStorage, CallSiteStorage <Func <CallSite, object, RubyArray> > /*!*/ toYamlPropertiesStorage, MutableString /*!*/ self) { var toYamlStyleSite = toYamlStyleStorage.GetCallSite("to_yaml_style", 0); var toYamlPropertiesSite = toYamlPropertiesStorage.GetCallSite("to_yaml_properties", 0); return(RubyOps.IsTrue(toYamlStyleSite.Target(toYamlStyleSite, self)) || toYamlPropertiesSite.Target(toYamlPropertiesSite, self).Count == 0 || AfterNewLine(self.ConvertToString())); }
public static MutableString Digest( CallSiteStorage <Func <CallSite, RubyClass, object> > /*!*/ allocateStorage, CallSiteStorage <Func <CallSite, object, MutableString, object> > /*!*/ digestStorage, RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ str) { // TODO: new? var allocateSite = allocateStorage.GetCallSite("allocate", 0); object obj = allocateSite.Target(allocateSite, self); // TODO: check obj var site = digestStorage.GetCallSite("digest", 1); return((MutableString)site.Target(site, obj, str)); }
public static MutableString DigestNew( CallSiteStorage <Func <CallSite, object, object> > /*!*/ finishStorage, CallSiteStorage <Func <CallSite, object, object> > /*!*/ resetStorage, object self) { var finish = finishStorage.GetCallSite("finish", 0); object value = finish.Target(finish, self); var reset = resetStorage.GetCallSite("reset", 0); reset.Target(reset, self); // TODO: cast? return((MutableString)value); }
public static MutableString Digest( CallSiteStorage <Func <CallSite, object, object, object> > /*!*/ initializeCopyStorage, CallSiteStorage <Func <CallSite, RubyClass, object> > /*!*/ allocateStorage, CallSiteStorage <Func <CallSite, object, object> > /*!*/ finishStorage, object self) { object clone; if (!RubyUtils.TryDuplicateObject(initializeCopyStorage, allocateStorage, self, true, out clone)) { throw RubyExceptions.CreateArgumentError("unable to copy object"); } var finish = finishStorage.GetCallSite("finish", 0); // TODO: cast? return((MutableString)finish.Target(finish, clone)); }
public static object Shift(CallSiteStorage <Func <CallSite, Hash, object, object> > /*!*/ storage, Hash /*!*/ self) { self.RequireNotFrozen(); if (self.Count == 0) { var site = storage.GetCallSite("default", 1); return(site.Target(site, self, null)); } IEnumerator <KeyValuePair <object, object> > e = self.GetEnumerator(); e.MoveNext(); KeyValuePair <object, object> pair = e.Current; self.Remove(pair.Key); return(IDictionaryOps.MakeArray(pair)); }
public static RubyModule /*!*/ Include( CallSiteStorage <Func <CallSite, RubyModule, RubyModule, object> > /*!*/ appendFeaturesStorage, CallSiteStorage <Func <CallSite, RubyModule, RubyModule, object> > /*!*/ includedStorage, RubyModule /*!*/ self, [NotNullItems] params RubyModule /*!*/[] /*!*/ modules) { RubyUtils.RequireMixins(self, modules); var appendFeatures = appendFeaturesStorage.GetCallSite("append_features", 1); var included = includedStorage.GetCallSite("included", 1); // Kernel#append_features inserts the module at the beginning of ancestors list; // ancestors after include: [modules[0], modules[1], ..., modules[N-1], self, ...] for (int i = modules.Length - 1; i >= 0; i--) { appendFeatures.Target(appendFeatures, modules[i], self); included.Target(included, modules[i], self); } return(self); }
public static MutableString Digest( CallSiteStorage <Func <CallSite, object, MutableString, object> > /*!*/ updateStorage, CallSiteStorage <Func <CallSite, object, object> > /*!*/ finishStorage, CallSiteStorage <Func <CallSite, object, object> > /*!*/ resetStorage, object self, [DefaultProtocol, NotNull] MutableString /*!*/ str) { var update = updateStorage.GetCallSite("update", 1); update.Target(update, self, str); var finish = finishStorage.GetCallSite("finish", 0); object value = finish.Target(finish, self); var reset = resetStorage.GetCallSite("reset", 0); reset.Target(reset, self); // TODO: cast? return((MutableString)value); }
internal static Exception/*!*/ CreateExceptionToRaise(RespondToStorage/*!*/ respondToStorage, UnaryOpStorage/*!*/ storage0, BinaryOpStorage/*!*/ storage1, CallSiteStorage<Action<CallSite, Exception, RubyArray>>/*!*/ setBackTraceStorage, object/*!*/ obj, object arg, RubyArray backtrace) { if (Protocols.RespondTo(respondToStorage, obj, "exception")) { Exception e = null; if (arg != Missing.Value) { var site = storage1.GetCallSite("exception"); e = site.Target(site, obj, arg) as Exception; } else { var site = storage0.GetCallSite("exception"); e = site.Target(site, obj) as Exception; } if (e != null) { if (backtrace != null) { var site = setBackTraceStorage.GetCallSite("set_backtrace", 1); site.Target(site, e, backtrace); } return e; } } throw RubyExceptions.CreateTypeError("exception class/object expected"); }
public static object ReadInputLine(CallSiteStorage<Func<CallSite, object, MutableString, object>>/*!*/ storage, object self, [NotNull]MutableString/*!*/ separator) { var site = storage.GetCallSite("gets", 1); return site.Target(site, storage.Context.StandardInput, separator); }
public static object ReadInputLine(CallSiteStorage<Func<CallSite, object, object, object, object>>/*!*/ storage, object self, [NotNull]MutableString/*!*/ separator, [DefaultProtocol]int limit) { var site = storage.GetCallSite("gets", 2); return site.Target(site, storage.Context.StandardInput, separator, limit); }
public static MutableString Digest( CallSiteStorage<Func<CallSite, object, MutableString, object>>/*!*/ updateStorage, CallSiteStorage<Func<CallSite, object, object>>/*!*/ finishStorage, CallSiteStorage<Func<CallSite, object, object>>/*!*/ resetStorage, object self, [DefaultProtocol, NotNull]MutableString/*!*/ str) { var update = updateStorage.GetCallSite("update", 1); update.Target(update, self, str); var finish = finishStorage.GetCallSite("finish", 0); object value = finish.Target(finish, self); var reset = resetStorage.GetCallSite("reset", 0); reset.Target(reset, self); // TODO: cast? return (MutableString)value; }
public static MutableString HexDigest(CallSiteStorage<Func<CallSite, object, MutableString, object>>/*!*/ storage, RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ str) { var site = storage.GetCallSite("digest", 1); MutableString result = (MutableString)site.Target(site, self, str); // TODO: check result != null return HexEncode(result); }
public static object MatchObject(CallSiteStorage<Func<CallSite, RubyScope, RubyRegex, MutableString, object>>/*!*/ storage, RubyScope/*!*/ scope, MutableString/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ pattern) { var site = storage.GetCallSite("match", new RubyCallSignature(1, RubyCallFlags.HasImplicitSelf | RubyCallFlags.HasScope)); return site.Target(site, scope, new RubyRegex(pattern, RubyRegexOptions.NONE), self); }
public static Node ToYamlNode(CallSiteStorage<Func<CallSite, RubyContext, Exception, object>>/*!*/ messageStorage, Exception/*!*/ self, [NotNull]RubyRepresenter/*!*/ rep) { var site = messageStorage.GetCallSite("message", 0); var map = new Dictionary<MutableString, object>() { { MutableString.Create("message"), site.Target(site, rep.Context, self) } }; rep.AddYamlProperties(self, map); return rep.Map(self, map); }
public static object Match(CallSiteStorage<Func<CallSite, RubyContext, object, MutableString, object>>/*!*/ storage, RubyScope/*!*/ scope, MutableString/*!*/ self, object obj) { var site = storage.GetCallSite("=~", 1); return site.Target(site, scope.RubyContext, obj, self); }
public static object PrecFloat(CallSiteStorage<Func<CallSite, object, RubyClass, object>>/*!*/ precStorage, object self) { var prec = precStorage.GetCallSite("prec", 1); return prec.Target(prec, self, precStorage.Context.GetClass(typeof(double))); }
public static object Prec(CallSiteStorage<Func<CallSite, RubyContext, RubyClass, object, object>>/*!*/ inducedFromStorage, object self, [NotNull]RubyClass/*!*/ klass) { var inducedFrom = inducedFromStorage.GetCallSite("induced_from", 1); return inducedFrom.Target(inducedFrom, klass.Context, klass, self); }
internal static object Each(CallSiteStorage<EachSiteN>/*!*/ each, object self, IList/*!*/ args, Proc/*!*/ block) { var site = each.GetCallSite("each", new RubyCallSignature(0, RubyCallFlags.HasImplicitSelf | RubyCallFlags.HasBlock | RubyCallFlags.HasSplattedArgument)); return site.Target(site, self, block, args); }
private static object New(string/*!*/ methodName, CallSiteStorage<Func<CallSite, object, object, object>>/*!*/ storage, TypeGroup/*!*/ self, params object[]/*!*/ args) { var cls = GetNonGenericClass(storage.Context, self); var site = storage.GetCallSite(methodName, new RubyCallSignature(1, RubyCallFlags.HasImplicitSelf | RubyCallFlags.HasSplattedArgument) ); return site.Target(site, cls, RubyOps.MakeArrayN(args)); }
public static bool IsComplexYaml( CallSiteStorage<Func<CallSite, RubyContext, object, MutableString>>/*!*/ toYamlStyleStorage, CallSiteStorage<Func<CallSite, RubyContext, object, RubyArray>>/*!*/ toYamlPropertiesStorage, RubyContext/*!*/ context, MutableString/*!*/ self) { var toYamlStyleSite = toYamlStyleStorage.GetCallSite("to_yaml_style", 0); var toYamlPropertiesSite = toYamlPropertiesStorage.GetCallSite("to_yaml_properties", 0); return RubyOps.IsTrue(toYamlStyleSite.Target(toYamlStyleSite, context, self)) || toYamlPropertiesSite.Target(toYamlPropertiesSite, context, self).Count == 0 || AfterNewLine(self.ConvertToString()); }
private static IList/*!*/ CreateResultArray(CallSiteStorage<Func<CallSite, RubyClass, object>>/*!*/ allocateStorage, IList/*!*/ list) { // RubyArray: var array = list as RubyArray; if (array != null) { return array.CreateInstance(); } // interop - call a default ctor to get an instance: var allocate = allocateStorage.GetCallSite("allocate", 0); var cls = allocateStorage.Context.GetClassOf(list); var result = allocate.Target(allocate, cls) as IList; if (result != null) { return result; } throw RubyExceptions.CreateTypeError(String.Format("{0}#allocate should return IList", cls.Name)); }
internal static object Each(CallSiteStorage <EachSite> /*!*/ each, object self, Proc /*!*/ block) { var site = each.GetCallSite("each", new RubyCallSignature(0, RubyCallFlags.HasImplicitSelf | RubyCallFlags.HasBlock)); return(site.Target(site, self, block)); }
public static object Match(CallSiteStorage<Func<CallSite, RubyScope, object, string, object>>/*!*/ storage, RubyScope/*!*/ scope, string/*!*/ self, object obj) { var site = storage.GetCallSite("=~", new RubyCallSignature(1, RubyCallFlags.HasScope | RubyCallFlags.HasImplicitSelf)); return site.Target(site, scope, obj, self); }
public static object MatchRegexp(CallSiteStorage<Func<CallSite, RubyScope, RubyRegex, MutableString, object>>/*!*/ storage, RubyScope/*!*/ scope, MutableString/*!*/ self, [NotNull]RubyRegex/*!*/ regex) { var site = storage.GetCallSite("match", new RubyCallSignature(1, RubyCallFlags.HasImplicitSelf | RubyCallFlags.HasScope)); return site.Target(site, scope, regex, self); }
internal static object Each(CallSiteStorage<EachSite>/*!*/ each, object self, Proc/*!*/ block) { var site = each.GetCallSite("each", new RubyCallSignature(0, RubyCallFlags.HasImplicitSelf | RubyCallFlags.HasBlock)); return site.Target(site, self, block); }
public static MutableString Digest( CallSiteStorage<Func<CallSite, RubyClass, object>>/*!*/ allocateStorage, CallSiteStorage<Func<CallSite, object, MutableString, object>>/*!*/ digestStorage, RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ str) { // TODO: new? var allocateSite = allocateStorage.GetCallSite("allocate", 0); object obj = allocateSite.Target(allocateSite, self); // TODO: check obj var site = digestStorage.GetCallSite("digest", 1); return (MutableString)site.Target(site, obj, str); }
private static object/*!*/ New(string/*!*/ methodName, CallSiteStorage<Func<CallSite, object, object, object, object>>/*!*/ storage, BlockParam block, TypeGroup/*!*/ self, [NotNull]params object[] args) { var cls = GetNonGenericClass(storage.Context, self); var site = storage.GetCallSite(methodName, new RubyCallSignature(1, RubyCallFlags.HasImplicitSelf | RubyCallFlags.HasSplattedArgument | RubyCallFlags.HasBlock) ); return site.Target(site, cls, block != null ? block.Proc : null, RubyOps.MakeArrayN(args)); }
public static MutableString Digest( CallSiteStorage<Func<CallSite, object, object, object>>/*!*/ initializeCopyStorage, CallSiteStorage<Func<CallSite, RubyClass, object>>/*!*/ allocateStorage, CallSiteStorage<Func<CallSite, object, object>>/*!*/ finishStorage, object self) { object clone; if (!RubyUtils.TryDuplicateObject(initializeCopyStorage, allocateStorage, self, true, out clone)) { throw RubyExceptions.CreateArgumentError("unable to copy object"); } var finish = finishStorage.GetCallSite("finish", 0); // TODO: cast? return (MutableString)finish.Target(finish, clone); }
public static object Extend( CallSiteStorage<Func<CallSite, RubyModule, object, object>>/*!*/ extendObjectStorage, CallSiteStorage<Func<CallSite, RubyModule, object, object>>/*!*/ extendedStorage, object self, [NotNull]RubyModule/*!*/ module, [NotNull]params RubyModule/*!*/[]/*!*/ modules) { Assert.NotNull(self, modules); RubyUtils.RequireMixins(module.SingletonClass, modules); var extendObject = extendObjectStorage.GetCallSite("extend_object", 1); var extended = extendedStorage.GetCallSite("extended", 1); // Kernel#extend_object inserts the module at the beginning of the object's singleton ancestors list; // ancestors after extend: [modules[0], modules[1], ..., modules[N-1], self-singleton, ...] for (int i = modules.Length - 1; i >= 0; i--) { extendObject.Target(extendObject, modules[i], self); extended.Target(extended, modules[i], self); } extendObject.Target(extendObject, module, self); extended.Target(extended, module, self); return self; }
public static MutableString DigestNew( CallSiteStorage<Func<CallSite, object, object>>/*!*/ finishStorage, CallSiteStorage<Func<CallSite, object, object>>/*!*/ resetStorage, object self) { var finish = finishStorage.GetCallSite("finish", 0); object value = finish.Target(finish, self); var reset = resetStorage.GetCallSite("reset", 0); reset.Target(reset, self); // TODO: cast? return (MutableString)value; }
public static object ReadInputLine(CallSiteStorage<Func<CallSite, object, object>>/*!*/ storage, object self) { var site = storage.GetCallSite("gets", 0); return site.Target(site, storage.Context.StandardInput); }
public static RubyModule/*!*/ Include( CallSiteStorage<Func<CallSite, RubyContext, RubyModule, RubyModule, object>>/*!*/ appendFeaturesStorage, CallSiteStorage<Func<CallSite, RubyContext, RubyModule, RubyModule, object>>/*!*/ includedStorage, RubyModule/*!*/ self, [NotNull]params RubyModule[]/*!*/ modules) { RubyUtils.RequireMixins(self, modules); var appendFeatures = appendFeaturesStorage.GetCallSite("append_features", 1); var included = includedStorage.GetCallSite("included", 1); // Kernel#append_features inserts the module at the beginning of ancestors list; // ancestors after include: [modules[0], modules[1], ..., modules[N-1], self, ...] for (int i = modules.Length - 1; i >= 0; i--) { appendFeatures.Target(appendFeatures, self.Context, modules[i], self); included.Target(included, self.Context, modules[i], self); } return self; }
internal static object Each(CallSiteStorage <EachSiteN> /*!*/ each, object self, IList /*!*/ args, Proc /*!*/ block) { var site = each.GetCallSite("each", new RubyCallSignature(0, RubyCallFlags.HasImplicitSelf | RubyCallFlags.HasBlock | RubyCallFlags.HasSplattedArgument)); return(site.Target(site, self, block, args)); }
public static object CopyStream( ConversionStorage<MutableString>/*!*/ toPath, ConversionStorage<int>/*!*/ toInt, RespondToStorage/*!*/ respondTo, BinaryOpStorage/*!*/ writeStorage, CallSiteStorage<Func<CallSite, object, object, object, object>>/*!*/ readStorage, RubyClass/*!*/ self, object src, object dst, [DefaultParameterValue(-1)]int count, [DefaultParameterValue(-1)]int src_offset) { if (count < -1) { throw RubyExceptions.CreateArgumentError("count should be >= -1"); } if (src_offset < -1) { throw RubyExceptions.CreateArgumentError("src_offset should be >= -1"); } RubyIO srcIO = src as RubyIO; RubyIO dstIO = dst as RubyIO; Stream srcStream = null, dstStream = null; var context = toPath.Context; CallSite<Func<CallSite, object, object, object>> writeSite = null; CallSite<Func<CallSite, object, object, object, object>> readSite = null; try { if (srcIO == null || dstIO == null) { var toPathSite = toPath.GetSite(TryConvertToPathAction.Make(toPath.Context)); var srcPath = toPathSite.Target(toPathSite, src); if (srcPath != null) { srcStream = new FileStream(context.DecodePath(srcPath), FileMode.Open, FileAccess.Read); } else { readSite = readStorage.GetCallSite("read", 2); } var dstPath = toPathSite.Target(toPathSite, dst); if (dstPath != null) { dstStream = new FileStream(context.DecodePath(dstPath), FileMode.Truncate); } else { writeSite = writeStorage.GetCallSite("write", 1); } } else { srcStream = srcIO.GetReadableStream(); dstStream = dstIO.GetWritableStream(); } if (src_offset != -1) { if (srcStream == null) { throw RubyExceptions.CreateArgumentError("cannot specify src_offset for non-IO"); } srcStream.Seek(src_offset, SeekOrigin.Current); } MutableString userBuffer = null; byte[] buffer = null; long bytesCopied = 0; long remaining = (count < 0) ? Int64.MaxValue : count; int minBufferSize = 16 * 1024; if (srcStream != null) { buffer = new byte[Math.Min(minBufferSize, remaining)]; } while (remaining > 0) { int bytesRead; int chunkSize = (int)Math.Min(minBufferSize, remaining); if (srcStream != null) { userBuffer = null; bytesRead = srcStream.Read(buffer, 0, chunkSize); } else { userBuffer = MutableString.CreateBinary(); bytesRead = Protocols.CastToFixnum(toInt, readSite.Target(readSite, src, chunkSize, userBuffer)); } if (bytesRead <= 0) { break; } if (dstStream != null) { if (userBuffer != null) { dstStream.Write(userBuffer, 0, bytesRead); } else { dstStream.Write(buffer, 0, bytesRead); } } else { if (userBuffer == null) { userBuffer = MutableString.CreateBinary(bytesRead).Append(buffer, 0, bytesRead); } else { userBuffer.SetByteCount(bytesRead); } writeSite.Target(writeSite, dst, userBuffer); } bytesCopied += bytesRead; remaining -= bytesRead; } return Protocols.Normalize(bytesCopied); } finally { if (srcStream != null) { srcStream.Close(); } if (dstStream != null) { dstStream.Close(); } } }
public static Proc/*!*/ CreateNew(CallSiteStorage<Func<CallSite, Proc, Proc, object>>/*!*/ storage, RubyClass/*!*/ self, Proc/*!*/ proc) { Assert.NotNull(storage, self, proc); // an instance of Proc class, the identity is preserved: if (self.GetUnderlyingSystemType() == typeof(Proc)) { return proc; } // an instance of a Proc subclass: var result = new Proc.Subclass(self, proc); var initialize = storage.GetCallSite("initialize", new RubyCallSignature(0, RubyCallFlags.HasImplicitSelf | RubyCallFlags.HasBlock)); // a call to the initializer with a block: object initResult = null; do { // a new proc is created each iteration (even if a subclass is passed in, the Proc class is created): var argProc = proc.Create(proc); try { initResult = initialize.Target(initialize, proc, argProc); } catch (EvalUnwinder u) { initResult = u.ReturnValue; } Debug.Assert(proc != argProc, "retry doesn't propagate to the caller"); } while (RubyOps.IsRetrySingleton(initResult)); return result; }
public static object Find(CallSiteStorage<EachSite>/*!*/ each, CallSiteStorage<Func<CallSite, object, object>>/*!*/ callStorage, BlockParam predicate, object self, [Optional]object ifNone) { object result = Missing.Value; Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) { if (predicate == null) { throw RubyExceptions.NoBlockGiven(); } object blockResult; if (predicate.Yield(item, out blockResult)) { result = blockResult; return selfBlock.Break(blockResult); } if (Protocols.IsTrue(blockResult)) { result = item; return selfBlock.Break(item); } return null; })); if (result == Missing.Value) { if (ifNone == Missing.Value || ifNone == null) { return null; } var site = callStorage.GetCallSite("call", 0); result = site.Target(site, ifNone); } return result; }
public static bool TryFlattenArray( CallSiteStorage<Func<CallSite, IList, object>>/*!*/ flattenStorage, ConversionStorage<IList>/*!*/ tryToAry, IList list, out IList/*!*/ result) { // TODO: create correct subclass of RubyArray rather than RubyArray directly result = new RubyArray(); using (IDisposable handle = _infiniteFlattenTracker.TrackObject(list)) { if (handle == null) { throw RubyExceptions.CreateArgumentError("tried to flatten recursive array"); } bool flattened = false; for (int i = 0; i < list.Count; i++) { IList item = Protocols.TryCastToArray(tryToAry, list[i]); if (item != null) { flattened = true; var flatten = flattenStorage.GetCallSite("flatten", 0); object flattenedItem = flatten.Target(flatten, item); IList flattenedList = Protocols.TryCastToArray(tryToAry, flattenedItem); if (flattenedList != null) { AddRange(result, flattenedList); } else { result.Add(flattenedItem); } } else { result.Add(list[i]); } } return flattened; } }