private ValuePrimitive <MathematicaScalar> GetRandomValue(ILanguageType valueType) { Expr valueExpr; if (valueType.IsInteger()) { valueExpr = new Expr(_randomSource.Next(1, 10)); } else if (valueType.IsBoolean()) { valueExpr = new Expr(_randomSource.Next(0, 1) != 0); } else if (valueType.IsScalar()) { valueExpr = new Expr(_randomSource.NextDouble() * 10.0 - 5.0); } //value_expr = new Expr(new Expr(ExpressionType.Symbol, "Rational"), _RandomSource.Next(1, 10), _RandomSource.Next(1, 10)); else { throw new InvalidOperationException(); } return (ValuePrimitive <MathematicaScalar> .Create( (TypePrimitive)valueType, MathematicaScalar.Create(SymbolicUtils.Cas, valueExpr) )); }
public void VerifyOperation_TypeCast(ILanguageType targetType) { //Cast an integer to a scalar if (targetType.IsScalar() && Operand1Type.IsInteger()) { ForceAtomicOperands(targetType); } //Cast a number to a multivector else if (targetType.IsFrameMultivector() && Operand1Type.IsNumber()) { ForceAtomicOperands(targetType); } //Cast multivector to a multivector with the same frame dimension (by diectly copying coeffecients) //useful for example when transforming a computation to Euclidean space with the same dimensions else if (targetType.IsFrameMultivector() && Operand1Type.IsFrameMultivector() && targetType.GetFrame().VSpaceDimension == Operand1Type.GetFrame().VSpaceDimension) { ForceAtomicOperands(targetType); } else { Context.CreateTypeMismatch("Cannot apply type cast " + targetType.TypeSignature + " to expression of type " + Operand1TypeSignature); } }
public IProject GetProjectTemplate(ICategory category, ILanguageType langType, Guid projectId) { if (category == null || langType == null || projectId == null) { return(null); } if (category.Name == null || langType.Name == null) { return(null); } if (this._templates == null || this._templates.Count == 0) { this._templates = GetTemplates(); } Logger.Debug(String.Format("Applying filter [Category = '{0}' And LanguageType = '{1}' And Project.Id = '{2}'] on all templates", category.Name, langType.Name, projectId)); foreach (ITemplate template in this._templates) { if (template.Category.Equals(category.Name) && template.LanguageType.Equals(langType.Name)) { foreach (IProject v_project in template.Projects) { if (projectId == v_project.Id) { return(v_project); } } } } return(null); }
private void VerifyOperation_Times() { if (Operand1Type.IsNumber() && Operand2Type.IsNumber()) { ForceAtomicScalarOperands(ScalarType); } else if (Operand1Type.IsFrameMultivector() && Operand2Type.IsNumber()) { _resultType = Operand1Type; _atomicOperand1 = Context.ActiveParentCommandBlock.ExpressionToMultivectorAtomicExpression(OperandsMultivectorType, _operand1); _atomicOperand2 = Context.ActiveParentCommandBlock.ExpressionToScalarAtomicExpression(_operand2); } else if (Operand1Type.IsNumber() && Operand2Type.IsFrameMultivector()) { _resultType = Operand2Type; _atomicOperand1 = Context.ActiveParentCommandBlock.ExpressionToScalarAtomicExpression(_operand1); _atomicOperand2 = Context.ActiveParentCommandBlock.ExpressionToMultivectorAtomicExpression(OperandsMultivectorType, _operand2); } else { Context.CreateTypeMismatch("cannot apply Times to expressions of type " + Operand1TypeSignature + " and " + Operand2TypeSignature); } }
/// <summary> /// Create a new ValueComponentAccessBySymbol object and append it to this LanguageValueAccess /// </summary> /// <param name="accessStepSymbol"></param> /// <param name="accessStepType"></param> /// <returns></returns> public LanguageValueAccess Append(SymbolLValue accessStepSymbol, ILanguageType accessStepType) { var accessStep = ValueAccessStepByLValue.Create(accessStepType, accessStepSymbol); _accessSteps.Add(accessStep); return(this); }
/// <summary> /// Create a new ValueComponentAccessByIndexList object and append it to this LanguageValueAccess /// </summary> /// <param name="accessStepIndexList"></param> /// <param name="accessStepType"></param> /// <returns></returns> public LanguageValueAccess Append <TK>(IEnumerable <TK> accessStepIndexList, ILanguageType accessStepType) where TK : IComparable <TK> { var accessStep = ValueAccessStepByKeyList <TK> .Create(accessStepType, accessStepIndexList); _accessSteps.Add(accessStep); return(this); }
protected SymbolStructureDataMember(string symbolName, ILanguageType symbolType, LanguageScope parentScope, string symbolRoleName, bool canRead, bool canWrite) : base(symbolName, symbolType, parentScope, symbolRoleName) { DefinitionIndex = parentScope.Symbols(symbolRoleName).Count(); CanRead = canRead; CanWrite = canWrite; }
private void ForceAtomicMultivectorOperands(ILanguageType resultType) { _resultType = resultType; _atomicOperand1 = Context.ActiveParentCommandBlock.ExpressionToMultivectorAtomicExpression(OperandsMultivectorType, _operand1); _atomicOperand2 = ReferenceEquals(_operand2, null) ? null : Context.ActiveParentCommandBlock.ExpressionToMultivectorAtomicExpression(OperandsMultivectorType, _operand2); }
public ILanguageExpressionBasic Generate_TypeCast(ILanguageType targetType, ILanguageOperator castOp, ILanguageExpression expr) { SetOperands(expr); VerifyOperation_TypeCast(targetType); return(BasicUnary.CreateTypeCast(targetType, castOp, _atomicOperand1)); }
public ILanguageExpressionAtomic Generate_PolyadicOperand(ILanguageType lhsType, ILanguageExpression rhsExpr) { SetOperands(rhsExpr); VerifyOperation_PolyadicOperandAssignment(lhsType); return(_atomicOperand1); }
public bool IsCompatibleType(ILanguageType languageType) { if (!(languageType is GMacFrameMultivector)) { return(false); } return(((GMacFrameMultivector)languageType).ObjectId == ObjectId); }
public virtual bool IsSameType(ILanguageType languageType) { if (!(languageType is TypePrimitive)) { return(false); } return(((TypePrimitive)languageType).ObjectId == ObjectId); }
/// <summary> /// True for a frame multivector type /// </summary> /// <param name="langType"></param> /// <returns></returns> public static bool IsFrameMultivector(this ILanguageType langType) { if (ReferenceEquals(langType, null)) { return(false); } return(langType is GMacFrameMultivector); }
/// <summary> /// True for built-in types /// </summary> /// <param name="langType"></param> /// <returns></returns> public static bool IsPrimitiveType(this ILanguageType langType) { if (ReferenceEquals(langType, null)) { return(false); } return(langType is TypePrimitive); }
/// <summary> /// True for a GMac structure type /// </summary> /// <param name="langType"></param> /// <returns></returns> public static bool IsStructure(this ILanguageType langType) { if (ReferenceEquals(langType, null)) { return(false); } return(langType is TypeStructure); }
public virtual bool IsSameType(ILanguageType languageType) { if (!(languageType is TypeReference)) { return(false); } return(((TypeReference)languageType).DataType.IsSameType(DataType)); }
/// <summary> /// Retutns true if the two types are multivector types and have the same frame /// </summary> /// <param name="langType"></param> /// <param name="rhsType"></param> /// <returns></returns> public static bool HasSameFrame(this ILanguageType langType, ILanguageType rhsType) { return (langType != null && rhsType != null && langType is GMacFrameMultivector && rhsType is GMacFrameMultivector && ((GMacFrameMultivector)langType).ParentFrame.ObjectId == ((GMacFrameMultivector)rhsType).ParentFrame.ObjectId); }
public virtual bool IsCompatibleType(ILanguageType languageType) { if (!(languageType is TypeStructure)) { return(false); } return(((TypeStructure)languageType).ObjectId == ObjectId); }
public virtual bool IsCompatibleType(ILanguageType languageType) { if (!(languageType is TypeArray)) { return(false); } return(ArrayItemType.IsCompatibleType(((TypeArray)languageType).ArrayItemType)); }
public virtual bool IsCompatibleType(ILanguageType languageType) { if (!(languageType is TypePointer)) { return(false); } return(((TypePointer)languageType).DataType.IsCompatibleType(DataType)); }
public virtual CommandDeclareVariable DefineLocalVariable(ILanguageType symbolType) { var localVar = SymbolLocalVariable.Create(symbolType, ChildCommandBlockScope); var command = new CommandDeclareVariable(ChildCommandBlockScope, localVar); CommandsList.Add(command); return(command); }
/// <summary> /// Define a new temporary local variable in the optimized block /// </summary> /// <param name="varType"></param> /// <returns></returns> private SymbolLocalVariable DefineNewLocalVariable(ILanguageType varType) { _updateChainFlag = true; var varName = "AV" + (_augmentedVariablesIndex++).ToString("X4"); var declareCommand = _optimizedBlock.DefineLocalVariable(varName, varType); return((SymbolLocalVariable)declareCommand.DataStore); }
/// <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))); }
protected SymbolProcedureParameter(string symbolName, ILanguageType symbolType, LanguageScope parentScope, string symbolRoleName, bool dirIn, bool dirOut) : base(symbolName, symbolType, parentScope, symbolRoleName) { if (!(dirIn || dirOut)) { throw new Exception("Illegal procedure parameter direction"); } DefinitionIndex = parentScope.Symbols(symbolRoleName).Count(); DirectionIn = dirIn; DirectionOut = dirOut; }
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); }
internal bool LookupParameterType(string symbolName, out ILanguageType paramType) { SymbolProcedureParameter macroParam; if (ChildSymbolScope.LookupSymbol(symbolName, RoleNames.MacroParameter, out macroParam)) { paramType = macroParam.SymbolType; return(true); } paramType = null; return(false); }
public bool LookupLocalVariableType(string symbolName, out ILanguageType localVarType) { LanguageSymbol symbol; if (ChildCommandBlockScope.LookupSymbol(symbolName, RootAst.LocalVariableRoleName, out symbol)) { localVarType = ((SymbolDataStore)symbol).SymbolType; return(true); } localVarType = null; return(false); }
internal AstDatastoreValueAccess ToValueAccess(string valueAccessName, ILanguageType requiredType) { var valueAccess = ToValueAccess(valueAccessName); if (valueAccess.GMacType.AssociatedType.IsSameType(requiredType)) { return(valueAccess); } throw new InvalidOperationException( $"Specified macro parameter {valueAccessName} is not of required type {requiredType.TypeSignature}" ); }
/// <summary> /// True for built-in integer or scalar type /// </summary> /// <param name="langType"></param> /// <returns></returns> public static bool IsNumber(this ILanguageType langType) { if (ReferenceEquals(langType, null)) { return(false); } if (!(langType is TypePrimitive)) { return(false); } return(((TypePrimitive)langType).ObjectName == TypeNames.Integer || ((TypePrimitive)langType).ObjectName == TypeNames.Scalar); }
/// <summary> /// True for built-in boolean type /// </summary> /// <param name="langType"></param> /// <returns></returns> public static bool IsBoolean(this ILanguageType langType) { if (ReferenceEquals(langType, null)) { return(false); } if (!(langType is TypePrimitive)) { return(false); } return(((TypePrimitive)langType).ObjectName == TypeNames.Bool); }