/// <summary> /// Evaluate a basic unary expression /// </summary> /// <param name="expr"></param> /// <returns></returns> public override ILanguageValue Visit(BasicUnary expr) { var typePrimitive = expr.Operator as TypePrimitive; if (typePrimitive != null && typePrimitive.IsScalar()) { return(EvaluateBasicUnaryCastToScalar(expr)); } if (expr.Operator is GMacFrameMultivector) { return(EvaluateBasicUnaryCastToMultivector(expr)); } if (expr.Operator is GMacMultivectorTransform) { return(EvaluateBasicUnaryMultivectorTransform(expr)); } var value1 = expr.Operand.AcceptVisitor(this); var unaryOp = GMacInterpreterUtils.UnaryEvaluators[expr.Operator.OperatorName]; return(value1.AcceptOperation(unaryOp)); }
internal static AstExpression ToAstExpression(this BasicUnary expr) { var op1 = expr.Operator as OperatorPrimitive; if (ReferenceEquals(op1, null) == false) { return(new AstUnaryExpression(expr)); } var op2 = expr.Operator as GMacMultivectorTransform; if (ReferenceEquals(op2, null) == false) { return(new AstTransformCall(expr)); } var op3 = expr.Operator as TypePrimitive; if (ReferenceEquals(op3, null) == false) { return(new AstTypeCast(expr)); } var op4 = expr.Operator as GMacFrameMultivector; if (ReferenceEquals(op4, null) == false) { return(new AstTypeCast(expr)); } return(null); }
/// <summary> /// Evaluate a cast to multivector value operation /// </summary> /// <param name="expr"></param> /// <returns></returns> private ILanguageValue EvaluateBasicUnaryCastToMultivector(BasicUnary expr) { var value1 = expr.Operand.AcceptVisitor(this); var mvType = (GMacFrameMultivector)expr.Operator; if (value1.ExpressionType.IsNumber()) { var scalarValue = ((ValuePrimitive <MathematicaScalar>)value1).Value; return(GMacValueMultivector.Create( mvType, GaSymMultivector.CreateScalar( mvType.ParentFrame.GaSpaceDimension, scalarValue ) )); } if (value1.ExpressionType.IsFrameMultivector() && value1.ExpressionType.GetFrame().VSpaceDimension == mvType.ParentFrame.VSpaceDimension) { var mvValue = (GMacValueMultivector)value1; return(GMacValueMultivector.Create( mvType, GaSymMultivector.CreateCopy(mvValue.SymbolicMultivector) )); } throw new InvalidOperationException("Invalid cast operation"); }
/// <summary> /// Evaluate a high-level basic unary expression into a value suitable for low-level code generation /// </summary> /// <param name="expr"></param> /// <returns></returns> public override ILanguageValue Visit(BasicUnary expr) { //Evaluate a cast-to-scalar operation var typePrimitive = expr.Operator as TypePrimitive; if (typePrimitive != null && typePrimitive.IsScalar()) { return(EvaluateBasicUnaryCastToScalar(expr)); } //Evaluate a cast-to-multivector operation if (expr.Operator is GMacFrameMultivector) { return(EvaluateBasicUnaryCastToMultivector(expr)); } //Evaluate a multivector linear transform operation if (expr.Operator is GMacMultivectorTransform) { return(EvaluateBasicUnaryMultivectorTransform(expr)); } //Evaluate all other types of unary operations using standard GMac unary evaluation process var value1 = expr.Operand.AcceptVisitor(this); var unaryOp = GMacInterpreterUtils.UnaryEvaluators[expr.Operator.OperatorName]; return(value1.AcceptOperation(unaryOp)); }
public ILanguageExpressionBasic Generate_UnaryNorm(GMacOpInfo opInfo, ILanguageExpression expr) { SetOperands(expr); VerifyOperation_UnaryNorm(); return(BasicUnary.CreatePrimitive(_resultType, opInfo.OpName, _atomicOperand1)); }
public ILanguageExpressionBasic Generate_TransformApplication(GMacMultivectorTransform transform, ILanguageExpression expr) { SetOperands(expr); VerifyOperation_TransformApplication(transform); return(BasicUnary.Create(_resultType, transform, _atomicOperand1)); }
public ILanguageExpressionBasic Generate_UnaryGradeInversion(ILanguageExpression expr) { SetOperands(expr); VerifyOperation_UnaryOperation(); return(BasicUnary.CreatePrimitive(_resultType, GMacOpInfo.UnaryGradeInvolution.OpName, _atomicOperand1)); }
public ILanguageExpressionBasic Generate_TypeCast(ILanguageType targetType, ILanguageOperator castOp, ILanguageExpression expr) { SetOperands(expr); VerifyOperation_TypeCast(targetType); return(BasicUnary.CreateTypeCast(targetType, castOp, _atomicOperand1)); }
public BasicUnary ReplaceLValueByExpression(BasicUnary oldExpr, SymbolLValue oldLvalue, ILanguageExpressionAtomic newExpr) { ReplaceLValueByExpression(oldExpr.Operator, oldLvalue, newExpr); oldExpr.ChangeOperand(ReplaceLValueByExpression(oldExpr.Operand, oldLvalue, newExpr)); return(oldExpr); }
private ILanguageExpression CompileBasicUnary(BasicUnary expr) { var compiledOperator = expr.Operator.DuplicateOperator(); var compiledOperand = (ILanguageExpressionAtomic)CompileExpression(expr.Operand); return(BasicUnary.Create(expr.ExpressionType, compiledOperator, compiledOperand)); }
public ILanguageExpressionBasic Generate_UnaryCliffordConjugate(ILanguageExpression expr) { SetOperands(expr); VerifyOperation_UnaryOperation(); return(BasicUnary.CreatePrimitive(_resultType, GMacOpInfo.UnaryCliffordConjugate.OpName, _atomicOperand1)); }
internal static AstTransformCall ToAstTransformCall(this BasicUnary expr) { if (expr.Operator is GMacMultivectorTransform) { return(new AstTransformCall(expr)); } throw new InvalidCastException(); }
internal static AstUnaryExpression ToAstUnaryExpression(this BasicUnary expr) { if (expr.Operator is OperatorPrimitive) { return(new AstUnaryExpression(expr)); } throw new InvalidCastException(); }
public void Visit(BasicUnary expr) { Log.Append(expr.Operator.OperatorName); Log.Append("("); expr.Operand.AcceptVisitor(this); Log.Append(")"); }
/// <summary> /// Evaluate a multivector transform operation /// </summary> /// <param name="expr"></param> /// <returns></returns> private GMacValueMultivector EvaluateBasicUnaryMultivectorTransform(BasicUnary expr) { var value1 = (GMacValueMultivector)expr.Operand.AcceptVisitor(this); var transform = (GMacMultivectorTransform)expr.Operator; return(GMacValueMultivector.Create( transform.TargetFrame.MultivectorType, transform.AssociatedSymbolicTransform[value1.SymbolicMultivector] )); }
public TreeNode Visit(BasicUnary expr) { var node = new TreeNode("<UNARY>" + expr.Operator.OperatorName) { Tag = expr }; node.Nodes.Add(expr.Operand.AcceptVisitor(this)); return(node); }
public IEnumerable <SymbolLValue> GetLValues(BasicUnary expr) { var lvalues = GetLValues(expr.Operator); var access = expr.Operand as LanguageValueAccess; if (access != null) { lvalues = lvalues.Concat(access.AccessLValues); } return(lvalues); }
internal static AstTypeCast ToAstTypeCast(this BasicUnary expr) { if (expr.Operator is GMacFrameMultivector) { return(new AstTypeCast(expr)); } if (expr.Operator is TypePrimitive) { return(new AstTypeCast(expr)); } throw new InvalidCastException(); }
//Methods for processing high-level RHS expressions into values with suitable composition for low-level code generation #region High-Level Expression Evaluation and Processing Methods /// <summary> /// Evaluate a cast to a scalar value operation /// </summary> /// <param name="expr"></param> /// <returns></returns> private ILanguageValue EvaluateBasicUnaryCastToScalar(BasicUnary expr) { var value1 = expr.Operand.AcceptVisitor(this); if (value1.ExpressionType.IsInteger()) { return(ValuePrimitive <MathematicaScalar> .Create( (TypePrimitive)expr.ExpressionType, ((ValuePrimitive <MathematicaScalar>)value1).Value )); } throw new InvalidOperationException("Invalid cast operation"); }
private static ILanguageExpressionAtomic AtomicExpressionToMultivectorAtomicExpression(this CommandBlock commandBlock, GMacFrameMultivector mvType, ILanguageExpressionAtomic oldExpr) { if (oldExpr.ExpressionType.IsSameType(mvType)) { return(oldExpr); } if (!oldExpr.ExpressionType.IsNumber()) { throw new InvalidCastException("Cannot convert atomic expression of type " + oldExpr.ExpressionType.TypeSignature + " to a expression of type " + mvType.TypeSignature); } var valuePrimitive = oldExpr as ValuePrimitive <int>; if (valuePrimitive != null) { return(GMacValueMultivector.CreateScalar( mvType, MathematicaScalar.Create(SymbolicUtils.Cas, valuePrimitive.Value) )); } var primitive = oldExpr as ValuePrimitive <MathematicaScalar>; if (primitive != null) { return(GMacValueMultivector.CreateScalar( mvType, primitive.Value )); } //This should be a value access of type integer or scalar if (!(oldExpr is LanguageValueAccess)) { throw new InvalidCastException( "Cannot convert atomic expression " + oldExpr + " of type " + oldExpr.ExpressionType.TypeSignature + " to a atomic expression of type" + mvType.TypeSignature ); } //Create a cast operation var newRhsExpr = BasicUnary.Create(mvType, mvType, oldExpr); //The new expresssion is not atomic. Create a local variable to hold value and return the local variable //as a direct value access object return(NonAtomicExpressionToValueAccess(commandBlock, newRhsExpr)); }
public void Visit(BasicUnary expr) { //var opPrimitive = expr.Operator as OperatorPrimitive; //if (opPrimitive != null) // Log.Append(opPrimitive.OperatorSymbolString); //else // Log.Append(expr.Operator.OperatorName); Log.Append(expr.Operator.OperatorName); Log.Append("("); expr.Operand.AcceptVisitor(this); Log.Append(")"); }
private static ILanguageExpressionAtomic AtomicExpressionToScalarAtomicExpression(this CommandBlock commandBlock, ILanguageExpressionAtomic oldExpr) { var scalarType = ((GMacAst)commandBlock.RootAst).ScalarType; if (oldExpr.ExpressionType.IsSameType(scalarType)) { return(oldExpr); } if (!oldExpr.ExpressionType.IsInteger()) { throw new InvalidCastException("Cannot convert atomic expression of type " + oldExpr.ExpressionType.TypeSignature + " to a scalar atomic expression"); } var valuePrimitive = oldExpr as ValuePrimitive <int>; if (valuePrimitive != null) { return(ValuePrimitive <MathematicaScalar> .Create( scalarType, MathematicaScalar.Create(SymbolicUtils.Cas, valuePrimitive.Value) )); } //This should be a value access of type integer if (!(oldExpr is LanguageValueAccess)) { throw new InvalidCastException("Cannot convert atomic expression " + oldExpr + " of type " + oldExpr.ExpressionType.TypeSignature + " to a scalar atomic expression"); } //Create a cast operation var newRhsExpr = BasicUnary.Create(scalarType, scalarType, oldExpr); //The new expresssion is not atomic. Create a local variable to hold value and return the local variable //as a direct value access object return(NonAtomicExpressionToValueAccess(commandBlock, newRhsExpr)); }
internal BasicUnary CreateTransformExpression(ILanguageExpressionAtomic operand) { return(BasicUnary.Create(TargetFrame.MultivectorType, this, operand)); }
internal AstUnaryExpression(BasicUnary expr) { AssociatedUnaryExpression = expr; }
/// <summary> /// Compute the value of the given language expression /// </summary> /// <param name="expr"></param> /// <returns></returns> public abstract ILanguageValue Visit(BasicUnary expr);
internal AstTransformCall(BasicUnary expr) { AssociatedUnaryExpression = expr; }
internal AstTypeCast(BasicUnary expr) { AssociatedUnaryExpression = expr; }
internal BasicUnary CreateCastExpression(ILanguageExpressionAtomic operand) { return(BasicUnary.CreateTypeCast(this, this, operand)); }