[m-rev.] diff negation in trace goals conditions
Ondrej Bojar
bojar at csse.unimelb.edu.au
Wed Feb 21 22:36:30 AEDT 2007
Incorporated Zoltan's and Julien's comments, will commit tomorrow unless more
comments appear.
Estimated hours taken: 2
Added support for negation in conditions (run_time and compile_time) for trace
goals.
compiler/mercury_to_mercury.m:
Output negated conditions.
compiler/ml_code_gen.m:
compiler/pragma_c_gen.m:
Test for negated conditions at run time.
compiler/prog_data.m:
Modified type definition for trace_expr/1 to include negation.
compiler/prog_io_goal.m:
Parsing of negated expressions.
compiler/simplify.m:
Compile-time evaluation of conditions with negation.
doc/reference_manual.texi:
Announced negation. Fixed a copy-paste typo in description of run-time
conditions.
tests/hard_coded/trace_goal_env_3.m:
Added a simple test for negation.
tests/hard_coded/trace_goal_env_3.exp:
Expected result if env-vars are not set.
tests/hard_coded/Mmakefile:
Enabled trace_goal_env_3.
tests/invalid/trace_goal_env.m:
Added a simple malformed trace goal condition.
tests/invalid/trace_goal_env.err_exp:
Expected error message.
tests/invalid/Mmakefile:
Enabled trace_goal_env for C-generating backends only.
Index: compiler/mercury_to_mercury.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.314
diff -u -r1.314 mercury_to_mercury.m
--- compiler/mercury_to_mercury.m 19 Jan 2007 07:04:19 -0000 1.314
+++ compiler/mercury_to_mercury.m 21 Feb 2007 11:02:16 -0000
@@ -2942,6 +2942,11 @@
TraceExpr = trace_base(Base),
PrintBase(Base, !IO)
;
+ TraceExpr = trace_not(TraceExprA),
+ io.write_string("not(", !IO),
+ mercury_output_trace_expr(PrintBase, TraceExprA, !IO),
+ io.write_string(")", !IO)
+ ;
TraceExpr = trace_op(trace_or, TraceExprA, TraceExprB),
io.write_string("(", !IO),
mercury_output_trace_expr(PrintBase, TraceExprA, !IO),
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.196
diff -u -r1.196 ml_code_gen.m
--- compiler/ml_code_gen.m 8 Jan 2007 03:03:11 -0000 1.196
+++ compiler/ml_code_gen.m 21 Feb 2007 11:02:16 -0000
@@ -2476,6 +2476,10 @@
ZeroRval = const(mlconst_int(0)),
CondRval = binop(ne, EnvVarRval, ZeroRval)
;
+ Expr = trace_not(ExprA),
+ ml_generate_runtime_cond_code(ExprA, RvalA, !Info),
+ CondRval = unop(std_unop(logical_not), RvalA)
+ ;
Expr = trace_op(TraceOp, ExprA, ExprB),
ml_generate_runtime_cond_code(ExprA, RvalA, !Info),
ml_generate_runtime_cond_code(ExprB, RvalB, !Info),
Index: compiler/pragma_c_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/pragma_c_gen.m,v
retrieving revision 1.103
diff -u -r1.103 pragma_c_gen.m
--- compiler/pragma_c_gen.m 15 Jan 2007 02:23:48 -0000 1.103
+++ compiler/pragma_c_gen.m 21 Feb 2007 11:02:16 -0000
@@ -432,6 +432,10 @@
ZeroRval = const(llconst_int(0)),
CondRval = binop(ne, EnvVarRval, ZeroRval)
;
+ Expr = trace_not(ExprA),
+ generate_runtime_cond_code(ExprA, RvalA, !CI),
+ CondRval = unop(logical_not, RvalA)
+ ;
Expr = trace_op(TraceOp, ExprA, ExprB),
generate_runtime_cond_code(ExprA, RvalA, !CI),
generate_runtime_cond_code(ExprB, RvalB, !CI),
Index: compiler/prog_data.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.187
diff -u -r1.187 prog_data.m
--- compiler/prog_data.m 15 Jan 2007 10:30:35 -0000 1.187
+++ compiler/prog_data.m 21 Feb 2007 11:02:16 -0000
@@ -916,6 +916,7 @@
:- type trace_expr(Base)
---> trace_base(Base)
+ ; trace_not(trace_expr(Base))
; trace_op(trace_op, trace_expr(Base), trace_expr(Base)).
:- type trace_op
Index: compiler/prog_io_goal.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_io_goal.m,v
retrieving revision 1.50
diff -u -r1.50 prog_io_goal.m
--- compiler/prog_io_goal.m 1 Dec 2006 15:04:16 -0000 1.50
+++ compiler/prog_io_goal.m 21 Feb 2007 11:02:16 -0000
@@ -818,6 +818,18 @@
MaybeTree = error1(LErrors ++ RErrors)
)
;
+ Term = term.functor(term.atom("not"), [SubTerm], _)
+ ->
+ parse_trace_tree(BaseParser, SubTerm, MaybeSubExpr),
+ (
+ MaybeSubExpr = ok1(SubExpr)
+ ->
+ MaybeTree = ok1(trace_not(SubExpr))
+ ;
+ SubErrors = get_any_errors1(MaybeSubExpr),
+ MaybeTree = error1(SubErrors)
+ )
+ ;
BaseParser(Term, MaybeBase),
(
MaybeBase = ok1(Base),
Index: compiler/simplify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.206
diff -u -r1.206 simplify.m
--- compiler/simplify.m 19 Jan 2007 07:04:30 -0000 1.206
+++ compiler/simplify.m 21 Feb 2007 11:02:16 -0000
@@ -1675,6 +1675,8 @@
Result = at_least_at_deep(EffTraceLevel)
)
).
+evaluate_compile_time_condition(trace_not(ExprA), Info) =
+ not(evaluate_compile_time_condition(ExprA, Info)).
evaluate_compile_time_condition(trace_op(Op, ExprA, ExprB), Info) = Result :-
ResultA = evaluate_compile_time_condition(ExprA, Info),
ResultB = evaluate_compile_time_condition(ExprB, Info),
Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.383
diff -u -r1.383 reference_manual.texi
--- doc/reference_manual.texi 13 Feb 2007 12:35:04 -0000 1.383
+++ doc/reference_manual.texi 21 Feb 2007 11:02:16 -0000
@@ -9340,8 +9340,8 @@
or it has to be compiled in a debugging grade.
In general, the single argument of the @samp{compile_time} function symbol
-is a boolean expression that may use the @samp{and} and @samp{or} operators
-to connect one or more primitive compile-time conditions.
+is a boolean expression that may use the @samp{and}, @samp{or} and @samp{not}
+operators to connect one or more primitive compile-time conditions.
There are three kinds of conditions.
The first has the form @samp{flag(@var{FlagName})},
where @var{FlagName} is an arbitrary name picked by the programmer;
@@ -9362,8 +9362,8 @@
(It doesn't matter what value it is set to.)
In general, the single argument of the @samp{run_time} function symbol
-is a boolean expression that may use the @samp{and} and @samp{or} operators
-to connect one or more primitive compile-time conditions.
+is a boolean expression that may use the @samp{and}, @samp{or} and @samp{not}
+operators to connect one or more primitive run-time conditions.
There is just one condition.
It has the form @samp{env(@var{EnvVarName})},
this condition is true
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.309
diff -u -r1.309 Mmakefile
--- tests/hard_coded/Mmakefile 13 Feb 2007 01:59:01 -0000 1.309
+++ tests/hard_coded/Mmakefile 21 Feb 2007 11:02:16 -0000
@@ -330,6 +330,7 @@
foreign_type_assertion \
lookup_disj \
trace_goal_env_1 \
+ trace_goal_env_2 \
trace_goal_env_2
else
C_ONLY_PROGS=
Index: tests/hard_coded/trace_goal_env_3.exp
===================================================================
RCS file: tests/hard_coded/trace_goal_env_3.exp
diff -N tests/hard_coded/trace_goal_env_3.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/trace_goal_env_3.exp 21 Feb 2007 11:02:16 -0000
@@ -0,0 +1 @@
+A: 43xx44
Index: tests/hard_coded/trace_goal_env_3.m
===================================================================
RCS file: tests/hard_coded/trace_goal_env_3.m
diff -N tests/hard_coded/trace_goal_env_3.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/trace_goal_env_3.m 21 Feb 2007 11:02:16 -0000
@@ -0,0 +1,31 @@
+:- module trace_goal_env_3.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+:- import_module int.
+:- import_module string.
+
+main(!IO) :-
+ promise_pure (
+ p(42, A),
+ io.write_string("A: " ++ A ++ "\n", !IO)
+ ).
+
+:- pred p(int::in, string::out) is det.
+
+p(N, S) :-
+ trace [runtime(env("TRACE_ABC")
+ and not(
+ env("TRACE_NEITHER_AB") or env("TRACE_NOR_BC")
+ )),
+ io(!IO)]
+ (
+ io.write_string("Seen ABC and not NOT_ABC.\n", !IO)
+ ),
+ S = int_to_string(N+1) ++ "xx" ++ int_to_string(N+2).
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.208
diff -u -r1.208 Mmakefile
--- tests/invalid/Mmakefile 7 Feb 2007 14:00:44 -0000 1.208
+++ tests/invalid/Mmakefile 21 Feb 2007 11:02:16 -0000
@@ -233,7 +233,8 @@
# The following require that the back-end support the C interface
C_INTERFACE_MODULES = \
- foreign_decl_line_number
+ foreign_decl_line_number \
+ trace_goal_env
# The following require that the compiler not ignore `pragma type_spec'
# declarations
Index: tests/invalid/trace_goal_env.err_exp
===================================================================
RCS file: tests/invalid/trace_goal_env.err_exp
diff -N tests/invalid/trace_goal_env.err_exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/invalid/trace_goal_env.err_exp 21 Feb 2007 11:02:16 -0000
@@ -0,0 +1,3 @@
+trace_goal_env.m:023: Error: runtime takes exactly one argument, which should
be a boolean expression of run-time tests: runtime(env("TRACE_ABC"), not
env("TRACE_NEITHER_AB") or env("TRACE_NOR_BC")).
+trace_goal_env.m:030: Error: invalid trace goal paramater: not
runtime(env("TRACE_ABC")).
+trace_goal_env.m:020: Error: no clauses for predicate `p'/2.
Index: tests/invalid/trace_goal_env.m
===================================================================
RCS file: tests/invalid/trace_goal_env.m
diff -N tests/invalid/trace_goal_env.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/invalid/trace_goal_env.m 21 Feb 2007 11:02:16 -0000
@@ -0,0 +1,34 @@
+:- module trace_goal_env.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+:- import_module int.
+:- import_module string.
+
+main(!IO) :-
+ promise_pure (
+ p(42, A),
+ io.write_string("A: " ++ A ++ "\n", !IO)
+ ).
+
+:- pred p(int::in, string::out) is det.
+
+p(N, S) :-
+ trace [runtime(env("TRACE_ABC"), not(
+ env("TRACE_NEITHER_AB") or env("TRACE_NOR_BC")
+ )),
+ io(!IO)]
+ (
+ io.write_string("Seen ABC and not NOT_ABC.\n", !IO)
+ ),
+ trace [not(runtime(env("TRACE_ABC"))), io(!IO)]
+ (
+ io.write_string("Seen ABC and not NOT_ABC.\n", !IO)
+ ),
+ S = int_to_string(N+1) ++ "xx" ++ int_to_string(N+2).
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list