]> gitweb.factorcode.org Git - factor.git/blob - extra/alien/fortran/fortran-docs.factor
factor: trim using lists
[factor.git] / extra / alien / fortran / fortran-docs.factor
1 ! Copyright (C) 2009 Joe Groff
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax sequences strings words.symbol classes.struct ;
4 QUALIFIED-WITH: alien.syntax c
5 IN: alien.fortran
6
7 ARTICLE: "alien.fortran-abis" "Fortran ABIs"
8 "Fortran does not have a standard ABI like C does. Factor supports the following Fortran ABIs:"
9 { $list
10     { { $link gfortran-abi } " is used by gfortran, the Fortran compiler included with GCC 4." }
11     { { $link f2c-abi } " is used by the F2C Fortran-to-C translator and G77, the Fortran compiler included with GCC 3.x and earlier. It is also used by gfortran when compiling with the -ff2c flag." }
12     { { $link intel-unix-abi } " is used by the Intel Fortran Compiler on Linux and Mac OS X." }
13     { { $link intel-windows-abi } " is used by the Intel Fortran Compiler on Windows." }
14 }
15 "A library's ABI is specified when that library is opened by the " { $link add-fortran-library } " word." ;
16
17 ARTICLE: "alien.fortran-types" "Fortran types"
18 "The Fortran FFI recognizes the following Fortran types:"
19 { $list
20     { { $snippet "INTEGER" } " specifies a four-byte integer value. Sized integers can be specified with " { $snippet "INTEGER*1" } ", " { $snippet "INTEGER*2" } ", " { $snippet "INTEGER*4" } ", and " { $snippet "INTEGER*8" } "." }
21     { { $snippet "LOGICAL" } " specifies a four-byte boolean value. Sized booleans can be specified with " { $snippet "LOGICAL*1" } ", " { $snippet "LOGICAL*2" } ", " { $snippet "LOGICAL*4" } ", and " { $snippet "LOGICAL*8" } "." }
22     { { $snippet "REAL" } " specifies a single-precision floating-point real value." }
23     { { $snippet "DOUBLE-PRECISION" } " specifies a double-precision floating-point real value. The alias " { $snippet "REAL*8" } " is also recognized." }
24     { { $snippet "COMPLEX" } " specifies a single-precision floating-point complex value." }
25     { { $snippet "DOUBLE-COMPLEX" } " specifies a double-precision floating-point complex value. The alias " { $snippet "COMPLEX*16" } " is also recognized." }
26     { { $snippet "CHARACTER(n)" } " specifies a character string of length " { $snippet "n" } ". The Fortran 77 syntax " { $snippet "CHARACTER*n" } " is also recognized." }
27     { "Fortran arrays can be specified by suffixing a comma-separated set of dimensions in parentheses, e.g. " { $snippet "REAL(2,3,4)" } ". Arrays of unspecified length can be specified using " { $snippet "*" } " as a dimension. Arrays are passed in as flat " { $link "specialized-arrays" } "." }
28     { "Struct classes defined by " { $link POSTPONE: STRUCT: } " are also supported as parameter and return types." }
29 }
30 "When declaring the parameters of Fortran functions, an output argument can be specified by prefixing an exclamation point to the type name. This will cause the function word to leave the final value of the parameter on the stack." ;
31
32 HELP: FUNCTION:
33 { $syntax "FUNCTION: RETURN-TYPE NAME ( [!]ARGUMENT-TYPE NAME, ... ) ;" }
34 { $description "Declares a Fortran function binding with the given return type and arguments. See " { $link "alien.fortran-types" } " for a list of supported types." } ;
35
36 HELP: SUBROUTINE:
37 { $syntax "SUBROUTINE: NAME ( [!]ARGUMENT-TYPE NAME, ... ) ;" }
38 { $description "Declares a Fortran subroutine binding with the given arguments. See " { $link "alien.fortran-types" } " for a list of supported types." } ;
39
40 HELP: LIBRARY:
41 { $syntax "LIBRARY: name" }
42 { $values { "name" "a logical library name" } }
43 { $description "Sets the logical library for subsequent " { $link POSTPONE: FUNCTION: } " and " { $link POSTPONE: SUBROUTINE: } " definitions. The given library name must have been opened with a previous call to " { $link add-fortran-library } "." } ;
44
45 HELP: add-fortran-library
46 { $values { "name" string } { "soname" string } { "fortran-abi" symbol } }
47 { $description "Opens the shared library in the file specified by " { $snippet "soname" } " under the logical name " { $snippet "name" } " so that it may be used in subsequent " { $link POSTPONE: LIBRARY: } " and " { $link fortran-invoke } " calls. Functions and subroutines from the library will be defined using the specified " { $snippet "fortran-abi" } ", which must be one of the supported " { $link "alien.fortran-abis" } "." }
48 ;
49
50 HELP: fortran-invoke
51 { $values
52     { "return" string } { "library" string } { "procedure" string } { "parameters" sequence }
53 }
54 { $description "Invokes the Fortran subroutine or function " { $snippet "procedure" } " in " { $snippet "library" } " with parameters specified by the " { $link "alien.fortran-types" } " specified in the " { $snippet "parameters" } " sequence. If the " { $snippet "return" } " value is " { $link f } ", no return value is expected, otherwise a return value of the specified Fortran type is expected. Input values are taken off the top of the datastack, and output values are left for the return value (if any) and any parameters specified as out parameters by prepending " { $snippet "\"!\"" } "." }
55 ;
56
57 ARTICLE: "alien.fortran" "Fortran FFI"
58 "The " { $vocab-link "alien.fortran" } " vocabulary provides an interface to code in shared libraries written in Fortran."
59 { $subsections
60     "alien.fortran-types"
61     "alien.fortran-abis"
62     add-fortran-library
63     POSTPONE: LIBRARY:
64     POSTPONE: FUNCTION:
65     POSTPONE: SUBROUTINE:
66     fortran-invoke
67 } ;
68
69 ABOUT: "alien.fortran"