/// <summary>
        /// Get the Type that is supposed to define the member we are about to invoke.
        /// </summary>
        /// <param name="node">Parse node describing the primitive call.</param>
        /// <returns>Type that is supposed to define the member we are about to invoke.</returns>
        private Type GetDefiningType(Compiler.SemanticNodes.PrimitiveCallNode node)
        {
            String definingTypeName = node.ApiParameters[0].Value;
            // Get the type that is expected to implement the member we are looking for.
            Type definingType = NativeTypeClassMap.GetType(definingTypeName);

            if (definingType == null)
            {
                throw new PrimitiveInvalidTypeException(String.Format(CodeGenerationErrors.WrongTypeName, definingTypeName)).SetErrorLocation(node);
            }
            return(definingType);
        }
示例#2
0
        protected Expression UnaryOperation(Conversion conversion, Func <Expression, Type, Expression> func)
        {
            if (this.Parameters == null)
            {
                return(null);
            }
            if (this.Parameters.Count != 1)
            {
                return(null);
            }
            Type type = (this.Parameters[0] == "self") ? null : NativeTypeClassMap.GetType(this.Parameters[0]);

            Type[]             types = new Type[] { type };
            IList <Expression> args  = this.GetArguments(types, conversion);

            return(func(args[0], type));
        }
示例#3
0
        /// <summary>
        /// Create a new Smalltalk Runtime.
        /// </summary>
        public SmalltalkRuntime()
        {
            this.SymbolTable        = new SymbolTable(this);
            this.NativeTypeClassMap = new NativeTypeClassMap(this);
            this.ExtensionScope     = new SmalltalkNameScope(this);
            GlobalConstantBinding smalltalk = new GlobalConstantBinding(this.GetSymbol("Smalltalk"));

            smalltalk.SetValue(this);
            this.ExtensionScope.GlobalConstants.Add(smalltalk);
            this.ExtensionScope.WriteProtect();
            this.GlobalScope = new SmalltalkNameScope(this, this.ExtensionScope);
            this.GlobalScope.WriteProtect();
            this.ServicesCache = new Dictionary <object, object>();
            this.ExtensionScope.ProtectedNames.AddRange(new string[] {
                "nil", "true", "false", "self", "super", "Object", "Smalltalk"
            }
                                                        .Select(str => this.GetSymbol(str)));
        }
示例#4
0
        protected Type[] GetArgumentTypes(IEnumerable <string> parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            // Then get type definitions for each parameter we are to pass to the member.
            bool        first         = true;
            List <Type> argumentTypes = new List <Type>();

            foreach (string typeName in parameters)
            {
                // Special case, for lazy people, the first parameter type can be "this", meaning the same as the defining type.
                if (first && (typeName == "this"))
                {
                    if (this.DefiningType == null)
                    {
                        throw new ArgumentNullException("this.DefiningType");
                    }
                    argumentTypes.Add(this.DefiningType);
                }
                else
                {
                    // Get the parameter type, if we fail to find one, throw an exception now!
                    Type type = NativeTypeClassMap.GetType(typeName);
                    if (type == null)
                    {
                        throw new PrimitiveInvalidTypeException(String.Format(CodeGenerationErrors.WrongTypeName, typeName));
                    }
                    argumentTypes.Add(type);
                }
                first = false;
            }

            return(argumentTypes.ToArray());
        }
        private Expression Shift()
        {
            if (this.Parameters == null)
            {
                return(null);
            }
            if (this.Parameters.Count != 2)
            {
                return(null);
            }
            // We don't support if the shift parameter is other than int
            if (NativeTypeClassMap.GetType(this.Parameters[1]) != typeof(int))
            {
                throw new PrimitiveInvalidTypeException(String.Format(CodeGenerationErrors.WrongShiftTypeName, this.Parameters[1]));
            }
            Type type = NativeTypeClassMap.GetType(this.Parameters[0]);

            int bits;

            if (type == typeof(System.Numerics.BigInteger))
            {
                bits = 0;
            }
            else if (type == typeof(Int64))
            {
                bits = -63;
            }
            else if (type == typeof(Int32))
            {
                bits = -31;
            }
            else if (type == typeof(Int16))
            {
                bits = -15;
            }
            else if (type == typeof(SByte))
            {
                bits = -7;
            }
            else if (type == typeof(UInt64))
            {
                bits = 64;
            }
            else if (type == typeof(UInt32))
            {
                bits = 32;
            }
            else if (type == typeof(UInt16))
            {
                bits = 16;
            }
            else if (type == typeof(Byte))
            {
                bits = 8;
            }
            else
            {
                throw new PrimitiveInvalidTypeException(String.Format(CodeGenerationErrors.WrongShiftTypeName, this.Parameters[0]));
            }

            IList <Expression> args  = this.GetArguments(new Type[] { type, typeof(int) }, Conversion.Checked);
            Expression         value = args[0];
            Expression         shift = args[1];
            Expression         zero  = this.GetZero(type);

            return(this.Shift(value, shift, type, bits, zero));
        }