X-Git-Url: http://nitlanguage.org diff --git a/src/compiling/compiling.nit b/src/compiling/compiling.nit index 0099b6b..429505b 100644 --- a/src/compiling/compiling.nit +++ b/src/compiling/compiling.nit @@ -19,9 +19,10 @@ package compiling import table_computation import compiling_base -import icode_generator +private import icode_generator private import compiling_global private import compiling_icode +private import analysis redef class Program # The type of code generation to use @@ -58,7 +59,7 @@ redef class Program cprogram.files.add("$CLIBDIR/gc_static_objects_list.c") tc.info("Generating C code",1) - for m in module.mhe.greaters_and_self do m.compile_separate_module(cprogram) + for m in main_module.mhe.greaters_and_self do m.compile_separate_module(cprogram) tc.info("Generating main, tables and makefile ...",1) compile_main(cprogram) @@ -71,15 +72,15 @@ redef class Program # Compile the main file private fun compile_main(cprogram: CProgram) do - var v = new CompilerVisitor(module, cprogram) + var v = new CompilerVisitor(main_module, cprogram) v.add_decl("#include ") compile_tables_to_c(v) compile_main_part(v) - var filename = "{cprogram.compdir}/{module.name}._tables.c" + var filename = "{cprogram.compdir}/{main_module.cname}._tables.c" cprogram.files.add(filename) var f = new OFStream.open(filename) - f.write("/* This C file is generated by NIT to compile program {module.name}. */\n") - for m in module.mhe.greaters_and_self do + f.write("/* This C file is generated by NIT to compile program {main_module.cname}. */\n") + for m in main_module.mhe.greaters_and_self do f.write("#include \"{cprogram.module_header_name(m)}\"\n") end v.header_writer.write_to_stream(f) @@ -90,39 +91,55 @@ end redef class MMModule # Compile the sep or glob files (of the current module only) - private fun compile_separate_module(cprogram: CProgram) + fun compile_separate_module(cprogram: CProgram) do var tc = cprogram.program.tc - tc.info("Generating C code for module: {name}",2) + tc.info("Generating C code for module: {full_name}",2) var v = new CompilerVisitor(self, cprogram) v.add_decl("#include ") - var native_name = location.file.strip_extension(".nit") - var native_header = native_name + "_nit.h" - if native_header.file_exists then - v.add_decl("#include <{native_header.basename("")}>") - cprogram.include_dirs.add("-I {native_name.dirname}") + if is_extern_hybrid then + # adds reference to frontier files + # if module uses the native interface + var nitni_header_name = "{name}._nitni.h" + v.add_decl("#include \"{nitni_header_name}\"") + var nitni_body_name = "{name}._nitni.c" + cprogram.files.add( "{cprogram.compdir}/{nitni_body_name}" ) + + # add reference to extern implementation + var native_name = location.file.filename.strip_extension(".nit") + var native_body = native_name + ".nit.c" + if native_body.file_exists then + cprogram.files.add(native_body) + else # try old style filename + native_body = native_name + "_nit.c" + if native_body.file_exists then cprogram.files.add(native_body) + end + if uses_ffi then + var ffi_header_name = "{cname}._ffi.h" + v.add_decl("#include \"{ffi_header_name}\"") + var ffi_body_name = "{cname}._ffi.c" + cprogram.files.add( "{cprogram.compdir}/{ffi_body_name}" ) + end end - var native_body = native_name + "_nit.c" - if native_body.file_exists then cprogram.files.add(native_body) declare_class_tables_to_c(v) compile_mod_to_c(v) var hfilename = cprogram.module_header_name(self) var f = new OFStream.open("{cprogram.compdir}/{hfilename}") - f.write("/* This C header file is generated by NIT to compile modules and programs that requires {name}. */\n") - f.write("#ifndef {name}{cprogram.get_file_ending}\n") - f.write("#define {name}{cprogram.get_file_ending}\n") + f.write("/* This C header file is generated by NIT to compile modules and programs that requires {full_name}. */\n") + f.write("#ifndef {cname}{cprogram.get_file_ending}\n") + f.write("#define {cname}{cprogram.get_file_ending}\n") for m in mhe.direct_greaters do f.write("#include \"{cprogram.module_header_name(m)}\"\n") v.header_writer.write_to_stream(f) f.write("#endif\n") f.close - var cfilename = "{cprogram.compdir}/{name}.{cprogram.get_file_ending}.c" + var cfilename = "{cprogram.compdir}/{cname}.{cprogram.get_file_ending}.c" cprogram.files.add(cfilename) f = new OFStream.open("{cfilename}") - f.write("/* This C file is generated by NIT to compile module {name}. */\n") + f.write("/* This C file is generated by NIT to compile module {cname}. */\n") f.write("#include \"{hfilename}\"\n") v.top_writer.write_to_stream(f) f.close