private string CompileJs(string mainAssemblyName, string outputName, List <Ref> refs, List <string> errors, bool outputRuntimeJs = false) { try { var settings = new CompileSettings(); foreach (var r in refs) { settings.AddAssembly(r.path, translate: r.translate); } settings.OutputRuntimeJs = outputRuntimeJs; settings.AddAssembly(mainAssemblyName, translate: true); settings.OutputFileName = outputName; settings.OutputILComments = true; var compiler = new Compiler(settings); var result = compiler.Compile(); return(result.EntryPointAssembly); } catch (Exception e) { errors.Add(e.Message + "\n" + e.StackTrace); } return(null); }
public Context(Universe universe, List <CilAssembly> asms, CompileSettings settings) { ReflectionUniverse = universe; Assemblies = asms; SystemTypes = new SystemTypes(universe); Settings = settings; }
public static void CompileDec(ParsedCommandOptions opts) { var Dec = new DecFile(@"C:\Users\yveem\source\repos\Redmond\TestDec.dec"); CompileSettings.InitSettings(Dec.SettingsLines); var gram = new DecGrammar(Dec); Console.WriteLine("Generating parsing table..."); ParseFile parseFile = new ParseFile(@"C:\Users\yveem\source\repos\Redmond\TestParse.parse"); parseFile.SetLexLines(Dec.LexLines); parseFile.SetParseTableLines(gram.SerializeParsingTable()); parseFile.SetTokenIdLines(ProductionEntry.Register.Serialize()); parseFile.Save(); Console.WriteLine("Done!"); Console.Beep(); var parser = gram.GetParser(); var input = new MultiFileInputStream(new List <string>(new string[] { @"C:\Users\yveem\source\repos\Redmond\TestInput.txt" })); //var input = GetAllCSFiles(@"C:\Users\yveem\source\repos\CompileTestProject"); TokenStream Input = new TokenStream(input, Dec.LexLines, new string(Enumerable.Range('\x1', 127).Select(i => (char)i).ToArray())); parser.Parse(Input); var tree = SyntaxTreeNode.CurrentNode; Console.WriteLine(tree.ToTreeString()); Console.WriteLine("============\n"); new IntermediateGenerator(new ConsoleStream()).Start(tree); Console.WriteLine("============\n"); }
public ClangToolchainSettings() { CompileSettings = new CompileSettings(); LinkSettings = new LinkSettings(); }
public GccToolchainSettings() { CompileSettings = new CompileSettings(); LinkSettings = new LinkSettings(); }
public STM32ToolchainSettings() { CompileSettings = new CompileSettings(); LinkSettings = new LinkSettings(); }
static void PreCompileExecutableFunctions() { Console.WriteLine(); Console.WriteLine("--------------------------------------------------------"); Console.WriteLine("--- PreCompileExecutableFunctions()"); Console.WriteLine("--------------------------------------------------------"); // Ensure RuleApplication cache is empty RuleSession.RuleApplicationCache.Clear(); Console.WriteLine("1) Cached RuleApplications: " + RuleSession.RuleApplicationCache.Count); // Expecting 0 // Create 4 in-memory RuleApplications RuleApplicationDef ra1 = new RuleApplicationDef("ra1"); ra1.Entities.Add(new EntityDef("Entity1")).Fields.Add(new FieldDef("Calculation1", "1 + 2", DataType.Integer)); RuleApplicationDef ra2 = new RuleApplicationDef("ra2"); ra2.Entities.Add(new EntityDef("Entity1")).Fields.Add(new FieldDef("Calculation1", "1 + 2", DataType.Integer)); RuleApplicationDef ra3 = new RuleApplicationDef("ra3"); ra3.Entities.Add(new EntityDef("Entity1")).Fields.Add(new FieldDef("Calculation1", "1 + 2", DataType.Integer)); RuleApplicationDef ra4 = new RuleApplicationDef("ra4"); ra4.Entities.Add(new EntityDef("Entity1")).Fields.Add(new FieldDef("Calculation1", "1 + 2", DataType.Integer)); // Create 4 RuleApplicationReferences - Note the implicit casting RuleApplicationReference raRef1 = ra1; RuleApplicationReference raRef2 = ra2; RuleApplicationReference raRef3 = ra3; RuleApplicationReference raRef4 = ra4; // Usage #1: Pre-compile RuleApplications via RuleApplicationCache.Add() - Note EngineLogOptions are compiled into the executable functions raRef1.Compile(CompileSettings.Create(EngineLogOptions.Execution | EngineLogOptions.SummaryStatistics)); raRef2.Compile(); raRef3.Compile(CompileSettings.Create(EngineLogOptions.SummaryStatistics)); raRef4.Compile(CompileSettings.Default); Console.WriteLine("2) Cached RuleApplications: " + RuleSession.RuleApplicationCache.Count); // Expecting 4 // Usage #2: Pre-compile RuleApplications via RuleApplicationReference.Compile() RuleSession.RuleApplicationCache.Add(ra1, CompileSettings.Create(EngineLogOptions.Execution | EngineLogOptions.SummaryStatistics)); RuleSession.RuleApplicationCache.Add(ra2); RuleSession.RuleApplicationCache.Add(ra3, CompileSettings.Create(EngineLogOptions.SummaryStatistics)); RuleSession.RuleApplicationCache.Add(ra4, CompileSettings.Default); Console.WriteLine("3) Cached RuleApplications: " + RuleSession.RuleApplicationCache.Count); // Expecting same 4 // Test ra1 - Metadata + Functions pre-compiled Console.WriteLine("--------------------------------------------------------"); Console.WriteLine("4) RuleApplication '{0}' Metadata Compile timestamp: {1}", ra1.Name, raRef1.LastMetadataCompile); Console.WriteLine("5) RuleApplication '{0}' Function Compile timestamp: {1}", ra1.Name, raRef1.GetLastFunctionCompile(CompileSettings.Create(EngineLogOptions.Execution | EngineLogOptions.SummaryStatistics))); using (RuleSession session = new RuleSession(raRef1)) { session.Settings.LogOptions = EngineLogOptions.Execution | EngineLogOptions.SummaryStatistics; session.CreateEntity("Entity1"); session.ApplyRules(); Console.WriteLine("6) RuleApplication '{0}' Dynamic Function Compile Count during rule execution: {1}", ra1.Name, session.Statistics.FunctionCompileTime.SampleCount); // Expecting 0 due to function pre-compile } // Test ra2 - Only Metadata pre-compiled Console.WriteLine("--------------------------------------------------------"); Console.WriteLine("7) RuleApplication '{0}' Metadata Compile timestamp: {1}", ra2.Name, raRef2.LastMetadataCompile); Console.WriteLine("8) RuleApplication '{0}' Function Compile timestamp: {1}", ra2.Name, raRef2.GetLastFunctionCompile(CompileSettings.Create(EngineLogOptions.Execution | EngineLogOptions.SummaryStatistics))); using (RuleSession session = new RuleSession(raRef2)) { session.Settings.LogOptions = EngineLogOptions.Execution | EngineLogOptions.SummaryStatistics; session.CreateEntity("Entity1"); session.ApplyRules(); Console.WriteLine("9) RuleApplication '{0}' Dynamic Function Compile Count during rule execution: {1}", ra2.Name, session.Statistics.FunctionCompileTime.SampleCount); // Expecting 1 due to functions not pre-compile } // Test ra3 - Metadata + Functions pre-compiled Console.WriteLine("--------------------------------------------------------"); Console.WriteLine("10) RuleApplication '{0}' Metadata Compile timestamp: {1}", ra3.Name, raRef3.LastMetadataCompile); Console.WriteLine("11) RuleApplication '{0}' Function Compile timestamp: {1}", ra3.Name, raRef3.GetLastFunctionCompile(CompileSettings.Create(EngineLogOptions.SummaryStatistics))); using (RuleSession session = new RuleSession(raRef3)) { session.Settings.LogOptions = EngineLogOptions.SummaryStatistics; session.CreateEntity("Entity1"); session.ApplyRules(); Console.WriteLine("12) RuleApplication '{0}' Dynamic Function Compile Count during rule execution: {1}", ra3.Name, session.Statistics.FunctionCompileTime.SampleCount); // Expecting 0 due to function pre-copile } // Test ra4 - Metadata + Functions pre-compiled Console.WriteLine("--------------------------------------------------------"); Console.WriteLine("13) RuleApplication '{0}' Metadata Compile timestamp: {1}", ra4.Name, raRef4.LastMetadataCompile); Console.WriteLine("14) RuleApplication '{0}' Function Compile timestamp (Default): {1}", ra4.Name, raRef4.GetLastFunctionCompile(CompileSettings.Default)); // Note: RuleSession Statistics requires EngineLogOptions.SummaryStatistics to be enabled; CompileSettings.Default does not enable SummaryStatistics unless Info logging is enabled in the .config file. // Test ra4 Function Compile timestamp for different type of CompileSettings Console.WriteLine("15) RuleApplication '{0}' Function Compile timestamp (EngineLogOptions.Execution): {1}", ra4.Name, raRef4.GetLastFunctionCompile(CompileSettings.Create(EngineLogOptions.Execution))); // Should be missing because we only checked compiled functions for the Default options }
public void CompileStage(CompileSettings compileSettings, Stage stage, Project project) { if (stage == null) { throw new ArgumentNullException(nameof(stage)); } if (project == null) { throw new ArgumentNullException(nameof(project)); } if (compileSettings == null) { throw new ArgumentNullException(nameof(compileSettings)); } var builder = new StringBuilder(); // a stage in winforms is a form. // lets create the form code. builder.AppendLine($"using System.Windows.Forms;"); builder.AppendLine(); builder.AppendLine($"public class frm{stage.Name} : Form"); builder.AppendLine("{"); builder.AppendLine($"\tpublic frm{stage.Name}()"); builder.AppendLine("\t{"); var properties = stage.GetType().GetProperties(); var list = new List <string>(); string flowType = string.IsNullOrWhiteSpace(FlowControlName) ? "FlowLayoutPanel" : FlowControlName; builder.AppendLine($"\t\tthis.Text = \"{stage.Name}\";"); builder.AppendLine(); builder.AppendLine($"\t\tvar __flowLayoutPanel = new {flowType}();"); builder.AppendLine("\t\t__flowLayoutPanel.FlowDirection = FlowDirection.TopDown;"); builder.AppendLine("\t\t__flowLayoutPanel.Dock = DockStyle.Fill;"); builder.AppendLine(); foreach (var item in properties) { string type = ""; string namePrefix = ""; if (item.PropertyType == typeof(string)) { //builder.AppendLine("\t}"); type = "TextBox"; namePrefix = "txt"; } if (string.IsNullOrWhiteSpace(type)) { throw new Exception($"Type not supported: {item.PropertyType.ToString()}"); } var controlName = $"{namePrefix}{item.Name}"; builder.AppendLine($"\t\t{type} {controlName} = new {type}();"); builder.AppendLine(); list.Add(controlName); } foreach (var item in stage.Actions) { var buttonName = $"btn{item.Key}"; builder.AppendLine($"\t\tButton {buttonName} = new Button();"); builder.AppendLine($"\t\t{buttonName}.Text = \"{item.Key}\";"); builder.AppendLine(); list.Add(buttonName); } for (int i = 0; i < list.Count; i++) { var name = list[i]; builder.AppendLine($"\t\t{name}.TabIndex = {i};"); builder.AppendLine($"\t\t__flowLayoutPanel.Controls.Add({name});"); builder.AppendLine(); } builder.AppendLine("\t\tthis.Controls.Add(__flowLayoutPanel);"); builder.AppendLine("\t}"); builder.AppendLine("}"); if (!Directory.Exists(compileSettings.Path)) { Directory.CreateDirectory(compileSettings.Path); } File.WriteAllText(Path.Combine(compileSettings.Path, $"frm{stage.Name}.cs"), builder.ToString()); }
public void CompileStage(CompileSettings compileSettings, Stage stage, Project project) { if (stage == null) { throw new ArgumentNullException(nameof(stage)); } if (project == null) { throw new ArgumentNullException(nameof(project)); } if (compileSettings == null) { throw new ArgumentNullException(nameof(compileSettings)); } var builder = new StringBuilder(); builder.AppendLine("<html>"); builder.AppendLine("<head>"); builder.AppendLine($"<meta charset=\"utf-8\">"); if (UseBoostrap) { builder.AppendLine($"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"); builder.AppendLine($"<link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css\" integrity=\"sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z\" crossorigin=\"anonymous\">"); } builder.AppendLine($"<title>{stage.Name}</title>"); builder.AppendLine("</head>"); builder.AppendLine("<body>"); if (UseBoostrap) { builder.AppendLine($"<div class=\"container-fluid\">"); builder.AppendLine("<nav class=\"navbar navbar-light bg-light\">"); builder.AppendLine($"<a class=\"navbar-brand\" href=\"#\">{stage.Name}</a>"); builder.AppendLine("</nav>"); builder.AppendLine("</div>"); } if (!string.IsNullOrWhiteSpace(DefaultContainerClass)) { builder.AppendLine($"<div class=\"{DefaultContainerClass}\" style=\"margin-top:14px\">"); } builder.AppendLine("<form>"); var properties = stage.GetType().GetProperties(); foreach (var item in properties) { string type = ""; string namePrefix = ""; if (item.PropertyType == typeof(string)) { //builder.AppendLine("\t}"); type = "Input"; namePrefix = "txt"; var inputClass = ""; if (UseBoostrap) { inputClass = $" class=\"form-control\""; builder.AppendLine("<div class=\"form-group\">"); //<div class="form-group"> } builder.AppendLine($"<{type}{inputClass} placeholder='{item.Name}' type='text' name='{namePrefix}{item.Name}'/>"); if (!UseBoostrap) { builder.AppendLine("</br>"); } else { builder.AppendLine("</div>"); } } if (string.IsNullOrWhiteSpace(type)) { throw new Exception($"Type not supported: {item.PropertyType.ToString()}"); } } foreach (var item in stage.Actions) { var buttonName = $"btn{item.Key}"; var buttonClass = ""; if (UseBoostrap) { buttonClass = $" class=\"btn btn-primary btn-block\""; } builder.AppendLine($"<button{buttonClass} name='{buttonName}'>{item.Key}</button>"); if (!UseBoostrap) { builder.AppendLine("</br>"); } } if (!string.IsNullOrWhiteSpace(DefaultContainerClass)) { builder.AppendLine($"</div>"); } builder.AppendLine("</form>"); builder.AppendLine("</body>"); builder.AppendLine("</html>"); if (!Directory.Exists(compileSettings.Path)) { Directory.CreateDirectory(compileSettings.Path); } File.WriteAllText(Path.Combine(compileSettings.Path, $"html{stage.Name}.html"), builder.ToString()); }
public AssemblyLoader(CompileSettings settings) { this.settings = settings; }