示例#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));
        }