Example #1
0
        /// <summary>
        /// Returns the location of the compiled assembly
        /// </summary>
        /// <returns></returns>
        public string Compile(string filename)
        {
            var instructions = Parser.GenerateDIL(File.ReadAllText(filename)).ToArray();

            LanguageInstruction?areLoopOperationsBalanced;

            if ((areLoopOperationsBalanced = AreLoopOperationsBalanced(instructions)) != null)
            {
                throw new InstructionNotFoundException(String.Format("Expected to find an {0} instruction but didn't.", (~areLoopOperationsBalanced.Value).ToString()));
            }

            var dilInstructions = new DILOperationSet(instructions);

            // If we're not in debug mode, optimize the shit out of it!
            if (!OptionEnabled(CompilationOptions.DebugMode))
            {
                while (dilInstructions.Optimize(ref dilInstructions))
                {
                }
            }

            //var interpreter = new Interpreter(30000);
            //interpreter.Run(dilInstructions);

            return(CompileToExecutable(dilInstructions, filename));
        }
Example #2
0
        private static string Translate(Parser inputParser, Parser outputParser, string sourceInput)
        {
            var inputInstructions = inputParser.GenerateDIL(sourceInput);
            var sb = new StringBuilder();
            foreach (var languageInstruction in inputInstructions.ToArray())
            {
                sb.Append(outputParser.AllowedInstructions.GetBySecond(languageInstruction));
            }

            return sb.ToString();
        }