[m-rev.] for review: negation in trace goals conditions

Ondrej Bojar bojar at csse.unimelb.edu.au
Tue Feb 20 13:50:58 AEDT 2007


(Sorry for the bad diff format, new machine, bad defaults.)

Estimated hours taken: 1

Added support for negating literals in conditions (run_time and 
compile_time)
for trace goals.

NEWS:
     Announced negation in trace goal conditions literals.

compiler/mercury_to_mercury.m:
     Output of negated conditions.

compiler/ml_code_gen.m:
     Test for negated conditions at run time.

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 of 
literals.

compiler/prog_io_goal.m:
     Parsing of negated literals.

compiler/simplify.m:
     Compile-time evaluation of conditions with negated literals.

doc/reference_manual.texi:
     Announced negation of literals. 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 on literals.

tests/hard_coded/trace_goal_env_3.exp:
     Expected result if env-vars are not set.

Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.447
diff -u -r1.447 NEWS
--- NEWS	15 Feb 2007 00:41:47 -0000	1.447
+++ NEWS	20 Feb 2007 02:46:57 -0000
@@ -16,6 +16,8 @@
    escape sequence.
  * promise_equivalent_solutions scopes (et al.) must now also list 
variables
    with inst any that may be constrained by the goal.
+* Conditions (run_time and compile_time) in trace goals allow negation of
+  literals.

  Changes to the Mercury standard library:

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	20 Feb 2007 02:46:57 -0000
@@ -2942,6 +2942,11 @@
          TraceExpr = trace_base(Base),
          PrintBase(Base, !IO)
      ;
+        TraceExpr = trace_not_base(Base),
+        io.write_string("not(", !IO),
+        PrintBase(Base, !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	20 Feb 2007 02:46:57 -0000
@@ -2476,6 +2476,12 @@
          ZeroRval = const(mlconst_int(0)),
          CondRval = binop(ne, EnvVarRval, ZeroRval)
      ;
+        Expr = trace_not_base(trace_envvar(EnvVar)),
+        ml_gen_info_add_env_var_name(EnvVar, !Info),
+        EnvVarRval = lval(global_var_ref(env_var_ref(EnvVar))),
+        ZeroRval = const(mlconst_int(0)),
+        CondRval = binop(eq, EnvVarRval, ZeroRval)
+    ;
          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	20 Feb 2007 02:46:57 -0000
@@ -432,6 +432,14 @@
          ZeroRval = const(llconst_int(0)),
          CondRval = binop(ne, EnvVarRval, ZeroRval)
      ;
+        Expr = trace_not_base(trace_envvar(EnvVar)),
+        get_used_env_vars(!.CI, UsedEnvVars0),
+        set.insert(UsedEnvVars0, EnvVar, UsedEnvVars),
+        set_used_env_vars(UsedEnvVars, !CI),
+        EnvVarRval = lval(global_var_ref(env_var_ref(EnvVar))),
+        ZeroRval = const(llconst_int(0)),
+        CondRval = binop(eq, EnvVarRval, ZeroRval)
+    ;
          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	20 Feb 2007 02:46:57 -0000
@@ -916,6 +916,7 @@

  :- type trace_expr(Base)
      --->    trace_base(Base)
+    ;       trace_not_base(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	20 Feb 2007 02:46:57 -0000
@@ -818,6 +818,18 @@
              MaybeTree = error1(LErrors ++ RErrors)
          )
      ;
+        Term = term.functor(term.atom("not"), [SubTerm], _)
+    ->
+        BaseParser(SubTerm, MaybeSubExpr),
+        (
+            MaybeSubExpr = ok1(SubExpr)
+        ->
+            MaybeTree = ok1(trace_not_base(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	20 Feb 2007 02:46:57 -0000
@@ -1675,6 +1675,8 @@
              Result = at_least_at_deep(EffTraceLevel)
          )
      ).
+evaluate_compile_time_condition(trace_not_base(Base), Info) =
+    not(evaluate_compile_time_condition(trace_base(Base), 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	20 Feb 2007 02:46:57 -0000
@@ -9341,7 +9341,8 @@

  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.
+to connect one or more primitive compile-time conditions. The primitive
+conditions can be negated with @samp{not}.
  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;
@@ -9363,7 +9364,8 @@

  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.
+to connect one or more primitive run-time conditions. The primitive
+conditions can be negated with @samp{not}.
  There is just one condition.
  It has the form @samp{env(@var{EnvVarName})},
  this condition is true
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	20 Feb 2007 02:46:58 -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	20 Feb 2007 02:46:58 -0000
@@ -0,0 +1,28 @@
+:- 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_NOT_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