public CompilerData Compile(InputData idata, CompilerData cdata) { cdata.ExecuteThis = idata.PathToSource; cdata.Executor = "clisp"; cdata.Success = true; return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { Directory.SetCurrentDirectory (idata.BaseDir); List<string> dropLines = new List<string>(); dropLines.Add("F# Compiler for F# 4.1"); dropLines.Add("Freely distributed under the Apache 2.0 Open Source License"); dropLines.Add ("F# Compiler for F# 4.0"); string compiler = "fsharpc"; string args = "-o "+idata.BaseDir+"a.exe "+ idata.PathToSource; long compileTime; var res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs = compileTime; if(!File.Exists(idata.BaseDir+"a.exe")) { if(res.Count > 1) { cdata.Error = Utils.RemoveSomeLines(Utils.ConcatenateString(res[0], res[1]), dropLines); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) { cdata.Warning = Utils.RemoveSomeLines(Utils.ConcatenateString(res[0], res[1]), dropLines); } cdata.ExecuteThis = idata.BaseDir+"a.exe"; cdata.Executor = "mono"; cdata.Success = true; return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { Directory.SetCurrentDirectory (idata.BaseDir); string compiler = "/home/ren/scala-2.11.7/bin/fsc"; string args = "-deprecation -unchecked -encoding UTF-8 -d " + idata.BaseDir +" "+ idata.PathToSource; long compileTime; //Syscall.chmod(idata.BaseDir, FilePermissions.ACCESSPERMS); //Syscall.chmod(idata.PathToSource, FilePermissions.ACCESSPERMS); var res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs = compileTime; if(!File.Exists(idata.BaseDir+"Rextester.class") || !string.IsNullOrEmpty(res[1])) { if(res.Count > 1) { if(string.IsNullOrEmpty(res[0]) && string.IsNullOrEmpty(res[1])) cdata.Error = "Entry class 'Rextester' missing (it's either you haven't declared 'object Rextester' or you have declared 'package some_package')."; else cdata.Error = Utils.ConcatenateString(res[0], res[1]); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) cdata.Warning = Utils.ConcatenateString(res[0], res[1]); cdata.ExecuteThis = "-Dfile.encoding=UTF-8 -classpath " +idata.BaseDir+" Rextester"; cdata.Executor = "/home/ren/scala-2.11.7/bin/scala"; cdata.Success = true; return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { string compiler = "ocamlc"; string args = "-o "+idata.BaseDir+"a.out "+ idata.PathToSource; long compileTime; var res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs = compileTime; if(!File.Exists(idata.BaseDir+"a.out")) { if(res.Count > 1) { cdata.Error = Utils.ConcatenateString(res[0], res[1]); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) { cdata.Warning = Utils.ConcatenateString(res[0], res[1]); } cdata.ExecuteThis = idata.BaseDir+"a.out"; cdata.Executor = ""; cdata.Success = true; return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { Directory.SetCurrentDirectory (idata.BaseDir); string compiler = "javac"; string args = " -Xlint -encoding UTF-8 " + idata.PathToSource; long compileTime; var res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs = compileTime; if(!File.Exists(idata.BaseDir+"Rextester.class") || !string.IsNullOrEmpty(res[1])) { if(res.Count > 1) { if(string.IsNullOrEmpty(res[0]) && string.IsNullOrEmpty(res[1])) cdata.Error = "Method 'main' must be in a class 'Rextester'."; else cdata.Error = Utils.ConcatenateString(res[0], res[1]); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) cdata.Warning = Utils.ConcatenateString(res[0], res[1]); cdata.ExecuteThis = "-Xmx256m -Dfile.encoding=UTF-8 -classpath " +idata.BaseDir+" Rextester"; cdata.Executor = "java"; cdata.Success = true; return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { Environment.SetEnvironmentVariable ("HOME", idata.BaseDir); Directory.SetCurrentDirectory (idata.BaseDir); string compiler = "erl"; string args = "-compile " + idata.PathToSource; long compileTime; var res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs = compileTime; if(!File.Exists(idata.BaseDir+"source.beam")) { if(res.Count > 1) { cdata.Error = Utils.ConcatenateString(res[0], res[1]); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) { cdata.Warning = Utils.ConcatenateString(res[0], res[1]); } cdata.ExecuteThis = "-noshell -s source entry_point -s init stop"; cdata.Executor = "erl"; cdata.Success = true; return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { Directory.SetCurrentDirectory (idata.BaseDir); cdata.ExecuteThis = idata.PathToSource; cdata.Executor = "elixir"; cdata.Success = true; return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { Directory.SetCurrentDirectory (idata.BaseDir); cdata.ExecuteThis = "--no-auto-compile -s "+idata.PathToSource; //--no-auto-compile cdata.Executor = "guile"; cdata.Success = true; return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { Directory.SetCurrentDirectory (idata.BaseDir); File.Move (idata.PathToSource, idata.PathToSource.Replace ("source.m", "source_rextester.m")); cdata.ExecuteThis = " -q -f --no-window-system --no-history " + idata.PathToSource.Replace ("source.m", "source_rextester.m"); cdata.Executor = "octave"; cdata.Success = true; string source = File.ReadAllText(idata.PathToSource.Replace ("source.m", "source_rextester.m")); File.WriteAllText(idata.PathToSource.Replace ("source.m", "source_rextester.m"), "cd " + idata.BaseDir + ";" + Environment.NewLine + source); return cdata; }
static void TestEngineDirectly(string Program , Languages Lang) { Engine engine = new Engine(); InputData idata = new InputData() { Program = Program, Lang = Lang }; var odata = engine.DoWork(idata); ShowData(odata); }
public CompilerData Compile(InputData idata, CompilerData cdata) { string compiler = "gcc"; if(string.IsNullOrEmpty(idata.Compiler_args) || !idata.Compiler_args.Contains("-o a.out")) { cdata.Error = "Compiler args must contain '-o a.out'"; cdata.Success = false; return cdata; } if(string.IsNullOrEmpty(idata.Compiler_args) || !idata.Compiler_args.Contains("source_file.m")) { cdata.Error = "Compiler args must contain 'source_file.m'"; cdata.Success = false; return cdata; } idata.Compiler_args = idata.Compiler_args.Replace("source_file.m", idata.PathToSource); idata.Compiler_args = idata.Compiler_args.Replace("-o a.out", "-o "+ idata.BaseDir + "a.out "); string args = idata.Compiler_args; //string args = " -MMD -MP -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -fno-strict-aliasing -fexceptions -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -pthread -fPIC -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -g -O2 -fgnu-runtime -fconstant-string-class=NSConstantString -I. -I/usr/local/include/GNUstep -I/usr/include/GNUstep" + " -o "+ idata.BaseDir + "a.out " + idata.PathToSource + " -lobjc -lgnustep-base"; long compileTime; var res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs = compileTime; if(!File.Exists(idata.BaseDir+"a.out")) { if(res.Count > 1) { cdata.Error = Utils.ConcatenateString(res[0], res[1]); /*if(cdata.Error != null) { string[] ew = cdata.Error.Split(new string[]{"\n"}, StringSplitOptions.RemoveEmptyEntries); string error = ""; string warning = ""; foreach(var a in ew) if(a.Contains("error: ")) error+=a+"\n"; else if(a.Contains("warning: ")) warning+=a+"\n"; cdata.Error = error; cdata.Warning = warning; }*/ } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) cdata.Warning = Utils.ConcatenateString(res[0], res[1]); cdata.ExecuteThis = idata.BaseDir+"a.out"; cdata.Executor = ""; cdata.Success = true; return cdata; }
static OutputData TestEngineDirectly(string Program, string Input, Languages Lang, string Args) { Engine engine = new Engine(); InputData idata = new InputData() { Program = Program, Input = Input, Lang = Lang, Compiler_args = Args }; return engine.DoWork(idata); }
public CompilerData Compile(InputData idata, CompilerData cdata) { string compiler = "gcc"; if(string.IsNullOrEmpty(idata.Compiler_args) || !idata.Compiler_args.Contains("-o a.out")) { cdata.Error = "Compiler args must contain '-o a.out'"; cdata.Success = false; return cdata; } if(string.IsNullOrEmpty(idata.Compiler_args) || !idata.Compiler_args.Contains("source_file.c")) { cdata.Error = "Compiler args must contain 'source_file.c'"; cdata.Success = false; return cdata; } idata.Compiler_args = idata.Compiler_args.Replace("source_file.c", idata.PathToSource); idata.Compiler_args = idata.Compiler_args.Replace("-o a.out", "-o "+ idata.BaseDir + "a.out "); string args = idata.Compiler_args; long compileTime; var res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs = compileTime; if(!File.Exists(idata.BaseDir+"a.out")) { if(res.Count > 1) { cdata.Error = Utils.ConcatenateString(res[0], res[1]); /*if(cdata.Error != null) { string[] ew = cdata.Error.Split(new string[]{"\n"}, StringSplitOptions.RemoveEmptyEntries); string error = ""; string warning = ""; foreach(var a in ew) if(a.Contains("warning: ")) warning+=a+"\n"; else error+=a+"\n"; cdata.Error = error; cdata.Warning = warning; }*/ } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) cdata.Warning = Utils.ConcatenateString(res[0], res[1]); cdata.ExecuteThis = idata.BaseDir+"a.out"; cdata.Executor = ""; cdata.Success = true; return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { Directory.SetCurrentDirectory (idata.BaseDir); List<string> dropLines = new List<string>(); dropLines.Add("sh: /bin/rm: Permission denied"); cdata.ExecuteThis = " --slave --vanilla -f " + idata.PathToSource; cdata.Executor = "R"; cdata.Success = true; string source = File.ReadAllText(idata.PathToSource); File.WriteAllText(idata.PathToSource, "setwd('" + idata.BaseDir + "')" + Environment.NewLine + source); return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { string compiler = "nasm"; string args = "-f elf64 -o "+idata.BaseDir+"1.o " + idata.PathToSource; long compileTime; var res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs = compileTime; if(!File.Exists(idata.BaseDir+"1.o")) { if(res.Count > 1) { cdata.Error = Utils.ConcatenateString(res[0], res[1]); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) { cdata.Warning = Utils.ConcatenateString(res[0], res[1]); } //now linker compiler = "ld"; args = "-o "+idata.BaseDir+"a.out "+idata.BaseDir+"1.o"; res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs += compileTime; if(!File.Exists(idata.BaseDir+"a.out")) { if(res.Count > 1) { cdata.Error = "Linker:\n"+Utils.ConcatenateString(res[0], res[1]); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) { if(!string.IsNullOrEmpty(cdata.Warning)) cdata.Warning += "\n"; else cdata.Warning = ""; cdata.Warning += "Linker:\n"; cdata.Warning = Utils.ConcatenateString(res[0], res[1]); } cdata.ExecuteThis = idata.BaseDir+"a.out"; cdata.Executor = ""; cdata.Success = true; return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { Directory.SetCurrentDirectory (idata.BaseDir); List<string> dropLines = new List<string>(); dropLines.Add("Compiling"); dropLines.Add("Linking"); string compiler = "ghc"; if(string.IsNullOrEmpty(idata.Compiler_args) || !idata.Compiler_args.Contains("-o a.out")) { cdata.Error = "Compiler args must contain '-o a.out'"; cdata.Success = false; return cdata; } if(string.IsNullOrEmpty(idata.Compiler_args) || !idata.Compiler_args.Contains("source_file.hs")) { cdata.Error = "Compiler args must contain 'source_file.hs'"; cdata.Success = false; return cdata; } idata.Compiler_args = idata.Compiler_args.Replace("source_file.hs", idata.PathToSource); idata.Compiler_args = idata.Compiler_args.Replace("-o a.out", "-o "+ idata.BaseDir + "a.out "); string args = idata.Compiler_args; //string args = /*"-Wall*/" -o " + idata.BaseDir + "a.out " + idata.PathToSource; long compileTime; var res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs = compileTime; if(!File.Exists(idata.BaseDir+"a.out")) { if(res.Count > 1) { cdata.Error = Utils.RemoveSomeLines(Utils.ConcatenateString(res[0], res[1]), dropLines); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) { cdata.Warning = Utils.RemoveSomeLines(Utils.ConcatenateString(res[0], res[1]), dropLines); } cdata.ExecuteThis = idata.BaseDir+"a.out"; cdata.Executor = ""; cdata.Success = true; return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { string compiler = "dmd"; if(string.IsNullOrEmpty(idata.Compiler_args) || !idata.Compiler_args.Contains("-ofa.out")) { cdata.Error = "Compiler args must contain '-ofa.out'"; cdata.Success = false; return cdata; } if(string.IsNullOrEmpty(idata.Compiler_args) || !idata.Compiler_args.Contains("source_file.d")) { cdata.Error = "Compiler args must contain 'source_file.d'"; cdata.Success = false; return cdata; } idata.Compiler_args = idata.Compiler_args.Replace("source_file.d", idata.PathToSource); idata.Compiler_args = idata.Compiler_args.Replace("-ofa.out", "-of"+ idata.BaseDir + "a.out "); string args = idata.Compiler_args; long compileTime; var res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs = compileTime; if(!File.Exists(idata.BaseDir+"a.out")) { if(res.Count > 1) { cdata.Error = Utils.ConcatenateString(res[0], res[1]); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) cdata.Warning = Utils.ConcatenateString(res[0], res[1]); cdata.ExecuteThis = idata.BaseDir+"a.out"; cdata.Executor = ""; cdata.Success = true; return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { List<string> dropLines = new List<string>(); dropLines.Add("Free Pascal Compiler version"); dropLines.Add("Copyright (c)"); dropLines.Add("Target OS:"); dropLines.Add("Compiling "); dropLines.Add("Linking "); dropLines.Add("lines compiled"); dropLines.Add("contains output sections; did you forget -T?"); dropLines.Add("Fatal: Compilation aborted"); dropLines.Add("returned an error exitcode (normal if you did not specify a source file to be compiled)"); string compiler = "fpc"; string args = "-o"+idata.BaseDir+"a.out " + " -Fi"+idata.BaseDir + " " + idata.PathToSource; long compileTime; var res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs = compileTime; if(!File.Exists(idata.BaseDir+"a.out")) { if(res.Count > 1) { cdata.Error = Utils.RemoveSomeLines(Utils.ConcatenateString(res[0], res[1]), dropLines); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) { cdata.Warning = Utils.RemoveSomeLines(Utils.ConcatenateString(res[0], res[1]), dropLines); } cdata.ExecuteThis = idata.BaseDir+"a.out"; cdata.Executor = ""; cdata.Success = true; return cdata; }
public OutputData DoWork(InputData idata) { CompilerData cdata = null; try { OutputData odata = new OutputData(); cdata = CreateExecutable(idata); if(!cdata.Success) { odata.Errors = cdata.Error; odata.Warnings = cdata.Warning; odata.Stats = string.Format("Compilation time: {0} sec", Math.Round((double)CompileTimeMs/(double)1000), 2); return odata; } if(!string.IsNullOrEmpty(cdata.Warning)) { odata.Warnings = cdata.Warning; } Stopwatch watch = new Stopwatch(); watch.Start(); using(Process process = new Process()) { process.StartInfo.FileName = ParentRootPath+"parent.py"; process.StartInfo.Arguments = cdata.Executor+(string.IsNullOrEmpty(cdata.Executor) ? "" : " ")+cdata.ExecuteThis; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.Start(); OutputReader output = new OutputReader(process.StandardOutput); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); errorReader.Join(5000); outputReader.Join(5000); if(!string.IsNullOrEmpty(error.Output)) { int index = error.Output.LastIndexOf('\n'); int exitcode; if(index != -1 && index+1 < error.Output.Length && Int32.TryParse(error.Output.Substring(index+1), out exitcode)) { odata.ExitCode = exitcode; switch(exitcode) { case -8: odata.Exit_Status = "Floating point exception (SIGFPE)"; break; case -9: odata.Exit_Status = "Kill signal (SIGKILL)"; break; case -11: odata.Exit_Status = "Invalid memory reference (SIGSEGV)"; break; case -6: odata.Exit_Status = "Abort signal from abort(3) (SIGABRT)"; break; case -4: odata.Exit_Status = "Illegal instruction (SIGILL)"; break; case -13: odata.Exit_Status = "Broken pipe: write to pipe with no readers (SIGPIPE)"; break; case -14: odata.Exit_Status = "Timer signal from alarm(2) (SIGALRM)"; break; case -15: odata.Exit_Status = "Termination signal (SIGTERM)"; break; case -19: odata.Exit_Status = "Stop process (SIGSTOP)"; break; case -17: odata.Exit_Status = "Child stopped or terminated (SIGCHLD)"; break; default: odata.Exit_Status = string.Format("Exit code: {0} (see 'man 7 signal' for explanation)", exitcode); break; } error.Output = error.Output.Substring(0, index); } } odata.Errors = error.Output; odata.Output = output.Output; } watch.Stop(); if(idata.Lang != Languages.Python) { odata.Stats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec", Math.Round((double)CompileTimeMs / (double)1000, 2), Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2)); } else { odata.Stats = string.Format("Absolute running time: {0} sec", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2)); } return odata; } catch(Exception ex) { return new OutputData() { System_Error = ex.Message }; } finally { if(cdata != null) Cleanup(cdata.CleanThis); } }
CompilerData CreateExecutable(InputData input) { string ext = ""; string compiler = ""; string args = ""; string rand = RandomString(); string dir = rand + "/"; switch(input.Lang) { case Languages.Java: ext = ".java"; break; case Languages.Python: ext = ".py"; break; case Languages.C: ext = ".c"; break; case Languages.CPP: ext = ".cpp"; break; default: ext = ".unknown"; break; } string PathToSource = RootPath+dir+rand+ext; Directory.CreateDirectory(RootPath+dir); using(TextWriter sw = new StreamWriter(PathToSource)) { sw.Write(input.Program); } CompilerData cdata = new CompilerData(); cdata.CleanThis = RootPath+dir; List<string> res = new List<string>(); switch(input.Lang) { case Languages.Java: compiler = "javac"; args = " -Xlint -encoding UTF-8 " + PathToSource; res = CallCompiler(compiler, args); if(!File.Exists(RootPath+dir+"Rextester.class")) { if(res.Count > 1) { if(string.IsNullOrEmpty(res[0]) && string.IsNullOrEmpty(res[1])) cdata.Error = "Entry class 'Rextester' not found."; else cdata.Error = ConcatenateString(res[0], res[1]); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) cdata.Warning = ConcatenateString(res[0], res[1]); cdata.ExecuteThis = "-Dfile.encoding=UTF-8 -classpath " +RootPath+dir+" Rextester"; cdata.Executor = "java"; cdata.Success = true; return cdata; case Languages.Python: cdata.ExecuteThis = PathToSource; cdata.Executor = "python"; cdata.Success = true; return cdata; case Languages.C: compiler = "gcc"; args = "-Wall -o " + RootPath + dir + "a.out " + PathToSource; res = CallCompiler(compiler, args); if(!File.Exists(RootPath+dir+"a.out")) { if(res.Count > 1) { cdata.Error = ConcatenateString(res[0], res[1]); if(cdata.Error != null) { string[] ew = cdata.Error.Split(new string[]{"\n"}, StringSplitOptions.RemoveEmptyEntries); string error = ""; string warning = ""; foreach(var a in ew) if(a.Contains("error: ")) error+=a+"\n"; else if(a.Contains("warning: ")) warning+=a+"\n"; cdata.Error = error; cdata.Warning = warning; } } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) cdata.Warning = ConcatenateString(res[0], res[1]); cdata.ExecuteThis = RootPath+dir+"a.out"; cdata.Executor = ""; cdata.Success = true; return cdata; case Languages.CPP: compiler = "g++"; args = "-Wall -o " + RootPath + dir + "a.out " + PathToSource; res = CallCompiler(compiler, args); if(!File.Exists(RootPath+dir+"a.out")) { if(res.Count > 1) { cdata.Error = ConcatenateString(res[0], res[1]); if(cdata.Error != null) { string[] ew = cdata.Error.Split(new string[]{"\n"}, StringSplitOptions.RemoveEmptyEntries); string error = ""; string warning = ""; foreach(var a in ew) if(a.Contains("error: ")) error+=a+"\n"; else if(a.Contains("warning: ")) warning+=a+"\n"; cdata.Error = error; cdata.Warning = warning; } } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) cdata.Warning = ConcatenateString(res[0], res[1]); cdata.ExecuteThis = RootPath+dir+"a.out"; cdata.Executor = ""; cdata.Success = true; return cdata; default: break; } cdata.Success = false; return cdata; }
public CompilerData Compile(InputData idata, CompilerData cdata) { List<string> dropLines = new List<string>(); dropLines.Add("gcc-4.9 -c -I"); dropLines.Add ("file name does not match unit name, should be"); Directory.SetCurrentDirectory (idata.BaseDir); string compiler = "gnat compile"; string args = idata.PathToSource; long compileTime; var res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs = compileTime; if(!File.Exists(idata.BaseDir + "source.o")) { if(res.Count > 1) { cdata.Error = Utils.RemoveSomeLines(Utils.ConcatenateString(res[0], res[1]), dropLines); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) { cdata.Warning = Utils.RemoveSomeLines(Utils.ConcatenateString(res[0], res[1]),dropLines); } //now binder compiler = "gnatbind"; args = idata.BaseDir + "source"; res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs += compileTime; if(!File.Exists(idata.BaseDir+"b~source.adb")) { if(res.Count > 1) { cdata.Error = "Binder:\n"+Utils.RemoveSomeLines(Utils.ConcatenateString(res[0], res[1]), dropLines); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) { if(!string.IsNullOrEmpty(cdata.Warning)) cdata.Warning += "\n"; else cdata.Warning = ""; cdata.Warning += "Binder:\n"; cdata.Warning = Utils.RemoveSomeLines(Utils.ConcatenateString(res[0], res[1]), dropLines); } //now linker compiler = "gnatlink"; args = idata.BaseDir + "source"; res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs += compileTime; if(!File.Exists(idata.BaseDir+"source")) { if(res.Count > 1) { cdata.Error = "Linker:\n"+Utils.RemoveSomeLines(Utils.ConcatenateString(res[0], res[1]), dropLines); } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) { if(!string.IsNullOrEmpty(cdata.Warning)) cdata.Warning += "\n"; else cdata.Warning = ""; cdata.Warning += "Linker:\n"; cdata.Warning = Utils.RemoveSomeLines(Utils.ConcatenateString(res[0], res[1]), dropLines); } cdata.ExecuteThis = idata.BaseDir+"source"; cdata.Executor = ""; cdata.Success = true; return cdata; }
CompilerData CreateExecutable(InputData input) { string ext = ""; string rand = Utils.RandomString(); string dir = rand + "/"; switch(input.Lang) { case Languages.Java: ext = ".java"; break; case Languages.Python: ext = ".py"; break; case Languages.C: ext = ".c"; break; case Languages.CPP: ext = ".cpp"; break; case Languages.Php: ext = ".php"; break; case Languages.Pascal: ext = ".pas"; break; case Languages.ObjectiveC: ext = ".m"; break; case Languages.Haskell: ext = ".hs"; break; case Languages.Ruby: ext = ".rb"; break; case Languages.Perl: ext = ".pl"; break; case Languages.Lua: ext = ".lua"; break; case Languages.Nasm: ext = ".asm"; break; case Languages.Javascript: ext = ".js"; break; case Languages.Lisp: ext = ".lsp"; break; case Languages.Prolog: ext = ".prolog"; break; case Languages.Go: ext = ".go"; break; case Languages.Scala: ext = ".scala"; break; case Languages.Scheme: ext = ".scm"; break; case Languages.Nodejs: ext = ".js"; break; case Languages.Python3: ext = ".py"; break; case Languages.Octave: ext = ".m"; break; case Languages.CClang: ext = ".c"; break; case Languages.CppClang: ext = ".cpp"; break; case Languages.D: ext = ".d"; break; case Languages.R: ext = ".r"; break; case Languages.Tcl: ext = ".tcl"; break; case Languages.Swift: ext = ".swift"; break; case Languages.FSharp: ext = ".fs"; break; case Languages.Bash: ext = ".sh"; break; case Languages.Rust: ext = ".rs"; break; case Languages.Ada: ext = ".adb"; break; case Languages.Erlang: ext = ".erl"; break; case Languages.Elixir: ext = ".exs"; break; case Languages.Ocaml: ext = ".ml"; break; case Languages.Clojure: ext = ".clj"; break; default: ext = ".unknown"; break; } string PathToSource = RootPath+dir+/*rand*/"source"+ext; input.PathToSource = PathToSource; input.BaseDir = RootPath+dir; input.Rand = rand; Directory.CreateDirectory(RootPath+dir); using(TextWriter sw = new StreamWriter(PathToSource)) { sw.Write(input.Program); } CompilerData cdata = new CompilerData(); cdata.CleanThis = RootPath+dir; var comp = ICompilerFactory.GetICompiler(input.Lang); if(comp != null) return comp.Compile(input, cdata); cdata.Success = false; return cdata; }
public Result DoWork(string Program, string Input, Languages Language, string user, string pass, string compiler_args = "", bool bytes = false, bool programCompressed = false, bool inputCompressed = false) { if(user != GlobalUtils.TopSecret.ServiceUser || pass != GlobalUtils.TopSecret.ServicePass) { return new Result() { Errors = null, Warnings = null, Output = null, Stats = null, Exit_Status = null, Exit_Code = null, System_Error = "Not authorized." }; } if(programCompressed) Program = Decompress(Program); if(inputCompressed) Input = Decompress(Input); if(!string.IsNullOrEmpty(Program) && Program.ToLower().Contains("setsid")) { return new Result() { Errors = "setsid system call is not allowed." }; } Engine engine = new Engine(); InputData idata = new InputData() { Program = Program, Input = Input, Lang = Language, Compiler_args = compiler_args }; var odata = engine.DoWork(idata); Regex r = new Regex(Engine.RootPath + @"\d+/source"); if(Language == Languages.Javascript && !string.IsNullOrEmpty(odata.Output)) odata.Output = r.Replace(odata.Output, "source_file"); var res = new Result() { Errors = !string.IsNullOrEmpty(odata.Errors) ? r.Replace(odata.Errors, "source_file") : odata.Errors, Warnings = !string.IsNullOrEmpty(odata.Warnings) ? r.Replace(odata.Warnings, "source_file") : odata.Warnings, Output = odata.Output, Stats = odata.Stats, Exit_Status = odata.Exit_Status, Exit_Code = odata.ExitCode, System_Error = odata.System_Error, Files = odata.Files }; if(!string.IsNullOrEmpty(odata.Output) && odata.Output.Length > 1000) { res.Output = Compress(odata.Output); res.IsOutputCompressed = true; } if(bytes) { if(!string.IsNullOrEmpty(res.Errors)) { res.Errors_Bytes = System.Text.Encoding.Unicode.GetBytes(res.Errors); res.Errors = null; } if(!string.IsNullOrEmpty(res.Warnings)) { res.Warnings_Bytes = System.Text.Encoding.Unicode.GetBytes(res.Warnings); res.Warnings = null; } if(!string.IsNullOrEmpty(res.Output)) { res.Output_Bytes = System.Text.Encoding.Unicode.GetBytes(res.Output); res.Output = null; } } return res; }
public CompilerData Compile(InputData idata, CompilerData cdata) { string compiler = "go"; if(string.IsNullOrEmpty(idata.Compiler_args) || !idata.Compiler_args.Contains("-o a.out")) { cdata.Error = "Compiler args must contain '-o a.out'"; cdata.Success = false; return cdata; } if(string.IsNullOrEmpty(idata.Compiler_args) || !idata.Compiler_args.Contains("source_file.go")) { cdata.Error = "Compiler args must contain 'source_file.go'"; cdata.Success = false; return cdata; } idata.Compiler_args = idata.Compiler_args.Replace("source_file.go", idata.PathToSource); idata.Compiler_args = idata.Compiler_args.Replace("-o a.out", "-o "+ idata.BaseDir + "a.out "); string args = "build " + idata.Compiler_args; //string args = "build -o " + idata.BaseDir + "a.out " + idata.PathToSource; long compileTime; var res = Engine.CallCompiler(compiler, args, out compileTime); cdata.CompileTimeMs = compileTime; Regex r = new Regex(@"service/usercode/\d+/\d+"); if(!File.Exists(idata.BaseDir+"a.out")) { if(res.Count > 1) { cdata.Error = Utils.ConcatenateString(res[0], res[1]); cdata.Error = cdata.Error.Replace("# command-line-arguments\n", ""); cdata.Error = r.Replace(cdata.Error, "source_file"); /*if(cdata.Error != null) { string[] ew = cdata.Error.Split(new string[]{"\n"}, StringSplitOptions.RemoveEmptyEntries); string error = ""; string warning = ""; foreach(var a in ew) if(a.Contains("error: ")) error+=a+"\n"; else if(a.Contains("warning: ")) warning+=a+"\n"; cdata.Error = error; cdata.Warning = warning; }*/ } cdata.Success = false; return cdata; } if(res.Count > 1 && (!string.IsNullOrEmpty(res[0]) || !string.IsNullOrEmpty(res[1]))) { cdata.Warning = Utils.ConcatenateString(res[0], res[1]); cdata.Warning = r.Replace(cdata.Warning, "source_file"); } cdata.ExecuteThis = idata.BaseDir+"a.out"; cdata.Executor = ""; cdata.Success = true; return cdata; }
public OutputData DoWork(InputData idata) { CompilerData cdata = null; try { OutputData odata = new OutputData(); cdata = CreateExecutable(idata); if(!cdata.Success) { odata.Errors = cdata.Error; odata.Warnings = cdata.Warning; odata.Stats = string.Format("Compilation time: {0} sec", Math.Round((double)cdata.CompileTimeMs/(double)1000, 2)); return odata; } if(!string.IsNullOrEmpty(cdata.Warning)) { odata.Warnings = cdata.Warning; } Stopwatch watch = new Stopwatch(); watch.Start(); using(Process process = new Process()) { process.StartInfo.FileName = ParentRootPath+"parent.py"; //process.StartInfo.FileName = "/home/ren/a.out"; process.StartInfo.Arguments = cdata.Executor+(string.IsNullOrEmpty(cdata.Executor) ? "" : " ")+cdata.ExecuteThis; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = true; process.Start(); if (!string.IsNullOrEmpty(idata.Input)) { InputWriter input = new InputWriter(process.StandardInput, idata.Input); Thread inputWriter = new Thread(new ThreadStart(input.Writeinput)); inputWriter.Start(); } OutputReader output = new OutputReader(process.StandardOutput); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); errorReader.Join(5000); outputReader.Join(5000); if(!string.IsNullOrEmpty(error.Output)) { int index = error.Output.LastIndexOf('\n'); int exitcode; if(index != -1 && index+1 < error.Output.Length) { string[] info = error.Output.Substring(index+1).Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if(info.Length > 0 && Int32.TryParse(info[0], out exitcode)) { odata.ExitCode = exitcode; switch(exitcode) { case -8: odata.Exit_Status = "Floating point exception (SIGFPE)"; break; case -9: odata.Exit_Status = "Kill signal (SIGKILL)"; break; case -11: odata.Exit_Status = "Invalid memory reference (SIGSEGV)"; break; case -6: odata.Exit_Status = "Abort signal from abort(3) (SIGABRT)"; break; case -4: odata.Exit_Status = "Illegal instruction (SIGILL)"; break; case -13: odata.Exit_Status = "Broken pipe: write to pipe with no readers (SIGPIPE)"; break; case -14: odata.Exit_Status = "Timer signal from alarm(2) (SIGALRM)"; break; case -15: odata.Exit_Status = "Termination signal (SIGTERM)"; break; case -19: odata.Exit_Status = "Stop process (SIGSTOP)"; break; case -17: odata.Exit_Status = "Child stopped or terminated (SIGCHLD)"; break; default: odata.Exit_Status = string.Format("Exit code: {0} (see 'man 7 signal' for explanation)", exitcode); break; } error.Output = error.Output.Substring(0, index); if(info.Length > 1) { double cpuTime; Double.TryParse(info[1], out cpuTime); CpuTimeInSec = cpuTime; } if(info.Length > 2) { int memory; Int32.TryParse(info[2], out memory); MemoryPickInKilobytes = memory; } } } } odata.Errors = error.Output; odata.Output = output.Output; if(idata.Lang == Languages.Octave) { string bad_err = "error: No such file or directory"+Environment.NewLine+"error: ignoring octave_execution_exception while preparing to exit"; if(odata.Errors != null && odata.Errors.Contains(bad_err)) { odata.Errors = odata.Errors.Replace(bad_err, ""); if(string.IsNullOrEmpty(odata.Errors.Trim())) { odata.Errors = null; } } List<FileData> files = new List<FileData>(); foreach (string file_name in Directory.GetFiles(cdata.CleanThis, "*.png")) { var file = new FileData(); file.Data = File.ReadAllBytes(file_name); file.CreationDate = File.GetCreationTime(file_name); files.Add(file); } odata.Files = files.OrderBy(f => f.CreationDate).Select(f => f.Data).ToList(); } if(idata.Lang == Languages.R) { string bad_err = "sh: /bin/rm: Permission denied"; if(odata.Errors != null && odata.Errors.Contains(bad_err)) { odata.Errors = odata.Errors.Replace(bad_err, ""); if(string.IsNullOrEmpty(odata.Errors.Trim())) { odata.Errors = null; } } if(File.Exists(Path.Combine(cdata.CleanThis, "Rplots.pdf"))) { using(var p = new Process()) { process.StartInfo.FileName = "pdftoppm"; process.StartInfo.WorkingDirectory = cdata.CleanThis; process.StartInfo.Arguments = "-png Rplots.pdf plots"; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.Start(); process.WaitForExit(); } List<FileData> files = new List<FileData>(); foreach (string file_name in Directory.GetFiles(cdata.CleanThis, "*.png")) { var file = new FileData(); file.Data = File.ReadAllBytes(file_name); file.CreationDate = File.GetCreationTime(file_name); files.Add(file); } odata.Files = files.OrderBy(f => f.CreationDate).Select(f => f.Data).ToList(); } } } watch.Stop(); if(Utils.IsCompiled(idata.Lang)) { odata.Stats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec, cpu time: {2} sec, memory peak: {3} Mb", Math.Round((double)cdata.CompileTimeMs / (double)1000, 2), Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2), Math.Round(CpuTimeInSec, 2), MemoryPickInKilobytes/1024); } else { odata.Stats = string.Format("Absolute running time: {0} sec, cpu time: {1} sec, memory peak: {2} Mb", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2), Math.Round(CpuTimeInSec, 2), MemoryPickInKilobytes/1024); } return odata; } catch(Exception ex) { return new OutputData() { System_Error = ex.Message }; } finally { if(cdata != null) Cleanup(cdata.CleanThis); } }