Ejemplo n.º 1
0
        private static object EvaluateVectorLiteral(VectorLiteral vectorLiteral, EvaluationContext context)
        {
            var vector = new double[vectorLiteral.Elements.Count];

            for (int i = 0; i < vectorLiteral.Elements.Count; i++)
            {
                if (!((Evaluate(vectorLiteral.Elements[i], context) ?? 0.0) is double number))
                {
                    throw new InvalidOperationException($"A {BaseTypes.Vector} can only contain numbers.");
                }

                vector[i] = number;
            }
            return(vector);
        }
Ejemplo n.º 2
0
 public WriteAction Visit(VectorLiteral vectorLiteral)
 {
     return(Format(ReservedName.__vector__ + "(@)", Translate(vectorLiteral.Items, ", ")));
 }
Ejemplo n.º 3
0
        public Expression TypeCheck(VectorLiteral vectorLiteral, Scope scope)
        {
            var position = vectorLiteral.Position;
            var items = vectorLiteral.Items;

            var typedItems = TypeCheck(items, scope);

            var firstItemType = typedItems.First().Type;

            foreach (var typedItem in typedItems)
                Unify(typedItem.Position, firstItemType, typedItem.Type);

            return new VectorLiteral(position, typedItems, NamedType.Vector(firstItemType));
        }
Ejemplo n.º 4
0
 public string Visit(VectorLiteral vectorLiteral)
 {
     return(String.Format("[{0}]", Translate(vectorLiteral.Items, ", ")));
 }