Esempio n. 1
0
 protected virtual T VisitPyModuleExpression(PyModuleExpression node)
 {
     if (ThrowNotImplementedException)
     {
         throw new NotImplementedException(string.Format("Method {0} is not supported in class {1}", "VisitPyModuleExpression", this.GetType().FullName));
     }
     return(default(T));
 }
Esempio n. 2
0
        private static IPyValue SingleArgumentMathFunction(
            string name,
            IExternalTranslationContext ctx,
            CsharpMethodCallExpression src)
        {
            var moduleExpression = new PyModuleExpression(PyModules.Math, name);

            return(new PyMethodCallExpression(moduleExpression, name, SingleArg(ctx, src)));
        }
Esempio n. 3
0
        public IPyValue TranslateToPython(IExternalTranslationContext ctx, CsharpMethodCallExpression src)
        {
            if (src.MethodInfo.DeclaringType == typeof(Math))
            {
                // https://docs.python.org/3/library/math.html
                if (src.Arguments.Length == 1)
                {
                    var name = ConvertToDirect1(src.MethodInfo.Name);
                    if (name != null)
                    {
                        return(SingleArgumentMathFunction(name, ctx, src));
                    }
                }
                else if (src.Arguments.Length == 2)
                {
                    var name = ConvertToDirect2(src.MethodInfo.Name);
                    if (name != null)
                    {
                        var moduleExpression = new PyModuleExpression(PyModules.Math, name);
                        return(new PyMethodCallExpression(moduleExpression, name, Args(ctx, src)));
                    }
                }

                var fn = src.MethodInfo.ToString();

                /*
                 * switch (fn)
                 * {
                 *  case "Double Sin(Double)":
                 *  case "Double Cos(Double)":
                 *  case "Double Tan(Double)":
                 *      return SingleArgumentMathFunction(src.MethodInfo.Name.ToLower(), ctx, src);
                 * }
                 */
                throw new NotImplementedException($"{nameof(SystemMathNodeTranslator)}->{fn}");
            }

            if (src.MethodInfo.DeclaringType == typeof(double))
            {
                var fn = src.MethodInfo.ToString();
                switch (fn)
                {
                case "Boolean IsNaN(Double)":
                    return(SingleArgumentMathFunction("isnan", ctx, src));

                case "Boolean IsInfinity(Double)":
                    return(SingleArgumentMathFunction("isinf", ctx, src));
                }
            }
            return(null);
        }