Add logging jars
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -15,7 +15,6 @@ dist/
|
|||||||
downloads/
|
downloads/
|
||||||
eggs/
|
eggs/
|
||||||
.eggs/
|
.eggs/
|
||||||
lib/
|
|
||||||
lib64/
|
lib64/
|
||||||
parts/
|
parts/
|
||||||
sdist/
|
sdist/
|
||||||
|
|||||||
BIN
Project-01/uap25-pro01-tram/lib/apiguardian-api-1.1.2.jar
Normal file
BIN
Project-01/uap25-pro01-tram/lib/apiguardian-api-1.1.2.jar
Normal file
Binary file not shown.
BIN
Project-01/uap25-pro01-tram/lib/hamcrest-core-1.3.jar
Normal file
BIN
Project-01/uap25-pro01-tram/lib/hamcrest-core-1.3.jar
Normal file
Binary file not shown.
BIN
Project-01/uap25-pro01-tram/lib/junit-4.13.1.jar
Normal file
BIN
Project-01/uap25-pro01-tram/lib/junit-4.13.1.jar
Normal file
Binary file not shown.
BIN
Project-01/uap25-pro01-tram/lib/junit-jupiter-5.8.1.jar
Normal file
BIN
Project-01/uap25-pro01-tram/lib/junit-jupiter-5.8.1.jar
Normal file
Binary file not shown.
BIN
Project-01/uap25-pro01-tram/lib/junit-jupiter-api-5.8.1.jar
Normal file
BIN
Project-01/uap25-pro01-tram/lib/junit-jupiter-api-5.8.1.jar
Normal file
Binary file not shown.
BIN
Project-01/uap25-pro01-tram/lib/junit-jupiter-engine-5.8.1.jar
Normal file
BIN
Project-01/uap25-pro01-tram/lib/junit-jupiter-engine-5.8.1.jar
Normal file
Binary file not shown.
BIN
Project-01/uap25-pro01-tram/lib/junit-jupiter-params-5.8.1.jar
Normal file
BIN
Project-01/uap25-pro01-tram/lib/junit-jupiter-params-5.8.1.jar
Normal file
Binary file not shown.
BIN
Project-01/uap25-pro01-tram/lib/junit-platform-commons-1.8.1.jar
Normal file
BIN
Project-01/uap25-pro01-tram/lib/junit-platform-commons-1.8.1.jar
Normal file
Binary file not shown.
BIN
Project-01/uap25-pro01-tram/lib/junit-platform-engine-1.8.1.jar
Normal file
BIN
Project-01/uap25-pro01-tram/lib/junit-platform-engine-1.8.1.jar
Normal file
Binary file not shown.
BIN
Project-01/uap25-pro01-tram/lib/log4j-api-2.24.1.jar
Normal file
BIN
Project-01/uap25-pro01-tram/lib/log4j-api-2.24.1.jar
Normal file
Binary file not shown.
BIN
Project-01/uap25-pro01-tram/lib/log4j-core-2.24.1.jar
Normal file
BIN
Project-01/uap25-pro01-tram/lib/log4j-core-2.24.1.jar
Normal file
Binary file not shown.
BIN
Project-01/uap25-pro01-tram/lib/opentest4j-1.2.0.jar
Normal file
BIN
Project-01/uap25-pro01-tram/lib/opentest4j-1.2.0.jar
Normal file
Binary file not shown.
@@ -3,31 +3,116 @@ package de.unitrier.st.uap.w25.tram;
|
|||||||
import org.apache.logging.log4j.Level;
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.core.config.Configurator;
|
import org.apache.logging.log4j.core.config.Configurator;
|
||||||
|
|
||||||
final class Main {
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public final class Main {
|
||||||
private Main() {}
|
private Main() {}
|
||||||
|
|
||||||
static void main(String[] argv) {
|
public static void main(String[] argv) {
|
||||||
// Configurator.setRootLevel(Level.DEBUG);
|
if (argv.length < 1) {
|
||||||
|
System.err.println("Usage:");
|
||||||
|
System.err.println(" java -jar tram.jar <tramFile> [--debug [logFile]] [--stack [v1,v2,...]]");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
String tramPath = argv[0];
|
||||||
|
boolean debug = false;
|
||||||
|
String logFile = null;
|
||||||
|
String stackArg = null;
|
||||||
|
|
||||||
|
// Parse arguments
|
||||||
|
for (int i = 1; i < argv.length; i++) {
|
||||||
|
switch (argv[i]) {
|
||||||
|
case "--debug" -> {
|
||||||
|
debug = true;
|
||||||
|
if (i + 1 < argv.length && !argv[i + 1].startsWith("--")) {
|
||||||
|
logFile = argv[++i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "--stack" -> {
|
||||||
|
if (i + 1 < argv.length) {
|
||||||
|
stackArg = argv[++i];
|
||||||
|
} else {
|
||||||
|
System.err.println("Error: missing stack argument after --stack");
|
||||||
|
System.exit(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
System.err.println("Unknown argument: " + argv[i]);
|
||||||
|
System.exit(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify .tram file
|
||||||
|
Path tramFile = Path.of(tramPath);
|
||||||
|
if (!Files.exists(tramFile)) {
|
||||||
|
System.err.println("Error: file not found -> " + tramPath);
|
||||||
|
System.exit(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure logging
|
||||||
|
if (debug) {
|
||||||
|
Configurator.setRootLevel(Level.DEBUG);
|
||||||
|
if (logFile != null) {
|
||||||
|
Path logPath = Path.of(logFile);
|
||||||
|
try {
|
||||||
|
Files.createDirectories(logPath.getParent() != null ? logPath.getParent() : Path.of("."));
|
||||||
|
if (!Files.exists(logPath)) Files.createFile(logPath);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Error: cannot create log file -> " + logPath);
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(5);
|
||||||
|
}
|
||||||
|
LoggedMachine.toFile(logPath.toString());
|
||||||
|
System.out.println("Debug logging to file: " + logPath);
|
||||||
|
} else {
|
||||||
|
System.out.println("Debug logging to console.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
Configurator.setRootLevel(Level.INFO);
|
Configurator.setRootLevel(Level.INFO);
|
||||||
|
}
|
||||||
|
|
||||||
Instruction[] code = Assembler.readTRAMCode(
|
// Parse optional stack
|
||||||
//"tramcode/square.tram"
|
Integer[] stack = parseStack(stackArg);
|
||||||
//"tramcode/wrapper.tram"
|
|
||||||
//"tramcode/example1.tram"
|
|
||||||
//"tramcode/example2.tram"
|
|
||||||
//"tramcode/example3.tram"
|
|
||||||
"tramcode/test.tram"
|
|
||||||
);
|
|
||||||
|
|
||||||
// int lineNr = 0;
|
// Load TRAM code and execute
|
||||||
// for (Instruction instr : code) {
|
Instruction[] code = Assembler.readTRAMCode(tramPath);
|
||||||
// if (instr != null) {
|
LoggedMachine tram = new LoggedMachine(code, stack);
|
||||||
// System.out.println(String.format("%03d", lineNr) + "| " + instr);
|
|
||||||
// lineNr++;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
LoggedMachine tram = new LoggedMachine(code, new Integer[]{}); // empty stack or predefined args
|
|
||||||
tram.execute();
|
tram.execute();
|
||||||
|
|
||||||
|
System.out.println("Execution complete.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a stack argument given in Python list notation, e.g. "[1,2,3]"
|
||||||
|
*/
|
||||||
|
private static Integer[] parseStack(String stackArg) {
|
||||||
|
if (stackArg == null || stackArg.isBlank()) {
|
||||||
|
return new Integer[] {};
|
||||||
|
}
|
||||||
|
String trimmed = stackArg.trim();
|
||||||
|
if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
|
||||||
|
trimmed = trimmed.substring(1, trimmed.length() - 1);
|
||||||
|
}
|
||||||
|
if (trimmed.isBlank()) {
|
||||||
|
return new Integer[] {};
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] parts = trimmed.split(",");
|
||||||
|
List<Integer> list = new ArrayList<>();
|
||||||
|
for (String p : parts) {
|
||||||
|
try {
|
||||||
|
list.add(Integer.parseInt(p.trim()));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.err.println("Invalid stack element: " + p);
|
||||||
|
System.exit(6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list.toArray(new Integer[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,10 +36,11 @@
|
|||||||
<orderEntry type="module-library">
|
<orderEntry type="module-library">
|
||||||
<library>
|
<library>
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
<root url="jar://$MODULE_DIR$/lib/log4j-core-2.24.1.jar!/" />
|
<root url="file://$MODULE_DIR$/lib" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES />
|
<SOURCES />
|
||||||
|
<jarDirectory url="file://$MODULE_DIR$/lib" recursive="false" />
|
||||||
</library>
|
</library>
|
||||||
</orderEntry>
|
</orderEntry>
|
||||||
<orderEntry type="module-library">
|
<orderEntry type="module-library">
|
||||||
@@ -51,5 +52,14 @@
|
|||||||
<SOURCES />
|
<SOURCES />
|
||||||
</library>
|
</library>
|
||||||
</orderEntry>
|
</orderEntry>
|
||||||
|
<orderEntry type="module-library">
|
||||||
|
<library>
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MODULE_DIR$/lib/log4j-core-2.24.1.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</orderEntry>
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
Reference in New Issue
Block a user