redef fun identify_language(n) do return n.is_java
- redef fun compile_module_block(block, ccu, nmodule)
+ redef fun compile_module_block(block, ccu, mmodule)
do
- nmodule.ensure_java_files
- var java_file = nmodule.java_file
+ mmodule.ensure_java_files
+ var java_file = mmodule.java_file
assert java_file != null
java_file.header.add(block.code)
end
- redef fun compile_extern_method(block, m, ccu, nmodule)
+ redef fun compile_extern_method(block, m, ccu, mmodule)
do
ffi_ccu = ccu
- nmodule.ensure_java_files
- var java_file = nmodule.java_file
+ mmodule.ensure_java_files
+ var java_file = mmodule.java_file
assert java_file != null
- var mmodule = nmodule.mmodule.as(not null)
var mclass_type = m.parent.as(AClassdef).mclass.mclass_type
var mmethodef = m.mpropdef
var mproperty = m.mpropdef.mproperty
# Java implementation function in Java
var java_csig = mproperty.build_csignature(mclass_type, mmodule, "___java_impl", long_signature, java_call_context)
- nmodule.java_file.class_content.add """
+ mmodule.java_file.class_content.add """
public static {{{java_csig}}} {
// from Nit FII at: {{{block.location}}}
{{{block.code}}}
"""
end
- redef fun compile_extern_class(block, m, ccu, nmodule) do end
+ redef fun compile_extern_class(block, m, ccu, mmodule) do end
redef fun get_ftype(block, m) do return new ForeignJavaType(block.code)
- redef fun compile_to_files(nmodule, compdir)
+ redef fun compile_to_files(mmodule, compdir)
do
# Make sure we have a .java file
- nmodule.ensure_java_files
+ mmodule.ensure_java_files
# Needed compiler and linker options
- nmodule.insert_compiler_options
+ mmodule.insert_compiler_options
# Enable linking C callbacks to java native methods
- nmodule.ensure_linking_callback_methods(ffi_ccu, nmodule.ffi_callbacks[self])
+ mmodule.ensure_linking_callback_methods(ffi_ccu, mmodule.ffi_callbacks[self])
# Java implementation code
- var java_file = nmodule.java_file
+ var java_file = mmodule.java_file
assert java_file != null
var extern_java_file = java_file.write_to_files(compdir)
- nmodule.ffi_files.add(extern_java_file)
+ mmodule.ffi_files.add(extern_java_file)
end
var ffi_ccu: CCompilationUnit # HACK
- redef fun compile_callback(callback, nmodule, mainmodule, ccu)
+ redef fun compile_callback(callback, mmodule, mainmodule, ccu)
do
ffi_ccu = ccu
- callback.compile_callback_to_java(nmodule, ccu)
+ callback.compile_callback_to_java(mmodule, mainmodule, ccu)
end
end
-redef class AModule
+redef class MModule
# Pure java class source file
private var java_file: nullable JavaClassTemplate = null
if java_file != null then return
# Java implementation code
- java_file = new JavaClassTemplate(mmodule.impl_java_class_name)
+ java_file = new JavaClassTemplate(impl_java_class_name)
end
# Compile C code to call JNI and link C callbacks implementations to Java extern methods
var jni_methods = new Array[String]
for cb in callbacks do
- jni_methods.add_all(cb.jni_methods_declaration(mmodule.as(not null)))
+ jni_methods.add_all(cb.jni_methods_declaration(self))
end
var cf = new CFunction("static void nit_ffi_with_java_register_natives(JNIEnv* env, jclass jclazz)")
# Tell the C compiler where to find jni.h and how to link with libjvm
private fun insert_compiler_options
do
- mmodule.c_compiler_options = "{mmodule.c_compiler_options} -I $(JAVA_HOME)/include/"
- mmodule.c_linker_options = "{mmodule.c_linker_options} -L $(JNI_LIB_PATH) -ljvm"
+ c_compiler_options = "{c_compiler_options} -I $(JAVA_HOME)/include/"
+ c_linker_options = "{c_linker_options} -L $(JNI_LIB_PATH) -ljvm"
end
-end
-redef class MModule
# Name of the generated Java class where to store all implementation methods of this module
# as well as generated callbacks.
private fun impl_java_class_name: String do return "Nit_{name}"
redef class NitniCallback
# Compile C and Java code to implement this callback
- fun compile_callback_to_java(nmodule: AModule, ccu: CCompilationUnit) do end
+ fun compile_callback_to_java(mmodule: MModule, mainmodule: MModule, ccu: CCompilationUnit) do end
# Returns the list of C functions to link with extern Java methods, as required
# to enable this callback from Java code.
#
- # Return used by `AModule::ensure_linking_callback_methods`
+ # Return used by `MModule::ensure_linking_callback_methods`
#
# TODO we return an Array to support cast and other features like that
fun jni_methods_declaration(from_module: MModule): Array[String] do return new Array[String]
end
redef class MExplicitCall
- redef fun compile_callback_to_java(nmodule, ccu)
+ redef fun compile_callback_to_java(mmodule, mainmodule, ccu)
do
var mproperty = mproperty
assert mproperty isa MMethod
- var mmodule = nmodule.mmodule.as(not null)
# In C, indirection implementing the Java extern methods
var csignature = mproperty.build_c_implementation_signature(recv_mtype, mmodule, "___indirect", long_signature, from_java_call_context)
var cf = new CFunction("JNIEXPORT {csignature}")
- cf.exprs.add "\t{mproperty.build_ccall(recv_mtype, mmodule, null, long_signature, from_java_call_context, null)}\n"
+ cf.exprs.add "\t{mproperty.build_ccall(recv_mtype, mainmodule, null, long_signature, from_java_call_context, null)}\n"
ccu.add_local_function cf
# In Java, declare the extern method as a private static local method
- var java_signature = mproperty.build_csignature(recv_mtype, mmodule, null, short_signature, java_call_context)
- nmodule.java_file.class_content.add "private native static {java_signature};\n"
+ var java_signature = mproperty.build_csignature(recv_mtype, mainmodule, null, short_signature, java_call_context)
+ mmodule.java_file.class_content.add "private native static {java_signature};\n"
end
redef fun jni_methods_declaration(from_mmodule)
do
var ftype = mclass.ftype
if ftype isa ForeignJavaType then return "Object"
- if mclass.name == "Bool" then return "Bool"
+ if mclass.name == "Bool" then return "Boolean"
if mclass.name == "Char" then return "Char"
if mclass.name == "Int" then return "Int"
if mclass.name == "Float" then return "Double"