chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.76k stars 414 forks source link

Generate an initialization function for --library-fortran #12569

Open daviditen opened 5 years ago

daviditen commented 5 years ago

Initializing the runtime/modules for --library-fortran currently requires the library author to write an initialization function like:

export proc chpl_library_init_ftn() {
  extern proc chpl_library_init(argc: c_int, argv: c_ptr(c_ptr(c_char)));
  var filename = c"fake";
  chpl_library_init(1, c_ptrTo(filename): c_ptr(c_ptr(c_char)));;
  chpl__init_MyModuleName();
}

It would be good to generate an initializer like this so the library author doesn't need to.

bradcray commented 5 years ago

Given that we're now only conditionally useing ISO_Fortran_binding.chpl when --library-fortran is used, could this simply be made module-level initialization code in that module, such that it would run on program startup for any --library-fortran compilation? (in which case, maybe the module should also be renamed to something more general like FortranInterop.chpl or simply Fortran.chpl?)

lydia-duncan commented 5 years ago

Since the last line depends on the name of the program being compiled with --library-fortran, I'm not sure that is possible