Add a move op
diff --git a/src/main/java/com/google/dexmaker/Code.java b/src/main/java/com/google/dexmaker/Code.java
index 50345c3..0d232bd 100644
--- a/src/main/java/com/google/dexmaker/Code.java
+++ b/src/main/java/com/google/dexmaker/Code.java
@@ -429,7 +429,7 @@
currentLabel.marked = true;
}
- // instructions: constants
+ // instructions: locals
public <T> void loadConstant(Local<T> target, T value) {
Rop rop = value == null
@@ -445,6 +445,14 @@
}
}
+ /**
+ * Copies the value in {@code source} to {@code target}.
+ */
+ public <T> void move(Local<T> target, Local<T> source) {
+ addInstruction(new PlainInsn(Rops.opMove(source.type.ropType),
+ sourcePosition, target.spec(), source.spec()));
+ }
+
// instructions: unary and binary
public <T> void op(UnaryOp op, Local<T> target, Local<T> source) {
@@ -480,7 +488,10 @@
}
/**
- * Compare floats or doubles.
+ * Compare floats or doubles. This stores -1 in {@code target} if {@code
+ * a < b}, 0 in {@code target} if {@code a == b} and 1 in target if {@code
+ * a > b}. This stores {@code nanValue} in {@code target} if either value
+ * is {@code NaN}.
*/
public <T extends Number> void compareFloatingPoint(
Local<Integer> target, Local<T> a, Local<T> b, int nanValue) {
@@ -497,7 +508,9 @@
}
/**
- * Compare longs.
+ * Compare longs. This stores -1 in {@code target} if {@code
+ * a < b}, 0 in {@code target} if {@code a == b} and 1 in target if {@code
+ * a > b}.
*/
public void compareLongs(Local<Integer> target, Local<Long> a, Local<Long> b) {
addInstruction(new PlainInsn(Rops.CMPL_LONG, sourcePosition, target.spec(),
diff --git a/src/test/java/com/google/dexmaker/DexMakerTest.java b/src/test/java/com/google/dexmaker/DexMakerTest.java
index 97aeb56..cfd994c 100644
--- a/src/test/java/com/google/dexmaker/DexMakerTest.java
+++ b/src/test/java/com/google/dexmaker/DexMakerTest.java
@@ -1534,7 +1534,7 @@
assertEquals(5, intArrayLength.invoke(null, new Object[] { new int[5] }));
Method longArrayLength = arrayLengthMethod(LONG_ARRAY);
- assertEquals(0, longArrayLength.invoke(null, new Object[] { new long[0] }));
+ assertEquals(0, longArrayLength.invoke(null, new Object[]{new long[0]}));
assertEquals(5, longArrayLength.invoke(null, new Object[] { new long[5] }));
Method objectArrayLength = arrayLengthMethod(OBJECT_ARRAY);
@@ -1712,6 +1712,26 @@
method.invoke(instance); // will take 100ms
}
+ public void testMoveInt() throws Exception {
+ /*
+ * public static int call(int a) {
+ * int b = a;
+ * int c = a + b;
+ * return c;
+ * }
+ */
+ MethodId<?, Integer> methodId = GENERATED.getMethod(TypeId.INT, "call", TypeId.INT);
+ Code code = dexMaker.declare(methodId, PUBLIC | STATIC);
+ Local<Integer> a = code.getParameter(0, TypeId.INT);
+ Local<Integer> b = code.newLocal(TypeId.INT);
+ Local<Integer> c = code.newLocal(TypeId.INT);
+ code.move(b, a);
+ code.op(BinaryOp.ADD, c, a, b);
+ code.returnValue(c);
+
+ assertEquals(6, getMethod().invoke(null, 3));
+ }
+
// TODO: cast primitive to non-primitive
// TODO: cast non-primitive to primitive
// TODO: cast byte to integer
@@ -1724,10 +1744,7 @@
// TODO: don't generate multiple times (?)
- // TODO: test array types
-
// TODO: test generating an interface
-
// TODO: declare native method or abstract method
// TODO: get a thrown exception 'e' into a local