Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69618 - in trunk/libs/spirit/example/qi/compiler_tutorial: . calc7 calc8 mini_c
From: joel_at_[hidden]
Date: 2011-03-07 02:02:29


Author: djowel
Date: 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
New Revision: 69618
URL: http://svn.boost.org/trac/boost/changeset/69618

Log:
mini_c + updates
Added:
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/annotation.hpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/ast.hpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/compiler.cpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/compiler.hpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/error_handler.hpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression.cpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression.hpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression_def.hpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/function.cpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/function.hpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/function_def.hpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/main.cpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/skipper.hpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/statement.cpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/statement.hpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/statement_def.hpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/vm.cpp (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/vm.hpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/example/qi/compiler_tutorial/Jamfile | 11 +++
   trunk/libs/spirit/example/qi/compiler_tutorial/calc7/compiler.cpp | 12 +-
   trunk/libs/spirit/example/qi/compiler_tutorial/calc7/compiler.hpp | 8 +-
   trunk/libs/spirit/example/qi/compiler_tutorial/calc7/expression.cpp | 2
   trunk/libs/spirit/example/qi/compiler_tutorial/calc7/expression.hpp | 4
   trunk/libs/spirit/example/qi/compiler_tutorial/calc7/expression_def.hpp | 4
   trunk/libs/spirit/example/qi/compiler_tutorial/calc7/main.cpp | 8 +
   trunk/libs/spirit/example/qi/compiler_tutorial/calc7/statement.cpp | 2
   trunk/libs/spirit/example/qi/compiler_tutorial/calc7/statement.hpp | 4
   trunk/libs/spirit/example/qi/compiler_tutorial/calc7/statement_def.hpp | 4
   trunk/libs/spirit/example/qi/compiler_tutorial/calc7/vm.cpp | 2
   trunk/libs/spirit/example/qi/compiler_tutorial/calc7/vm.hpp | 2
   trunk/libs/spirit/example/qi/compiler_tutorial/calc8/compiler.cpp | 131 ++++++++++++++++++++++++---------------
   trunk/libs/spirit/example/qi/compiler_tutorial/calc8/compiler.hpp | 14 +--
   trunk/libs/spirit/example/qi/compiler_tutorial/calc8/expression.cpp | 2
   trunk/libs/spirit/example/qi/compiler_tutorial/calc8/expression.hpp | 4
   trunk/libs/spirit/example/qi/compiler_tutorial/calc8/expression_def.hpp | 5
   trunk/libs/spirit/example/qi/compiler_tutorial/calc8/main.cpp | 16 ++--
   trunk/libs/spirit/example/qi/compiler_tutorial/calc8/statement.cpp | 2
   trunk/libs/spirit/example/qi/compiler_tutorial/calc8/statement.hpp | 4
   trunk/libs/spirit/example/qi/compiler_tutorial/calc8/statement_def.hpp | 4
   trunk/libs/spirit/example/qi/compiler_tutorial/calc8/vm.cpp | 45 ++++++++++--
   trunk/libs/spirit/example/qi/compiler_tutorial/calc8/vm.hpp | 23 ++++--
   23 files changed, 194 insertions(+), 119 deletions(-)

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/Jamfile
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/Jamfile (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/Jamfile 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -34,3 +34,14 @@
     calc8/statement.cpp
     calc8/main.cpp
     ;
+
+exe mini_c :
+ mini_c/vm.cpp
+ mini_c/compiler.cpp
+ mini_c/expression.cpp
+ mini_c/statement.cpp
+ mini_c/function.cpp
+ mini_c/main.cpp
+ ;
+
+

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc7/compiler.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc7/compiler.cpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc7/compiler.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -10,7 +10,7 @@
 #include <boost/variant/apply_visitor.hpp>
 #include <boost/assert.hpp>
 
-namespace client
+namespace client { namespace code_gen
 {
     void program::op(int a)
     {
@@ -101,8 +101,8 @@
                     std::cout << "op_int " << *pc++ << std::endl;
                     break;
 
- case op_adstk:
- std::cout << "op_adstk " << *pc++ << std::endl;
+ case op_stk_adj:
+ std::cout << "op_stk_adj " << *pc++ << std::endl;
                     break;
             }
         }
@@ -204,8 +204,8 @@
     {
         program.clear();
 
- // op_adstk 0 for now. we'll know how many variables we'll have later
- program.op(op_adstk, 0);
+ // op_stk_adj 0 for now. we'll know how many variables we'll have later
+ program.op(op_stk_adj, 0);
         BOOST_FOREACH(ast::statement const& s, x)
         {
             if (!boost::apply_visitor(*this, s))
@@ -217,5 +217,5 @@
         program[1] = program.nvars(); // now store the actual number of variables
         return true;
     }
-}
+}}
 

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc7/compiler.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc7/compiler.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc7/compiler.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -16,7 +16,7 @@
 #include <boost/spirit/include/phoenix_function.hpp>
 #include <boost/spirit/include/phoenix_operator.hpp>
 
-namespace client
+namespace client { namespace code_gen
 {
     ///////////////////////////////////////////////////////////////////////////
     // The Program
@@ -53,7 +53,7 @@
         typedef bool result_type;
 
         template <typename ErrorHandler>
- compiler(client::program& program, ErrorHandler& error_handler_)
+ compiler(client::code_gen::program& program, ErrorHandler& error_handler_)
           : program(program)
         {
             using namespace boost::phoenix::arg_names;
@@ -74,12 +74,12 @@
         bool operator()(ast::variable_declaration const& x) const;
         bool operator()(ast::statement_list const& x) const;
 
- client::program& program;
+ client::code_gen::program& program;
 
         boost::function<
             void(int tag, std::string const& what)>
         error_handler;
     };
-}
+}}
 
 #endif
\ No newline at end of file

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc7/expression.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc7/expression.cpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc7/expression.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -11,4 +11,4 @@
 #include "expression_def.hpp"
 
 typedef std::string::const_iterator iterator_type;
-template struct client::expression<iterator_type>;
+template struct client::parser::expression<iterator_type>;

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc7/expression.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc7/expression.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc7/expression.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -26,7 +26,7 @@
 #include "error_handler.hpp"
 #include <vector>
 
-namespace client
+namespace client { namespace parser
 {
     namespace qi = boost::spirit::qi;
     namespace ascii = boost::spirit::ascii;
@@ -46,7 +46,7 @@
         qi::rule<Iterator, ast::operand(), ascii::space_type> primary_expr;
         qi::rule<Iterator, std::string(), ascii::space_type> identifier;
     };
-}
+}}
 
 #endif
 

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc7/expression_def.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc7/expression_def.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc7/expression_def.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -9,7 +9,7 @@
 #include "annotation.hpp"
 #include <boost/spirit/include/phoenix_function.hpp>
 
-namespace client
+namespace client { namespace parser
 {
     template <typename Iterator>
     expression<Iterator>::expression(error_handler<Iterator>& error_handler)
@@ -89,6 +89,6 @@
         on_success(primary_expr,
             annotation_function(error_handler.iters)(_val, _1));
     }
-}
+}}
 
 

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc7/main.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc7/main.cpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc7/main.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -53,13 +53,15 @@
     iterator_type end = source.end();
 
     client::vmachine vm; // Our virtual machine
- client::program program; // Our VM program
+ client::code_gen::program program; // Our VM program
     client::ast::statement_list ast; // Our AST
 
     client::error_handler<iterator_type>
         error_handler(iter, end); // Our error handler
- client::statement<iterator_type> parser(error_handler); // Our parser
- client::compiler compile(program, error_handler); // Our compiler
+ client::parser::statement<iterator_type>
+ parser(error_handler); // Our parser
+ client::code_gen::compiler
+ compile(program, error_handler); // Our compiler
 
     boost::spirit::ascii::space_type space;
     bool success = phrase_parse(iter, end, parser, space, ast);

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc7/statement.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc7/statement.cpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc7/statement.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -11,4 +11,4 @@
 #include "statement_def.hpp"
 
 typedef std::string::const_iterator iterator_type;
-template struct client::statement<iterator_type>;
+template struct client::parser::statement<iterator_type>;

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc7/statement.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc7/statement.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc7/statement.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -9,7 +9,7 @@
 
 #include "expression.hpp"
 
-namespace client
+namespace client { namespace parser
 {
     ///////////////////////////////////////////////////////////////////////////////
     // The statement grammar
@@ -25,7 +25,7 @@
         qi::rule<Iterator, ast::assignment(), ascii::space_type> assignment;
         qi::rule<Iterator, std::string(), ascii::space_type> identifier;
     };
-}
+}}
 
 #endif
 

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc7/statement_def.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc7/statement_def.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc7/statement_def.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -8,7 +8,7 @@
 #include "error_handler.hpp"
 #include "annotation.hpp"
 
-namespace client
+namespace client { namespace parser
 {
     template <typename Iterator>
     statement<Iterator>::statement(error_handler<Iterator>& error_handler)
@@ -70,6 +70,6 @@
         on_success(assignment,
             annotation_function(error_handler.iters)(_val, _1));
     }
-}
+}}
 
 

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc7/vm.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc7/vm.cpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc7/vm.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -55,7 +55,7 @@
                     *stack_ptr++ = *pc++;
                     break;
 
- case op_adstk:
+ case op_stk_adj:
                     stack_ptr = stack.begin() + *pc++;
                     break;
             }

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc7/vm.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc7/vm.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc7/vm.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -25,7 +25,7 @@
         op_load, // load a variable
         op_store, // store a variable
         op_int, // push constant integer into the stack
- op_adstk // adjust the stack for local variables
+ op_stk_adj // adjust the stack for local variables
     };
 
     class vmachine

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc8/compiler.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc8/compiler.cpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc8/compiler.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -9,8 +9,10 @@
 #include <boost/foreach.hpp>
 #include <boost/variant/apply_visitor.hpp>
 #include <boost/assert.hpp>
+#include <boost/lexical_cast.hpp>
+#include <set>
 
-namespace client
+namespace client { namespace code_gen
 {
     void program::op(int a)
     {
@@ -65,107 +67,138 @@
                 << p.first << ", @" << p.second << std::endl;
         }
 
- std::cout << "start:" << std::endl;
+ std::map<std::size_t, std::string> lines;
+ std::set<std::size_t> jumps;
+
         while (pc != code.end())
         {
- std::size_t pos = pc-code.begin();
- if (jumps.find(pos) != jumps.end())
- std::cout << pos << ':' << std::endl;
+ std::string line;
+ std::size_t address = pc - code.begin();
 
             switch (*pc++)
             {
                 case op_neg:
- std::cout << " op_neg" << std::endl;
+ line += " op_neg";
                     break;
 
                 case op_not:
- std::cout << " op_not" << std::endl;
+ line += " op_not";
                     break;
 
                 case op_add:
- std::cout << " op_add" << std::endl;
+ line += " op_add";
                     break;
 
                 case op_sub:
- std::cout << " op_sub" << std::endl;
+ line += " op_sub";
                     break;
 
                 case op_mul:
- std::cout << " op_mul" << std::endl;
+ line += " op_mul";
                     break;
 
                 case op_div:
- std::cout << " op_div" << std::endl;
+ line += " op_div";
                     break;
 
                 case op_eq:
- std::cout << " op_eq" << std::endl;
+ line += " op_eq";
                     break;
 
                 case op_neq:
- std::cout << " op_neq" << std::endl;
+ line += " op_neq";
                     break;
 
                 case op_lt:
- std::cout << " op_lt" << std::endl;
+ line += " op_lt";
                     break;
 
                 case op_lte:
- std::cout << " op_lte" << std::endl;
+ line += " op_lte";
                     break;
 
                 case op_gt:
- std::cout << " op_gt" << std::endl;
+ line += " op_gt";
                     break;
 
                 case op_gte:
- std::cout << " op_gte" << std::endl;
+ line += " op_gte";
                     break;
 
                 case op_and:
- std::cout << " op_and" << std::endl;
+ line += " op_and";
                     break;
 
                 case op_or:
- std::cout << " op_or" << std::endl;
+ line += " op_or";
                     break;
 
                 case op_load:
- std::cout << " op_load " << locals[*pc++] << std::endl;
+ line += " op_load ";
+ line += boost::lexical_cast<std::string>(locals[*pc++]);
                     break;
 
                 case op_store:
- std::cout << " op_store " << locals[*pc++] << std::endl;
+ line += " op_store ";
+ line += boost::lexical_cast<std::string>(locals[*pc++]);
                     break;
 
                 case op_int:
- std::cout << " op_int " << *pc++ << std::endl;
+ line += " op_int ";
+ line += boost::lexical_cast<std::string>(*pc++);
                     break;
 
                 case op_true:
- std::cout << " op_true" << std::endl;
+ line += " op_true";
                     break;
 
                 case op_false:
- std::cout << " op_false" << std::endl;
+ line += " op_false";
                     break;
 
                 case op_jump:
- std::cout << " op_jump " << *pc++ << std::endl;
+ {
+ line += " op_jump ";
+ std::size_t pos = (pc - code.begin()) + *pc++;
+ if (pos == code.size())
+ line += "end";
+ else
+ line += boost::lexical_cast<std::string>(pos);
+ jumps.insert(pos);
+ }
                     break;
 
                 case op_jump_if:
- std::cout << " op_jump_if " << *pc++ << std::endl;
+ {
+ line += " op_jump_if ";
+ std::size_t pos = (pc - code.begin()) + *pc++;
+ if (pos == code.size())
+ line += "end";
+ else
+ line += boost::lexical_cast<std::string>(pos);
+ jumps.insert(pos);
+ }
                     break;
 
- case op_adstk:
- std::cout << " op_adstk " << *pc++ << std::endl;
+ case op_stk_adj:
+ line += " op_stk_adj ";
+ line += boost::lexical_cast<std::string>(*pc++);
                     break;
             }
+ lines[address] = line;
         }
 
- if (jumps.find(code.size()) != jumps.end())
- std::cout << code.size() << ':' << std::endl;
+ std::cout << "start:" << std::endl;
+ typedef std::pair<std::size_t, std::string> line_info;
+ BOOST_FOREACH(line_info const& l, lines)
+ {
+ std::size_t pos = l.first;
+ if (jumps.find(pos) != jumps.end())
+ std::cout << pos << ':' << std::endl;
+ std::cout << l.second << std::endl;
+ }
+
+ std::cout << "end:" << std::endl;
     }
 
     bool compiler::operator()(unsigned int x) const
@@ -296,49 +329,45 @@
     {
         if (!(*this)(x.condition))
             return false;
- program.op(op_jump_if, 0); // we shall fill this (0) in later
- std::size_t skip = program.size()-1; // mark its position
+ program.op(op_jump_if, 0); // we shall fill this (0) in later
+ std::size_t skip = program.size()-1; // mark its position
         if (!(*this)(x.then))
             return false;
- program[skip] = program.size(); // now we know where to jump to (after the if branch)
+ program[skip] = program.size()-skip; // now we know where to jump to (after the if branch)
 
- if (x.else_) // We got an alse
+ if (x.else_) // We got an alse
         {
- program[skip] += 2; // adjust for the "else" jump
- program.op(op_jump, 0); // we shall fill this (0) in later
- std::size_t exit = program.size()-1;// mark its position
+ program[skip] += 2; // adjust for the "else" jump
+ program.op(op_jump, 0); // we shall fill this (0) in later
+ std::size_t exit = program.size()-1; // mark its position
             if (!(*this)(*x.else_))
                 return false;
- program[exit] = program.size(); // now we know where to jump to (after the else branch)
- program.add_jump(program[exit]);
+ program[exit] = program.size()-exit; // now we know where to jump to (after the else branch)
         }
 
- program.add_jump(program[skip]);
         return true;
     }
 
     bool compiler::operator()(ast::while_statement const& x) const
     {
- std::size_t loop = program.size(); // mark our position
+ std::size_t loop = program.size(); // mark our position
         if (!(*this)(x.condition))
             return false;
- program.op(op_jump_if, 0); // we shall fill this (0) in later
- std::size_t exit = program.size()-1; // mark its position
+ program.op(op_jump_if, 0); // we shall fill this (0) in later
+ std::size_t exit = program.size()-1; // mark its position
         if (!(*this)(x.body))
             return false;
- program.op(op_jump, loop); // loop back
- program[exit] = program.size(); // now we know where to jump to (to exit the loop)
-
- program.add_jump(loop);
- program.add_jump(program[exit]);
+ program.op(op_jump,
+ int(loop-1) - int(program.size())); // loop back
+ program[exit] = program.size()-exit; // now we know where to jump to (to exit the loop)
         return true;
     }
 
     bool compiler::start(ast::statement_list const& x) const
     {
         program.clear();
- // op_adstk 0 for now. we'll know how many variables we'll have later
- program.op(op_adstk, 0);
+ // op_stk_adj 0 for now. we'll know how many variables we'll have later
+ program.op(op_stk_adj, 0);
 
         if (!(*this)(x))
         {
@@ -348,5 +377,5 @@
         program[1] = program.nvars(); // now store the actual number of variables
         return true;
     }
-}
+}}
 

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc8/compiler.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc8/compiler.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc8/compiler.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -11,13 +11,12 @@
 #include "error_handler.hpp"
 #include <vector>
 #include <map>
-#include <set>
 #include <boost/function.hpp>
 #include <boost/spirit/include/phoenix_core.hpp>
 #include <boost/spirit/include/phoenix_function.hpp>
 #include <boost/spirit/include/phoenix_operator.hpp>
 
-namespace client
+namespace client { namespace code_gen
 {
     ///////////////////////////////////////////////////////////////////////////
     // The Program
@@ -30,7 +29,7 @@
 
         int& operator[](std::size_t i) { return code[i]; }
         int const& operator[](std::size_t i) const { return code[i]; }
- void clear() { code.clear(); variables.clear(); jumps.clear(); }
+ void clear() { code.clear(); variables.clear(); }
         std::size_t size() const { return code.size(); }
         std::vector<int> const& operator()() const { return code; }
 
@@ -41,12 +40,9 @@
         void print_variables(std::vector<int> const& stack) const;
         void print_assembler() const;
 
- void add_jump(std::size_t jump) { jumps.insert(jump); }
-
     private:
 
         std::map<std::string, int> variables;
- std::set<std::size_t> jumps;
         std::vector<int> code;
     };
 
@@ -58,7 +54,7 @@
         typedef bool result_type;
 
         template <typename ErrorHandler>
- compiler(client::program& program, ErrorHandler& error_handler_)
+ compiler(client::code_gen::program& program, ErrorHandler& error_handler_)
           : program(program)
         {
             using namespace boost::phoenix::arg_names;
@@ -85,12 +81,12 @@
 
         bool start(ast::statement_list const& x) const;
 
- client::program& program;
+ client::code_gen::program& program;
 
         boost::function<
             void(int tag, std::string const& what)>
         error_handler;
     };
-}
+}}
 
 #endif
\ No newline at end of file

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc8/expression.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc8/expression.cpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc8/expression.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -11,4 +11,4 @@
 #include "expression_def.hpp"
 
 typedef std::string::const_iterator iterator_type;
-template struct client::expression<iterator_type>;
+template struct client::parser::expression<iterator_type>;

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc8/expression.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc8/expression.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc8/expression.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -26,7 +26,7 @@
 #include "error_handler.hpp"
 #include <vector>
 
-namespace client
+namespace client { namespace parser
 {
     namespace qi = boost::spirit::qi;
     namespace ascii = boost::spirit::ascii;
@@ -61,7 +61,7 @@
             keywords
             ;
     };
-}
+}}
 
 #endif
 

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc8/expression_def.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc8/expression_def.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc8/expression_def.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -9,7 +9,7 @@
 #include "annotation.hpp"
 #include <boost/spirit/include/phoenix_function.hpp>
 
-namespace client
+namespace client { namespace parser
 {
     template <typename Iterator>
     expression<Iterator>::expression(error_handler<Iterator>& error_handler)
@@ -73,6 +73,7 @@
             ;
 
         keywords.add
+ ("var")
             ("true")
             ("false")
             ("if")
@@ -153,6 +154,6 @@
         on_success(primary_expr,
             annotation_function(error_handler.iters)(_val, _1));
     }
-}
+}}
 
 

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc8/main.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc8/main.cpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc8/main.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -48,14 +48,16 @@
     iterator_type iter = source.begin();
     iterator_type end = source.end();
 
- client::vmachine vm; // Our virtual machine
- client::program program; // Our VM program
- client::ast::statement_list ast; // Our AST
+ client::vmachine vm; // Our virtual machine
+ client::code_gen::program program; // Our VM program
+ client::ast::statement_list ast; // Our AST
 
     client::error_handler<iterator_type>
- error_handler(iter, end); // Our error handler
- client::statement<iterator_type> parser(error_handler); // Our parser
- client::compiler compile(program, error_handler); // Our compiler
+ error_handler(iter, end); // Our error handler
+ client::parser::statement<iterator_type>
+ parser(error_handler); // Our parser
+ client::code_gen::compiler
+ compile(program, error_handler); // Our compiler
 
     boost::spirit::ascii::space_type space;
     bool success = phrase_parse(iter, end, parser, space, ast);
@@ -76,7 +78,7 @@
 
             std::cout << "-------------------------\n";
             std::cout << "Results------------------\n\n";
- program.print_variables(vm.get_stack());
+ program.print_variables(vm.stack);
         }
         else
         {

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc8/statement.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc8/statement.cpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc8/statement.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -11,4 +11,4 @@
 #include "statement_def.hpp"
 
 typedef std::string::const_iterator iterator_type;
-template struct client::statement<iterator_type>;
+template struct client::parser::statement<iterator_type>;

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc8/statement.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc8/statement.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc8/statement.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -9,7 +9,7 @@
 
 #include "expression.hpp"
 
-namespace client
+namespace client { namespace parser
 {
     ///////////////////////////////////////////////////////////////////////////////
     // The statement grammar
@@ -30,7 +30,7 @@
         qi::rule<Iterator, ast::while_statement(), ascii::space_type> while_statement;
         qi::rule<Iterator, std::string(), ascii::space_type> identifier;
     };
-}
+}}
 
 #endif
 

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc8/statement_def.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc8/statement_def.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc8/statement_def.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -8,7 +8,7 @@
 #include "error_handler.hpp"
 #include "annotation.hpp"
 
-namespace client
+namespace client { namespace parser
 {
     template <typename Iterator>
     statement<Iterator>::statement(error_handler<Iterator>& error_handler)
@@ -106,6 +106,6 @@
         on_success(assignment,
             annotation_function(error_handler.iters)(_val, _1));
     }
-}
+}}
 
 

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc8/vm.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc8/vm.cpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc8/vm.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -5,6 +5,7 @@
     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 =============================================================================*/
 #include "vm.hpp"
+#include <boost/assert.hpp>
 
 #if defined(_MSC_VER)
 # pragma warning(disable: 4800) // forcing value to bool 'true' or 'false'
@@ -13,14 +14,18 @@
 
 namespace client
 {
- void vmachine::execute(std::vector<int> const& code)
+ int vmachine::execute(
+ std::vector<int> const& code
+ , std::vector<int>::const_iterator pc
+ , std::vector<int>::iterator frame_ptr
+ )
     {
- std::vector<int>::const_iterator pc = code.begin();
- std::vector<int>::iterator locals = stack.begin();
- stack_ptr = stack.begin();
+ std::vector<int>::iterator stack_ptr = frame_ptr;
 
         while (pc != code.end())
         {
+ BOOST_ASSERT(pc != code.end());
+
             switch (*pc++)
             {
                 case op_neg:
@@ -92,12 +97,12 @@
                     break;
 
                 case op_load:
- *stack_ptr++ = locals[*pc++];
+ *stack_ptr++ = frame_ptr[*pc++];
                     break;
 
                 case op_store:
                     --stack_ptr;
- locals[*pc++] = stack_ptr[0];
+ frame_ptr[*pc++] = stack_ptr[0];
                     break;
 
                 case op_int:
@@ -113,20 +118,42 @@
                     break;
 
                 case op_jump:
- pc = code.begin() + *pc;
+ pc += *pc;
                     break;
 
                 case op_jump_if:
                     if (!bool(stack_ptr[-1]))
- pc = code.begin() + *pc;
+ pc += *pc;
                     else
                         ++pc;
                     --stack_ptr;
                     break;
 
- case op_adstk:
+ case op_stk_adj:
                     stack_ptr = stack.begin() + *pc++;
                     break;
+
+ case op_call:
+ {
+ int nargs = *pc++;
+ int jump = *pc++;
+
+ // a function call is a recursive call to execute
+ int r = execute(
+ code
+ , code.begin() + jump
+ , stack_ptr - nargs
+ );
+
+ // cleanup after return from function
+ stack_ptr[-nargs] = r; // get return value
+ stack_ptr -= (nargs - 1); // the stack will now contain
+ // the return value
+ }
+ break;
+
+ case op_return:
+ return stack_ptr[-1];
             }
         }
     }

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/calc8/vm.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/calc8/vm.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/calc8/vm.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -35,15 +35,18 @@
 
         op_load, // load a variable
         op_store, // store a variable
- op_adstk, // adjust the stack for local variables
 
         op_int, // push constant integer into the stack
         op_true, // push constant 0 into the stack
         op_false, // push constant 1 into the stack
 
- op_jump_if, // jump to an absolute position in the code if top stack
+ op_jump_if, // jump to a relative position in the code if top stack
                         // evaluates to false
- op_jump // jump to an absolute position in the code
+ op_jump, // jump to a relative position in the code
+
+ op_stk_adj, // adjust the stack (for args and locals)
+ op_call, // function call
+ op_return // return from function
     };
 
     class vmachine
@@ -52,17 +55,21 @@
 
         vmachine(unsigned stackSize = 4096)
           : stack(stackSize)
- , stack_ptr(stack.begin())
         {
         }
 
- void execute(std::vector<int> const& code);
- std::vector<int> const& get_stack() const { return stack; };
+ int execute(
+ std::vector<int> const& code // the program code
+ , std::vector<int>::const_iterator pc // program counter
+ , std::vector<int>::iterator frame_ptr // start of arguments and locals
+ );
 
- private:
+ int execute(std::vector<int> const& code)
+ {
+ return execute(code, code.begin(), stack.begin());
+ };
 
         std::vector<int> stack;
- std::vector<int>::iterator stack_ptr;
     };
 }
 

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/annotation.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/annotation.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,82 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_MINIC_ANNOTATION_HPP)
+#define BOOST_SPIRIT_MINIC_ANNOTATION_HPP
+
+#include <map>
+#include <boost/variant/apply_visitor.hpp>
+#include "ast.hpp"
+
+namespace client
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // The annotation handler links the AST to a map of iterator positions
+ // for the purpose of subsequent semantic error handling when the
+ // program is being compiled.
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct annotation
+ {
+ template <typename, typename>
+ struct result { typedef void type; };
+
+ std::vector<Iterator>& iters;
+ annotation(std::vector<Iterator>& iters)
+ : iters(iters) {}
+
+ struct set_id
+ {
+ typedef void result_type;
+
+ int id;
+ set_id(int id) : id(id) {}
+
+ // This will catch all nodes inheriting from ast::tagged
+ void operator()(ast::tagged& x) const
+ {
+ x.id = id;
+ }
+
+ // This will catch all nodes except those inheriting from ast::tagged
+ void operator()(...) const
+ {
+ // (no-op) no need for tags
+ }
+ };
+
+ void operator()(ast::operand& ast, Iterator pos) const
+ {
+ int id = iters.size();
+ iters.push_back(pos);
+ boost::apply_visitor(set_id(id), ast);
+ }
+
+ void operator()(ast::assignment& ast, Iterator pos) const
+ {
+ int id = iters.size();
+ iters.push_back(pos);
+ ast.lhs.id = id;
+ }
+
+ void operator()(ast::return_statement& ast, Iterator pos) const
+ {
+ int id = iters.size();
+ iters.push_back(pos);
+ ast.id = id;
+ }
+
+ void operator()(ast::identifier& ast, Iterator pos) const
+ {
+ int id = iters.size();
+ iters.push_back(pos);
+ ast.id = id;
+ }
+ };
+}
+
+#endif
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/ast.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/ast.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,223 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_MINIC_AST_HPP)
+#define BOOST_SPIRIT_MINIC_AST_HPP
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/variant/recursive_variant.hpp>
+#include <boost/fusion/include/adapt_struct.hpp>
+#include <boost/fusion/include/io.hpp>
+#include <boost/optional.hpp>
+#include <list>
+
+namespace client { namespace ast
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // The AST
+ ///////////////////////////////////////////////////////////////////////////
+ struct tagged
+ {
+ int id; // Used to annotate the AST with the iterator position.
+ // This id is used as a key to a map<int, Iterator>
+ // (not really part of the AST.)
+ };
+
+ struct nil {};
+ struct unary;
+ struct function_call;
+ struct expression;
+
+ struct identifier : tagged
+ {
+ identifier(std::string const& name = "") : name(name) {}
+ std::string name;
+ };
+
+ typedef boost::variant<
+ nil
+ , bool
+ , unsigned int
+ , identifier
+ , boost::recursive_wrapper<unary>
+ , boost::recursive_wrapper<function_call>
+ , boost::recursive_wrapper<expression>
+ >
+ operand;
+
+ enum optoken
+ {
+ op_plus,
+ op_minus,
+ op_times,
+ op_divide,
+ op_positive,
+ op_negative,
+ op_not,
+ op_equal,
+ op_not_equal,
+ op_less,
+ op_less_equal,
+ op_greater,
+ op_greater_equal,
+ op_and,
+ op_or
+ };
+
+ struct unary
+ {
+ optoken operator_;
+ operand operand_;
+ };
+
+ struct operation
+ {
+ optoken operator_;
+ operand operand_;
+ };
+
+ struct function_call
+ {
+ identifier function_name;
+ std::list<expression> args;
+ };
+
+ struct expression
+ {
+ operand first;
+ std::list<operation> rest;
+ };
+
+ struct assignment
+ {
+ identifier lhs;
+ expression rhs;
+ };
+
+ struct variable_declaration
+ {
+ assignment assign;
+ };
+
+ struct if_statement;
+ struct while_statement;
+ struct statement_list;
+ struct return_statement;
+
+ typedef boost::variant<
+ variable_declaration
+ , assignment
+ , boost::recursive_wrapper<if_statement>
+ , boost::recursive_wrapper<while_statement>
+ , boost::recursive_wrapper<return_statement>
+ , boost::recursive_wrapper<statement_list>
+ >
+ statement;
+
+ struct statement_list : std::list<statement> {};
+
+ struct if_statement
+ {
+ expression condition;
+ statement then;
+ boost::optional<statement> else_;
+ };
+
+ struct while_statement
+ {
+ expression condition;
+ statement body;
+ };
+
+ struct return_statement : tagged
+ {
+ boost::optional<expression> expr;
+ };
+
+ struct function
+ {
+ std::string return_type;
+ identifier function_name;
+ std::list<identifier> args;
+ statement_list body;
+ };
+
+ typedef std::list<function> function_list;
+
+ // print functions for debugging
+ inline std::ostream& operator<<(std::ostream& out, nil)
+ {
+ out << "nil"; return out;
+ }
+
+ inline std::ostream& operator<<(std::ostream& out, identifier const& id)
+ {
+ out << id.name; return out;
+ }
+}}
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::unary,
+ (client::ast::optoken, operator_)
+ (client::ast::operand, operand_)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::operation,
+ (client::ast::optoken, operator_)
+ (client::ast::operand, operand_)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::function_call,
+ (client::ast::identifier, function_name)
+ (std::list<client::ast::expression>, args)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::expression,
+ (client::ast::operand, first)
+ (std::list<client::ast::operation>, rest)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::variable_declaration,
+ (client::ast::assignment, assign)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::assignment,
+ (client::ast::identifier, lhs)
+ (client::ast::expression, rhs)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::if_statement,
+ (client::ast::expression, condition)
+ (client::ast::statement, then)
+ (boost::optional<client::ast::statement>, else_)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::while_statement,
+ (client::ast::expression, condition)
+ (client::ast::statement, body)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::return_statement,
+ (boost::optional<client::ast::expression>, expr)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::function,
+ (std::string, return_type)
+ (client::ast::identifier, function_name)
+ (std::list<client::ast::identifier>, args)
+ (client::ast::statement_list, body)
+)
+
+#endif

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/compiler.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/compiler.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,546 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#include "compiler.hpp"
+#include "vm.hpp"
+#include <boost/foreach.hpp>
+#include <boost/variant/apply_visitor.hpp>
+#include <boost/assert.hpp>
+#include <boost/lexical_cast.hpp>
+#include <set>
+
+namespace client { namespace code_gen
+{
+ void function::op(int a)
+ {
+ code.push_back(a);
+ size_ += 1;
+ }
+
+ void function::op(int a, int b)
+ {
+ code.push_back(a);
+ code.push_back(b);
+ size_ += 2;
+ }
+
+ void function::op(int a, int b, int c)
+ {
+ code.push_back(a);
+ code.push_back(b);
+ code.push_back(c);
+ size_ += 3;
+ }
+
+ int const* function::find_var(std::string const& name) const
+ {
+ std::map<std::string, int>::const_iterator i = variables.find(name);
+ if (i == variables.end())
+ return 0;
+ return &i->second;
+ }
+
+ void function::add_var(std::string const& name)
+ {
+ variables[name] = variables.size();
+ }
+
+ void function::link_to(std::string const& name, std::size_t address)
+ {
+ function_calls[address] = name;
+ }
+
+ void function::print_variables(std::vector<int> const& stack) const
+ {
+ typedef std::pair<std::string, int> pair;
+ BOOST_FOREACH(pair const& p, variables)
+ {
+ std::cout << " " << p.first << ": " << stack[p.second] << std::endl;
+ }
+ }
+
+ void function::print_assembler() const
+ {
+ std::vector<int>::const_iterator pc = code.begin() + address;
+
+ std::vector<std::string> locals(variables.size());
+ typedef std::pair<std::string, int> pair;
+ BOOST_FOREACH(pair const& p, variables)
+ {
+ locals[p.second] = p.first;
+ std::cout << " local "
+ << p.first << ", @" << p.second << std::endl;
+ }
+
+ std::map<std::size_t, std::string> lines;
+ std::set<std::size_t> jumps;
+
+ while (pc != (code.begin() + address + size_))
+ {
+ std::string line;
+ std::size_t address = pc - code.begin();
+
+ switch (*pc++)
+ {
+ case op_neg:
+ line += " op_neg";
+ break;
+
+ case op_not:
+ line += " op_not";
+ break;
+
+ case op_add:
+ line += " op_add";
+ break;
+
+ case op_sub:
+ line += " op_sub";
+ break;
+
+ case op_mul:
+ line += " op_mul";
+ break;
+
+ case op_div:
+ line += " op_div";
+ break;
+
+ case op_eq:
+ line += " op_eq";
+ break;
+
+ case op_neq:
+ line += " op_neq";
+ break;
+
+ case op_lt:
+ line += " op_lt";
+ break;
+
+ case op_lte:
+ line += " op_lte";
+ break;
+
+ case op_gt:
+ line += " op_gt";
+ break;
+
+ case op_gte:
+ line += " op_gte";
+ break;
+
+ case op_and:
+ line += " op_and";
+ break;
+
+ case op_or:
+ line += " op_or";
+ break;
+
+ case op_load:
+ line += " op_load ";
+ line += boost::lexical_cast<std::string>(locals[*pc++]);
+ break;
+
+ case op_store:
+ line += " op_store ";
+ line += boost::lexical_cast<std::string>(locals[*pc++]);
+ break;
+
+ case op_int:
+ line += " op_int ";
+ line += boost::lexical_cast<std::string>(*pc++);
+ break;
+
+ case op_true:
+ line += " op_true";
+ break;
+
+ case op_false:
+ line += " op_false";
+ break;
+
+ case op_jump:
+ {
+ line += " op_jump ";
+ std::size_t pos = (pc - code.begin()) + *pc++;
+ if (pos == code.size())
+ line += "end";
+ else
+ line += boost::lexical_cast<std::string>(pos);
+ jumps.insert(pos);
+ }
+ break;
+
+ case op_jump_if:
+ {
+ line += " op_jump_if ";
+ std::size_t pos = (pc - code.begin()) + *pc++;
+ if (pos == code.size())
+ line += "end";
+ else
+ line += boost::lexical_cast<std::string>(pos);
+ jumps.insert(pos);
+ }
+ break;
+
+ case op_call:
+ {
+ line += " op_call ";
+ int nargs = *pc++;
+ std::size_t jump = *pc++;
+ line += boost::lexical_cast<std::string>(nargs) + ", ";
+ BOOST_ASSERT(function_calls.find(jump) != function_calls.end());
+ line += function_calls.find(jump)->second;
+ }
+ break;
+
+ case op_stk_adj:
+ line += " op_stk_adj ";
+ line += boost::lexical_cast<std::string>(*pc++);
+ break;
+
+
+ case op_return:
+ line += " op_return";
+ break;
+ }
+ lines[address] = line;
+ }
+
+ std::cout << "start:" << std::endl;
+ typedef std::pair<std::size_t, std::string> line_info;
+ BOOST_FOREACH(line_info const& l, lines)
+ {
+ std::size_t pos = l.first;
+ if (jumps.find(pos) != jumps.end())
+ std::cout << pos << ':' << std::endl;
+ std::cout << l.second << std::endl;
+ }
+
+ std::cout << "end:" << std::endl << std::endl;
+ }
+
+ bool compiler::operator()(unsigned int x)
+ {
+ BOOST_ASSERT(current != 0);
+ current->op(op_int, x);
+ return true;
+ }
+
+ bool compiler::operator()(bool x)
+ {
+ BOOST_ASSERT(current != 0);
+ current->op(x ? op_true : op_false);
+ return true;
+ }
+
+ bool compiler::operator()(ast::identifier const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ int const* p = current->find_var(x.name);
+ if (p == 0)
+ {
+ std::cout << x.id << std::endl;
+ error_handler(x.id, "Undeclared variable: " + x.name);
+ return false;
+ }
+ current->op(op_load, *p);
+ return true;
+ }
+
+ bool compiler::operator()(ast::operation const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ if (!boost::apply_visitor(*this, x.operand_))
+ return false;
+ switch (x.operator_)
+ {
+ case ast::op_plus: current->op(op_add); break;
+ case ast::op_minus: current->op(op_sub); break;
+ case ast::op_times: current->op(op_mul); break;
+ case ast::op_divide: current->op(op_div); break;
+
+ case ast::op_equal: current->op(op_eq); break;
+ case ast::op_not_equal: current->op(op_neq); break;
+ case ast::op_less: current->op(op_lt); break;
+ case ast::op_less_equal: current->op(op_lte); break;
+ case ast::op_greater: current->op(op_gt); break;
+ case ast::op_greater_equal: current->op(op_gte); break;
+
+ case ast::op_and: current->op(op_and); break;
+ case ast::op_or: current->op(op_or); break;
+ default: BOOST_ASSERT(0); return false;
+ }
+ return true;
+ }
+
+ bool compiler::operator()(ast::unary const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ if (!boost::apply_visitor(*this, x.operand_))
+ return false;
+ switch (x.operator_)
+ {
+ case ast::op_negative: current->op(op_neg); break;
+ case ast::op_not: current->op(op_not); break;
+ case ast::op_positive: break;
+ default: BOOST_ASSERT(0); return false;
+ }
+ return true;
+ }
+
+ bool compiler::operator()(ast::function_call const& x)
+ {
+ BOOST_ASSERT(current != 0);
+
+ if (functions.find(x.function_name.name) == functions.end())
+ {
+ std::cout << x.function_name.id << std::endl;
+ error_handler(x.function_name.id, "Function not found: " + x.function_name.name);
+ return false;
+ }
+
+ boost::shared_ptr<code_gen::function> p = functions[x.function_name.name];
+
+ if (p->nargs() != x.args.size())
+ {
+ std::cout << x.function_name.id << std::endl;
+ error_handler(x.function_name.id, "Wrong number of arguments: " + x.function_name.name);
+ return false;
+ }
+
+ BOOST_FOREACH(ast::expression const& expr, x.args)
+ {
+ if (!(*this)(expr))
+ return false;
+ }
+
+ current->op(
+ op_call,
+ p->nargs(),
+ p->get_address());
+ current->link_to(x.function_name.name, p->get_address());
+
+ return true;
+ }
+
+ bool compiler::operator()(ast::expression const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ if (!boost::apply_visitor(*this, x.first))
+ return false;
+ BOOST_FOREACH(ast::operation const& oper, x.rest)
+ {
+ if (!(*this)(oper))
+ return false;
+ }
+ return true;
+ }
+
+ bool compiler::operator()(ast::assignment const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ if (!(*this)(x.rhs))
+ return false;
+ int const* p = current->find_var(x.lhs.name);
+ if (p == 0)
+ {
+ std::cout << x.lhs.id << std::endl;
+ error_handler(x.lhs.id, "Undeclared variable: " + x.lhs.name);
+ return false;
+ }
+ current->op(op_store, *p);
+ return true;
+ }
+
+ bool compiler::operator()(ast::variable_declaration const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ int const* p = current->find_var(x.assign.lhs.name);
+ if (p != 0)
+ {
+ std::cout << x.assign.lhs.id << std::endl;
+ error_handler(x.assign.lhs.id, "Duplicate variable: " + x.assign.lhs.name);
+ return false;
+ }
+ bool r = (*this)(x.assign.rhs);
+ if (r) // don't add the variable if the RHS fails
+ {
+ current->add_var(x.assign.lhs.name);
+ current->op(op_store, *current->find_var(x.assign.lhs.name));
+ }
+ return r;
+ }
+
+ bool compiler::operator()(ast::statement const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ return boost::apply_visitor(*this, x);
+ }
+
+ bool compiler::operator()(ast::statement_list const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ BOOST_FOREACH(ast::statement const& s, x)
+ {
+ if (!(*this)(s))
+ return false;
+ }
+ return true;
+ }
+
+ bool compiler::operator()(ast::if_statement const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ if (!(*this)(x.condition))
+ return false;
+ current->op(op_jump_if, 0); // we shall fill this (0) in later
+ std::size_t skip = current->size()-1; // mark its position
+ if (!(*this)(x.then))
+ return false;
+ (*current)[skip] = current->size()-skip; // now we know where to jump to (after the if branch)
+
+ if (x.else_) // We got an alse
+ {
+ (*current)[skip] += 2; // adjust for the "else" jump
+ current->op(op_jump, 0); // we shall fill this (0) in later
+ std::size_t exit = current->size()-1; // mark its position
+ if (!(*this)(*x.else_))
+ return false;
+ (*current)[exit] = current->size()-exit;// now we know where to jump to (after the else branch)
+ }
+
+ return true;
+ }
+
+ bool compiler::operator()(ast::while_statement const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ std::size_t loop = current->size(); // mark our position
+ if (!(*this)(x.condition))
+ return false;
+ current->op(op_jump_if, 0); // we shall fill this (0) in later
+ std::size_t exit = current->size()-1; // mark its position
+ if (!(*this)(x.body))
+ return false;
+ current->op(op_jump,
+ int(loop-1) - int(current->size())); // loop back
+ (*current)[exit] = current->size()-exit; // now we know where to jump to (to exit the loop)
+ return true;
+ }
+
+ bool compiler::operator()(ast::return_statement const& x)
+ {
+ if (void_return)
+ {
+ if (x.expr)
+ {
+ std::cout << x.id << std::endl;
+ error_handler(x.id, "'void' function returning a value: ");
+ return false;
+ }
+ }
+ else
+ {
+ if (!x.expr)
+ {
+ std::cout << x.id << std::endl;
+ error_handler(x.id, current_function_name + " function must return a value: ");
+ return false;
+ }
+ }
+
+ if (x.expr)
+ {
+ if (!(*this)(*x.expr))
+ return false;
+ }
+ current->op(op_return);
+ return true;
+ }
+
+ bool compiler::operator()(ast::function const& x)
+ {
+ void_return = x.return_type == "void";
+ if (functions.find(x.function_name.name) != functions.end())
+ {
+ std::cout << x.function_name.id << std::endl;
+ error_handler(x.function_name.id, "Duplicate function: " + x.function_name.name);
+ return false;
+ }
+ boost::shared_ptr<code_gen::function>& p = functions[x.function_name.name];
+ p.reset(new code_gen::function(code, x.args.size()));
+ current = p.get();
+ current_function_name = x.function_name.name;
+
+ // op_stk_adj 0 for now. we'll know how many variables
+ // we'll have later and add them
+ current->op(op_stk_adj, 0);
+ BOOST_FOREACH(ast::identifier const& arg, x.args)
+ {
+ current->add_var(arg.name);
+ }
+
+ if (!(*this)(x.body))
+ return false;
+ (*current)[1] = current->nvars(); // now store the actual number of variables
+ // this includes the arguments
+ return true;
+ }
+
+ bool compiler::operator()(ast::function_list const& x)
+ {
+ // Jump to the main function
+ code.push_back(op_jump);
+ code.push_back(0); // we will fill this in later when we finish compiling
+ // and we know where the main function is
+
+ BOOST_FOREACH(ast::function const& f, x)
+ {
+ if (!(*this)(f))
+ {
+ code.clear();
+ return false;
+ }
+ }
+ // find the main function
+ boost::shared_ptr<code_gen::function> p =
+ find_function("main");
+
+ if (!p) // main function not found
+ {
+ std::cerr << "Error: main function not defined" << std::endl;
+ return false;
+ }
+ code[1] = p->get_address()-1; // jump to this (main function) address
+
+ return true;
+ }
+
+ void compiler::print_assembler() const
+ {
+ typedef std::pair<std::string, boost::shared_ptr<code_gen::function> > pair;
+ BOOST_FOREACH(pair const& p, functions)
+ {
+ std::cout << ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" << std::endl;
+ std::cout << p.second->get_address() << ": function " << p.first << std::endl;
+ p.second->print_assembler();
+ }
+ }
+
+ boost::shared_ptr<code_gen::function>
+ compiler::find_function(std::string const& name) const
+ {
+ function_table::const_iterator i = functions.find(name);
+ if (i == functions.end())
+ return boost::shared_ptr<code_gen::function>();
+ else
+ return i->second;
+ }
+}}
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/compiler.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/compiler.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,119 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_MINIC_COMPILER_HPP)
+#define BOOST_SPIRIT_MINIC_COMPILER_HPP
+
+#include "ast.hpp"
+#include "error_handler.hpp"
+#include <vector>
+#include <map>
+#include <boost/function.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_function.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+namespace client { namespace code_gen
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // The Function
+ ///////////////////////////////////////////////////////////////////////////
+ struct function
+ {
+ function(std::vector<int>& code, int nargs)
+ : code(code), address(code.size()), size_(0), nargs_(nargs) {}
+
+ void op(int a);
+ void op(int a, int b);
+ void op(int a, int b, int c);
+
+ int& operator[](std::size_t i) { return code[address+i]; }
+ int const& operator[](std::size_t i) const { return code[address+i]; }
+ std::size_t size() const { return size_; }
+ std::size_t get_address() const { return address; }
+
+ int nargs() const { return nargs_; }
+ int nvars() const { return variables.size(); }
+ int const* find_var(std::string const& name) const;
+ void add_var(std::string const& name);
+ void link_to(std::string const& name, std::size_t address);
+
+ void print_variables(std::vector<int> const& stack) const;
+ void print_assembler() const;
+
+ private:
+
+ std::map<std::string, int> variables;
+ std::map<std::size_t, std::string> function_calls;
+ std::vector<int>& code;
+ std::size_t address;
+ std::size_t size_;
+ std::size_t nargs_;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // The Compiler
+ ///////////////////////////////////////////////////////////////////////////
+ struct compiler
+ {
+ typedef bool result_type;
+
+ template <typename ErrorHandler>
+ compiler(ErrorHandler& error_handler_)
+ : current(0)
+ {
+ using namespace boost::phoenix::arg_names;
+ using boost::phoenix::cref;
+ using boost::phoenix::function;
+
+ error_handler = function<ErrorHandler>(error_handler_)(
+ "Error! ", _2, cref(error_handler_.iters)[_1]);
+ }
+
+ bool operator()(ast::nil) { BOOST_ASSERT(0); return false; }
+ bool operator()(unsigned int x);
+ bool operator()(bool x);
+ bool operator()(ast::identifier const& x);
+ bool operator()(ast::operation const& x);
+ bool operator()(ast::unary const& x);
+ bool operator()(ast::function_call const& x);
+ bool operator()(ast::expression const& x);
+ bool operator()(ast::assignment const& x);
+ bool operator()(ast::variable_declaration const& x);
+ bool operator()(ast::statement_list const& x);
+ bool operator()(ast::statement const& x);
+ bool operator()(ast::if_statement const& x);
+ bool operator()(ast::while_statement const& x);
+ bool operator()(ast::return_statement const& x);
+ bool operator()(ast::function const& x);
+ bool operator()(ast::function_list const& x);
+
+ void print_assembler() const;
+
+ boost::shared_ptr<code_gen::function>
+ find_function(std::string const& name) const;
+
+ std::vector<int>& get_code() { return code; }
+ std::vector<int> const& get_code() const { return code; }
+
+ private:
+
+ typedef std::map<std::string, boost::shared_ptr<code_gen::function> > function_table;
+
+ std::vector<int> code;
+ code_gen::function* current;
+ std::string current_function_name;
+ function_table functions;
+ bool void_return;
+
+ boost::function<
+ void(int tag, std::string const& what)>
+ error_handler;
+ };
+}}
+
+#endif
\ No newline at end of file

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/error_handler.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/error_handler.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,93 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_MINIC_ERROR_HANDLER_HPP)
+#define BOOST_SPIRIT_MINIC_ERROR_HANDLER_HPP
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+namespace client
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // The error handler
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct error_handler
+ {
+ template <typename, typename, typename>
+ struct result { typedef void type; };
+
+ error_handler(Iterator first, Iterator last)
+ : first(first), last(last) {}
+
+ template <typename Message, typename What>
+ void operator()(
+ Message const& message,
+ What const& what,
+ Iterator err_pos) const
+ {
+ int line;
+ Iterator line_start = get_pos(err_pos, line);
+ if (err_pos != last)
+ {
+ std::cout << message << what << " line " << line << ':' << std::endl;
+ std::cout << get_line(line_start) << std::endl;
+ for (; line_start != err_pos; ++line_start)
+ std::cout << ' ';
+ std::cout << '^' << std::endl;
+ }
+ else
+ {
+ std::cout << "Unexpected end of file. ";
+ std::cout << message << what << " line " << line << std::endl;
+ }
+ }
+
+ Iterator get_pos(Iterator err_pos, int& line) const
+ {
+ line = 1;
+ Iterator i = first;
+ Iterator line_start = first;
+ while (i != err_pos)
+ {
+ bool eol = false;
+ if (i != err_pos && *i == '\r') // CR
+ {
+ eol = true;
+ line_start = ++i;
+ }
+ if (i != err_pos && *i == '\n') // LF
+ {
+ eol = true;
+ line_start = ++i;
+ }
+ if (eol)
+ ++line;
+ else
+ ++i;
+ }
+ return line_start;
+ }
+
+ std::string get_line(Iterator err_pos) const
+ {
+ Iterator i = err_pos;
+ // position i to the next EOL
+ while (i != last && (*i != '\r' && *i != '\n'))
+ ++i;
+ return std::string(err_pos, i);
+ }
+
+ Iterator first;
+ Iterator last;
+ std::vector<Iterator> iters;
+ };
+}
+
+#endif
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,14 @@
+/*=============================================================================
+ 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)
+=============================================================================*/
+#if defined(_MSC_VER)
+# pragma warning(disable: 4345)
+#endif
+
+#include "expression_def.hpp"
+
+typedef std::string::const_iterator iterator_type;
+template struct client::parser::expression<iterator_type>;

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,77 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_MINIC_EXPRESSION_HPP)
+#define BOOST_SPIRIT_MINIC_EXPRESSION_HPP
+
+///////////////////////////////////////////////////////////////////////////////
+// Spirit v2.5 allows you to suppress automatic generation
+// of predefined terminals to speed up complation. With
+// BOOST_SPIRIT_NO_PREDEFINED_TERMINALS defined, you are
+// responsible in creating instances of the terminals that
+// you need (e.g. see qi::uint_type uint_ below).
+#define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
+///////////////////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////
+// Uncomment this if you want to enable debugging
+// #define BOOST_SPIRIT_QI_DEBUG
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/spirit/include/qi.hpp>
+#include "ast.hpp"
+#include "error_handler.hpp"
+#include "skipper.hpp"
+#include <vector>
+
+namespace client { namespace parser
+{
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // The expression grammar
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct expression : qi::grammar<Iterator, ast::expression(), skipper<Iterator> >
+ {
+ expression(error_handler<Iterator>& error_handler);
+
+ qi::rule<Iterator, ast::expression(), skipper<Iterator> >
+ expr, equality_expr, relational_expr,
+ logical_expr, additive_expr, multiplicative_expr
+ ;
+
+ qi::rule<Iterator, ast::operand(), skipper<Iterator> >
+ unary_expr, primary_expr
+ ;
+
+ qi::rule<Iterator, ast::function_call(), skipper<Iterator> >
+ function_call
+ ;
+
+ qi::rule<Iterator, std::list<ast::expression>(), skipper<Iterator> >
+ argument_list
+ ;
+
+ qi::rule<Iterator, std::string(), skipper<Iterator> >
+ identifier
+ ;
+
+ qi::symbols<char, ast::optoken>
+ equality_op, relational_op, logical_op,
+ additive_op, multiplicative_op, unary_op
+ ;
+
+ qi::symbols<char>
+ keywords
+ ;
+ };
+}}
+
+#endif
+
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression_def.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression_def.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,175 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#include "expression.hpp"
+#include "error_handler.hpp"
+#include "annotation.hpp"
+#include <boost/spirit/include/phoenix_function.hpp>
+
+namespace client { namespace parser
+{
+ template <typename Iterator>
+ expression<Iterator>::expression(error_handler<Iterator>& error_handler)
+ : expression::base_type(expr)
+ {
+ qi::_1_type _1;
+ qi::_2_type _2;
+ qi::_3_type _3;
+ qi::_4_type _4;
+
+ qi::char_type char_;
+ qi::uint_type uint_;
+ qi::_val_type _val;
+ qi::raw_type raw;
+ qi::lexeme_type lexeme;
+ qi::alpha_type alpha;
+ qi::alnum_type alnum;
+ qi::bool_type bool_;
+
+ using qi::on_error;
+ using qi::on_success;
+ using qi::fail;
+ using boost::phoenix::function;
+
+ typedef function<client::error_handler<Iterator> > error_handler_function;
+ typedef function<client::annotation<Iterator> > annotation_function;
+
+ ///////////////////////////////////////////////////////////////////////
+ // Tokens
+ equality_op.add
+ ("==", ast::op_equal)
+ ("!=", ast::op_not_equal)
+ ;
+
+ relational_op.add
+ ("<", ast::op_less)
+ ("<=", ast::op_less_equal)
+ (">", ast::op_greater)
+ (">=", ast::op_greater_equal)
+ ;
+
+ logical_op.add
+ ("&&", ast::op_and)
+ ("||", ast::op_or)
+ ;
+
+ additive_op.add
+ ("+", ast::op_plus)
+ ("-", ast::op_minus)
+ ;
+
+ multiplicative_op.add
+ ("*", ast::op_times)
+ ("/", ast::op_divide)
+ ;
+
+ unary_op.add
+ ("+", ast::op_positive)
+ ("-", ast::op_negative)
+ ("!", ast::op_not)
+ ;
+
+ keywords.add
+ ("true")
+ ("false")
+ ("if")
+ ("else")
+ ("while")
+ ("int")
+ ("void")
+ ("return")
+ ;
+
+ ///////////////////////////////////////////////////////////////////////
+ // Main expression grammar
+ expr =
+ equality_expr.alias()
+ ;
+
+ equality_expr =
+ relational_expr
+ >> *(equality_op > relational_expr)
+ ;
+
+ relational_expr =
+ logical_expr
+ >> *(relational_op > logical_expr)
+ ;
+
+ logical_expr =
+ additive_expr
+ >> *(logical_op > additive_expr)
+ ;
+
+ additive_expr =
+ multiplicative_expr
+ >> *(additive_op > multiplicative_expr)
+ ;
+
+ multiplicative_expr =
+ unary_expr
+ >> *(multiplicative_op > unary_expr)
+ ;
+
+ unary_expr =
+ primary_expr
+ | (unary_op > primary_expr)
+ ;
+
+ primary_expr =
+ uint_
+ | function_call
+ | identifier
+ | bool_
+ | '(' > expr > ')'
+ ;
+
+ function_call =
+ (identifier >> '(')
+ > argument_list
+ > ')'
+ ;
+
+ //~ argument_list =
+ //~ (expr > *(',' > expr)) // $$$$
+ //~ ;
+
+ argument_list = -(expr % ',');
+
+
+ identifier =
+ !keywords
+ >> raw[lexeme[(alpha | '_') >> *(alnum | '_')]]
+ ;
+
+ ///////////////////////////////////////////////////////////////////////
+ // Debugging and error handling and reporting support.
+ BOOST_SPIRIT_DEBUG_NODES(
+ (expr)
+ (equality_expr)
+ (relational_expr)
+ (logical_expr)
+ (additive_expr)
+ (multiplicative_expr)
+ (unary_expr)
+ (primary_expr)
+ (identifier)
+ );
+
+ ///////////////////////////////////////////////////////////////////////
+ // Error handling: on error in expr, call error_handler.
+ on_error<fail>(expr,
+ error_handler_function(error_handler)(
+ "Error! Expecting ", _4, _3));
+
+ ///////////////////////////////////////////////////////////////////////
+ // Annotation: on success in primary_expr, call annotation.
+ on_success(primary_expr,
+ annotation_function(error_handler.iters)(_val, _1));
+ }
+}}
+
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/function.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/function.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,14 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if defined(_MSC_VER)
+# pragma warning(disable: 4345)
+#endif
+
+#include "function_def.hpp"
+
+typedef std::string::const_iterator iterator_type;
+template struct client::parser::function<iterator_type>;

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/function.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/function.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,32 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_MINIC_FUNCTION_HPP)
+#define BOOST_SPIRIT_MINIC_FUNCTION_HPP
+
+#include "statement.hpp"
+
+namespace client { namespace parser
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // The function grammar
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct function : qi::grammar<Iterator, ast::function(), skipper<Iterator> >
+ {
+ function(error_handler<Iterator>& error_handler);
+
+ statement<Iterator> body;
+ qi::rule<Iterator, std::string(), skipper<Iterator> > name;
+ qi::rule<Iterator, ast::identifier(), skipper<Iterator> > identifier;
+ qi::rule<Iterator, std::list<ast::identifier>(), skipper<Iterator> > argument_list;
+ qi::rule<Iterator, ast::function(), skipper<Iterator> > start;
+ };
+}}
+
+#endif
+
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/function_def.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/function_def.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,74 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#include "function.hpp"
+#include "error_handler.hpp"
+#include "annotation.hpp"
+
+namespace client { namespace parser
+{
+ template <typename Iterator>
+ function<Iterator>::function(error_handler<Iterator>& error_handler)
+ : function::base_type(start), body(error_handler)
+ {
+ qi::_1_type _1;
+ qi::_2_type _2;
+ qi::_3_type _3;
+ qi::_4_type _4;
+
+ qi::_val_type _val;
+ qi::raw_type raw;
+ qi::lexeme_type lexeme;
+ qi::alpha_type alpha;
+ qi::alnum_type alnum;
+ qi::string_type string;
+
+ using qi::on_error;
+ using qi::on_success;
+ using qi::fail;
+ using boost::phoenix::function;
+
+ typedef function<client::error_handler<Iterator> > error_handler_function;
+ typedef function<client::annotation<Iterator> > annotation_function;
+
+ name =
+ !body.expr.keywords
+ >> raw[lexeme[(alpha | '_') >> *(alnum | '_')]]
+ ;
+
+ identifier = name;
+ argument_list = -(identifier > *(',' > identifier));
+
+ start =
+ lexeme[(string("void") | string("int"))
+ >> !(alnum | '_')] // make sure we have whole words
+ > identifier
+ > '('
+ > argument_list
+ > ')'
+ > '{'
+ > body
+ > '}'
+ ;
+
+ // Debugging and error handling and reporting support.
+ BOOST_SPIRIT_DEBUG_NODES(
+ (identifier)
+ (start)
+ );
+
+ // Error handling: on error in start, call error_handler.
+ on_error<fail>(start,
+ error_handler_function(error_handler)(
+ "Error! Expecting ", _4, _3));
+
+ // Annotation: on success in start, call annotation.
+ on_success(identifier,
+ annotation_function(error_handler.iters)(_val, _1));
+ }
+}}
+
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/main.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/main.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,122 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+///////////////////////////////////////////////////////////////////////////////
+//
+// Now we'll introduce boolean expressions and control structures.
+// Is it obvious now what we are up to? ;-)
+//
+// [ JDG April 9, 2007 ] spirit2
+// [ JDG February 18, 2011 ] Pure attributes. No semantic actions.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "function.hpp"
+#include "skipper.hpp"
+#include "vm.hpp"
+#include "compiler.hpp"
+#include <boost/lexical_cast.hpp>
+#include <fstream>
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int main(int argc, char **argv)
+{
+ char const* filename;
+ if (argc > 1)
+ {
+ filename = argv[1];
+ }
+ else
+ {
+ std::cerr << "Error: No input file provided." << std::endl;
+ return 1;
+ }
+
+ std::ifstream in(filename, std::ios_base::in);
+
+ if (!in)
+ {
+ std::cerr << "Error: Could not open input file: "
+ << filename << std::endl;
+ return 1;
+ }
+
+ std::string source_code; // We will read the contents here.
+ in.unsetf(std::ios::skipws); // No white space skipping!
+ std::copy(
+ std::istream_iterator<char>(in),
+ std::istream_iterator<char>(),
+ std::back_inserter(source_code));
+
+ typedef std::string::const_iterator iterator_type;
+ iterator_type iter = source_code.begin();
+ iterator_type end = source_code.end();
+
+ client::vmachine vm; // Our virtual machine
+ client::ast::function_list ast; // Our AST
+
+ client::error_handler<iterator_type>
+ error_handler(iter, end); // Our error handler
+ client::parser::function<iterator_type>
+ function(error_handler); // Our parser
+ client::parser::skipper<iterator_type>
+ skipper; // Our skipper
+ client::code_gen::compiler
+ compiler(error_handler); // Our compiler
+
+
+ bool success = phrase_parse(iter, end, +function, skipper, ast);
+
+ std::cout << "-------------------------\n";
+
+ if (success && iter == end)
+ {
+ if (compiler(ast))
+ {
+ boost::shared_ptr<client::code_gen::function>
+ p = compiler.find_function("main");
+ if (!p)
+ return 1;
+
+ int nargs = argc-2;
+ if (p->nargs() != nargs)
+ {
+ std::cerr << "Error: main function requires " << p->nargs() << " arguments." << std::endl;
+ std::cerr << nargs << "supplied." << std::endl;
+ return 1;
+ }
+
+ std::cout << "Success\n";
+ std::cout << "-------------------------\n";
+ std::cout << "Assembler----------------\n\n";
+ compiler.print_assembler();
+
+ // Push the arguments into our stack
+ for (int i = 0; i < nargs; ++i)
+ vm.get_stack()[i] = boost::lexical_cast<int>(argv[i+2]);
+
+ // Call the interpreter
+ int r = vm.execute(compiler.get_code());
+
+ std::cout << "-------------------------\n";
+ std::cout << "Result: " << r << std::endl;
+ std::cout << "-------------------------\n\n";
+ }
+ else
+ {
+ std::cout << "Compile failure\n";
+ }
+ }
+ else
+ {
+ std::cout << "Parse failure\n";
+ }
+ return 0;
+}
+
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/skipper.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/skipper.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,40 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_MINIC_SKIPPER_HPP)
+#define BOOST_SPIRIT_MINIC_SKIPPER_HPP
+
+#include <boost/spirit/include/qi.hpp>
+
+namespace client { namespace parser
+{
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // The skipper grammar
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct skipper : qi::grammar<Iterator>
+ {
+ skipper() : skipper::base_type(start)
+ {
+ qi::char_type char_;
+ ascii::space_type space;
+
+ start =
+ space // tab/space/cr/lf
+ | "/*" >> *(char_ - "*/") >> "*/" // C-style comments
+ ;
+ }
+
+ qi::rule<Iterator> start;
+ };
+}}
+
+#endif
+
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/statement.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/statement.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,14 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if defined(_MSC_VER)
+# pragma warning(disable: 4345)
+#endif
+
+#include "statement_def.hpp"
+
+typedef std::string::const_iterator iterator_type;
+template struct client::parser::statement<iterator_type>;

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/statement.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/statement.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,38 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_MINIC_STATEMENT_HPP)
+#define BOOST_SPIRIT_MINIC_STATEMENT_HPP
+
+#include "expression.hpp"
+
+namespace client { namespace parser
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // The statement grammar
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct statement : qi::grammar<Iterator, ast::statement_list(), skipper<Iterator> >
+ {
+ statement(error_handler<Iterator>& error_handler);
+
+ expression<Iterator> expr;
+ qi::rule<Iterator, ast::statement_list(), skipper<Iterator> >
+ statement_list, compound_statement;
+
+ qi::rule<Iterator, ast::statement(), skipper<Iterator> > statement_;
+ qi::rule<Iterator, ast::variable_declaration(), skipper<Iterator> > variable_declaration;
+ qi::rule<Iterator, ast::assignment(), skipper<Iterator> > assignment;
+ qi::rule<Iterator, ast::if_statement(), skipper<Iterator> > if_statement;
+ qi::rule<Iterator, ast::while_statement(), skipper<Iterator> > while_statement;
+ qi::rule<Iterator, ast::return_statement(), skipper<Iterator> > return_statement;
+ qi::rule<Iterator, std::string(), skipper<Iterator> > identifier;
+ };
+}}
+
+#endif
+
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/statement_def.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/statement_def.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,120 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#include "statement.hpp"
+#include "error_handler.hpp"
+#include "annotation.hpp"
+
+namespace client { namespace parser
+{
+ template <typename Iterator>
+ statement<Iterator>::statement(error_handler<Iterator>& error_handler)
+ : statement::base_type(statement_list), expr(error_handler)
+ {
+ qi::_1_type _1;
+ qi::_2_type _2;
+ qi::_3_type _3;
+ qi::_4_type _4;
+
+ qi::_val_type _val;
+ qi::raw_type raw;
+ qi::lexeme_type lexeme;
+ qi::alpha_type alpha;
+ qi::alnum_type alnum;
+ qi::lit_type lit;
+
+ using qi::on_error;
+ using qi::on_success;
+ using qi::fail;
+ using boost::phoenix::function;
+
+ typedef function<client::error_handler<Iterator> > error_handler_function;
+ typedef function<client::annotation<Iterator> > annotation_function;
+
+ statement_list =
+ +statement_
+ ;
+
+ statement_ =
+ variable_declaration
+ | assignment
+ | compound_statement
+ | if_statement
+ | while_statement
+ | return_statement
+ ;
+
+ identifier =
+ !expr.keywords
+ >> raw[lexeme[(alpha | '_') >> *(alnum | '_')]]
+ ;
+
+ variable_declaration =
+ lexeme["int" >> !(alnum | '_')] // make sure we have whole words
+ > &identifier // expect an identifier
+ > assignment
+ ;
+
+ assignment =
+ identifier
+ > '='
+ > expr
+ > ';'
+ ;
+
+ if_statement =
+ lit("if")
+ > '('
+ > expr
+ > ')'
+ > statement_
+ >
+ -(
+ lexeme["else" >> !(alnum | '_')] // make sure we have whole words
+ > statement_
+ )
+ ;
+
+ while_statement =
+ lit("while")
+ > '('
+ > expr
+ > ')'
+ > statement_
+ ;
+
+ compound_statement =
+ '{' >> -statement_list >> '}'
+ ;
+
+ return_statement =
+ lexeme["return" >> !(alnum | '_')] // make sure we have whole words
+ > -expr
+ > ';'
+ ;
+
+ // Debugging and error handling and reporting support.
+ BOOST_SPIRIT_DEBUG_NODES(
+ (statement_list)
+ (identifier)
+ (variable_declaration)
+ (assignment)
+ );
+
+ // Error handling: on error in statement_list, call error_handler.
+ on_error<fail>(statement_list,
+ error_handler_function(error_handler)(
+ "Error! Expecting ", _4, _3));
+
+ // Annotation: on success in assignment, call annotation.
+ on_success(assignment,
+ annotation_function(error_handler.iters)(_val, _1));
+ on_success(return_statement,
+ annotation_function(error_handler.iters)(_val, _1));
+ }
+}}
+
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/vm.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/vm.cpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,159 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#include "vm.hpp"
+
+#if defined(_MSC_VER)
+# pragma warning(disable: 4800) // forcing value to bool 'true' or 'false'
+ // (performance warning)
+#endif
+
+namespace client
+{
+ int vmachine::execute(
+ std::vector<int> const& code
+ , std::vector<int>::const_iterator pc
+ , std::vector<int>::iterator frame_ptr
+ )
+ {
+ std::vector<int>::iterator stack_ptr = frame_ptr;
+
+ while (true)
+ {
+ switch (*pc++)
+ {
+ case op_neg:
+ stack_ptr[-1] = -stack_ptr[-1];
+ break;
+
+ case op_not:
+ stack_ptr[-1] = !bool(stack_ptr[-1]);
+ break;
+
+ case op_add:
+ --stack_ptr;
+ stack_ptr[-1] += stack_ptr[0];
+ break;
+
+ case op_sub:
+ --stack_ptr;
+ stack_ptr[-1] -= stack_ptr[0];
+ break;
+
+ case op_mul:
+ --stack_ptr;
+ stack_ptr[-1] *= stack_ptr[0];
+ break;
+
+ case op_div:
+ --stack_ptr;
+ stack_ptr[-1] /= stack_ptr[0];
+ break;
+
+ case op_eq:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1] == stack_ptr[0]);
+ break;
+
+ case op_neq:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1] != stack_ptr[0]);
+ break;
+
+ case op_lt:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1] < stack_ptr[0]);
+ break;
+
+ case op_lte:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1] <= stack_ptr[0]);
+ break;
+
+ case op_gt:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1] > stack_ptr[0]);
+ break;
+
+ case op_gte:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1] >= stack_ptr[0]);
+ break;
+
+ case op_and:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1]) && bool(stack_ptr[0]);
+ break;
+
+ case op_or:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1]) || bool(stack_ptr[0]);
+ break;
+
+ case op_load:
+ *stack_ptr++ = frame_ptr[*pc++];
+ break;
+
+ case op_store:
+ --stack_ptr;
+ frame_ptr[*pc++] = stack_ptr[0];
+ break;
+
+ case op_int:
+ *stack_ptr++ = *pc++;
+ break;
+
+ case op_true:
+ *stack_ptr++ = true;
+ break;
+
+ case op_false:
+ *stack_ptr++ = false;
+ break;
+
+ case op_jump:
+ pc += *pc;
+ break;
+
+ case op_jump_if:
+ if (!bool(stack_ptr[-1]))
+ pc += *pc;
+ else
+ ++pc;
+ --stack_ptr;
+ break;
+
+ case op_stk_adj:
+ stack_ptr += *pc++;
+ break;
+
+ case op_call:
+ {
+ int nargs = *pc++;
+ int jump = *pc++;
+
+ // a function call is a recursive call to execute
+ int r = execute(
+ code
+ , code.begin() + jump
+ , stack_ptr - nargs
+ );
+
+ // cleanup after return from function
+ stack_ptr[-nargs] = r; // get return value
+ stack_ptr -= (nargs - 1); // the stack will now contain
+ // the return value
+ }
+ break;
+
+ case op_return:
+ return stack_ptr[-1];
+ }
+ }
+ }
+}
+
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/vm.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/vm.hpp 2011-03-07 02:02:19 EST (Mon, 07 Mar 2011)
@@ -0,0 +1,82 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_MINIC_VM_HPP)
+#define BOOST_SPIRIT_MINIC_VM_HPP
+
+#include <vector>
+
+namespace client
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // The Virtual Machine
+ ///////////////////////////////////////////////////////////////////////////
+ enum byte_code
+ {
+ op_neg, // negate the top stack entry
+ op_add, // add top two stack entries
+ op_sub, // subtract top two stack entries
+ op_mul, // multiply top two stack entries
+ op_div, // divide top two stack entries
+
+ op_not, // boolean negate the top stack entry
+ op_eq, // compare the top two stack entries for ==
+ op_neq, // compare the top two stack entries for !=
+ op_lt, // compare the top two stack entries for <
+ op_lte, // compare the top two stack entries for <=
+ op_gt, // compare the top two stack entries for >
+ op_gte, // compare the top two stack entries for >=
+
+ op_and, // logical and top two stack entries
+ op_or, // logical or top two stack entries
+
+ op_load, // load a variable
+ op_store, // store a variable
+
+ op_int, // push constant integer into the stack
+ op_true, // push constant 0 into the stack
+ op_false, // push constant 1 into the stack
+
+ op_jump_if, // jump to a relative position in the code if top stack
+ // evaluates to false
+ op_jump, // jump to a relative position in the code
+
+ op_stk_adj, // adjust the stack (for args and locals)
+ op_call, // function call
+ op_return // return from function
+ };
+
+ class vmachine
+ {
+ public:
+
+ vmachine(unsigned stackSize = 4096)
+ : stack(stackSize)
+ {
+ }
+
+ int execute(std::vector<int> const& code)
+ {
+ return execute(code, code.begin(), stack.begin());
+ }
+
+ std::vector<int> const& get_stack() const { return stack; };
+ std::vector<int>& get_stack() { return stack; };
+
+ private:
+
+ int execute(
+ std::vector<int> const& code // the program code
+ , std::vector<int>::const_iterator pc // program counter
+ , std::vector<int>::iterator frame_ptr // start of arguments and locals
+ );
+
+ std::vector<int> stack;
+ };
+}
+
+#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