[m-dev.] for review: implement pragma export for MLDS backend

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Jul 18 13:33:41 AEST 2000


On 17-Jul-2000, Peter Ross <peter.ross at miscrit.be> wrote:
> +
> Index: compiler/mlds_to_c.m

> @@ -349,6 +358,172 @@
>  	mlds_output_context(mlds__make_context(Context)),
>  	io__write_string(Code).
>  
> +:- pred mlds_output_pragma_export_decl(mlds_module_name, indent,
> +		mlds__pragma_export, io__state, io__state).
> +:- mode mlds_output_pragma_export_decl(in, in, in, di, uo) is det.
> +
> +mlds_output_pragma_export_decl(ModuleName, Indent,
> +		ml_pragma_export(C_name, _MLDS_Name, Signature0, Context,
> +			IsFunc)) -->
> +	(
> +		{ IsFunc = yes }
> +	->
> +		{ Signature = det_func_signature(Signature0) }
> +	;
> +		{ Signature = Signature0 }
> +	),
> +	{ Name = qual(ModuleName, export(C_name)) },
> +	mlds_indent(Context, Indent),
> +	mlds_output_func_decl(Indent, Name, Context, Signature),
> +	io__write_string(";").
> +
> +:- pred mlds_output_pragma_export_defn(mlds_module_name, indent,
> +		mlds__pragma_export, io__state, io__state).
> +:- mode mlds_output_pragma_export_defn(in, in, in, di, uo) is det.
> +
> +mlds_output_pragma_export_defn(ModuleName, Indent,
> +		ml_pragma_export(C_name, MLDS_Name, MLDS_Signature, Context,
> +			IsFunc)) -->
> +	(
> +		{ IsFunc = yes },
> +		{ Signature = det_func_signature(MLDS_Signature) }
> +	;
> +		{ IsFunc = no },
> +		{ Signature = MLDS_Signature }
> +	),
> +	{ Name = qual(ModuleName, export(C_name)) },
> +	mlds_indent(Context, Indent),
> +	mlds_output_func_decl(Indent, Name, Context, Signature),

Hmm, all that code there is duplicated.
I suggest you factor out the common code.

> +
> +	%
> +	% Write out the arguments to the MLDS function.  Note the last
> +	% in the list of the arguments in the return value, so it must
> +	% be "&arg"

s/in the return value/is the return value/
                       ^

> +:- func argument_names(mlds_module_name, mlds__func_params)
> +		= list(mlds__qualified_entity_name).
> +
> +argument_names(ModuleName, mlds__func_params(Parameters, _RetTypes))
> +		= QualNames :-
> +	list__map(fst, Parameters, Names),
> +	list__map((pred(Name::in, QualName::out) is det :-
> +			QualName = qual(ModuleName, Name)),
> +			Names, QualNames).

Personally I would write that as

	Names = list__map(fst, Parameters),
	QualNames = list__map(func(Name) = qual(ModuleName, Name), Names).

> Index: library/io.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/io.m,v
> retrieving revision 1.198
> diff -u -r1.198 io.m
> --- library/io.m	2000/06/08 07:59:01	1.198
> +++ library/io.m	2000/07/17 12:59:01
> @@ -1809,6 +1809,27 @@
>  
>  :- pragma export(io__print(in, in, di, uo), "ML_io_print_to_stream").
>  
> +:- pragma c_code("
> +/*
> +** XXX this is a hack to work-around the current lack of
> +** support for `pragma export'.
> +*/
> +#ifndef MR_BOOTSTRAPPED_PRAGMA_EXPORT
> +  extern void mercury__io__print_3_p_0(MR_Word ti, MR_Box x);
> +  extern void mercury__io__print_4_p_0(MR_Word ti, MR_Word stream, MR_Box x);
> +
> +  void
> +  ML_io_print_to_cur_stream(MR_Word ti, MR_Word x) {
> +	mercury__io__print_3_p_0(ti, (MR_Box) x);
> +  }
> +
> +  void
> +  ML_io_print_to_stream(MR_Word ti, MR_Word stream, MR_Word x) {
> +	mercury__io__print_4_p_0(ti, stream, (MR_Box) x);
> +  }
> +#endif
> +").

That should be inside `#ifdef MR_HIGHLEVEL_CODE'.

BTW, why move this from runtime/mercury.c to library/io.m?

> +++ runtime/mercury.h	2000/07/17 12:59:04
> @@ -43,15 +43,17 @@
>  ** XXX this is a hack to work-around the current lack of
>  ** support for `pragma export'.
>  */
> -#ifndef MR_HIGHLEVEL_DATA
> -#define ML_report_uncaught_exception \
> -		mercury__exception__report_uncaught_exception_3_p_0
> -#define ML_throw_io_error		mercury__io__throw_io_error_1_p_0
> -#define ML_io_finalize_state		mercury__io__finalize_state_2_p_0
> -#define ML_io_init_state		mercury__io__init_state_2_p_0
> -#define ML_io_stderr_stream		mercury__io__stderr_stream_3_p_0
> -#define ML_io_stdin_stream		mercury__io__stdin_stream_3_p_0
> -#define ML_io_stdout_stream		mercury__io__stdout_stream_3_p_0
> +#ifndef MR_BOOTSTRAPPED_PRAGMA_EXPORT
> +  #ifndef MR_HIGHLEVEL_DATA
> +  #define ML_report_uncaught_exception \
> +			 mercury__exception__report_uncaught_exception_3_p_0
> +  #define ML_throw_io_error		mercury__io__throw_io_error_1_p_0
> +  #define ML_io_finalize_state		mercury__io__finalize_state_2_p_0
> +  #define ML_io_init_state		mercury__io__init_state_2_p_0
> +  #define ML_io_stderr_stream		mercury__io__stderr_stream_3_p_0
> +  #define ML_io_stdin_stream		mercury__io__stdin_stream_3_p_0
> +  #define ML_io_stdout_stream		mercury__io__stdout_stream_3_p_0
> +  #endif
>  #endif

The #defines there should be indented 4 spaces rather than 2.

> Index: runtime/mercury_init.h
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/runtime/mercury_init.h,v
> retrieving revision 1.21
> diff -u -r1.21 mercury_init.h
> --- runtime/mercury_init.h	2000/05/08 16:11:06	1.21
> +++ runtime/mercury_init.h	2000/07/17 12:59:06
> @@ -115,9 +115,20 @@
>  extern	void	ML_io_stderr_stream(Word *);
>  extern	void	ML_io_stdout_stream(Word *);
>  extern	void	ML_io_stdin_stream(Word *);
> -extern	void	ML_io_print_to_cur_stream(Word, Word);
> -extern	void	ML_io_print_to_stream(Word, Word, Word);
>  
> +#ifndef MR_HIGHLEVEL_CODE
> +  extern void	ML_io_print_to_stream(Word, Word, Word);
> +  extern void	ML_io_print_to_cur_stream(Word, Word);
> +#else
> +  #ifdef MR_BOOTSTRAPPED_PRAGMA_EXPORT
> +    extern void	ML_io_print_to_stream(MR_Word, MR_Word, MR_Box);
> +    extern void	ML_io_print_to_cur_stream(MR_Word, MR_Box);
> +  #else
> +    extern void	ML_io_print_to_stream(Word, Word, Word);
> +    extern void	ML_io_print_to_cur_stream(Word, Word);
> +  #endif
> +#endif

The prototype should be the same regardless of whether
MR_HIGHLEVEL_CODE is set or not.  Otherwise you haven't
implemented `pragma export' correctly, i.e. in a way that matches
the documentation in the Mercury language reference manual.

>  /* in trace/mercury_trace_internal.h */
>  extern	char	*MR_trace_getline(const char *, FILE *mdb_in, FILE *mdb_out);
>  
> @@ -138,11 +149,20 @@
>  extern	bool	ML_DI_found_match(Integer, Integer, Integer, Word, String,
>  		String, Integer, Integer, Integer, Word, String, Word);
>  		/* found_match/12 */
> -extern	Integer	ML_DI_get_var_number(Word);
>  extern	void	ML_DI_read_request_from_socket(Word, Word *, Integer *);
>  
> +#ifndef MR_HIGHLEVEL_CODE
> +  extern Integer	ML_DI_get_var_number(Word);
> +#else
> +  extern MR_Integer	ML_DI_get_var_number(MR_Word);
> +#endif

Likewise here.

>  /* in library/std_util.m  */
> -extern	String	ML_type_name(Word);
> +#ifndef MR_HIGHLEVEL_CODE
> +  extern String		ML_type_name(Word);
> +#else
> +  extern MR_String	ML_type_name(MR_Word);
> +#endif

And here.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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