Provide dynamic operations currying for Algebra<T> instead of eager calls and add JS code generation support #162
@ -204,18 +204,13 @@ internal class AsmBuilder<T>(
|
|||||||
*/
|
*/
|
||||||
fun loadObjectConstant(value: Any, type: Type = tType): Unit = invokeMethodVisitor.run {
|
fun loadObjectConstant(value: Any, type: Type = tType): Unit = invokeMethodVisitor.run {
|
||||||
val idx = if (value in constants) constants.indexOf(value) else constants.also { it += value }.lastIndex
|
val idx = if (value in constants) constants.indexOf(value) else constants.also { it += value }.lastIndex
|
||||||
loadThis()
|
invokeMethodVisitor.load(0, classType)
|
||||||
getfield(classType.internalName, "constants", OBJECT_ARRAY_TYPE.descriptor)
|
getfield(classType.internalName, "constants", OBJECT_ARRAY_TYPE.descriptor)
|
||||||
iconst(idx)
|
iconst(idx)
|
||||||
visitInsn(AALOAD)
|
visitInsn(AALOAD)
|
||||||
if (type != OBJECT_TYPE) checkcast(type)
|
if (type != OBJECT_TYPE) checkcast(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads `this` variable.
|
|
||||||
*/
|
|
||||||
private fun loadThis(): Unit = invokeMethodVisitor.load(0, classType)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Either loads a numeric constant [value] from the class's constants field or boxes a primitive
|
* Either loads a numeric constant [value] from the class's constants field or boxes a primitive
|
||||||
* constant from the constant pool.
|
* constant from the constant pool.
|
||||||
@ -234,27 +229,21 @@ internal class AsmBuilder<T>(
|
|||||||
SHORT_TYPE -> invokeMethodVisitor.iconst(value.toInt())
|
SHORT_TYPE -> invokeMethodVisitor.iconst(value.toInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
box(primitive)
|
val r = PRIMITIVES_TO_BOXED.getValue(primitive)
|
||||||
|
|
||||||
|
invokeMethodVisitor.invokestatic(
|
||||||
|
r.internalName,
|
||||||
|
"valueOf",
|
||||||
|
getMethodDescriptor(r, primitive),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
loadObjectConstant(value, boxed)
|
loadObjectConstant(value, boxed)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Boxes the current value and pushes it.
|
|
||||||
*/
|
|
||||||
private fun box(primitive: Type) {
|
|
||||||
val r = PRIMITIVES_TO_BOXED.getValue(primitive)
|
|
||||||
|
|
||||||
invokeMethodVisitor.invokestatic(
|
|
||||||
r.internalName,
|
|
||||||
"valueOf",
|
|
||||||
getMethodDescriptor(r, primitive),
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a variable [name] from arguments [Map] parameter of [Expression.invoke].
|
* Loads a variable [name] from arguments [Map] parameter of [Expression.invoke].
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user