Dear devs,
I upgraded inline-java [1] to use GHC 9.10.2 recently. inline-java has a GHC plugin responsible for embedding JVM bytecode in Haskell modules. This message is to consult on the most appropriate way to do it.
The byte code is placed in a C literal array of bytes, and the C code is added in mg_foreign together with C constructor functions that run when loading the module to add the bytecode to a global bytecode table [2]. The global bytecode table is then fed to the JVM when initializing inline-java.
The GHC API in 9.10.2 requires creating a CStub which does have a field to indicate constructor functions [3], but I wouldn't know how to create the CLabels it needs. So instead, I just put the constructor functions in the getCStub field, and set getInitializers to an empty list. The constructor functions seem to run at initialization just the same.
Should inline-java do this differently?
Thanks in advance!
Facundo
data CStub = CStub { getCStub :: SDoc
, getInitializers :: [CLabel]
-- ^ Initializers to be run at startup
-- See Note [Initializers and finalizers in Cmm] in
-- "GHC.Cmm.InitFini".
, getFinalizers :: [CLabel]
-- ^ Finalizers to be run at shutdown
}