From 9acaa4890c7e336020ebe3eafcb061b1d3b9c1c9 Mon Sep 17 00:00:00 2001 From: Josh Davies Date: Mon, 25 Nov 2024 12:49:17 +0000 Subject: [PATCH 1/2] Add documentation for UNCHANGED_ and ZERO_ --- doc/manual/prepro.tex | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/manual/prepro.tex b/doc/manual/prepro.tex index 5a7e5ba32..44d3f523d 100644 --- a/doc/manual/prepro.tex +++ b/doc/manual/prepro.tex @@ -108,6 +108,14 @@ \section{The preprocessor variables} #endif #enddo \end{verbatim} +\item[UNCHANGED\_] Takes the value 1 if all active expressions were unchanged in the + previous module, and 0 otherwise. `UNCHANGED\_exprname' is 1 if the + expression ``exprname'' was unchanged in the previous module, and + 0 otherwise. +\item[ZERO\_] Takes the value 1 if all active expressions were zero in the + previous module, and 0 otherwise. `ZERO\_exprname' is 1 if the + expression ``exprname'' was zero in the previous module, and + 0 otherwise. \end{description} \noindent If \FORM\ cannot find a preprocessor variable, because it has From 4c8d47e305b06aa92a79b7b7822940305a35ed7b Mon Sep 17 00:00:00 2001 From: Josh Davies Date: Fri, 23 May 2025 16:34:06 +0100 Subject: [PATCH 2/2] Add a simple test for UNCHANGED_ and ZERO_ Currently, UNCHANGED_ is not always "correct", for example when an expression becomes zero due to Multiply 0; --- check/features.frm | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/check/features.frm b/check/features.frm index 5a1ff3c8c..fbdd33de1 100644 --- a/check/features.frm +++ b/check/features.frm @@ -1187,3 +1187,93 @@ else assert runtime_error?('Could not create sort file: bad_path\xformxxx.sor') end *--#] TempSortDir_windows : +*--#[ ZeroUnchanged : +#- + +#procedure exprinfo + #message Module `CMODULE_': + #do e = {`activeexprnames_'} + #if `ZERO_`e'' + #message zero `e': `ZERO_`e'' + #endif + #if `UNCHANGED_`e'' + #message unchanged `e': `UNCHANGED_`e'' + #endif + #enddo + #if `ZERO_' + #message All zero: `ZERO_' + #endif + #if `UNCHANGED_' + #message All unchanged: `UNCHANGED_' + #endif + #message +#endprocedure + + +Off stats; + +Symbol x,y; + +Local test1 = x; +Local test2 = y; +Local test3 = 1; +.sort:1; + +#call exprinfo +Identify x = 0; +.sort:2; + +#call exprinfo +Identify y = 0; +.sort:3; + +#call exprinfo +.sort:4; + +#call exprinfo +Multiply 0; +.sort:5; + +#message Here, test3 is incorrectly flagged as unchanged: +#call exprinfo +Print; +.end +assert succeeded? +assert result("test1") =~ expr("0") +assert result("test2") =~ expr("0") +assert result("test3") =~ expr("0") +assert stdout =~ exact_pattern(<<'EOF') +~~~Module 2: +~~~ +~~~Module 3: +~~~zero test1: 1 +~~~unchanged test2: 1 +~~~unchanged test3: 1 +~~~ +~~~Module 4: +~~~zero test1: 1 +~~~unchanged test1: 1 +~~~zero test2: 1 +~~~unchanged test3: 1 +~~~ +~~~Module 5: +~~~zero test1: 1 +~~~unchanged test1: 1 +~~~zero test2: 1 +~~~unchanged test2: 1 +~~~unchanged test3: 1 +~~~All unchanged: 1 +~~~ +~~~Here, test3 is incorrectly flagged as unchanged: +~~~Module 6: +~~~zero test1: 1 +~~~unchanged test1: 1 +~~~zero test2: 1 +~~~unchanged test2: 1 +~~~zero test3: 1 +~~~unchanged test3: 1 +~~~All zero: 1 +~~~All unchanged: 1 +~~~ +EOF +*--#] ZeroUnchanged :