private static void checkCanConvertTypes(PrimitiveDataType from, PrimitiveDataType to)
 {
     if (!BuiltIn.DataTypes.CanConvertTo(from, to))
     {
         throw new SyntaxException($"No conversion from {from.Name} to {to.Name}.");
     }
 }
        public static PrimitiveDataType GetImmedateDataType(ushort value)
        {
            PrimitiveDataType smallestDataType = null;

            foreach (var datatype in BuiltIn.DataTypes.All.Reverse())
            {
                if (value < datatype.MaxValue)
                {
                    smallestDataType = datatype;
                }
            }

            // Exeption cant possibly throw as ParseImmediate parses up to int data type
            if (smallestDataType == null)
            {
                throw new SyntaxException($"No datatype suitable for value ({value})");
            }

            return(smallestDataType);
        }
Exemple #3
0
 public static bool CanConvertTo(PrimitiveDataType from, PrimitiveDataType to) => to.NumBits >= @from.NumBits;