Esempio n. 1
0
        private StackValue CreateVector(int start, int vecLen, int step, bool typed, bool fix, StackValue?keys = null)
        {
            var bitWidth    = BitWidthUtil.Width(vecLen);
            var prefixElems = 1;

            if (keys != null)
            {
                var elemWidth = keys.Value.ElementWidth(_offset, 0);
                if ((int)elemWidth > (int)bitWidth)
                {
                    bitWidth = elemWidth;
                }

                prefixElems += 2;
            }

            var vectorType = Type.Key;

            for (var i = start; i < _stack.Count; i += step)
            {
                var elemWidth = _stack[i].ElementWidth(_offset, i + prefixElems);
                if ((int)elemWidth > (int)bitWidth)
                {
                    bitWidth = elemWidth;
                }

                if (typed)
                {
                    if (i == start)
                    {
                        vectorType = _stack[i].TypeOfValue;
                    }
                    else
                    {
                        if (vectorType != _stack[i].TypeOfValue)
                        {
                            throw new Exception($"Your typed vector is of type {vectorType} but the item on index {i} is of type {_stack[i].TypeOfValue}");
                        }
                    }
                }
            }

            if (TypesUtil.IsTypedVectorElement(vectorType) == false)
            {
                throw new Exception("Your fixed types are not one of: Int / UInt / Float / Key");
            }

            var byteWidth = Align(bitWidth);

            if (keys != null)
            {
                Write(keys.Value, byteWidth);
                Write(1 << (int)keys.Value.InternalWidth, byteWidth);
            }

            if (!fix)
            {
                Write(vecLen, byteWidth);
            }

            var vloc = _offset;

            for (var i = start; i < _stack.Count; i += step)
            {
                Write(_stack[i], byteWidth);
            }

            if (!typed)
            {
                for (var i = start; i < _stack.Count; i += step)
                {
                    Write(_stack[i].StoredPackedType());
                }
            }


            if (keys != null)
            {
                return(StackValue.Value(vloc, bitWidth, Type.Map));
            }

            if (typed)
            {
                var type = TypesUtil.ToTypedVector(vectorType, (byte)(fix ? vecLen : 0));
                return(StackValue.Value(vloc, bitWidth, type));
            }

            return(StackValue.Value(vloc, bitWidth, Type.Vector));
        }
Esempio n. 2
0
 internal Type Add(bool value)
 {
     _stack.Add(StackValue.Value(value));
     return(Type.Bool);
 }
Esempio n. 3
0
 internal Type Add(ulong value)
 {
     _stack.Add(StackValue.Value(value));
     return(Type.Uint);
 }
Esempio n. 4
0
 internal Type Add(double value)
 {
     _stack.Add(StackValue.Value(value));
     return(Type.Float);
 }
Esempio n. 5
0
 internal Type AddNull()
 {
     _stack.Add(StackValue.Null());
     return(Type.Null);
 }