[m-dev.] for review: remove fact_table compiler warnings
David Overton
dmo at cs.mu.OZ.AU
Wed Aug 18 12:38:46 AEST 1999
Hi,
Zoltan, would you please review this.
David
Estimated hours taken: 1.5
compiler/fact_table.m:
Make some changes to the generated C code to remove C compiler
warnings.
tests/hard_coded/Mmakefile:
tests/hard_coded/factt_non.m:
tests/hard_coded/factt_non.exp:
tests/hard_coded/factt_non_examples:
Add a test case for nondet and multi `pragma fact_tables'.
Index: compiler//fact_table.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/fact_table.m,v
retrieving revision 1.25
diff -u -r1.25 fact_table.m
--- fact_table.m 1999/06/01 09:43:41 1.25
+++ fact_table.m 1999/08/18 02:11:17
@@ -1416,8 +1416,12 @@
{ proc_id_to_int(ProcID, ProcInt) },
{ string__format("%s_hash_table_%d_",
[s(StructName), i(ProcInt)], HashTableName) },
- { string__format("extern %s0;\n", [s(HashTableName)],
- C_HeaderCode0) },
+ { string__format(
+ "extern struct fact_table_hash_table_i %s0;\n",
+ [s(HashTableName)], C_HeaderCode0) },
+ % Note: the type declared here is not
+ % necessarily correct. The type is declared
+ % just to stop the C compiler emitting warnings.
{ map__lookup(ProcTable, ProcID, ProcInfo) },
{ proc_info_argmodes(ProcInfo, ArgModes) },
read_sort_file_line(FactArgInfos, ArgModes, ModuleInfo,
@@ -1489,8 +1493,11 @@
{ proc_id_to_int(ProcID, ProcInt) },
{ string__format("%s_hash_table_%d_",
[s(StructName), i(ProcInt)], HashTableName) },
- { string__format("extern %s0;\n", [s(HashTableName)],
- C_HeaderCode1) },
+ { string__format("extern struct fact_table_hash_table_i %s0;\n",
+ [s(HashTableName)], C_HeaderCode1) },
+ % Note: the type declared here is not
+ % necessarily correct. The type is declared
+ % just to stop the C compiler emitting warnings.
{ string__append(C_HeaderCode1, C_HeaderCode0,
C_HeaderCode2) },
{ map__lookup(ProcTable, ProcID, ProcInfo) },
@@ -2356,7 +2363,7 @@
write_fact_table_pointer_array(NumFacts, StructName, OutputStream,
C_HeaderCode) -->
{ string__append_list(
- ["struct ", StructName, "_struct *", StructName, "[]"],
+ ["const struct ", StructName, "_struct *", StructName, "[]"],
PointerArrayName) },
{ string__append_list(["extern ", PointerArrayName, ";\n"],
C_HeaderCode) },
@@ -2735,7 +2742,7 @@
Integer hashval, hashsize;
Word ind;
void *current_table;
- char keytype;
+ char keytype = '\\0';
Word current_key, tmp;
/*
Index: tests//hard_coded/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/hard_coded/Mmakefile,v
retrieving revision 1.62
diff -u -r1.62 Mmakefile
--- Mmakefile 1999/07/12 06:25:42 1.62
+++ Mmakefile 1999/08/18 02:16:48
@@ -38,6 +38,7 @@
expand \
export_test \
factt \
+ factt_non \
float_map \
float_reg \
float_rounding_bug \
Index: tests//hard_coded/factt_non.exp
===================================================================
RCS file: factt_non.exp
diff -N factt_non.exp
--- /dev/null Wed Aug 18 12:16:58 1999
+++ factt_non.exp Wed Aug 18 10:03:23 1999
@@ -0,0 +1,4 @@
+yes - no
+yes("foo") - no
+yes("bar") - no
+["1", "1.0", "bar", "foo"]
Index: tests//hard_coded/factt_non.m
===================================================================
RCS file: factt_non.m
diff -N factt_non.m
--- /dev/null Wed Aug 18 12:16:58 1999
+++ factt_non.m Wed Aug 18 10:01:18 1999
@@ -0,0 +1,68 @@
+:- module factt_non.
+:- interface.
+
+:- import_module io.
+:- pred main(io__state::di, io__state::uo) is cc_multi.
+
+:- implementation.
+
+:- import_module int, float, string.
+:- import_module std_util, list, bool.
+
+:- pred example(int, float, string).
+:- mode example(in, in, in) is semidet.
+:- mode example(in, in, out) is nondet.
+:- mode example(in, out, out) is nondet.
+:- mode example(out, out, out) is multi.
+
+:- pragma fact_table(example/3,"factt_non_examples").
+
+main -->
+ { test_in_in_in(Result1) },
+ { test_in_in_out(Result2) },
+ { test_in_out_out(Result3) },
+ { test_out_out_out(Result4) },
+ print(Result1), nl,
+ print(Result2), nl,
+ print(Result3), nl,
+ print(Result4), nl.
+
+:- pred test_in_in_in(pair(bool)::out) is det.
+
+test_in_in_in(Res1 - Res2) :-
+ Res1 = ( example(2, 2.0, "2.0") -> yes ; no ),
+ Res2 = ( example(42, 2.0, "foobar") -> yes ; no ).
+
+:- pred test_in_in_out(pair(maybe(string))::out) is cc_multi.
+
+test_in_in_out(Res1 - Res2) :-
+ Res1 = ( example(42, 3.0, S1) -> yes(S1) ; no ),
+ Res2 = ( example(42, 2.0, S2) -> yes(S2) ; no ).
+
+:- pred test_in_out_out(pair(maybe(string))::out) is cc_multi.
+
+test_in_out_out(Res1 - Res2) :-
+ (
+ example(42, F1, S1),
+ F1 > 10.0
+ ->
+ Res1 = yes(S1)
+ ;
+ Res1 = no
+ ),
+ (
+ example(2, F2, S2),
+ F2 > 10.0
+ ->
+ Res2 = yes(S2)
+ ;
+ Res2 = no
+ ).
+
+:- pred test_out_out_out(list(string)::out) is det.
+
+test_out_out_out(Res) :-
+ solutions((pred(S::out) is nondet :-
+ example(N, F, S),
+ ( N > 10 ; F < 1.5 )
+ ), Res).
Index: tests//hard_coded/factt_non_examples
===================================================================
RCS file: factt_non_examples
diff -N factt_non_examples
--- /dev/null Wed Aug 18 12:16:58 1999
+++ factt_non_examples Wed Aug 18 09:59:35 1999
@@ -0,0 +1,7 @@
+example(1, 1.0, "1").
+example(1, 1.0, "1.0").
+example(2, 2.0, "2").
+example(2, 2.0, "2.0").
+example(42, 3.0, "foo").
+example(42, 42.5, "bar").
+
--
David Overton Department of Computer Science & Software Engineering
MEngSc Student The University of Melbourne, Australia
+61 3 9344 9159 http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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