Exemplo n.º 1
0
        private TreeNode Visit_MultivectorConstruction(BasicPolyadic expr)
        {
            var mvTypeCons = (GMacFrameMultivectorConstructor)expr.Operator;
            var operands   = expr.Operands.AsByIndex;

            var node = new TreeNode("<CONSTRUCT>" + mvTypeCons.MultivectorType.SymbolAccessName)
            {
                Tag = expr
            };

            if (mvTypeCons.HasDefaultValueSource)
            {
                var subNode = node.Nodes.Add("<DEFAULT>");
                subNode.Nodes.Add(mvTypeCons.DefaultValueSource.AcceptVisitor(this));
            }

            foreach (var pair in operands.OperandsDictionary)
            {
                node.Nodes.Add(Visit(mvTypeCons.MultivectorType, pair.Key, pair.Value));
            }

            return(node);
        }
Exemplo n.º 2
0
        public TreeNode Visit(BasicPolyadic expr)
        {
            if (expr.Operator is GMacMacro)
            {
                return(Visit_MacroCall(expr));
            }

            if (expr.Operator is GMacStructureConstructor)
            {
                return(Visit_StructureConstruction(expr));
            }

            if (expr.Operator is GMacFrameMultivectorConstructor)
            {
                return(Visit_MultivectorConstruction(expr));
            }

            if (expr.Operator is GMacParametricSymbolicExpression)
            {
                return(Visit_SymbolicExpression(expr));
            }

            return(null);
        }
        private ILanguageExpression translate_Expression_Function_Macro(GMacMacro macro, ParseTreeNode node)
        {
            var operands = OperandsByValueAccess.Create();

            if (node.ChildNodes.Count == 0)
            {
                return(BasicPolyadic.Create(macro.OutputParameterType, macro, operands));
            }

            var expressionFunctionInputsNode = node.ChildNodes[0];

            var subNode = expressionFunctionInputsNode.ChildNodes[0];

            switch (subNode.Term.ToString())
            {
            case GMacParseNodeNames.ExpressionFunctionInputsAssignments:
                var expressionFunctionInputsAssignmentsNode = subNode;

                foreach (var nodeExpressionFunctionInputsAssignmentsItem in expressionFunctionInputsAssignmentsNode.ChildNodes)
                {
                    var lhsNode = nodeExpressionFunctionInputsAssignmentsItem.ChildNodes[0].ChildNodes[0];
                    var rhsNode = nodeExpressionFunctionInputsAssignmentsItem.ChildNodes[1];

                    var lhsValAccess = GMacValueAccessGenerator.Translate_LValue_MacroParameter(Context, lhsNode, macro);

                    var rhsExpr =
                        BasicExpressionGenerator.Generate_PolyadicOperand(
                            lhsValAccess.ExpressionType,
                            GMacExpressionGenerator.Translate(BasicExpressionGenerator, rhsNode)
                            );

                    operands.AddOperand(lhsValAccess, rhsExpr);
                }

                break;

            case GMacParseNodeNames.ExpressionFunctionInputsExpressions:
                var nodeExpressionFunctionInputsExpressions = subNode;

                var i = -1;
                foreach (var parameter in macro.Parameters)
                {
                    if (i >= nodeExpressionFunctionInputsExpressions.ChildNodes.Count)
                    {
                        break;
                    }

                    //The first parameter of any macro is the 'result' output parameter; ignore it
                    if (i >= 0)
                    {
                        var rhsNode = nodeExpressionFunctionInputsExpressions.ChildNodes[i];

                        var lhsValAccess = LanguageValueAccess.Create(parameter);

                        var rhsExpr =
                            BasicExpressionGenerator.Generate_PolyadicOperand(
                                lhsValAccess.ExpressionType,
                                GMacExpressionGenerator.Translate(BasicExpressionGenerator, rhsNode)
                                );

                        operands.AddOperand(lhsValAccess, rhsExpr);
                    }

                    i = i + 1;
                }

                if (nodeExpressionFunctionInputsExpressions.ChildNodes.Count > i)
                {
                    return(CompilationLog.RaiseGeneratorError <ILanguageExpression>("Expecting a list of at most " + i + " expression as input to the macro call", node));
                }

                break;

            default:
                return(CompilationLog.RaiseGeneratorError <ILanguageExpression>("Expecting a list of expressions or list of parameter assignments as input to the macro call", node));
            }

            return(BasicPolyadic.Create(macro.OutputParameterType, macro, operands));
        }
Exemplo n.º 4
0
 internal AstMacroCall(BasicPolyadic expr)
 {
     AssociatedPolyadicExpression = expr;
 }
Exemplo n.º 5
0
 internal AstStructureConstructor(BasicPolyadic expr)
 {
     AssociatedPolyadicExpression = expr;
 }
Exemplo n.º 6
0
 internal AstParametricSymbolicExpression(BasicPolyadic expr)
 {
     AssociatedPolyadicExpression = expr;
 }
Exemplo n.º 7
0
 internal AstMultivectorConstructor(BasicPolyadic expr)
 {
     AssociatedPolyadicExpression = expr;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Compute the value of the given language expression
 /// </summary>
 /// <param name="expr"></param>
 /// <returns></returns>
 public abstract ILanguageValue Visit(BasicPolyadic expr);