Exemplo n.º 1
0
        private ForeignKeyViolationException ForeignKeyViolation(int keySurr)
        {
            Obj key = source.store.SurrToValue(keySurr);

            Obj[] fromTuple = new Obj[] { key, IntObj.Get(source.Lookup(keySurr)) };
            return(ForeignKeyViolationException.BinaryUnary(source.relvarName, 1, target.relvarName, fromTuple, key));
        }
Exemplo n.º 2
0
        public override void Copy(int first, int count, Obj[] array, int destOffset)
        {
            int srcOffset = offset + first;

            for (int i = 0; i < count; i++)
            {
                array[destOffset + i] = IntObj.Get(ints[srcOffset + i]);
            }
        }
Exemplo n.º 3
0
        private KeyViolationException Col1KeyViolation(int idx, long value, long otherValue, bool betweenNew)
        {
            //## BUG: Stores may contain only part of the value (id(5) -> 5)
            Obj key = store.SurrToValue(idx);

            Obj[] tuple1 = new Obj[] { key, IntObj.Get(value) };
            Obj[] tuple2 = new Obj[] { key, IntObj.Get(otherValue) };
            return(new KeyViolationException(relvarName, KeyViolationException.key_1, tuple1, tuple2, betweenNew));
        }
Exemplo n.º 4
0
        ////////////////////////////////////////////////////////////////////////////////

        // If the function is successfull, it returns the index of the next token to consume
        // If it fails, it returns the location/index of the error, negated and decremented by one
        static long ParseObj(Token[] tokens, long offset, out Obj var)
        {
            int length = tokens.Length;

            if (offset >= length)
            {
                var = null;
                return(-offset - 1);
            }

            Token token = tokens[offset];

            switch (token.type)
            {
            case TokenType.Comma:
            case TokenType.Colon:
            case TokenType.Semicolon:
            case TokenType.Arrow:
            case TokenType.ClosePar:
            case TokenType.CloseBracket:
                var = null;
                return(-offset - 1);

            case TokenType.Int:
                var = IntObj.Get((long)token.value);
                return(offset + 1);

            case TokenType.Float:
                var = new FloatObj((double)token.value);
                return(offset + 1);

            case TokenType.Symbol:
                return(ParseSymbOrTaggedObj(tokens, offset, out var));

            case TokenType.OpenPar:
                if (IsRecord(tokens, offset))
                {
                    return(ParseRec(tokens, offset, out var));
                }
                else
                {
                    return(ParseSeq(tokens, offset, out var));
                }

            case TokenType.OpenBracket:
                return(ParseUnordColl(tokens, offset, out var));

            case TokenType.String:
                var = Miscellanea.StrToObj((string)token.value);
                return(offset + 1);

            default:
                var = null;
                throw new InvalidOperationException(); // Unreachable code
            }
        }
Exemplo n.º 5
0
        public static Obj BuildConstIntSeq(int[] vals)
        {
            int len = vals.Length;

            Obj[] objs = new Obj[len];
            for (int i = 0; i < len; i++)
            {
                objs[i] = IntObj.Get(vals[i]);
            }
            return(new MasterSeqObj(objs));
        }
Exemplo n.º 6
0
 // Inefficient, but used only for debugging
 public override Obj SurrToValue(int surr)
 {
     for (int i = 0; i < count; i++)
     {
         if (surrogates[i] == surr)
         {
             return(IntObj.Get(values[i]));
         }
     }
     return(IntObj.Get(store.SurrToValue(surr)));
 }
Exemplo n.º 7
0
 public static Obj At(long[] array, int size, long idx)
 {
     if (idx < size)
     {
         return(IntObj.Get(array[(int)idx]));
     }
     else
     {
         throw ErrorHandler.SoftFail();
     }
 }
Exemplo n.º 8
0
        public static Obj StringToObj(string str)
        {
            int[] cps = Miscellanea.CodePoints(str);
            int   len = cps.Length;

            Obj[] objs = new Obj[len];
            for (int i = 0; i < len; i++)
            {
                objs[i] = IntObj.Get(cps[i]);
            }
            return(new TaggedObj(SymbTable.StringSymbId, new MasterSeqObj(objs)));
        }
Exemplo n.º 9
0
        public static Obj GetChar_P(object env)
        {
            int ch = Console.Read();

            if (ch != -1)
            {
                return(new TaggedObj(SymbTable.JustSymbId, IntObj.Get(ch)));
            }
            else
            {
                return(SymbObj.Get(SymbTable.NothingSymbId));
            }
        }
Exemplo n.º 10
0
        public static Obj Parse(Obj text)
        {
            byte[] bytes = text.GetInnerObj().GetByteArray();
            Obj    obj;
            long   errorOffset;
            bool   ok = Parse(bytes, out obj, out errorOffset);

            if (ok)
            {
                return(new TaggedObj(SymbTable.SuccessSymbId, obj));
            }
            else
            {
                return(new TaggedObj(SymbTable.FailureSymbId, IntObj.Get(errorOffset)));
            }
        }
Exemplo n.º 11
0
        public static Obj StrToObj(string str)
        {
            int len = str.Length;

            Obj[] chars = new Obj[len];
            int   count = 0;
            int   i     = 0;

            while (i < len)
            {
                int ch = Char.ConvertToUtf32(str, i);
                chars[count++] = IntObj.Get(ch);
                i += Char.IsSurrogatePair(str, i) ? 2 : 1;
            }
            return(new TaggedObj(SymbTable.StringSymbId, new MasterSeqObj(chars, count)));
        }
Exemplo n.º 12
0
 public override Obj GetInnerObj()
 {
     return(IntObj.Get(GetInnerLong()));
 }
Exemplo n.º 13
0
 public override Obj GetObjAt(long idx)
 {
     return(IntObj.Get(GetLongAt(idx)));
 }
Exemplo n.º 14
0
 public override NeSeqObj Append(long value)
 {
     return(Append(IntObj.Get(value)));
 }
Exemplo n.º 15
0
        //////////////////////////////////////////////////////////////////////////////

        private ForeignKeyViolationException ForeignKeyViolation(int keySurr, long value)
        {
            Obj[] tuple = new Obj[] { source.store.SurrToValue(keySurr), IntObj.Get(value) };
            return(ForeignKeyViolationException.BinaryUnary(source.relvarName, 1, target.relvarName, tuple));
        }
Exemplo n.º 16
0
        //////////////////////////////////////////////////////////////////////////////

        public static Obj Copy(ColumnBase[] columns, bool flipCols)
        {
            int totalSize = 0;

            for (int i = 0; i < columns.Length; i++)
            {
                totalSize += columns[i].count;
            }

            if (totalSize == 0)
            {
                return(EmptyRelObj.singleton);
            }

            Obj[] objs1 = new Obj[totalSize];
            Obj[] objs2 = new Obj[totalSize];

            int next = 0;

            for (int i = 0; i < columns.Length; i++)
            {
                ColumnBase col = columns[i];
                if (col is IntColumn)
                {
                    IntColumn      intCol = (IntColumn)col;
                    IntColumn.Iter it     = intCol.GetIter();
                    while (!it.Done())
                    {
                        objs1[next] = intCol.mapper(it.GetIdx());
                        objs2[next] = IntObj.Get(it.GetValue());
                        next++;
                        it.Next();
                    }
                }
                else if (col is FloatColumn)
                {
                    FloatColumn      floatCol = (FloatColumn)col;
                    FloatColumn.Iter it       = floatCol.GetIter();
                    while (!it.Done())
                    {
                        objs1[next] = floatCol.mapper(it.GetIdx());
                        objs2[next] = new FloatObj(it.GetValue());
                        next++;
                        it.Next();
                    }
                }
                else
                {
                    ObjColumn      objCol = (ObjColumn)col;
                    ObjColumn.Iter it     = objCol.GetIter();
                    while (!it.Done())
                    {
                        objs1[next] = objCol.mapper(it.GetIdx());
                        objs2[next] = it.GetValue();
                        next++;
                        it.Next();
                    }
                }
            }
            Debug.Assert(next == totalSize);

            if (flipCols)
            {
                Obj[] tmp = objs1;
                objs1 = objs2;
                objs2 = tmp;
            }

            return(Builder.CreateBinRel(objs1, objs2));
        }
Exemplo n.º 17
0
 override public Obj AsObj()
 {
     return(IntObj.Get(value));
 }