Esempio n. 1
0
        public override object Execute(Script script, Scope scope, Token previousToken, object unknown)
        {
            if (unknown != null)
            {
                // TODO: Write a better message for this...
                throw new Exception("An object cannot be passed to a 'new' object!");
            }

            return Invoke(script, scope, null, script.FindType(_name), null, _arguments, _generics);
        }
Esempio n. 2
0
        /// <summary>
        /// Invokes a method on type.
        /// </summary>
        /// <param name="script"></param>
        /// <param name="scope"></param>
        /// <param name="obj">The object that the method before returned, this can be null for static methods.</param>
        /// <param name="objectType">The type of object.</param>
        /// <param name="methodName">The method we want to call, if null, we are assuming that we want to call the constructor for this type.</param>
        /// <param name="arguments">The arguments for the method.</param>
        /// <param name="generics">If generic, the types we are passing to it.</param>
        /// <param name="locals">Local variables.</param>
        /// <returns>The result of the method, or Slimterpreter.Void if no return type.</returns>
        protected object Invoke(Script script, Scope scope, object obj, Type objectType, string methodName, List<List<Token>> arguments, List<string> generics)
        {
            if (generics.Count != 0)
            {
                var genericTypes = new Type[generics.Count];
                for (int i = 0; i < generics.Count; i++)
                {
                    Type type = script.FindType(generics[i]);
                    if (type == null)
                    {
                        throw new InvalidCastException("Cannot cast to type " + generics[i]);
                    }
                    genericTypes[i] = type;
                }
                objectType = objectType.MakeGenericType(genericTypes);
            }

            // Solve the parameters.
            var argumentTypes = new Type[arguments.Count];
            var argumentValues = new object[arguments.Count];
            for (int i = 0; i < arguments.Count; i++)
            {
                object res = null;
                // We need to get to the end of the list of Calls...
                for (int j = 0; j < arguments[i].Count; j++)
                {
                    if (j + 1 < arguments[i].Count)
                    {
                        res = arguments[i][j].Execute(script, null, null, res);
                    }
                    else if (j + 1 == arguments[i].Count)
                    {
                        argumentValues[i] = arguments[i][j].Execute(script, scope, null, res);
                        if (argumentValues[i] == null)
                        {
                            argumentTypes[i] = typeof (object);
                        }
                        else
                        {
                            argumentTypes[i] = argumentValues[i].GetType();
                        }
                    }
                }
            }

            if (methodName == null)
            {
                return ConstructorInvoke(objectType, argumentTypes, argumentValues);
            }
            else
            {
                return MethodInvoke(obj, methodName, objectType, argumentTypes, argumentValues);
            }
        }
Esempio n. 3
0
 public override object Execute(Script script, Scope scope, Token previousToken, object unknown)
 {
     return script.FindType(_id);
 }