예제 #1
0
        private bool BindKWArgs(string[] argNames, int kwDictIndex, int paramArray)
        {
            bool fHasDict = false;
            IAttributesCollection kwDict = null;

            if (kwDictIndex != -1)
            {
                // append kw value to dictionary
                _realArgs[kwDictIndex] = kwDict = new SymbolDictionary();
                _haveArg[kwDictIndex]  = true;
                fHasDict = true;
            }
            for (int i = 0; i < _kwNames.Length; i++)
            {
                int index          = FindParamIndex(argNames, _kwNames[i]);
                int argumentsIndex = i + _arguments.Length - _kwNames.Length;
                if (index != -1 && index != kwDictIndex && index != paramArray)
                {
                    // attempt to bind to a real arg
                    if (_haveArg[index])
                    {
                        if (index == paramArray)
                        {
                            _error = RuntimeHelpers.SimpleTypeError(String.Format("{0}() got an unexpected keyword argument '{1}'", _methodName, _kwNames[i]));
                        }
                        else
                        {
                            _error = RuntimeHelpers.SimpleTypeError(String.Format("got multiple values for keyword argument {0}", _kwNames[i]));
                        }
                        return(false);
                    }

                    _haveArg[index]  = true;
                    _realArgs[index] = _arguments[argumentsIndex];
                }
                else if (fHasDict)
                {
                    // append kw value to dictionary
                    kwDict[SymbolTable.StringToId(_kwNames[i])] = _arguments[argumentsIndex];
                }
                else if (AllowUnboundArgs)
                {
                    if (_unboundArgs == null)
                    {
                        _unboundArgs = new List <UnboundArgument>();
                    }
                    _unboundArgs.Add(new UnboundArgument(_kwNames[i], _arguments[argumentsIndex]));
                }
                else
                {
                    _error = RuntimeHelpers.SimpleTypeError(String.Format("{0}() got an unexpected keyword argument '{1}'", _methodName, _kwNames[i]));
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
        public static SymbolDictionary MakeSymbolDictionary(SymbolId[] names, object[] values)
        {
            SymbolDictionary res = new SymbolDictionary();

            for (int i = 0; i < names.Length; i++)
            {
                ((IAttributesCollection)res)[names[i]] = values[i];
            }
            return(res);
        }
예제 #3
0
 private void EnsureDictionary(int id)
 {
     while (_dicts.Count <= id)
     {
         _dicts.Add(null);
     }
     if (_dicts[id] == null)
     {
         _dicts[id] = new SymbolDictionary();
     }
 }