/// <summary>
		/// Inicjalizuje nową encję.
		/// </summary>
		/// <param name="id">Identyfikator.</param>
		public GameEntity(string id)
		{
			Logger.Trace("Creating new game entity with id {0}", id);
			this._Components = new ComponentsCollection(this);
			this._Attributes = new AttributesCollection(this);
			this.Id = id;
		}
Ejemplo n.º 2
0
        public static Type GetNewType(string typeName, PythonTuple bases, IAttributesCollection dict) {
            if (bases == null) bases = PythonTuple.EMPTY;
            // we're really only interested in the "correct" base type pulled out of bases
            // and any slot information contained in dict
            // other info might be used for future optimizations

            NewTypeInfo typeInfo = GetTypeInfo(typeName, bases, GetSlots(dict));

            if (typeInfo.BaseType.IsValueType)
                throw PythonOps.TypeError("cannot derive from {0} because it is a value type", typeInfo.BaseType.FullName);
            if (typeInfo.BaseType.IsSealed)
                throw PythonOps.TypeError("cannot derive from {0} because it is sealed", typeInfo.BaseType.FullName);

            Type ret = _newTypes.GetOrCreateValue(typeInfo,
                delegate() {
                    if (typeInfo.InterfaceTypes.Count == 0 && typeInfo.Slots == null) {
                        // types that the have DynamicBaseType attribute can be used as NewType's directly, no 
                        // need to create a new type unless we're adding interfaces or slots...
                        object[] attrs = typeInfo.BaseType.GetCustomAttributes(typeof(DynamicBaseTypeAttribute), false);
                        if (attrs.Length > 0) {
                            return typeInfo.BaseType;
                        }
                    }

                    // creation code                    
                    return GetTypeMaker(bases, typeInfo).CreateNewType();
                });
            
            OptimizedScriptCode.InitializeFields(ret, true);

            return ret;
        }
Ejemplo n.º 3
0
            public StructType(CodeContext/*!*/ context, string name, PythonTuple bases, IAttributesCollection members)
                : base(context, name, bases, members) {

                foreach (PythonType pt in ResolutionOrder) {
                    StructType st = pt as StructType;
                    if (st != this && st != null) {
                        st.EnsureFinal();
                    }

                    UnionType ut = pt as UnionType;
                    if (ut != null) {
                        ut.EnsureFinal();
                    }
                }

                object pack;
                if (members.TryGetValue(SymbolTable.StringToId("_pack_"), out pack)) {
                    if (!(pack is int) || ((int)pack < 0)) {
                        throw PythonOps.ValueError("pack must be a non-negative integer");
                    }
                    _pack = (int)pack;
                }

                object fields;
                if (members.TryGetValue(SymbolTable.StringToId("_fields_"), out fields)) {
                    SetFields(fields);
                }

                // TODO: _anonymous_
            }
Ejemplo n.º 4
0
 public static void PerformModuleReload(PythonContext context, IAttributesCollection dict) {
     Scope scope = Importer.ImportModule(context.SharedContext, context.SharedContext.GlobalScope.Dict, "itertools", false, -1) as Scope;
     if (scope != null) {
         dict[SymbolTable.StringToId("map")] = scope.LookupName(context, SymbolTable.StringToId("imap"));
         dict[SymbolTable.StringToId("filter")] = scope.LookupName(context, SymbolTable.StringToId("ifilter"));
         dict[SymbolTable.StringToId("zip")] = scope.LookupName(context, SymbolTable.StringToId("izip"));
     }
 }
Ejemplo n.º 5
0
 public static void PerformModuleReload(PythonContext context, IAttributesCollection dict) {
     PythonModule scope = Importer.ImportModule(context.SharedContext, context.SharedContext.GlobalDict, "itertools", false, -1) as PythonModule;
     if (scope != null) {
         dict[SymbolTable.StringToId("map")] = scope.__dict__["imap"];
         dict[SymbolTable.StringToId("filter")] = scope.__dict__["ifilter"];
         dict[SymbolTable.StringToId("zip")] = scope.__dict__["izip"];
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Runs the formatting operation on the given format and keyword arguments
        /// </summary>
        public static string/*!*/ FormatString(PythonContext/*!*/ context, string/*!*/ format, PythonTuple/*!*/ args, IAttributesCollection/*!*/ kwArgs) {
            ContractUtils.RequiresNotNull(context, "context");
            ContractUtils.RequiresNotNull(format, "format");
            ContractUtils.RequiresNotNull(args, "args");
            ContractUtils.RequiresNotNull(kwArgs, "kwArgs");

            return Formatter.FormatString(context, format, args, kwArgs);
        }
Ejemplo n.º 7
0
            public UnionType(CodeContext/*!*/ context, string name, PythonTuple bases, IAttributesCollection members)
                : base(context, name, bases, members) {

                object fields;
                if (members.TryGetValue(SymbolTable.StringToId("_fields_"), out fields)) {
                    SetFields(fields);
                }
            }
Ejemplo n.º 8
0
            public PointerType(CodeContext/*!*/ context, string name, PythonTuple bases, IAttributesCollection members)
                : base(context, name, bases, members) {

                object type;
                if (members.TryGetValue(SymbolTable.StringToId("_type_"), out type) && !(type is INativeType)) {
                    throw PythonOps.TypeError("_type_ must be a type");
                }
                _type = (INativeType)type;
            }
Ejemplo n.º 9
0
        public object Invoke(IAttributesCollection args) {
            Dictionary<object, object> dict = new Dictionary<object, object>();

            foreach (KeyValuePair<object, object> pair in args) {
                dict.Add(pair.Key, pair.Value);
            }

            return Invoke(dict);
        }
Ejemplo n.º 10
0
 public static void PerformModuleReload(PythonContext/*!*/ context, IAttributesCollection/*!*/ dict) {
     context.EnsureModuleException("PickleError", dict, "PickleError", "cPickle");
     context.EnsureModuleException("PicklingError", dict, "PicklingError", "cPickle");
     context.EnsureModuleException("UnpicklingError", dict, "UnpicklingError", "cPickle");
     context.EnsureModuleException("UnpickleableError", dict, "UnpickleableError", "cPickle");
     context.EnsureModuleException("BadPickleGet", dict, "BadPickleGet", "cPickle");
     dict[Symbols.Builtins] = context.BuiltinModuleInstance;
     dict[SymbolTable.StringToId("compatible_formats")] = PythonOps.MakeList("1.0", "1.1", "1.2", "1.3", "2.0");
 }
Ejemplo n.º 11
0
        public TargetObject(ICategory category, string categoryType)
        {
            this.CategoryType = categoryType;
            this._variablesProbabilityMap = new AttributesCollection();

            foreach (string variableName in category.Attributes)
            {
                this._variablesProbabilityMap.Add(variableName);
            }
        }
Ejemplo n.º 12
0
            /// <summary>
            /// Creates a new partial object with the provided positional and keyword arguments.
            /// </summary>
            public partial(CodeContext/*!*/ context, object func, [ParamDictionary]IAttributesCollection keywords, [NotNull]params object[]/*!*/ args) {
                if (!PythonOps.IsCallable(context, func)) {
                    throw PythonOps.TypeError("the first argument must be callable");
                }

                _function = func;
                _keywordArgs = keywords;
                _args = args;
                _context = context;
            }
Ejemplo n.º 13
0
 public static void PerformModuleReload(PythonContext/*!*/ context, IAttributesCollection/*!*/ dict) {
     dict.Add(SymbolTable.StringToId(_keyDefaultAction), "default");
     dict.Add(SymbolTable.StringToId(_keyOnceRegistry), new PythonDictionary());
     dict.Add(SymbolTable.StringToId(_keyFilters), new List() {
         // Default filters
         PythonTuple.MakeTuple("ignore", null, PythonExceptions.PendingDeprecationWarning, null, 0),
         PythonTuple.MakeTuple("ignore", null, PythonExceptions.ImportWarning, null, 0),
         PythonTuple.MakeTuple("ignore", null, PythonExceptions.BytesWarning, null, 0)
     });
     context.SetModuleState(_keyFields, dict);
 }
Ejemplo n.º 14
0
            public ArrayType(CodeContext/*!*/ context, string name, PythonTuple bases, IAttributesCollection dict)
                : base(context, name, bases, dict) {
                object len;
                int iLen;
                if (!dict.TryGetValue(SymbolTable.StringToId("_length_"), out len) || !(len is int) || (iLen = (int)len) < 0) {
                    throw PythonOps.AttributeError("arrays must have _length_ attribute and it must be a positive integer");
                }

                object type;
                if (!dict.TryGetValue(SymbolTable.StringToId("_type_"), out type)) {
                    throw PythonOps.AttributeError("class must define a '_type_' attribute");
                }

                _length = iLen;
                _type = (INativeType)type;

                if (_type is SimpleType) {
                    SimpleType st = (SimpleType)_type;
                    if (st._type == SimpleTypeKind.Char) {
                        // TODO: (c_int * 2).value isn't working
                        SetCustomMember(context,
                            SymbolTable.StringToId("value"),
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetCharArrayValue")),
                                NameType.Property | NameType.Python
                            )
                        );

                        SetCustomMember(context,
                            SymbolTable.StringToId("raw"),
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayRaw")),
                                NameType.Property | NameType.Python
                            )
                        );
                    } else if (st._type == SimpleTypeKind.WChar) {
                        SetCustomMember(context,
                            SymbolTable.StringToId("value"),
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayValue")),
                                NameType.Property | NameType.Python
                            )
                        );

                        SetCustomMember(context,
                            SymbolTable.StringToId("raw"),
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayRaw")),
                                NameType.Property | NameType.Python
                            )
                        );
                    }
                }
            }
		public void SetUp()
		{
			GameEntity ent = new GameEntity("Test");
			this.Collection = new AttributesCollection(ent);

			this.Attribute = new Mock<Attribute>("Attribute", 0.0);
			this.GenericAttribute = new Mock<Attribute<int>>("GenericAttribute", 1);

			this.Collection.Add(this.Attribute.Object);
			this.Collection.Add(this.GenericAttribute.Object);
		}
        public AttributesDictionaryStorage(IAttributesCollection data) {
            Debug.Assert(data != null);

            _hidden = new CommonDictionaryStorage();
            foreach (var key in data.Keys) {
                string strKey = key as string;
                if (strKey != null && strKey.Length > 0 && strKey[0] == '$') {
                    _hidden.Add(strKey, null);
                }
            }

            _data = data;
        }
Ejemplo n.º 17
0
        public static void PerformModuleReload(PythonContext/*!*/ context, IAttributesCollection/*!*/ dict) {
            if (!context.HasModuleState(_defaultTimeoutKey)) {
                context.SetModuleState(_defaultTimeoutKey, null);
            }

            context.SetModuleState(_defaultBufsizeKey, DefaultBufferSize);

            context.EnsureModuleException("sslerror", dict, "sslerror", "socket");
            PythonType socketErr = context.EnsureModuleException("socketerror", dict, "error", "socket");
            context.EnsureModuleException("socketherror", socketErr, dict, "herror", "socket");
            context.EnsureModuleException("socketgaierror", socketErr, dict, "gaierror", "socket");
            context.EnsureModuleException("sockettimeout", socketErr, dict, "timeout", "socket");
        }
Ejemplo n.º 18
0
            private static int VerifyMaxLen(IAttributesCollection dict) {
                if (dict.Count != 1) {
                    throw PythonOps.TypeError("deque() takes at most 1 keyword argument ({0} given)", dict.Count);
                }
                
                object value;
                if (!dict.TryGetValue(SymbolTable.StringToId("maxlen"), out value)) {
                    IEnumerator<object> e = dict.Keys.GetEnumerator();
                    if (e.MoveNext()) {
                        throw PythonOps.TypeError("deque(): '{0}' is an invalid keyword argument", e.Current);
                    }
                }

                return VerifyMaxLenValue(value);
            }
Ejemplo n.º 19
0
            private static int VerifyMaxLen(IAttributesCollection dict) {
                if (dict.Count != 1) {
                    throw PythonOps.TypeError("deque() takes at most 1 keyword argument ({0} given)", dict.Count);
                }
                
                object value;
                if (!dict.TryGetValue(SymbolTable.StringToId("maxlen"), out value)) {
                    IEnumerator<object> e = dict.Keys.GetEnumerator();
                    if (e.MoveNext()) {
                        throw PythonOps.TypeError("deque(): '{0}' is an invalid keyword argument", e.Current);
                    }
                }

                if (value is int) return (int)value;
                else if (value is Extensible<int>) return ((Extensible<int>)value).Value;
                throw PythonOps.TypeError("deque(): keyword argument 'maxlen' requires integer");
            }
Ejemplo n.º 20
0
        public static object __new__(CodeContext/*!*/ context, [NotNull]PythonType cls, string name, PythonTuple bases, IAttributesCollection dict) {
            if (cls != TypeCache.OldClass) throw PythonOps.TypeError("{0} is not a subtype of classobj", cls.Name);

            if (!dict.ContainsKey(Symbols.Module)) {
                object moduleValue;
                if (context.GlobalScope.TryGetVariable(Symbols.Name, out moduleValue)) {
                    dict[Symbols.Module] = moduleValue;
                }
            }

            foreach (object o in bases) {
                if (o is PythonType) {
                    return PythonOps.MakeClass(context, name, bases._data, String.Empty, dict);
                }
            }

            return new OldClass(name, bases, dict, String.Empty);
        }
Ejemplo n.º 21
0
        private double EvalProbabilityForCategoryType(string categoryType, IAttributesCollection attributes)
        {
            double result = 1.0;

            foreach (string attribute in attributes.Keys)
            {
                double probability = this._category.Engine.GetCategoryType(categoryType).GetProbability(attribute);
                if (probability == 0.0)
                {
                    result *= 0.00001;
                }
                else
                {
                    result *= probability;
                }
            }

            return result;
        }
Ejemplo n.º 22
0
        public static void PerformModuleReload(PythonContext/*!*/ context, IAttributesCollection/*!*/ dict) {

            context.EnsureModuleException("ArgumentError", dict, "ArgumentError", "_ctypes");
            context.EnsureModuleException("COMError", dict, "COMError", "_ctypes");

            // TODO: Provide an implementation which is coordinated with our _refCountTable
            context.SystemState.__dict__["getrefcount"] = null;
            PythonDictionary pointerTypeCache = new PythonDictionary();
            dict[SymbolTable.StringToId("_pointer_type_cache")] = pointerTypeCache;
            context.SetModuleState(_pointerTypeCacheKey, pointerTypeCache);

            if (Environment.OSVersion.Platform == PlatformID.Win32NT ||
                Environment.OSVersion.Platform == PlatformID.Win32S ||
                Environment.OSVersion.Platform == PlatformID.Win32Windows ||
                Environment.OSVersion.Platform == PlatformID.WinCE) {
                context.SetModuleState(_conversion_mode, PythonTuple.MakeTuple("mbcs", "ignore"));
            } else {
                context.SetModuleState(_conversion_mode, PythonTuple.MakeTuple("ascii", "strict"));
            }
        }
Ejemplo n.º 23
0
            public SimpleType(CodeContext/*!*/ context, string name, PythonTuple bases, IAttributesCollection dict)
                : base(context, name, bases, dict) {
                object val;
                string sVal;

                const string allowedTypes = "?cbBghHiIlLdfuzZqQPXOv";
                if (!TryGetBoundCustomMember(context, SymbolTable.StringToId("_type_"), out val) ||
                    (sVal = StringOps.AsString(val)) == null ||
                    sVal.Length != 1 ||
                    allowedTypes.IndexOf(sVal[0]) == -1) {
                    throw PythonOps.AttributeError("AttributeError: class must define a '_type_' attribute which must be a single character string containing one of '{0}'.", allowedTypes);
                }

                _charType = sVal[0];
                switch (sVal[0]) {
                    case '?': _type = SimpleTypeKind.Boolean; break;
                    case 'c': _type = SimpleTypeKind.Char; break;
                    case 'b': _type = SimpleTypeKind.SignedByte; break;
                    case 'B': _type = SimpleTypeKind.UnsignedByte; break;
                    case 'h': _type = SimpleTypeKind.SignedShort; break;
                    case 'H': _type = SimpleTypeKind.UnsignedShort; break;
                    case 'i': _type = SimpleTypeKind.SignedInt; break;
                    case 'I': _type = SimpleTypeKind.UnsignedInt; break;
                    case 'l': _type = SimpleTypeKind.SignedLong; break;
                    case 'L': _type = SimpleTypeKind.UnsignedLong; break;
                    case 'f': _type = SimpleTypeKind.Single; break;
                    case 'g': // long double, new in 2.6
                    case 'd': _type = SimpleTypeKind.Double; break;
                    case 'q': _type = SimpleTypeKind.SignedLongLong; break;
                    case 'Q': _type = SimpleTypeKind.UnsignedLongLong; break;
                    case 'O': _type = SimpleTypeKind.Object; break;
                    case 'P': _type = SimpleTypeKind.Pointer; break;
                    case 'z': _type = SimpleTypeKind.CharPointer; break;
                    case 'Z': _type = SimpleTypeKind.WCharPointer; break;
                    case 'u': _type = SimpleTypeKind.WChar; break;
                    case 'p': // what are these?
                    case 'X':
                    case 'v':
                        throw new NotImplementedException("simple type " + sVal);
                }
            }
Ejemplo n.º 24
0
 /// <summary>
 /// Compiles a list of source units into a single module.
 /// <c>options</c> can be <c>null</c>
 /// <c>errroSink</c> can be <c>null</c>
 /// <c>dictionary</c> can be <c>null</c>
 /// </summary>
 public IScriptModule CompileModule(string name, ScriptModuleKind kind, CompilerOptions options, ErrorSink errorSink,
                                    IAttributesCollection dictionary, params SourceUnit[] sourceUnits)
 {
     return(_manager.CompileModule(name, kind, new Scope(dictionary), options, errorSink, sourceUnits));
 }
Ejemplo n.º 25
0
 public override void Clear()
 {
     _data = new SymbolDictionary();
     _hidden.Clear();
 }
Ejemplo n.º 26
0
        public virtual bool ValueEquals(object other)
        {
            if (Object.ReferenceEquals(this, other))
            {
                return(true);
            }

            IAttributesCollection oth = other as IAttributesCollection;
            IAttributesCollection ths = this as IAttributesCollection;

            if (oth == null)
            {
                return(false);
            }

            if (oth.Count != ths.Count)
            {
                return(false);
            }

            foreach (KeyValuePair <object, object> o in ths)
            {
                object res;
                if (!oth.TryGetObjectValue(o.Key, out res))
                {
                    return(false);
                }
#if CLR2
                IValueEquality ve = res as IValueEquality;
                if (ve != null)
                {
                    if (!ve.ValueEquals(o.Value))
                    {
                        return(false);
                    }
                }
                else if ((ve = (o.Value as IValueEquality)) != null)
                {
                    if (!ve.Equals(res))
                    {
                        return(false);
                    }
                }
                else
#endif
                if (res != null)
                {
                    if (!res.Equals(o.Value))
                    {
                        return(false);
                    }
                }
                else if (o.Value != null)
                {
                    if (!o.Value.Equals(res))
                    {
                        return(false);
                    }
                } // else both null and are equal
            }
            return(true);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Creates a module.
        /// <c>dictionary</c> can be <c>null</c>
        /// </summary>
        /// <returns></returns>
        public IScriptModule CreateModule(string name, ScriptModuleKind kind, IAttributesCollection dictionary, params ICompiledCode[] compiledCodes)
        {
            Contract.RequiresNotNullItems(compiledCodes, "compiledCodes");

            ScriptCode[] script_codes = new ScriptCode[compiledCodes.Length];
            for (int i = 0; i < compiledCodes.Length; i++) {
                script_codes[i] = ScriptCode.FromCompiledCode(compiledCodes[i] as CompiledCode);
                if (script_codes[i] == null) {
                    throw new ArgumentException(Resources.RemoteCodeModuleComposition, String.Format("{0}[{1}]", "compiledCodes", i));
                }
            }

            return _manager.CreateModule(name, kind, new Scope(dictionary), script_codes);
        }
Ejemplo n.º 28
0
 public void M203([ParamDictionaryAttribute] IAttributesCollection arg)
 {
     Flag.Set(arg.Count);
 }
Ejemplo n.º 29
0
 public Ctor105([ParamDictionary] IAttributesCollection arg)
 {
 }
Ejemplo n.º 30
0
 public ScriptScope CreateScope(IAttributesCollection dictionary)
 {
     return(InvariantEngine.CreateScope(dictionary));
 }
Ejemplo n.º 31
0
 public static JSObject Create(CodeContext context, FunctionObject function, SymbolId [] paramIds, IAttributesCollection dict,
                               object [] actualParameters)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 32
0
 public override void Clear(ref DictionaryStorage storage)
 {
     _data = new SymbolDictionary();
     _hidden.Clear();
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Creates a new Scope with the provided parent and dictionary.
 /// </summary>
 public Scope(Scope parent, IAttributesCollection dictionary)
     : this(parent, dictionary, true)
 {
 }
Ejemplo n.º 34
0
 public AttributesAdapter(IAttributesCollection data)
 {
     _data = data;
 }
Ejemplo n.º 35
0
 public Scope(IAttributesCollection dictionary)
 {
     _extensions = ScopeExtension.EmptyArray;
     _storage    = new AttributesAdapter(dictionary);
 }
Ejemplo n.º 36
0
 // The locals dictionary must be first so that we have the benefit of an emtpy stack when we emit the value
 // in the ScopeExpression
 public static CodeContext CreateNestedCodeContext(IAttributesCollection locals, CodeContext context)
 {
     return(new CodeContext(new Scope(context.Scope, locals), context.LanguageContext, context.ModuleContext));
 }
Ejemplo n.º 37
0
        public virtual Statement MakeInvalidParametersError(MethodBinder binder, DynamicAction action, CallType callType, IList <MethodBase> targets, StandardRule rule, object [] args)
        {
            int  minArgs = Int32.MaxValue;
            int  maxArgs = Int32.MinValue;
            int  maxDflt = Int32.MinValue;
            int  argsProvided = args.Length - 1; // -1 to remove the object we're calling
            bool hasArgList = false, hasNamedArgument = false;
            Dictionary <string, bool> namedArgs = new Dictionary <string, bool>();

            CallAction ca = action as CallAction;

            if (ca != null)
            {
                hasNamedArgument = ca.Signature.HasNamedArgument();
                int dictArgIndex = ca.Signature.IndexOf(ArgumentKind.Dictionary);

                if (dictArgIndex > -1)
                {
                    argsProvided--;
                    IAttributesCollection iac = args[dictArgIndex + 1] as IAttributesCollection;
                    if (iac != null)
                    {
                        foreach (KeyValuePair <object, object> kvp in iac)
                        {
                            namedArgs[(string)kvp.Key] = false;
                        }
                    }
                }

                argsProvided += GetParamsArgumentCountAdjust(ca, args);
                foreach (SymbolId si in ca.Signature.GetArgumentNames())
                {
                    namedArgs[SymbolTable.IdToString(si)] = false;
                }
            }
            else
            {
                maxArgs = minArgs = rule.Parameters.Length;
                maxDflt = 0;
            }

            foreach (MethodBase mb in targets)
            {
                if (callType == CallType.ImplicitInstance && CompilerHelpers.IsStatic(mb))
                {
                    continue;
                }

                ParameterInfo[] pis  = mb.GetParameters();
                int             cnt  = pis.Length;
                int             dflt = 0;

                if (!CompilerHelpers.IsStatic(mb) && callType == CallType.None)
                {
                    cnt++;
                }

                foreach (ParameterInfo pi in pis)
                {
                    if (pi.ParameterType == typeof(CodeContext))
                    {
                        cnt--;
                    }
                    else if (CompilerHelpers.IsParamArray(pi))
                    {
                        cnt--;
                        hasArgList = true;
                    }
                    else if (CompilerHelpers.IsParamDictionary(pi))
                    {
                        cnt--;
                    }
                    else if (!CompilerHelpers.IsMandatoryParameter(pi))
                    {
                        dflt++;
                        cnt--;
                    }

                    namedArgs[pi.Name] = true;
                }

                minArgs = System.Math.Min(cnt, minArgs);
                maxArgs = System.Math.Max(cnt, maxArgs);
                maxDflt = System.Math.Max(dflt, maxDflt);
            }

            foreach (KeyValuePair <string, bool> kvp in namedArgs)
            {
                if (kvp.Value == false)
                {
                    // unbound named argument.
                    return(rule.MakeError(
                               Ast.Ast.Call(
                                   typeof(RuntimeHelpers).GetMethod("TypeErrorForExtraKeywordArgument"),
                                   Ast.Ast.Constant(binder._name, typeof(string)),
                                   Ast.Ast.Constant(kvp.Key, typeof(string))
                                   )
                               ));
                }
            }

            return(rule.MakeError(
                       Ast.Ast.Call(
                           typeof(RuntimeHelpers).GetMethod("TypeErrorForIncorrectArgumentCount", new Type[] {
                typeof(string), typeof(int), typeof(int), typeof(int), typeof(int), typeof(bool), typeof(bool)
            }),
                           Ast.Ast.Constant(binder._name, typeof(string)), // name
                           Ast.Ast.Constant(minArgs),                      // min formal normal arg cnt
                           Ast.Ast.Constant(maxArgs),                      // max formal normal arg cnt
                           Ast.Ast.Constant(maxDflt),                      // default cnt
                           Ast.Ast.Constant(argsProvided),                 // args provided
                           Ast.Ast.Constant(hasArgList),                   // hasArgList
                           Ast.Ast.Constant(hasNamedArgument)              // kwargs provided
                           )
                       ));
        }
Ejemplo n.º 38
0
 private IAttributesCollection EnsureDict() {
     if (_dict == null) {
         _dict = PythonDictionary.MakeSymbolDictionary();
     }
     return _dict;
 }
Ejemplo n.º 39
0
 public ScriptScope CreateScope(IAttributesCollection dictionary)
 {
     ContractUtils.RequiresNotNull(dictionary, "dictionary");
     return(new ScriptScope(this, new Scope(dictionary)));
 }
Ejemplo n.º 40
0
 public void M451(ref int arg1, [ParamDictionary] IAttributesCollection arg2)
 {
     arg1 = 10;
 }
Ejemplo n.º 41
0
 // other scopes:
 protected RubyClosureScope(RubyScope /*!*/ parent, IAttributesCollection /*!*/ frame)
     : base(parent, frame)
 {
 }
Ejemplo n.º 42
0
 public Ctor250(int x, [ParamDictionary] IAttributesCollection y)
 {
 }
 public IScriptModule CreateModule(string name, ScriptModuleKind kind, IAttributesCollection dictionary, params ICompiledCode[] compiledCodes)
 {
     return(RemoteWrapper.WrapRemotable <IScriptModule>(_manager.Environment.CreateModule(name, kind, dictionary, compiledCodes)));
 }
Ejemplo n.º 44
0
 public void M351(int x, [ParamDictionary] IAttributesCollection arg)
 {
     Flag <object> .Set(arg);
 }
 public IScriptModule CompileModule(string name, ScriptModuleKind kind, CompilerOptions options, ErrorSink errorSink, IAttributesCollection dictionary, params SourceUnit[] sourceUnits)
 {
     return(RemoteWrapper.WrapRemotable <IScriptModule>(_manager.Environment.CompileModule(name, kind, options, errorSink, dictionary, sourceUnits)));
 }
Ejemplo n.º 46
0
 public void SetVariables(IAttributesCollection dictionary)
 {
     Contract.RequiresNotNull(dictionary, "dictionary");
     _manager.Variables = dictionary;
 }
Ejemplo n.º 47
0
        private object _lastInputLine; // TODO: per method scope and top level scope, not block scope

        // top scope:
        protected RubyClosureScope(LanguageContext /*!*/ language, IAttributesCollection /*!*/ frame)
            : base(language, frame)
        {
        }
Ejemplo n.º 48
0
 public static void PerformModuleReload(PythonContext/*!*/ context, IAttributesCollection/*!*/ dict) {
     // set the lock count to zero on the 1st load, don't reset the lock count on reloads
     if (!context.HasModuleState(_lockCountKey)) {
         context.SetModuleState(_lockCountKey, 0L);
     }
 }
Ejemplo n.º 49
0
 // other scopes:
 protected RubyScope(RubyScope /*!*/ parent, IAttributesCollection /*!*/ frame)
     : base(null, parent.Top.LanguageContext, parent)
 {
     _frame = frame;
     _top   = parent.Top;
 }
Ejemplo n.º 50
0
 public void SetVariables(IAttributesCollection dictionary)
 {
     Contract.RequiresNotNull(dictionary, "dictionary");
     _manager.Variables = dictionary;
 }
Ejemplo n.º 51
0
 // top scope:
 protected RubyScope(LanguageContext /*!*/ language, IAttributesCollection /*!*/ frame)
     : base(null, language, null)
 {
     _frame = frame;
     _top   = (RubyTopLevelScope)this;
 }
Ejemplo n.º 52
0
        /// <summary>
        /// Gets the member names which are defined in this type and any extension members.
        /// 
        /// This search does not include members in any subtypes or their extension members.
        /// </summary>
        public void LookupMembers(CodeContext/*!*/ context, PythonType/*!*/ type, IAttributesCollection/*!*/ memberNames) {
            if (!_typeMembers.IsFullyCached(type.UnderlyingSystemType)) {
                Dictionary<string, KeyValuePair<PythonTypeSlot, MemberGroup>> members = new Dictionary<string, KeyValuePair<PythonTypeSlot, MemberGroup>>();

                foreach (ResolvedMember rm in TypeInfo.GetMembers(
                    this,
                    EmptyGetMemberAction,
                    type.UnderlyingSystemType)) {

                    if (!members.ContainsKey(rm.Name)) {
                        members[rm.Name] = new KeyValuePair<PythonTypeSlot, MemberGroup>(
                            PythonTypeOps.GetSlot(rm.Member, rm.Name, PrivateBinding), 
                            rm.Member
                        );
                    }
                }

                _typeMembers.CacheAll(type.UnderlyingSystemType, members);
            }

            foreach (KeyValuePair<string, PythonTypeSlot> kvp in _typeMembers.GetAllMembers(type.UnderlyingSystemType)) {
                PythonTypeSlot slot = kvp.Value;
                string name = kvp.Key;

                if (slot.IsAlwaysVisible || PythonOps.IsClsVisible(context)) {
                    memberNames[SymbolTable.StringToId(name)] = slot;
                }
            }
        }
Ejemplo n.º 53
0
        private void CompileWithArrayGlobals(out DlrMainCallTarget target, out IAttributesCollection globals) {
            GlobalArrayRewriter rewriter = new GlobalArrayRewriter();
            Expression<DlrMainCallTarget> lambda = rewriter.RewriteLambda(Code);

            // Compile target
            target = lambda.Compile(SourceUnit.EmitDebugSymbols);

            // Create globals
            globals = rewriter.CreateDictionary();
        }
Ejemplo n.º 54
0
        private ModuleContext _moduleContext; // internally mutable, optional (shouldn't be used when not set)

        public CodeContext(CodeContext parent, IAttributesCollection locals)
            : this(new Scope(parent.Scope, locals), parent.LanguageContext, parent.ModuleContext)
        {
        }
Ejemplo n.º 55
0
 /// <summary>
 /// Creates a new top-level Scope with the provided dictionary
 /// </summary>
 public Scope(IAttributesCollection dictionary)
     : this(null, dictionary)
 {
 }
Ejemplo n.º 56
0
 public void M352([ParamDictionary] IAttributesCollection arg, params int[] x)
 {
     Flag <object> .Set(arg);
 }
Ejemplo n.º 57
0
        public void SetGlobalsDictionary(IAttributesCollection dictionary)
        {
            ContractUtils.RequiresNotNull(dictionary, "dictionary");

            _scopeWrapper.Dict = dictionary;
        }
Ejemplo n.º 58
0
        private void CompileWithStaticGlobals(out DlrMainCallTarget target, out IAttributesCollection globals) {
            // Create typegen
            TypeGen typeGen = Snippets.Shared.DefineType(MakeDebugName(), typeof(CustomSymbolDictionary), false, SourceUnit.EmitDebugSymbols);
            typeGen.TypeBuilder.DefineDefaultConstructor(MethodAttributes.Public);

            // Create rewriter
            GlobalStaticFieldRewriter rewriter = new GlobalStaticFieldRewriter(typeGen);

            // Compile lambda
            LambdaExpression lambda = rewriter.RewriteLambda(Code, "Initialize");
            MethodBuilder mb = typeGen.TypeBuilder.DefineMethod(lambda.Name, CompilerHelpers.PublicStatic);
            lambda.CompileToMethod(mb, SourceUnit.EmitDebugSymbols);

            // Create globals dictionary, finish type
            rewriter.EmitDictionary();
            Type type = typeGen.FinishType();
            globals = (IAttributesCollection)Activator.CreateInstance(type);

            // Create target
            target = (DlrMainCallTarget)Delegate.CreateDelegate(typeof(DlrMainCallTarget), type.GetMethod("Initialize"));

            // TODO: clean this up after clarifying dynamic site initialization logic
            InitializeFields(type);
        }        
Ejemplo n.º 59
0
 public ScriptScope CreateScope(string languageId, IAttributesCollection dictionary)
 {
     return(GetEngine(languageId).CreateScope(dictionary));
 }