public static Assembly CompileCode(string code, CompilationTarget target = CompilationTarget.Library) { var parsed = new LightParser().Parse(code); AssertEx.That(() => !parsed.HasErrors); var processor = TestEnvironment.Container.Resolve <LightProcessor>(); processor.Process(parsed.Root, new ProcessingOptions { ReferencedAssemblies = { typeof(CompilationHelper).Assembly } }); var assemblyName = GetAssemblyName(); var compilationArguments = new CompilationArguments { AssemblyName = assemblyName, AssemblyVersion = new Version(0, 1, 0, 0), Target = target }; var stream = new MemoryStream(); var compiler = TestEnvironment.Container.Resolve <LightCompiler>(); compiler.Compile((AstRoot)parsed.Root, stream, compilationArguments); var bytes = stream.ToArray(); var assembly = Assembly.Load(bytes); WriteAssemblyOnDiskAndPEVerify(assembly, bytes, target); return(assembly); }
public object Compilation([FromBody] CompilationArguments arguments) { var result = _processor.Process(arguments.Code, new ProcessingOptions { SourceLanguage = arguments.SourceLanguage, TargetLanguage = arguments.TargetLanguage, ScriptMode = arguments.Mode == CompilationMode.Script, OptimizationsEnabled = arguments.OptimizationsEnabled }); return(new { success = result.IsSuccess, //result.SyntaxTree, result.Decompiled, errors = result.GetDiagnostics(DiagnosticSeverity.Error), warnings = result.GetDiagnostics(DiagnosticSeverity.Warning) }); }
public object Compilation([FromBody] CompilationArguments arguments) { var processor = arguments.Branch != null ? _processorManager.GetBranchProcessor(arguments.Branch) : _processorManager.DefaultProcessor; var result = processor.Process(arguments.Code, new ProcessingOptions { SourceLanguage = arguments.SourceLanguage, TargetLanguage = arguments.TargetLanguage, ScriptMode = arguments.Mode == CompilationMode.Script, OptimizationsEnabled = arguments.OptimizationsEnabled }); return(new { success = result.IsSuccess, //result.SyntaxTree, result.Decompiled, errors = result.GetDiagnostics(DiagnosticSeverity.Error).Select(d => d.ToString()), warnings = result.GetDiagnostics(DiagnosticSeverity.Warning).Select(d => d.ToString()) }); }