Example #1
0
        /// <summary>
        /// Add values to the integer (changes the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to add to the integer</param>
        /// <returns>The sum of all the arguments and the internal integer</returns>
        public ktValue Add(ktList Arguments)
        {
            ktValue Value = ktValue.Null;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't add nothing (null) to an integer!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                // If there's nothing in this argument
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }
                // Try to convert the argument to an int and add it to the internal integer
                m_value += GetAsInt((ktValue)L.Node.Value);
            }

            // Wrap this object in a ktValue ...
            Value = new ktValue("return", "ktInt", this, m_HardType, true);

            // ... and return it
            return Value;
        }
Example #2
0
        public bool SetVariable(ktString Name, ktValue Value, bool Add, bool Copy, bool IgnoreConstant)
        {
            // Nothing to use??
            if (Name.IsEmpty() || (Value == null) || (m_Block == null))
            {
                return false;
            }

            return m_Block.SetVariable(Name, Value, Add, Copy, IgnoreConstant);
        }
Example #3
0
        public ktValue(ktValue Value)
            : base("ktValue", 0)
        {
            //ktDebug.Log( "Value::CONSTR( " + Value.Export() + " )" );
            SetName(Value.Name);
            SetType(Value.Type);
            SetHardType(Value.HardType);
            SetConstant(Value.Constant);

            m_Object = Value.Value;
        }
Example #4
0
        public override int Compare(ktString op, ktValue val)
        {
            int ret = 0;
            bool bVal = val.ToBool();

            switch (op)
            {
                case "<>":
                case "!=":
                case "op<>":
                case "op!=":
                case "operator<>":
                case "operator!=":
                case "ne":
                case "isnotequal":
                case "notequal":
                    {
                        ret = (m_value != bVal) ? 1 : 0;
                        break;
                    }
                case "==":
                case "op==":
                case "operator==":
                case "isequal":
                case "equal":
                case "eq":
                    {
                        ret = (m_value == bVal) ? 1 : 0;
                        break;
                    }
                default:
                    {
                        throw new ktError("Couldn't find the method '" +
                                          op + "' in class '" + m_Name + "'.", ktERR._404);
                    }
            }

            return ret;
        }
Example #5
0
        /// <summary>
        /// Calculate the modulus of the integer and the arguments (doesn't change the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to multiply with the integer</param>
        /// <returns>The product of all the arguments and the internal integer</returns>
        public ktValue _Modulus(ktList Arguments)
        {
            ktValue Value = ktValue.Null;
            ktValue Arg = ktValue.Null;
            int res = m_value;
            int a = 1;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't divide an integer with nothing (null)!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                // If there's nothing in this argument
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }

                // Get the argument as an integer
                a = GetAsInt((ktValue)L.Node.Value);
                // Do modulus with the current argument
                res %= a;
            }
            // Create a new ktInt and wrap it in a ktValue
            Value = new ktValue("return", "ktInt", new ktInt(res), true, true);

            return Value;
        }
Example #6
0
 public virtual ktClass CreateObject(ktValue Value)
 {
     return CreateObject(Value.ToString());
 }
Example #7
0
        /// <summary>
        /// Calculate the value of the integer XOR with the power of the arguments (doesn't change the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to XOR the integer with</param>
        public ktValue _ExclusiveOr(ktList Arguments)
        {
            ktValue Value = ktValue.Null;
            int res = m_value;
            int a = 1;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't divide an integer with nothing (null)!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }

                // Get the argument as an integer
                a = GetAsInt((ktValue)L.Node.Value);
                // Perform an XOR-operation
                res ^= a;
            }
            // Create a new ktInt and wrap it in a ktValue
            Value = new ktValue("return", "ktInt", new ktInt(res), false, true);

            return Value;
        }
Example #8
0
        public override ktValue SetProperty(ktString Name, ktValue Value)
        {
            if ((Name == "this") || (Name == "_this") ||
                (Name == "object") || (Name == "_object") ||
                (Name == "_") || (Name.IsEmpty()))
            {
                /*try {
                    m_Value = Convert.ToInt32( Value.ToString() );
                } catch (Exception E) {
                    if (E.GetType() == typeof( System.FormatException )) {
                        throw new ktError( "kactalkClass::CreateObject: Cant make '" + Value + "' into an integer", ktERR.WRONGTYPE );
                    }
                }*/
            } /*else if (Name == "MathMode") {
            //				m_Value.MathMode = (((ktClass)Value.Value).ToString().ToLower() == "true");
                m_Value.MathMode = Value.ToBool();
            } */else
            {
                throw new ktError("Couldn't find the property '" +
                                  Name + "' in class '" + m_Name + "'.", ktERR._404);
            }

            return GetProperty("_");
        }
Example #9
0
 public bool SetVariable(ktString Name, ktValue Value, bool Add, bool Copy)
 {
     return SetVariable(Name, Value, Add, Copy, false);
 }
Example #10
0
 public ktRunStatementClass(ktValue Value)
     : this()
 {
     m_IsClass = false;
     SetProperty("_", Value);
 }
Example #11
0
        public override ktClass CreateObject(ktValue Value)
        {
            /*
            int I = 0;

            try {
                I = Convert.ToInt32( Value.ToString() );
            } catch (Exception E) {
                if (E.GetType() == typeof( System.FormatException )) {
                    throw new ktError( "kactalkClass::CreateObject: Cant make '" + Value + "' into an integer", ktERR.WRONGTYPE );
                }
            }*/

            return new ktRunStatementClass(new ktRunStatement());
        }
Example #12
0
 /// <summary>
 /// Get the argument/ktValue as an integer (takes in account strict typing etc)
 /// </summary>
 /// <param name="Arg">The argument</param>
 /// <returns></returns>
 protected int GetAsInt(ktValue Arg)
 {
     // Was we given a ktInt??
     if (Arg.Type == "ktInt")
     {
         // Get the value directly from the ktInt object
         return ((ktInt)Arg.Value).m_value;
     }
     // We got something else
     else
     {
         // Is this declared as a hard/strict type
         if (m_HardType)
         {
             throw new ktError("ktInt::Assign: Cant make '" + Arg.Type + "' into a (hard) ktInt!", ktERR.WRONGTYPE);
         }
         // Not hard?
         else
         {
             // Try to convert it to an integer (Use the ToInt of the argument value)
             return Arg.ToInt();
         }
     }
 }
Example #13
0
 public override ktClass CreateObject(ktValue Value)
 {
     return new ktInt( GetAsInt( Value ) );
 }
Example #14
0
 /// <summary>
 /// Main constructor for kactalkClass,
 /// it takes the kacTalk object/interpreter it should wrap/represent (as a ktValue)
 /// </summary>
 public kactalkClass(ktValue Value)
     : this()
 {
     m_IsClass = false;
     SetProperty("_", Value);
 }
Example #15
0
        /// <summary>
        /// Compare the integer with the given value
        /// </summary>
        /// <param name="op">The operator to use for the comparison</param>
        /// <param name="val">The value to compare with</param>
        /// <returns>A value representing the comparison</returns>
        public override int Compare(ktString op, ktValue val)
        {
            int ret = 0;
            // Get the value as an integer
            int iVal = GetAsInt(val);

            // Check which operator we should use
            switch ( op.AsLower() )
            {
                case ">":
                case "op>":
                case "operator>":
                case "mt":
                case "gt":
                case "greater":
                case "greaterthan":
                case "more":
                case "morethan":
                case "isgreater":
                case "isgreaterthan":
                case "ismore":
                case "ismorethan":
                    {
                        ret = (m_value > iVal) ? 1 : 0;
                        break;
                    }
                case ">=":
                case "op>=":
                case "operator>=":
                case "mte":
                case "gte":
                case "greaterorequal":
                case "greaterthanorequal":
                case "moreorequal":
                case "morethanorequal":
                case "isgreaterorequal":
                case "isgreaterthanorequal":
                case "ismoreorequal":
                case "ismorethanorequal":
                    {
                        ret = (m_value >= iVal) ? 1 : 0;
                        break;
                    }
                case "<":
                case "op<":
                case "operator<":
                case "lt":
                case "less":
                case "lessthan":
                case "isless":
                case "islessthan":
                    {
                        ret = (m_value < iVal) ? 1 : 0;
                        break;
                    }
                case "<=":
                case "op<=":
                case "operator<=":
                case "lte":
                case "lessorequal":
                case "lessthanorequal":
                case "islessorequal":
                case "islessthanorequal":
                    {
                        ret = (m_value <= iVal) ? 1 : 0;
                        break;
                    }
                case "<>":
                case "!=":
                case "op<>":
                case "op!=":
                case "operator<>":
                case "operator!=":
                case "ne":
                case "isnotequal":
                case "notequal":
                    {
                        ret = (m_value != iVal) ? 1 : 0;
                        break;
                    }
                case "==":
                case "op==":
                case "operator==":
                case "isequal":
                case "equal":
                case "eq":
                    {
                        ret = (m_value == iVal) ? 1 : 0;
                        break;
                    }
                case "compare":
                    {
                        ret = m_value.CompareTo(iVal);
                        break;
                    }
                default:
                    {
                        throw new ktError("Couldn't find the method '" +
                                          op + "' in class '" + m_Name + "'.", ktERR._404);
                    }
            }

            return ret;
        }
Example #16
0
        public virtual ktValue _GetProperty(ktString Name, bool Copy)
        {
            ktValue Value = ktValue.Null;

            if (Name.IsEmpty())
            {
                return Value;
            }

            if (m_Properties == null)
            {
                throw new ktError("Couldn't find the property '" +
                                  Name + "' in class '" + m_Name + "'.", ktERR._404);
            }

            ktNode Node = m_Properties.GetNode(Name);
            if ((Node == null) || (Node.Value == null))
            {
                throw new ktError("Couldn't find the property '" +
                                  Name + "' in class '" + m_Name + "'.", ktERR._404);
                //return Value;
            }

            if (Copy)
            {
                Value = new ktValue((ktValue)Node.Value);
            }
            else
            {
                Value = (ktValue)Node.Value;
            }

            return Value;
        }
Example #17
0
        public virtual ktValue SetProperty(ktString Name, ktValue Value)
        {
            if (Name.IsEmpty())
            {
                throw new ktError("Didn't get the name of the property to change in class '" +
                                m_Name + "'.", ktERR.NOTSET);
            }

            if (m_Properties == null)
            {
                m_Properties = new ktList();
            }

            ktNode Node = m_Properties.GetNode(Name);

            if ((Node == null) || (Node.Value == null))
            {
                if (m_AddIfNotSet)
                {
                    return AddProperty(Name, Value);
                }
                else
                {
                    throw new ktError("Couldn't find the property '" +
                                      Name + "' in class '" + m_Name + "'.", ktERR._404);
                }
            }
            else
            {
                ktValue Prop = (ktValue)Node.Value;

                if (Prop.Constant)
                {
                    throw new ktError("The property '" + Name + "' in class '" +
                            m_Name + "' is a constant and can't be changed.", ktERR.CONST);
                }
                else if (Value == null)
                {
                    // HUM???
                    Prop.Value = null;
                }
                else
                {
                    Prop.SetValue(Value);
                }

                return Prop;
            }
        }
Example #18
0
        public virtual ktValue GetMember(ktString Name)
        {
            ktValue Value = ktValue.Null;

            try
            {
                Value = GetProperty(Name);
                //ktDebug.Log( "GM::P V:" + Value.ToString() + ";" );
                if (!Value.IsNull())
                {
                    return Value;
                }
            }
            catch (Exception)
            {
                //ktDebug.Log( "Err:" + E.ToString() + ";" );
            }
            try
            {
                ktFunction Func = GetMethod(Name);

                Value = new ktValue(Name, "ktFunction", Func, true, true);

                if (!Value.IsNull())
                {
                    return Value;
                }
            }
            catch (Exception)
            {
                if (Name == "Export")
                {
                    ktDelegateFunction Func = new ktDelegateFunction("Export", ExportValue);

                    Value = new ktValue(Name, "ktFunction", Func, true, true);

                    if (!Value.IsNull())
                    {
                        return Value;
                    }
                }
                else if (Name.AsLower() == "tostring")
                {
                    ktDelegateFunction Func = new ktDelegateFunction("ToString", ToStringValue);

                    Value = new ktValue(Name, "ktFunction", Func, true, true);

                    if (!Value.IsNull())
                    {
                        return Value;
                    }
                }
            }

            throw new ktError("Can't find the member '" + Name + "' in class '" + m_Name + "'!", ktERR._404);
        }
Example #19
0
        /// <summary>
        /// Multiply values with the integer (doesn't change the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to multiply with the integer</param>
        /// <returns>The product of all the arguments and the internal integer</returns>
        public ktValue _Multiply(ktList Arguments)
        {
            ktValue Value = ktValue.Null;
            int res = m_value;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't multiply nothing (null) to an integer!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                // If there's nothing in this argument
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }
                // Multiply with the current argument
                res *= GetAsInt((ktValue)L.Node.Value);
            }
            // Create a new ktInt and wrap it in a ktValue
            Value = new ktValue("return", "ktInt", new ktInt(res), true, true);

            return Value;
        }
Example #20
0
        /// <summary>
        /// Calculate the value of the integer XOR with the power of the arguments (changes the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to XOR the integer with</param>
        /// <returns>The result</returns>
        public ktValue ExclusiveOr(ktList Arguments)
        {
            ktValue Value = ktValue.Null;
            int a = 1;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't XOR an integer with nothing (null)!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }

                // Get the argument as an integer
                a = GetAsInt((ktValue)L.Node.Value);
                // Perform an XOR-operation
                m_value ^= a;
            }
            // Wrap this object in a ktValue ...
            Value = new ktValue("return", "ktInt", this, false, true);

            // ... and return it
            return Value;
        }
Example #21
0
        /// <summary>
        /// Calculate the value of the integer raised to the power of the arguments (doesn't change the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to raise the integer with</param>
        /// <returns>The value of the internal integer to the power of the arguments</returns>
        public ktValue _Power(ktList Arguments)
        {
            ktValue Value = ktValue.Null;
            int res = m_value;
            int a = 1;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't raise an integer with nothing (null)!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                // If there's nothing in this argument
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }

                // Get the argument as an integer
                a = GetAsInt((ktValue)L.Node.Value);
                // Raise it to the power of the argument
                res = (int)Math.Pow((double)res,(double)a);
            }
            // Create a new ktInt and wrap it in a ktValue
            Value = new ktValue("return", "ktInt", new ktInt(res), true, true);

            return Value;
        }
Example #22
0
        /// <summary>
        /// Multiply values with the integer (changes the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to multiply with the integer</param>
        /// <returns>The product of all the arguments and the internal integer</returns>
        public ktValue Multiply(ktList Arguments)
        {
            ktValue Value = ktValue.Null;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't multiply nothing (null) with an integer!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                // If there's nothing in this argument
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }
                // Multiply with the current argument
                m_value *= GetAsInt((ktValue)L.Node.Value);
            }
            // Wrap this object in a ktValue ...
            Value = new ktValue("return", "ktInt", this, m_HardType, true);

            // ... and return it
            return Value;
        }
Example #23
0
 public override ktValue AddProperty(ktValue Value)
 {
     return Value;
 }
Example #24
0
        public virtual ktValue AddProperty(ktValue Value)
        {
            if (Value == null)
            {
                throw new ktError("Need a value-object when adding a property " +
                                      " to class '" + m_Name + "'.", ktERR.NOTSET);
            }

            if (m_Properties == null)
            {
                m_Properties = new ktList();
            }

            m_Properties.Add(Value.Name, Value);

            return Value;
        }
Example #25
0
        public override ktList GetProperties()
        {
            ktValue This = new ktValue(m_Name, "int", this, true, false);
            ktList List = new ktList();

            List.Add("_", This);
            List.Add("this", This);
            List.Add("_this", This);
            List.Add("object", This);
            List.Add("_object", This);

            List.Add("MathMode", This);

            return List;
        }
Example #26
0
        /// <summary>
        /// Add values to the integer (doesn't change the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to add to the integer</param>
        /// <returns>The sum of all the arguments and the internal integer</returns>
        public ktValue _Add(ktList Arguments)
        {
            ktValue Value = ktValue.Null;
            int res = 0;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't add nothing (null) to an integer!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                // If there's nothing in this argument
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }
                // Try to convert the argument to an int and add it to the sum
                res += GetAsInt((ktValue)L.Node.Value);
            }
            // Add the current sum to the internal integer, create a new ktInt and wrap it in a ktValue
            Value = new ktValue("return", "ktInt", new ktInt(m_value + res), true, true);

            // Return the result
            return Value;
        }
Example #27
0
        public virtual ktValue AddProperty(ktString Name, ktValue Value)
        {
            if (Value == null)
            {
                throw new ktError("Need a value-object when adding property '" +
                                Name + "' to class '" + m_Name + "'.", ktERR.NOTSET);
            }

            Value.SetName(Name);

            return AddProperty(Value);
        }
Example #28
0
        /// <summary>
        /// Divide values with the integer (doesn't change the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to divide the integer with</param>
        /// <returns>The quotient of all the arguments and the internal integer</returns>
        public ktValue _Divide(ktList Arguments)
        {
            ktValue Value = ktValue.Null;
            int res = m_value;
            int a = 1;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't divide an integer with nothing (null)!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                // If there's nothing in this argument
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }

                // Get the argument as an integer
                a = GetAsInt((ktValue)L.Node.Value);
                // Check so it isn't zero
                if (a == 0)
                {
                    // Oops, can't do that!!!
                    throw new ktError("You can't divide by zero!", ktERR.DIV_BY_ZERO);
                }
                // Divide with the current argument
                res /= a;
            }
            // Create a new ktInt and wrap it in a ktValue
            Value = new ktValue("return", "ktInt", new ktInt(res), true, true);

            return Value;
        }
Example #29
0
 public bool SetVariable(ktString Name, ktValue Value)
 {
     return SetVariable(Name, Value, true);
 }
Example #30
0
 public virtual int Compare(ktString op, ktValue val)
 {
     throw new ktError("Compare not implemented in '" + this.m_Name + "'!");
 }