diff options
Diffstat (limited to 'vaporize/library/Kettle.java')
-rw-r--r-- | vaporize/library/Kettle.java | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/vaporize/library/Kettle.java b/vaporize/library/Kettle.java index 2590d4b..340d53e 100644 --- a/vaporize/library/Kettle.java +++ b/vaporize/library/Kettle.java @@ -5,7 +5,8 @@ import java.util.ArrayList; /** * This class contains various generic methods for - * assembling common-use vaporm strings. + * assembling common-use vaporm strings and managing + * the original input program. * * Robert Martin cries */ @@ -17,20 +18,21 @@ class Kettle { this.vapor = vapor; } - protected String indexOriginal(Node n) { + protected String get(Node n) { /** * Given the source position of a Node, returns the original line. */ - return this.vapor.get(n.sourcePos.line-1); + return this.vapor.get(this.indexOf(n)); } - protected String functionParameters(VFunction prev, int in, + protected void replaceFunctionDeclare(VFunction prev, int in, int out, int local) { - return String.format("func %s [in %d, out %d, local %d]", - this.indexOriginal(prev).split(" ")[1], - in, - out, - local); + this.set(prev, + String.format("func %s [in %d, out %d, local %d]", + this.parseFuncName(this.get(prev)), + in, + out, + local)); } protected String spill() { @@ -40,4 +42,29 @@ class Kettle { protected String backup() { return null; } + + protected String dump() { + return String.join("\n", this.vapor); + } + + private int indexOf(Node n) { + return n.sourcePos.line-1; + } + + private void set(Node n, String s) { + /** + * Sets the position of Node n in the original + * file to String s. + */ + this.vapor.set(this.indexOf(n), s); + } + + private static String parseFuncName(String func) { + /** + * "func A_foo(this t.1)" -> "A_foo" + */ + int openParenIndex = func.indexOf('('); + return func.substring(5, openParenIndex); + } + } |