Exemple #1
0
        private Result Serialize_WZ_Gam(Stream stream, UInt32 gamType, CompileType compileType, XYInt scrollMin, sXY_uint scrollMax)
        {
            var returnResult = new Result("Serializing .gam", false);

            logger.Info("Serializing .gam");

            var fileGAM = new BinaryWriter(stream, App.ASCIIEncoding);

            IOUtil.WriteText(fileGAM, false, "game");
            fileGAM.Write(8U);
            fileGAM.Write(0U); //Time
            if (compileType == CompileType.Multiplayer)
            {
                fileGAM.Write(0U);
            }
            else if (compileType == CompileType.Campaign)
            {
                fileGAM.Write(gamType);
            }
            fileGAM.Write(scrollMin.X);
            fileGAM.Write(scrollMin.Y);
            fileGAM.Write(scrollMax.X);
            fileGAM.Write(scrollMax.Y);
            fileGAM.Write(new byte[20]);
            fileGAM.Flush();

            return(returnResult);
        }
Exemple #2
0
 private OptData(String[] settings, IEnumerable <String> lines)
 {
     this.compileType       = ((CompileType)(Int32.Parse(settings.First())));
     this.nasmArgs          = settings[1];
     this.fileExt           = settings[2];
     this.bonusInstructions = lines;
 }
Exemple #3
0
        /// <summary>
        ///  Called for scripts that output one file that relies on the file name.
        /// </summary>
        /// <param name="script">The script text to compile.</param>
        /// <param name="outputFile">The output file to compile to.</param>
        /// <param name="type">The type of script to compile.</param>
        /// <returns>The number of successfully compiled scripts.</returns>
        ///
        /// <exception cref="ArgumentNullException">
        ///  <paramref name="script"/> or <paramref name="outputFile"/> is null.
        /// </exception>
        private int CompileScriptToFile(string script, string outputFile, CompileType type)
        {
            if (script == null)
            {
                throw new ArgumentNullException(nameof(script));
            }
            if (outputFile == null)
            {
                throw new ArgumentNullException(nameof(outputFile));
            }
            // Generate a new temporary compile directory
            // Delete the temporary compile directory when done
            using (var tmp = CreateCompileTempDir()) {
                string tmpFile   = Path.Combine(tmp, Path.ChangeExtension(Path.GetFileName(outputFile), ".txt"));
                string outputDir = Path.GetDirectoryName(outputFile);
                if (outputDir.Length == 0)
                {
                    outputDir = Directory.GetCurrentDirectory();
                }

                // Write the script to the file
                File.WriteAllText(tmpFile, script, CatUtils.ShiftJIS);

                // Run the compiler and move the output files
                return(RunCompiler(type, Path.GetFileName(tmpFile), tmp, outputDir));
            }
        }
 // Constructor
 internal AsyncCompileOperation(ScriptDomain domain, bool isCSharpSource, ScriptSecurityMode securityMode, string[] sourceOrFiles, IMetadataReferenceProvider[] additionalReferenceAssemblies = null)
 {
     this.compileDomain        = domain;
     this.sourceCompileType    = (isCSharpSource == true) ? CompileType.CompileSource : CompileType.CompileFile;
     this.securityMode         = securityMode;
     this.sourceOrFiles        = sourceOrFiles;
     this.additionalReferences = additionalReferenceAssemblies;
 }
 public Property(AccessLimit accessLimit, CompileType compileType, VariableType type, string name, string getReturnCode, string comment = null)
 {
     this.AccessLimit   = accessLimit;
     this.Type          = TypeUtil.GetCodeType(type);
     this.CompileType   = compileType;
     this.Name          = name;
     this.GetReturnCode = getReturnCode;
     this.Comment       = comment;
 }
Exemple #6
0
        /// <summary>
        ///  Runs the compiled by getting the exe type, running the exe, then copying the generated files to
        ///  <paramref name="outputDir"/>.
        /// </summary>
        /// <param name="type">The type of script to compile.</param>
        /// <param name="patternOrFile">The wildcard pattern or file name to compile.</param>
        /// <param name="tmp">The temporary directory path being worked in.</param>
        /// <param name="outputDir">The output directory for the compiled files.</param>
        /// <returns>The number of successfully compiled scripts.</returns>
        private int RunCompiler(CompileType type, string patternOrFile, string tmp, string outputDir)
        {
            // Get the executable path and extension
            string exe;

            switch (type)
            {
            case CompileType.Animation: exe = AcPath; break;

            case CompileType.ScreenScript: exe = FesPath; break;

            case CompileType.SceneScript: exe = McPath; break;

            default: throw new ArgumentException(nameof(type));
            }


            if (exe == null)
            {
                throw new InvalidOperationException($"Cannot compile {type} when path to compiler has " +
                                                    $"not been specified!");
            }

            // Run the compiler
            ProcessStartInfo startInfo = new ProcessStartInfo {
                FileName               = exe,
                Arguments              = $"\"{patternOrFile}\"",
                UseShellExecute        = false,
                WorkingDirectory       = tmp,
                RedirectStandardOutput = false,
            };

            using (Process p = Process.Start(startInfo))
                p.WaitForExit();

            // Move the compiled output files to the output directory
            int count = 0;

            string[] tmpFiles = Directory.GetFiles(tmp);
            for (int i = 0; i < tmpFiles.Length; i++)
            {
                string tmpFile = tmpFiles[i];
                string file    = Path.Combine(outputDir, Path.GetFileName(tmpFile));
                // Make sure the file exists (was successfully compiled)
                if (File.Exists(tmpFile))
                {
                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }
                    File.Move(tmpFile, file);
                    count++;
                }
            }

            return(count);
        }
Exemple #7
0
    private void SetMemoryIndex(MachineCode mc, string input, bool isSource)
    {
        int    val      = 0;
        string sval     = "";
        bool   isNumber = false;

        Char[] subChar   = input.ToCharArray();
        string subString = "";

        for (int i = 0; i < subChar.Length; i++)
        {
            if (subChar[i] != 'm' && subChar[i] != 'M' && subChar[i] != ']' && subChar[i] != '[')
            {
                subString += subChar[i];
            }
        }

        CompileType type = GetType(subString);

        if (type == CompileType.Number)
        {
            int.TryParse(subString, out val);
            isNumber = true;
        }

        if (type == CompileType.Register)
        {
            sval     = subString;
            isNumber = false;
        }

        if (isNumber)
        {
            if (isSource)
            {
                mc.sourceMemoryIndex = val;
            }
            else
            {
                mc.destMemoryIndex = val;
            }
        }
        else
        {
            if (isSource)
            {
                mc.isSourceMemoryIndexIsRegister = true;
                mc.sourceRegister = GetRegisterIndex(sval);
            }
            else
            {
                mc.isDestMemoryIndexIsRegister = true;
                mc.destRegister = GetRegisterIndex(sval);
            }
        }
    }
 public Variable(AccessLimit accessLimit, CompileType compileType, VariableType type, string name, string value, string comment = null)
 {
     this.AccessLimit = accessLimit;
     this.CompileType = compileType;
     this.Name        = name;
     this.Value       = value;
     this.Type        = TypeUtil.GetCodeType(type);
     this.CompileType = compileType;
     this.Comment     = comment;
 }
        public ITaskCompiler CreateInstance(CompileType type)
        {
            switch (type)
            {
                case CompileType.HtmlTemplateTag:
                    return new ScriptTagCompiler();

                default:
                    throw new Exception(String.Format("Format {0} not implemented.", type));
            }
        }
Exemple #10
0
 internal static string BuildTypeAttributeMetadata(CompileType type, CompileAttribute attribute,
                                                   string baseClassOrInterfaceName, string attributeName)
 {
     return($@"new AttributedTypeMetadata<{baseClassOrInterfaceName}, {attributeName}>(
             typeof({type.FullName}),
             new {attributeName}({string.Join(", ", attribute.GetValues())})
             {{
                 {string.Join(@",
                 ", attribute.GetProperties().Select(x => $"{x.property} = {x.value}"))}
             }},
             () => new {type.FullName}()
         )");
 }
Exemple #11
0
 public InterfaceOptions()
 {
     //set to default
     CompileName         = "";
     CompileMultiPlayers = 2.ToStringInvariant();
     CompileMultiAuthor  = "";
     CompileMultiLicense = "";
     AutoScrollLimits    = true;
     ScrollMin           = new XYInt(0, 0);
     ScrollMax.X         = 0U;
     ScrollMax.Y         = 0U;
     CampaignGameType    = -1;
     CompileType         = CompileType.Unspecified;
 }
Exemple #12
0
        public String compile(Boolean explorerBit = false)
        {
            if (!(File.Exists(this.instructionsFile)))
            {
                Byte[] defaultInst = Encoding.UTF8.GetBytes("3,-fobj,bin" + Environment.NewLine);
                using (FileStream fs = File.Create(this.instructionsFile))
                    fs.Write(defaultInst, 0, defaultInst.Length);
            }

            OptData data = OptData.getOptData(File.ReadAllLines(this.instructionsFile));
            String  compiledFn = "\"" + compileDir + @"\" + header.pName + "." + data.fileExt + "\"", compileBatchFile = this.compileDir + @"\compile.bat", retVal = compiledFn.Substring(1).Remove(compiledFn.Length - 2);
            String  append = (explorerBit)?"\nexplorer \"" + this.compileDir + '"':"";

            append += (data.bonusInstructions.Count() > 0)?'\n' + data.bonusInstructions.Where(x => (!(String.IsNullOrEmpty(x)))).Select(x => x.Replace("%EXEPATH%", '"' + Application.ExecutablePath + '"').Replace("%BINDIR%", this.compileDir).Replace("%CMPFILE%", compiledFn)).merge("\n"):"";

            this.compileType = data.compileType;

            switch (this.compileType)
            {
            case CompileType.FASM:
                File.WriteAllText(compileBatchFile, "(\ncd \"" + Compiler.exeDir + "\\include\"\n" + "fasm " + '"' + this.entryFile + "\" " + compiledFn + append + "\n)1> \"" + this.compileDir + "\\output.txt\" 2>&1");
                this.compilerProcess = Process.Start(new ProcessStartInfo()
                {
                    FileName = compileBatchFile, CreateNoWindow = true, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden
                });
                return(retVal);

            case CompileType.NASM:
                //TODO:: Load in NASM includes @ compile time, this is probably easy, test if setting WorkingDirectory in the ProcessStartInfo to src folder will work.
                File.WriteAllText(compileBatchFile, "(\ncd \"" + Compiler.exeDir + "\\include\"\n" + "nasm " + data.nasmArgs + " \"" + this.entryFile + "\" -o " + compiledFn + append + "\n)1> \"" + this.compileDir + "\\output.txt\" 2>&1");
                this.compilerProcess = Process.Start(new ProcessStartInfo()
                {
                    FileName = compileBatchFile, CreateNoWindow = true, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden
                });
                return(retVal);

            case CompileType.MASM:
                MessageBox.Show("Sorry!! MASM Is not yet supported!");                         //TODO:: Support compiling with MASM
                return(retVal);

            default:
                this.compilerProcess = Process.Start(new ProcessStartInfo()
                {
                    FileName = @"C:\Windows\Cmd.exe", Arguments = " /c echo whatever"
                });
                return(Compiler.exeDir + @"\invalidCompileType.vbs");
            }
        }
Exemple #13
0
    private void CompileOperation(CompileType type)
    {
        var data = Resources.Load <FrpGraphContainer>(_fileName);
        var ir   = IntermediateRepresentation.Create(data);

        switch (type)
        {
        case CompileType.FlapJax:
        {
            FrapjaxCompiler.Print(ir);
            break;
        }

        case CompileType.Sodium:
        {
            SodiumCompiler.Print(ir);
            break;
        }
        }
    }
Exemple #14
0
        /// <summary>
        ///  Called to compile a pattern of script files or a single script file.<para/>
        ///  This method compies the files to a temporary directory so they can be encoded in
        ///  <see cref="CatUtils.ShiftJIS"/>.
        /// </summary>
        /// <param name="patternOrFile">The wildcard pattern or file path to compile.</param>
        /// <param name="outputDir">The output directory for the files.</param>
        /// <param name="type">The type of script to compile.</param>
        /// <returns>The number of successfully compiled scripts.</returns>
        ///
        /// <exception cref="ArgumentNullException">
        ///  <paramref name="patternOrFile"/> or <paramref name="outputDir"/> is null.
        /// </exception>
        private int CompileFiles(string patternOrFile, string outputDir, CompileType type)
        {
            if (patternOrFile == null)
            {
                throw new ArgumentNullException(nameof(patternOrFile));
            }
            if (outputDir == null)
            {
                throw new ArgumentNullException(nameof(outputDir));
            }
            string patternName = Path.GetFileName(patternOrFile);
            string patternDir  = Path.GetDirectoryName(patternOrFile);

            if (patternDir.Length == 0)
            {
                patternDir = ".";
            }
            if (!Path.IsPathRooted(patternDir))
            {
                patternDir = Path.GetFullPath(patternDir);
            }

            // Generate a new temporary compile directory
            // Delete the temporary compile directory when done
            using (var tmp = CreateCompileTempDir()) {
                // Copy and re-encode the files to the tmp directory with ShiftJIS encoding.
                string[] txtFiles = Directory.GetFiles(patternDir, patternName);
                for (int i = 0; i < txtFiles.Length; i++)
                {
                    string file    = txtFiles[i];
                    string tmpFile = Path.Combine(tmp, Path.GetFileName(file));
                    CatUtils.ReEncodeToShiftJIS(file, tmpFile);
                }

                // Run the compiler and move the output files
                return(RunCompiler(type, patternName, tmp, outputDir));
            }
        }
Exemple #15
0
        public static async Task Compile(DirectoryInfo inputDir, CompileType compileType, DirectoryInfo outputDir)
        {
            FileInfo[] microFiles = inputDir.GetFiles("*.mcs");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine($"Found {microFiles.Length} .mcs source file(s).");

            int filesCompiled = 0;
            int sucesses      = 0;

            if (microFiles.Length > 0 && (compileType == CompileType.Auto || compileType == CompileType.Microcode))
            {
                var microCompiler = Compilers.FirstOrDefault(c => c.CompileType == CompileType.Microcode);
                if (microCompiler != null)
                {
                    foreach (var micro in microFiles)
                    {
                        try
                        {
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine($"Compiling {micro.Name}...");
                            filesCompiled++;
                            await microCompiler.CompileAsync(micro, outputDir);

                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine($"Compilation complete!");
                            sucesses++;
                        }
                        catch (CompilationException compEx)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine($"Compilation of {micro.Name} failed ({compEx.Position.Line},{compEx.Position.Col}): {compEx.Message}");
                        }
                        catch (Exception ex)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine($"Compilation of {micro.Name} failed: {ex.Message}");
                        }
                    }
                }
                else
                {
                    throw new CompilationException($"Could not find a required ICompiler for compilation type {compileType}.");
                }
            }

            FileInfo[] codeFiles = inputDir.GetFiles("*.ccs");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine($"Found {codeFiles.Length} .ccs source file(s).");

            if (codeFiles.Length > 0 && (compileType == CompileType.Auto || compileType == CompileType.Commands))
            {
                FileInfo[] docFiles =
                    inputDir.GetFiles("*.mcd")
                    .Concat(outputDir.GetFiles("*.mcd"))
                    .ToArray();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine($"Found {docFiles.Length} .mcd documentation file(s).");

                var codeCompiler = Compilers.FirstOrDefault(c => c.CompileType == CompileType.Commands);
                if (codeCompiler != null)
                {
                    foreach (var code in codeFiles)
                    {
                        try
                        {
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine($"Compiling {code.Name}...");
                            filesCompiled++;
                            await codeCompiler.CompileAsync(code, docFiles, outputDir);

                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine($"Compilation complete!");
                            sucesses++;
                        }
                        catch (CompilationException compEx)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine($"Compilation of {code.Name} failed ({compEx.Position.Line},{compEx.Position.Col}): {compEx.Message}");
                        }
                        catch (Exception ex)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine($"Compilation of {code.Name} failed: {ex.Message}");
                        }
                    }
                }
                else
                {
                    throw new CompilationException($"Could not find a required ICompiler for compilation type {compileType}.");
                }
            }

            if (sucesses == filesCompiled)
            {
                Console.ForegroundColor = ConsoleColor.Green;
            }
            else if (sucesses == 0)
            {
                Console.ForegroundColor = ConsoleColor.Red;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
            }
            Console.WriteLine($"Compilation complete: {sucesses} out of {filesCompiled} succeeded.");
            Console.ResetColor();
        }
Exemple #16
0
    private void SetMachineCode(MachineCode mc, string instruction, string input1, string input2)
    {
        //setting instruction
        error.NotDefinedInstruction |= !Enum.TryParse(instruction.ToUpper(), out mc.instruction);

        //setting mode and following settings
        CompileType type1 = GetType(input1);
        CompileType type2 = GetType(input2);

        if (type1 == CompileType.Register && type2 == CompileType.Register)
        {
            mc.mode           = CPUMode.RegisterToRegister;
            mc.sourceRegister = GetRegisterIndex(input1);
            mc.destRegister   = GetRegisterIndex(input2);
        }
        else if (type1 == CompileType.Register && type2 == CompileType.Memory)
        {
            mc.mode           = CPUMode.RegisterToMemory;
            mc.sourceRegister = GetRegisterIndex(input1);
            SetMemoryIndex(mc, input2, false);
        }
        else if (type1 == CompileType.Register && type2 == CompileType.Number)
        {
            mc.mode           = CPUMode.RegisterToNumber;
            mc.sourceRegister = GetRegisterIndex(input1);
            mc.value          = GetValue(input2);
        }
        else if (type1 == CompileType.Memory && type2 == CompileType.Number)
        {
            mc.mode = CPUMode.MemoryToNumber;
            SetMemoryIndex(mc, input1, true);
        }
        else if (type1 == CompileType.Memory && type2 == CompileType.Register)
        {
            mc.mode         = CPUMode.MemoryToRegister;
            mc.destRegister = GetRegisterIndex(input2);
            SetMemoryIndex(mc, input1, true);
        }
        else if (type1 == CompileType.Memory && type2 == CompileType.Memory)
        {
            mc.mode = CPUMode.MemoryToMemory;
            SetMemoryIndex(mc, input1, true);
            SetMemoryIndex(mc, input2, false);
        }
        else if (type1 == CompileType.Memory && type2 == CompileType.Noting)
        {
            mc.mode = CPUMode.MemoryOnly;
            SetMemoryIndex(mc, input1, true);
        }
        else if (type1 == CompileType.Register && type2 == CompileType.Noting)
        {
            mc.mode           = CPUMode.RegisterOnly;
            mc.sourceRegister = GetRegisterIndex(input1);
        }
        else if (type1 == CompileType.Number && type2 == CompileType.Register)
        {
            mc.mode         = CPUMode.NumberToRegister;
            mc.value        = GetValue(input1);
            mc.destRegister = GetRegisterIndex(input2);
        }
        else if (type1 == CompileType.Number && type2 == CompileType.Memory)
        {
            mc.mode  = CPUMode.NumberToMemory;
            mc.value = GetValue(input1);
            SetMemoryIndex(mc, input2, false);
        }
        else if (type1 == CompileType.Number && type2 == CompileType.Noting)
        {
            mc.mode  = CPUMode.NumberOnly;
            mc.value = GetValue(input1);
        }
        else if (type1 == CompileType.Noting && type2 == CompileType.Noting)
        {
            mc.mode = CPUMode.Noting;
        }
        else
        {
            error.SetModeError = true;
            mc.mode            = CPUMode.Noting;
        }
    }