[m-rev.] diff: intgen
Peter Ross
peter.ross at miscrit.be
Mon Feb 18 09:53:01 AEDT 2002
Hi,
===================================================================
Estimated hours taken: _____
Branches: ______
<overview or general description of changes>
<directory>/<file>:
<detailed description of changes>
intgen.m:
Index: intgen.m
===================================================================
RCS file: /home/mercury1/repository/dotnet/intgen/intgen.m,v
retrieving revision 1.27
diff -u -r1.27 intgen.m
--- intgen.m 17 Feb 2002 17:22:23 -0000 1.27
+++ intgen.m 17 Feb 2002 22:52:36 -0000
@@ -89,7 +89,8 @@
---> parameter(
param_pos :: int,
param_mode :: (mode),
- param_type :: (type)
+ param_type :: (type),
+ param_type_name :: name
).
:- type (mode)
@@ -440,7 +441,8 @@
% need to add the this pointer to the
% parameter list at the beginning.
StaticOrInstance = (instance),
- Params = [parameter(0, in, to_type(ObjectType)) | Params0]
+ Params = [parameter(0, in, to_type(ObjectType),
+ type_to_name(ObjectType)) | Params0]
),
impure ReturnType = get_ReturnType(Method),
@@ -517,7 +519,7 @@
NextPos = Pos + 1,
Mode = in
),
- Param = parameter(Pos, Mode, to_type(Type)),
+ Param = parameter(Pos, Mode, to_type(Type), type_to_name(Type)),
NeededImports = needed_imports(no, Type).
% Given a type determine all of its parent types.
@@ -880,6 +882,7 @@
list__foldl(output_constructor_decl(Indent), Module ^ constructors),
list__foldl(output_function_decl(Indent), Statics),
+ list__foldl(output_constrained_func_decl(Indent), Statics),
list__foldl(output_sub_module_int(no, Indent + 2),
map__values(Module ^ submodules)),
@@ -988,6 +991,7 @@
list__foldl(output_constructor_body(Indent), Module ^ constructors),
list__foldl(output_function_decl(Indent), Instances),
+ list__foldl(output_constrained_func_decl(Indent), Instances),
list__foldl(output_function_body(Indent), Module ^ functions),
list__foldl(output_sub_module_impl(no, Indent + 2),
@@ -1266,15 +1270,160 @@
io__write_string(" is det."),
io__nl.
-/*
:- pred output_constrained_func_decl(int::in, function::in,
io__state::di, io__state::uo) is det.
-output_constrained_func_decl(Indent, Function) -->
- io__write_string(
-*/
-
+output_constrained_func_decl(Indent,
+ function(Id, _Name, MercuryName, _Asm,
+ InstOrStatic, RetType, Params)) -->
+ output_indent(Indent),
+ io__write_string("% :- "),
+ % output_some(merge_parameters(Params, RetType)),
+ output_some(Params),
+ io__write_string(" impure "),
+ ( { RetType = yes(_) },
+ io__write_string("func '")
+ ; { RetType = no },
+ io__write_string("pred '")
+ ),
+ ( { InstOrStatic = (instance) },
+ io__write_string("tc_"),
+ io__write_int(Id),
+ io__write_string("_")
+ ; { InstOrStatic = static },
+ []
+ ),
+ io__write_string(MercuryName),
+ io__write_string("'"),
+ io__nl.
+
+:- func merge_parameters(list(parameter), maybe(parameter)) = list(parameter).
+
+merge_parameters(Params, yes(Param)) = [Param | Params].
+merge_parameters(Params, no) = Params.
+
+:- pred output_some(list(parameter)::in,
+ io__state::di, io__state::uo) is det.
+
+output_some(Params) -->
+ { list__filter(is_exist_type_variable, Params, Exists) },
+ ( { Exists = [_|_] } ->
+ io__write_string("some ["),
+ io__write_list(Exists, ", ", output_type_var),
+ io__write_string("] ")
+ ;
+ []
+ ).
+
+:- pred output_exist_constraints(list(parameter)::in,
+ io__state::di, io__state::uo) is det.
+
+output_exist_constraints(Params) -->
+ { list__filter(is_exist_type_variable, Params, Exists) },
+ ( { Exists = [_|_] } ->
+ io__write_string("=> ("),
+ io__write_list(Exists, ", ", output_param_type_class),
+ io__write_string(")")
+ ;
+ []
+ ).
+
+:- pred output_univ_constraints(list(parameter)::in,
+ io__state::di, io__state::uo) is det.
+
+output_univ_constraints(Params) -->
+ { list__filter(is_univ_type_variable, Params, Exists) },
+ ( { Exists = [_|_] } ->
+ io__write_string("<= ("),
+ io__write_list(Exists, ", ", output_param_type_class),
+ io__write_string(")")
+ ;
+ []
+ ).
+
+:- pred output_param_type_class(parameter::in,
+ io__state::di, io__state::uo) is det.
+
+output_param_type_class(Param) -->
+ io__write_string("'"),
+ output_mercury_name(Param ^ param_type_name),
+ io__write_string("__"),
+ io__write_string(Param ^ param_type_name ^ name),
+ io__write_string("'("),
+ output_type_var(Param),
+ io__write_string(")").
+:- pred output_type_var(parameter::in,
+ io__state::di, io__state::uo) is det.
+
+output_type_var(Param) -->
+ io__write_string("T"),
+ io__write_int(Param ^ param_pos).
+
+:- pred is_univ_type_variable(parameter::in) is semidet.
+
+is_univ_type_variable(Param) :-
+ ( Param ^ param_mode = in
+ ; Param ^ param_mode = byref
+ ),
+ reference = is_ref_or_value(Param ^ param_type).
+
+:- func is_ref_or_value((type)) = ref_or_value.
+
+is_ref_or_value(string) = reference.
+is_ref_or_value(char) = value.
+is_ref_or_value(int) = value.
+is_ref_or_value(type(_, RefOrVal, _)) = RefOrVal.
+is_ref_or_value(array(T)) = is_ref_or_value(T).
+is_ref_or_value(byref(T)) = is_ref_or_value(T).
+
+:- pred is_exist_type_variable(parameter::in) is semidet.
+
+is_exist_type_variable(Param) :-
+ ( Param ^ param_mode = out
+ % XXX byref
+ % ; Param ^ param_mode = byref
+ ),
+ yes = is_sealed(Param ^ param_type).
+
+:- func is_sealed((type)) = bool.
+
+is_sealed(string) = yes.
+is_sealed(char) = yes.
+is_sealed(int) = yes.
+ % XXX Might be!
+is_sealed(type(_, reference, _)) = no.
+is_sealed(type(_, value, _)) = yes.
+is_sealed(array(T)) = is_sealed(T).
+is_sealed(byref(T)) = is_sealed(T).
+
+:- pred output_univ_type_variable(parameter::in,
+ io__state::di, io__state::uo) is det.
+
+output_univ_type_variable(Param) -->
+ ( { Param ^ param_mode = in },
+ io__write_string("T_"),
+ io__write_int(Param ^ param_pos)
+ ; { Param ^ param_mode = out },
+ { error("output_univ_type_variable: output param.") }
+ ; { Param ^ param_mode = byref },
+ io__write_string("T_"),
+ io__write_int(Param ^ param_pos)
+ ).
+
+:- pred output_exist_type_variable(parameter::in,
+ io__state::di, io__state::uo) is det.
+
+output_exist_type_variable(Param) -->
+ ( { Param ^ param_mode = in },
+ { error("output_exist_type_variable: input param.") }
+ ; { Param ^ param_mode = out },
+ io__write_string("T_"),
+ io__write_int(Param ^ param_pos)
+ ; { Param ^ param_mode = byref },
+ io__write_string("T_"),
+ io__write_int(Param ^ param_pos + 1)
+ ).
:- pred output_function_body(int::in, function::in,
io__state::di, io__state::uo) is det.
@@ -1373,9 +1522,8 @@
},
{ WriteCallParam = (pred(Param::in, di, uo) is det -->
- { Param = parameter(_Pos, _Mode, Type) },
output_indent(Indent + 2),
- output_il_type(Type)
+ output_il_type(Param ^ param_type)
)},
io__write_list(CallParams, ",\n", WriteCallParam),
io__nl,
@@ -1389,16 +1537,15 @@
output_store_byrefs(Indent, Params) -->
% Store the by refs.
{ WriteByRef = (pred(Param::in, di, uo) is det -->
- { Param = parameter(Pos, Mode, _) },
- ( { Mode = byref } ->
+ ( { Param ^ param_mode = byref } ->
output_indent(Indent),
io__write_string("ldloc 'Var_"),
- io__write_int(Pos),
+ io__write_int(Param ^ param_pos),
io__write_string("'\n"),
output_indent(Indent),
io__write_string("stloc 'Var_"),
- io__write_int(Pos + 1),
+ io__write_int(Param ^ param_pos + 1),
io__write_string("'\n")
;
[]
@@ -1412,22 +1559,21 @@
output_parameter_list(Params) -->
( { Params = [_|_] } ->
{ WriteVarMode = (pred(Param::in, di, uo) is det -->
- { Param = parameter(Pos, Mode, _PType) },
- ( { Mode = in },
+ ( { Param ^ param_mode = in },
io__write_string("Var_"),
- io__write_int(Pos),
+ io__write_int(Param ^ param_pos),
io__write_string("::in")
- ; { Mode = out },
+ ; { Param ^ param_mode = out },
io__write_string("Var_"),
- io__write_int(Pos),
+ io__write_int(Param ^ param_pos),
io__write_string("::out")
- ; { Mode = byref },
+ ; { Param ^ param_mode = byref },
io__write_string("Var_"),
- io__write_int(Pos),
+ io__write_int(Param ^ param_pos),
io__write_string("::in"),
% XXX byref
%io__write_string(", Var_"),
- %io__write_int(Pos + 1),
+ %io__write_int(Param ^ param_pos + 1),
%io__write_string("::out"),
[]
)
@@ -1444,19 +1590,18 @@
output_load_input_params(Indent, Params) -->
{ WriteInput = (pred(Param::in, di, uo) is det -->
- { Param = parameter(Pos, Mode, _PType) },
output_indent(Indent),
- ( { Mode = in },
+ ( { Param ^ param_mode = in },
io__write_string("ldloc 'Var_"),
- io__write_int(Pos),
+ io__write_int(Param ^ param_pos),
io__write_string("'")
- ; { Mode = out },
+ ; { Param ^ param_mode = out },
io__write_string("ldloca 'Var_"),
- io__write_int(Pos),
+ io__write_int(Param ^ param_pos),
io__write_string("'")
- ; { Mode = byref },
+ ; { Param ^ param_mode = byref },
io__write_string("ldloca 'Var_"),
- io__write_int(Pos),
+ io__write_int(Param ^ param_pos),
io__write_string("'")
),
io__nl
@@ -1465,8 +1610,9 @@
:- pred output_parameter(parameter::in, io__state::di, io__state::uo) is det.
-output_parameter(parameter(_Pos, Mode, Type)) -->
- output_mode(output_sep(output_type(Type)), Mode).
+output_parameter(Param) -->
+ output_mode(output_sep(
+ output_type(Param ^ param_type)), Param ^ param_mode).
:- pred output_sep(pred(io__state, io__state)::pred(di, uo) is det,
io__state::di, io__state::uo) is det.
--------------------------------------------------------------------------
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