Skip to content

Commit

Permalink
Merge pull request #19 from schemil053/dev
Browse files Browse the repository at this point in the history
Merge upstream
  • Loading branch information
schemil053 authored Nov 15, 2024
2 parents 02b6032 + 8bbe13a commit 7eaad39
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 6 deletions.
47 changes: 47 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -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.
52 changes: 52 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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
<!--- Describe what should happen if this issue is resolved. For bugs, explain the correct behavior. For feature requests, describe how the improvement should work. -->

---

### Current Behavior
<!--- Describe what happens currently instead of the expected behavior. For bugs, explain the incorrect behavior. For feature requests, note the existing limitations or gaps. -->

---

### Possible Solution
<!--- Optionally suggest potential fixes or ideas for implementing a change. This is helpful but not required. -->

---

### Steps to Reproduce (for bugs)
<!--- Provide clear steps to reproduce the issue. Include links to live examples or any relevant code snippets if applicable. -->
- [ ] Step 1:
- [ ] Step 2:
- [ ] Step 3:
- [ ] Step 4:

---

### Context
<!--- Explain the impact of this issue. How does it affect your project or workflow? Providing context helps us identify the best solution. -->

---

### Environment
<!--- Include key details about your setup to help diagnose the issue. -->
- **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.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -152,6 +153,25 @@ mvn install
</dependency>
```

[## 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 <ARG1> <ARG2> <ARG...>...
```
You can find all available Instructions [here](src/main/resources/Instructions.md)

### Highlang
Structure
```text
command <arg1> <arg2> <arg...>...
```
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)
Expand Down
28 changes: 24 additions & 4 deletions README_DE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -109,7 +110,7 @@ Hier sind einige empfohlene Methoden:
</profile>
</profiles>
```
2. Bauen und bereitstellen:
2. Bauen und in die Repo laden:
```bash
mvn deploy -P beispiel-repo
```
Expand Down Expand Up @@ -147,6 +148,25 @@ mvn install
</dependency>
```

## 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 <ARG1> <ARG2> <ARG...>...
```
Alle Anweisungen sind [hier](src/main/resources/Instructions.md) aufgelistet.

### Highlang
Structure
```text
anweisung <arg1> <arg2> <arg...>...
```
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/Highlang.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Die Sprache ist wie folgt aufgebaut:
| print | <Variable> | Gibt die angegebene Variable aus |
| println | <Variable> | Gibt die angegebene Variable aus und fügt ein \n hinzu |
| putnot | <Variable> | Verneint den angegebene Boolean |
| out | <Variable> <Port> | Gibt etwas auf dem IO-Port aus |
| in | <Variable> <Port> | Speichert den Wert auf Port in der Variable |

Natürlich können Erweiterungen und PreCompiler die Möglichkeiten und Befehle erweitern.

Expand Down

0 comments on commit 7eaad39

Please sign in to comment.