
/* This shows how to interface to a simple Fortran function, using the new
   bitcode interface. To compile the Fortran example to a bitcode file:
   llvm-gfortran -emit-llvm -c fact.f90 -o fact.bc

   The following line imports the resulting bitcode module. Note that no
   explicit extern declarations are necessary on the Pure side, these are all
   done automatically. */

using "bc:fact";

/* The Fortran function 'fact' in fact.f90 is available as 'fact_' (note the
   trailing underscore). Unfortunately, the Fortran dialect understood by
   llvm-gfortran doesn't support the 'value' attribute, so the integer
   argument of 'fact_' needs to be passed by reference. This can be done most
   conveniently using a temporary int vector, as shown below. */

/* Note: If you're using the new dragonegg plugin instead of llvm-gfortran, as
   explained in the Makefile, then the 'value' attribute is available, so that
   int values can be passed directly to Fortran functions. To make this work,
   simply add the declaration 'value n' to the fact function in fact.f90 and
   change the definition below accordingly: fact n::int = fact_ n; */

fact n::int = fact_ {n};

// Example:
map fact (1..10);
