Merge: Refactor FFI, the framework is now based on MModules
authorJean Privat <jean@pryen.org>
Tue, 13 May 2014 19:22:37 +0000 (15:22 -0400)
committerJean Privat <jean@pryen.org>
Tue, 13 May 2014 19:22:37 +0000 (15:22 -0400)
* Should fix #437 by supporting the use of the Java FFI across many modules in global compilation.
* Should also work (but we need an example for it): `nitg cross_platform_prog.nit -m android`

Pull-Request: #456
Reviewed-by: Jean Privat <jean@pryen.org>

1  2 
src/android_platform.nit
src/common_ffi/c.nit
src/common_ffi/common_ffi.nit
src/common_ffi/ffi_base.nit
src/common_ffi/java.nit
src/compiler_ffi.nit

Simple merge
Simple merge
Simple merge
@@@ -108,11 -108,11 +108,11 @@@ class FFILanguag
        fun identify_language(block: AExternCodeBlock ): Bool is abstract
  
        # Generate wrapper code for this module/header code block
-       fun compile_module_block(block: AExternCodeBlock, ecc: CCompilationUnit, nmodule: AModule) is abstract
+       fun compile_module_block(block: AExternCodeBlock, ecc: CCompilationUnit, mmodule: MModule) is abstract
  
        # Generate wrapper code for this extern method
 -      fun compile_extern_method(block: AExternCodeBlock, m: AExternPropdef,
 -              ecc: CCompilationUnit, mmodule: MModule) is abstract
 +      fun compile_extern_method(block: AExternCodeBlock, m: AMethPropdef,
-               ecc: CCompilationUnit, nmodule: AModule) is abstract
++              ecc: CCompilationUnit, nmodule: MModule) is abstract
  
        # Generate wrapper code for this extern class
        fun compile_extern_class(block: AExternCodeBlock, m: AClassdef,
@@@ -160,30 -159,30 +159,30 @@@ class JavaLanguag
  
        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.as(not null), nmodule.ffi_callbacks[self])
 -              mmodule.ensure_linking_callback_methods(ffi_ccu, mmodule.ffi_callbacks[self])
++              mmodule.ensure_linking_callback_methods(ffi_ccu.as(not null), 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
 +      var ffi_ccu: nullable CCompilationUnit = null # 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
  
@@@ -79,8 -80,8 +80,8 @@@ redef class MModul
        end
  end
  
 -redef class AExternPropdef
 +redef class AMethPropdef
-       fun compile_ffi_support_to_c(v: AbstractCompilerVisitor)
+       private fun compile_ffi_support_to_c(v: AbstractCompilerVisitor)
        do
                var mmodule = mpropdef.mclassdef.mmodule
                var mainmodule = v.compiler.mainmodule
                v.declare_once("{csignature};")
  
                # FFI part
-               compile_ffi_method(amodule)
+               amodule.ensure_compile_ffi_wrapper
+               compile_ffi_method(mmodule)
  
 +              assert self isa AExternPropdef
 +
                # nitni - Compile missing callbacks
                mmodule.ensure_compile_nitni_base(v)
                var ccu = mmodule.nitni_ccu.as(not null)
                # manage nitni callback set
                mmodule.foreign_callbacks.join(foreign_callbacks)
        end
 -end
  
 -redef class AExternMethPropdef
 -      redef fun compile_to_c(v, mpropdef, arguments)
 +      redef fun compile_externmeth_to_c(v, mpropdef, arguments)
        do
                var mmodule = mpropdef.mclassdef.mmodule
-               var amodule = v.compiler.modelbuilder.mmodule2nmodule[mmodule]
  
                # if using the old native interface fallback on previous implementation
                var nextern = self.n_extern
  
                compile_ffi_support_to_c(v)
        end
 -end
  
 -redef class AExternInitPropdef
 -      redef fun compile_to_c(v, mpropdef, arguments)
 +      redef fun compile_externinit_to_c(v, mpropdef, arguments)
        do
                var mmodule = mpropdef.mclassdef.mmodule
-               var amodule = v.compiler.modelbuilder.mmodule2nmodule[mmodule]
  
                # if using the old native interface fallback on previous implementation
                var nextern = self.n_extern