Exemplo n.º 1
0
        public override void Excute(ExcutingStack stack)
        {
            Operands[0].Excute(stack);

            var func = stack.Get(Operands[0]);

            if (func is JFunction jsf)
            {
                var ls = new List <Any>();

                for (int i = 1; i < Operands.Count; i++)
                {
                    Operands[i].Excute(stack);

                    ls.Add(stack.Get(Operands[i]));
                }


                stack.Push(this, jsf.Excute(stack, ls.ToArray()));
            }
            else if (func is JMappingFunction jmaf)
            {
                var ls = new List <object>();

                for (int i = 1; i < Operands.Count; i++)
                {
                    Operands[i].Excute(stack);
                    ls.Add(stack.Get(Operands[i]).GetObject());
                }

                var result = jmaf.Invoker(jmaf.Parent.Instance, ls.ToArray());

                var type = result.GetType();

                if (BaseTypes.Numbers.Contains(type))
                {
                    stack.Push(this, JNumber.CreateJNumber(result));
                }
                else if (BaseTypes.TString == type)
                {
                    stack.Push(this, new JString((string)result));
                }
                else if (BaseTypes.TBoolean == type)
                {
                    stack.Push(this, new JBool((bool)result));
                }
                else if (type == typeof(void))
                {
                    stack.Push(this, new JVoid());
                }
                else
                {
                    stack.Push(this, new JMappingObject(result));
                }
            }
            else
            {
                throw new MemberNotAFunctionException();
            }
        }