internal bool CallSetter(CodeContext context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object[], object> > > storage, object instance, object[] args, object value) { if (NeedToReturnProperty(instance, Setter)) { return(false); } if (_setfunc == null) { lock (this) { if (_setfunc == null) { MakeSetFunc(); } } } if (args.Length != 0) { _setfunc.Call(context, storage, instance, ArrayUtils.Append(args, value)); } else { _setfunc.Call(context, storage, instance, new [] { value }); } return(true); }
private object CallGetter(CodeContext context, PythonType owner, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object> > > storage, object instance) { if (NeedToReturnProperty(instance, Getter)) { return(this); } if (Getter.Length == 0) { throw new MissingMemberException("unreadable property"); } if (owner == null) { owner = DynamicHelpers.GetPythonType(instance); } // this matches the logic in the default binder when it does a property get. We // need to duplicate it here to be consistent for all gets. MethodInfo[] members = Getter; Type type = owner.UnderlyingSystemType; if (Getter.Length > 1) { // if we were given multiple members pick the member closest to the type... Type bestMemberDeclaringType = Getter[0].DeclaringType; MethodInfo bestMember = Getter[0]; for (int i = 1; i < Getter.Length; i++) { MethodInfo mt = Getter[i]; if (!IsApplicableForType(type, mt)) { continue; } if (Getter[i].DeclaringType.IsSubclassOf(bestMemberDeclaringType) || !IsApplicableForType(type, bestMember)) { bestMember = Getter[i]; bestMemberDeclaringType = Getter[i].DeclaringType; } } members = new MethodInfo[] { bestMember }; } BuiltinFunction target = PythonTypeOps.GetBuiltinFunction(type, __name__, members); // Workaround for https://github.com/IronLanguages/ironpython3/issues/1326 Debug.Assert(members.Length == 1); if (members[0].IsStatic) { instance = null; } return(target.Call0(context, storage, instance)); }
private static void EnsureReduceData(CodeContext context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object?, object?, object?, object?> > > siteData) { if (siteData.Data == null) { siteData.Data = CallSite <Func <CallSite, CodeContext, object?, object?, object?, object?> > .Create( context.LanguageContext.Invoke( new CallSignature(2) ) ); } }
public object this[SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object[], object> > > storage, params object[] key] { get { return(GetValue(DefaultContext.Default, storage, key)); } set { if (!SetValue(DefaultContext.Default, storage, key, value)) { throw PythonOps.AttributeErrorForReadonlyAttribute(DeclaringType.Name, __name__); } } }
public static object OverloadedNewBasic(CodeContext context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object[], object> > > storage, BuiltinFunction overloads\u00F8, PythonType type\u00F8, params object[] args\u00F8) { if (type\u00F8 == null) { throw PythonOps.TypeError("__new__ expected type object, got {0}", PythonOps.Repr(context, DynamicHelpers.GetPythonType(type\u00F8))); } if (args\u00F8 == null) { args\u00F8 = new object[1]; } return(overloads\u00F8.Call(context, storage, null, args\u00F8)); }
internal object Call0(CodeContext context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object> > > storage, object instance) { storage = GetInitializedStorage(context, storage); object callable; if (!GetDescriptor().TryGetValue(context, instance, DynamicHelpers.GetPythonTypeFromType(DeclaringType), out callable)) { callable = this; } return(storage.Data.Target(storage.Data, context, callable)); }
public static object?reduce(CodeContext /*!*/ context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object?, object?, object?, object?> > > siteData, object?func, object?seq, object?initializer) { IEnumerator i = PythonOps.GetEnumerator(seq); EnsureReduceData(context, siteData); CallSite <Func <CallSite, CodeContext, object?, object?, object?, object?> > site = siteData.Data; object?ret = initializer; while (i.MoveNext()) { ret = site.Target(site, context, func, ret, i.Current); } return(ret); }
internal object Call(CodeContext context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object[], IDictionary <object, object>, object> > > storage, object instance, object[] args, IDictionary <object, object> keywordArgs) { if (storage == null) { storage = context.LanguageContext.GetGenericKeywordCallSiteStorage(); } if (storage.Data == null) { storage.Data = context.LanguageContext.MakeKeywordSplatSite(); } if (instance != null) { return(storage.Data.Target(storage.Data, context, this, ArrayUtils.Insert(instance, args), keywordArgs)); } return(storage.Data.Target(storage.Data, context, this, args, keywordArgs)); }
public static object?reduce(CodeContext /*!*/ context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object?, object?, object?, object?> > > siteData, object?func, object?seq) { IEnumerator i = PythonOps.GetEnumerator(seq); if (!i.MoveNext()) { throw PythonOps.TypeError("reduce() of empty sequence with no initial value"); } EnsureReduceData(context, siteData); CallSite <Func <CallSite, CodeContext, object?, object?, object?, object?> > site = siteData.Data; object?ret = i.Current; while (i.MoveNext()) { ret = site.Target(site, context, func, ret, i.Current); } return(ret); }
internal object CallGetter(CodeContext context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object[], object> > > storage, object instance, object[] args) { if (NeedToReturnProperty(instance, Getter)) { return(this); } if (Getter.Length == 0) { throw new MissingMemberException("unreadable property"); } if (_getfunc == null) { lock (this) { if (_getfunc == null) { MakeGetFunc(); } } } return(_getfunc.Call(context, storage, instance, args)); }
internal MarshalWriter(SiteLocalStorage<WriterSites>/*!*/ sites, BinaryWriter/*!*/ writer, RubyContext/*!*/ context, int? limit) { Assert.NotNull(sites, writer, context); _sites = sites; _writer = writer; _context = context; _recursionLimit = (limit.HasValue ? limit.Value : -1); _symbols = new Dictionary<string, int>(); _objects = new Dictionary<object, int>(ReferenceEqualityComparer<object>.Instance); #if !SILVERLIGHT _streamingContext = new StreamingContext(StreamingContextStates.Other, _context); #endif }
public static object reduce(CodeContext /*!*/ context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object, object, object> > > siteData, object func, object seq, object initializer) { return(Builtin.reduce(context, siteData, func, seq, initializer)); }
public object __call__(CodeContext context, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object[], IAttributesCollection, object>>> storage, [ParamDictionary]IAttributesCollection dictArgs, params object[] args) { return _template.__call__(context, storage, dictArgs, args); }
public static MutableString Dump(SiteLocalStorage<WriterSites>/*!*/ sites, RubyModule/*!*/ self, object obj, int limit) { MemoryStream buffer = new MemoryStream(); BinaryWriter writer = new BinaryWriter(buffer); MarshalWriter dumper = new MarshalWriter(sites, writer, self.Context, limit); dumper.Dump(obj); return MutableString.CreateBinary(buffer.ToArray()); }
internal object CallGetter(CodeContext context, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object[], object>>> storage, object instance, object[] args) { if (NeedToReturnProperty(instance, Getter)) { return this; } if (Getter.Length == 0) { throw new MissingMemberException("unreadable property"); } return CallTarget(context, storage, _getter, instance, args); }
internal object Call(CodeContext context, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object[], IAttributesCollection, object>>> storage, object instance, object[] args, IAttributesCollection keywordArgs) { if (storage == null) { storage = PythonContext.GetContext(context).GetGenericKeywordCallSiteStorage(); } if (storage.Data == null) { storage.Data = PythonContext.GetContext(context).MakeKeywordSplatSite(); } if (instance != null) { return storage.Data.Target(storage.Data, context, this, ArrayUtils.Insert(instance, args), keywordArgs); } return storage.Data.Target(storage.Data, context, this, args, keywordArgs); }
private object CallGetter(CodeContext context, PythonType owner, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object>>> storage, object instance) { if (NeedToReturnProperty(instance, Getter)) { return this; } if (Getter.Length == 0) { throw new MissingMemberException("unreadable property"); } if (owner == null) { owner = DynamicHelpers.GetPythonType(instance); } // this matches the logic in the default binder when it does a property get. We // need to duplicate it here to be consistent for all gets. MethodInfo[] members = Getter; Type type = owner.UnderlyingSystemType; if (Getter.Length > 1) { // if we were given multiple members pick the member closest to the type... Type bestMemberDeclaringType = Getter[0].DeclaringType; MethodInfo bestMember = Getter[0]; for (int i = 1; i < Getter.Length; i++) { MethodInfo mt = Getter[i]; if (!IsApplicableForType(type, mt)) { continue; } if (Getter[i].DeclaringType.IsSubclassOf(bestMemberDeclaringType) || !IsApplicableForType(type, bestMember)) { bestMember = Getter[i]; bestMemberDeclaringType = Getter[i].DeclaringType; } } members = new MethodInfo[] { bestMember }; } BuiltinFunction target = PythonTypeOps.GetBuiltinFunction(type, __name__, members); return target.Call0(context, storage, instance); }
public object GetValue(CodeContext context, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object[], object>>> storage, object[] keys) { return CallGetter(context, storage, _instance, keys); }
private static SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object[], object> > > GetInitializedStorage(CodeContext context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object[], object> > > storage) { if (storage == null) { storage = context.LanguageContext.GetGenericCallSiteStorage(); } if (storage.Data == null) { storage.Data = context.LanguageContext.MakeSplatSite(); } return(storage); }
public static object Load(SiteLocalStorage<ReaderSites>/*!*/ sites, RubyScope/*!*/ scope, RubyModule/*!*/ self, [NotNull]RubyIO/*!*/ source, [Optional]Proc proc) { BinaryReader reader = source.GetBinaryReader(); MarshalReader loader = new MarshalReader(sites, reader, scope.GlobalScope, proc); return loader.Load(); }
public static object Load(SiteLocalStorage<ReaderSites>/*!*/ sites, RespondToStorage/*!*/ respondToStorage, RubyScope/*!*/ scope, RubyModule/*!*/ self, object source, [Optional]Proc proc) { Stream stream = null; if (source != null) { stream = RubyIOOps.CreateIOWrapper(respondToStorage, self.Context, source, FileAccess.Read); } if (stream == null || !stream.CanRead) { throw RubyExceptions.CreateTypeError("instance of IO needed"); } BinaryReader reader = new BinaryReader(stream); MarshalReader loader = new MarshalReader(sites, reader, scope.GlobalScope, proc); return loader.Load(); }
public static object Load(SiteLocalStorage<ReaderSites>/*!*/ sites, RubyScope/*!*/ scope, RubyModule/*!*/ self, [NotNull]MutableString/*!*/ source, [Optional]Proc proc) { BinaryReader reader = new BinaryReader(new MemoryStream(source.ConvertToBytes())); MarshalReader loader = new MarshalReader(sites, reader, scope.GlobalScope, proc); return loader.Load(); }
public static object Dump(SiteLocalStorage<WriterSites>/*!*/ sites, RespondToStorage/*!*/ respondToStorage, RubyModule/*!*/ self, object obj, object io, [Optional]int? limit) { Stream stream = null; if (io != null) { stream = RubyIOOps.CreateIOWrapper(respondToStorage, self.Context, io, FileAccess.Write); } if (stream == null || !stream.CanWrite) { throw RubyExceptions.CreateTypeError("instance of IO needed"); } BinaryWriter writer = new BinaryWriter(stream); MarshalWriter dumper = new MarshalWriter(sites, writer, self.Context, limit); dumper.Dump(obj); return io; }
public static object Dump(SiteLocalStorage<WriterSites>/*!*/ sites, RubyModule/*!*/ self, object obj, [NotNull]RubyIO/*!*/ io, [Optional]int? limit) { BinaryWriter writer = io.GetBinaryWriter(); MarshalWriter dumper = new MarshalWriter(sites, writer, self.Context, limit); dumper.Dump(obj); return io; }
internal MarshalReader(SiteLocalStorage<ReaderSites>/*!*/ sites, BinaryReader/*!*/ reader, RubyGlobalScope/*!*/ globalScope, Proc proc) { _sites = sites; _reader = reader; _globalScope = globalScope; _proc = proc; _symbols = new Dictionary<int, string>(); _objects = new Dictionary<int, object>(); }
internal object CallTarget(CodeContext context, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object[], object>>> storage, MethodInfo[] targets, object instance, params object[] args) { BuiltinFunction target = PythonTypeOps.GetBuiltinFunction(DeclaringType, __name__, targets); return target.Call(context, storage, instance, args); }
internal bool CallSetter(CodeContext context, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object[], object>>> storage, object instance, object[] args, object value) { if (NeedToReturnProperty(instance, Setter)) { return false; } if (args.Length != 0) { CallTarget(context, storage, _setter, instance, ArrayUtils.Append(args, value)); } else { CallTarget(context, storage, _setter, instance, value); } return true; }
public static object GetAttributeNoThrow(CodeContext /*!*/ context, object self, string name, PythonTypeSlot getAttributeSlot, PythonTypeSlot getAttrSlot, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, string, object> > > /*!*/ callSite) { object value; if (callSite.Data == null) { callSite.Data = MakeGetAttrSite(context); } try { if (getAttributeSlot.TryGetValue(context, self, ((IPythonObject)self).PythonType, out value)) { return(callSite.Data.Target(callSite.Data, context, value, name)); } } catch (MissingMemberException) { try { if (getAttrSlot != null && getAttrSlot.TryGetValue(context, self, ((IPythonObject)self).PythonType, out value)) { return(callSite.Data.Target(callSite.Data, context, value, name)); } return(OperationFailed.Value); } catch (MissingMemberException) { return(OperationFailed.Value); } } try { if (getAttrSlot != null && getAttrSlot.TryGetValue(context, self, ((IPythonObject)self).PythonType, out value)) { return(callSite.Data.Target(callSite.Data, context, value, name)); } } catch (MissingMemberException) { } return(OperationFailed.Value); }
public object GetValue(CodeContext context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object[], object> > > storage, object[] keys) { return(CallGetter(context, storage, _instance, keys)); }
public static object GetAttribute(CodeContext /*!*/ context, object self, string name, PythonTypeSlot getAttributeSlot, PythonTypeSlot getAttrSlot, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, string, object> > > /*!*/ callSite) { object value; if (callSite.Data == null) { callSite.Data = MakeGetAttrSite(context); } try { if (getAttributeSlot.TryGetValue(context, self, ((IPythonObject)self).PythonType, out value)) { return(callSite.Data.Target(callSite.Data, context, value, name)); } } catch (MissingMemberException) { if (getAttrSlot != null && getAttrSlot.TryGetValue(context, self, ((IPythonObject)self).PythonType, out value)) { ExceptionHelpers.DynamicStackFrames = null; return(callSite.Data.Target(callSite.Data, context, value, name)); } throw; } if (getAttrSlot != null && getAttrSlot.TryGetValue(context, self, ((IPythonObject)self).PythonType, out value)) { return(callSite.Data.Target(callSite.Data, context, value, name)); } throw PythonOps.AttributeError(name); }
internal object CallGetter(CodeContext context, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object[], object>>> storage, object instance, object[] args) { if (NeedToReturnProperty(instance, Getter)) { return this; } if (Getter.Length == 0) { throw new MissingMemberException("unreadable property"); } if (_getfunc == null) { lock (this) { if (_getfunc == null) { MakeGetFunc(); } } } return _getfunc.Call(context, storage, instance, args); }
public static MutableString Dump(SiteLocalStorage<WriterSites>/*!*/ sites, RubyModule/*!*/ self, object obj) { return Dump(sites, self, obj, -1); }
internal bool CallSetter(CodeContext context, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object[], object>>> storage, object instance, object[] args, object value) { if (NeedToReturnProperty(instance, Setter)) { return false; } if (_setfunc == null) { lock (this) { if (_setfunc == null) { MakeSetFunc(); } } } if (args.Length != 0) { _setfunc.Call(context, storage, instance, ArrayUtils.Append(args, value)); } else { _setfunc.Call(context, storage, instance, new [] { value }); } return true; }
public static object reduce(CodeContext/*!*/ context, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object, object, object>>> siteData, object func, object seq, object initializer) { return Builtin.reduce(context, siteData, func, seq, initializer); }
private static SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object[], object>>> GetInitializedStorage(CodeContext context, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object[], object>>> storage) { if (storage == null) { storage = PythonContext.GetContext(context).GetGenericCallSiteStorage(); } if (storage.Data == null) { storage.Data = PythonContext.GetContext(context).MakeSplatSite(); } return storage; }
public object this[SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object[], object>>> storage, params object[] key] { get { return GetValue(DefaultContext.Default, storage, key); } set { if (!SetValue(DefaultContext.Default, storage, key, value)) { throw PythonOps.AttributeErrorForReadonlyAttribute(DeclaringType.Name, SymbolTable.StringToId(__name__)); } } }
private static SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object> > > GetInitializedStorage(CodeContext context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object> > > storage) { if (storage.Data == null) { storage.Data = CallSite <Func <CallSite, CodeContext, object, object> > .Create( context.LanguageContext.InvokeNone ); } return(storage); }
public static object GetAttributeNoThrow(CodeContext/*!*/ context, object self, string name, PythonTypeSlot getAttributeSlot, PythonTypeSlot getAttrSlot, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, string, object>>>/*!*/ callSite) { object value; if (callSite.Data == null) { callSite.Data = MakeGetAttrSite(context); } try { if (getAttributeSlot.TryGetBoundValue(context, self, ((IPythonObject)self).PythonType, out value)) { return callSite.Data.Target(callSite.Data, context, value, name); } } catch (MissingMemberException) { try { if (getAttrSlot != null && getAttrSlot.TryGetBoundValue(context, self, ((IPythonObject)self).PythonType, out value)) { return callSite.Data.Target(callSite.Data, context, value, name); } return OperationFailed.Value; } catch (MissingMemberException) { return OperationFailed.Value; } } try { if (getAttrSlot != null && getAttrSlot.TryGetBoundValue(context, self, ((IPythonObject)self).PythonType, out value)) { return callSite.Data.Target(callSite.Data, context, value, name); } } catch (MissingMemberException) { } return OperationFailed.Value; }
public object __call__(CodeContext /*!*/ context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object[], IDictionary <object, object>, object> > > storage, [ParamDictionary] IDictionary <object, object> dictArgs, params object[] args) { return(Call(context, storage, null, args, dictArgs)); }
internal object CallTarget(CodeContext context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object[], object> > > storage, MethodInfo[] targets, object instance, params object[] args) { BuiltinFunction target = PythonTypeOps.GetBuiltinFunction(DeclaringType, __name__, targets); return(target.Call(context, storage, instance, args)); }
public object __call__(CodeContext context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object[], IDictionary <object, object>, object> > > storage, [ParamDictionary] IDictionary <object, object> dictArgs, params object[] args) { return(_template.__call__(context, storage, dictArgs, args)); }
internal object Call(CodeContext context, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object[], object>>> storage, object instance, object[] args) { storage = GetInitializedStorage(context, storage); object callable; if (!GetDescriptor().TryGetBoundValue(context, instance, DynamicHelpers.GetPythonTypeFromType(DeclaringType), out callable)) { callable = this; } return storage.Data.Target(storage.Data, context, callable, args); }