Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            FortranOptions opts = new FortranOptions();
            MessageCollection messages = new MessageCollection(opts);

            opts.Messages = messages;
            if (opts.Parse(args)) {
                Compiler comp = new Compiler(opts);
                comp.Messages = messages;

                foreach (string srcfile in opts.SourceFiles) {
                    if (!File.Exists(srcfile)) {
                        messages.Error(MessageCode.SOURCEFILENOTFOUND, String.Format("File '{0}' not found", srcfile));
                        break;
                    }
                    comp.Compile(srcfile);
                }
                if (messages.ErrorCount == 0) {
                    comp.Save();
                    if (opts.Run && messages.ErrorCount == 0) {
                        comp.Execute();
                    }
                }
            }
            foreach (Message msg in messages) {
                if (msg.Level == MessageLevel.Error) {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                Console.WriteLine(msg);
                Console.ResetColor();
            }
            if (messages.ErrorCount > 0) {
                Console.WriteLine(String.Format("*** {0} errors found. Compilation stopped.", messages.ErrorCount));
            }
        }
Ejemplo n.º 2
0
 // Compile the given code, run the specified function and verify
 // that the double precision result matches
 public static void HelperRunDouble(Compiler comp, string entryPointName, double expectedValue)
 {
     ExecutionResult execResult = comp.Execute(entryPointName);
     Assert.IsTrue(execResult.Success);
     Assert.IsTrue(DoubleCompare(expectedValue, (double)execResult.Result), "Saw " + execResult.Result + " but expected " + expectedValue);
 }
Ejemplo n.º 3
0
 // Compile the given code, run the specified function and verify
 // that the string result matches
 public static void HelperRunString(Compiler comp, string entryPointName, string expectedValue)
 {
     ExecutionResult execResult = comp.Execute(entryPointName);
     Assert.IsTrue(execResult.Success);
     Assert.AreEqual(expectedValue, execResult.Result.ToString());
 }
Ejemplo n.º 4
0
 // Compile the given code, run the specified function and verify
 // that the integer result matches
 public static void HelperRunInteger(Compiler comp, string entryPointName, int expectedValue)
 {
     ExecutionResult execResult = comp.Execute(entryPointName);
     Assert.IsTrue(execResult.Success);
     Assert.AreEqual(expectedValue, (int)execResult.Result);
 }
Ejemplo n.º 5
0
 // Compile the given code, run the specified function and verify
 // that the float result matches
 public static void HelperRunFloat(Compiler comp, string entryPointName, float expectedValue)
 {
     ExecutionResult execResult = comp.Execute(entryPointName);
     Assert.IsTrue(execResult.Success);
     Assert.IsTrue(FloatCompare(expectedValue, (float)execResult.Result), "Saw " + execResult.Result + " but expected " + expectedValue);
 }
Ejemplo n.º 6
0
        public void ArithDivisionByZero()
        {
            string [] code = new [] {
                "      FUNCTION ITEST",
                "        INTEGER I,J",
                "        I = 10",
                "        J = 0",
                "        RETURN I/J",
                "      END"
            };

            Compiler comp = new Compiler(new FortranOptions());
            comp.CompileString(code);
            Assert.AreEqual(0, comp.Messages.ErrorCount);
            Assert.Throws(typeof(System.DivideByZeroException), delegate { comp.Execute("ITEST"); });
        }