internal static void DeclareParametersInScope(this IArgumentSet args, ExpressionEval eval) { if (eval == null) { return; } // For class method no need to add extra parameters, but first parameter type should be the class. // For static and unbound methods do not add or set anything. // For regular bound methods add first parameter and set it to the class. foreach (var a in args.Arguments) { if (a.Value is IMember m && !string.IsNullOrEmpty(a.Name)) { eval.DeclareVariable(a.Name, m, VariableSource.Declaration, a.Location); } } if (args.ListArgument != null && !string.IsNullOrEmpty(args.ListArgument.Name)) { var type = new PythonCollectionType(null, BuiltinTypeId.List, eval.Interpreter, false); var list = new PythonCollection(type, args.ListArgument.Values); eval.DeclareVariable(args.ListArgument.Name, list, VariableSource.Declaration, args.ListArgument.Location); } if (args.DictionaryArgument != null) { foreach (var kvp in args.DictionaryArgument.Arguments) { eval.DeclareVariable(kvp.Key, kvp.Value, VariableSource.Declaration, args.DictionaryArgument.Location); } } }
public override IMember Index(IPythonInstance instance, object index) { var n = PythonCollection.GetIndex(index); if (n < 0) { n = ItemTypes.Count + n; // -1 means last, etc. } if (n >= 0 && n < ItemTypes.Count) { return(ItemTypes[n]); } return(UnknownType); }
public override IMember Index(IPythonInstance instance, IArgumentSet args) { var n = PythonCollection.GetIndex(args); if (n < 0) { n = ItemTypes.Count + n; // -1 means last, etc. } if (n >= 0 && n < ItemTypes.Count) { var t = ItemTypes[n]; return(t.CreateInstance(args)); } return(UnknownType); }