예제 #1
0
        public object EvaluateValues(ExecContext context)
        {
            bool   isNum       = valueType.CanStoreValue(context, IntrinsicTypeDefs.NUMBER);
            double nextInteger = 0;
            bool   isString    = valueType.CanStoreValue(context, IntrinsicTypeDefs.STRING);

            for (int ii = 0; ii < _values.Count; ++ii)
            {
                ClassValue_Enum val = (ClassValue_Enum)_classDef.Allocate(context);
                val.Get(mrName).value          = _values[ii].name;
                _classDef.staticVars[ii].value = val;

                if (null == _values[ii].initializer)
                {
                    if (isNum)
                    {
                        // If number, use next consecutive integer.
                        val.Get(mrValue).value = nextInteger;
                        nextInteger            = Math.Floor(nextInteger + 1);
                    }
                    else if (isString)
                    {
                        // If string, just use name.
                        val.Get(mrValue).value = _values[ii].name;
                    }
                    else
                    {
                        // Use the default value.
                        val.Get(mrValue).value = valueType.GetDefaultValue(context);
                    }
                }
                else
                {
                    object init = _values[ii].initializer.Evaluate(context);
                    if (context.IsRuntimeErrorSet())
                    {
                        return(null);
                    }
                    val.Get(mrValue).value = init;

                    if (isNum)
                    {
                        nextInteger = Math.Floor((double)init + 1);
                    }
                }
            }

            return(false);
        }
예제 #2
0
        public virtual bool CanStoreValue(ExecContext context, ITypeDef valueType)
        {
            //if (valueType is TypeDef) {
            //	return null == (valueType as TypeDef).IsNull();
            //}
            if (valueType.IsNull())
            {
                return(true);
            }

            TypeDef_Function funcValueType = valueType as TypeDef_Function;

            if (null == funcValueType)
            {
                return(false);
            }

            if (!retType.Equals(IntrinsicTypeDefs.VOID) && !retType.CanStoreValue(context, funcValueType.retType))
            {
                return(false);
            }

            if (null != classType)
            {
                if (null == funcValueType.classType || !classType.CanStoreValue(context, funcValueType.classType))
                {
                    return(false);
                }
                // This is the point of isStatic in this class. This is saying, "I can save a reference to a class member function only if it is static."
            }
            else if (null != funcValueType.classType && !funcValueType.isStaticMember)
            {
                return(false);
            }

            // Mismatch if other's max args exceeds our max args.
            if (argTypes.Count > funcValueType.argTypes.Count)
            {
                return(false);
            }

            // Mismatch if we have fewer min args than they do.
            // (Meaning we could be called with fewer arguments than they have default values for.)
            if (minArgs < funcValueType.minArgs)
            {
                return(false);
            }

            // Make sure that for every argument WE have, THEIR argument's type matches.
            for (int ii = 0; ii < argTypes.Count; ++ii)
            {
                if (!funcValueType.argTypes[ii].CanStoreValue(context, argTypes[ii]))
                {
                    return(false);
                }
            }

            return(true);
        }