Exemplo n.º 1
0
 public static Exception MultipleKeywordArgumentError(TotemFunction function, string name)
 {
     return TypeError("{0}() got multiple values for keyword argument '{1}'", function.Name, name);
 }
Exemplo n.º 2
0
		public object CallTarget(TotemFunction function, object arg0, object arg1, object arg2, object arg3)
		{
			TotemOps.FunctionPushFrame((TotemContext)function.Context.LanguageContext);
			try
			{
				return _target(function, arg0, arg1, arg2, arg3);
			} 
			finally
			{
				TotemOps.FunctionPopFrame();
			}
		}
Exemplo n.º 3
0
		public object CallTarget(TotemFunction function, object arg0, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, object arg11, object arg12, object arg13, object arg14)
		{
			TotemOps.FunctionPushFrame((TotemContext)function.Context.LanguageContext);
			try
			{
				return _target(function, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14);
			} 
			finally
			{
				TotemOps.FunctionPopFrame();
			}
		}
Exemplo n.º 4
0
 public static void CheckParamsZero(TotemFunction function, List<object> extraArgs)
 {
     if (extraArgs.Count != 0)
     {
         throw function.BadArgumentError(extraArgs.Count + function.NormalArgumentCount);
     }
 }
Exemplo n.º 5
0
		public static object OriginalCallTargetN(TotemFunction function, params object[] args)
		{
			function.Code.LazyCompileFirstTarget(function);
			return ((Func<TotemFunction, object[], object>)function.Code.Target)(function, args);
		}
Exemplo n.º 6
0
 public static object GetOrCopyParamsTuple(TotemFunction function, object input)
 {
     if (input == null)
         throw TypeError("{0}() arguments after * can not be null", function.Name);
     throw new NotImplementedException("TotemOps.GetOrCopyParamsTuple");
 }
Exemplo n.º 7
0
 public static CodeContext GetParentContextFromFunction(TotemFunction function)
 {
     return function.Context;
 }
Exemplo n.º 8
0
        public static TotemDictionary CopyAndVerifyUserMapping(TotemFunction function, object dict)
        {
            if (!(dict is IDictionary))
                throw TypeError("{0}() argument after ** must be a mapping, not {1}", function.Name, DynamicHelpers.GetTotemType(dict).Name);

            return CopyAndVerifyDictionary(function, (IDictionary)dict);
        }
Exemplo n.º 9
0
        public static TotemDictionary CopyAndVerifyTotemDictionary(TotemFunction function, TotemDictionary dict)
        {
            if (dict._storage.HasNonStringAttributes())
                throw TypeError("{0}() keywords must be strings", function.Name);

            return new TotemDictionary(dict);
        }
Exemplo n.º 10
0
 public static Exception BadKeywordArgumentError(TotemFunction function, int count)
 {
     return function.BadKeywordArgumentError(count);
 }
Exemplo n.º 11
0
 public static TotemDictionary CopyAndVerifyDictionary(TotemFunction function, IDictionary dict)
 {
     foreach (object o in dict.Keys)
         if (!(o is string))
             throw TypeError("{0}() keywords must be strings", function.Name);
     return new TotemDictionary(dict);
 }
Exemplo n.º 12
0
        public static void AddDictionaryArgument(TotemFunction function, string name, object value, TotemDictionary dict)
        {
            if (dict.ContainsKey(name))
                throw MultipleKeywordArgumentError(function, name);

            dict[name] = value;
        }
Exemplo n.º 13
0
 public static MutableTuple GetLocalClosureFromFunction(TotemFunction function)
 {
     return function.Closure;
 }
Exemplo n.º 14
0
 public static Exception UnexpectedKeywordArgumentError(TotemFunction function, string name)
 {
     return TypeError("{0}() got an unexpected keyword argument '{1}'", function.Name, name);
 }
Exemplo n.º 15
0
 public static Delegate FunctionGetLightThrowTarget(TotemFunction function)
 {
     return function.Code.LightThrowTarget;
 }
Exemplo n.º 16
0
        public static TotemArray CopyAndVerifyParamsList(TotemFunction function, object list)
        {
            if (!(list is IList))
                throw TypeError("{0}() arguments after * must be lists, not {1}", function.Name, DynamicHelpers.GetTotemType(list).Name);

            IList l = (IList)list;
            return new TotemArray(l);
        }
Exemplo n.º 17
0
        public static object GetFunctionParametersValue(TotemFunction function, int index, string name, TotemArray extraArgs, TotemDictionary dict)
        {
            object val;
            if (extraArgs != null && extraArgs.Count > 0)
                return extraArgs.Shift();

            if (dict != null && dict.TryRemoveValue(name, out val))
                return val;

            return function.Defaults[index];
        }
Exemplo n.º 18
0
        public static object ExtractAnyArgument(TotemFunction function, string name, int argCnt, TotemArray list, IDictionary dict)
        {
            object val;
            if (dict.Contains(name))
            {
                if (list.Count != 0)
                    throw MultipleKeywordArgumentError(function, name);

                val = dict[name];
                dict.Remove(name);
                return val;
            }

            if(list.Count != 0)
            {
                return list.Shift();
            }

            if (function.ExpandListPosition == -1 && dict.Count > 0)
            {
                // Totem raises an error for extra splatted kw keys before missing arguments.
                // Therefore we check for this in the error case here.
                foreach (string x in dict.Keys)
                {
                    bool found = false;
                    foreach (string y in function.ArgNames)
                    {
                        if (x == y)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                        throw UnexpectedKeywordArgumentError(function, x);
                }
            }

            throw BinderOps.TypeErrorForIncorrectArgumentCount(
                function.Name,
                function.NormalArgumentCount,
                function.Defaults.Length,
                argCnt,
                function.ExpandListPosition != -1,
                dict.Count > 0
            );
        }
Exemplo n.º 19
0
 public static void VerifyUnduplicatedByPosition(TotemFunction function, string name, int position, int listlen)
 {
     if (listlen > 0 && listlen > position)
         throw MultipleKeywordArgumentError(function, name);
 }
Exemplo n.º 20
0
        public static object ExtractDictionaryArgument(TotemFunction function, string name, int argCnt, TotemDictionary dict)
        {
            object val;
            if (dict.TryGetValue(name, out val))
            {
                dict.Remove(name);
                return val;
            }

            throw TypeError("{0}() takes exactly {1} arguments ({2} given)", function.Name, function.NormalArgumentCount, argCnt);
        }
Exemplo n.º 21
0
        public static void CheckDictionaryZero(TotemFunction function, IDictionary dict)
        {
            if (dict.Count != 0)
            {
                IDictionaryEnumerator ie = dict.GetEnumerator();
                ie.MoveNext();

                throw UnexpectedKeywordArgumentError(function, (string)ie.Key);
            }
        }
Exemplo n.º 22
0
        public static object ExtractParamsArgument(TotemFunction function, int argCnt, TotemArray list)
        {
            if (list.Count != 0)
                return list.Shift();

            throw function.BadArgumentError(argCnt);
        }
Exemplo n.º 23
0
 public static void CheckUserParamsZero(TotemFunction function, object sequence)
 {
     var t = sequence.GetType();
     if (typeof(IList).IsAssignableFrom(t))
         throw ValueError("Not a list type");
     IList l = (IList)sequence;
     if (l.Count != 0)
     {
         throw function.BadArgumentError(l.Count + function.NormalArgumentCount);
     }
 }
Exemplo n.º 24
0
 public static int FunctionGetCompatibility(TotemFunction function)
 {
     return function.FunctionCompatibility;
 }
Exemplo n.º 25
0
		public static object OriginalCallTarget0(TotemFunction function)
		{
			function.Code.LazyCompileFirstTarget(function);
			return ((Func<TotemFunction, object>)function.Code.Target)(function);
		}
Exemplo n.º 26
0
 public static object FunctionGetDefaultValue(TotemFunction function, int index)
 {
     return function.Defaults[index];
 }
Exemplo n.º 27
0
		public static object OriginalCallTarget5(TotemFunction function, object arg0, object arg1, object arg2, object arg3, object arg4)
		{
			function.Code.LazyCompileFirstTarget(function);
			return ((Func<TotemFunction, object, object, object, object, object, object>)function.Code.Target)(function, arg0, arg1, arg2, arg3, arg4);
		}
Exemplo n.º 28
0
 public static Delegate FunctionGetTarget(TotemFunction function)
 {
     return function.Code.Target;
 }
Exemplo n.º 29
0
		public static object OriginalCallTarget11(TotemFunction function, object arg0, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10)
		{
			function.Code.LazyCompileFirstTarget(function);
			return ((Func<TotemFunction, object, object, object, object, object, object, object, object, object, object, object, object>)function.Code.Target)(function, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
		}
Exemplo n.º 30
0
 /// <summary>
 /// Called the 1st time a function is invoked by our OriginalCallTarget* methodSetups
 /// over in TotemCallTargets.  This computes the real delegate which needs to be
 /// created for the function.  Usually this means starting off interpretering.  It 
 /// also involves adding the wrapper function for recursion enforcement.
 /// 
 /// Because this can race against sys.settrace/setprofile we need to take our 
 /// _ThreadIsEnumeratingAndAccountingLock to ensure no one is actively changing all
 /// of the live functions.
 /// </summary>
 internal void LazyCompileFirstTarget(TotemFunction function)
 {
     lock (_CodeCreateAndUpdateDelegateLock)
     {
         UpdateDelegate(function.Context.LanguageContext, true);
     }
 }