diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..00f38da --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,47 @@ +# Contributor Covenant Code of Conduct + +## Our Commitment + +To foster an open, welcoming, and inclusive environment, we as contributors and maintainers commit to ensuring that participation in our project and community is harassment-free for everyone. This includes individuals of all ages, body types, abilities, ethnicities, gender identities and expressions, levels of experience, education, socio-economic backgrounds, nationalities, personal appearances, races, religions, sexual orientations, or any other characteristic. + +## Our Standards + +We strive to create a positive, respectful, and constructive community. Examples of behavior that contribute to this include: + +- Using welcoming and inclusive language. +- Respecting diverse perspectives and experiences. +- Accepting constructive feedback gracefully. +- Prioritizing the community's best interests. +- Demonstrating empathy and kindness toward others. + +Unacceptable behaviors that do not align with these values include but are not limited to: + +- Using sexualized language, imagery, or unwelcome sexual advances. +- Engaging in trolling, insults, or personal and political attacks. +- Harassing others publicly or privately. +- Publishing private information (e.g., physical or email addresses) without explicit consent. +- Acting in any way deemed inappropriate in a professional or community setting. + +## Our Responsibilities + +Project maintainers are responsible for clearly defining acceptable behavior and enforcing these standards consistently and fairly. They are empowered to: + +- Edit, delete, or reject comments, commits, code, or contributions that violate this Code of Conduct. +- Take temporary or permanent action against individuals for inappropriate, threatening, or harmful behavior. + +## Scope + +This Code of Conduct applies to all project spaces, including official channels like forums, repositories, and social media accounts. It also extends to public interactions where individuals represent the project or community, such as conferences, events, or online discussions. + +Project maintainers may further clarify what constitutes project representation and ensure that guidelines are well understood. + +## Enforcement + +If you experience or witness abusive, harassing, or otherwise unacceptable behavior, please report it by contacting the project team. All reports will be reviewed promptly, thoroughly, and confidentially. + +The project team will respond appropriately to the situation, which may include: +- Taking corrective action. +- Communicating outcomes with the affected parties. +- Enforcing temporary or permanent sanctions as necessary. + +Maintainers who fail to uphold or enforce this Code of Conduct in good faith may face repercussions as determined by the project’s leadership team. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..a154e33 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,52 @@ +### Check for Existing Issues +Before creating a new issue, please search the [issue tracker](../) to see if it has already been reported. + +--- + +### Checklist +Before submitting your issue, please confirm that you have: +- [ ] Searched the issue tracker to check if this issue has already been reported. +- [ ] Included a clear and descriptive title. +- [ ] Provided all relevant details in the sections below. + +--- + +### Expected Behavior + + +--- + +### Current Behavior + + +--- + +### Possible Solution + + +--- + +### Steps to Reproduce (for bugs) + +- [ ] Step 1: +- [ ] Step 2: +- [ ] Step 3: +- [ ] Step 4: + +--- + +### Context + + +--- + +### Environment + +- **Version Used:** +- **Browser and Version:** +- **Operating System and Version (Desktop or Mobile):** +- **Project Link (if applicable):** + +--- + +This format ensures all critical details are captured while providing a structured way to validate the completeness of the issue report. \ No newline at end of file diff --git a/README.md b/README.md index b0010b4..2ee3f91 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,9 @@ URL: https://github.com/schemil053/ScheCPUEmulator - [Registers](#registers) - [Memory Management](#memory-management) 4. [Usage](#usage) -5. [Examples](#examples) -6. [Future Improvements](#future-improvements) +5. [Programming Languages](#programming-languages) +6. [Examples](#examples) +7. [Future Improvements](#future-improvements) ## Introduction This project is a Java-based CPU emulator that aims to simulate fundamental CPU operations for educational purposes. The emulator is designed to simplify understanding of how CPUs function, making it accessible and easy to learn for those new to computing. @@ -152,6 +153,25 @@ mvn install ``` +[## Programming Languages +There are 2 Languages that this default configuration can compile and understand. +The first one is Schessembler. It's an assembly-like language with a custom instruction set. +The second one is Highlang. It converts to Schessembler, wich converts to bytecode. + +### Schessembler +Structure: +```text +INSTRUCTION ... +``` +You can find all available Instructions [here](src/main/resources/Instructions.md) + +### Highlang +Structure +```text +command ... +``` +You can find all available Instructions [here](src/main/resources/Highlang.md)]() + ## Examples ### Schessembler Examples - [Hello world (char by char)](src/test/resources/hello-world.sasm) diff --git a/README_DE.md b/README_DE.md index ee4a7b5..e5d247c 100644 --- a/README_DE.md +++ b/README_DE.md @@ -17,13 +17,14 @@ URL: https://github.com/schemil053/ScheCPUEmulator - [Register](#register) - [Speicherverwaltung](#speicherverwaltung) 4. [Verwendung](#verwendung) -5. [Beispiele](#beispiele) -6. [Zukünftige Verbesserungen](#zukünftige-verbesserungen) +5. [Programmiersprachen](#programmiersprachen) +6. [Beispiele](#beispiele) +7. [Zukünftige Verbesserungen](#zukünftige-verbesserungen) ## Einleitung Dieses Projekt ist ein Java-basierter CPU-Emulator, der grundlegende CPU-Operationen zu Lernzwecken simuliert. Der Emulator wurde entwickelt, um das Verständnis dafür zu erleichtern, wie eine CPU funktioniert und für Einsteiger leicht zugänglich und verständlich zu machen. -Dieser Emulator läuft im "locked-down"-Modus: Programme werden zur Compile-Zeit geladen, d. h. Speicher und Befehle können zur Laufzeit nicht verändert werden. Diese Einschränkung ermöglicht Anfängern, sich auf die grundlegende CPU-Mechanik zu konzentrieren, ohne zusätzliche Komplexität. +Dieser Emulator läuft im "locked-down"-Modus: Programme werden beim Start in einem anderem Speicher geladen, d. h. Speicher und Befehle können zur Laufzeit nicht verändert werden. Diese Einschränkung ermöglicht Anfängern, sich auf die grundlegende CPU-Mechanik zu konzentrieren, ohne zusätzliche Komplexität. ## Projektziele - Die Grundlagen des CPU-Designs vermitteln: Der Hauptzweck dieses Emulators ist es, den Benutzern zu helfen, zu verstehen, wie eine CPU funktioniert. @@ -109,7 +110,7 @@ Hier sind einige empfohlene Methoden: ``` -2. Bauen und bereitstellen: +2. Bauen und in die Repo laden: ```bash mvn deploy -P beispiel-repo ``` @@ -147,6 +148,25 @@ mvn install ``` +## Programmiersprachen +Dieses Projekt versteht in der Standardkonfiguration zwei Programmiersprachen, welche kompiliert werden können. +Die erste ist Schessembler. Sie hat einige Ähnlichkeiten mit Assembler, allerdings eine eigene Anweisungstabelle. +Die zweite Programmiersprache ist Highlang. Sie wird in Schessembler umgewandelt, welches in Bytecode umgewandelt werden kann. + +### Schessembler +Structure: +```text +ANWEISUNG ... +``` +Alle Anweisungen sind [hier](src/main/resources/Instructions.md) aufgelistet. + +### Highlang +Structure +```text +anweisung ... +``` +Alle Anweisungen sind [hier](src/main/resources/Highlang.md) aufgelistet. + ## Beispiele ### Schessembler-Beispiele - [Hello world (Zeichen für Zeichen)](src/test/resources/hello-world.sasm) diff --git a/src/main/java/de/emilschlampp/scheCPU/high/HighProgramCompiler.java b/src/main/java/de/emilschlampp/scheCPU/high/HighProgramCompiler.java index 4e5cd8f..0654d59 100644 --- a/src/main/java/de/emilschlampp/scheCPU/high/HighProgramCompiler.java +++ b/src/main/java/de/emilschlampp/scheCPU/high/HighProgramCompiler.java @@ -11,6 +11,8 @@ import java.util.Map; import java.util.function.Consumer; +import static de.emilschlampp.scheCPU.util.StaticValues.*; + public class HighProgramCompiler { private final String program; private String output; @@ -302,6 +304,44 @@ public HighProgramCompiler compile() { "LOADMEM BOOL 1\n" + "OUTWM 5 20" ; + } else if(split[0].equals("out")) { + String val = split[1]; + + String portVal = split[2]; + + if(!isInt(portVal)) { + error("invalid port!"); + } + + int port = parseInt(portVal); + + if (!variableAddresses.containsKey(val)) { + error("variable not found!"); + } + + int address = variableAddresses.get(val); + + code = code + "\n" + + "OUTWM "+port+" "+address; + } else if(split[0].equals("in")) { + String val = split[1]; + + String portVal = split[2]; + + if(!isInt(portVal)) { + error("invalid port!"); + } + + int port = parseInt(portVal); + + if (!variableAddresses.containsKey(val)) { + error("variable not found!"); + } + + int address = variableAddresses.get(val); + + code = code + "\n" + + "INWM "+port+" "+address; } else if (split[0].equals("println")) { String val = split[1]; @@ -390,6 +430,38 @@ public HighProgramCompiler compile() { return this; } + private boolean isInt(String i) { + try { + Integer.parseInt(i); + return true; + } catch (Throwable t) { + return false; + } + } + + private int parseInt(String i) { + if(!isInt(i)) { + throw new RuntimeException("Expected Integer"); + } + return Integer.parseInt(i); + } + + private int toRegID(String v) { + switch (v) { + case "A": + return REGID_A; + case "B": + return REGID_B; + case "C": + return REGID_C; + case "D": + return REGID_D; + case "BOOL": + return REGID_BOOLVAL; + } + throw new RuntimeException("err"); + } + private void error(String message) { throw new IllegalStateException("error in line " + currentLine + ": " + message); } diff --git a/src/main/resources/Highlang.md b/src/main/resources/Highlang.md index 1c38b87..0cf09f2 100644 --- a/src/main/resources/Highlang.md +++ b/src/main/resources/Highlang.md @@ -24,6 +24,8 @@ Die Sprache ist wie folgt aufgebaut: | print | | Gibt die angegebene Variable aus | | println | | Gibt die angegebene Variable aus und fügt ein \n hinzu | | putnot | | Verneint den angegebene Boolean | +| out | | Gibt etwas auf dem IO-Port aus | +| in | | Speichert den Wert auf Port in der Variable | Natürlich können Erweiterungen und PreCompiler die Möglichkeiten und Befehle erweitern.