|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r64154 - in sandbox/SOC/2010/phoenix3: boost/phoenix boost/phoenix/scope boost/phoenix/scope/detail libs/phoenix/test/scope
From: thom.heller_at_[hidden]
Date: 2010-07-19 08:13:10
Author: theller
Date: 2010-07-19 08:13:08 EDT (Mon, 19 Jul 2010)
New Revision: 64154
URL: http://svn.boost.org/trac/boost/changeset/64154
Log:
let implementation basics
Added:
sandbox/SOC/2010/phoenix3/boost/phoenix/scope/detail/local_gen.hpp (contents, props changed)
sandbox/SOC/2010/phoenix3/boost/phoenix/scope/let.hpp (contents, props changed)
Text files modified:
sandbox/SOC/2010/phoenix3/boost/phoenix/scope.hpp | 2
sandbox/SOC/2010/phoenix3/boost/phoenix/scope/detail/local_variable.hpp | 2
sandbox/SOC/2010/phoenix3/boost/phoenix/scope/lambda.hpp | 236 +++------------------------------------
sandbox/SOC/2010/phoenix3/libs/phoenix/test/scope/lambda_tests.cpp | 1
sandbox/SOC/2010/phoenix3/libs/phoenix/test/scope/let_tests.cpp | 10 +
5 files changed, 32 insertions(+), 219 deletions(-)
Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/scope.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/scope.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/scope.hpp 2010-07-19 08:13:08 EDT (Mon, 19 Jul 2010)
@@ -11,7 +11,7 @@
#include <boost/phoenix/version.hpp>
#include <boost/phoenix/scope/scoped_environment.hpp>
#include <boost/phoenix/scope/lambda.hpp>
-//#include <boost/phoenix/let.hpp>
+#include <boost/phoenix/scope/let.hpp>
#include <boost/phoenix/scope/local_variable.hpp>
#endif
Added: sandbox/SOC/2010/phoenix3/boost/phoenix/scope/detail/local_gen.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/scope/detail/local_gen.hpp 2010-07-19 08:13:08 EDT (Mon, 19 Jul 2010)
@@ -0,0 +1,55 @@
+/*==============================================================================
+ Copyright (c) 2005-2010 Joel de Guzman
+ Copyright (c) 2010 Thomas Heller
+
+ 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)
+==============================================================================*/
+
+#if !PHOENIX_IS_ITERATING
+
+#ifndef PHOENIX_SCOPE_DETAIL_LAMBDA_LOCAL_GEN_HPP
+#define PHOENIX_SCOPE_DETAIL_LAMBDA_LOCAL_GEN_HPP
+
+#define PHOENIX_ITERATION_PARAMS \
+ (3, (3, PHOENIX_LOCAL_LIMIT, \
+ <boost/phoenix/scope/detail/local_gen.hpp>))
+#include PHOENIX_ITERATE()
+
+#endif
+
+#else
+
+#define PHOENIX_LOCAL_GEN_ACTOR_TYPES_I(_, n, __) \
+ BOOST_PP_COMMA_IF(n) typename proto::result_of::child_c<A ## n, 1>::type
+
+#define PHOENIX_LOCAL_GEN_ACTOR_TYPES BOOST_PP_REPEAT(PHOENIX_ITERATION, PHOENIX_LOCAL_GEN_ACTOR_TYPES_I, _)
+
+#define PHOENIX_LOCAL_GEN_ACTOR_I(_, n, __) \
+ BOOST_PP_COMMA_IF(n) proto::child_c<1>(a ## n)
+
+#define PHOENIX_LOCAL_GEN_ACTOR BOOST_PP_REPEAT(PHOENIX_ITERATION, PHOENIX_LOCAL_GEN_ACTOR_I, _)
+
+#define PHOENIX_LOCAL_GEN_KEY_TYPES_I(_, n, __) \
+ BOOST_PP_COMMA_IF(n) \
+ typename proto::result_of::value< \
+ typename proto::result_of::child_c< \
+ typename proto::result_of::child_c<A ## n, 0>::type, 0 \
+ >::type \
+ >::type::type::key_type \
+
+#define PHOENIX_LOCAL_GEN_KEY_TYPES BOOST_PP_REPEAT(PHOENIX_ITERATION, PHOENIX_LOCAL_GEN_KEY_TYPES_I, _)
+
+ template <PHOENIX_typename_A>
+ PHOENIX_LOCAL_GEN_NAME<
+ BOOST_PP_CAT(fusion::vector, PHOENIX_ITERATION)<PHOENIX_LOCAL_GEN_ACTOR_TYPES>
+ , detail::map_local_index_to_tuple<PHOENIX_LOCAL_GEN_KEY_TYPES>
+ > const
+ operator()(PHOENIX_A_const_ref_a) const
+ {
+ return
+ BOOST_PP_CAT(
+ fusion::vector, PHOENIX_ITERATION)<PHOENIX_LOCAL_GEN_ACTOR_TYPES>(PHOENIX_LOCAL_GEN_ACTOR);
+ }
+
+#endif
Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/scope/detail/local_variable.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/scope/detail/local_variable.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/scope/detail/local_variable.hpp 2010-07-19 08:13:08 EDT (Mon, 19 Jul 2010)
@@ -126,7 +126,7 @@
template <typename Key, typename Env>
struct apply_local
{
- BOOST_STATIC_ASSERT( is_scoped_environment<Env>::value );
+ //BOOST_STATIC_ASSERT( is_scoped_environment<Env>::value );
// $$$ TODO: static assert that Env is a scoped_environment $$$
typedef typename get_local<Key, Env>::type type;
};
Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/scope/lambda.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/scope/lambda.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/scope/lambda.hpp 2010-07-19 08:13:08 EDT (Mon, 19 Jul 2010)
@@ -21,13 +21,19 @@
namespace boost { namespace phoenix
{
-//#if 0
namespace result_of
{
- template <typename Env, typename Expr>
+ template <typename Env, typename Expr, typename OuterEnv, typename Locals, typename Map>
struct lambda
{
- typedef typename boost::result_of<eval_grammar(Expr const&, Env&)>::type type;
+ typedef scoped_environment<
+ Env
+ , typename proto::result_of::value<OuterEnv>::type
+ , typename proto::result_of::value<Locals>::type
+ , Map
+ > environment;
+
+ typedef typename boost::result_of<eval_grammar(Expr const&, environment&)>::type type;
};
}
@@ -39,22 +45,15 @@
template <typename This, typename Env, typename Expr, typename OuterEnv, typename Locals>
struct result<This(Env&, Expr const&, OuterEnv const&, Locals const&)>
- {
- typedef scoped_environment<
- Env
- , typename proto::result_of::value<OuterEnv>::type
- , typename proto::result_of::value<Locals>::type
- , Map
- > environment;
-
- typedef typename boost::result_of<eval_grammar(Expr const&, environment&)>::type type;
- };
+ : result_of::lambda<Env, Expr, OuterEnv, Locals, Map>
+ {};
template <typename Env, typename Expr, typename OuterEnv, typename Locals>
- typename result<lambda_eval(Env&, Expr const&, OuterEnv const&, Locals const&)>::type
+ typename result_of::lambda<Env, Expr, OuterEnv, Locals, Map>::type
operator()(Env& env, Expr const& expr, OuterEnv const& outer_env, Locals const& locals) const
{
- typedef typename result<lambda_eval(Env&, Expr const&, OuterEnv const&, Locals const&)>::environment environment;
+ typedef typename result_of::lambda<Env, Expr, OuterEnv, Locals, Map>::environment environment;
+
environment args(env, proto::value(outer_env), proto::value(locals));
return eval(expr, args);
@@ -64,7 +63,6 @@
template <typename Expr, typename OuterEnv, typename Locals, typename Map>
struct make_lambda : compose<lambda_eval<Map>, Expr, OuterEnv, Locals> {};
- template <typename Map>
struct lambda_actor_eval
{
template <typename Sig>
@@ -115,7 +113,9 @@
{
typedef typename result<lambda_actor(Env&)>::locals_type locals_type;
- return make_lambda<Expr, Env, locals_type, Map>()(expr, env, fusion::transform(vars, detail::initialize_local<Env>(env)));
+ return make_lambda<
+ Expr, Env, locals_type, Map
+ >()(expr, env, fusion::as_vector(fusion::transform(vars, detail::initialize_local<Env>(env))));
}
Expr expr;
@@ -123,7 +123,7 @@
};
template <typename Expr, typename Vars, typename Map>
- struct make_lambda_actor: compose<lambda_actor_eval<Map>, lambda_actor<Expr, Vars, Map> > {};
+ struct make_lambda_actor: compose<lambda_actor_eval, lambda_actor<Expr, Vars, Map> > {};
template <typename Vars, typename Map>
struct lambda_actor_gen
@@ -198,207 +198,13 @@
, proto::child_c<1>(a1)
);
}
- };
-
- lambda_gen const lambda = lambda_gen();
-
-//#endif
-#if 0
-
- /*
- namespace result_of
- {
- template <typename Expr, typename OuterEnv, typename Locals, typename Map, typename A0 = void, typename A1 = void>
- struct lambda;
-
- template <typename Expr, typename OuterEnv, typename Locals, typename Map, typename A0>
- struct lambda<Expr, OuterEnv, Locals, Map, A0>
- {
- typedef typename make_basic_environment<A0>::type basic_env;
- typedef scoped_environment<basic_env, OuterEnv, Locals, Map> args;
-
- typedef typename boost::result_of<eval_grammar(Expr const&, args&)>::type type;
- };
- }
-
- template <typename LambdaExpr, typename OuterEnv, typename Locals, typename Map>
- struct lambda_eval
- : LambdaExpr
- {
- typedef LambdaExpr base_type;
-
- lambda_eval(LambdaExpr const& lambda_expr, OuterEnv const& outer_env, Locals const& locals)
- : base_type(lambda_expr)
- , outer_env(outer_env)
- , locals(locals)
- {}
-
- template <typename Sig>
- struct result;
-
- template <typename This, typename A0>
- struct result<This(A0)>
- : result_of::lambda<LambdaExpr, OuterEnv, Locals, Map, A0>
- {};
-
- int
- operator()() const
- {
- typename make_basic_environment<>::type env;
- scoped_environment<typename make_basic_environment<>::type, OuterEnv, Locals, Map> args(env, outer_env, locals);
-
- return eval(*this, args);
- }
-
- template <typename A0>
- typename result_of::lambda<LambdaExpr, OuterEnv, Locals, Map, A0 const&>::type
- operator()(A0 const& a0) const
- {
- typename make_basic_environment<A0 const&>::type env(a0);
- scoped_environment<typename make_basic_environment<A0 const&>::type, OuterEnv, Locals, Map> args(env, outer_env, locals);
-
- return eval(*this, args);
- }
-
- template <typename A0>
- typename result_of::lambda<LambdaExpr, OuterEnv, Locals, Map, A0&>::type
- operator()(A0& a0) const
- {
- typename make_basic_environment<A0&>::type env(a0);
- scoped_environment<typename make_basic_environment<A0&>::type, OuterEnv, Locals, Map> args(env, outer_env, locals);
-
- return eval(*this, args);
- }
-
- OuterEnv outer_env;
- Locals locals;
- };
- */
-
- template <typename LambdaExpr, typename Vars, typename Map>
- struct lambda_actor_eval
- {
- lambda_actor_eval(LambdaExpr const& lambda_expr, Vars const& vars) : lambda_expr(lambda_expr), vars(vars) {}
-
- LambdaExpr lambda_expr;
- Vars vars;
-
- template <typename Sig>
- struct result;
-
- template <typename This, typename Env>
- struct result<This(Env&)>
- {
-
- typedef typename
- fusion::result_of::as_vector<
- typename fusion::result_of::transform<
- Vars
- , detail::initialize_local<Env>
- >::type
- >::type
- locals_type;
- /*
- typedef lambda_eval<LambdaExpr, Env, locals_type, Map> type;
- */
-
- typedef typename make_local_actor<LambdaExpr, Env, locals_type, Map>::type type;
- };
-
- template <typename Env>
- typename result<lambda_actor_eval(Env&)>::type const
- operator()(Env& env) const
- {
- typedef typename result<lambda_actor_eval(Env&)>::locals_type locals_type;
- return make_local_actor<LambdaExpr, Env, locals_type, Map>()(lambda_expr, env, fusion::as_vector(fusion::transform(vars, detail::initialize_local<Env>(env))));
- }
-
- /*
- template <typename Env>
- typename result<lambda_actor_eval(Env&)>::type const
- operator()(Env& env) const
- {
- typedef typename result<lambda_actor_eval(Env&)>::locals_type locals_type;
- return lambda_eval<LambdaExpr, Env, locals_type, Map>(lambda_expr, env, fusion::as_vector(fusion::transform(vars, detail::initialize_local<Env>(env))));
- }
- */
- };
-
- template <typename LambdaExpr, typename Vars, typename Map>
- struct make_lambda_actor_eval
- {
- typedef typename
- proto::result_of::make_expr<
- proto::tag::function
- , default_domain_with_basic_expr
- , lambda_actor_eval<LambdaExpr, Vars, Map>
- , env
- >::type
- base_type;
-
- typedef actor<base_type> type;
- };
-
- template <typename Vars, typename Map>
- struct lambda_gen_actor
- {
- lambda_gen_actor(Vars const& vars) : vars(vars) {}
-
- template <typename LambdaExpr>
- typename make_lambda_actor_eval<LambdaExpr, Vars, Map>::type const
- operator[](LambdaExpr const& lambda_expr) const
- {
- typename make_lambda_actor_eval<LambdaExpr, Vars,Map>::type const e = {{lambda_actor_eval<LambdaExpr, Vars, Map>(lambda_expr, vars), env()}};
- return e;
- }
-
- Vars const & vars;
- };
-
- namespace local_names { struct _a_key; struct _b_key; }
-
- struct lambda_gen
- : lambda_gen_actor<fusion::vector0<>, detail::map_local_index_to_tuple<> >
- {
- typedef lambda_gen_actor<fusion::vector0<>, detail::map_local_index_to_tuple<> > base_type;
-
- lambda_gen()
- : base_type( fusion::vector0<>() )
- {}
-
- template <typename A0>
- lambda_gen_actor<
- fusion::vector1<typename proto::result_of::child_c<A0, 1>::type>
- , detail::map_local_index_to_tuple<local_names::_a_key>
- > const
- operator()( A0 const& a0) const
- {
- return fusion::vector1<typename proto::result_of::child_c<A0, 1>::type>(proto::child_c<1>(a0));
- }
-
- template <typename A0, typename A1>
- lambda_gen_actor<
- fusion::vector2<
- typename proto::result_of::child_c<A0, 1>::type
- , typename proto::result_of::child_c<A1, 1>::type
- >
- , detail::map_local_index_to_tuple<local_names::_a_key, local_names::_b_key>
- > const
- operator()( A0 const& a0, A1 const& a1) const
- {
- return fusion::vector2<
- typename proto::result_of::child_c<A0, 1>::type
- , typename proto::result_of::child_c<A1, 1>::type
- >(
- proto::child_c<1>(a0)
- , proto::child_c<1>(a1)
- );
- }
+ #define PHOENIX_LOCAL_GEN_NAME lambda_actor_gen
+ #include <boost/phoenix/scope/detail/local_gen.hpp>
+ #undef PHOENIX_LOCAL_GEN_NAME
};
lambda_gen const lambda = lambda_gen();
-#endif
}}
#endif
Added: sandbox/SOC/2010/phoenix3/boost/phoenix/scope/let.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/scope/let.hpp 2010-07-19 08:13:08 EDT (Mon, 19 Jul 2010)
@@ -0,0 +1,170 @@
+/*==============================================================================
+ Copyright (c) 2001-2010 Joel de Guzman
+ Copyright (c) 2004 Daniel Wallin
+ Copyright (c) 2010 Thomas Heller
+
+ 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 PHOENIX_SCOPE_LET_HPP
+#define PHOENIX_SCOPE_LET_HPP
+
+#include <boost/fusion/include/transform.hpp>
+#include <boost/fusion/include/as_vector.hpp>
+#include <boost/phoenix/core/limits.hpp>
+#include <boost/phoenix/scope/scoped_environment.hpp>
+#include <boost/phoenix/core/actor.hpp>
+#include <boost/phoenix/scope/local_actor.hpp>
+#include <boost/phoenix/scope/detail/local_variable.hpp>
+#include <boost/phoenix/support/element_at.hpp>
+#include <boost/phoenix/support/iterate.hpp>
+
+namespace boost { namespace phoenix
+{
+ struct let_eval
+ {
+ template <typename Sig>
+ struct result;
+
+ template <typename This, typename Env, typename A>
+ struct result<This(Env&, A const&)>
+ : boost::result_of<typename proto::result_of::value<A>::type(Env&)>
+ {};
+
+ template <typename Env, typename A>
+ typename result<let_eval(Env&, A const&)>::type const
+ operator()(Env& env, A const& a)
+ {
+ return proto::value(a)(env);
+ }
+ };
+
+ template <typename Expr, typename Vars, typename Map>
+ struct let_actor
+ {
+ let_actor(Expr const& expr, Vars const& vars)
+ : expr(expr)
+ , vars(vars)
+ {}
+
+ template <typename Sig>
+ struct result;
+
+ template <typename This, typename Env>
+ struct result<This(Env&)>
+ {
+ typedef typename
+ fusion::result_of::as_vector<
+ typename fusion::result_of::transform<
+ Vars
+ , detail::initialize_local<Env>
+ >::type
+ >::type
+ locals_type;
+
+ typedef scoped_environment<Env, Env, locals_type, Map> env_type;
+
+ typedef typename boost::result_of<eval_grammar(Expr const&, env_type&)>::type type;
+ };
+
+ template <typename Env>
+ typename result<let_actor(Env&)>::type const
+ operator()(Env& env) const
+ {
+ typedef typename result<let_actor(Env&)>::locals_type locals_type;
+
+ scoped_environment<Env, Env, locals_type, Map> args(env, env, as_vector(fusion::transform(vars, detail::initialize_local<Env>(env))));
+
+ return eval(expr, args);
+ }
+
+ Expr expr;
+ Vars vars;
+ };
+
+ template <typename Expr, typename Vars, typename Map>
+ struct make_let: compose<let_eval, let_actor<Expr, Vars, Map> > {};
+
+ template <typename Vars, typename Map>
+ struct let_actor_gen
+ {
+
+ template <typename Expr>
+ typename make_let<Expr, Vars, Map>::type const
+ operator[](Expr const expr) const
+ {
+ return make_let<Expr, Vars, Map>()(let_actor<Expr, Vars, Map>(expr, vars));
+ }
+
+ let_actor_gen(Vars const& vars)
+ : vars(vars) {}
+
+ Vars const& vars;
+ };
+
+ struct let_gen
+ : let_actor_gen<
+ fusion::vector0<>
+ , detail::map_local_index_to_tuple<> >
+ {
+ typedef let_actor_gen<fusion::vector0<>, detail::map_local_index_to_tuple<> > base_type;
+
+ let_gen()
+ : base_type(fusion::vector0<>())
+ {}
+
+ template <typename A0>
+ let_actor_gen<
+ fusion::vector1<typename proto::result_of::child_c<A0, 1>::type>
+ , detail::map_local_index_to_tuple<
+ typename proto::result_of::value<
+ typename proto::result_of::child_c<
+ typename proto::result_of::child_c<A0, 0>::type, 0
+ >::type
+ >::type::type::key_type
+ >
+ > const
+ operator()(A0 const& a0) const
+ {
+ return fusion::vector1<typename proto::result_of::child_c<A0, 1>::type>(proto::child_c<1>(a0));
+ }
+
+ template <typename A0, typename A1>
+ let_actor_gen<
+ fusion::vector2<
+ typename proto::result_of::child_c<A0, 1>::type
+ , typename proto::result_of::child_c<A1, 1>::type
+ >
+ , detail::map_local_index_to_tuple<
+ typename proto::result_of::value<
+ typename proto::result_of::child_c<
+ typename proto::result_of::child_c<A0, 0>::type, 0
+ >::type
+ >::type::type::key_type
+ , typename proto::result_of::value<
+ typename proto::result_of::child_c<
+ typename proto::result_of::child_c<A1, 0>::type, 0
+ >::type
+ >::type::type::key_type
+ >
+ > const
+ operator()(A0 const& a0, A1 const& a1) const
+ {
+ return fusion::vector2<
+ typename proto::result_of::child_c<A0, 1>::type
+ , typename proto::result_of::child_c<A1, 1>::type
+ >(
+ proto::child_c<1>(a0)
+ , proto::child_c<1>(a1)
+ );
+ }
+
+ #define PHOENIX_LOCAL_GEN_NAME let_actor_gen
+ #include <boost/phoenix/scope/detail/local_gen.hpp>
+ #undef PHOENIX_LOCAL_GEN_NAME
+ };
+
+ let_gen const let = let_gen();
+}}
+
+#endif
Modified: sandbox/SOC/2010/phoenix3/libs/phoenix/test/scope/lambda_tests.cpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/libs/phoenix/test/scope/lambda_tests.cpp (original)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/scope/lambda_tests.cpp 2010-07-19 08:13:08 EDT (Mon, 19 Jul 2010)
@@ -76,7 +76,6 @@
int
main()
{
-
{
int x = 1;
int y = lambda[_1]()(x);
Modified: sandbox/SOC/2010/phoenix3/libs/phoenix/test/scope/let_tests.cpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/libs/phoenix/test/scope/let_tests.cpp (original)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/scope/let_tests.cpp 2010-07-19 08:13:08 EDT (Mon, 19 Jul 2010)
@@ -10,6 +10,8 @@
#include <vector>
#define PHOENIX_LIMIT 6
+#define PHOENIX_LOCAL_LIMIT 10
+#include <boost/phoenix/core/limits.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/phoenix/core.hpp>
@@ -35,7 +37,8 @@
(x) == x
);
}
-
+
+ /*
{
int x = 1, y = 10;
BOOST_TEST(
@@ -46,7 +49,9 @@
(x, y) == x + y
);
}
+ */
+ /*
{
int x = 1, y = 10, z = 13;
BOOST_TEST(
@@ -75,6 +80,7 @@
(x, y) == x + -y
);
}
+
{
int x = 999;
@@ -126,6 +132,7 @@
int x = (let(_a = 1)[let(_b = _1)[ _a ]])(y);
BOOST_TEST(x == 1);
}
+ */
{
// show that this code returns an lvalue
@@ -140,6 +147,7 @@
int& j = let(_a = arg1)[ _a ](i);
BOOST_TEST(&i == &j);
}
+
return boost::report_errors();
}
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