[m-dev.] for review: Added a new format "newpretty" to the browser.

Sarvamanan THURAIRATNAM sthur at students.cs.mu.oz.au
Mon Feb 12 17:42:44 AEDT 2001


Estimated hours taken : 180 

For Mark Brown to Review. 

Added a new pretty printing format to the term browser. This new format 
helps put a limit on the size of the term printed during debugging. 
This limit is specified by setting the number of lines you want the term to be 
printed on and the width of these lines. Refer to sized_pretty.m for 
Examples. 

browser/sized_pretty.m: 
	New file that does what's described above. 

browser/browse.m: 
browser/browser_info.m: 
browser/parse.m: 
trace/mercury_trace_browse.c: 
trace/mercury_trace_browse.h: 
trace/mercury_trace_internal.c: 
	Modified to accommodate the new format. 

This is a relative diff between the newest version of the code and the 
previous version I posted:

The first change is:
Before in the first_pass, after the limit is reached the arguments are not 
annotated. I have changed that so if the limit is reached the rest of the arguments
are annontated with their share. This way more information is given to second_pass.

--- /home/stude/s/sthur/oldsized_pretty.m	Sat Feb 10 12:56:02 2001
+++ /home/stude/s/sthur/Review/mercury/browser/sized_pretty.m	Sat Feb 10 15:35:14 2001
@@ -315,8 +315,12 @@
 		[MaybeFlaggedSize | MaybeFlaggedSizes]) :-
 	(
 		Flag = yes(ArgLimit),
-		AppliedArgLimit = max_measure(ArgLimit,
-			subtract_measures(Limit, SoFar0, Params)),
+		( compare_measures(SoFar0, Limit) = (>) ->
+			AppliedArgLimit = ArgLimit
+		;
+			AppliedArgLimit = max_measure(ArgLimit,
+				subtract_measures(Limit, SoFar0, Params))
+		),
 		first_pass(Arg, Params, AppliedArgLimit, Size),
 		MaybeFlaggedSize = yes(ArgLimit - Size),
 		extract_size_from_annotation(Size) = ArgSize,
@@ -335,14 +339,12 @@
 		Exact1 = Exact0
 	),
 	( compare_measures(SoFar1, Limit) = (>) ->
-		SoFar = SoFar1,
-		Exact = no,
-		annotate_args_with_zero_size(FlaggedArgs, zero_measure,
-			MaybeFlaggedSizes)
+		Exact2 = no
 	;
-		annotate_args_with_size(FlaggedArgs, Params, Limit,
-			SoFar1, SoFar, Exact1, Exact, MaybeFlaggedSizes)
-	).
+		Exact2 = Exact1
+	),
+	annotate_args_with_size(FlaggedArgs, Params, Limit, SoFar1, SoFar, 
+		Exact2, Exact, MaybeFlaggedSizes).
 
 %------------------------------------------------------------------------------%
The second change is:
check_args function now takes an extra argument, so the functor size can be passed
to it initially. It will then add the sizes of the arguments to it. Before the
functor size is not considered in check_args.

	% Annotates the arguments with zero limit.
@@ -402,8 +404,9 @@
 		( if Flag = yes(X) then
 	    		ArgLimit = X,
 	    		check_args(NewParams, MaybeArgs, ArgLimit, Passed, 
-				Used),
-			LeftOver = subtract_measures(NewLimit, Used, Params),
+				FSize, Used),
+			LeftOver = add_measures(subtract_measures(NewLimit, 
+			  	Used, Params), FSize, Params),
 	    		measured_split(Univ, Params, LeftOver, Arity - Passed, 
 				no, _, Flag2, _, _),
 	    		( if Flag2 = yes(Y) then
@@ -438,28 +441,29 @@
 	% obey the Limit and are fully represented("exact") and "Used"
 	% represents the space that these terms take up.
 :- pred check_args(MeasureParams::in, list(maybe(pair(T, size_annotated_term(T)
-	)))::in, T::in, int::out, T::out) is det
+	)))::in, T::in, int::out, T::in, T::out) is det
 	<= measure_with_params(T, MeasureParams).
 
-check_args(_, [], _, 0, zero_measure).
-check_args(Params, [HeadArg | Rest], ArgLimit, Passed, Used) :-
+check_args(_, [], _, 0, Used0, Used0).
+check_args(Params, [HeadArg | Rest], ArgLimit, Passed, Used0, Used) :-
 	if HeadArg = yes(X) then
 		X = _ - STerm,
 		Size = extract_size_from_annotation(STerm), 
 		( if STerm = exact(_, _, _, _, _) then
 	    		( if compare_measures(ArgLimit, Size) = (<) then
-	    			check_args(Params, Rest, ArgLimit, Passed, Used)
+	    			check_args(Params, Rest, ArgLimit, Passed, 
+					Used0, Used)
 	    		else
 	    			Passed = 1 + PassedRest,
-				Used = add_measures(UsedRest, Size, Params),
+				UsedSofar = add_measures(Used0, Size, Params),
 	    			check_args(Params, Rest, ArgLimit, PassedRest, 
-					UsedRest)
+					UsedSofar, Used)
 	    		)
 		else
-	    		check_args(Params, Rest, ArgLimit, Passed, Used)
+	    		check_args(Params, Rest, ArgLimit, Passed, Used0, Used)
 		)
     	else
-		check_args(Params, Rest, ArgLimit, Passed, Used).
+		check_args(Params, Rest, ArgLimit, Passed, Used0, Used).
 
 %------------------------------------------------------------------------------%
 	% This predicate accepts a list of size annotated terms(paired

The Folllowing is the diff for tests directory:

? hard_coded/exceptions/CLEAN
? hard_coded/purity/CLEAN
Index: debugger/browse_pretty.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/browse_pretty.exp,v
retrieving revision 1.3
diff -u -r1.3 browse_pretty.exp
--- debugger/browse_pretty.exp	2000/10/27 08:38:54	1.3
+++ debugger/browse_pretty.exp	2001/02/12 06:19:56
@@ -6,7 +6,7 @@
 mdb> print *
        HeadVar__1             	big(big(big(small, ./2, small), .(1, ./2), small), .(1, .(2, ./2)), big(big(small, ./2, big/3), ./2, small))
 mdb> browse 1
-browser> set format pretty
+browser> set format raw_pretty
 browser> set depth 10
 browser> ls
 big(
@@ -143,6 +143,41 @@
   big(big(small, ./2, small), .(1, ./2), small), 
   .(1, .(2, ./2)), 
   big(big(small, ./2, big/3), .(1, ./2), small))
+browser> set format pretty
+browser> set lines 4
+browser> set width 40
+browser> ls
+big(
+  big(big/3, .(1, ./2), small), 
+  .(1, .(2, .(3, []))), 
+  big(big/3, .(1, ./2), small))
+browser> set width 80
+browser> ls
+big(
+  big(big(small, .(1, []), small), .(1, .(2, [])), small), 
+  .(1, .(2, .(3, []))), 
+  big(big(small, ./2, big/3), .(1, .(2, .(3, ./2))), small))
+browser> set lines 12
+browser> set width 40
+browser> ls
+big(
+  big(
+    big(small, .(1, []), small), 
+    .(1, .(2, [])), 
+    small), 
+  .(1, .(2, .(3, []))), 
+  big(
+    big(small, .(1, ./2), big/3), 
+    .(1, .(2, .(3, .(4, .(5, ./2))))), 
+    small))
+browser> cd 3
+browser> set lines 4
+browser> set width 30
+browser> ls
+big(
+  big(small, ./2, big/3), 
+  .(1, .(2, .(3, ./2))), 
+  small)
 browser> quit
 mdb> continue
 big(big(big(small, [1], small), [1, 2], small), [1, 2, 3], big(big(small, [1, 2, 3, 4], big(small, [1, 2, 3, 4, 5], small)), [1, 2, 3, 4, 5, 6], small)).
Index: debugger/browse_pretty.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/browse_pretty.inp,v
retrieving revision 1.2
diff -u -r1.2 browse_pretty.inp
--- debugger/browse_pretty.inp	2000/10/27 08:38:54	1.2
+++ debugger/browse_pretty.inp	2001/02/12 06:19:56
@@ -2,7 +2,7 @@
 goto 3
 print *
 browse 1
-set format pretty
+set format raw_pretty
 set depth 10
 ls
 set width 131
@@ -13,6 +13,19 @@
 ls
 set width 79
 set depth 3
+ls
+set format pretty
+set lines 4
+set width 40
+ls
+set width 80
+ls
+set lines 12
+set width 40
+ls
+cd 3
+set lines 4
+set width 30
 ls
 quit
 continue

--------------------------------------------------------------------------
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