Esempio n. 1
0
        public static void WriteSourceMainEntry(CCodeWriterBase c, IndentedTextWriter itw, IMethodSymbol mainMethod)
        {
            itw.WriteLine();
            var mainHasParameters = mainMethod.Parameters.Length > 0;

            itw.Write("auto __main(");
            if (mainHasParameters)
            {
                itw.Write("int32_t argc, char* argv[]");
            }

            itw.WriteLine(") -> int32_t");
            itw.WriteLine("{");
            itw.Indent++;

            itw.WriteLine("__startup();");
            if (!mainMethod.ReturnsVoid)
            {
                itw.Write("auto exit_code = ");
            }

            c.WriteMethodFullName(mainMethod);
            itw.Write("(");
            if (mainHasParameters)
            {
                itw.Write("__get_arguments(argc, argv)");
            }

            itw.WriteLine(");");
            itw.WriteLine("__shutdown();");
            itw.Write("return ");
            if (!mainMethod.ReturnsVoid)
            {
                itw.Write("exit_code");
            }
            else
            {
                itw.Write("CoreLib::System::Environment::get_ExitCode()");
            }

            itw.WriteLine(";");

            itw.Indent--;
            itw.WriteLine("}");
            itw.WriteLine();

            // main
            itw.WriteLine("auto main(int32_t argc, char* argv[]) -> int32_t");
            itw.WriteLine("{");
            itw.Indent++;
            itw.Write("return __main(");
            if (mainHasParameters)
            {
                itw.Write("argc, argv");
            }
            itw.WriteLine(");");
            itw.Indent--;
            itw.WriteLine("}");
        }
Esempio n. 2
0
        public static void WriteSourceMainEntry(CCodeWriterBase c, IndentedTextWriter itw, IMethodSymbol mainMethod)
        {
            itw.WriteLine();
            itw.WriteLine("auto main() -> int32_t");
            itw.WriteLine("{");
            itw.WriteLine("#ifdef GC_H");
            itw.Indent++;
            itw.WriteLine("GC_INIT()");
            itw.Indent--;
            itw.WriteLine("#endif");
            itw.Indent++;

            c.WriteMethodFullName(mainMethod);
            itw.Write("(");
            if (mainMethod.Parameters.Length > 0)
            {
                itw.Write("nullptr");
            }

            itw.WriteLine(");");
            itw.WriteLine("return 0;");
            itw.Indent--;
            itw.WriteLine("}");
        }
Esempio n. 3
0
        public static void WriteSourceMainEntry(CCodeWriterBase c, IMethodSymbol mainMethod)
        {
            c.Separate();

            var mainHasParameters = mainMethod.Parameters.Length > 0;

            c.TextSpan("auto __main(");
            if (mainHasParameters)
            {
                c.TextSpan("int32_t argc, char* argv[]");
            }

            c.TextSpanNewLine(") -> int32_t");

            c.OpenBlock();

            c.TextSpan("__startup()");
            c.EndStatement();
            if (!mainMethod.ReturnsVoid)
            {
                c.TextSpan("auto exit_code = ");
            }

            c.WriteMethodFullName(mainMethod);
            c.TextSpan("(");
            if (mainHasParameters)
            {
                c.TextSpan("__get_arguments(argc, argv)");
            }

            c.TextSpan(")");
            c.EndStatement();

            c.TextSpan("__shutdown()");
            c.EndStatement();

            c.TextSpan("return ");
            if (!mainMethod.ReturnsVoid)
            {
                c.TextSpan("exit_code");
            }
            else
            {
                c.TextSpan("CoreLib::System::Environment::get_ExitCode()");
            }

            c.TextSpanNewLine(";");

            c.EndBlock();

            c.Separate();

            // main
            c.TextSpanNewLine("auto main(int32_t argc, char* argv[]) -> int32_t");
            c.OpenBlock();
            c.TextSpan("return __main(");
            if (mainHasParameters)
            {
                c.TextSpan("argc, argv");
            }

            c.TextSpanNewLine(");");
            c.EndBlock();
        }