Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61392 - in trunk/libs/spirit/example/scheme: scheme test/utree utree/detail
From: joel_at_[hidden]
Date: 2010-04-18 23:26:53


Author: djowel
Date: 2010-04-18 23:26:52 EDT (Sun, 18 Apr 2010)
New Revision: 61392
URL: http://svn.boost.org/trac/boost/changeset/61392

Log:
trimmed back utree size to 16 bytes (on 32 bit machines)
Text files modified:
   trunk/libs/spirit/example/scheme/scheme/compiler.hpp | 11 ++++++++---
   trunk/libs/spirit/example/scheme/test/utree/utree_test.cpp | 7 +++++++
   trunk/libs/spirit/example/scheme/utree/detail/utree_detail1.hpp | 4 +++-
   trunk/libs/spirit/example/scheme/utree/detail/utree_detail2.hpp | 21 ++++++++++++++++++---
   4 files changed, 36 insertions(+), 7 deletions(-)

Modified: trunk/libs/spirit/example/scheme/scheme/compiler.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/scheme/compiler.hpp (original)
+++ trunk/libs/spirit/example/scheme/scheme/compiler.hpp 2010-04-18 23:26:52 EDT (Sun, 18 Apr 2010)
@@ -65,9 +65,14 @@
 
     struct incorrect_arity : scheme_exception
     {
+ std::string msg;
+ incorrect_arity(std::string const& id)
+ : msg("scheme: Invalid number of parameters to function call ("
+ + id + ')') {}
+
         virtual const char* what() const throw()
         {
- return "scheme: Invalid number of parameters to function call";
+ return msg.c_str();;
         }
     };
 
@@ -287,12 +292,12 @@
                 if (r.second < 0) // non-fixed arity
                 {
                     if (int(flist.size()) < -r.second)
- throw incorrect_arity();
+ throw incorrect_arity(name);
                 }
                 else // fixed arity
                 {
                     if (int(flist.size()) != r.second)
- throw incorrect_arity();
+ throw incorrect_arity(name);
                 }
                 return (*r.first)(flist);
             }

Modified: trunk/libs/spirit/example/scheme/test/utree/utree_test.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/test/utree/utree_test.cpp (original)
+++ trunk/libs/spirit/example/scheme/test/utree/utree_test.cpp 2010-04-18 23:26:52 EDT (Sun, 18 Apr 2010)
@@ -248,5 +248,12 @@
         check(ref, "( 1 2 3 4 )");
     }
 
+ {
+ // check the tag
+ utree x;
+ x.tag(123);
+ BOOST_TEST(x.tag() == 123);
+ }
+
     return boost::report_errors();
 }

Modified: trunk/libs/spirit/example/scheme/utree/detail/utree_detail1.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/utree/detail/utree_detail1.hpp (original)
+++ trunk/libs/spirit/example/scheme/utree/detail/utree_detail1.hpp 2010-04-18 23:26:52 EDT (Sun, 18 Apr 2010)
@@ -53,7 +53,6 @@
         node* first;
         node* last;
         std::size_t size;
- short tag;
     };
 
     ///////////////////////////////////////////////////////////////////////////
@@ -111,6 +110,9 @@
 
         char& info();
         char info() const;
+
+ short tag() const;
+ void tag(short tag);
     };
 }}
 

Modified: trunk/libs/spirit/example/scheme/utree/detail/utree_detail2.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/utree/detail/utree_detail2.hpp (original)
+++ trunk/libs/spirit/example/scheme/utree/detail/utree_detail2.hpp 2010-04-18 23:26:52 EDT (Sun, 18 Apr 2010)
@@ -35,6 +35,21 @@
         info() = (t << 1) | (info() & 1);
     }
 
+ short fast_string::tag() const
+ {
+ // warning the tag is not allowed for fast_string!!! it's only
+ // placed here to avoid excess padding.
+ return (int(buff[small_string_size-2]) << 8) + buff[small_string_size-1];
+ }
+
+ void fast_string::tag(short tag)
+ {
+ // warning the tag is not allowed for fast_string!!! it's only
+ // placed here to avoid excess padding.
+ buff[small_string_size-2] = tag >> 8;
+ buff[small_string_size-1] = tag & 0xff;
+ }
+
     inline bool fast_string::is_heap_allocated() const
     {
         return info() & 1;
@@ -258,7 +273,6 @@
         first = last = 0;
         size = 0;
         node* p = other.first;
- tag = other.tag;
         while (p != 0)
         {
             push_back(p->val);
@@ -1024,6 +1038,7 @@
                 break;
             case type::list_type:
                 l.copy(other.l);
+ s.tag(other.s.tag());
                 break;
         }
     }
@@ -1073,13 +1088,13 @@
     inline short utree::tag() const
     {
         BOOST_ASSERT(get_type() == type::list_type);
- return l.tag;
+ return s.tag();
     }
 
     inline void utree::tag(short tag)
     {
         ensure_list_type();
- l.tag = tag;
+ s.tag(tag);
     }
 }
 


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