Skip to content

Commit

Permalink
Revert "Try to add str concat" because wrong branch
Browse files Browse the repository at this point in the history
This reverts commit 26dec15.
  • Loading branch information
schemil053 committed Dec 6, 2024
1 parent 26dec15 commit 8a1af5d
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 171 deletions.
174 changes: 85 additions & 89 deletions src/main/java/de/emilschlampp/scheCPU/compile/Compiler.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ public String decompile() {
if(instruction.getOpCode() == CZMJMP_OPCODE) {
line = "CZMJMP "+instruction.getAddress();
}
if(instruction.getOpCode() == ADDMM_OPCODE) {
line = "ADDMM "+instruction.getAddress()+" "+instruction.getAddressS();
}


pr+="\n"+line;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ public static Instruction parse(InputStream inputStream) throws IOException {
if(instruction.opCode == CZMJMP_OPCODE) {
instruction.address = FolderIOUtil.readInt(inputStream);
}
if(instruction.opCode == ADDMM_OPCODE) {
instruction.address = FolderIOUtil.readInt(inputStream);
instruction.addressS = FolderIOUtil.readInt(inputStream);
}

return instruction;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,6 @@ public void execute() {
jmp++;
}
break;
case ADDMM_OPCODE:
memory[instruction.getAddress()]+=instruction.getAddressS();
break;
default:
throw new RuntimeException("not implemented: " + instruction.getOpCode());
}
Expand Down
89 changes: 18 additions & 71 deletions src/main/java/de/emilschlampp/scheCPU/high/HighProgramCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,59 +92,6 @@ public HighProgramCompiler compile() {
} else {
error("not found! available: variable, option");
}
} else if (split[0].equals("concatvstr")) {
String varname1 = split[1];
String varname2 = split[2];

if (protectedVariables.contains(varname1)) {
error("access violation!");
}

if (!variableAddresses.containsKey(varname1) || !variableAddresses.containsKey(varname2)) {
error("variable not found!");
}

int addr1 = variableAddresses.get(varname1);
int addr2 = variableAddresses.get(varname2);

int func = tmpFuncID++;
int func1 = tmpFuncID++;

/*
"INWM 5 20\n" + // BJMP speichern
"STORE BOOL 1\n" + // Altes Register speichern
"STOREMEM 2 0\n" +
"LOADMEM A " + address + "\n" +
"STOREMEM 3 " + (address + 1) + "\n" + // +1 weil auf der Adresse ja die Anzahl der Zeichen liegt (und addresse+1 = erstes Zeichen)
"FUNC tmp_" + f1 + "\n" +
"CMPM A 2\n" +
"CJMP printChar_" + f2 + "\n" +
"JMP end_" + f3 + "\n" +
"FUNC printChar_" + f2 + "\n" +
"OUTWDM " + options.getOrDefault("io-print-port", "34") + " 3\n" +
"ADDM 3 1\n" +
"ADDM 2 1\n" +
"JMP tmp_" + f1 + "\n" +
"FUNC end_" + f3 + "\n" +
"LOADMEM BOOL 1\n" +
"OUTWM 5 20"
*/

code = code + "\n" +
"ADDMM " + addr1 + " " + addr2 + "\n" +
"INWM 5 20\n" + //BJMP speichern
"STORE BOOL 1\n" + // Altes Register speichern
"STORE A 2\n" + // Altes Register speichern
"STOREMEM 2 0\n" +
"FUNC mem_concat_" + func + "\n" +
"CMPM A 2\n" +
"CJMP mem_concat_" + func + "\n" +

"FUNC end_" + func1 + "\n" +
"LOADMEM BOOL 1\n" +
"LOADMEM A 2\n" +
"OUTWM 5 20"
;
} else if (split[0].equals("ret")) {
if (currentMethod == null) {
error("can only be called inside a method!");
Expand Down Expand Up @@ -318,12 +265,12 @@ public HighProgramCompiler compile() {

code = code + "\n" +
"STORE BOOL 7\n" +
"CMPMEM " + variableAddresses.get(var1) + " " + variableAddresses.get(var2) + "\n" +
"CZJMP start_" + f1 + "\n" +
"JMP end_" + f2 + "\n" +
"FUNC start_" + f1 + "\n" +
"STOREMEM " + variableAddresses.get(target) + " 1\n" +
"FUNC end_" + f2 + "\n" +
"CMPMEM "+variableAddresses.get(var1)+" "+variableAddresses.get(var2)+"\n" +
"CZJMP start_"+f1+"\n" +
"JMP end_"+f2+"\n" +
"FUNC start_"+f1+"\n" +
"STOREMEM "+variableAddresses.get(target)+" 1\n" +
"FUNC end_"+f2+"\n" +
"LOADMEM BOOL 7"; //TODO: Fertig coden
} else if (split[0].equals("print")) {
String val = split[1];
Expand Down Expand Up @@ -357,12 +304,12 @@ public HighProgramCompiler compile() {
"LOADMEM BOOL 1\n" +
"OUTWM 5 20"
;
} else if (split[0].equals("out")) {
} else if(split[0].equals("out")) {
String val = split[1];

String portVal = split[2];

if (!isInt(portVal)) {
if(!isInt(portVal)) {
error("invalid port!");
}

Expand All @@ -375,13 +322,13 @@ public HighProgramCompiler compile() {
int address = variableAddresses.get(val);

code = code + "\n" +
"OUTWM " + port + " " + address;
} else if (split[0].equals("in")) {
"OUTWM "+port+" "+address;
} else if(split[0].equals("in")) {
String val = split[1];

String portVal = split[2];

if (!isInt(portVal)) {
if(!isInt(portVal)) {
error("invalid port!");
}

Expand All @@ -394,7 +341,7 @@ public HighProgramCompiler compile() {
int address = variableAddresses.get(val);

code = code + "\n" +
"INWM " + port + " " + address;
"INWM "+port+" "+address;
} else if (split[0].equals("println")) {
String val = split[1];

Expand Down Expand Up @@ -444,18 +391,18 @@ public HighProgramCompiler compile() {
code = code + "\n" +
"MULM " + address + " -1\n" +
"ADDM " + address + " 1";
} else if (split[0].equals("asm")) {
if (options.getOrDefault("disable-asm", "0").equals("1")) {
} else if(split[0].equals("asm")) {
if(options.getOrDefault("disable-asm", "0").equals("1")) {
error("asm is disabled");
}
String asm = "";
for (int i = 1; i < split.length; i++) {
asm += (" " + split[i]);
asm += (" "+split[i]);
}
if (!asm.isEmpty()) {
if(!asm.isEmpty()) {
asm = asm.substring(1);
}
code = code + "\n" + asm;
code = code+"\n"+asm;
} else {
if (compileProcessor != null) {
String a = compileProcessor.generateSchesemForInstruction(compileContext, split);
Expand Down Expand Up @@ -493,7 +440,7 @@ private boolean isInt(String i) {
}

private int parseInt(String i) {
if (!isInt(i)) {
if(!isInt(i)) {
throw new RuntimeException("Expected Integer");
}
return Integer.parseInt(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class StaticValues {
public static final int CMJMP_OPCODE = 35;
public static final int CNMJMP_OPCODE = 36;
public static final int CZMJMP_OPCODE = 37;
public static final int ADDMM_OPCODE = 38; //TODO: SUB, DIV and MUL



Expand Down

0 comments on commit 8a1af5d

Please sign in to comment.