Files
mercury/tests/invalid/string_format_bad.m
Simon Taylor f1275fa6e8 Implement io.write for arbitrary streams. With type specialization
Estimated hours taken: 25
Branches: main

Implement io.write for arbitrary streams.  With type specialization
this is only slightly slower than the original.

library/stream.string_writer.m:
library/library.m:
	A module containing predicates for writing to streams
	which accept strings.

library/stream.m:
	Move stream.format to stream.string_writer.m.

	Add stream.put_list, which is like io.write_list.

library/io.m:
	Move io.write and io.print to stream.string_writer.m.

library/term_io.m:
	Add stream versions of predicates used by io.write.

library/ops.m:
	Move io.adjust_priority_for_assoc to here (private
	predicate used only by library modules).

	Export ops.mercury_max_priority for use by
	stream.string_writer.write.

Mmake.common.in:
compiler/modules.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
compiler/prog_util.m:
compiler/format_call.m:
mdbcomp/prim_data.m:
	Allow sub-modules in the standard library.

compiler/polymorphism.m:
	Fix a bug which caused tests/hard_coded/print_stream.m to
	fail with this change.  The wrong argument type_info would
	be extracted from a typeclass_info if the constraints of the
	typeclass-info were not all variables.

browser/browse.m:
tests/hard_coded/stream_format.m:
tests/hard_coded/test_injection.m:
tests/invalid/string_format_bad.m:
tests/invalid/string_format_unknown.m:
	Updated for predicates moved between library modules.

util/mdemangle.c:
	The demangler doesn't properly handle the arguments MR_DECL_LL*
	and various other recently added macros for type specialized
	procedures.  It's still broken (it doesn't handle mode and label
	suffixes properly), but the output is at least more readable.
2006-12-21 11:11:37 +00:00

65 lines
1.4 KiB
Mathematica

% vim: ts=4 sw=4 expandtab ft=mercury
:- module string_format_bad.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module bool.
:- import_module float.
:- import_module int.
:- import_module list.
:- import_module stream, stream.string_writer.
:- import_module string.
main(!IO) :-
S1 = string.format("", [s("x1")]),
io.write_string(S1, !IO),
S2 = string.format("%d", [s("x2")]),
io.write_string(S2, !IO),
io.stdout_stream(OutputStream, !IO),
io.format("%d", [s("x3")], !IO),
io.format(OutputStream, "%d", [s("x4")], !IO),
stream.string_writer.format(OutputStream, "%d", [s("x4")], !IO),
io.format("%w", [i(5)], !IO),
io.write_string(p(s("five")), !IO),
F6 = "%s %f",
make_bool(6, T6),
(
T6 = yes,
V6A = i(6)
->
V6 = [s("six"), V6A],
io.format(OutputStream, F6, V6, !IO),
make_bool(7, T7),
F7 = "%d %s %d",
(
T7 = yes,
io.format(OutputStream, F7, [f(7.0) | V6], !IO)
;
T7 = no
)
;
true
).
:- pred make_bool(int::in, bool::out) is det.
make_bool(_, yes).
:- func t(string) = string.
t(S) = S.
:- func p(string.poly_type) = string.
p(s(S)) = t(string.format("%s", [s(S)])).
p(c(C)) = t(string.format("%c", [c(C)])).
p(i(I)) = t(string.format("%d", [i(I)])).
p(f(F)) = t(string.format("%f", [f(F)])).