Provide dynamic operations currying for Algebra<T> instead of eager calls and add JS code generation support #162
@ -7,6 +7,8 @@ import org.objectweb.asm.*
|
|||||||
import org.objectweb.asm.Opcodes.*
|
import org.objectweb.asm.Opcodes.*
|
||||||
import org.objectweb.asm.Type.*
|
import org.objectweb.asm.Type.*
|
||||||
import org.objectweb.asm.commons.InstructionAdapter
|
import org.objectweb.asm.commons.InstructionAdapter
|
||||||
|
import java.lang.invoke.MethodHandles
|
||||||
|
import java.lang.invoke.MethodType
|
||||||
import java.util.stream.Collectors.toMap
|
import java.util.stream.Collectors.toMap
|
||||||
import kotlin.contracts.InvocationKind
|
import kotlin.contracts.InvocationKind
|
||||||
import kotlin.contracts.contract
|
import kotlin.contracts.contract
|
||||||
@ -187,13 +189,14 @@ internal class AsmBuilder<T>(
|
|||||||
visitEnd()
|
visitEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
// java.io.File("dump.class").writeBytes(classWriter.toByteArray())
|
val cls = classLoader.defineClass(className, classWriter.toByteArray())
|
||||||
|
val l = MethodHandles.publicLookup()
|
||||||
|
|
||||||
classLoader
|
if (hasConstants)
|
||||||
.defineClass(className, classWriter.toByteArray())
|
l.findConstructor(cls, MethodType.methodType(Void.TYPE, Array<Any>::class.java))
|
||||||
.constructors
|
.invoke(constants.toTypedArray()) as Expression<T>
|
||||||
.first()
|
else
|
||||||
.newInstance(*(constants.toTypedArray().wrapToArrayIf { hasConstants })) as Expression<T>
|
l.findConstructor(cls, MethodType.methodType(Void.TYPE)).invoke() as Expression<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -248,7 +251,7 @@ internal class AsmBuilder<T>(
|
|||||||
r.internalName,
|
r.internalName,
|
||||||
"valueOf",
|
"valueOf",
|
||||||
getMethodDescriptor(r, primitive),
|
getMethodDescriptor(r, primitive),
|
||||||
false
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user