public override GamaValueRef VisitExprOpMul([NotNull] GamaParser.ExprOpMulContext context)
        {
            var lhs = Visit(context.expr(0));
            var rhs = Visit(context.expr(1));
            var op  = context.opMul().GetText();

            GamaFunctionList oplist;

            if (op == "*")
            {
                oplist = lhs.Type.Meta.Operators.Mul;
            }
            else if (op == "/")
            {
                oplist = lhs.Type.Meta.Operators.Div;
            }
            else
            {
                oplist = lhs.Type.Meta.Operators.Mod;
            }

            var target = !IsEmptyTT ? TopTT : null;

            GamaFunctionRef fnref = null;

            if (target == null)
            {
                fnref = oplist.FindFunction(new[] { lhs.Type, rhs.Type });
            }
            else
            {
                fnref = oplist.FindFunction(target, new[] { lhs.Type, rhs.Type });
            }

            if (fnref == null)
            {
                GamaCompiledFunctionList coplist;
                if (op == "*")
                {
                    coplist = lhs.Type.Meta.CompiledOperators.Mul;
                }
                else if (op == "/")
                {
                    coplist = lhs.Type.Meta.CompiledOperators.Div;
                }
                else
                {
                    coplist = lhs.Type.Meta.CompiledOperators.Mod;
                }

                GamaCompiledFunctionRef cfnref = null;
                if (target == null)
                {
                    cfnref = coplist.FindFunction(lhs.Type, rhs.Type);
                }
                else
                {
                    cfnref = coplist.FindFunction(target, new[] { lhs.Type, rhs.Type });
                }

                if (cfnref == null)
                {
                    Parent.NamespaceContext.Context.AddError(new ErrorNoViableOperator(context));
                    return(null);
                }
                var cbuilder = Parent.Builder;
                Parent.CurrentBlock.PositionBuilderAtEnd(cbuilder);
                return(cfnref.Call(cbuilder, lhs, rhs));
            }

            /* LLVM */
            var block   = Parent.CurrentBlock;
            var builder = Parent.Builder;

            block.PositionBuilderAtEnd(builder);
            var result = builder.BuildCall(fnref.Value, new LLVMValueRef[] { lhs.Value, rhs.Value });

            return(new GamaValueRef(fnref.ReturnType, result, false));
        }
Example #2
0
 /// <summary>
 /// Visit a parse tree produced by the <c>ExprOpMul</c>
 /// labeled alternative in <see cref="GamaParser.expr"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitExprOpMul([NotNull] GamaParser.ExprOpMulContext context)
 {
     return(VisitChildren(context));
 }
Example #3
0
 /// <summary>
 /// Exit a parse tree produced by the <c>ExprOpMul</c>
 /// labeled alternative in <see cref="GamaParser.expr"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitExprOpMul([NotNull] GamaParser.ExprOpMulContext context)
 {
 }