[m-dev.] for review: allow io__read for some univs
Mark Anthony BROWN
dougl at cs.mu.OZ.AU
Wed Oct 20 17:09:52 AEST 1999
Hi,
This is a fairly simple change, but should be reviewed since
it will be visible in the documentation.
Cheers,
Mark.
Estimated hours taken: 0.5
Allow io__read, term__term_to_type, etc, to read in some values of
type univ.
library/io.m:
Fix a misleading comment---some limitations of `io__read'
were not explicit.
library/term.m:
Add some extra cases to `term_to_univ_special_case', to
handle values of type `univ' which contain either an
int, a float or a string.
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.186
diff -u -r1.186 io.m
--- io.m 1999/10/18 15:46:27 1.186
+++ io.m 1999/10/20 06:29:47
@@ -281,10 +281,12 @@
% For higher-order types, or for types defined using the
% foreign language interface (pragma c_code), the text output
% will only describe the type that is being printed, not the
-% value, and the result may not be parsable by io__read.
-% But in all other cases the format used is standard Mercury
-% syntax, and if you do append a period and newline (".\n"),
-% then the results can be read in again using `io__read'.
+% value, and the result may not be parsable by `io__read'.
+% For the types `univ' and `typeinfo', the result may not
+% be parsable by `io__read', either. But in all other cases
+% the format used is standard Mercury syntax, and if you do
+% append a period and newline (".\n"), then the results can
+% be read in again using `io__read'.
:- pred io__nl(io__state, io__state).
:- mode io__nl(di, uo) is det.
Index: library/term.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/term.m,v
retrieving revision 1.90
diff -u -r1.90 term.m
--- term.m 1999/10/18 11:13:42 1.90
+++ term.m 1999/10/20 04:08:57
@@ -472,12 +472,30 @@
term__term_to_univ_special_case("builtin", "c_pointer", _, _, _,
_, _) :-
fail.
-term__term_to_univ_special_case("std_util", "univ", _, _, _, _, _) :-
+term__term_to_univ_special_case("std_util", "univ", [], Term, _, _, Result) :-
% Implementing this properly would require keeping a
% global table mapping from type names to type_infos
% for all of the types in the program...
- % so for the moment, we don't allow it.
- fail.
+ % so for the moment, we only allow it for basic types.
+ Term = term__functor(term__atom("univ"), [Arg], _),
+ Arg = term__functor(term__atom(":"), [Value, Type], _),
+ (
+ Type = term__functor(term__atom("int"), [], _),
+ Value = term__functor(term__integer(Int), [], _),
+ Univ = univ(Int)
+ ;
+ Type = term__functor(term__atom("string"), [], _),
+ Value = term__functor(term__string(String), [], _),
+ Univ = univ(String)
+ ;
+ Type = term__functor(term__atom("float"), [], _),
+ Value = term__functor(term__float(Float), [], _),
+ Univ = univ(Float)
+ ),
+ % The result is a `univ', but it is also wrapped in a `univ'
+ % like all the other results returned from this procedure.
+ Result = ok(univ(Univ)).
+
term__term_to_univ_special_case("std_util", "type_info", _, _, _, _, _) :-
% ditto
fail.
--
Mark Brown, PhD student )O+ | "Another of Fortran's breakthroughs
(m.brown at cs.mu.oz.au) | was the GOTO statement, which was...
Dept. of Computer Science and Software | uniquely simple and understandable"
Engineering, University of Melbourne | -- IEEE, 1994
--------------------------------------------------------------------------
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