Example #1
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));
        }
Example #2
0
        /// <summary>
        /// Executing element. For most of the elements in the program it is element itself,
        /// but for the list it is result of executing operation that is mentioned in the head
        /// of the list.
        /// </summary>
        /// <param name="E"></param>
        /// <returns></returns>
        public GSCore ExecuteElement(GSCore E)
        {
            if (E is GSList)
            {
                GSList L = (GSList)E;
                if (L.Count == 0)
                {
                    return(GSVoid.Void);
                }
                else if (L.Count == 1)
                {
                    return(ExecuteElement(L[0]));
                }
                else
                {
                    GSCore result  = null;
                    GSCore target  = ExecuteElement(L.Parts[0]);
                    string message = (L.Parts[1] is GSToken ? (L.Parts[1] as GSToken).Token : L.Parts[1].getStringValue());
                    if (target != null)
                    {
                        result = target.ExecuteMessage(message, L.Parts.getEvaluatedSublist(this, 2));
                    }

                    if (result == null)
                    {
                        return(new GSString());
                    }
                    return(result);
                }
            }
            else if (E is GSToken)
            {
                GSToken t = E as GSToken;
                if (t.Token.StartsWith("#"))
                {
                    return(new GSString(t.Token));
                }
                return(EvaluateProperty(((GSToken)E).Token));
            }
            else
            {
                return(E);
            }
        }
Example #3
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);
        }