From bfbb5533d92c5c6ebb426b8a05a978156d4acbed Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 21 Nov 2001 04:47:44 +0000 Subject: [PATCH] some small progress made [SVN r11760] --- new/assert.jam | 34 +++++++------------------- new/errors.jam | 46 +++++++++++++++++++++++++++++++++++ new/modules.jam | 41 +++++++++++++++++++++++++------ new/numbers.jam | 59 +++++++++++++++++++++++++++++++++++++++++++++ new/regex.jam | 12 ++++----- new/set.jam | 31 ++++++++++++++++++++++++ new/ultility.jam | 27 +++++++++++++++++++++ v2/errors.jam | 46 +++++++++++++++++++++++++++++++++++ v2/modules.jam | 41 +++++++++++++++++++++++++------ v2/ultility.jam | 27 +++++++++++++++++++++ v2/util/assert.jam | 34 +++++++------------------- v2/util/numbers.jam | 59 +++++++++++++++++++++++++++++++++++++++++++++ v2/util/regex.jam | 12 ++++----- v2/util/set.jam | 31 ++++++++++++++++++++++++ 14 files changed, 424 insertions(+), 76 deletions(-) create mode 100644 new/errors.jam create mode 100644 new/numbers.jam create mode 100644 new/set.jam create mode 100644 new/ultility.jam create mode 100644 v2/errors.jam create mode 100644 v2/ultility.jam create mode 100644 v2/util/numbers.jam create mode 100644 v2/util/set.jam diff --git a/new/assert.jam b/new/assert.jam index 2327c0e67..04f2c8282 100644 --- a/new/assert.jam +++ b/new/assert.jam @@ -3,22 +3,17 @@ # all copies. This software is provided "as is" without express or implied # warranty, and with no claim as to its suitability for any purpose. -rule report-module ( prefix ? : suffix ? ) -{ - # We report some large line number so that emacs, etc., will at least locate the file. - ECHO $(prefix) [ modules.binding [ CALLER_MODULE 1 ] ] ":" line 99999 $(suffix) ; -} +import errors : error ; rule equal ( a * : b * ) { if $(a) != $(b) { - report-module ; - EXIT assertion failure: \"$(a)\" "!=" \"$(b)\" ; + error assertion failure: \"$(a)\" "!=" \"$(b)\" ; } } -rule Rule ( rule-name args * : expected * ) +rule result ( expected * : rule-name args * ) { module [ CALLER_MODULE ] @@ -28,20 +23,18 @@ rule Rule ( rule-name args * : expected * ) if $(result) != $(expected) { - report-module ; - ECHO assertion failure: "[" $(rule-name) \"$(args)\" "]" ; - ECHO expected: \"$(expected)\" ; - EXIT got: \"$(result)\" ; + error assertion failure: "[" $(rule-name) \"$(args)\" "]" + : expected: \"$(expected)\" + : got: \"$(result)\" ; } } rule nonempty-variable ( name ) { local empty ; - if $($(variable)) = $(empty) + if $($(variable)) = $(empty) { - report-module ; - EXIT assertion failure, expecting non-empty variable $(variable) ; + error assertion failure: expecting non-empty variable $(variable) ; } } @@ -56,17 +49,8 @@ rule true ( rule-name args * ) if ! $(result) { - report-module ; - EXIT assertion failure, expecting true result from + error assertion failure: expecting true result from "[" $(rule-name) \"$(args)\" "]" ; } } -# Get around the capitalized naming (required to avoid a clash with the rule -# keyword) by importing Rule into the global namespace as assert.rule -IMPORT : assert : Rule : assert.rule ; - -rule __test__ ( ) -{ - # no tests yet for assertions -} diff --git a/new/errors.jam b/new/errors.jam new file mode 100644 index 000000000..699eef6b3 --- /dev/null +++ b/new/errors.jam @@ -0,0 +1,46 @@ +# (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +# A utility rule used to report the including module when there is an error, so +# that editors may find it. +rule report-module ( prefix ? : suffix ? : frames ? ) +{ + frames ?= 1 ; + # We report some large line number so that emacs, etc., will at least locate the file. + ECHO $(prefix) [ modules.binding [ CALLER_MODULE $(frames) ] ] ":" line 99999 $(suffix) ; +} + +rule backtrace +{ + local digits = 1 2 3 4 5 6 7 8 9 ; + local bt = [ BACKTRACE ] ; + bt = $(bt[5-]) ; + while $(bt) + { + ECHO $(bt[1]):$(bt[2]): "in" $(bt[4]) ; + + for local n in $(digits) + { + if $($(n))-is-not-empty + { + ECHO $($(n)) ; + } + } + digits = ; + + bt = $(bt[5-]) ; + } +} + +rule error +{ + backtrace error: $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ; + EXIT ; +} + +rule warning +{ + backtrace warning: $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ; +} diff --git a/new/modules.jam b/new/modules.jam index d5444c0a5..3c1869ae7 100644 --- a/new/modules.jam +++ b/new/modules.jam @@ -4,10 +4,11 @@ # warranty, and with no claim as to its suitability for any purpose. # Keep a record so that no module is included multiple times -module local imported-modules ; +module local loaded-modules ; -# meant to be invoked from -rule no_test_defined +# meant to be invoked from import when no __test__ rule is defined in a given +# module +local rule no_test_defined { ECHO warning: no __test__ rule defined in module [ CALLER_MODULE ] ; } @@ -25,15 +26,19 @@ rule binding ( module ) # module are imported into the caller's module. rule import ( module-name : rules-opt * : rename-opt * ) { - - if ! ( $(module-name) in $(imported-modules) ) + # First see if the module needs to be loaded + if ! ( $(module-name) in $(loaded-modules) ) { - imported-modules += $(module-name) ; + loaded-modules += $(module-name) ; module $(module-name) { + module local __name__ = $(module-name) ; + + # Prepare a default behavior, in case no __test__ is defined. IMPORT $(module-name) : modules : no_test_defined : __test__ ; + # Add some grist so that the module will have a unique target name local module-target = $(module-name:G=module@:S=.jam) ; SEARCH on $(module-target) = $(BOOST_BUILD_PATH) ; @@ -41,13 +46,15 @@ rule import ( module-name : rules-opt * : rename-opt * ) include $(module-name:G=module@:S=.jam) ; # run the module's test, if any. - if $(BOOST_BUILD_TEST) + if nonempty$(BOOST_BUILD_TEST) { ECHO testing module $(module-name)... ; local ignored = [ __test__ ] ; } } } + + # If any rules are to be imported, do so now. if $(rules-opt) { if $(rules-opt) = * @@ -59,8 +66,28 @@ rule import ( module-name : rules-opt * : rename-opt * ) } } +# This helper is used by import (above) to record the binding (path) of +# each loaded module. rule record-binding ( module-target : binding ) { module local $(module-target:G=:S=).__binding__ = $(binding) ; } +# Returns the module-local value of a variable. +rule peek ( module-name variable ) +{ + module $(module-name) + { + return $($(variable)) ; + } +} + +rule __test__ ( ) +{ + import assert ; + module modules.__test__ + { + module local foo = bar ; + } + assert.result bar : peek modules.__test__ foo ; +} \ No newline at end of file diff --git a/new/numbers.jam b/new/numbers.jam new file mode 100644 index 000000000..11d8928c2 --- /dev/null +++ b/new/numbers.jam @@ -0,0 +1,59 @@ +# (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +module local digits = 0 1 2 3 4 5 6 7 8 9 ; +module local powers = 1 ; +module local zeros = "" ; +module local natural = $(digits) ; +module local znatural = $(digits) ; + +local rule extend ( ) +{ + natural += $(digits[2-])$(znatural) ; + znatural = $(digits)$(znatural) ; +} + +rule increment ( number ) +{ + local r = $(natural[$(number)-]) ; + local x = $(r[3]) ; + if ( $(x) ) + { + return $(x) ; + } + else + { + extend ; + return [ increment $(number) ] ; + } +} + +rule decrement ( number ) +{ + local x = $(natural[$(number)]) ; + if ( $(x) ) + { + return $(x) ; + } + else + { + extend ; + return [ decrement $(number) ] ; + } +} + +rule __test__ ( ) +{ + import assert ; + assert.result 2 : increment 1 ; + assert.result 1 : decrement 2 ; + assert.result 50 : increment 49 ; + assert.result 49 : decrement 50 ; + assert.result 99 : increment 98 ; + assert.result 99 : decrement 100 ; + assert.result 100 : increment 99 ; + assert.result 1000 : increment 999 ; + assert.result 999 : decrement 1000 ; +} diff --git a/new/regex.jam b/new/regex.jam index fe6a726ca..7c7914171 100644 --- a/new/regex.jam +++ b/new/regex.jam @@ -25,10 +25,10 @@ rule __test__ ( ) { import assert ; - assert.rule split "a/b/c" / : a b c ; - assert.rule split "/a/b/c" / : a b c ; - assert.rule split "//a/b/c" / : "" a b c ; - assert.rule split "/a//b/c" / : a "" b c ; - assert.rule split "/a//b/c/" / : a "" b c "" ; - assert.rule split "/a//b/c//" / : a "" b c "" "" ; + assert.result a b c : split "a/b/c" / ; + assert.result a b c : split "/a/b/c" / ; + assert.result "" a b c : split "//a/b/c" / ; + assert.result a "" b c : split "/a//b/c" / ; + assert.result a "" b c "" : split "/a//b/c/" / ; + assert.result a "" b c "" "" : split "/a//b/c//" / ; } \ No newline at end of file diff --git a/new/set.jam b/new/set.jam new file mode 100644 index 000000000..642cd9bd0 --- /dev/null +++ b/new/set.jam @@ -0,0 +1,31 @@ +# (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +# difference +# returns the elements of B that are not in A +rule difference ( B * : A * ) +{ + local result = ; + local element ; + for element in $(B) + { + if ! ( $(element) in $(A) ) + { + result += $(element) ; + } + } + return $(result) ; +} + +rule __test__ ( ) +{ + import assert ; + + assert.result 0 1 4 6 8 9 + : difference 0 1 2 3 4 5 6 7 8 9 : 2 3 5 7 ; + +} + + diff --git a/new/ultility.jam b/new/ultility.jam new file mode 100644 index 000000000..1764055b4 --- /dev/null +++ b/new/ultility.jam @@ -0,0 +1,27 @@ +# (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +rule ungrist ( names * ) +{ + local result ; + for local name in $(names) + { + local stripped = [ SUBST $(name) ^<(.*)>$ $1 ] ; + if ! $(stripped) + { + ECHO *** error: in ungrist $(names) ; + EXIT *** $(name) is not of the form <.*> ; + } + result += $(stripped) ; + } + return $(result) ; +} + +rule __test__ +{ + import assert ; + assert.result foo bar : ungrist ; +} + diff --git a/v2/errors.jam b/v2/errors.jam new file mode 100644 index 000000000..699eef6b3 --- /dev/null +++ b/v2/errors.jam @@ -0,0 +1,46 @@ +# (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +# A utility rule used to report the including module when there is an error, so +# that editors may find it. +rule report-module ( prefix ? : suffix ? : frames ? ) +{ + frames ?= 1 ; + # We report some large line number so that emacs, etc., will at least locate the file. + ECHO $(prefix) [ modules.binding [ CALLER_MODULE $(frames) ] ] ":" line 99999 $(suffix) ; +} + +rule backtrace +{ + local digits = 1 2 3 4 5 6 7 8 9 ; + local bt = [ BACKTRACE ] ; + bt = $(bt[5-]) ; + while $(bt) + { + ECHO $(bt[1]):$(bt[2]): "in" $(bt[4]) ; + + for local n in $(digits) + { + if $($(n))-is-not-empty + { + ECHO $($(n)) ; + } + } + digits = ; + + bt = $(bt[5-]) ; + } +} + +rule error +{ + backtrace error: $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ; + EXIT ; +} + +rule warning +{ + backtrace warning: $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ; +} diff --git a/v2/modules.jam b/v2/modules.jam index d5444c0a5..3c1869ae7 100644 --- a/v2/modules.jam +++ b/v2/modules.jam @@ -4,10 +4,11 @@ # warranty, and with no claim as to its suitability for any purpose. # Keep a record so that no module is included multiple times -module local imported-modules ; +module local loaded-modules ; -# meant to be invoked from -rule no_test_defined +# meant to be invoked from import when no __test__ rule is defined in a given +# module +local rule no_test_defined { ECHO warning: no __test__ rule defined in module [ CALLER_MODULE ] ; } @@ -25,15 +26,19 @@ rule binding ( module ) # module are imported into the caller's module. rule import ( module-name : rules-opt * : rename-opt * ) { - - if ! ( $(module-name) in $(imported-modules) ) + # First see if the module needs to be loaded + if ! ( $(module-name) in $(loaded-modules) ) { - imported-modules += $(module-name) ; + loaded-modules += $(module-name) ; module $(module-name) { + module local __name__ = $(module-name) ; + + # Prepare a default behavior, in case no __test__ is defined. IMPORT $(module-name) : modules : no_test_defined : __test__ ; + # Add some grist so that the module will have a unique target name local module-target = $(module-name:G=module@:S=.jam) ; SEARCH on $(module-target) = $(BOOST_BUILD_PATH) ; @@ -41,13 +46,15 @@ rule import ( module-name : rules-opt * : rename-opt * ) include $(module-name:G=module@:S=.jam) ; # run the module's test, if any. - if $(BOOST_BUILD_TEST) + if nonempty$(BOOST_BUILD_TEST) { ECHO testing module $(module-name)... ; local ignored = [ __test__ ] ; } } } + + # If any rules are to be imported, do so now. if $(rules-opt) { if $(rules-opt) = * @@ -59,8 +66,28 @@ rule import ( module-name : rules-opt * : rename-opt * ) } } +# This helper is used by import (above) to record the binding (path) of +# each loaded module. rule record-binding ( module-target : binding ) { module local $(module-target:G=:S=).__binding__ = $(binding) ; } +# Returns the module-local value of a variable. +rule peek ( module-name variable ) +{ + module $(module-name) + { + return $($(variable)) ; + } +} + +rule __test__ ( ) +{ + import assert ; + module modules.__test__ + { + module local foo = bar ; + } + assert.result bar : peek modules.__test__ foo ; +} \ No newline at end of file diff --git a/v2/ultility.jam b/v2/ultility.jam new file mode 100644 index 000000000..1764055b4 --- /dev/null +++ b/v2/ultility.jam @@ -0,0 +1,27 @@ +# (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +rule ungrist ( names * ) +{ + local result ; + for local name in $(names) + { + local stripped = [ SUBST $(name) ^<(.*)>$ $1 ] ; + if ! $(stripped) + { + ECHO *** error: in ungrist $(names) ; + EXIT *** $(name) is not of the form <.*> ; + } + result += $(stripped) ; + } + return $(result) ; +} + +rule __test__ +{ + import assert ; + assert.result foo bar : ungrist ; +} + diff --git a/v2/util/assert.jam b/v2/util/assert.jam index 2327c0e67..04f2c8282 100644 --- a/v2/util/assert.jam +++ b/v2/util/assert.jam @@ -3,22 +3,17 @@ # all copies. This software is provided "as is" without express or implied # warranty, and with no claim as to its suitability for any purpose. -rule report-module ( prefix ? : suffix ? ) -{ - # We report some large line number so that emacs, etc., will at least locate the file. - ECHO $(prefix) [ modules.binding [ CALLER_MODULE 1 ] ] ":" line 99999 $(suffix) ; -} +import errors : error ; rule equal ( a * : b * ) { if $(a) != $(b) { - report-module ; - EXIT assertion failure: \"$(a)\" "!=" \"$(b)\" ; + error assertion failure: \"$(a)\" "!=" \"$(b)\" ; } } -rule Rule ( rule-name args * : expected * ) +rule result ( expected * : rule-name args * ) { module [ CALLER_MODULE ] @@ -28,20 +23,18 @@ rule Rule ( rule-name args * : expected * ) if $(result) != $(expected) { - report-module ; - ECHO assertion failure: "[" $(rule-name) \"$(args)\" "]" ; - ECHO expected: \"$(expected)\" ; - EXIT got: \"$(result)\" ; + error assertion failure: "[" $(rule-name) \"$(args)\" "]" + : expected: \"$(expected)\" + : got: \"$(result)\" ; } } rule nonempty-variable ( name ) { local empty ; - if $($(variable)) = $(empty) + if $($(variable)) = $(empty) { - report-module ; - EXIT assertion failure, expecting non-empty variable $(variable) ; + error assertion failure: expecting non-empty variable $(variable) ; } } @@ -56,17 +49,8 @@ rule true ( rule-name args * ) if ! $(result) { - report-module ; - EXIT assertion failure, expecting true result from + error assertion failure: expecting true result from "[" $(rule-name) \"$(args)\" "]" ; } } -# Get around the capitalized naming (required to avoid a clash with the rule -# keyword) by importing Rule into the global namespace as assert.rule -IMPORT : assert : Rule : assert.rule ; - -rule __test__ ( ) -{ - # no tests yet for assertions -} diff --git a/v2/util/numbers.jam b/v2/util/numbers.jam new file mode 100644 index 000000000..11d8928c2 --- /dev/null +++ b/v2/util/numbers.jam @@ -0,0 +1,59 @@ +# (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +module local digits = 0 1 2 3 4 5 6 7 8 9 ; +module local powers = 1 ; +module local zeros = "" ; +module local natural = $(digits) ; +module local znatural = $(digits) ; + +local rule extend ( ) +{ + natural += $(digits[2-])$(znatural) ; + znatural = $(digits)$(znatural) ; +} + +rule increment ( number ) +{ + local r = $(natural[$(number)-]) ; + local x = $(r[3]) ; + if ( $(x) ) + { + return $(x) ; + } + else + { + extend ; + return [ increment $(number) ] ; + } +} + +rule decrement ( number ) +{ + local x = $(natural[$(number)]) ; + if ( $(x) ) + { + return $(x) ; + } + else + { + extend ; + return [ decrement $(number) ] ; + } +} + +rule __test__ ( ) +{ + import assert ; + assert.result 2 : increment 1 ; + assert.result 1 : decrement 2 ; + assert.result 50 : increment 49 ; + assert.result 49 : decrement 50 ; + assert.result 99 : increment 98 ; + assert.result 99 : decrement 100 ; + assert.result 100 : increment 99 ; + assert.result 1000 : increment 999 ; + assert.result 999 : decrement 1000 ; +} diff --git a/v2/util/regex.jam b/v2/util/regex.jam index fe6a726ca..7c7914171 100644 --- a/v2/util/regex.jam +++ b/v2/util/regex.jam @@ -25,10 +25,10 @@ rule __test__ ( ) { import assert ; - assert.rule split "a/b/c" / : a b c ; - assert.rule split "/a/b/c" / : a b c ; - assert.rule split "//a/b/c" / : "" a b c ; - assert.rule split "/a//b/c" / : a "" b c ; - assert.rule split "/a//b/c/" / : a "" b c "" ; - assert.rule split "/a//b/c//" / : a "" b c "" "" ; + assert.result a b c : split "a/b/c" / ; + assert.result a b c : split "/a/b/c" / ; + assert.result "" a b c : split "//a/b/c" / ; + assert.result a "" b c : split "/a//b/c" / ; + assert.result a "" b c "" : split "/a//b/c/" / ; + assert.result a "" b c "" "" : split "/a//b/c//" / ; } \ No newline at end of file diff --git a/v2/util/set.jam b/v2/util/set.jam new file mode 100644 index 000000000..642cd9bd0 --- /dev/null +++ b/v2/util/set.jam @@ -0,0 +1,31 @@ +# (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +# difference +# returns the elements of B that are not in A +rule difference ( B * : A * ) +{ + local result = ; + local element ; + for element in $(B) + { + if ! ( $(element) in $(A) ) + { + result += $(element) ; + } + } + return $(result) ; +} + +rule __test__ ( ) +{ + import assert ; + + assert.result 0 1 4 6 8 9 + : difference 0 1 2 3 4 5 6 7 8 9 : 2 3 5 7 ; + +} + +