[m-rev.] for review: mlds__function_body

Peter Ross peter.ross at miscrit.be
Fri Jul 13 01:44:30 AEST 2001


Tyson wrote:
> Hi,
>
> ===================================================================
>
>
> Estimated hours taken: 0.75
> Branches: main
>
> Use a new mlds__function_body type to represent function bodies, as the
old
> usage of maybe/1 was error prone ("no" meant the function had been
declared
> using :- pragma external, not merely that the body was missing).
>
> compiler/mlds.m:
> Add mlds__function_body type.
>
> compiler/ml_code_gen.m:
> compiler/ml_code_util.m:
> compiler/ml_elim_nested.m:
> compiler/ml_optimize.m:
> compiler/ml_tailcall.m:
> compiler/ml_util.m:
> compiler/mlds_to_c.m:
> compiler/mlds_to_csharp.m:
> compiler/mlds_to_gcc.m:
> compiler/mlds_to_il.m:
> compiler/mlds_to_java.m:
> compiler/mlds_to_mcpp.m:
> Handle this change.


The change looks good, I assume you didn't meant to include this
documentation change.

> Index: doc/reference_manual.texi
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
> retrieving revision 1.208
> diff -u -r1.208 reference_manual.texi
> --- doc/reference_manual.texi 2001/06/13 04:28:17 1.208
> +++ doc/reference_manual.texi 2001/07/12 14:52:54
> @@ -49,6 +49,7 @@
>  @author Peter Schachte
>  @author Simon Taylor
>  @author Chris Speirs
> + at author Tyson Speirs
>  @page
>  @vskip 0pt plus 1filll
>  Copyright @copyright{} 1995-2001 The University of Melbourne.
> @@ -96,6 +97,8 @@
>                        collections.
>  * Semantics::         Declarative and operational semantics of Mercury
>                        programs.
> +* Foreign language interface:: The foreign language interface allows
> +       C code to be called from Mercury code.
>  * C interface::       The C interface allows C code to be called
>                        from Mercury code, and vice versa.
>  * Impurity::          Users can write impure Mercury code.
> @@ -4672,6 +4675,119 @@
>  For example, they may wish to provide semantics in which function
>  evaluation is lazy, rather than strict; semantics with a guaranteed
>  fair search rule; and so forth.
> +
> + at node Foreign language interface
> + at chapter Foreign language interface
> +
> + at menu
> +* Calling foreign code from Mercury::   How to implement a Mercury
predicate
> + or function as a call to foreign
> + lanugage code.
> + at end menu
> +
> + at node Calling foreign code from Mercury
> + at section Calling foreign code from Mercury
> +
> + at c we have no multi-language import mechanism at the moment.
> +
> +Mercury procedures can be implemented using fragments of foreign language
> +code using @samp{pragma foreign_proc}.
> +
> + at menu
> +* pragma foreign_code::         Defining Mercury procedures using foreign
code.
> + at end menu
> +
> + at node pragma foreign_code
> + at subsection pragma foreign_code
> +
> +A declaration of the form
> +
> + at example
> +:- pragma foreign_proc("@var{Lang}", @var{Pred}(@var{Var1}::@var{Mode1},
@var{Var2}::@var{Mode2}, @dots{}),
> +        @var{Attributes}, @var{Foreign_Code}).
> + at end example
> +
> + at noindent
> +or
> +
> + at example
> +:- pragma foreign_proc("@var{Lang}", @var{Func}(@var{Var1}::@var{Mode1},
@var{Var2}::@var{Mode2}, @dots{}) = (@var{Var}::@var{Mode}),
> +        @var{Attributes}, @var{Foreign_Code}).
> + at end example
> +
> + at noindent
> +means that any calls to the specified mode of @var{Pred} or @var{Func}
> +will result in execution of the foreign code given in @var{Foreign_Code}
> +written in language @var{Lang}.
> +The foreign code fragment may refer to the specified variables
> +(@var{Var1}, @var{Var2}, @dots{}, and @var{Var})
> +directly by name.  These variables will have foreign language types
> +corresponding to their Mercury types, as determined by language and
> +implementation specific rules.
> +It is an error for a variable to occur more than once in the argument
list.
> +
> +Additional restrictions on the foreign language interface code
> +depend on the foreign language, the backend target, and the
implementation.
> +For more information, including the list of supported foreign languages
and
> +the strings used to identify them, see the ``Foreign Language
Interfaces''
> +chapter of the Mercury User's Guide.
> +
> +If there is a @code{pragma foreign_proc} declaration for a
> +mode of a predicate or function, then there must not be any clauses for
that
> +predicate or function, and there must be a @code{pragma foreign_proc}
> + at c or @code{pragma import}
> +declaration for every mode of the predicate or function.
> +
> +For example, the following piece of code defines a Mercury function
> + at samp{sin/1} which calls the C function @samp{sin()} of the same name.
> +
> + at example
> +:- func sin(float) = float.
> +:- pragma foreign_proc("C", sin(X::in) = (Sin::out),
> +        [may_call_mercury],
> +        "Sin = sin(X);").
> + at end example
> +
> +If the C code does not recursively invoke Mercury code,
> +as in the above example, then you can use @samp{will_not_call_mercury}
> +in place of @samp{may_call_mercury} in the declarations above.
> +This allows the compiler to use a slightly more efficient calling
convention.
> +(If you use this form, and the C code @emph{does} invoke Mercury code,
> +then the behaviour is undefined --- your program may misbehave or crash.)
> +
> + at c XXX TYSE UP TO HERE
> + at c Move this to the User's Guide
> + at c
> +The C code in a @code{pragma c_code} declaration
> +for any procedure whose determinism indicates that it could fail
> +must assign a truth value to the macro @samp{SUCCESS_INDICATOR}.
> +For example:
> +
> + at example
> +:- pred string__contains_char(string, character).
> +:- mode string__contains_char(in, in) is semidet.
> +
> +:- pragma c_code(string__contains_char(Str::in, Ch::in),
> +        [will_not_call_mercury],
> +        "SUCCESS_INDICATOR = (strchr(Str, Ch) != NULL);").
> + at end example
> +
> + at code{SUCCESS_INDICATOR} should not be used other than as the target of
> +an assignment.
> +(For example, it may be @code{#define}d to a register, so you should not
> +try to take its address.)
> +Procedures whose determinism indicates that that they cannot fail
> +should not access @code{SUCCESS_INDICATOR}.
> +
> +Arguments whose mode is input will have their values set by the
> +Mercury implementation on entry to the C code.  If the procedure
> +succeeds, the C code must set the values of all output arguments
> +before returning.  If the procedure fails, the C code need only
> +set @code{SUCCESS_INDICATOR} to false (zero).
> +
> +
>
+ at c -----------------------------------------------------------------------
> +
>
>  @node C interface
>  @chapter C interface
>
>
> --
>        Tyson Dowd           #
>                             #  Surreal humour isn't everyone's cup of fur.
>      trd at cs.mu.oz.au        #
> http://www.cs.mu.oz.au/~trd #
> --------------------------------------------------------------------------
> mercury-reviews mailing list
> post:  mercury-reviews at cs.mu.oz.au
> administrative address: owner-mercury-reviews at cs.mu.oz.au
> unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message:
unsubscribe
> subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message:
subscribe
> --------------------------------------------------------------------------
>

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list