Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61221 - in trunk/libs/spirit/example/scheme: . detail test
From: joel_at_[hidden]
Date: 2010-04-12 04:24:22


Author: djowel
Date: 2010-04-12 04:24:21 EDT (Mon, 12 Apr 2010)
New Revision: 61221
URL: http://svn.boost.org/trac/boost/changeset/61221

Log:
now ok with g++ and msvc
Text files modified:
   trunk/libs/spirit/example/scheme/detail/utree_detail2.hpp | 20 --------------------
   trunk/libs/spirit/example/scheme/scheme_interpreter.hpp | 23 ++++++++++++++---------
   trunk/libs/spirit/example/scheme/test/scheme_test.scm | 13 ++++++++++---
   trunk/libs/spirit/example/scheme/utree.hpp | 17 +----------------
   trunk/libs/spirit/example/scheme/utree_operators.hpp | 16 ++--------------
   5 files changed, 27 insertions(+), 62 deletions(-)

Modified: trunk/libs/spirit/example/scheme/detail/utree_detail2.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/detail/utree_detail2.hpp (original)
+++ trunk/libs/spirit/example/scheme/detail/utree_detail2.hpp 2010-04-12 04:24:21 EDT (Mon, 12 Apr 2010)
@@ -375,9 +375,6 @@
 
                 case type::reference_type:
                     return apply(*x.p, f);
-
- case type::function_type:
- return f(x.f);
             }
         }
 
@@ -431,9 +428,6 @@
 
                 case type::reference_type:
                     return apply(*x.p, y, f);
-
- case type::function_type:
- return visit_impl::apply(y, detail::bind(f, x.f));
             }
         }
     };
@@ -514,12 +508,6 @@
         set_type(type::reference_type);
     }
 
- inline utree::utree(function_ptr fptr)
- : f(fptr)
- {
- set_type(type::function_type);
- }
-
     inline utree::utree(utree const& other)
     {
         copy(other);
@@ -605,14 +593,6 @@
         return *this;
     }
 
- inline utree& utree::operator=(function_ptr fptr)
- {
- free();
- f = fptr;
- set_type(type::function_type);
- return *this;
- }
-
     template <typename F>
     typename F::result_type
     inline utree::visit(utree const& x, F f)

Modified: trunk/libs/spirit/example/scheme/scheme_interpreter.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/scheme_interpreter.hpp (original)
+++ trunk/libs/spirit/example/scheme/scheme_interpreter.hpp 2010-04-12 04:24:21 EDT (Mon, 12 Apr 2010)
@@ -233,7 +233,8 @@
         }
     };
 
- function_composer const if_ = if_composer();
+ function_composer const if_
+ = function_composer(if_composer());
 
     ///////////////////////////////////////////////////////////////////////////
     // less_than_equal
@@ -264,7 +265,8 @@
         }
     };
 
- function_composer const less_than_equal = less_than_equal_composer();
+ function_composer const less_than_equal
+ = function_composer(less_than_equal_composer());
 
     ///////////////////////////////////////////////////////////////////////////
     // plus
@@ -296,7 +298,8 @@
         }
     };
 
- function_composer const plus = plus_composer();
+ function_composer const plus
+ = function_composer(plus_composer());
 
     ///////////////////////////////////////////////////////////////////////////
     // minus
@@ -331,7 +334,8 @@
         }
     };
 
- function_composer const minus = minus_composer();
+ function_composer const minus
+ = function_composer(minus_composer());
 
     ///////////////////////////////////////////////////////////////////////////
     // times
@@ -363,7 +367,8 @@
         }
     };
 
- function_composer const times = times_composer();
+ function_composer const times
+ = function_composer(times_composer());
 
     ///////////////////////////////////////////////////////////////////////////
     // lambda
@@ -392,8 +397,8 @@
     {
         // we must hold f by reference because functions can be recursive
         boost::reference_wrapper<actor const> f;
- int arity;
- lambda_composer(actor const& f, int arity)
+ std::size_t arity;
+ lambda_composer(actor const& f, std::size_t arity)
           : f(f), arity(arity) {}
 
         typedef actor result_type;
@@ -405,9 +410,9 @@
         }
     };
 
- inline function_composer const lambda(actor const& f, int arity)
+ inline function_composer const lambda(actor const& f, std::size_t arity)
     {
- return lambda_composer(f, arity);
+ return function_composer(lambda_composer(f, arity));
     }
 }
 

Modified: trunk/libs/spirit/example/scheme/test/scheme_test.scm
==============================================================================
--- trunk/libs/spirit/example/scheme/test/scheme_test.scm (original)
+++ trunk/libs/spirit/example/scheme/test/scheme_test.scm 2010-04-12 04:24:21 EDT (Mon, 12 Apr 2010)
@@ -1,5 +1,12 @@
 (define (dbl x) (+ x x))
+
 (define len 123)
-(dbl len)
-(define (factorial n) (if (<= n 0) 1 (* n (factorial (- n 1)))))
-(factorial 10)
\ No newline at end of file
+
+(dbl len) ; 246
+
+; The hello-world for interpreters ;-)
+(define (factorial n)
+ (if (<= n 0) 1
+ (* n (factorial (- n 1)))))
+
+(factorial 10) ; 3628800
\ No newline at end of file

Modified: trunk/libs/spirit/example/scheme/utree.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/utree.hpp (original)
+++ trunk/libs/spirit/example/scheme/utree.hpp 2010-04-12 04:24:21 EDT (Mon, 12 Apr 2010)
@@ -44,8 +44,7 @@
             symbol_type,
             binary_type,
             list_type,
- reference_type,
- function_type
+ reference_type
         };
     };
 
@@ -55,17 +54,6 @@
     struct nil {};
 
     ///////////////////////////////////////////////////////////////////////////
- // The environment (this is forward declared)
- ///////////////////////////////////////////////////////////////////////////
- class environment;
-
- ///////////////////////////////////////////////////////////////////////////
- // Function pointer
- ///////////////////////////////////////////////////////////////////////////
- class utree;
- typedef utree (*function_ptr)(environment& env);
-
- ///////////////////////////////////////////////////////////////////////////
     // A typed string with parametric Base storage. The storage can be any
     // range or (stl container) of chars.
     ///////////////////////////////////////////////////////////////////////////
@@ -181,7 +169,6 @@
         utree(char const* str, std::size_t len);
         utree(std::string const& str);
         utree(boost::reference_wrapper<utree> ref);
- utree(function_ptr fptr);
 
         template <typename Base, utree_type::info type_>
         utree(basic_string<Base, type_> const& bin);
@@ -197,7 +184,6 @@
         utree& operator=(char const* s);
         utree& operator=(std::string const& s);
         utree& operator=(boost::reference_wrapper<utree> ref);
- utree& operator=(function_ptr fptr);
 
         template <typename Base, utree_type::info type_>
         utree& operator=(basic_string<Base, type_> const& bin);
@@ -298,7 +284,6 @@
             int i;
             double d;
             utree* p;
- function_ptr f;
         };
     };
 }

Modified: trunk/libs/spirit/example/scheme/utree_operators.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/utree_operators.hpp (original)
+++ trunk/libs/spirit/example/scheme/utree_operators.hpp 2010-04-12 04:24:21 EDT (Mon, 12 Apr 2010)
@@ -7,11 +7,6 @@
 #if !defined(BOOST_SPIRIT_UTREE_OPERATORS)
 #define BOOST_SPIRIT_UTREE_OPERATORS
 
-#if defined(BOOST_MSVC)
-# pragma warning(push)
-# pragma warning(disable: 4804)
-#endif
-
 #include "utree.hpp"
 #include <boost/preprocessor/cat.hpp>
 #include <boost/type_traits/is_arithmetic.hpp>
@@ -211,11 +206,6 @@
             }
             (*this)(')');
         }
-
- void operator()(function_ptr fptr) const
- {
- out << "function-pointer(" << fptr << ')';
- }
     };
 
     template <typename Base>
@@ -375,6 +365,8 @@
         template <typename A> \
         static utree eval(A const& a) \
         { \
+ static int b; \
+ (void) b; \
             return utree(expr); \
         } \
     }; \
@@ -524,8 +516,4 @@
     }
 }
 
-#if defined(BOOST_MSVC)
-# pragma warning(pop)
-#endif
-
 #endif


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