Ejemplo n.º 1
0
        public override ILanguageValue CreateDefaultValue(ILanguageType langType)
        {
            if (ReferenceEquals(langType, null))
            {
                throw new ArgumentNullException();
            }

            if (langType.IsSameType(BooleanType))
            {
                return(ValuePrimitive <bool> .Create((TypePrimitive)langType, false));
            }

            if (langType.IsSameType(IntegerType))
            {
                return(ValuePrimitive <int> .Create((TypePrimitive)langType, 0));
            }

            if (langType.IsSameType(ScalarType))
            {
                return(ValuePrimitive <MathematicaScalar> .Create((TypePrimitive)langType, SymbolicUtils.Constants.Zero));
            }

            var typeStructure = langType as GMacStructure;

            if (typeStructure != null)
            {
                var structure = typeStructure;

                var valueSparse = ValueStructureSparse.Create(structure);

                //This code is not required for a sparse structure value
                //foreach (var data_member in structure.DataMembers)
                //    value_sparse[data_member.ObjectName] = this.CreateDefaultValue(data_member.SymbolType);

                return(valueSparse);
            }

            if (!(langType is GMacFrameMultivector))
            {
                throw new InvalidOperationException("GMac type not recognized!");
            }

            var mvType = (GMacFrameMultivector)langType;

            var value = GMacValueMultivector.CreateZero(mvType);

            //This code is not required for a sparse multivector value
            //for (int id = 0; id < mv_type.ParentFrame.GASpaceDimension; id++)
            //    value[id] = SymbolicUtils.Constants.Zero;

            return(value);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns true if an expression of type rhs_type can be assigned to an expression of type lhs_type
 /// </summary>
 /// <param name="lhsType"></param>
 /// <param name="rhsType"></param>
 /// <returns></returns>
 public static bool CanAssignValue(this ILanguageType lhsType, ILanguageType rhsType)
 {
     return
         ((IsBoolean(lhsType) && IsBoolean(rhsType)) ||
          (IsInteger(lhsType) && IsInteger(rhsType)) ||
          (IsScalar(lhsType) && IsNumber(rhsType)) ||
          (IsStructure(lhsType) && lhsType.IsSameType(rhsType)) ||
          (IsFrameMultivector(lhsType) && IsNumber(rhsType)) ||
          (HasSameFrame(lhsType, rhsType)));
 }
Ejemplo n.º 3
0
        private void VerifyOperation_PolyadicOperandAssignment(ILanguageType lhsType)
        {
            if (lhsType.IsSameType(Operand1Type))
            {
                ForceAtomicOperands(null);
            }

            else if (lhsType.IsScalar() && Operand1Type.IsNumber())
            {
                ForceAtomicScalarOperands(null);
            }

            else if (lhsType.IsFrameMultivector() && Operand1Type.IsNumber())
            {
                ForceAtomicMultivectorOperands(null);
            }

            else
            {
                Context.CreateTypeMismatch("Cannot assign expression of type " + Operand1TypeSignature + " to parameter of type " + lhsType);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// True if this is a valid type exactly like the given type
 /// </summary>
 /// <param name="astType"></param>
 /// <returns></returns>
 public bool IsSameType(AstType astType)
 {
     return(IsValid && astType.IsNotNullAndValid() && AssociatedType.IsSameType(astType.AssociatedType));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// True if the type of this symbol is the same as the given type
 /// </summary>
 /// <param name="languageType">The name of the type to be compared</param>
 /// <returns></returns>
 public bool HasSameType(ILanguageType languageType)
 {
     return(HasType && _symbolType.IsSameType(languageType));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Retutns true if the two types are of the same multivector type
 /// </summary>
 /// <param name="langType"></param>
 /// <param name="rhsType"></param>
 /// <returns></returns>
 public static bool IsSameMultivector(this ILanguageType langType, ILanguageType rhsType)
 {
     return(IsFrameMultivector(langType) && langType.IsSameType(rhsType));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Retutns true if the two types are of the same structure type
 /// </summary>
 /// <param name="langType"></param>
 /// <param name="rhsType"></param>
 /// <returns></returns>
 public static bool IsSameStructure(this ILanguageType langType, ILanguageType rhsType)
 {
     return(IsStructure(langType) && langType.IsSameType(rhsType));
 }