Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61569 - in trunk/libs/spirit/example/scheme: scheme test/scheme
From: joel_at_[hidden]
Date: 2010-04-26 04:22:56


Author: djowel
Date: 2010-04-26 04:22:55 EDT (Mon, 26 Apr 2010)
New Revision: 61569
URL: http://svn.boost.org/trac/boost/changeset/61569

Log:
Scheme extension: forward declarations.
Text files modified:
   trunk/libs/spirit/example/scheme/scheme/compiler.hpp | 35 ++++++++++++++++++-----------------
   trunk/libs/spirit/example/scheme/test/scheme/scheme_test3.cpp | 1 +
   2 files changed, 19 insertions(+), 17 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-26 04:22:55 EDT (Mon, 26 Apr 2010)
@@ -322,32 +322,33 @@
         {
             try
             {
+ function* fp = 0;
                 if (env.defined(name))
                 {
- function* fp = env.find_forward(name);
- if (fp == 0 || !fp->empty())
+ fp = env.find_forward(name);
+ if (fp != 0 && !fp->empty())
                         throw body_already_defined(name);
+ }
 
- function lambda = make_lambda(args, fixed_arity, body);
- if (!lambda.empty())
- *fp = lambda(); // unprotect (eval returns a function)
- else
- throw no_body();
- return *fp;
+ if (fp == 0)
+ {
+ fragments.push_back(function());
+ fp = &fragments.back();
+ env.define(name, external_function(*fp, env.level()), args.size(), fixed_arity);
+ }
 
+ function lambda = make_lambda(args, fixed_arity, body);
+ if (!lambda.empty())
+ {
+ // unprotect (eval returns a function)
+ *fp = lambda();
                 }
                 else
                 {
- fragments.push_back(function());
- function& f = fragments.back();
- env.define(name, external_function(f, env.level()), args.size(), fixed_arity);
- function lambda = make_lambda(args, fixed_arity, body);
- if (!lambda.empty())
- f = lambda(); // unprotect (eval returns a function)
- else
- env.forward_declare(name, &f); // allow forward declaration of scheme functions
- return f;
+ // allow forward declaration of scheme functions
+ env.forward_declare(name, fp);
                 }
+ return *fp;
             }
             catch (std::exception const&)
             {

Modified: trunk/libs/spirit/example/scheme/test/scheme/scheme_test3.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/test/scheme/scheme_test3.cpp (original)
+++ trunk/libs/spirit/example/scheme/test/scheme/scheme_test3.cpp 2010-04-26 04:22:55 EDT (Mon, 26 Apr 2010)
@@ -35,6 +35,7 @@
     {
         // test forward declaration (a scheme extension)
         utree src =
+ "(define (dbl n))" // multiple forward declarations allowed
             "(define (dbl n))"
             "(define foo (dbl 10))"
             "(define (dbl n) (* n 2))"


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