static int Main(string[] args) { CommandLineParameters programParams = ParseParameters(args); if (!ValidateFilesExists(programParams.Files)) { return(-2); } CompilerDriver driver = new CompilerDriver(programParams); CompileStatus status = driver.CompileFiles(); if (status.Success) { Console.WriteLine("Built successfully"); } else { Console.WriteLine("Error building"); Console.WriteLine(String.Join("\n", status.Errors.Select(e => String.Format("File: {0} Line:{1} Column:{2} {3}", e.ErrorSourceFile, e.ErrorLineNumber, e.ErrorPositionInLine, e.ErrorMessage)) )); } Console.ReadLine(); return(0); }
public void Output(string directoryName, string fileNameWithoutExtension, CompileStatus status) { StringBuilder output = new StringBuilder(); InitializeOutput(output); foreach (var nativeCodeSnippet in GlobalNativeCodeSnippets) { output.AppendLine(nativeCodeSnippet); } foreach (var clepsClass in ClassesLoaded) { GenerateClass(output, clepsClass.Value); } output.AppendLine(GlobalInitializer.GetMethodBodyWithoutDeclaration()); FunctionClepsType voidFuncType = new FunctionClepsType(new List <ClepsType>(), VoidClepsType.GetVoidType()); foreach (var clepsType in CompilerConstants.SystemSupportedTypes) { output.AppendFormat("{0}.{1}.{2}();\n", JavaScriptCodeParameters.TOPLEVELNAMESPACE, clepsType.GetClepsTypeString(), JavaScriptCodeParameters.GetMangledFunctionName("classStaticInitializer", voidFuncType)); } if (!String.IsNullOrWhiteSpace(EntryPointClass) && !String.IsNullOrWhiteSpace(EntryPointFunctionName)) { output.AppendFormat("{0}.{1}.{2}();\n", JavaScriptCodeParameters.TOPLEVELNAMESPACE, EntryPointClass, JavaScriptCodeParameters.GetMangledFunctionName("classStaticInitializer", voidFuncType)); output.AppendFormat("{0}.{1}.{2}();\n", JavaScriptCodeParameters.TOPLEVELNAMESPACE, EntryPointClass, JavaScriptCodeParameters.GetMangledFunctionName(EntryPointFunctionName, voidFuncType)); } var outputFileName = Path.Combine(directoryName, fileNameWithoutExtension + ".js"); File.WriteAllText(outputFileName, output.ToString()); }
public TestResult(string mmlFilePath, CompareResult compareResult, CompileStatus dotnetResult, CompileStatus dosResult) { MMLFilePath = mmlFilePath; CompareResult = compareResult; DotNetResult = dotnetResult; DosResult = dosResult; }
public void Output(string directoryName, string fileNameWithoutExtension, CompileStatus status) { //the static initializer function has an if statement created so that the initializer runs once. Closing this if block ClassStaticInitializers.Values.ToList().ForEach(m => m.CloseBlock()); var outputter = new JavaScriptCodeOutputter(ClassesLoaded, ClassInitializers, ClassStaticInitializers, GlobalInitializer, EntryPointClass, EntryPointFunctionName, GlobalNativeCodeSnippets); outputter.Output(directoryName, fileNameWithoutExtension, status); }
/** * Refreshes the cached data for this job. * * @throws BoaException if the command fails for any reason * @throws NotLoggedInException if not already logged in to the API */ public void refresh() { JobHandle j = client.getJob(id); this.date = j.getDate(); this.compilerStatus = j.getCompilerStatus(); this.execStatus = j.getExecutionStatus(); }
public JobHandle(BoaClient cli, int ID, DateTime dateTime, InputHandle data, CompileStatus compStat, ExecutionStatus execStat) { client = cli; id = ID; date = dateTime; dataset = data; compilerStatus = compStat; execStatus = execStat; }
public TestResult(string mmlFilePath, CompareResult compareResult, CompileStatus dotnetResult, int dosExitCode, CompileStatus dosResult, string?compiledFilesdir) { MMLFilePath = mmlFilePath; CompareResult = compareResult; DotNetResult = dotnetResult; DosResult = dosResult; DosExitCode = dosExitCode; CompiledFilesDir = compiledFilesdir; }
public void Output(string directoryName, string fileNameWithoutExtension, CompileStatus status) { var outputFileName = Path.Combine(directoryName, fileNameWithoutExtension + ".js"); IntPtr llvmErrorMessagePtr; LLVMBool llvmFailure = LLVM.PrintModuleToFile(Module, outputFileName, out llvmErrorMessagePtr); string errorMessage = Marshal.PtrToStringAnsi(llvmErrorMessagePtr); LLVM.DisposeMessage(llvmErrorMessagePtr); if (llvmFailure) { status.AddError(new CompilerError(outputFileName, 0, 0, "Module Output failed : " + errorMessage)); } }
public void Output(string directoryName, string fileNameWithoutExtension, CompileStatus status) { StringBuilder output = new StringBuilder(); InitializeOutput(output); foreach (var clepsClass in classesLoaded) { GenerateClass(output, clepsClass.Value); } var outputFileName = Path.Combine(directoryName, fileNameWithoutExtension + ".js"); File.WriteAllText(outputFileName, output.ToString()); }
public CompileStatus CompileFiles() { ClassManager classManager = new ClassManager(); CompileStatus status = new CompileStatus(Args.ExitOnFirstError); ICodeGenerator codeGenerator = new JavaScriptCodeGenerator(); TypeManager typeManager = new TypeManager(); EntryPointManager entryPointManager = new EntryPointManager(status, Args.EntryPointClass); try { codeGenerator.Initiate(); { ClepsClassNamesCollectorVisitor classSkeletonGenerator = new ClepsClassNamesCollectorVisitor(status, classManager, codeGenerator); ParseFilesWithGenerator(classSkeletonGenerator, status); } { ClepsMemberGeneratorVisitor memberGenerator = new ClepsMemberGeneratorVisitor(status, classManager, codeGenerator, entryPointManager); ParseFilesWithGenerator(memberGenerator, status); } { ClepsFunctionBodyGeneratorVisitor functionBodyGenerator = new ClepsFunctionBodyGeneratorVisitor(status, classManager, codeGenerator, typeManager); ParseFilesWithGenerator(functionBodyGenerator, status); } string entryClassName = entryPointManager.GetChosenEntryPointOrNull(); if (!String.IsNullOrWhiteSpace(entryClassName)) { codeGenerator.AddEntryPoint(entryClassName, EntryPointManager.EntryPointName); } codeGenerator.Output(Args.OutputDirectory, Args.OutputFileName, status); } catch (CompilerLogException) { //Supress compiler errors } finally { codeGenerator.Close(); } return(status); }
private void ParseFilesWithGenerator(ClepsAbstractVisitor generator, CompileStatus status) { foreach (string fileName in Args.Files) { LexerParserErrorHandler lexerParserErrorHandler = new LexerParserErrorHandler(fileName, status); var data = File.ReadAllText(fileName); AntlrInputStream s = new AntlrInputStream(data); ClepsLexer lexer = new ClepsLexer(s); CommonTokenStream tokens = new CommonTokenStream(lexer); ClepsParser parser = new ClepsParser(tokens); parser.RemoveErrorListeners(); parser.AddErrorListener(lexerParserErrorHandler); var parsedFile = parser.compilationUnit(); generator.ParseFile(fileName, parsedFile); } }
public CompileStatus CompileFiles() { ClassManager classManager = new ClassManager(); CompileStatus status = new CompileStatus(Args.ExitOnFirstError); ICodeGenerator codeGenerator = new JavaScriptCodeGenerator(); TypeManager typeManager = new TypeManager(); FunctionOverloadManager functionOverloadManager = new FunctionOverloadManager(); try { codeGenerator.Initiate(); { ClepsClassNamesCollectorVisitor classSkeletonGenerator = new ClepsClassNamesCollectorVisitor(status, classManager, codeGenerator); ParseFilesWithGenerator(classSkeletonGenerator, status); } { ClepsMemberGeneratorVisitor memberGenerator = new ClepsMemberGeneratorVisitor(status, classManager, codeGenerator); ParseFilesWithGenerator(memberGenerator, status); } //{ // ClepsCodeAnalysisGeneratorParser codeAnalysisGenerator = new ClepsCodeAnalysisGeneratorParser(status, classManager, codeGenerator); // ParseFilesWithGenerator(codeAnalysisGenerator, status); //} { ClepsFunctionBodyGeneratorVisitor functionBodyGenerator = new ClepsFunctionBodyGeneratorVisitor(status, classManager, codeGenerator, typeManager, functionOverloadManager); ParseFilesWithGenerator(functionBodyGenerator, status); } codeGenerator.Output(Args.OutputDirectory, Args.OutputFileName, status); } catch (CompilerErrorException) { //Supress compiler errors } finally { codeGenerator.Close(); } return(status); }
public LexerParserErrorHandler(string fileName, CompileStatus compileStatus) { FileName = fileName; CompileStatus = compileStatus; }
public ClepsMemberGeneratorVisitor(CompileStatus status, ClassManager classManager, ICodeGenerator codeGenerator, EntryPointManager entryPointManager) : base(status, classManager, codeGenerator) { EntryPointManager = entryPointManager; }
private CompileResult(CompileStatus compileStatus, string output, string fileName) { CompileStatus = compileStatus; Output = output; FileName = fileName; }
public ClepsAbstractVisitor(CompileStatus status, ClassManager classManager, ICodeGenerator codeGenerator) { Status = status; ClassManager = classManager; CodeGenerator = codeGenerator; }
public ClepsFunctionBodyAnalysisVisitor_Partial(CompileStatus status, ClassManager classManager, ICodeGenerator codeGenerator) : base(status, classManager, codeGenerator) { }
public ClepsMemberGeneratorVisitor(CompileStatus status, ClassManager classManager, ICodeGenerator codeGenerator) : base(status, classManager, codeGenerator) { }
public ClepsFunctionBodyGeneratorVisitor(CompileStatus status, ClassManager classManager, ICodeGenerator codeGenerator, TypeManager typeManager, FunctionOverloadManager functionOverloadManager) : base(status, classManager, codeGenerator) { TypeManager = typeManager; FunctionOverloadManager = functionOverloadManager; }
public ClepsClassNamesCollectorVisitor(CompileStatus status, ClassManager classManager, ICodeGenerator codeGenerator) : base(status, classManager, codeGenerator) { }
public EntryPointManager(CompileStatus status, string specifiedEntryPointClass = null) { Status = status; SpecifiedEntryPointClass = specifiedEntryPointClass; }
private double GradeOneSubmission(string problemName, string userName, out JudgeUpdateScoreType status) { status = JudgeUpdateScoreType.OK; int total = problemModel[problemName].Testcases.Count; //Remove old submission judgeModel.RemoveSubmission(problemName, userName); OnUpdateScore?.Invoke(this, new JudgeUpdateScoreSubmissionEvent() { ProblemName = problemName, UserName = userName, Status = JudgeUpdateScoreType.RemoveSubmission, Points = 0, }); OnGradeStatusChanged?.Invoke(this, new JudgeGradingEvent() { Event = JudgeGradingEventType.BeginGradingSubmission, ProblemName = problemName, UserName = userName }); //--------------- check submission existed & get user, problem object User user = userModel[userName]; Problem problem = problemModel[problemName]; List <UserSubmission> submissions = user.GetSubmission(problemName); if (submissions.Count == 0) { //Submission not found OnGradeStatusChanged?.Invoke(this, new JudgeGradingEvent() { Event = JudgeGradingEventType.SubmissionNotFound, UserName = userName, ProblemName = problemName }); TestcasesGraded += total; judgeModel.CreateNewSubmission(problemName, userName, "Not found submission!", "MS", "(null)"); status = JudgeUpdateScoreType.SubmissionNotFound; return(0); } //--------------- make directory string currentDir = FS.Combine(workSpace, DateTime.Now.Ticks.ToString()); string currentUserDir = FS.Combine(currentDir, user.UserName); string currentProblemDir = FS.Combine(currentDir, problem.ProblemName); string inputRun = FS.Combine(currentProblemDir, "input.txt"); FS.CreateDirectory(currentDir); FS.CreateDirectory(currentUserDir); FS.CreateDirectory(currentProblemDir); FS.CreateEmptyFile(inputRun); Compiler compiler = null; UserSubmission submission = null; CompileStatus compileResult = null; //--------------- compile foreach (UserSubmission sub in submissions) { submission = sub; string userSourceCode = FS.Combine(userModel.UserDirectory, userName, sub.ToString()); string newSource = FS.Combine(currentUserDir, sub.ToString()); FS.CopyFile(userSourceCode, newSource); if (!compilerManager.Contains(sub.Extension)) { continue; } List <Compiler> compilers = compilerManager[sub.Extension]; bool found = false; foreach (Compiler com in compilers) { compiler = com; OnGradeStatusChanged.Invoke(this, new JudgeGradingEvent() { Event = JudgeGradingEventType.Compiling, Status = com.Name, UserName = userName, ProblemName = problemName }); compileResult = com.Compile(sandbox, sub.ToString(), currentUserDir); if (!IsGrading) //cancel { FS.DeleteDirectory(currentDir); TestcasesGraded += total; return(0); } if (compileResult.Success) { found = true; break; } } if (found) { break; } } if (compiler == null) { //Submission not found OnGradeStatusChanged?.Invoke(this, new JudgeGradingEvent() { Event = JudgeGradingEventType.CompilerNotFound, UserName = userName, ProblemName = problemName }); TestcasesGraded += total; judgeModel.CreateNewSubmission(problemName, userName, "Not found submission!", "MS", "(null)"); status = JudgeUpdateScoreType.CompilerNotFound; return(0); } if (!compileResult.Success) { //Compile error OnGradeStatusChanged?.Invoke(this, new JudgeGradingEvent() { Status = compileResult.Message, UserName = userName, ProblemName = problemName, Event = JudgeGradingEventType.CompileError }); TestcasesGraded += total; FS.DeleteDirectory(currentDir); judgeModel.CreateNewSubmission(problemName, userName, compileResult.Message, "CE", compiler.Name); status = JudgeUpdateScoreType.CompileError; return(0); } //OK OnGradeStatusChanged.Invoke(this, new JudgeGradingEvent() { Event = JudgeGradingEventType.CompileSuccessfully, UserName = userName, ProblemName = problemName, Status = compiler.Name }); //Check execute exist if (!FS.FileExist(FS.Combine(currentUserDir, compileResult.OutputFileName))) { OnGradeStatusChanged?.Invoke(this, new JudgeGradingEvent() { ProblemName = problemName, UserName = userName, Event = JudgeGradingEventType.SubmissionNotFound }); OnGradeStatusChanged?.Invoke(this, new JudgeGradingEvent() { ProblemName = problemName, UserName = userName, Event = JudgeGradingEventType.NotFoundExecute }); judgeModel.CreateNewSubmission(problemName, userName, "Not found execute", "NFE", compiler.Name); status = JudgeUpdateScoreType.ExecuteNotFound; return(0); } //3. Run testcase List <SubmissionTestcaseResult> gradingTestcaseResult = new List <SubmissionTestcaseResult>(); foreach (Testcase test in problem.Testcases) { OnGradeStatusChanged?.Invoke(this, new JudgeGradingEvent() { Event = JudgeGradingEventType.BeginRunTest }); string currentTestDir = FS.Combine(currentProblemDir, test.TestcaseName); string sourceInput = FS.Combine(problem.ParentDirectory, problem.ProblemName, test.TestcaseName, problem.Input); string sourceOutput = FS.Combine(problem.ParentDirectory, problem.ProblemName, test.TestcaseName, problem.Output); string destOutput = FS.Combine(currentTestDir, problem.Output); //create testcase directory FS.CreateDirectory(currentTestDir); //copy execute FS.CopyFile(FS.Combine(currentUserDir, compileResult.OutputFileName), FS.Combine(currentTestDir, compileResult.OutputFileName)); //copy input if (!problem.UseStdin) { string destInput = FS.Combine(currentTestDir, problem.Input); FS.CopyFile(sourceInput, destInput); } //run var running_status = sandbox.StartRun(-1, ('"' + compiler.RunProgram + '"' + " " + compiler.RunArgs).Replace("$NAME$", submission.Name), currentTestDir, problem.Timelimit, problem.Memorylimit * 1024, problem.UseStdin ? sourceInput : inputRun, problem.UseStdout ? destOutput : null, TreatExitCodeNonZeroAsRTE ); if (!IsGrading) //cancel { TestcasesGraded += total; FS.DeleteDirectory(currentDir); return(0); } TestcasesGraded++; total--; string grading_status = running_status.Status.ToString(); double points = 0.0; int timeExecute = running_status.TimeExecuted; int memUsed = running_status.MemoryUsed; //check if (running_status.ExitCode != 0) { if (running_status.Status == SandBoxStatusType.TLE) { OnGradeStatusChanged?.Invoke(this, new JudgeGradingEvent() { Event = JudgeGradingEventType.EndRunTest, ProblemName = problemName, UserName = userName, TestCaseName = test.TestcaseName, TimeExecuted = timeExecute, Status = "TLE" }); } else if (running_status.Status == SandBoxStatusType.MLE) { OnGradeStatusChanged?.Invoke(this, new JudgeGradingEvent() { Event = JudgeGradingEventType.EndRunTest, ProblemName = problemName, UserName = userName, TestCaseName = test.TestcaseName, Status = "MLE" }); } else if (running_status.Status == SandBoxStatusType.RTE) { OnGradeStatusChanged?.Invoke(this, new JudgeGradingEvent() { Event = JudgeGradingEventType.EndRunTest, ProblemName = problemName, UserName = userName, TestCaseName = test.TestcaseName, Status = "RTE" }); } else if (running_status.Status == SandBoxStatusType.UnknownError) { OnGradeStatusChanged?.Invoke(this, new JudgeGradingEvent() { Event = JudgeGradingEventType.EndRunTest, ProblemName = problemName, UserName = userName, TestCaseName = test.TestcaseName, Status = "Unknown" }); } else { throw new Exception("JUDGER ERROR"); } } else { //if run ok -> copy output & rename FS.CopyFile(sourceOutput, destOutput + "$"); //check result bool checker_result = checker.Compare(problem.Checker, problem.Output, problem.Output + "$", currentTestDir); if (checker_result) { grading_status = "AC"; points = test.Point; } else { grading_status = "WA"; } OnGradeStatusChanged?.Invoke(this, new JudgeGradingEvent() { Event = JudgeGradingEventType.EndRunTest, MemoryUsed = memUsed, TimeExecuted = timeExecute, Status = grading_status, Points = points, TestCaseName = test.TestcaseName, ProblemName = problemName, UserName = userName, }); } gradingTestcaseResult.Add(new SubmissionTestcaseResult() { ProblemName = problemName, UserName = userName, TestcaseName = test.TestcaseName, Points = points, MemoryUsed = memUsed, TimeExecuted = timeExecute, Status = grading_status }); } //update status to database & calc score double totalScore = 0; int submission_id = judgeModel.CreateNewSubmission(problemName, userName, compileResult.Message, "OK", compiler.Name); foreach (SubmissionTestcaseResult r in gradingTestcaseResult) { if (r.Status == "AC") { judgeModel.UpdateLanguageTimeGrading(compiler.Name, r.TimeExecuted); } judgeModel.UpdateStatus(submission_id, r.TestcaseName, r.Points, r.Status, r.TimeExecuted, r.MemoryUsed); totalScore += r.Points; } //4. Clean FS.DeleteDirectory(currentDir); OnGradeStatusChanged?.Invoke(this, new JudgeGradingEvent() { Event = JudgeGradingEventType.EndGradingSubmission }); status = JudgeUpdateScoreType.OK; return(totalScore); }