-
- # Complete compilation of generated code
- fun compile_to_files(mmodule: MModule, directory: String) do end
-end
-
-redef class TString
- # Returns the content of this node without both of the surrounding "
- fun without_quotes: String
- do
- assert text.length >= 2
- return text.substring(1, text.length-2)
- end
-end
-
-redef class TExternCodeSegment
- # Returns the content of this node without the surrounding `{ and `}
- fun without_guard: String
- do
- assert text.length >= 4
- return text.substring(2, text.length-4)
- end
-end
-
-redef class CCompilationUnit
- fun write_as_impl(mmodule: MModule, compdir: String)
- do
- var base_name = "{mmodule.c_name}._ffi"
-
- var h_file = "{base_name}.h"
- var guard = "{mmodule.c_name.to_upper}_NIT_H"
- write_header_to_file(mmodule, "{compdir}/{h_file}", new Array[String], guard)
-
- var c_file = "{base_name}.c"
- write_body_to_file(mmodule, "{compdir}/{c_file}", ["<stdlib.h>", "<stdio.h>", "\"{h_file}\""])
-
- files.add( "{compdir}/{c_file}" )
- end
-
- fun write_header_to_file(mmodule: MModule, file: String, includes: Array[String], guard: String)
- do
- var stream = new FileWriter.open( file )
-
- # header comments
- var module_info = "/*\n\tExtern implementation of Nit module {mmodule.name}\n*/\n"
-
- stream.write( module_info )
-
- stream.write( "#ifndef {guard}\n" )
- stream.write( "#define {guard}\n\n" )
-
- for incl in includes do stream.write( "#include {incl}\n" )
-
- compile_header_core( stream )
-
- # header file guard close
- stream.write( "#endif\n" )
- stream.close
- end
-
- fun write_body_to_file(mmodule: MModule, file: String, includes: Array[String])
- do
- var stream = new FileWriter.open(file)
-
- var module_info = "/*\n\tExtern implementation of Nit module {mmodule.name}\n*/\n"
-
- stream.write( module_info )
- for incl in includes do stream.write( "#include {incl}\n" )
-
- compile_body_core( stream )
-
- stream.close
- end
-end
-
-class ForeignType
- fun ctype: String do return "void*"