Serpent Compiler:

+ Labels encoding bug
This commit is contained in:
romanman 2014-06-10 11:49:38 +01:00
parent 9ae78521a6
commit a47ecf6f90
2 changed files with 22 additions and 1 deletions

View File

@ -231,6 +231,7 @@ public class SerpentEditor extends JFrame {
}else{ }else{
asmResult = SerpentCompiler.compile(codeArea.getText()); asmResult = SerpentCompiler.compile(codeArea.getText());
machineCode = SerpentCompiler.compileAssemblyToMachine(asmResult); machineCode = SerpentCompiler.compileAssemblyToMachine(asmResult);
machineCode = SerpentCompiler.encodeMachineCodeForVMRun(machineCode, null);
} }
} catch (Throwable th) { } catch (Throwable th) {

View File

@ -135,8 +135,22 @@ public class SerpentCompiler {
} }
// encode ref for 5 bytes
for (int i = 0; i < lexaList.size(); ++i){
String lexa = lexaList.get(i);
if (!lexa.contains("REF_")) continue;
lexaList.add(i + 1, lexa);
lexaList.add(i + 2, lexa);
lexaList.add(i + 3, lexa);
lexaList.add(i + 4, lexa);
i += 4;
}
// calc label pos & remove labels // calc label pos & remove labels
HashMap<String, Integer> labels = new HashMap<String, Integer>(); HashMap<String, Integer> labels = new HashMap<String, Integer>();
for (int i = 0; i < lexaList.size(); ++i){ for (int i = 0; i < lexaList.size(); ++i){
String lexa = lexaList.get(i); String lexa = lexaList.get(i);
@ -145,7 +159,9 @@ public class SerpentCompiler {
String label = lexaList.remove(i); String label = lexaList.remove(i);
String labelNum = label.split("LABEL_")[1]; String labelNum = label.split("LABEL_")[1];
labels.put(labelNum, i); int labelPos = i;
labels.put(labelNum, labelPos);
--i; --i;
} }
@ -156,6 +172,10 @@ public class SerpentCompiler {
if (!lexa.contains("REF_")) continue; if (!lexa.contains("REF_")) continue;
String ref = lexaList.remove(i); String ref = lexaList.remove(i);
lexaList.remove(i);
lexaList.remove(i);
lexaList.remove(i);
lexaList.remove(i);
String labelNum = ref.split("REF_")[1]; String labelNum = ref.split("REF_")[1];
Integer pos = labels.get(labelNum); Integer pos = labels.get(labelNum);