From a47ecf6f902311d3013d3e5eb1b98159b917fd11 Mon Sep 17 00:00:00 2001 From: romanman Date: Tue, 10 Jun 2014 11:49:38 +0100 Subject: [PATCH] Serpent Compiler: + Labels encoding bug --- .../java/org/ethereum/gui/SerpentEditor.java | 1 + .../org/ethereum/serpent/SerpentCompiler.java | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/SerpentEditor.java b/ethereumj-core/src/main/java/org/ethereum/gui/SerpentEditor.java index 3b99a2ee..e84e58af 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/SerpentEditor.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/SerpentEditor.java @@ -231,6 +231,7 @@ public class SerpentEditor extends JFrame { }else{ asmResult = SerpentCompiler.compile(codeArea.getText()); machineCode = SerpentCompiler.compileAssemblyToMachine(asmResult); + machineCode = SerpentCompiler.encodeMachineCodeForVMRun(machineCode, null); } } catch (Throwable th) { diff --git a/ethereumj-core/src/main/java/org/ethereum/serpent/SerpentCompiler.java b/ethereumj-core/src/main/java/org/ethereum/serpent/SerpentCompiler.java index 65785cf6..c4c9791c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/serpent/SerpentCompiler.java +++ b/ethereumj-core/src/main/java/org/ethereum/serpent/SerpentCompiler.java @@ -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 HashMap labels = new HashMap(); + for (int i = 0; i < lexaList.size(); ++i){ String lexa = lexaList.get(i); @@ -145,7 +159,9 @@ public class SerpentCompiler { String label = lexaList.remove(i); String labelNum = label.split("LABEL_")[1]; - labels.put(labelNum, i); + int labelPos = i; + + labels.put(labelNum, labelPos); --i; } @@ -156,6 +172,10 @@ public class SerpentCompiler { if (!lexa.contains("REF_")) continue; String ref = lexaList.remove(i); + lexaList.remove(i); + lexaList.remove(i); + lexaList.remove(i); + lexaList.remove(i); String labelNum = ref.split("REF_")[1]; Integer pos = labels.get(labelNum);