Re: [proto] Using Phoenix inside eUML: mixing grammars

2011-05-02 Thread Christophe Henry
>> Anyway, I am hoping not to write any cool transform but simply save
>> the type of the phoenix expression so that I can re-create an actor
>> later. If I need to rewrite differently what BuildGuards was doing, I
>> gain little. I would like phoenix to do the grammar parsing and
>> building of actor.
>
> It does ... just pass on proto::_right and it should be good:
>
> struct BuildEventPlusGuard
>  : proto::when<
>proto::subscript<
>proto::terminal
>  , phoenix::meta_grammar  // match the phoenix actor
>>
>  , TempRow<
>none
>  , proto::_left
>  , none
>  , none
>  , proto::_right // Pass the type along. which is a phoenix actor.
>>(proto::_right)  // Pass the object along. Which is the actor (1)
>>
> {};

Great! This is what I unsuccessfully tried (I was missing the second
proto::_right, my bad).

> (1): Here you can work around the thing with the possibly uninitialized stuff.
> Just copy the phoenix actor (should be cheap, if not optimized away 
> completely).

Oh the copy is really not a problem, the transition table is purely a
compile-time construct, there is no call at run-time.

So, for Michael who must be impatient to see some progress, so far this works:

struct some_guard_impl
{
typedef bool result_type;

bool operator()()
{
cout << "calling: some_guard" << endl;
return true;
}
};
boost::phoenix::function some_guard;

struct some_action_impl
{
typedef void result_type;

void operator()()
{
cout << "calling: some_action" << endl;
}
};
boost::phoenix::function some_action;

BOOST_MSM_EUML_TRANSITION_TABLE((
  Open == Empty + open_close
[some_guard()&&some_guard()] / (some_action(),some_action())

  // these standard constructs are also ok
  //Open == Empty + open_close  / some_action()
  //Empty + open_close  [some_guard()] / some_action()
  //Open == Empty   / some_action()
  //  
+--+
 ),transition_table)


So far it's looking pretty good. I still have stuff to think about but
I like the direction this takes.

Thanks,
Christophe
___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto


Re: [proto] Using Phoenix inside eUML: mixing grammars

2011-05-01 Thread Michael Caisse

On 05/01/2011 10:32 PM, Thomas Heller wrote:

On Monday, April 25, 2011 06:39:14 PM Christophe Henry wrote:
   

Anyway, I am hoping not to write any cool transform but simply save
the type of the phoenix expression so that I can re-create an actor
later. If I need to rewrite differently what BuildGuards was doing, I
gain little. I would like phoenix to do the grammar parsing and
building of actor.
 

It does ... just pass on proto::_right and it should be good:

struct BuildEventPlusGuard
   : proto::when<
 proto::subscript<
 proto::terminal
   , phoenix::meta_grammar  // match the phoenix actor
 >
   , TempRow<
 none
   , proto::_left
   , none
   , none
   , proto::_right // Pass the type along. which is a phoenix actor.
 >(proto::_right)  // Pass the object along. Which is the actor (1)
 >
{};

(1): Here you can work around the thing with the possibly uninitialized stuff.
Just copy the phoenix actor (should be cheap, if not optimized away completely).

   

Thanks,
Christophe
 

___
   


Not that you guys need it... but just consider me on the sidelines 
cheering you on. I've been spending a lot of time lately with MSM and 
would *love* too see some Phoenix 3 support in it!


michael

--
In the Sacramento/Folsom area?
** Profesional C++ Training mid-May **
http://www.objectmodelingdesigns.com/boostcon_deal.html

Michael Caisse
Object Modeling Designs
www.objectmodelingdesigns.com

___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto


Re: [proto] Using Phoenix inside eUML: mixing grammars

2011-05-01 Thread Thomas Heller
On Monday, April 25, 2011 06:39:14 PM Christophe Henry wrote:
> Hi Thomas,
> 
> Sorry to come back to the subject so late, I didn't manage before :(
> 
> > If you want to use it as a transform you need the evaluator with an
> > appropriate action that does the desired transform... here is an
> > example:
> >
> > struct BuildEventPlusGuard
> >  : proto::when<
> >  proto::subscript,
> > phoenix::meta_grammar >,
> >  TempRow > phoenix::evaluator(proto::_right, some_cool_action())>()
> >  >
> > {};
> >
> > Now, some_cool_action can do the transform that BuildGuards was doing.
> 
> Hmmm, I get a compiler error, which was expected (would be too easy
> otherwise ;- ) ), but the error is surprising. The error is that
> phoenix::evaluator seems to believe some_cool_action should be a
> random access fusion sequence (expects an environment?).

You are right ... slippery on my side ... evaluator expects a context, which is 
a tuple containing the environment and the actions: http://goo.gl/24fU9

> Anyway, I am hoping not to write any cool transform but simply save
> the type of the phoenix expression so that I can re-create an actor
> later. If I need to rewrite differently what BuildGuards was doing, I
> gain little. I would like phoenix to do the grammar parsing and
> building of actor.

It does ... just pass on proto::_right and it should be good:

struct BuildEventPlusGuard
  : proto::when<
proto::subscript<
proto::terminal
  , phoenix::meta_grammar  // match the phoenix actor
>
  , TempRow<
none
  , proto::_left
  , none
  , none
  , proto::_right // Pass the type along. which is a phoenix actor.
>(proto::_right)  // Pass the object along. Which is the actor (1)
>
{};

(1): Here you can work around the thing with the possibly uninitialized stuff. 
Just copy the phoenix actor (should be cheap, if not optimized away completely).

> Thanks,
> Christophe
___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto


Re: [proto] Using Phoenix inside eUML: mixing grammars

2011-04-25 Thread Christophe Henry
Hi Thomas,

Sorry to come back to the subject so late, I didn't manage before :(

> If you want to use it as a transform you need the evaluator with an
> appropriate action that does the desired transform... here is an
> example:
>
> struct BuildEventPlusGuard
>  : proto::when<
>  proto::subscript,
> phoenix::meta_grammar >,
>  TempRow phoenix::evaluator(proto::_right, some_cool_action())>()
>  >
> {};
>
> Now, some_cool_action can do the transform that BuildGuards was doing.

Hmmm, I get a compiler error, which was expected (would be too easy
otherwise ;- ) ), but the error is surprising. The error is that
phoenix::evaluator seems to believe some_cool_action should be a
random access fusion sequence (expects an environment?).

Anyway, I am hoping not to write any cool transform but simply save
the type of the phoenix expression so that I can re-create an actor
later. If I need to rewrite differently what BuildGuards was doing, I
gain little. I would like phoenix to do the grammar parsing and
building of actor.

Thanks,
Christophe
___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto


Re: [proto] Using Phoenix inside eUML: mixing grammars

2011-03-21 Thread Thomas Heller
On Wed, Mar 16, 2011 at 9:56 PM, Christophe Henry
 wrote:
> Hi,

Sorry for the late reply ...

> I have my eUML grammar, defing, for example a transition as:
>
> SourceState+ Event [some_guard] == TargetState
>
> I want to write for some_guard an expression of a phoenix grammar. The
> relevant part of the expression is:
> Event [some_guard]
>
> Where the corresponding part of my grammar is:
>
> struct BuildEventPlusGuard
>    : proto::when<
>            proto::subscript,BuildGuards >,
>            TempRow()
>        >
> {};
>
> BuildGuards is, at the moment, a proto::switch_ grammar, which I want
> to replace with something matching a phoenix grammar and returning me
> a phoenix::actor, which I will then save into TempRow.
> I suppose I could typeof/decltype the phoenix expression but it
> doesn't seem like the best solution, I'd prefer to delay this.
> Is there something like a phoenix grammar which I can call to check if
> the expression is valid, and if yes, which will return me the correct
> phoenix::actor?

There is boos::phoenix::meta_grammar which can be used to check for
valid phoenix expressions. It is really just the grammar, you can't
use it as a transform.
In your case you can reuse the meta grammar in a great way to restrict
certain constructs:

struct my_custom_phoenix_grammar
: proto::switch_
{
template 
struct case_ : meta_grammar::case_ {};
};

The above, by default allows everything that's in meta_grammar with
the ability to override some of meta_grammar's rules.

If you want to use it as a transform you need the evaluator with an
appropriate action that does the desired transform... here is an
example:

 struct BuildEventPlusGuard
    : proto::when<
            proto::subscript,
phoenix::meta_grammar >,
            TempRow()
        >
 {};

Now, some_cool_action can do the transform that BuildGuards was doing.

> Second question. Now it's becoming more "interesting". And not easy to
> explain :(
>
> For eUML, a guard can be defined as "g1 && g2", where g1 and g2 are
> functors, taking 4 arguments. For example (to make short):
> struct g1_
> {
>    template 
>    void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
>    {
>        ...
>    }
> };
>  g1_ g1;
>
> The fact that there are 4 arguments is the condition to make this work
> without placeholders.
>
> I 'm pretty sure that, while this clearly should be a function for
> phoenix, I would not like the syntax:
> g1(arg1,arg2,arg3,arg4) && g2(arg1,arg2,arg3,arg4).
>
> Is it possible to define g1 and g2 as custom terminals, but still get
> them treated like functions?

Yes!

Here is an example:

template 
struct msm_guard
{};

template 
struct msm_guard_actor;

template 
struct msm_guard_expression
: phoenix::terminal, msm_guard_actor>
{};

template 
struct msm_guard_actor
{
typedef actor base_type;
base_type expr;
msm_guard_actor(base_type const & base) : expr(base) {}

// define the operator() overloads here to allow something
// that michael suggested. The result should be full blown phoenix
// expressions (BOOST_PHOENIX_DEFINE_EXPRESSION)
};

namespace boost { namespace phoenix {
namespace result_of
{
template 
is_nullary > : mpl::false_ {};
}
template 
struct is_custom_terminal > : mpl::true_ {};

template 
struct custom_terminal >
: proto::call<
G(
proto::functional::at(_env, mpl::int_<1>())
  , proto::functional::at(_env, mpl::int_<2>())
  , proto::functional::at(_env, mpl::int_<3>())
  , proto::functional::at(_env, mpl::int_<4>())
   )
   >
{};
}}

I hope that above example helps you and clarifies how to customize
phoenix V3 even further.
Note on that terminal thing: It's not in trunk yet ... I did on
another computer, cause the spirit port needed it ... I don't have
access to that computer right now ... I will commit it later today.

> (To solve the problem, my current implementation generates me a
> functor of type And_ which has an operator () with 4
> arguments).
>
> Thanks,
> Christophe
> ___
> proto mailing list
> proto@lists.boost.org
> http://lists.boost.org/mailman/listinfo.cgi/proto
>
___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto


Re: [proto] Using Phoenix inside eUML: mixing grammars

2011-03-21 Thread Christophe Henry
>> I 'm pretty sure that, while this clearly should be a function for
>> phoenix, I would not like the syntax:
>> g1(arg1,arg2,arg3,arg4)&&  g2(arg1,arg2,arg3,arg4).
>>
>
> Placeholders would be great here. I find most of the time I only care
> about EVT or EVT and FSM. Having MSM defined placeholders with cool
> names like evt_ and fsm_ wouldn't be bad IMHO.

These already exist but you are proving me that they aren't used to
their full potential now.


> Also... shouldn't operator() return a bool for a guard? Then this just
> becomes a composition. If g1 and g2 are phoenix functions then (making
> up some new MSM placeholders):
>
>  g1(evt_) && g2(evt_,fsm_)
>
>will result in the composed lazy functors and placeholders are now
> your friends.

Nice!

> This also allows me to write full phoenix lambdas inline with the eUML
> which would be the cat's meow!

Yes, looks great! Actually, it would also be possible with today's
implementation, so that I don't know why I didn't do it yet. Shame on
me ;-)
I use this stuff for example in:
clear_(fsm_(m_src_container))

But I didn't think of generalizing this.

However, I'd still like to also have the possibility to write only g1
&& g2, treating g1 and g2 as terminals. The reason is that this way, I
am currently able to use the functor front end functors inside eUML,
which is quite nice. I'm pretty sure it'd be possible with phoenix too
and I'd avoid a regression.

> I like the way these discussions are going Christophe!
>
> michael

Me too! I have the hope the discussions on this list will deliver
something really cool.
Thanks for the great point!
Unfortunately, I didn't manage to get further on the first (blocking)
point yet :(

Thanks,
Christophe
___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto


Re: [proto] Using Phoenix inside eUML: mixing grammars

2011-03-20 Thread Michael Caisse

On 03/16/2011 01:56 PM, Christophe Henry wrote:

Hi,

I have my eUML grammar, defing, for example a transition as:

   





Second question. Now it's becoming more "interesting". And not easy to
explain :(

For eUML, a guard can be defined as "g1&&  g2", where g1 and g2 are
functors, taking 4 arguments. For example (to make short):
struct g1_
{
 template
 void operator()(EVT const&  ,FSM&,SourceState&  ,TargetState&  )
 {
 ...
 }
};
  g1_ g1;

The fact that there are 4 arguments is the condition to make this work
without placeholders.

I 'm pretty sure that, while this clearly should be a function for
phoenix, I would not like the syntax:
g1(arg1,arg2,arg3,arg4)&&  g2(arg1,arg2,arg3,arg4).
   


Placeholders would be great here. I find most of the time I only care 
about EVT or EVT and FSM. Having MSM defined placeholders with cool 
names like evt_ and fsm_ wouldn't be bad IMHO.


Also... shouldn't operator() return a bool for a guard? Then this just 
becomes a composition. If g1 and g2 are phoenix functions then (making 
up some new MSM placeholders):


 g1(evt_) && g2(evt_,fsm_)

   will result in the composed lazy functors and placeholders are now 
your friends.


This also allows me to write full phoenix lambdas inline with the eUML 
which would be the cat's meow!


I like the way these discussions are going Christophe!

michael

--

Michael Caisse
Object Modeling Designs
www.objectmodelingdesigns.com

___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto