[m-dev.] diff: MLDS backend: handle output arguments

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Sep 18 00:18:03 AEST 1999


Estimated hours taken: 1

Add support to the MLDS backend for MLDS builtin types,
including pointer types, so that we can handle output arguments.

compiler/mlds.m:
	Add builtin MLDS types for int, bool, float, char,
	continuation functions, and pointers.

compiler/ml_code_gen.m:
	Generate the new builtin MLDS types for bool, continuation
	functions, and pointers.

compiler/mlds_to_c.m:
	Change mlds_output_type to output the new builtin MLDS types.
	Also ensure that we map the Mercury types to Integer, Float,
	Char, etc., while the builtin MLDS types get mapped to int,
	float, char.

Workspace: /home/mercury0/fjh/mercury
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.2
diff -u -r1.2 ml_code_gen.m
--- ml_code_gen.m	1999/09/10 09:51:06	1.2
+++ ml_code_gen.m	1999/09/17 13:52:12
@@ -665,7 +665,7 @@
 :- func ml_gen_succeeded_var_decl(mlds__context) = mlds__defn.
 ml_gen_succeeded_var_decl(Context) = MLDS_Defn :-
 	Name = data(var("succeeded")),
-	ml_bool_type(Type),
+	Type = mlds__bool_type,
 	MaybeInitializer = no,
 	Defn = data(Type, MaybeInitializer),
 	DeclFlags = ml_gen_var_decl_flags,
@@ -2386,15 +2386,14 @@
 	proc_info_argmodes(ProcInfo, HeadModes),
 
 	( CodeModel = model_semi ->
-		ml_bool_type(Bool),
-		RetTypes = [Bool]
+		RetTypes = [mlds__bool_type]
 	;
 		RetTypes = []
 	),
 	ml_gen_arg_decls(ModuleInfo, HeadVars, HeadTypes, HeadModes,
 		VarSet, FuncArgs0),
 	( CodeModel = model_non ->
-		ml_cont_type(ContType),
+		ContType = mlds__cont_type,
 		ContName = data(var("cont")),
 		ContArg = ContName - ContType,
 		FuncArgs = list__append(FuncArgs0, [ContArg])
@@ -2464,7 +2463,7 @@
 ml_gen_arg_decl(ModuleInfo, Var, Type, Mode, VarSet, FuncArg) :-
 	MLDS_Type = mercury_type_to_mlds_type(Type),
 	( mode_is_output(ModuleInfo, Mode) ->
-		MLDS_ArgType = ml_ptr_type(MLDS_Type)
+		MLDS_ArgType = mlds__ptr_type(MLDS_Type)
 	;
 		MLDS_ArgType = MLDS_Type
 	),
@@ -2532,24 +2531,6 @@
 	=(MLDSGenInfo),
 	{ ml_gen_info_get_var_types(MLDSGenInfo, VarTypes) },
 	{ map__lookup(VarTypes, Var, Type) }.
-
-%-----------------------------------------------------------------------------%
-%
-% XXX quick hacks for prototyping...
-
-:- pred ml_bool_type(mlds__type::out) is det.
-ml_bool_type(BoolType) :-
-	BoolType = mercury_type_to_mlds_type(int_type).
-
-:- pred ml_cont_type(mlds__type::out) is det.
-ml_cont_type(ContType) :-
-	construct_type(unqualified("Cont") - 0, [], ContT),
-	ContType = mercury_type_to_mlds_type(ContT).
-
-:- func ml_ptr_type(mlds__type) = mlds__type.
-ml_ptr_type(_Type) = PointerType :-
-	construct_type(unqualified("Pointer") - 0, [], PointerT),
-	PointerType = mercury_type_to_mlds_type(PointerT).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.6
diff -u -r1.6 mlds.m
--- mlds.m	1999/09/09 16:51:42	1.6
+++ mlds.m	1999/09/17 13:52:12
@@ -397,7 +397,30 @@
 		mlds__defns			% contains these members
 	).
 
-:- type mlds__type ---> mlds__type(prog_data__type).
+	% Note: the definition of the `mlds__type' type is subject to change.
+	% In particular, we might add new alternatives here, so try to avoid
+	% switching on this type.
+:- type mlds__type
+	--->	% Mercury data types
+		mercury_type(prog_data__type)
+
+		% The type for the continuation functions used
+		% to handle nondeterminism
+	;	mlds__cont_type
+
+		% MLDS native builtin types.
+		% These are the builtin types of the MLDS target language,
+		% whatever that may be.
+		% Currently we don't actually use many of these.
+	;	mlds__bool_type
+	;	mlds__int_type
+	;	mlds__float_type
+	;	mlds__char_type
+
+		% Pointer types.
+		% Currently these are used for handling output arguments.
+	;	mlds__ptr_type(mlds__type).
+
 :- type mercury_type == prog_data__type.
 
 :- func mercury_type_to_mlds_type(mercury_type) = mlds__type.
@@ -965,7 +988,7 @@
 % Currently mlds__types are just the same as Mercury types.
 % XXX something more complicated may be needed here...
 
-mercury_type_to_mlds_type(Type) = mlds__type(Type).
+mercury_type_to_mlds_type(Type) = mercury_type(Type).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.3
diff -u -r1.3 mlds_to_c.m
--- mlds_to_c.m	1999/09/10 09:51:06	1.3
+++ mlds_to_c.m	1999/09/17 13:52:12
@@ -543,18 +543,28 @@
 :- pred mlds_output_type(mlds__type, io__state, io__state).
 :- mode mlds_output_type(in, di, uo) is det.
 
-mlds_output_type(mlds__type(Type)) -->
+mlds_output_type(mercury_type(Type)) -->
 	( { Type = term__functor(term__atom("character"), [], _) } ->
-		io__write_string("char")
+		io__write_string("Char")
 	; { Type = term__functor(term__atom("int"), [], _) } ->
-		io__write_string("int")
+		io__write_string("Integer")
 	; { Type = term__functor(term__atom("string"), [], _) } ->
 		io__write_string("String")
 	; { Type = term__functor(term__atom("float"), [], _) } ->
 		io__write_string("Float")
 	;
+		% XXX we ought to use pointers to struct types here,
+		% so that distinct Mercury types map to distinct C types
 		io__write_string("Word")
 	).
+mlds_output_type(mlds__cont_type)  --> io__write_string("Cont").
+mlds_output_type(mlds__int_type)   --> io__write_string("int").
+mlds_output_type(mlds__float_type) --> io__write_string("float").
+mlds_output_type(mlds__bool_type)  --> io__write_string("bool").
+mlds_output_type(mlds__char_type)  --> io__write_string("char").
+mlds_output_type(mlds__ptr_type(Type)) -->
+	mlds_output_type(Type),
+	io__write_string(" *").
 
 %-----------------------------------------------------------------------------%
 %

-- 
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