Skip to content

Commit

Permalink
Merge pull request #17 from schemil053/dev
Browse files Browse the repository at this point in the history
Merge upstream
  • Loading branch information
schemil053 authored Nov 12, 2024
2 parents 6aa2170 + 7ab713f commit 02b6032
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -P github-repo -B package --file pom.xml
run: mvn -P github-repo -B package test --file pom.xml
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ mvn install
- [Hello world (loadstrm)](src/test/resources/simple-loadstrm-english.sasm)

### Implementation
- [Simple Compiler (Schessembler)](src/test/java/de/emilschlampp/scheCPU/compile/CompilerTest.java)
- [Simple Compiler (Highlang)](src/test/java/de/emilschlampp/scheCPU/high/HighCompilerTest.java)
- [Executor (Bytecode)](src/test/java/de/emilschlampp/scheCPU/emulator/CPUEmulatorTest.java)
- [Simple Compiler (Schessembler)](src/test/java/de/emilschlampp/scheCPU/examples/compile/CompilerTest.java)
- [Simple Compiler (Highlang)](src/test/java/de/emilschlampp/scheCPU/examples/high/HighCompilerTest.java)
- [Executor (Bytecode)](src/test/java/de/emilschlampp/scheCPU/examples/emulator/CPUEmulatorTest.java)


## Future Improvements
Expand Down
6 changes: 3 additions & 3 deletions README_DE.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ mvn install
- [Hello world (loadstrm)](src/test/resources/simple-loadstrm-german.sasm)

### Implementierung
- [Einfacher Compiler (Schessembler)](src/test/java/de/emilschlampp/scheCPU/compile/CompilerTest.java)
- [Einfacher Compiler (Highlang)](src/test/java/de/emilschlampp/scheCPU/high/HighCompilerTest.java)
- [Ausführung (Bytecode)](src/test/java/de/emilschlampp/scheCPU/emulator/CPUEmulatorTest.java)
- [Einfacher Compiler (Schessembler)](src/test/java/de/emilschlampp/scheCPU/examples/compile/CompilerTest.java)
- [Einfacher Compiler (Highlang)](src/test/java/de/emilschlampp/scheCPU/examples/high/HighCompilerTest.java)
- [Ausführung (Bytecode)](src/test/java/de/emilschlampp/scheCPU/examples/emulator/CPUEmulatorTest.java)

## Zukünftige Verbesserungen
- [ ] Eine Minecraft-Version des Emulators erstellen, die innerhalb von Minecraft läuft und Mechaniken hinzufügt, um Redstone über eine CPU zu steuern.
Expand Down
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@
</plugins>
</build>

<dependencies>
<!-- junit 5, unit test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>

<profiles>
<profile>
<id>emilschlampp-repo</id>
Expand All @@ -54,6 +71,9 @@
</repository>
</distributionManagement>
</profile>
<profile>
<id>github-repo</id>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.emilschlampp.scheCPU;
package de.emilschlampp.scheCPU.examples;

import de.emilschlampp.scheCPU.compile.Compiler;
import de.emilschlampp.scheCPU.dissassembler.Decompiler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.emilschlampp.scheCPU.compile;
package de.emilschlampp.scheCPU.examples.compile;

import de.emilschlampp.scheCPU.Main;
import de.emilschlampp.scheCPU.examples.Main;
import de.emilschlampp.scheCPU.compile.Compiler;

import java.io.FileOutputStream;
import java.util.Scanner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.emilschlampp.scheCPU.emulator;
package de.emilschlampp.scheCPU.examples.emulator;

import de.emilschlampp.scheCPU.emulator.ProcessorEmulator;
import de.emilschlampp.scheCPU.util.FolderIOUtil;

import java.io.FileInputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.emilschlampp.scheCPU.high;
package de.emilschlampp.scheCPU.examples.high;

import de.emilschlampp.scheCPU.Main;
import de.emilschlampp.scheCPU.compile.Compiler;
import de.emilschlampp.scheCPU.examples.Main;
import de.emilschlampp.scheCPU.high.HighProgramCompiler;

import java.io.FileOutputStream;
import java.util.Scanner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package de.emilschlampp.scheCPU.high;
package de.emilschlampp.scheCPU.examples.high;

import de.emilschlampp.scheCPU.compile.Compiler;
import de.emilschlampp.scheCPU.dissassembler.Decompiler;
import de.emilschlampp.scheCPU.emulator.ProcessorEmulator;
import de.emilschlampp.scheCPU.high.HighProgramCompiler;

import java.io.File;
import java.io.FileOutputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.emilschlampp.scheCPU.util;
package de.emilschlampp.scheCPU.examples.util;

import java.io.File;
import java.io.FileInputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.emilschlampp.scheCPU.tests;

import de.emilschlampp.scheCPU.compile.Compiler;
import de.emilschlampp.scheCPU.dissassembler.Decompiler;
import de.emilschlampp.scheCPU.util.StaticValues;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class CPUCompilerDecompilerTest {
@Test
public void testCompileDecompileSimple() {
String val = "OUTW 1 0"; // Only simple instructions are possible

byte[] program = new Compiler(val).compile();

assertEquals(val, new Decompiler(program).decompile());
}

@Test
public void testDeserial() {
String val = "OUTW 1 0"; // Do not change!!!

byte[] program = new Compiler(val).compile();

assertEquals(1, new Decompiler(program).getInstructions().length);
assertEquals(StaticValues.OUTW_OPCODE, new Decompiler(program).getInstructions()[0].getOpCode());
}
}
45 changes: 45 additions & 0 deletions src/test/java/de/emilschlampp/scheCPU/tests/CPUStateTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package de.emilschlampp.scheCPU.tests;

import de.emilschlampp.scheCPU.compile.Compiler;
import de.emilschlampp.scheCPU.emulator.ProcessorEmulator;
import de.emilschlampp.scheCPU.util.FolderIOUtil;
import de.emilschlampp.scheCPU.util.StaticValues;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class CPUStateTest {
@Test()
public void testSerialVersion() throws IOException {
ProcessorEmulator processorEmulator = new ProcessorEmulator(5, 5, new Compiler("OUTW 1 0").compile());
processorEmulator.execute();

ByteArrayInputStream inputStream = new ByteArrayInputStream(processorEmulator.saveState());

assertEquals(FolderIOUtil.readInt(inputStream), StaticValues.SERIAL_VERSION);
}

@Test()
public void testState() {
byte[] program = new Compiler("OUTW 1 0").compile();

ProcessorEmulator processorEmulator1 = new ProcessorEmulator(5, 5, program);
processorEmulator1.execute();

ProcessorEmulator processorEmulator2 = new ProcessorEmulator(5, 5, program);


ProcessorEmulator stateCopy1 = new ProcessorEmulator(processorEmulator1.saveState());
ProcessorEmulator stateCopy2 = new ProcessorEmulator(processorEmulator2.saveState());

assertNotEquals(processorEmulator1.getJmp(), stateCopy2.getJmp());
assertNotEquals(processorEmulator2.getJmp(), stateCopy1.getJmp());

assertEquals(processorEmulator1.getJmp(), stateCopy1.getJmp());
assertEquals(processorEmulator2.getJmp(), stateCopy2.getJmp());
}
}

0 comments on commit 02b6032

Please sign in to comment.