Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73574 - trunk/libs/spirit/example/qi/compiler_tutorial/conjure3
From: joel_at_[hidden]
Date: 2011-08-06 11:11:53


Author: djowel
Date: 2011-08-06 11:11:52 EDT (Sat, 06 Aug 2011)
New Revision: 73574
URL: http://svn.boost.org/trac/boost/changeset/73574

Log:
Now pre++ and pre-- works. lvalue handling works.
Text files modified:
   trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp | 28 +++++++++++++++++++---------
   trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.hpp | 7 +------
   2 files changed, 20 insertions(+), 15 deletions(-)

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp 2011-08-06 11:11:52 EDT (Sat, 06 Aug 2011)
@@ -144,15 +144,13 @@
     value compiler::operator()(ast::identifier const& x)
     {
         // Look this variable up in the function.
- value value = named_values[x.name];
+ lvalue value = named_values[x.name];
         if (!value)
         {
             error_handler(x.id, "Undeclared variable: " + x.name);
             return 0;
         }
-
- // Load the value.
- return builder.CreateLoad(value, x.name.c_str());
+ return value;
     }
 
     value compiler::operator()(ast::unary const& x)
@@ -165,13 +163,25 @@
         {
             case token_ids::compl_:
                 return builder.CreateXor(
- operand, value(-1), "compltmp");
+ operand, value(-1), "compl_tmp");
             case token_ids::minus:
- return builder.CreateNeg(operand, "negtmp");
+ return builder.CreateNeg(operand, "neg_tmp");
             case token_ids::not_:
- return builder.CreateNot(operand, "nottmp");
+ return builder.CreateNot(operand, "not_tmp");
             case token_ids::plus:
                 return operand;
+ case token_ids::plus_plus:
+ {
+ value r = builder.CreateAdd(operand, value(1), "add_tmp");
+ operand.assign(r);
+ return operand;
+ }
+ case token_ids::minus_minus:
+ {
+ value r = builder.CreateSub(operand, value(1), "sub_tmp");
+ operand.assign(r);
+ return operand;
+ }
             default: BOOST_ASSERT(0); return 0;
         }
     }
@@ -336,13 +346,13 @@
 
     value compiler::operator()(ast::assignment const& x)
     {
- lvalue lhs(named_values[x.lhs.name], builder);
- if (!lhs)
+ if (named_values.find(x.lhs.name) == named_values.end())
         {
             error_handler(x.lhs.id, "Undeclared variable: " + x.lhs.name);
             return 0;
         }
 
+ lvalue lhs = named_values[x.lhs.name];
         value rhs = (*this)(x.rhs);
         if (!rhs)
             return 0;

Modified: trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.hpp 2011-08-06 11:11:52 EDT (Sat, 06 Aug 2011)
@@ -79,11 +79,6 @@
         {}
 
         lvalue(llvm::IRBuilder<>& builder, char const* name);
-
- operator llvm::AllocaInst*() const
- {
- return dynamic_cast<llvm::AllocaInst*>(v);
- }
     };
 
     ///////////////////////////////////////////////////////////////////////////
@@ -152,7 +147,7 @@
 
         bool void_return;
         std::string current_function_name;
- std::map<std::string, llvm::AllocaInst*> named_values;
+ std::map<std::string, lvalue> named_values;
         llvm::BasicBlock* return_block;
         lvalue return_alloca;
 


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