Пример #1
0
        public Value Evaluate(ArrayYielder yielder)
        {
            var array = new Array();

            foreach (Closure closure in yielder.Items)
            {
                Value value = closure.Evaluate(new Arguments());
                if (value.Type == Value.ValueType.Nil)
                {
                    return(array);
                }
                var skip = false;
                foreach (Item item in items)
                {
                    var iterItem = new Array.IterItem
                    {
                        Value = value,
                        Key   = Array.GetKey(),
                        Index = array.Length
                    };
                    value = item.Process(iterItem, array.Length);
                    if (value == null || value.Type == Value.ValueType.Nil)
                    {
                        skip = true;
                        break;
                    }
                }
                if (!skip)
                {
                    array.Add(value);
                }
            }
            return(array);
        }
Пример #2
0
        public override Value Evaluate()
        {
            Value value = block.Evaluate();

            if (value.IsNil)
            {
                return(null);
            }
            switch (type)
            {
            case "return":
                Runtime.State.ReturnSignal = true;
                Runtime.State.ReturnValue  = value;
                return(value);

            case "exit":
                if (value.IsEmpty || value.IsTrue)
                {
                    Runtime.State.ExitSignal = true;
                }
                return(null);

            case "continue":
                if (value.IsEmpty || value.IsTrue)
                {
                    Runtime.State.SkipSignal = true;
                }
                return(null);

            case "yield":
                IStringify stringify;
                if (value.IsA(out stringify))
                {
                    value = stringify.String;
                }
                ClosureContext context = Runtime.State.ClosureContext;
                if (context == null)
                {
                    return(value);
                }
                ArrayYielder yielder = context.Yielder;
                yielder.Add(value.Resolve());
                return(value);
            }
            return(null);
        }