예제 #1
0
        private static void GenerateSceneCode(List <ReificationData> reificationDataList, Manager manager,
                                              Compiler compiler)
        {
            string path     = Path.Combine(manager.ProjectDir, manager.PrefabsDirName, "Main.cs");
            var    template = new Main(reificationDataList);

            System.IO.File.WriteAllText(path, template.TransformText());
            compiler.AddFile(path);
        }
예제 #2
0
        private static void GeneratePrefabs(Manager manager, List <FFEntity> scene, Compiler compiler, List <ReificationData> reificationDataList)
        {
            string path             = Path.Combine(manager.ProjectDir, manager.PrefabsDirName, "BreakoutPrefab.cs");
            var    BreakoutEntities = scene.FindAll(x => x.EntityTemplate == "Breakout");
            var    template         = new SpecificEntities.Breakout(BreakoutEntities);

            System.IO.File.WriteAllText(path, template.TransformText());
            reificationDataList.AddRange(template.ReificationData());
            compiler.AddFile(path);
        }
예제 #3
0
            public static void MonogameTest()
            {
                Compiler compiler = new Compiler();

                try
                {
                    compiler.AddFile(@"..\..\..\TestMonoGame\Game1.cs");
                    compiler.AddFile(@"..\..\..\TestMonoGame\Program.cs");
                    compiler.AddDependency("MonoGame.Framework.dll");
                    compiler.SetExecPath(".");
                    compiler.SetResourceFolder(@"..\..\..\TestMonoGame\Content");
                    compiler.SetExecutableName("PortableMonogame.exe");
                    compiler.CompileToPortableExec();
                    Debug.WriteLine("MonoGame Test successfully compiled.");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Caught exception during MONOGAMETEST : " + ex.Message);
                }
            }
예제 #4
0
 private static void GenerateEntity(Manager manager, FFEntity entity, Compiler compiler,
                                    List <ReificationData> reificationDataList, int nthEntity)
 {
     if (entity.EntityTemplate == null)
     {
         string name     = entity.Name + nthEntity.ToString();
         string path     = Path.Combine(manager.ProjectDir, manager.PrefabsDirName, name + ".cs");
         var    template = new EntityTemplate(entity, nthEntity);
         System.IO.File.WriteAllText(path, template.TransformText());
         reificationDataList.Add(template.ReificationData(entity, name));
         compiler.AddFile(path);
     }
 }
예제 #5
0
            public static void SimpleTest()
            {
                Compiler compiler = new Compiler();

                try
                {
                    compiler.AddFile("Testfile.cs");
                    compiler.AddDependency("System.Windows.Forms.dll");
                    compiler.SetExecPath(".");
                    compiler.SetExecutableName("compilation_testing.exe");
                    compiler.CompileToPortableExec();
                    Debug.WriteLine("Simple test successfully compiled.");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Caught exception during SIMPLETEST : " + ex.Message);
                }
            }
예제 #6
0
        public static int TestFile(string file, IEnumerable <string> preprocessor = null, bool onlyCompile = false)
        {
            if (!Directory.Exists("Samples"))
            {
                Directory.CreateDirectory("Samples");
            }
            File.Copy("../../../../Docs/" + file, file, true);

            string     outputName = file.Split('/').Last().Split('.').First();
            Processor  p          = new Processor();
            Compiler   c          = new Compiler();
            Decompiler decompiler = new Decompiler();

            LibrariesTest.PrepareLibraries(p, false);
            c.LibraryHandler = p.LibraryHandler;
            byte[] prog = null;

            if (preprocessor != null)
            {
                foreach (string s in preprocessor)
                {
                    c.AddPreprocessorFile(s);
                }
            }

            c.AddFile(file);
            c.Compile();

            prog = c.BinaryOutput();
            File.WriteAllBytes(String.Format("{0}.khl", outputName), prog);
            decompiler.Decompile(prog, String.Format("{0}.dkhl", outputName));

            if (onlyCompile)
            {
                return(0);
            }

            p = new Processor();
            LibrariesTest.PrepareLibraries(p, true);
            p.LoadProgram(prog);
            return(p.Run());
        }
예제 #7
0
        public ASTFile ParseFile()
        {
            var nodes      = new List <ASTNode>();
            var startToken = PeekToken();

            while (!EatToken(TokenKind.EndOfFile))
            {
                if (PeekTokenIs(TokenKind.Identifier) && PeekTokenIs(TokenKind.Colon, 1))
                {
                    var node = PeekTokenIs(TokenKind.Colon, 2) ? ParseProcedure() : ParseDeclaration();
                    if (node == null)
                    {
                        return(null);
                    }

                    nodes.Add(node);
                }
                else if (EatToken(TokenKind.Directive))
                {
                    if (EatenToken.Value == "include")
                    {
                        if (EatToken(TokenKind.String))
                        {
                            var    str = EatenToken;
                            string fileToAdd;

                            if (Path.IsPathRooted(str.Value))
                            {
                                fileToAdd = str.Value;
                            }
                            else
                            {
                                var directory = new FileInfo(str.Position.FileName).Directory.FullName;
                                fileToAdd = $"{directory}\\{str.Value}";
                            }

                            if (!File.Exists(fileToAdd))
                            {
                                Error($"Files does not exist: \"{str.Value}\"");
                                return(null);
                            }

                            _compiler.AddFile(fileToAdd);
                        }
                        else
                        {
                            Error("A string has to perceed the '#include' directive.");
                            return(null);
                        }
                    }
                    else
                    {
                        Error("Only '#include' directive can be used in global scope.");
                        return(null);
                    }
                }
            }

            return(new ASTFile(startToken.Position)
            {
                Nodes = nodes
            });
        }
예제 #8
0
 /// <summary>
 /// 添加一个带有代码的文件
 /// </summary>
 /// <param name="path">代码文件路径</param>
 /// <returns></returns>
 public CompilationException AddFile(string path)
 {
     return(Compiler.AddFile(path));
 }