Esempio n. 1
0
 public string[] getStringArray(GSCoreCollection C)
 {
     string[] result = new string[C.Count];
     for (int i = 0; i < C.Count; i++)
     {
         result[i] = ExecuteElement(C[i]).getStringValue();
     }
     return(result);
 }
Esempio n. 2
0
 public override GSCore ExecuteMessage(string token, GSCoreCollection args)
 {
     if (token.Equals("replace"))
     {
         string a1 = args.getSafe(0).getStringValue();
         string a2 = args.getSafe(1).getStringValue();
         if (a1.Length > 0)
         {
             return(new GSString(Value.Replace(a1, a2)));
         }
         else
         {
             return(this);
         }
     }
     else if (token.Equals("substring"))
     {
         int a = (int)args.getSafe(0).getIntegerValue();
         int b = (int)args.getSafe(1).getIntegerValue();
         if (b == 0)
         {
             return(new GSString(Value.Substring(a)));
         }
         else
         {
             return(new GSString(Value.Substring(a, b)));
         }
     }
     else if (token.Equals("padLeft"))
     {
         int a = (int)args.getSafe(0).getIntegerValue();
         if (a > Value.Length)
         {
             return(new GSString(Value.PadLeft(a)));
         }
         else
         {
             return(this);
         }
     }
     else if (token.Equals("padRight"))
     {
         int a = (int)args.getSafe(0).getIntegerValue();
         if (a > Value.Length)
         {
             return(new GSString(Value.PadRight(a)));
         }
         else
         {
             return(this);
         }
     }
     else
     {
         return(base.ExecuteMessage(token, args));
     }
 }
Esempio n. 3
0
 public long[] getIntegerArray(GSCoreCollection C)
 {
     long[] result = new long[C.Count];
     for (int i = 0; i < C.Count; i++)
     {
         result[i] = ExecuteElement(C[i]).getIntegerValue();
     }
     return(result);
 }
Esempio n. 4
0
 public bool[] getBooleanArray(GSCoreCollection C)
 {
     bool[] result = new bool[C.Count];
     for (int i = 0; i < C.Count; i++)
     {
         result[i] = Parent.ExecuteElement(C[i]).getBooleanValue();
     }
     return(result);
 }
Esempio n. 5
0
 public double[] getDoubleArray(GSCoreCollection C)
 {
     double[] result = new double[C.Count];
     for (int i = 0; i < C.Count; i++)
     {
         result[i] = ExecuteElement(C[i]).getDoubleValue();
     }
     return(result);
 }
Esempio n. 6
0
        public GSCoreCollection getNativeValues(GSCoreCollection args)
        {
            GSCoreCollection coll = new GSCoreCollection();

            foreach (GSCore item in args)
            {
                coll.Add(Parent.ExecuteElement(item));
            }
            return(coll);
        }
Esempio n. 7
0
        public GSCoreCollection getEvaluatedSublist(GSExecutor x, int fromIndex)
        {
            GSCoreCollection args = new GSCoreCollection();

            for (int n = fromIndex; n < Count; n++)
            {
                args.Add(x.ExecuteElement(this[n]));
            }
            return(args);
        }
Esempio n. 8
0
        private GSCore execNot(GSCoreCollection args)
        {
            int result = 0;

            if (args.Count > 0)
            {
                result = ~((int)args[0].getIntegerValue());
            }
            return(new GSInt32(result));
        }
Esempio n. 9
0
        public GSCoreCollection getSublist(int fromIndex)
        {
            GSCoreCollection args = new GSCoreCollection();

            for (int n = fromIndex; n < Count; n++)
            {
                args.Add(this[n]);
            }
            return(args);
        }
Esempio n. 10
0
        private GSCore execOr(GSCoreCollection args)
        {
            int result = 0;

            foreach (GSCore item in args)
            {
                int a = (int)item.getIntegerValue();
                result |= a;
            }
            return(new GSInt32(result));
        }
Esempio n. 11
0
        private GSCore execForeach(GSCoreCollection args)
        {
            if (args.Count < 4)
            {
                Debugger.Log(0, "", "Insufficient arguments for (FOREACH varName : list commands ) ");
                return(null);
            }
            GSCore t1 = args.getSafe(0);
            GSCore l1 = ExecuteElement(args.getSafe(2));

            if (!(t1 is GSToken))
            {
                Debugger.Log(0, "", "Token shoudl be second argument in FOREACH ");
                return(null);
            }
            if (!(l1 is GSList))
            {
                Debugger.Log(0, "", "List should be fourth argument in FOREACH ");
                return(null);
            }
            GSToken tk  = (GSToken)t1;
            GSList  lst = (GSList)l1;
            GSCore  r   = null;
            int     ik  = 0;

            foreach (GSCore item in lst.Parts)
            {
                SetVariable(tk.Token, item);
                for (int i = 3; i < args.Count; i++)
                {
                    r = ExecuteElement(args.getSafe(i));
                    if (r is GSReturn)
                    {
                        break;
                    }
                }
                ik++;

                if (r is GSReturn)
                {
                    GSReturn ret = r as GSReturn;
                    if (ret.Type == GSReturn.TYPE_BREAK)
                    {
                        break;
                    }
                    if (ret.Type == GSReturn.TYPE_RETURN)
                    {
                        return(ret);
                    }
                }
            }

            return(new GSInt64(ik));
        }
Esempio n. 12
0
        private GSCore execIf(GSCoreCollection args)
        {
            GSCore cond = ExecuteElement(args.getSafe(0));
            GSCore cmd1 = args.getSafe(1);
            GSCore cmd2 = args.getSafe(2);
            GSCore r    = null;

            if (cond.getBooleanValue())
            {
                bool running = false;
                foreach (GSCore cmd in args)
                {
                    if (cmd is GSToken && cmd.ToString().Equals("then"))
                    {
                        running = true;
                    }
                    if (cmd is GSToken && cmd.ToString().Equals("else"))
                    {
                        running = false;
                    }
                    if (running)
                    {
                        r = ExecuteElement(cmd);
                        if (r is GSReturn)
                        {
                            return(r);
                        }
                    }
                }
            }
            else
            {
                bool running = false;
                foreach (GSCore cmd in args)
                {
                    if (cmd is GSToken && cmd.ToString().Equals("else"))
                    {
                        running = true;
                    }
                    if (running)
                    {
                        r = ExecuteElement(cmd);
                        if (r is GSReturn)
                        {
                            return(r);
                        }
                    }
                }
            }

            return(cond);
        }
Esempio n. 13
0
        private GSCore execNot(GSCoreCollection args)
        {
            bool result = true;

            if (args.Count > 0)
            {
                result = !args[0].getBooleanValue();
            }
            return(new GSBoolean()
            {
                BooleanValue = result
            });
        }
Esempio n. 14
0
        private GSCore execAdd(GSCoreCollection args)
        {
            double[] arr = getDoubleArray(args);
            double   sum = 0;

            for (int i = 0; i < arr.Length; i++)
            {
                sum += arr[i];
            }
            return(new GSDouble()
            {
                DoubleValue = sum
            });
        }
Esempio n. 15
0
        private GSCore execAdd(GSCoreCollection args)
        {
            string[]      arr = Parent.getStringArray(args);
            StringBuilder sb  = new StringBuilder();

            foreach (string s in arr)
            {
                sb.Append(s);
            }
            return(new GSString()
            {
                Value = sb.ToString()
            });
        }
Esempio n. 16
0
        private GSCore execAdd(GSCoreCollection args)
        {
            long[] arr = Parent.getIntegerArray(args);
            long   sum = 0;

            for (int i = 0; i < arr.Length; i++)
            {
                sum += arr[i];
            }
            return(new GSInt64()
            {
                Int64Value = sum
            });
        }
Esempio n. 17
0
        private GSCore execDo(GSCoreCollection args)
        {
            GSCore last = null;

            foreach (GSCore item in args)
            {
                last = ExecuteElement(item);
                if (last is GSReturn)
                {
                    return(last);
                }
            }
            return(last);
        }
Esempio n. 18
0
        private GSCore execPrint(GSCoreCollection arg, bool newLine)
        {
            foreach (GSCore argument in arg)
            {
                GSCore val = ExecuteElement(argument);
                string str = val.getStringValue();
                str = ReplaceVariables(str);
                output.Append(str);
            }

            if (newLine)
            {
                output.AppendLine();
            }

            return(GSVoid.Void);
        }
Esempio n. 19
0
        public override GSCore ExecuteMessage(string token, GSCoreCollection args)
        {
            GSCore result = null;

            if (token.Equals("add") || token.Equals("+"))
            {
                result = execAdd(getNativeValues(args));
            }
            else if (token.Equals("sub") || token.Equals("-"))
            {
                result = execSub(getNativeValues(args));
            }
            else if (token.Equals("mul") || token.Equals("*"))
            {
                result = execMul(getNativeValues(args));
            }
            else if (token.Equals("div") || token.Equals("/"))
            {
                result = execDiv(getNativeValues(args));
            }
            else if ((token.Equals("gt") || token.Equals(">")) && args.Count > 1)
            {
                result = execGt(getNativeValues(args));
            }
            else if ((token.Equals("ge") || token.Equals(">=")) && args.Count > 1)
            {
                result = execGe(getNativeValues(args));
            }
            else if ((token.Equals("eq") || token.Equals("==")) && args.Count > 1)
            {
                result = execEq(getNativeValues(args));
            }
            else if ((token.Equals("ne") || token.Equals("!=")) && args.Count > 1)
            {
                result = execNe(getNativeValues(args));
            }
            else if ((token.Equals("le") || token.Equals("<=")) && args.Count > 1)
            {
                result = execLe(getNativeValues(args));
            }
            else if ((token.Equals("lt") || token.Equals("<")) && args.Count > 1)
            {
                result = execLt(getNativeValues(args));
            }
            return(base.ExecuteMessage(token, args));
        }
Esempio n. 20
0
        private GSCore execAnd(GSCoreCollection args)
        {
            bool result = true;

            foreach (GSCore item in args)
            {
                if (item.getBooleanValue() == false)
                {
                    result = false;
                    break;
                }
            }
            return(new GSBoolean()
            {
                BooleanValue = result
            });
        }
Esempio n. 21
0
        public override GSCore ExecuteMessage(string token, GSCoreCollection args)
        {
            GSCore result = null;

            if (token.Equals("and") || token.Equals("&"))
            {
                result = execAnd(Parent.getNativeValues(args));
            }
            else if (token.Equals("or") || token.Equals("|"))
            {
                result = execOr(Parent.getNativeValues(args));
            }
            else if (token.Equals("not") || token.Equals("!"))
            {
                result = execNot(args);
            }

            return(base.ExecuteMessage(token, args));
        }
Esempio n. 22
0
        private GSCore execAnd(GSCoreCollection args)
        {
            bool b      = false;
            int  result = 0;

            foreach (GSCore item in args)
            {
                int a = (int)item.getIntegerValue();
                if (b)
                {
                    result &= a;
                }
                else
                {
                    result = a;
                    b      = true;
                }
            }
            return(new GSInt32(result));
        }
Esempio n. 23
0
        private GSCore execMessage(GSCoreCollection args)
        {
            GSCore result = GSVoid.Void;

            // first is token, name of variable, object
            // second is token, message name
            // third etc are arguments
            if (args.Count >= 2 && args.getSafe(0) is GSToken && args.getSafe(1) is GSToken)
            {
                // evaluate the remaining portion of list
                GSCoreCollection subArgs = getNativeValues(args.getSublist(2));
                // first and second tokens
                GSToken t1 = args.getSafe(0) as GSToken;
                GSToken t2 = args.getSafe(1) as GSToken;
                // evaluate reference to object
                GSCore obj = ExecuteElement(t1);
                // execute message in the object
                result = obj.ExecuteMessage(t2.Token, subArgs);
            }

            return(result);
        }
Esempio n. 24
0
        /// <summary>
        /// Reading text with script
        /// Lines starting with # are comments
        /// Other lines are program
        /// </summary>
        /// <param name="text"></param>
        public void readList(String text)
        {
            Parts.Clear();
            Parent = this;

            StringReader sr          = new StringReader(text);
            String       line        = null;
            GSList       currentList = this;

            while ((line = sr.ReadLine()) != null)
            {
                readTextListLine(line, ref currentList);
            }

            if (Parts.Count == 1 && (Parts[0] is GSList))
            {
                Parts = (Parts[0] as GSList).Parts;
            }
            else if (Parts.Count > 1)
            {
                Parts.Insert(0, new GSToken("do"));
            }
        }
Esempio n. 25
0
        public override GSCore ExecuteMessage(string token, GSCoreCollection args)
        {
            GSCore result = null;

            if (token.Equals("print"))
            {
                result = execPrint(args, false);
            }
            else if (token.Equals("println"))
            {
                result = execPrint(args, true);
            }
            else if (token.Equals("if"))
            {
                result = execIf(args);
            }
            else if (token.Equals("while"))
            {
                result = execWhile(args);
            }
            else if (token.Equals("foreach"))
            {
                result = execForeach(args);
            }
            else if (token.Equals("x"))
            {
                result = execMessage(args);
            }
            else if (token.Equals("do"))
            {
                result = execDo(args);
            }
            else if (token.Equals("return"))
            {
                result = new GSReturn(args.getSafe(0));
            }
            else if (token.Equals("break"))
            {
                result = new GSReturn(GSReturn.TYPE_BREAK);
            }
            else if (token.Equals("continue"))
            {
                result = new GSReturn(GSReturn.TYPE_CONTINUE);
            }
            else if (token.Equals("set") && args.Count > 1)
            {
                result = execSet(args[0], args[1]);
            }
            else if (token.Equals("random"))
            {
                result = execRandom(args);
            }
            else
            {
                if (token.IndexOf('.') >= 0)
                {
                    string[] tp  = token.Split('.');
                    GSCore   obj = this;
                    for (int a = 0; a < tp.Length - 1; a++)
                    {
                        if (obj == null)
                        {
                            break;
                        }
                        obj = obj.GetPropertyValue(tp[a]);
                    }
                    if (obj != null)
                    {
                        return(obj.ExecuteMessage(tp[tp.Length - 1], args));
                    }
                }

                Debugger.Log(0, "", "UNKNOWN MESSAGE: " + token + " ");
            }

            return(result);
        }
Esempio n. 26
0
 /// <summary>
 /// This is executing instance message with arguments.
 /// Static methods (messages) are also defined here without the using the instance's data.
 /// </summary>
 /// <param name="token"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 public virtual GSCore ExecuteMessage(string token, GSCoreCollection args)
 {
     return(GSVoid.Void);
 }
Esempio n. 27
0
        public GSCore ExecuteMessage(string token)
        {
            GSCoreCollection args = new GSCoreCollection();

            return(ExecuteMessage(token, args));
        }