From e0b3c966b6114f0d5776076e71b17157bf236e46 Mon Sep 17 00:00:00 2001 From: James Roseborough Date: Tue, 27 Apr 2010 14:33:55 +0000 Subject: [PATCH] Improve bytecode generation. --- src/jse/org/luaj/vm2/luajc/Slots.java | 88 +++++++++++++++++++-------- 1 file changed, 63 insertions(+), 25 deletions(-) diff --git a/src/jse/org/luaj/vm2/luajc/Slots.java b/src/jse/org/luaj/vm2/luajc/Slots.java index f1674464..2459f9eb 100644 --- a/src/jse/org/luaj/vm2/luajc/Slots.java +++ b/src/jse/org/luaj/vm2/luajc/Slots.java @@ -48,6 +48,7 @@ public class Slots { private static final byte BIT_INVALID = 0x20; // slot becomes invlaid at this pc private static final byte BIT_NIL = 0x40; // slot initialized to nil at this point + final Prototype p; final int n,m; public final byte[][] slots; public final boolean[] branchdest; @@ -68,22 +69,21 @@ public class Slots { return (slots[0][slot] & (BIT_INVALID)) == 0; } - public Slots(Prototype p) { + public Slots(Prototype prototype) { + p = prototype; n = p.code.length; m = p.maxstacksize; slots = new byte[n+1][m]; branchdest = new boolean[n+1]; - markassignments( p ); - markuninitialized( p ); - markupvalues( p ); - markforloopupvalues( p ); + markassignments(); + while ( propogatebranches() ) + ; + markuninitialized(); + markupvalues(); + markforloopupvalues(); } - - public String tojstring() { - return tojstring(null); - } - - private void markassignments( Prototype p ) { + + private void markassignments() { // mark initial assignments and references int j=0; for ( ; j=0; ) { int i = p.code[pc1]; if ( Lua.GET_OPCODE(i) == Lua.OP_TFORLOOP ) { @@ -357,8 +394,9 @@ public class Slots { private void promoteUpvalueBefore(int index, int j) { int undef = prevUndefined(index,j); - int branch = firstBranchAfter(undef,index,j); - int assign = lastAssignBefore(branch,undef,j); +// int branch = firstBranchAfter(undef,index,j); +// int assign = lastAssignBefore(branch,undef,j); + int assign = firstAssignAfter(undef,index,j); slots[assign][j] |= BIT_UP_CREATE; while ( index>assign) promoteUpvalue( slots[index--], j ); @@ -399,6 +437,13 @@ public class Slots { return index; } + private int firstAssignAfter(int index, int limit, int j) { + for ( int i=index; ++i