private void buttonViewCompiledCode_Click(object sender, EventArgs e) { CodeBox box = CurrentBox; if (box == null) { return; } LinkAndOptimize(box); // Setup box comments List <string> code = new List <string>(); code.Add("// Compiled code, " + box.GatesInLinkedCode() + " gates"); if (box.Error) { code.Add("// NOTE: This box has errors. The code is incorrect."); } // Show box info code.Add(box.Symbol.ResolvedName); code.Add("{"); // Show all the code foreach (OpCodeExpr expr in box.LinkedCode) { StringBuilder sb = new StringBuilder(); sb.Append(" "); expr.PrintExpression(sb); sb.Append(";"); AddSplitString(code, sb); } code.Add("}"); // Setup to display the "view code" form // after closing this form FormViewText form = new FormViewText(); form.Text = "" + box + " (compiled)"; form.TextLines = code.ToArray(); FormResult = form; Close(); }
private void FormSimulate_Load(object sender, EventArgs e) { // Initialize form variables Text = Box.ParseBox.NameDecl.VariableName + " Simulation"; comboSpeed.Items.Add(new sComboSpeed("Speed: 100 gates/sec", 100)); comboSpeed.Items.Add(new sComboSpeed("Speed: 1000 gates/sec", 1000)); comboSpeed.Items.Add(new sComboSpeed("Speed: Fast as possible", 0)); comboSpeed.SelectedIndex = 0; mThreadSpeedGPS = 100; labelStats.Text = "Simulating " + Box.GatesInLinkedCode() + " gates"; // Setup edit field parameters IN/OUT SetupEditField(Box.Symbol, true); foreach (Symbol symbol in Box.Params) { SetupEditField(symbol, true); } // Setup edit field locals foreach (Symbol symbol in Box.Locals) { SetupEditField(symbol, false); } // Give the first input field the focus if (mFieldTabs.Count != 0) { mFieldInputs[0].Editor.CursorLoc = new TokenLoc(0, 1000); mFieldTabs[0].Focus(); } // Setup input field locations int left = 4; int inY = 4; int outY = 4; foreach (EditField field in mFieldInputs) { panelParams.Controls.Add(field); field.Location = new Point(left, inY); inY += field.Height; field.Visible = true; } // Setup output field locations foreach (EditField field in mFieldOutputs) { panelParams.Controls.Add(field); field.Location = new Point(left + field.Width, outY); outY += field.Height; field.Visible = true; } // Setup "Locals" label panelParams.Height = Math.Max(inY, outY) + 8; labelLocals.Top = panelParams.Bottom + 8; panelLocals.Top = labelLocals.Bottom; panelLocals.Height = Math.Max(1, ClientRectangle.Height - panelLocals.Top - 4); // Setup local field locations (two columns) int half = (mFieldLocals.Count + 1) / 2; for (int i = 0; i < mFieldLocals.Count; i++) { EditField field = mFieldLocals[i]; panelLocals.Controls.Add(field); field.Location = new Point(4 + (i >= half ? field.Width : 0), 4 + (i >= half ? i - half : i) * field.Height); field.Visible = true; } // Show this form before displaying an error message Show(); // Initialize the simulation (wait for stabilization) if (!ResetSim(OpState.Zero)) { MessageBox.Show(this, "Error: The simulation is un-stable. This can be " + "caused by something like: A = !A"); } // Start thread running Application.ApplicationExit += new EventHandler(Application_ApplicationExit); mThread = new Thread((ThreadStart) delegate { SimulationThread(); }); mThread.Start(); }