Commit b58123de authored by Alexander Dietsch's avatar Alexander Dietsch

Language:

-Changed all instances of Makro to Macro
-Renamed 'Program' 'Instruction'

GUI:
-Added missing functions
-Added working highlighting for Windows and semi working for Unix systems
(needs a rework if time)

Simulator:
-Minor Bugfixes

Console Application:
-Minor addition to functions; will be focused next
parent f55d8ae9
......@@ -8,6 +8,9 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MainLWSimulator", "MainLWSimulator\MainLWSimulator.csproj", "{EDB87D7D-56A9-40FA-912F-F2DFC530FA38}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LWSimulatorCons", "LWSimulatorCons\LWSimulatorCons.csproj", "{6E4E1071-0802-4610-9178-09D3C57F755D}"
ProjectSection(ProjectDependencies) = postProject
{EDB87D7D-56A9-40FA-912F-F2DFC530FA38} = {EDB87D7D-56A9-40FA-912F-F2DFC530FA38}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......
......@@ -77,6 +77,12 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MainLWSimulator\MainLWSimulator.csproj">
<Project>{edb87d7d-56a9-40fa-912f-f2dfc530fa38}</Project>
<Name>MainLWSimulator</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
......
......@@ -6,12 +6,15 @@ using System.Threading.Tasks;
using NDesk.Options;
using System.Diagnostics;
using System.IO;
using MainLWSimulator;
namespace LWSimulatorCons
{
class Program
{
private const int amInputErrors = 4;
private const int amInputErrors = 6;
private static LWCoordinator simulator;
private static long logLevel = 0;
static void Main(string[] args)
{
bool show_help = false;
......@@ -20,12 +23,14 @@ namespace LWSimulatorCons
long limitSteps = 0;
bool errorInd = false;
bool[] errors = new bool[amInputErrors];
bool quarantined = false;
bool run = false;
OptionSet opt = new OptionSet() {
{
"G|GUI", "start the simulator in a GUI and ignore all other options",
v => gui = v != null },
{
"R|limit-registers=", "limit the number of registers that any program is allowed to use at most; default is 100",
"lR|limit-registers=", "limit the number of registers that any program is allowed to use at most; default is 100",
v => {
if (!tryParseValue(v,out limitRegisters))
{
......@@ -34,7 +39,7 @@ namespace LWSimulatorCons
}
} },
{
"S|limit-steps=", "limit the number of steps that any program is allowed to do before being interrupted at most; default is 0 (off)",
"lS|limit-steps=", "limit the number of steps that any program is allowed to do at most before being interrupted; default is 0 (off)",
v => {
if (!tryParseValue(v,out limitSteps))
{
......@@ -42,6 +47,21 @@ namespace LWSimulatorCons
errors[2] = true;
}
} },
{
"ll|log-level=", "set the level of log; -1 - All messages and debug messages; 0 - All messages; 1 - No errors or warnings; 2 - no log output but result",
v => {
if (!tryParseValue(v,out logLevel))
{
errorInd = true;
errors[4] = true;
}
} },
{
"q|quarantined", "disallow the simulator to save the options so they won't carry over to the next start",
v => quarantined = v != null },
{
"r|run", "automatically run the program",
v => run = v != null },
{
"h|help", "show this message and exit",
v => show_help = v != null },
......@@ -60,6 +80,14 @@ namespace LWSimulatorCons
return;
}
if (show_help)
{
showHelp(opt);
#if (DEBUG)
Console.ReadLine();
#endif
return;
}
if (gui)
{
......@@ -80,6 +108,18 @@ namespace LWSimulatorCons
return;
}
simulator = new LWCoordinator(!quarantined);
if ((logLevel < -1 || logLevel > 2) && !errors[4])
{
errorInd = true;
errors[5] = true;
}
else
{
simulator.setLogFuncs(printLog, dummyFunc, dummyFunc<string>);
}
if (limitRegisters <= 0 && !errors[0])
{
......@@ -88,7 +128,11 @@ namespace LWSimulatorCons
}
else
{
if(!simulator.setOptionVal("maxRegAm",limitRegisters))
{
errorInd = true;
errors[1] = true;
}
}
if(limitSteps < 0 && !errors[2])
......@@ -98,11 +142,17 @@ namespace LWSimulatorCons
}
else
{
if (!simulator.setOptionVal("maxStepAm", limitSteps))
{
errorInd = true;
errors[3] = true;
}
}
if(errorInd)
if (errorInd)
{
Console.WriteLine("LWSimulator: Following errors occured:");
if (errors[0])
......@@ -113,32 +163,29 @@ namespace LWSimulatorCons
Console.WriteLine("\t-Couldn't parse the maximum number of steps");
if (errors[3])
Console.WriteLine("\t-Invalid number for maximum amount of steps");
#if (DEBUG)
Console.ReadLine();
#endif
return;
}
if (errors[4])
Console.WriteLine("\t-Couldn't parse the log level");
if (errors[5])
Console.WriteLine("\t-Invalid number for log level");
if (show_help)
{
showHelp(opt);
#if (DEBUG)
Console.ReadLine();
#endif
return;
}
#if (DEBUG)
Console.ReadLine();
#endif
}
static void printUsage()
private static void printUsage()
{
Console.WriteLine("Usage: lwsimulator.exe [OPTIONS]+");
Console.WriteLine("Starts the Loop-While-Simulator with specific options");
}
static void showHelp(OptionSet p)
private static void showHelp(OptionSet p)
{
printUsage();
Console.WriteLine();
......@@ -146,12 +193,33 @@ namespace LWSimulatorCons
p.WriteOptionDescriptions(Console.Out);
}
static bool tryParseValue(string s, out long value)
private static bool tryParseValue(string s, out long value)
{
value = -1;
if (!long.TryParse(s, out value))
return false;
return true;
}
private static void printLog(string s)
{
if (logLevel == 2 && !s.StartsWith("Code returned"))
return;
if (logLevel == 1 && (s.StartsWith("WARNING") || s.StartsWith("ERROR") || s.StartsWith("DEBUG")))
return;
if (logLevel == 0 && s.StartsWith("DEBUG"))
return;
Console.WriteLine(s);
}
private static void dummyFunc()
{
return;
}
private static void dummyFunc<T>(T arg)
{
return;
}
}
}
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
......
namespace LWSimulatorGUI
{
partial class DeleteRegisters
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lDelete = new System.Windows.Forms.Label();
this.nUDRegisterAm = new System.Windows.Forms.NumericUpDown();
this.lFollowing = new System.Windows.Forms.Label();
this.nUDRegister = new System.Windows.Forms.NumericUpDown();
this.bPrefOK = new System.Windows.Forms.Button();
this.bPrefCancel = new System.Windows.Forms.Button();
this.lRegister = new System.Windows.Forms.Label();
this.lAnd = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.nUDRegisterAm)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nUDRegister)).BeginInit();
this.SuspendLayout();
//
// lDelete
//
this.lDelete.AutoSize = true;
this.lDelete.Location = new System.Drawing.Point(9, 25);
this.lDelete.Name = "lDelete";
this.lDelete.Size = new System.Drawing.Size(83, 13);
this.lDelete.TabIndex = 0;
this.lDelete.Text = "Delete register x";
//
// nUDRegisterAm
//
this.nUDRegisterAm.Location = new System.Drawing.Point(81, 60);
this.nUDRegisterAm.Name = "nUDRegisterAm";
this.nUDRegisterAm.Size = new System.Drawing.Size(59, 20);
this.nUDRegisterAm.TabIndex = 1;
//
// lFollowing
//
this.lFollowing.AutoSize = true;
this.lFollowing.Location = new System.Drawing.Point(9, 62);
this.lFollowing.Name = "lFollowing";
this.lFollowing.Size = new System.Drawing.Size(66, 13);
this.lFollowing.TabIndex = 2;
this.lFollowing.Text = "the following";
//
// nUDRegister
//
this.nUDRegister.Location = new System.Drawing.Point(89, 23);
this.nUDRegister.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.nUDRegister.Name = "nUDRegister";
this.nUDRegister.Size = new System.Drawing.Size(59, 20);
this.nUDRegister.TabIndex = 0;
//
// bPrefOK
//
this.bPrefOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.bPrefOK.Location = new System.Drawing.Point(76, 100);
this.bPrefOK.Name = "bPrefOK";
this.bPrefOK.Size = new System.Drawing.Size(75, 23);
this.bPrefOK.TabIndex = 6;
this.bPrefOK.Text = "OK";
this.bPrefOK.UseVisualStyleBackColor = true;
this.bPrefOK.Click += new System.EventHandler(this.bPrefOK_Click);
//
// bPrefCancel
//
this.bPrefCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.bPrefCancel.Location = new System.Drawing.Point(157, 100);
this.bPrefCancel.Name = "bPrefCancel";
this.bPrefCancel.Size = new System.Drawing.Size(75, 23);
this.bPrefCancel.TabIndex = 7;
this.bPrefCancel.Text = "Cancel";
this.bPrefCancel.UseVisualStyleBackColor = true;
this.bPrefCancel.Click += new System.EventHandler(this.bPrefCancel_Click);
//
// lRegister
//
this.lRegister.AutoSize = true;
this.lRegister.Location = new System.Drawing.Point(146, 62);
this.lRegister.Name = "lRegister";
this.lRegister.Size = new System.Drawing.Size(52, 13);
this.lRegister.TabIndex = 8;
this.lRegister.Text = "register(s)";
//
// lAnd
//
this.lAnd.AutoSize = true;
this.lAnd.Location = new System.Drawing.Point(154, 25);
this.lAnd.Name = "lAnd";
this.lAnd.Size = new System.Drawing.Size(25, 13);
this.lAnd.TabIndex = 9;
this.lAnd.Text = "and";
//
// DeleteRegisters
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(244, 135);
this.Controls.Add(this.lAnd);
this.Controls.Add(this.lRegister);
this.Controls.Add(this.bPrefCancel);
this.Controls.Add(this.bPrefOK);
this.Controls.Add(this.nUDRegister);
this.Controls.Add(this.lFollowing);
this.Controls.Add(this.nUDRegisterAm);
this.Controls.Add(this.lDelete);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "DeleteRegisters";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Delete Registers";
((System.ComponentModel.ISupportInitialize)(this.nUDRegisterAm)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nUDRegister)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lDelete;
private System.Windows.Forms.NumericUpDown nUDRegisterAm;
private System.Windows.Forms.Label lFollowing;
private System.Windows.Forms.NumericUpDown nUDRegister;
private System.Windows.Forms.Button bPrefOK;
private System.Windows.Forms.Button bPrefCancel;
private System.Windows.Forms.Label lRegister;
private System.Windows.Forms.Label lAnd;
}
}
\ No newline at end of file
using MainLWSimulator;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LWSimulatorGUI
{
public partial class DeleteRegisters : Form
{
LWCoordinator simul;
public DeleteRegisters(LWCoordinator coord)
{
InitializeComponent();
simul = coord;
nUDRegister.Maximum = simul.getRegisterAmount() - 1;
nUDRegisterAm.Maximum = simul.getRegisterAmount() - 1;
// Attempt to get some uniformity between platforms
nUDRegister.Location = new Point(lDelete.Location.X + lDelete.Width - 2, nUDRegister.Location.Y);
lAnd.Location = new Point(nUDRegister.Location.X + nUDRegister.Width + 6, lAnd.Location.Y);
nUDRegisterAm.Location = new Point(lFollowing.Location.X + lFollowing.Width + 6, nUDRegisterAm.Location.Y);
lRegister.Location = new Point(nUDRegisterAm.Location.X + nUDRegisterAm.Width + 6, lRegister.Location.Y);
}
private void bPrefOK_Click(object sender, EventArgs e)
{
simul.removeRegisters((int)nUDRegister.Value, (int)nUDRegisterAm.Value + 1);
this.Close();
}
private void bPrefCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
......@@ -54,18 +54,33 @@
// nUDRegisterAm
//
this.nUDRegisterAm.Location = new System.Drawing.Point(41, 23);
this.nUDRegisterAm.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.nUDRegisterAm.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.nUDRegisterAm.Name = "nUDRegisterAm";
this.nUDRegisterAm.Size = new System.Drawing.Size(59, 20);
this.nUDRegisterAm.TabIndex = 1;
this.nUDRegisterAm.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// lRegisters
//
this.lRegisters.AutoSize = true;
this.lRegisters.Location = new System.Drawing.Point(106, 25);
this.lRegisters.Name = "lRegisters";
this.lRegisters.Size = new System.Drawing.Size(115, 13);
this.lRegisters.Size = new System.Drawing.Size(121, 13);
this.lRegisters.TabIndex = 2;
this.lRegisters.Text = "registers with the value";
this.lRegisters.Text = "register(s) with the value";
//
// rBToEnd
//
......@@ -106,7 +121,7 @@
// bPrefOK
//
this.bPrefOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.bPrefOK.Location = new System.Drawing.Point(180, 140);
this.bPrefOK.Location = new System.Drawing.Point(194, 140);
this.bPrefOK.Name = "bPrefOK";
this.bPrefOK.Size = new System.Drawing.Size(75, 23);
this.bPrefOK.TabIndex = 6;
......@@ -117,7 +132,7 @@
// bPrefCancel
//
this.bPrefCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.bPrefCancel.Location = new System.Drawing.Point(261, 140);
this.bPrefCancel.Location = new System.Drawing.Point(275, 140);
this.bPrefCancel.Name = "bPrefCancel";
this.bPrefCancel.Size = new System.Drawing.Size(75, 23);
this.bPrefCancel.TabIndex = 7;
......@@ -141,7 +156,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(348, 175);
this.ClientSize = new System.Drawing.Size(362, 175);
this.Controls.Add(this.nUDValue);
this.Controls.Add(this.bPrefCancel);
this.Controls.Add(this.bPrefOK);
......@@ -156,6 +171,7 @@
this.Name = "InsertRegisters";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Insert Registers";
((System.ComponentModel.ISupportInitialize)(this.nUDRegisterAm)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nUDRegister)).EndInit();
......
......@@ -19,6 +19,14 @@ namespace LWSimulatorGUI
InitializeComponent();
simul = coord;
nUDValue.Value = simul.getOptionVal("defRegVal");
nUDRegister.Maximum = simul.getRegisterAmount() - 1;
nUDRegisterAm.Maximum = simul.getOptionVal("maxRegAm") - simul.getRegisterAmount();
// Attempt to get some uniformity between platforms
nUDRegisterAm.Location = new Point(lInsert.Location.X + lInsert.Width + 6, nUDRegisterAm.Location.Y);
lRegisters.Location = new Point(nUDRegisterAm.Location.X + nUDRegisterAm.Width + 6, lRegisters.Location.Y);
nUDValue.Location = new Point(lRegisters.Location.X + lRegisters.Width + 6, nUDValue.Location.Y);
nUDRegister.Location = new Point(rBBeforeReg.Location.X + rBBeforeReg.Width - 2, nUDRegister.Location.Y);
}
private void rBBeforeReg_CheckedChanged(object sender, EventArgs e)
......@@ -29,7 +37,7 @@ namespace LWSimulatorGUI
private void bPrefOK_Click(object sender, EventArgs e)
{
if (rBBeforeReg.Checked)
simul.insertRegisters((int)nUDRegister.Value,(int)nUDRegisterAm.Value,(long)nUDValue.Value);
simul.insertRegisters((int)nUDRegister.Value, (int)nUDRegisterAm.Value, (long)nUDValue.Value);
else
simul.insertRegisters(simul.getRegisterAmount(), (int)nUDRegisterAm.Value, (long)nUDValue.Value);
this.Close();
......
......@@ -93,6 +93,18 @@
<Compile Include="CustomRichTextBox.cs">
<SubType>Component</SubType>
</Compile>