From: <ls...@us...> - 2010-03-28 19:12:47
|
Revision: 5740 http://jnode.svn.sourceforge.net/jnode/?rev=5740&view=rev Author: lsantha Date: 2010-03-28 19:12:41 +0000 (Sun, 28 Mar 2010) Log Message: ----------- Fixed a bug where expected item was not at the top of the item stack. Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/WordItem.java Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java 2010-03-28 19:03:38 UTC (rev 5739) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.java 2010-03-28 19:12:41 UTC (rev 5740) @@ -26,6 +26,7 @@ /** * @author Ewout Prangsma (ep...@us...) + * @author Levente S\u00e1ntha */ class ItemStack { @@ -129,6 +130,36 @@ return (stack[tos - 1] == item); } + /** + * Finds the position of the specified item on the stack starting from the top. + * + * @param item the item to find + * @return the position of the item or -1 if not found + */ + final int stackLocation(Item item) { + int ret = -1; + + int i = tos - 1; + while ((i >= 0) && (stack[i] != item)) + i--; + + if (i >= 0) + ret = tos - 1 - i; + + return ret; + } + + /** + * Exchanges the item at the specified position with the top item. + * + * @param pos the position of the item + */ + final void makeTop(int pos) { + Item tmp = stack[tos - 1]; + stack[tos - 1] = stack[tos - 1 - pos]; + stack[tos - 1 - pos] = tmp; + } + final void pop(EmitterContext ec) { if (tos <= 0) { throw new Error("Stack is empty"); Modified: trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/WordItem.java =================================================================== --- trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/WordItem.java 2010-03-28 19:03:38 UTC (rev 5739) +++ trunk/core/src/core/org/jnode/vm/x86/compiler/l1a/WordItem.java 2010-03-28 19:12:41 UTC (rev 5740) @@ -27,6 +27,7 @@ import org.jnode.assembler.x86.X86Register.GPR64; import org.jnode.vm.JvmType; import org.jnode.vm.Vm; +import org.jnode.vm.bytecode.StackException; import org.jnode.vm.x86.compiler.X86CompilerHelper; /** @@ -186,7 +187,22 @@ break; case Kind.STACK: - // TODO: make sure this is on top os stack + // TODO: make sure 'this' is on top of stack + // TODO: implemen it for 64 bits + if (!stack.operandStack.isTos(this)) { + + int stack_loc = stack.operandStack.stackLocation(this); + if (stack_loc < 0) + throw new StackException("Item not found on stack"); + + stack.operandStack.makeTop(stack_loc); + + //todo test it + os.writeMOV(org.jnode.vm.x86.compiler.X86CompilerConstants.BITS32, reg, helper.SP, helper.SLOTSIZE); + os.writeXCHG(helper.SP, org.jnode.vm.x86.compiler.X86CompilerConstants.BITS32 * stack_loc, reg); + os.writeMOV(org.jnode.vm.x86.compiler.X86CompilerConstants.BITS32, helper.SP, helper.SLOTSIZE, reg); + } + if (VirtualStack.checkOperandStack) { stack.operandStack.pop(this); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |