[m-dev.] for discussion: pragma foreign_import
Peter Ross
peter.ross at miscrit.be
Wed Dec 5 20:32:11 AEDT 2001
Here is the full diff as requested by fjh.
Index: reference_manual.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.230
diff -u -r1.230 reference_manual.texi
--- reference_manual.texi 4 Dec 2001 13:51:54 -0000 1.230
+++ reference_manual.texi 4 Dec 2001 14:35:33 -0000
@@ -4843,10 +4843,92 @@
code using @samp{pragma foreign_proc}.
@menu
+* pragma foreign_import:: Importing foreign procedures.
* pragma foreign_proc:: Defining Mercury procedures using foreign code.
* Foreign code attributes:: Describing properties of foreign
functions or code.
@end menu
+
+ at node pragma foreign_import
+ at subsection pragma foreign_import
+
+ at example
+:- pragma foreign_import(@var{Lang},
+ @var{Pred}(@var{Mode1}, @var{Mode2}, @dots{}),
+ @var{Attributes}, "@var{Name}").
+ at end example
+
+or
+
+ at example
+:- pragma foreign_import(@var{Lang},
+ @var{Func}(@var{Mode1}, @var{Mode2}, @dots{}) = @var{Mode},
+ @var{Attributes}, "@var{Name}").
+ at end example
+
+ at noindent
+imports a procedure in the foreign language specified by @var{Lang}
+for use by Mercury.
+ at var{Pred} or @var{Func} must specify the name of a previously declared
+Mercury predicate or function, and @var{Mode1}, @var{Mode2}, @dots{},
+and (for functions) @var{Mode} must specify one of the
+modes of that predicate or function.
+There must be no clauses for the specified Mercury procedure;
+instead, any calls to that procedure will be executed by calling
+the foreign language procedure specified by @var{Name}.
+The @var{Attributes} argument is optional; if present,
+it specifies properties of the given procedure
+(@pxref{Foreign code attributes}).
+
+The interface to the function for a given Mercury procedure is
+determined as explained in @ref{Data passing conventions}.
+
+If you use @samp{pragma foreign_import} for a polymorphically typed
+Mercury procedure,
+the compiler will prepend one @samp{type_info} argument to the parameters
+passed to the foreign language procedure for each polymorphic type
+variable in the Mercury procedure's type signature.
+The values passed in these arguments will be the same as the values that
+would be obtained using the Mercury @samp{type_of} function in the
+Mercury standard library module @samp{std_util}.
+These values may be useful in case the foreign language function wishes
+to in turn call another polymorphic Mercury procedure (@pxref{Calling
+Mercury code from C}).
+
+ at c XXX we need a calling Mercury code from the outside world section,
+ at c not just from C.
+
+You may not give a @samp{pragma foreign_import} declaration for a procedure
+with determinism @samp{nondet} or @samp{multi}.
+
+ at subsubsection pragma foreign_import for C
+
+To import a C function on the C backend
+use @code{c} for @var{Lang},
+and @var{Name} is the C function name.
+
+For example, the following code imports the C function @samp{cos()}
+as the Mercury function @samp{cos/1}:
+
+ at example
+:- func cos(float) = float.
+:- pragma import(cos(in) = out, [will_not_call_mercury], "cos").
+ at end example
+
+ at subsubsection pragma foreign_import for IL
+
+To import an IL function on the IL backend
+use @code{il} for @var{Lang},
+and @var{Name} is the IL syntax for class method references.
+
+For example, the following code imports the IL function @samp{Cos()}
+as the Mercury function @samp{cos/1}:
+
+ at example
+:- func cos(float) = float.
+:- pragma foreign_import(il, cos(in) = out,
+ "static float64 [mscorlib]System.Math.Cos(float64)"
+ at end example
@node pragma foreign_proc
@subsection pragma foreign_proc
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list