[m-dev.] for review: pragma foreign_code for MC++ (part 2/2)

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Nov 16 13:02:15 AEDT 2000


On 16-Nov-2000, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> @@ -215,7 +235,7 @@
>  		% which means that for Mercury functions the Mercury return
>  		% value becomes the last argument, and the C return value
>  		% is a bool that is used to indicate success or failure.
> -		C_Code0 = "SUCCESS_INDICATOR = ",
> +		C_Code0 = "MR_SUCCESS_INDICATOR = ",

That is definitely wrong now, and depending on the details of Zoltan's
change, might still be wrong after his change.

In fact SUCCESS_INDICATOR is one of the macros that we document in the
Mercury language reference manual.  So now that I think about it in
more detail, my guess is that Zoltan probably won't/didn't change it.

> diff -u compiler/intermod.m compiler/intermod.m
> --- compiler/intermod.m
> +++ compiler/intermod.m
> @@ -218,7 +218,7 @@
>  			intermod_info_get_preds(Preds0),
>  			( { pred_info_get_goal_type(PredInfo, pragmas) } ->
>  				% The header code must be written since
> -				% it could be used by the pragma_foreign_code.
> +				% it could be used by the pragma_c_code.
>  				intermod_info_set_write_header
>  			;
>  				[]

That looks wrong, I think.
At least I don't understand the reason for that change.
Did you somehow accidentally reverse that?

> @@ -459,10 +459,10 @@
>  	intermod__traverse_goal(Else0, Else, DoWrite3),
>  	{ bool__and_list([DoWrite1, DoWrite2, DoWrite3], DoWrite) }.
>  
> -	% Inlineable exported pragma_foreign_code goals can't use any
> +	% Inlineable exported pragma_c_code goals can't use any
>  	% non-exported types, so we just write out the clauses. 

Likewise.

> @@ -1098,8 +1098,8 @@
>  	globals__io_lookup_string_option(dump_hlds_options, VerboseDump),
>  	globals__io_set_option(dump_hlds_options, string("")),
>  	( { WriteHeader = yes } ->
> -		{ module_info_get_foreign_decl(ModuleInfo, ForeignDecl) },
> -		intermod__write_foreign_decl(ForeignDecl)
> +		{ module_info_get_foreign_header(ModuleInfo, CHeader) },
> +		intermod__write_c_header(CHeader)
>  	;
>  		[]
>  	),

Likewise.

> @@ -1122,14 +1122,13 @@
>  		intermod__write_modules(Rest)
>  	).
>  
> -:- pred intermod__write_foreign_decl(list(foreign_decl_code)::in,
> +:- pred intermod__write_c_header(list(foreign_header_code)::in,
>  				io__state::di, io__state::uo) is det.
>  
> -intermod__write_foreign_decl([]) --> [].
> -intermod__write_foreign_decl(
> -		[foreign_decl_code(Language, Header, _) | Headers]) -->
> -        intermod__write_foreign_decl(Headers),
> -        mercury_output_pragma_foreign_decl(Language, Header).
> +intermod__write_c_header([]) --> [].
> +intermod__write_c_header([Header - _ | Headers]) -->
> +        intermod__write_c_header(Headers),
> +        mercury_output_pragma_c_header(Header).

Likewise.

> @@ -1374,11 +1374,11 @@
>  	{ clauses_info_headvars(ClausesInfo, HeadVars) },
>  	{ clauses_info_clauses(ClausesInfo, Clauses) },
>  
> -		% handle pragma foreign_code(...) separately
> +		% handle pragma c_code(...) separately
>  	( { pred_info_get_goal_type(PredInfo, pragmas) } ->
>  		{ pred_info_procedures(PredInfo, Procs) },
> -		intermod__write_foreign_code(SymName, PredOrFunc, HeadVars,
> -			VarSet, Clauses, Procs)
> +		intermod__write_c_code(SymName, PredOrFunc, HeadVars, VarSet,
> +						Clauses, Procs)

Likewise.

> @@ -1594,13 +1594,13 @@
>  	% This marker should only occur after the magic sets transformation.
>  	error("intermod__should_output_marker: generate_inline").
>  
> -	% Some pretty kludgy stuff to get foreign code written correctly.
> -:- pred intermod__write_foreign_code(sym_name::in, pred_or_func::in, 
> +	% Some pretty kludgy stuff to get c code written correctly.
> +:- pred intermod__write_c_code(sym_name::in, pred_or_func::in, 
>  	list(prog_var)::in, prog_varset::in,
>  	list(clause)::in, proc_table::in, io__state::di, io__state::uo) is det.
>  
> -intermod__write_foreign_code(_, _, _, _, [], _) --> [].
> -intermod__write_foreign_code(SymName, PredOrFunc, HeadVars, Varset, 
> +intermod__write_c_code(_, _, _, _, [], _) --> [].
> +intermod__write_c_code(SymName, PredOrFunc, HeadVars, Varset, 
>  		[Clause | Clauses], Procs) -->
>  	{ Clause = clause(ProcIds, Goal, _) },
>  	(

Likewise.

> diff -u compiler/mlds_to_c.m compiler/mlds_to_c.m
> --- compiler/mlds_to_c.m
> +++ compiler/mlds_to_c.m
> @@ -448,17 +448,12 @@
>  			mlds_output_pragma_export_decl(ModuleName, Indent)).
>  
>  :- pred mlds_output_c_hdr_decl(indent,
> -	foreign_decl_code, io__state, io__state).
> +	foreign_header_code, io__state, io__state).
>  :- mode mlds_output_c_hdr_decl(in, in, di, uo) is det.

This one I don't understand either.

> -mlds_output_c_hdr_decl(_Indent, foreign_decl_code(Lang, Code, Context)) -->
> -		% only output C code in the C header file.
> -	( { Lang = c } ->
> -		mlds_output_context(mlds__make_context(Context)),
> -		io__write_string(Code)
> -	;
> -		{ sorry(this_file, "foreign code other than C") }
> -	).
> +mlds_output_c_hdr_decl(_Indent, Code - Context) -->
> +	mlds_output_context(mlds__make_context(Context)),
> +	io__write_string(Code).

Likewise.

> --- compiler/options.m
> +++ compiler/options.m
> @@ -1997,8 +1997,8 @@
>  		"\tto specify foreign languages in pragma foreign declarations",
>  		"\tis valid, but not all foreign languages are implemented",
>  		"\tin all backends.",
> -		"\tDefault value is C for the LLDS and MLDS->C backends,",
> -		"\tor ManagedC++ for the .NET backend.",
> +		"\tDefault value is `C' for the LLDS and MLDS->C backends,",
> +		"\tor `ManagedC++' for the .NET backend.",
>  
>  		"--no-type-layout",
>  		"(This option is not for general use.)",
>  attributes_to_strings(Attrs, StringList) :-
> +	% We ingore Lang because it isn't an attribute that you can put
> +	% in the attribute list -- the foreign language specifier string
> +	% is at the start of the pragma.

s/ingore/ignore/

This should probably be documented in the interface documentation
for attributes_to_strings.

> --- doc/user_guide.texi	2000/10/27 08:38:50	1.226
> +++ doc/user_guide.texi	2000/11/16 00:50:35
> @@ -3622,6 +3622,16 @@
>  is determined by the auto-configuration script.
>  
>  @sp 1
> + at item @code{--use-foreign-language @var{foreign language}}
> +Use the given foreign language to implement predicates
> +written in foreign languages.  Any name that can be used
> +to specify foreign languages in pragma foreign declarations
> +is valid, but not all foreign languages are implemented
> +in all backends.
> +Default value is `C' for the LLDS and MLDS->C backends,
> +or `ManagedC++' for the .NET backend.

I suggest s/pragma foreign/@samp{pragma foreign}.

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