From 8a1af5dafdc15271bd4aef1a6b45a5c807c5b1cd Mon Sep 17 00:00:00 2001 From: Emil Schlampp Date: Fri, 6 Dec 2024 09:19:35 +0100 Subject: [PATCH] Revert "Try to add str concat" because wrong branch This reverts commit 26dec15c013bbf4f8d54b4ccc95e11b2d237d9f0. --- .../scheCPU/compile/Compiler.java | 174 +++++++++--------- .../scheCPU/dissassembler/Decompiler.java | 3 - .../scheCPU/emulator/Instruction.java | 4 - .../scheCPU/emulator/ProcessorEmulator.java | 3 - .../scheCPU/high/HighProgramCompiler.java | 89 ++------- .../scheCPU/util/StaticValues.java | 1 - 6 files changed, 103 insertions(+), 171 deletions(-) diff --git a/src/main/java/de/emilschlampp/scheCPU/compile/Compiler.java b/src/main/java/de/emilschlampp/scheCPU/compile/Compiler.java index 8b9c5e0..dbce816 100644 --- a/src/main/java/de/emilschlampp/scheCPU/compile/Compiler.java +++ b/src/main/java/de/emilschlampp/scheCPU/compile/Compiler.java @@ -29,26 +29,26 @@ public byte[] compile() { for (String s : split) { debugLine++; s = splitComment(s); - if (s.replace(" ", "").isEmpty() || s.startsWith(";") || s.startsWith("#") || s.startsWith("//")) { + if(s.replace(" ", "").isEmpty() || s.startsWith(";") || s.startsWith("#") || s.startsWith("//")) { continue; } String[] cmd = s.split(" ", -1); - if (cmd.length == 0) { + if(cmd.length == 0) { continue; } if (cmd[0].equals("FUNC")) { - if (cmd.length == 2) { - if (isInt(cmd[1])) { - throw new RuntimeException("Invalid func name: " + cmd[1] + " Line: " + (fnC + 1)); + if(cmd.length == 2) { + if(isInt(cmd[1])) { + throw new RuntimeException("Invalid func name: "+cmd[1]+" Line: "+(fnC+1)); } functionsInstructionMap.put(cmd[1], fnC); } - } else if (cmd[0].equals("LOADSTRM")) { + } else if(cmd[0].equals("LOADSTRM")) { String val = ""; for (int i = 2; i < cmd.length; i++) { - val += (" " + cmd[i]); + val += (" "+ cmd[i]); } if (!val.isEmpty()) { val = val.substring(1); @@ -57,10 +57,10 @@ public byte[] compile() { for (char c : val.toCharArray()) { fnC++; } - } else if (cmd[0].equals("LOADSTRMC")) { + } else if(cmd[0].equals("LOADSTRMC")) { String val = ""; for (int i = 2; i < cmd.length; i++) { - val += (" " + cmd[i]); + val += (" "+ cmd[i]); } if (!val.isEmpty()) { val = val.substring(1); @@ -80,121 +80,121 @@ public byte[] compile() { for (String s : split) { debugLine++; s = splitComment(s); - if (s.replace(" ", "").isEmpty() || s.startsWith(";") || s.startsWith("#") || s.startsWith("//")) { + if(s.replace(" ", "").isEmpty() || s.startsWith(";") || s.startsWith("#") || s.startsWith("//")) { continue; } String[] cmd = s.split(" ", -1); - if (cmd.length == 0) { + if(cmd.length == 0) { continue; } cmd[0] = cmd[0].toUpperCase(Locale.ROOT); if (cmd[0].equals("JMP")) { //Jump to Adress, or use function defined by FUNC - if (cmd.length == 2) { + if(cmd.length == 2) { int address; - if (isInt(cmd[1])) { + if(isInt(cmd[1])) { address = parseInt(cmd[1]); } else { address = functionsInstructionMap.getOrDefault(cmd[1], -1); } - if (address == -1) { - throw new RuntimeException("invalid address: " + cmd[1]); + if(address == -1) { + throw new RuntimeException("invalid address: "+cmd[1]); } outputStream.write(JMP_OPCODE); FolderIOUtil.writeInt(outputStream, address); } else { throw new RuntimeException("jmp args"); } - } else if (cmd[0].equals("LOAD")) { //Load value to Register - if (cmd.length == 3) { + } else if(cmd[0].equals("LOAD")) { //Load value to Register + if(cmd.length == 3) { outputStream.write(LOAD_OPCODE); outputStream.write(toRegID(cmd[1])); FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //Value } else { throw new RuntimeException("err"); } - } else if (cmd[0].equals("LOADMEM")) { //Load memory value to register - if (cmd.length == 3) { + } else if(cmd[0].equals("LOADMEM")){ //Load memory value to register + if(cmd.length == 3) { outputStream.write(LOADMEM_OPCODE); outputStream.write(toRegID(cmd[1])); //Register FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //memadress } else { throw new RuntimeException("err"); } - } else if (cmd[0].equals("STORE")) { //Store register value to memory - if (cmd.length == 3) { + } else if(cmd[0].equals("STORE")){ //Store register value to memory + if(cmd.length == 3) { outputStream.write(STORE_OPCODE); outputStream.write(toRegID(cmd[1])); //Register FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //memadress } else { throw new RuntimeException("err"); } - } else if (cmd[0].equals("STOREREG")) { //Store memory value to register - if (cmd.length == 3) { + } else if(cmd[0].equals("STOREREG")){ //Store memory value to register + if(cmd.length == 3) { outputStream.write(STOREREG_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //memadress outputStream.write(toRegID(cmd[2])); //Register } else { throw new RuntimeException("err"); } - } else if (cmd[0].equals("CMPM")) { //Compare mem Value with Register - if (cmd.length == 3) { + } else if(cmd[0].equals("CMPM")){ //Compare mem Value with Register + if(cmd.length == 3) { outputStream.write(CMPM_OPCODE); outputStream.write(toRegID(cmd[1])); //Register FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //memadress } else { throw new RuntimeException("err"); } - } else if (cmd[0].equals("CMPMC")) { //Current mem address load by STORE - if (cmd.length == 2) { + } else if(cmd[0].equals("CMPMC")){ //Current mem address load by STORE + if(cmd.length == 2) { outputStream.write(CMPMC_OPCODE); outputStream.write(toRegID(cmd[1])); //Register } else { throw new RuntimeException("err"); } - } else if (cmd[0].equals("CMPR")) { //Current mem address load by STORE - if (cmd.length == 3) { + } else if(cmd[0].equals("CMPR")){ //Current mem address load by STORE + if(cmd.length == 3) { outputStream.write(CMPR_OPCODE); outputStream.write(toRegID(cmd[1])); //Register 1 outputStream.write(toRegID(cmd[2])); //Register 2 } else { throw new RuntimeException("err"); } - } else if (cmd[0].equals("ADDR")) { - if (cmd.length == 3) { + } else if(cmd[0].equals("ADDR")){ + if(cmd.length == 3) { outputStream.write(ADDR_OPCODE); outputStream.write(toRegID(cmd[1])); //Register 1 outputStream.write(toRegID(cmd[2])); //Register 2 } else { throw new RuntimeException("err"); } - } else if (cmd[0].equals("COPYR")) { - if (cmd.length == 3) { + } else if(cmd[0].equals("COPYR")){ + if(cmd.length == 3) { outputStream.write(COPYR_OPCODE); outputStream.write(toRegID(cmd[1])); //Register 1 outputStream.write(toRegID(cmd[2])); //Register 2 } else { throw new RuntimeException("err"); } - } else if (cmd[0].equals("BJMP")) { + } else if(cmd[0].equals("BJMP")) { outputStream.write(BJMP_OPCODE); - } else if (cmd[0].equals("CBJMP")) { + } else if(cmd[0].equals("CBJMP")) { outputStream.write(CBJMP_OPCODE); - } else if (cmd[0].equals("CNBJMP")) { + } else if(cmd[0].equals("CNBJMP")) { outputStream.write(CNBJMP_OPCODE); - } else if (cmd[0].equals("CZBJMP")) { + } else if(cmd[0].equals("CZBJMP")) { outputStream.write(CZBJMP_OPCODE); - } else if (cmd[0].equals("CMPMEM")) { //Compare mem address values - if (cmd.length == 3) { + } else if(cmd[0].equals("CMPMEM")){ //Compare mem address values + if(cmd.length == 3) { outputStream.write(CMPMEM_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //ADDR1 FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //ADDR2 } else { throw new RuntimeException("err"); } - } else if (cmd[0].equals("STOREMEM")) { //Store Value in Memory - if (cmd.length == 3) { + } else if(cmd[0].equals("STOREMEM")){ //Store Value in Memory + if(cmd.length == 3) { outputStream.write(STOREMEM_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //memadress FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //value @@ -202,14 +202,14 @@ public byte[] compile() { throw new RuntimeException("err"); } } else if (cmd[0].equals("CJMP")) { //Reads bool from boolstore, if it's positive JUMP - if (cmd.length == 2) { + if(cmd.length == 2) { int address; - if (isInt(cmd[1])) { + if(isInt(cmd[1])) { address = parseInt(cmd[1]); } else { address = functionsInstructionMap.getOrDefault(cmd[1], -1); } - if (address == -1) { + if(address == -1) { throw new RuntimeException("err"); } outputStream.write(CJMP_OPCODE); @@ -217,15 +217,15 @@ public byte[] compile() { } else { throw new RuntimeException("err"); } - } else if (cmd[0].equals("CNJMP")) { //Reads bool from boolstore, if it's positive JUMP - if (cmd.length == 2) { + } else if (cmd[0].equals("CNJMP")) { //Reads bool from boolstore, if it's positive JUMP + if(cmd.length == 2) { int address; - if (isInt(cmd[1])) { + if(isInt(cmd[1])) { address = parseInt(cmd[1]); } else { address = functionsInstructionMap.getOrDefault(cmd[1], -1); } - if (address == -1) { + if(address == -1) { throw new RuntimeException("err"); } outputStream.write(CNJMP_OPCODE); @@ -234,14 +234,14 @@ public byte[] compile() { throw new RuntimeException("err"); } } else if (cmd[0].equals("CZJMP")) { //Reads bool from boolstore, if it's positive JUMP - if (cmd.length == 2) { + if(cmd.length == 2) { int address; - if (isInt(cmd[1])) { + if(isInt(cmd[1])) { address = parseInt(cmd[1]); } else { address = functionsInstructionMap.getOrDefault(cmd[1], -1); } - if (address == -1) { + if(address == -1) { throw new RuntimeException("address invalid"); } outputStream.write(CZJMP_OPCODE); @@ -249,103 +249,99 @@ public byte[] compile() { } else { throw new RuntimeException("czjmp args"); } - } else if (cmd[0].equals("ADD")) { - if (cmd.length == 3) { + } else if(cmd[0].equals("ADD")) { + if(cmd.length == 3) { outputStream.write(ADD_OPCODE); outputStream.write(toRegID(cmd[1])); //Register FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //Value } else { throw new RuntimeException("add args"); } - } else if (cmd[0].equals("ADDM")) { + } else if(cmd[0].equals("ADDM")) { outputStream.write(ADDM_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Memory Address FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //Value - } else if (cmd[0].equals("SUB")) { - if (cmd.length == 3) { + } else if(cmd[0].equals("SUB")) { + if(cmd.length == 3) { outputStream.write(SUB_OPCODE); outputStream.write(toRegID(cmd[1])); //Register FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //Value } else { throw new RuntimeException("sub args"); } - } else if (cmd[0].equals("SUBM")) { + } else if(cmd[0].equals("SUBM")) { outputStream.write(SUBM_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Memory Address FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //VAl - } else if (cmd[0].equals("MUL")) { - if (cmd.length == 3) { + } else if(cmd[0].equals("MUL")) { + if(cmd.length == 3) { outputStream.write(MUL_OPCODE); outputStream.write(toRegID(cmd[1])); //Register FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //VAl } else { throw new RuntimeException("mul args"); } - } else if (cmd[0].equals("MJMP")) { + } else if(cmd[0].equals("MJMP")) { outputStream.write(MJMP_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Memory Address - } else if (cmd[0].equals("CMJMP")) { + } else if(cmd[0].equals("CMJMP")) { outputStream.write(CMJMP_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Memory Address - } else if (cmd[0].equals("CZMJMP")) { + } else if(cmd[0].equals("CZMJMP")) { outputStream.write(CZMJMP_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Memory Address - } else if (cmd[0].equals("CNMJMP")) { + } else if(cmd[0].equals("CNMJMP")) { outputStream.write(CNMJMP_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Memory Address - } else if (cmd[0].equals("MULM")) { + } else if(cmd[0].equals("MULM")) { outputStream.write(MULM_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Memory FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //Value - } else if (cmd[0].equals("DIV")) { - if (cmd.length == 3) { + } else if(cmd[0].equals("DIV")) { + if(cmd.length == 3) { outputStream.write(DIV_OPCODE); outputStream.write(toRegID(cmd[1])); //Register FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //VAl } else { throw new RuntimeException("div args"); } - } else if (cmd[0].equals("DIVM")) { + } else if(cmd[0].equals("DIVM")) { outputStream.write(DIVM_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Memory FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //Value - } else if (cmd[0].equals("OUTW")) { //Out from Value + } else if(cmd[0].equals("OUTW")) { //Out from Value outputStream.write(OUTW_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Port FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //Value - } else if (cmd[0].equals("OUTWM")) { //Out from Memory + } else if(cmd[0].equals("OUTWM")) { //Out from Memory outputStream.write(OUTWM_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Port FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //Memory Address - } else if (cmd[0].equals("OUTWDM")) { //Out from Memory + } else if(cmd[0].equals("OUTWDM")) { //Out from Memory outputStream.write(OUTWDM_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Port FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //Memory Address - } else if (cmd[0].equals("OUTWR")) { //Out from Register + } else if(cmd[0].equals("OUTWR")) { //Out from Register outputStream.write(OUTWR_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Port outputStream.write(toRegID(cmd[2])); - } else if (cmd[0].equals("INWM")) { //IN to Memory + } else if(cmd[0].equals("INWM")) { //IN to Memory outputStream.write(INWM_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Port FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //Memory Address - } else if (cmd[0].equals("INWDM")) { //IN to Memory + } else if(cmd[0].equals("INWDM")) { //IN to Memory outputStream.write(INWDM_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Port FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //Memory Address - } else if (cmd[0].equals("INWR")) { //IN to Register + } else if(cmd[0].equals("INWR")) { //IN to Register outputStream.write(INWR_OPCODE); FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Port outputStream.write(toRegID(cmd[2])); - } else if (cmd[0].equals("ADDMM")) { - outputStream.write(ADDMM_OPCODE); - FolderIOUtil.writeInt(outputStream, parseInt(cmd[1])); //Addr1 - FolderIOUtil.writeInt(outputStream, parseInt(cmd[2])); //Addr2 - } else if (cmd[0].equals("LOADSTRM")) { + } else if(cmd[0].equals("LOADSTRM")) { int address = parseInt(cmd[1]); String val = ""; for (int i = 2; i < cmd.length; i++) { - val += (" " + cmd[i]); + val += (" "+ cmd[i]); } if (!val.isEmpty()) { val = val.substring(1); @@ -354,15 +350,15 @@ public byte[] compile() { int off = 0; for (char c : val.toCharArray()) { outputStream.write(STOREMEM_OPCODE); - FolderIOUtil.writeInt(outputStream, address + off); //memadress + FolderIOUtil.writeInt(outputStream, address+off); //memadress FolderIOUtil.writeInt(outputStream, c); //value off++; } - } else if (cmd[0].equals("LOADSTRMC")) { + } else if(cmd[0].equals("LOADSTRMC")) { int address = parseInt(cmd[1]); String val = ""; for (int i = 2; i < cmd.length; i++) { - val += (" " + cmd[i]); + val += (" "+ cmd[i]); } if (!val.isEmpty()) { val = val.substring(1); @@ -371,23 +367,23 @@ public byte[] compile() { char[] ch = val.toCharArray(); int off = 0; outputStream.write(STOREMEM_OPCODE); - FolderIOUtil.writeInt(outputStream, address + off); //memadress + FolderIOUtil.writeInt(outputStream, address+off); //memadress FolderIOUtil.writeInt(outputStream, ch.length); //value off++; for (char c : ch) { outputStream.write(STOREMEM_OPCODE); - FolderIOUtil.writeInt(outputStream, address + off); //memadress + FolderIOUtil.writeInt(outputStream, address+off); //memadress FolderIOUtil.writeInt(outputStream, c); //value off++; } } else { - if (!cmd[0].equals("FUNC")) { + if(!cmd[0].equals("FUNC")) { throw new RuntimeException("Invalid " + cmd[0] + " line: " + debugLine); } } } } catch (Throwable throwable) { - throw new RuntimeException("check line " + debugLine, throwable); + throw new RuntimeException("check line "+debugLine, throwable); } return outputStream.toByteArray(); @@ -403,7 +399,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); @@ -426,7 +422,7 @@ private int toRegID(String v) { } private String splitComment(String orig) { - if (orig.isEmpty()) { + if(orig.isEmpty()) { return ""; } String l = orig; diff --git a/src/main/java/de/emilschlampp/scheCPU/dissassembler/Decompiler.java b/src/main/java/de/emilschlampp/scheCPU/dissassembler/Decompiler.java index 80de255..b2fa30b 100644 --- a/src/main/java/de/emilschlampp/scheCPU/dissassembler/Decompiler.java +++ b/src/main/java/de/emilschlampp/scheCPU/dissassembler/Decompiler.java @@ -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; diff --git a/src/main/java/de/emilschlampp/scheCPU/emulator/Instruction.java b/src/main/java/de/emilschlampp/scheCPU/emulator/Instruction.java index f03e1d8..bd73c09 100644 --- a/src/main/java/de/emilschlampp/scheCPU/emulator/Instruction.java +++ b/src/main/java/de/emilschlampp/scheCPU/emulator/Instruction.java @@ -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; } diff --git a/src/main/java/de/emilschlampp/scheCPU/emulator/ProcessorEmulator.java b/src/main/java/de/emilschlampp/scheCPU/emulator/ProcessorEmulator.java index a7aadf6..7c0598b 100644 --- a/src/main/java/de/emilschlampp/scheCPU/emulator/ProcessorEmulator.java +++ b/src/main/java/de/emilschlampp/scheCPU/emulator/ProcessorEmulator.java @@ -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()); } diff --git a/src/main/java/de/emilschlampp/scheCPU/high/HighProgramCompiler.java b/src/main/java/de/emilschlampp/scheCPU/high/HighProgramCompiler.java index d6082ee..0654d59 100644 --- a/src/main/java/de/emilschlampp/scheCPU/high/HighProgramCompiler.java +++ b/src/main/java/de/emilschlampp/scheCPU/high/HighProgramCompiler.java @@ -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!"); @@ -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]; @@ -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!"); } @@ -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!"); } @@ -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]; @@ -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); @@ -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); diff --git a/src/main/java/de/emilschlampp/scheCPU/util/StaticValues.java b/src/main/java/de/emilschlampp/scheCPU/util/StaticValues.java index 8912808..0e54c05 100644 --- a/src/main/java/de/emilschlampp/scheCPU/util/StaticValues.java +++ b/src/main/java/de/emilschlampp/scheCPU/util/StaticValues.java @@ -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