Ejemplo n.º 1
0
        public bool GetBoolean(long i)
        {
            RCBoolean val = (RCBoolean)Get(i);

            if (val == null)
            {
                throw new Exception(string.Format("No value at index {0} within block (count:{1})",
                                                  i,
                                                  Count));
            }
            return(val[0]);
        }
Ejemplo n.º 2
0
        public bool GetBoolean(string name)
        {
            RCBoolean val = (RCBoolean)Get(name);

            if (val == null)
            {
                throw new Exception("Required value " + name + " not found in block");
            }
            else
            {
                return(val[0]);
            }
        }
Ejemplo n.º 3
0
        public bool GetBoolean(string name, bool def)
        {
            RCBoolean val = (RCBoolean)Get(name);

            if (val == null)
            {
                return(def);
            }
            else
            {
                return(val[0]);
            }
        }
Ejemplo n.º 4
0
        public void EvalAssert(RCRunner runner, RCClosure closure, RCBoolean right)
        {
            for (int i = 0; i < right.Count; ++i)
            {
                if (!right[i])
                {
                    RCCube         target = new RCCube(new RCArray <string> ("S"));
                    Stack <object> names  = new Stack <object> ();
                    RCBlock        block  = new RCBlock("", ":", closure.Code);
                    block.Cubify(target, names);
                    ColumnBase column = target.GetColumn("r");

                    string expression;
                    if (column != null)
                    {
                        RCArray <string> refNames = (RCArray <string>)column.Array;
                        // Only display the variables whose values are referenced in the assert
                        // expression
                        RCBlock displayVars = RCBlock.Empty;
                        for (int j = 0; j < refNames.Count; ++j)
                        {
                            RCArray <string> nameParts = RCName.MultipartName(refNames[j], '.');
                            RCValue          val       = Eval.Resolve(null, closure, nameParts, null, returnNull: true);
                            if (val != null)
                            {
                                displayVars = new RCBlock(displayVars, refNames[j], ":", val);
                            }
                        }
                        expression = string.Format("{0}, {1}", closure.Code.ToString(), displayVars);
                    }
                    else
                    {
                        expression = string.Format("{0}", closure.Code.ToString());
                    }
                    throw new RCException(closure, RCErrors.Assert, "Failed: " + expression);
                }
            }
            runner.Yield(closure, new RCBoolean(true));
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
 public void EvalEval(RCRunner runner, RCClosure closure, RCBlock left, RCBoolean right)
 {
     runner.Yield(closure, right);
 }