Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2008-05-30 16:05:48


Author: eric_niebler
Date: 2008-05-30 16:05:47 EDT (Fri, 30 May 2008)
New Revision: 45962
URL: http://svn.boost.org/trac/boost/changeset/45962

Log:
incomplete implementation of lammbda
Added:
   branches/proto/v4/boost/phoenix/scope/lambda.hpp (contents, props changed)
Text files modified:
   branches/proto/v4/boost/phoenix/core/actor.hpp | 30 +++++++++++++++++++++++-------
   branches/proto/v4/boost/phoenix/core/reference.hpp | 10 ++++++----
   branches/proto/v4/boost/phoenix/core/value.hpp | 8 ++++----
   branches/proto/v4/boost/phoenix/scope.hpp | 4 ++--
   branches/proto/v4/boost/phoenix/scope/let.hpp | 18 ++++++++++++------
   branches/proto/v4/boost/phoenix/scope/local_variable.hpp | 5 +++++
   branches/proto/v4/boost/proto/deep_copy.hpp | 10 +++++-----
   branches/proto/v4/boost/proto/generate.hpp | 32 ++++++++++++++++----------------
   8 files changed, 73 insertions(+), 44 deletions(-)

Modified: branches/proto/v4/boost/phoenix/core/actor.hpp
==============================================================================
--- branches/proto/v4/boost/phoenix/core/actor.hpp (original)
+++ branches/proto/v4/boost/phoenix/core/actor.hpp 2008-05-30 16:05:47 EDT (Fri, 30 May 2008)
@@ -34,7 +34,10 @@
         namespace detail
         {
             ////////////////////////////////////////////////////////////////////////////////////////
- template<typename SubGrammar = proto::not_<proto::_>, typename X = proto::callable>
+ typedef proto::not_<proto::_> no_sub_grammar;
+
+ ////////////////////////////////////////////////////////////////////////////////////////
+ template<typename SubGrammar = no_sub_grammar, typename X = proto::callable>
             struct evaluator;
         }
 
@@ -66,13 +69,13 @@
         using actorns_::actor;
 
         ////////////////////////////////////////////////////////////////////////////////////////////
- template<typename SubGrammar>
+ template<typename SubGrammar = detail::no_sub_grammar>
         struct is_nullary_cases;
 
         ////////////////////////////////////////////////////////////////////////////////////////
         // True when a lambda expression can be applied with no arguments and
         // without an active exception object
- template<typename SubGrammar = proto::not_<proto::_>, typename X = proto::callable>
+ template<typename SubGrammar = detail::no_sub_grammar, typename X = proto::callable>
         struct is_nullary
           : proto::or_<
                 SubGrammar
@@ -81,6 +84,12 @@
         {};
 
         ////////////////////////////////////////////////////////////////////////////////////////
+ template<>
+ struct is_nullary<>
+ : proto::switch_<is_nullary_cases<> >
+ {};
+
+ ////////////////////////////////////////////////////////////////////////////////////////
         template<typename Tag, typename SubGrammar>
         struct is_nullary_extension
           : proto::nary_expr<Tag, proto::vararg<is_nullary<SubGrammar> > >
@@ -111,7 +120,7 @@
         namespace detail
         {
             ////////////////////////////////////////////////////////////////////////////////////////
- template<typename SubGrammar>
+ template<typename SubGrammar = detail::no_sub_grammar>
             struct evaluator_cases
             {
             private:
@@ -147,6 +156,12 @@
             {};
 
             ////////////////////////////////////////////////////////////////////////////////////////
+ template<>
+ struct evaluator<>
+ : proto::switch_<evaluator_cases<> >
+ {};
+
+ ////////////////////////////////////////////////////////////////////////////////////////
             // These terminal types are always stored by reference
             template<typename Value>
             struct storage
@@ -180,7 +195,7 @@
                 template<typename This, typename Expr>
                 struct result<This(Expr)>
                 {
- typedef actor<Expr> type;
+ typedef actor<typename proto::by_value_generator::result<void(Expr)>::type> type;
                 };
 
                 template<typename This, typename T>
@@ -194,10 +209,11 @@
                 };
 
                 template<typename Expr>
- actor<Expr> const
+ actor<typename proto::by_value_generator::result<void(Expr)>::type> const
                 operator()(Expr const &expr) const
                 {
- actor<Expr> that = {expr};
+ actor<typename proto::by_value_generator::result<void(Expr)>::type> that
+ = {proto::by_value_generator()(expr)};
                     return that;
                 }
 

Modified: branches/proto/v4/boost/phoenix/core/reference.hpp
==============================================================================
--- branches/proto/v4/boost/phoenix/core/reference.hpp (original)
+++ branches/proto/v4/boost/phoenix/core/reference.hpp 2008-05-30 16:05:47 EDT (Fri, 30 May 2008)
@@ -15,17 +15,19 @@
     ////////////////////////////////////////////////////////////////////////////////////////////
     template<typename T>
     struct reference
- : proto::terminal<T &>::type
+ : proto::extends<typename proto::terminal<T &>::type, reference<T> >
     {
         explicit reference(T &t)
- : proto::terminal<T &>::type(
+ : proto::extends<typename proto::terminal<T &>::type, reference<T> >(
                 proto::terminal<T &>::type::make(t)
             )
         {}
 
         reference(reference<T> const volatile &that)
- : proto::terminal<T &>::type(
- proto::terminal<T &>::type::make(that.child0)
+ : proto::extends<typename proto::terminal<T &>::type, reference<T> >(
+ proto::terminal<T &>::type::make(
+ proto::value(const_cast<reference<T> const &>(that))
+ )
             )
         {}
 

Modified: branches/proto/v4/boost/phoenix/core/value.hpp
==============================================================================
--- branches/proto/v4/boost/phoenix/core/value.hpp (original)
+++ branches/proto/v4/boost/phoenix/core/value.hpp 2008-05-30 16:05:47 EDT (Fri, 30 May 2008)
@@ -24,18 +24,18 @@
     ////////////////////////////////////////////////////////////////////////////////////////////
     template<typename T>
     struct value
- : proto::terminal<T>::type
+ : proto::extends<typename proto::terminal<T>::type, value<T> >
     {
         explicit value(T const &t)
- : proto::terminal<T>::type(
+ : proto::extends<typename proto::terminal<T>::type, value<T> >(
                 proto::terminal<T>::type::make(t)
             )
         {}
 
         value(value<T> const volatile &that)
- : proto::terminal<T>::type(
+ : proto::extends<typename proto::terminal<T>::type, value<T> >(
                 proto::terminal<T>::type::make(
- const_cast<T const &>(that.child0)
+ proto::value(const_cast<value<T> const &>(that))
                 )
             )
         {}

Modified: branches/proto/v4/boost/phoenix/scope.hpp
==============================================================================
--- branches/proto/v4/boost/phoenix/scope.hpp (original)
+++ branches/proto/v4/boost/phoenix/scope.hpp 2008-05-30 16:05:47 EDT (Fri, 30 May 2008)
@@ -8,8 +8,8 @@
 #ifndef BOOST_PHOENIX_SCOPE_HPP_EAN_2008_05_23
 #define BOOST_PHOENIX_SCOPE_HPP_EAN_2008_05_23
 
-#include <boost//phoenix/version.hpp>
-//#include <boost/phoenix/scope/lambda.hpp>
+#include <boost/phoenix/version.hpp>
+#include <boost/phoenix/scope/lambda.hpp>
 #include <boost/phoenix/scope/let.hpp>
 #include <boost/phoenix/scope/local_variable.hpp>
 

Added: branches/proto/v4/boost/phoenix/scope/lambda.hpp
==============================================================================
--- (empty file)
+++ branches/proto/v4/boost/phoenix/scope/lambda.hpp 2008-05-30 16:05:47 EDT (Fri, 30 May 2008)
@@ -0,0 +1,173 @@
+#ifndef BOOST_PP_IS_ITERATING
+ /*=============================================================================
+ Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2008 Eric Niebler
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ ==============================================================================*/
+ #ifndef BOOST_PHOENIX_SCOPE_LAMBDA_HPP_EAN_2008_05_29
+ #define BOOST_PHOENIX_SCOPE_LAMBDA_HPP_EAN_2008_05_29
+
+ #include <boost/preprocessor.hpp>
+ #include <boost/fusion/include/map.hpp>
+ #include <boost/fusion/include/fold.hpp>
+ #include <boost/fusion/include/pair.hpp>
+ #include <boost/fusion/include/as_map.hpp>
+ #include <boost/fusion/include/at_key.hpp>
+ #include <boost/fusion/include/transform.hpp>
+ #include <boost/phoenix/scope/let.hpp>
+
+ namespace boost { namespace phoenix
+ {
+ namespace tag
+ {
+ struct lambda_ {};
+ struct with_state {};
+ }
+
+ namespace detail
+ {
+ ////////////////////////////////////////////////////////////////////////////////////////
+ template<typename Map>
+ struct lambda_generator
+ : let_generator<Map>
+ {
+ typedef typename let_generator<Map>::map_type map_type;
+
+ explicit lambda_generator(Map const &map)
+ : let_generator<Map>(map)
+ {}
+
+ template<typename Body>
+ typename proto::result_of::make_expr<
+ tag::let_
+ , domain
+ , map_type const &
+ , typename proto::result_of::make_expr<
+ tag::lambda_
+ , domain
+ , Body const &
+ >::type const
+ >::type const
+ operator [](Body const &body) const
+ {
+ return proto::make_expr<tag::let_, domain>(
+ boost::ref(this->map)
+ , proto::make_expr<tag::lambda_, domain>(boost::ref(body))
+ );
+ }
+ };
+
+ ////////////////////////////////////////////////////////////////////////////////////////
+ struct LocalVariable
+ : proto::when<
+ proto::terminal<local_variable<proto::_> >
+ , proto::lazy<local_variable_evaluator<local_variable_tag<proto::_value> > >
+ >
+ {};
+
+ ////////////////////////////////////////////////////////////////////////////////////////
+ struct lambda_placeholder
+ {
+ template<typename Body>
+ typename proto::result_of::make_expr<
+ tag::let_
+ , domain
+ , fusion::map<> const
+ , typename proto::result_of::make_expr<
+ tag::lambda_
+ , domain
+ , Body const &
+ >::type const
+ >::type const
+ operator [](Body const &body) const
+ {
+ return proto::make_expr<tag::let_, domain>(
+ fusion::map<>()
+ , proto::make_expr<tag::lambda_, domain>(boost::ref(body))
+ );
+ }
+
+ #define BOOST_PP_ITERATION_PARAMS_1 (3, (1, PHOENIX_LIMIT, <boost/phoenix/scope/lambda.hpp>))
+ #include BOOST_PP_ITERATE()
+ };
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////////////////
+ // Evaluate a lambda() expression by simply returning the child let() expression.
+ template<typename SubGrammar>
+ struct extension<tag::lambda_, SubGrammar>
+ : proto::when<
+ proto::unary_expr<tag::lambda_, evaluator<SubGrammar> >
+ , proto::_make_expr<tag::with_state, detail::domain>(
+ proto::call<proto::_make_expr<proto::tag::terminal, detail::domain>(proto::_state)>
+ , proto::_child
+ )
+ >
+ {};
+
+ ////////////////////////////////////////////////////////////////////////////////////////////
+ template<typename SubGrammar>
+ struct extension<tag::with_state, SubGrammar>
+ : proto::otherwise<
+ evaluator<proto::or_<detail::LocalVariable, SubGrammar> >(
+ proto::_right
+ , proto::_value(proto::_left)
+ , proto::_data
+ )
+ >
+ {};
+
+ ////////////////////////////////////////////////////////////////////////////////////////////
+ detail::lambda_placeholder const lambda = {};
+ }}
+
+ #endif
+
+#else
+
+ #define N BOOST_PP_ITERATION()
+
+ ////////////////////////////////////////////////////////////////////////////////////////////
+ #define M0(Z, N, DATA) \
+ actor< \
+ proto::expr< \
+ proto::tag::assign \
+ , proto::list2< \
+ actor<phoenix::local_variable<BOOST_PP_CAT(T, N)> > \
+ , BOOST_PP_CAT(A, N) \
+ > \
+ > \
+ > const & BOOST_PP_CAT(a, N) \
+ /**/
+
+ ////////////////////////////////////////////////////////////////////////////////////////////
+ #define M1(Z, N, DATA) \
+ fusion::pair<BOOST_PP_CAT(T, N), BOOST_PP_CAT(A, N)> \
+ /**/
+
+ ////////////////////////////////////////////////////////////////////////////////////////////
+ #define M2(Z, N, DATA) \
+ fusion::make_pair<BOOST_PP_CAT(T, N)>(BOOST_PP_CAT(a, N).proto_base().child1) \
+ /**/
+
+ ////////////////////////////////////////////////////////////////////////////////////////////
+ template<
+ BOOST_PP_ENUM_PARAMS(N, typename T)
+ BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)
+ >
+ detail::lambda_generator<fusion::map<BOOST_PP_ENUM(N, M1, ~)> > const
+ operator()(BOOST_PP_ENUM(N, M0, ~)) const
+ {
+ typedef fusion::map<BOOST_PP_ENUM(N, M1, ~)> map_type;
+ return detail::lambda_generator<map_type>(map_type(BOOST_PP_ENUM(N, M2, ~)));
+ }
+
+ #undef M0
+ #undef M1
+ #undef M2
+
+ #undef N
+
+#endif

Modified: branches/proto/v4/boost/phoenix/scope/let.hpp
==============================================================================
--- branches/proto/v4/boost/phoenix/scope/let.hpp (original)
+++ branches/proto/v4/boost/phoenix/scope/let.hpp 2008-05-30 16:05:47 EDT (Fri, 30 May 2008)
@@ -49,7 +49,7 @@
                     return proto::implicit_expr(this->map, body);
                 }
 
- private:
+ protected:
                 typename proto::terminal<Map>::type map;
             };
 
@@ -76,7 +76,7 @@
                     typedef
                         fusion::pair<
                             First
- , typename boost::result_of<evaluator<SubGrammar>(Second, State, Data)>::type
+ , typename boost::result_of<evaluator<SubGrammar>(Second const &, State, Data)>::type
>
                     type;
                 };
@@ -84,17 +84,18 @@
                 template<typename First, typename Second>
                 fusion::pair<
                     First
- , typename boost::result_of<evaluator<SubGrammar>(Second, State, Data)>::type
+ , typename boost::result_of<evaluator<SubGrammar>(Second const &, State, Data)>::type
> const
                 operator()(fusion::pair<First, Second> const &p) const
                 {
                     typedef
                         fusion::pair<
                             First
- , typename boost::result_of<evaluator<SubGrammar>(Second, State, Data)>::type
+ , typename boost::result_of<evaluator<SubGrammar>(Second const &, State, Data)>::type
>
                     pair_type;
- return pair_type(evaluator<SubGrammar>()(p.second, this->state, this->data));
+ pair_type that(evaluator<SubGrammar>()(p.second, this->state, this->data));
+ return that;
                 }
 
             private:
@@ -122,6 +123,11 @@
                   , data(data)
                   , locals(fusion::as_map(fusion::transform(map, initialize_locals<State, Data, SubGrammar>(state, data))))
                 {}
+
+ friend std::ostream &operator<<(std::ostream &sout, scope const &)
+ {
+ return sout << typeid(scope).name();
+ }
 
                 State state; // outer state
                 Data data; // outer data
@@ -277,7 +283,7 @@
                 proto::expr< \
                     proto::tag::assign \
                   , proto::list2< \
- actor<local_variable<BOOST_PP_CAT(T, N)> > const & \
+ actor<local_variable<BOOST_PP_CAT(T, N)> > \
                       , BOOST_PP_CAT(A, N) \
> \
> \

Modified: branches/proto/v4/boost/phoenix/scope/local_variable.hpp
==============================================================================
--- branches/proto/v4/boost/phoenix/scope/local_variable.hpp (original)
+++ branches/proto/v4/boost/phoenix/scope/local_variable.hpp 2008-05-30 16:05:47 EDT (Fri, 30 May 2008)
@@ -22,6 +22,11 @@
         struct local_variable
         {
             typedef Tag tag_type;
+
+ friend std::ostream &operator<<(std::ostream &sout, local_variable const &)
+ {
+ return sout << typeid(local_variable).name();
+ }
         };
         
         ////////////////////////////////////////////////////////////////////////////////////////////

Modified: branches/proto/v4/boost/proto/deep_copy.hpp
==============================================================================
--- branches/proto/v4/boost/proto/deep_copy.hpp (original)
+++ branches/proto/v4/boost/proto/deep_copy.hpp 2008-05-30 16:05:47 EDT (Fri, 30 May 2008)
@@ -136,13 +136,13 @@
         {
         #define BOOST_PROTO_DEFINE_DEEP_COPY_TYPE(Z, N, DATA) \
             typename deep_copy_impl< \
- BOOST_PROTO_UNCVREF( \
- typename Expr::BOOST_PP_CAT(proto_child, N) \
- ) \
- >::type
+ typename Expr::BOOST_PP_CAT(proto_child_ref, N)::proto_derived_expr \
+ >::type \
+ /**/
 
         #define BOOST_PROTO_DEFINE_DEEP_COPY_FUN(Z, N, DATA) \
- proto::deep_copy(expr.proto_base().BOOST_PP_CAT(child, N))
+ proto::deep_copy(expr.proto_base().BOOST_PP_CAT(child, N)) \
+ /**/
 
         #define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/deep_copy.hpp>))
         #include BOOST_PP_ITERATE()

Modified: branches/proto/v4/boost/proto/generate.hpp
==============================================================================
--- branches/proto/v4/boost/proto/generate.hpp (original)
+++ branches/proto/v4/boost/proto/generate.hpp 2008-05-30 16:05:47 EDT (Fri, 30 May 2008)
@@ -55,11 +55,7 @@
             struct by_value_generator_;
 
         #define BOOST_PROTO_DEFINE_BY_VALUE_TYPE(Z, N, Expr) \
- typename remove_const< \
- typename remove_reference< \
- typename expr_traits<Expr>::args::BOOST_PP_CAT(child, N) \
- >::type \
- >::type \
+ typename expr_traits<Expr>::args::BOOST_PP_CAT(child_ref, N)::proto_derived_expr \
             /**/
 
         #define BOOST_PROTO_DEFINE_BY_VALUE(Z, N, expr) \
@@ -69,14 +65,16 @@
             template<typename Expr>
             struct by_value_generator_<Expr, 0>
             {
- typedef proto::expr<
- tag::terminal
- , term<typename expr_traits<Expr>::args::child_ref0::value_type>
- > type;
+ typedef
+ proto::expr<
+ typename expr_traits<Expr>::tag
+ , term<typename expr_traits<Expr>::args::child_ref0::value_type>
+ >
+ type;
 
                 static type const make(Expr const &expr)
                 {
- type that = {BOOST_PROTO_DEFINE_BY_VALUE(~, 0, expr)};
+ type that = {expr.child0};
                     return that;
                 }
             };
@@ -362,13 +360,15 @@
             template<typename Expr>
             struct by_value_generator_<Expr, N>
             {
- typedef proto::expr<
- typename expr_traits<Expr>::tag
- , BOOST_PP_CAT(list, N)<
- // typename expr_traits<Expr>::args::child_ref0::proto_derived_expr, ...
- BOOST_PP_ENUM(N, BOOST_PROTO_DEFINE_BY_VALUE_TYPE, Expr)
+ typedef
+ proto::expr<
+ typename expr_traits<Expr>::tag
+ , BOOST_PP_CAT(list, N)<
+ // typename expr_traits<Expr>::args::child_ref0::proto_derived_expr, ...
+ BOOST_PP_ENUM(N, BOOST_PROTO_DEFINE_BY_VALUE_TYPE, Expr)
+ >
>
- > type;
+ type;
 
                 static type const make(Expr const &expr)
                 {


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk