2
0
mirror of https://github.com/boostorg/phoenix.git synced 2026-02-14 13:02:10 +00:00

start of phoenix-3 core

[SVN r62422]
This commit is contained in:
Joel de Guzman
2010-06-04 06:02:29 +00:00
parent e42ef08568
commit a2557cce96
7 changed files with 212 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
/*=============================================================================
Copyright (c) 2001-2010 Joel de Guzman
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_CORE_HPP
#define PHOENIX_CORE_HPP
#include <boost/spirit/home/phoenix/version.hpp>
#endif

View File

@@ -0,0 +1,45 @@
/*=============================================================================
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 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 PHOENIX_CORE_ACTOR_HPP
#define PHOENIX_CORE_ACTOR_HPP
#include <boost/proto/proto.hpp>
namespace boost { namespace phoenix
{
////////////////////////////////////////////////////////////////////////////
// The actor class. The main thing! In phoenix, everything is an actor
// This class is responsible for full function evaluation. Partial
// function evaluation involves creating a hierarchy of actor objects.
////////////////////////////////////////////////////////////////////////////
template <class Expr>
struct actor
{
BOOST_PROTO_BASIC_EXTENDS(Expr, actor<Expr>, phoenix_domain)
BOOST_PROTO_EXTENDS_ASSIGN()
BOOST_PROTO_EXTENDS_SUBSCRIPT()
template <class Sig>
struct result : actor_result<Sig> {};
typedef actor<Expr> actor_type;
template <class A0>
typename boost::result_of<actor_type(A0 const&)>::type
operator()(A0 const& a0) const
{
BOOST_PROTO_ASSERT_MATCHES(*this, eval_grammar);
fusion::vector<A0 const&> args(a0);
return eval(*this, args);
}
/*... more...*/
};
}}
#endif

View File

@@ -0,0 +1,30 @@
/*=============================================================================
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 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 PHOENIX_CORE_ACTOR_RESULT_HPP
#define PHOENIX_CORE_ACTOR_RESULT_HPP
#include <boost/phoenix/core/meta_grammar.hpp>
#include <boost/fusion/container/vector.hpp>
namespace boost { namespace phoenix
{
////////////////////////////////////////////////////////////////////////////
// Return type computation
////////////////////////////////////////////////////////////////////////////
template<class Sig>
struct actor_result;
template <template Actor, template A0>
struct actor_result<Actor(A0)>
: boost::result_of<eval_grammar(Actor&, fusion::vector<A0>&)>
{};
/*... more ...*/
}}
#endif

View File

@@ -0,0 +1,25 @@
/*=============================================================================
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 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 PHOENIX_CORE_DOMAIN_HPP
#define PHOENIX_CORE_DOMAIN_HPP
#include <boost/proto/proto.hpp>
namespace boost { namespace phoenix
{
template <typename Expr>
struct actor;
struct phoenix_domain
: proto::domain<
proto::pod_generator<actor>,
proto::_, proto::default_domain>
{};
}}
#endif

View File

@@ -0,0 +1,82 @@
/*=============================================================================
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 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 PHOENIX_CORE_META_GRAMMAR_HPP
#define PHOENIX_CORE_META_GRAMMAR_HPP
#include <boost/proto/proto.hpp>
namespace boost { namespace phoenix
{
////////////////////////////////////////////////////////////////////////////
// Our meta-grammar and expression evaluator
////////////////////////////////////////////////////////////////////////////
struct eval_grammar
: proto::switch_<struct eval_cases>
{};
////////////////////////////////////////////////////////////////////////////
// A function object we can call
////////////////////////////////////////////////////////////////////////////
eval_grammar const eval = eval_grammar();
////////////////////////////////////////////////////////////////////////////
// Open ended grammar dispatch allows us to extend the grammar
// without modifying the code
////////////////////////////////////////////////////////////////////////////
struct eval_cases
{
template <class Tag>
struct case_ : proto::_default<eval_grammar> {};
};
////////////////////////////////////////////////////////////////////////////
// A dummy terminal that, when evaluated, returns the current state.
////////////////////////////////////////////////////////////////////////////
struct env
{};
////////////////////////////////////////////////////////////////////////////
// wrapper for a Fusion extension evaluator function. Keep this POD.
////////////////////////////////////////////////////////////////////////////
template <class Fun>
struct funcwrap
{
typedef Fun type;
};
// Handling for terminals, with the special case for env terminals.
struct func_grammar
: proto::or_<
proto::when<
proto::terminal<funcwrap<proto::_> >,
mpl::deref<proto::_value>()>
, proto::when<proto::terminal<env>, proto::_state>
, proto::_
>
{};
// Handling for function invocations. When _child0 is a
// funcwrap<>, don't evaluate the other child nodes. Just
// pass then unevaluated to the function.
template <>
struct eval_cases::case_<proto::tag::function>
: proto::or_<
proto::when<
proto::function<
proto::terminal<funcwrap<proto::_> >
, proto::terminal<env>
, proto::vararg<eval_grammar>
>
, proto::_default<func_grammar>
>
, proto::_default<eval_grammar>
>
{};
}}
#endif

View File

@@ -0,0 +1,18 @@
/*=============================================================================
Copyright (c) 2005-2008 Hartmut Kaiser
Copyright (c) 2005-2010 Joel de Guzman
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_VERSION_HPP
#define PHOENIX_VERSION_HPP
///////////////////////////////////////////////////////////////////////////////
//
// This is the version of the library
//
///////////////////////////////////////////////////////////////////////////////
#define BOOST_PHOENIX_VERSION 0x3000 // 3.0.0
#endif