fixes for two test cases

Zoltan Somogyi zs at cs.mu.OZ.AU
Wed Aug 12 11:36:40 AEST 1998


This is for Simon.

tests/hard_coded/space.{m,out}:
	Use our own random number generator, since the output of random.m
	depends on the wordsize of the machine.

tests/hard_coded/no_inline.{m,out}:
	Use a more direct test of whether the C code is inlined or not.

Zoltan.
cvs diff: Diffing .

Index: no_inline.exp
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/no_inline.exp,v
retrieving revision 1.1
diff -u -u -r1.1 no_inline.exp
--- no_inline.exp	1997/06/27 04:04:48	1.1
+++ no_inline.exp	1998/08/12 02:04:59
@@ -1,4 +1 @@
-I'm going to see whether `bar'/2 is inlined.
-(Remember kids, don't try this one at home.)
-
-It wasn't.
+[0, 1, 2, 3]
Index: no_inline.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/no_inline.m,v
retrieving revision 1.2
diff -u -u -r1.2 no_inline.m
--- no_inline.m	1998/08/12 00:28:41	1.2
+++ no_inline.m	1998/08/12 02:04:18
@@ -6,48 +6,28 @@
 :- import_module io.
 
 :- pred main(io__state::di, io__state::uo) is det.
-:- pred baz(io__state::di, io__state::uo) is det.
 
 :- implementation.
 
-main -->
-	io__write_string("I'm going to see whether `bar'/2 is inlined.\n"),
-	io__write_string("(Remember kids, don't try this one at home.)\n\n"),
-	bar,
-	io__write_string("It wasn't.\n").
+:- import_module list.
 
-:- pragma no_inline(bar/2).
+main -->
+	{
+	bar(A),
+	bar(B),
+	bar(C),
+	bar(D)
+	},
+	io__write([A, B, C, D]),
+	io__write_string("\n").
 
-:- pred bar(io__state::di, io__state::uo) is det.
+:- pragma no_inline(bar/1).
+:- pred bar(int::out) is det.
 
-:- pragma c_header_code("
-#include <stdio.h>
-").
-
-:- pragma c_code(bar(IO0::di, IO::uo), will_not_call_mercury, "
-	/* START INLINING */
+:- pragma c_code(bar(Value::out), "
 {
-	static int i = 0;
-	IO = IO0;
-
-	/* Check if I get run again - I'm supposed to only execute once! */
+	static int counter = 0;
 
-	if (i > 0) { 
-		printf(""bar/2: You inlined me!\n""
-			""Read my lips, `no_inline'\n\n"");
-		    fatal_error(""pragma no_inline ignored."");
-	}
-	i++;
-
-	tailcall(ENTRY(mercury__no_inline__baz_2_0),
-			ENTRY(mercury__no_inline__bar_2_0));
-	/* END INLINING */
+	Value = counter++;
 }
 ").
-
-
-:- pragma c_code(baz(IO0::di, IO::uo), will_not_call_mercury, "
-	IO = IO0;
-	proceed();
-").
-
Index: space.exp
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/space.exp,v
retrieving revision 1.1
diff -u -u -r1.1 space.exp
--- space.exp	1998/07/29 08:57:08	1.1
+++ space.exp	1998/08/12 03:26:09
@@ -1,30 +1,30 @@
 a2 d3 f3
 a2 c3 e3
+g#2 c3 f3
+g2 c3 e3
+a#2 d3 f3
+a2 c3 e3
+f2 a2 d3
+e2 a2 c3
 f2 a#2 d3
 e2 g2 c3
 f2 a2 d3
-a2 c3 e3
-a2 d3 f3
 a2 c3 e3
-g#2 c3 f3
-c3 e3 g3
-c3 f3 a3
-d3 g3 a#3
-c3 f3 a3
-d3 g3 a#3
-e3 g3 c4
-d3 f3 a#3
-c3 e3 a3
-d3 f3 a#3
-e3 a3 c4
-f3 a#3 d4
-e3 a3 c4
-f3 a#3 d4
-e3 g3 c4
-d3 f3 a#3
-c3 f3 a3
-a#2 d3 g3
+f2 a2 d3
+g2 c3 e3
 a2 c3 f3
 g2 c3 e3
-g2 a#2 d3
+a#2 d3 f3
+a2 c3 e3
+f2 a2 d3
+e2 g2 c3
+f2 a2 d3
+a2 c3 e3
+a#2 d3 f3
+g2 c3 e3
+f2 a2 d3
 f2 a2 c3
+g2 a#2 d3
+e2 a2 c3
+f2 a#2 d3
+e2 g2 c3
Index: space.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/space.m,v
retrieving revision 1.1
diff -u -u -r1.1 space.m
--- space.m	1998/07/29 08:57:09	1.1
+++ space.m	1998/08/12 03:21:22
@@ -23,7 +23,7 @@
 
 :- implementation.
 
-:- import_module char, string, int, list, std_util, random, require.
+:- import_module char, string, int, list, std_util, require.
 :- import_module getopt, bool.
 
 :- type option
@@ -118,7 +118,7 @@
 		->
 			{ getopt__lookup_int_option(Opts, length, Len) },
 			{ getopt__lookup_int_option(Opts, seed, Seed) },
-			{ random__init(Seed, Rnd) },
+			{ random_init(Seed, Rnd) },
 			{ Chord0 = chord(i, Kind, up(ii)) },
 			doit(Len, Note, Qual, Chord0, Rnd)
 		;
@@ -158,7 +158,7 @@
 figure_key("b", note(b, natural, 2), maj, maj).
 figure_key("bM", note(b, natural, 2), min, min).
 
-:- pred doit(int, note, qualifier, chord, random__supply, io__state, io__state).
+:- pred doit(int, note, qualifier, chord, random_supply, io__state, io__state).
 :- mode doit(in, in, in, in, mdi, di, uo) is det.
 
 doit(N, Trans, Qual, Chord0, Rnd0) -->
@@ -171,7 +171,7 @@
 		{ list__map(trans(Trans), Notes0, Notes) },
 		write_chord(Notes),
 		(
-			{ random__random(I, Rnd0, Rnd) },
+			{ random_random(I, Rnd0, Rnd) },
 			{ next_chord(Chord0, Qual, I, Chord1) }
 		->
 			{ N1 is N - 1 },
@@ -402,7 +402,7 @@
 	note_to_interval(Note, Qual, Int, Oct).
 
 :- pred note_to_interval(note, qualifier, interval, octave).
-:- mode note_to_interval(in, in, out, out) is nondet. % xxx
+:- mode note_to_interval(in, in, out, out) is semidet.
 :- mode note_to_interval(out, in, in, in) is multi.
 
 note_to_interval(note(c, natural, Oct), _, i, Oct).
@@ -748,5 +748,27 @@
 	io__write_string(StdErr,
 "usage: space [-h|--help] [-k|--key key[M]] [-l|--length n] [-s|--seed n]\n"
 ).
+
+%------------------------------------------------------------------------------%
+
+% This is a very bad number generator. Its only virtue is that
+% unlike random.m, its behavior does not depend on word size.
+
+:- type random_supply == int.
+
+:- pred random_init(int::in, random_supply::muo) is det.
+
+random_init(Seed, Supply) :-
+	copy(Seed, Supply).
+
+:- pred random_random(int::out, random_supply::mdi, random_supply::muo) is det.
+
+random_random(Value, Supply0, Supply) :-
+	Value = Supply0,
+	( Supply0 < 100 ->
+		Supply is Supply0 + 1
+	;
+		Supply is 0
+	).
 
 %------------------------------------------------------------------------------%
cvs diff: Diffing typeclasses



More information about the developers mailing list