コード例 #1
0
        public decimal GetDecimal(long i)
        {
            RCDecimal val = (RCDecimal)Get(i);

            if (val == null)
            {
                throw new Exception(string.Format("No value at index {0} within block (count:{1})",
                                                  i,
                                                  Count));
            }
            return(val[0]);
        }
コード例 #2
0
        public decimal GetDecimal(string name)
        {
            RCDecimal val = (RCDecimal)Get(name);

            if (val == null)
            {
                throw new Exception("Required value " + name + " not found in block");
            }
            else
            {
                return(val[0]);
            }
        }
コード例 #3
0
        public decimal GetDecimal(string name, decimal def)
        {
            RCDecimal val = (RCDecimal)Get(name);

            if (val == null)
            {
                return(def);
            }
            else
            {
                return(val[0]);
            }
        }
コード例 #4
0
        /*
         * protected Type InferType(string[] name, string original)
         * {
         * //Let's try to figure it out!
         * RCValue target = null;
         *
         * //Try the block under construction.
         * if (_block != null)
         * {
         * target = _block.Get(name);
         * }
         *
         * //Try to find it higher up the stack.
         * if (target == null)
         * {
         * RCBlock[] parents = _blocks.ToArray();
         * //When you ToArray the stack items come out in the same order
         * //you would have taken them off the stack.
         * for (int i = 0; i < parents.Length; ++i)
         * {
         * //There will be null blocks on the stack.
         * if (parents[i] != null)
         * {
         * target = parents[i].Get(name);
         * if (target != null) break;
         * }
         * }
         * }
         *
         * if (target == null)
         * {
         * throw new Exception("Unable to infer type for reference " + original + ".");
         * }
         * else return target.Yields;
         * }
         */

        protected RCVectorBase MakeVector(RCArray <RCToken> vector)
        {
            RCVectorBase result = null;

            if (vector[0].Text[0] == '~')
            {
                switch (vector[0].Text[1])
                {
                case 'x': return(RCByte.Empty);

                case 'b': return(RCBoolean.Empty);

                case 'l': return(RCLong.Empty);

                case 'd': return(RCDouble.Empty);

                case 'm': return(RCDecimal.Empty);

                case 's': return(RCString.Empty);

                case 'y': return(RCSymbol.Empty);

                case 't': return(RCTime.Empty);

                case 'n': return(RCIncr.Empty);

                default: throw new Exception("Unrecognized type code: " + vector[0].Text[1]);
                }
            }
            if (vector[0].Type == RCTokenType.Symbol)
            {
                RCArray <RCSymbolScalar> list = new RCArray <RCSymbolScalar> (vector.Count);
                for (int i = 0; i < vector.Count; ++i)
                {
                    list.Write(vector[i].ParseSymbol(_lexer));
                }
                result = new RCSymbol(list);
            }
            else if (vector[0].Type == RCTokenType.String)
            {
                RCArray <string> list = new RCArray <string> (vector.Count);
                for (int i = 0; i < vector.Count; ++i)
                {
                    list.Write(vector[i].ParseString(_lexer));
                }
                result = new RCString(list);
            }
            else if (vector[0].Type == RCTokenType.Boolean)
            {
                RCArray <bool> list = new RCArray <bool> (vector.Count);
                for (int i = 0; i < vector.Count; ++i)
                {
                    list.Write(vector[i].ParseBoolean(_lexer));
                }
                result = new RCBoolean(list);
            }
            else if (vector[0].Type == RCTokenType.Incr)
            {
                RCArray <RCIncrScalar> list = new RCArray <RCIncrScalar> (vector.Count);
                for (int i = 0; i < vector.Count; ++i)
                {
                    list.Write(vector[i].ParseIncr(_lexer));
                }
                result = new RCIncr(list);
            }
            else if (vector[0].Type == RCTokenType.Literal)
            {
                char type = vector[0].Text[1];
                switch (type)
                {
                case 'x':
                    RCArray <byte> list = new RCArray <byte> (vector.Count);
                    for (int i = 0; i < vector.Count; ++i)
                    {
                        list.Write(vector[i].ParseByte(_lexer));
                    }
                    result = new RCByte(list);
                    break;

                default: throw new Exception("Unknown type specifier:" + type);
                }
            }
            else if (vector[0].Type == RCTokenType.Time)
            {
                RCArray <RCTimeScalar> list = new RCArray <RCTimeScalar> (vector.Count);
                for (int i = 0; i < vector.Count; ++i)
                {
                    list.Write(vector[i].ParseTime(_lexer));
                }
                result = new RCTime(list);
            }
            else if (vector[0].Type == RCTokenType.Number)
            {
                // have a look at the last character in the last token
                // if there is a type specifier there we will use it to
                // create the appropriate type of vector.
                RCToken last = vector[vector.Count - 1];
                char    type = last.Text[last.Text.Length - 1];
                if (type == 'l')
                {
                    RCArray <long> list = new RCArray <long> (vector.Count);
                    for (int i = 0; i < vector.Count; ++i)
                    {
                        list.Write(vector[i].ParseLong(_lexer));
                    }
                    result = new RCLong(list);
                }
                if (type == 'd')
                {
                    RCArray <double> list = new RCArray <double> (vector.Count);
                    for (int i = 0; i < vector.Count; ++i)
                    {
                        list.Write(vector[i].ParseDouble(_lexer));
                    }
                    result = new RCDouble(list);
                }
                else if (type == 'm')
                {
                    RCArray <decimal> list = new RCArray <decimal> (vector.Count);
                    for (int i = 0; i < vector.Count; ++i)
                    {
                        list.Write(vector[i].ParseDecimal(_lexer));
                    }
                    result = new RCDecimal(list);
                }
                else // default to double
                {
                    if (vector[0].Text.IndexOf('.') > -1 || vector[0].Text == "NaN")
                    {
                        RCArray <double> list = new RCArray <double> (vector.Count);
                        for (int i = 0; i < vector.Count; ++i)
                        {
                            list.Write(vector[i].ParseDouble(_lexer));
                        }
                        result = new RCDouble(list);
                    }
                    else
                    {
                        RCArray <long> list = new RCArray <long> (vector.Count);
                        for (int i = 0; i < vector.Count; ++i)
                        {
                            list.Write(vector[i].ParseLong(_lexer));
                        }
                        result = new RCLong(list);
                    }
                }
            }
            return(result);
        }
コード例 #5
0
 public void EvalEval(RCRunner runner, RCClosure closure, RCBlock left, RCDecimal right)
 {
     runner.Yield(closure, right);
 }