Skip to content

Commit

Permalink
✅ Pass test
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed May 14, 2024
1 parent af827cf commit b713228
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {
}

tasks.test {
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
useJUnitPlatform()
}
kotlin {
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/vm/instruction/IfInstruction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class IfNe(pc: Int, code: CodeItem) : Instruction._22t(pc, code) {
}
return pc + insnLength
}

override fun toString(): String {
return "IfNe v$vA != v$vB, $offset"
}
}

class IfLt(pc: Int, code: CodeItem) : Instruction._22t(pc, code) {
Expand Down Expand Up @@ -184,6 +188,10 @@ class IfEqz(pc: Int, code: CodeItem) : Instruction._21t(pc, code) {
}
}

is RegisterValue.ArrayRef -> {
return pc + insnLength // Always false
}

else -> {
memory.exception = ExceptionValue("IfEqz: Not an integer or object reference")
return pc + insnLength
Expand Down Expand Up @@ -215,6 +223,10 @@ class IfNez(pc: Int, code: CodeItem) : Instruction._21t(pc, code) {
}
}

is RegisterValue.ArrayRef -> {
return pc + offset
}

else -> {
memory.exception = ExceptionValue("IfNez: Not an integer or object reference")
return pc + insnLength
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/vm/instruction/InstanceInstruction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import com.yhs0602.vm.instance.Instance
class NewInstance(pc: Int, val code: CodeItem) : Instruction._21c(pc, code) {
override fun execute(pc: Int, memory: Memory, environment: Environment, depth: Int): Int {
val typeId = environment.getTypeId(code, KindBBBB)
typeIdString = typeId.descriptor
val parsedClass = environment.getClassRepresentation(typeId, depth)
memory.registers[vAA] = environment.createInstance(parsedClass, code, depth)
return pc + insnLength
}
private var typeIdString: String = ""

override fun toString(): String {
return "NewInstance v$vAA <- new $KindBBBB"
return "NewInstance v$vAA <- new $KindBBBB($typeIdString)"
}
}

Expand Down
10 changes: 1 addition & 9 deletions src/test/kotlin/SimpleOperationTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import com.yhs0602.dex.DexFile
import com.yhs0602.dex.TypeId
import com.yhs0602.vm.Environment
import com.yhs0602.vm.GeneralMockedClass
import com.yhs0602.vm.RegisterValue
import com.yhs0602.vm.executeMethod
import com.yhs0602.vm.instance.MockedInstance
import java.io.PrintStream
import java.nio.file.Paths
import kotlin.jvm.internal.Intrinsics
Expand Down Expand Up @@ -38,13 +36,7 @@ class SimpleOperationTest {
it.methodId.name == methodName
} ?: error("No method found")
val codeItem = method.codeItem ?: error("No code found")
val args = Array(codeItem.insSize.toInt()) {
RegisterValue.ObjectRef(
TypeId("com/example/sample/TargetMethods;"), MockedInstance(
Object::class.java
)
) // To simply pass anything
}
val args = arrayOf<RegisterValue>()
val mockedClassesList = listOf(
GeneralMockedClass(StringBuilder::class.java),
GeneralMockedClass(PrintStream::class.java),
Expand Down

0 comments on commit b713228

Please sign in to comment.