Merge pull request #412 from mipt-npm/commandertvis/asm-debug
Add debug property for dumping classes generated with ASM
This commit is contained in:
commit
b0bbdc122e
@ -14,9 +14,11 @@ import space.kscience.kmath.expressions.Expression
|
||||
import space.kscience.kmath.expressions.MST
|
||||
import java.lang.invoke.MethodHandles
|
||||
import java.lang.invoke.MethodType
|
||||
import java.nio.file.Paths
|
||||
import java.util.stream.Collectors.toMap
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.io.path.writeBytes
|
||||
|
||||
/**
|
||||
* ASM Builder is a structure that abstracts building a class designated to unwrap [MST] to plain Java expression.
|
||||
@ -194,15 +196,18 @@ internal class AsmBuilder<T>(
|
||||
visitEnd()
|
||||
}
|
||||
|
||||
val cls = classLoader.defineClass(className, classWriter.toByteArray())
|
||||
// java.io.File("dump.class").writeBytes(classWriter.toByteArray())
|
||||
val binary = classWriter.toByteArray()
|
||||
val cls = classLoader.defineClass(className, binary)
|
||||
|
||||
if (System.getProperty("space.kscience.communicator.prettyapi.dump.generated.classes") == "1")
|
||||
Paths.get("$className.class").writeBytes(binary)
|
||||
|
||||
val l = MethodHandles.publicLookup()
|
||||
|
||||
if (hasConstants)
|
||||
l.findConstructor(cls, MethodType.methodType(Void.TYPE, Array<Any>::class.java))
|
||||
.invoke(constants.toTypedArray()) as Expression<T>
|
||||
(if (hasConstants)
|
||||
l.findConstructor(cls, MethodType.methodType(Void.TYPE, Array<Any>::class.java))(constants.toTypedArray())
|
||||
else
|
||||
l.findConstructor(cls, MethodType.methodType(Void.TYPE)).invoke() as Expression<T>
|
||||
l.findConstructor(cls, MethodType.methodType(Void.TYPE))()) as Expression<T>
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user