Example #1
0
 void StoreNamedParameter(IodineMethod method,
                          IodineObject [] arguments,
                          IodineNamedParameter param,
                          int paramIndex)
 {
     if (param.Name == method.VarargsParameter)
     {
         // Variable list arguments
         IodineObject [] tupleItems = new IodineObject [arguments.Length - paramIndex];
         Array.Copy(arguments, paramIndex, tupleItems, 0, arguments.Length - paramIndex);
         Top.StoreLocalExplicit(param.Name, new IodineTuple(tupleItems));
     }
     else if (param.Name == method.KwargsParameter)
     {
         /*
          * At the moment, keyword arguments are passed to the function as an IodineHashMap,
          */
         if (paramIndex < arguments.Length && arguments [paramIndex] is IodineDictionary)
         {
             Top.StoreLocalExplicit(param.Name, arguments [paramIndex]);
         }
         else
         {
             Top.StoreLocalExplicit(param.Name, new IodineDictionary());
         }
     }
     else
     {
         if (arguments.Length <= paramIndex && method.HasDefaultValues)
         {
             Top.StoreLocalExplicit(param.Name, method.DefaultValues [paramIndex - method.DefaultValuesStartIndex]);
         }
         else
         {
             Top.StoreLocalExplicit(param.Name, arguments [paramIndex++]);
         }
     }
 }
Example #2
0
        /*
         * Internal implementation of Invoke
         */
        private IodineObject Invoke(IodineMethod method, IodineObject[] arguments)
        {
            if (method.Bytecode.Instructions.Length > 0)
            {
                currentLocation = method.Bytecode.Instructions [0].Location;
            }

            int insCount      = method.Bytecode.Instructions.Length;
            int prevStackSize = stackSize;
            int i             = 0;

            lastObject = null;

            /*
             * Store function arguments into their respective local variable slots
             */
            foreach (string param in method.Parameters)
            {
                if (param == method.VarargsParameter)
                {
                    // Variable list arguments
                    IodineObject[] tupleItems = new IodineObject[arguments.Length - i];
                    Array.Copy(arguments, i, tupleItems, 0, arguments.Length - i);
                    Top.StoreLocalExplicit(param, new IodineTuple(tupleItems));
                }
                else if (param == method.KwargsParameter)
                {
                    /*
                     * At the moment, keyword arguments are passed to the function as an IodineHashMap,
                     */
                    if (i < arguments.Length && arguments [i] is IodineDictionary)
                    {
                        Top.StoreLocalExplicit(param, arguments [i]);
                    }
                    else
                    {
                        Top.StoreLocalExplicit(param, new IodineDictionary());
                    }
                }
                else
                {
                    if (arguments.Length <= i && method.HasDefaultValues)
                    {
                        Top.StoreLocalExplicit(param, method.DefaultValues [i - method.DefaultValuesStartIndex]);
                    }
                    else
                    {
                        Top.StoreLocalExplicit(param, arguments [i++]);
                    }
                }
            }

            StackFrame top = Top;

            top.Module = method.Module;
            if (traceCallback != null)
            {
                Trace(TraceType.Function, top, currentLocation);
            }

            IodineObject retVal = EvalCode(method.Bytecode);

            if (top.Yielded)
            {
                top.Pop();
            }

            /*
             * Calls __exit__ on any object used in a with statement
             */
            while (!top.Yielded && top.DisposableObjects.Count > 0)
            {
                top.DisposableObjects.Pop().Exit(this);
            }

            stackSize = prevStackSize;

            if (top.AbortExecution)
            {
                /*
                 * If AbortExecution was set, something went wrong and we most likely just
                 * raised an exception. We'll return right here and let what ever catches
                 * the exception clean up the stack
                 */
                return(retVal);
            }

            EndFrame();

            return(retVal);
        }