Пример #1
0
        // Create a row from a heading by converting a value
        public TupleValue RowC(TypedValue hdgarg, TypedValue[] valuearg)
        {
            var     heading = hdgarg.AsHeading();
            var     value   = valuearg[0];
            DataRow newrow  = null;

            if (value.DataType is DataTypeTuple)
            {
                newrow = value.AsRow();
            }
            else if (value.DataType is DataTypeUser)
            {
                var user = value as UserValue;
                newrow = DataRow.Create(user.Heading, user.Value);
            }
            else if (value.DataType is DataTypeRelation)
            {
                var rel = value.AsTable();
                newrow = rel.GetRows().FirstOrDefault();
                if (newrow == null)
                {
                    throw ProgramError.Fatal("Builtin", "relation is empty");
                }
            }
            Logger.Assert(newrow != null, "RowT");
            Logger.WriteLine(3, "[Row={0}]", newrow);
            return(TupleValue.Create(newrow));
        }
Пример #2
0
        // Create a row from values and a heading
        public TupleValue RowV(TypedValue hdgarg, params TypedValue[] valueargs)
        {
            var heading = hdgarg.AsHeading();
            var newrow  = DataRow.Create(heading, valueargs);

            Logger.WriteLine(3, "[Row={0}]", newrow);
            return(TupleValue.Create(newrow));
        }
Пример #3
0
 public override TypedValue DefaultValue()
 {
     if (_default == null)
     {
         _default = TupleValue.Create(DataRow.Create(Heading, MakeDefaultValues(Heading)));
     }
     return(_default);
 }
Пример #4
0
        // Create a row from a row
        //public TupleValue RowR(TypedValue hdgarg, TupleValue rowarg) {
        //  var newrow = rowarg.Value;
        //  Logger.WriteLine(3, "[Row={0}]", newrow);
        //  return TupleValue.Create(newrow);
        //}

        // Create a row by evaluating named expressions against a heading
        public TupleValue Row(TypedValue hdgarg, params CodeValue[] exprargs)
        {
            var heading = hdgarg.AsHeading();
            var exprs   = exprargs.Select(e => (e as CodeValue).AsEval).ToArray();
            var newrow  = DataRow.Create(heading, exprs);

            Logger.WriteLine(3, "[Row={0}]", newrow);
            return(TupleValue.Create(newrow));
        }
Пример #5
0
        // Transform tuple
        public TupleValue TransTuple(TupleValue tuparg, params CodeValue[] exprargs)
        {
            Logger.WriteLine(3, "TransTuple {0} {1}", tuparg, exprargs.Select(e => e.AsEval.Kind.ToString()).ToArray());
            var tup     = tuparg.Value;
            var exprs   = exprargs.Select(e => (e as CodeValue).AsEval).ToArray();
            var heading = DataHeading.Create(exprs);
            var tupnew  = tup.Transform(heading, exprs);

            Logger.WriteLine(3, "[TrT {0}]", tupnew);
            return(TupleValue.Create(tupnew));
        }
Пример #6
0
        // Dyadic tuple: does Set ops depending on joinop bit flags
        public TupleValue DyadicTuple(TupleValue tup1, TupleValue tup2, NumberValue joparg)
        {
            var joinop     = (JoinOps)joparg.Value;
            var mergeop    = (MergeOps)((int)(joinop & JoinOps.SETOPS) >> 3); // FIX: bit func?
            var newheading = DataHeading.Merge(mergeop, tup1.Value.Heading, tup2.Value.Heading);

            Logger.WriteLine(3, "DyadicTuple {0} {1} n={2} ({3} {4})", tup1, tup2, joparg, mergeop, newheading);
            var tupnew = DataRow.Create(newheading, tup1.Value, tup2.Value);

            Logger.WriteLine(3, "[DT {0}]", tupnew);
            return(TupleValue.Create(tupnew));
        }
Пример #7
0
        public void SetStructEnd()
        {
            var tuple = FilledValues();

            _valueholder = _valueholder._parent;
            var datatype = _valueholder.DataType;

            if (datatype is DataTypeUser)
            {
                _valueholder._values[_valueholder._colidx] = UserValue.Create(tuple, datatype as DataTypeUser);
            }
            else if (datatype is DataTypeTuple)
            {
                var row = DataRow.Create(datatype.Heading, tuple);
                _valueholder._values[_valueholder._colidx] = TupleValue.Create(row);
            }
            else
            {
                Logger.Assert(_valueholder.DataType is DataTypeRelation);
                _valueholder._list.Add(tuple);
            }
        }
Пример #8
0
 // Create a value for this type
 public TupleValue CreateValue(TypedValue[] values)
 {
     return(TupleValue.Create(DataRow.Create(Heading, values)));
 }
Пример #9
0
 static TupleValue()
 {
     Default = new TupleValue {
         Value = DataRow.Empty
     };
 }