Пример #1
0
        // ( module names -- )
        public override void Execute(Interpreter interp)
        {
            ArrayItem names  = (ArrayItem)interp.StackPop();
            Module    module = (Module)interp.StackPop();

            foreach (StackItem item in names.ArrayValue)
            {
                string name, newName;
                if (item is ArrayItem)
                {
                    ArrayItem arrayItem = (ArrayItem)item;
                    name    = ((StringItem)arrayItem.ArrayValue[0]).StringValue;
                    newName = ((StringItem)arrayItem.ArrayValue[1]).StringValue;
                }
                else
                {
                    name    = ((StringItem)item).StringValue;
                    newName = name;
                }

                Word word;
                if (!module.TryFindWord(name, out word))
                {
                    string msg = String.Format("Can't find word {0} in module '{1}'", name, module.Name);
                    throw new InvalidOperationException(msg);
                }

                word.Text = newName;
                interp.CurModule().AddWord(word);
            }
        }
Пример #2
0
        // ( items n -- items[n] )
        public override void Execute(Interpreter interp)
        {
            IntItem   n     = (IntItem)interp.StackPop();
            ArrayItem items = (ArrayItem)interp.StackPop();

            interp.StackPush(items.ArrayValue[n.IntValue]);
        }
Пример #3
0
        // ( list-of-lists -- list )
        public override void Execute(Interpreter interp)
        {
            ArrayItem        list_of_lists = (ArrayItem)interp.StackPop();
            List <StackItem> result        = new List <StackItem>();

            flatten(list_of_lists, result);
            interp.StackPush(new ArrayItem(result));
        }
Пример #4
0
        // ( items field -- sorted-items )
        public override void Execute(Interpreter interp)
        {
            StringItem       field     = (StringItem)interp.StackPop();
            ArrayItem        items     = (ArrayItem)interp.StackPop();
            List <StackItem> item_list = (List <StackItem>)items.ArrayValue;

            sort(item_list, field.StringValue);
            interp.StackPush(new ArrayItem(item_list));
        }
Пример #5
0
        // ( [a b ...] -- a b ... )
        public override void Execute(Interpreter interp)
        {
            ArrayItem items = (ArrayItem)interp.StackPop();

            foreach (StackItem item in items.ArrayValue)
            {
                interp.StackPush(item);
            }
        }
Пример #6
0
        // ( names -- )
        public override void Execute(Interpreter interp)
        {
            ArrayItem names = (ArrayItem)interp.StackPop();

            foreach (StringItem item in names.ArrayValue)
            {
                interp.CurModule().AddVariableIfMissing(item.StringValue);
            }
        }
Пример #7
0
        // ( modules -- )
        public override void Execute(Interpreter interp)
        {
            ArrayItem modules = (ArrayItem)interp.StackPop();

            foreach (Module m in modules.ArrayValue)
            {
                interp.UseModule(m);
            }
        }
Пример #8
0
        // ( a b -- [ a b ] )
        public override void Execute(Interpreter interp)
        {
            StackItem b      = interp.StackPop();
            StackItem a      = interp.StackPop();
            ArrayItem result = new ArrayItem();

            result.Add(a);
            result.Add(b);
            interp.StackPush(result);
        }
Пример #9
0
        // ( items forthic -- )
        public override void Execute(Interpreter interp)
        {
            StringItem forthic = (StringItem)interp.StackPop();
            ArrayItem  items   = (ArrayItem)interp.StackPop();

            foreach (var item in items.ArrayValue)
            {
                interp.StackPush(item);
                interp.Run(forthic.StringValue);
            }
        }
Пример #10
0
 void flatten(ArrayItem items, List <StackItem> res)
 {
     foreach (StackItem item in items.ArrayValue)
     {
         if (item.GetType() == typeof(ArrayItem))
         {
             flatten((ArrayItem)item, res);
         }
         else
         {
             res.Add(item);
         }
     }
 }
Пример #11
0
        // ( values fields -- record )
        public override void Execute(Interpreter interp)
        {
            ArrayItem fields = (ArrayItem)interp.StackPop();
            ArrayItem values = (ArrayItem)interp.StackPop();

            RecordItem result = new RecordItem();

            for (int i = 0; i < fields.ArrayValue.Count; i++)
            {
                StringItem keyItem = (StringItem)fields.ArrayValue[i];
                result.SetValue(keyItem.StringValue, values.ArrayValue[i]);
            }
            interp.StackPush(result);
        }
Пример #12
0
        // ( words -- )
        public override void Execute(Interpreter interp)
        {
            ArrayItem words = (ArrayItem)interp.StackPop();

            foreach (StringItem item in words.ArrayValue)
            {
                Word word;
                if (interp.TryFindWord(item.StringValue, out word))
                {
                    interp.CurModulePredecessor().AddWord(word);
                }
                else
                {
                    throw new InvalidOperationException(String.Format("Can't find {0} to publish", item.StringValue));
                }
            }
        }
Пример #13
0
        // ( array forthic -- ? )
        public override void Execute(Interpreter interp)
        {
            StringItem forthic = (StringItem)interp.StackPop();
            ArrayItem  indices = (ArrayItem)interp.StackPop();

            if (indices.ArrayValue.Count == 2)
            {
                IntItem i_max = (IntItem)indices.ArrayValue[0];
                IntItem j_max = (IntItem)indices.ArrayValue[1];
                for (var i = 0; i < i_max.IntValue; i++)
                {
                    for (var j = 0; j < j_max.IntValue; j++)
                    {
                        interp.StackPush(new IntItem(i));
                        interp.StackPush(new IntItem(j));
                        interp.Run(forthic.StringValue);
                    }
                }
            }
        }
Пример #14
0
 IntItem length(ArrayItem items)
 {
     return(new IntItem(items.ArrayValue.Count));
 }
Пример #15
0
        // ( items -- length )
        public override void Execute(Interpreter interp)
        {
            ArrayItem items = (ArrayItem)interp.StackPop();

            interp.StackPush(length(items));
        }