Ejemplo n.º 1
0
        public void Class()
        {
            var parser = new Parser(new Scanner("../../sources/for_unit_tests/class.exs"));
            parser.DoPostParseProcessing = true;
            parser.Parse();

            var ast = parser.TopmostAst;
            var options = new ExpressoCompilerOptions{
                LibraryPaths = new List<string>{""},
                OutputPath = "../../test_executable",
                BuildType = BuildType.Debug | BuildType.Executable
            };
            var emitter = new CSharpEmitter(parser, options);
            ast.AcceptWalker(emitter, null);

            var asm = emitter.AssemblyBuilder;
            var main_method = asm.GetModule("main.exe")
                .GetType("ExsMain")
                .GetMethod("Main", BindingFlags.NonPublic | BindingFlags.Static);
            Assert.AreEqual(main_method.Name, "Main");
            Assert.IsTrue(main_method.IsStatic);
            Assert.AreEqual(typeof(int), main_method.ReturnType);
            Assert.AreEqual(0, main_method.GetParameters().Length);
            //Assert.IsTrue(main_method.GetParameters().SequenceEqual(new []{typeof(string[])}));
            Console.Out.WriteLine("テスト実行");
            Console.Out.WriteLine(main_method.ToString());

            //main_method.Invoke(null, new object[]{});
        }
 /// <summary>
 /// Compiles and assemble into an assembly object.
 /// </summary>
 /// <returns>An assembly object.</returns>
 /// <param name="filePath">Path to the file which will be compiled.</param>
 /// <param name="options">Compiler options to use for the compilation.</param>
 public static Assembly CompileToAssembly(string filePath, ExpressoCompilerOptions options)
 {
     var parser = new Parser(new Scanner(filePath));
     parser.DoPostParseProcessing = true;
     parser.Parse();
     var ast = parser.TopmostAst;
     var emitter = new CSharpEmitter(parser, options);
     ast.AcceptWalker(emitter, new CSharpEmitterContext());
     return emitter.AssemblyBuilder;
 }
Ejemplo n.º 3
0
        public void SimpleLiterals()
        {
            var parser = new Parser(new Scanner("../../sources/for_unit_tests/simple_literals.exs"));
            parser.DoPostParseProcessing = true;
            parser.Parse();

            var ast = parser.TopmostAst;
            var options = new ExpressoCompilerOptions{
                LibraryPaths = new List<string>{""},
                OutputPath = "../../test_executable",
                BuildType = BuildType.Debug | BuildType.Executable
            };
            var emitter = new CSharpEmitter(parser, options);
            ast.AcceptWalker(emitter, null);

            var asm = emitter.AssemblyBuilder;
            var main_method = asm.GetModule("main.exe")
                .GetType("ExsMain")
                .GetMethod("Main", BindingFlags.NonPublic | BindingFlags.Static);
            Assert.AreEqual(main_method.Name, "Main");
            Assert.IsTrue(main_method.IsStatic);
            Assert.AreEqual(typeof(void), main_method.ReturnType);
            Assert.AreEqual(0, main_method.GetParameters().Length);
        }