|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r73575 - trunk/libs/spirit/example/qi/compiler_tutorial/conjure3
From: joel_at_[hidden]
Date: 2011-08-06 11:27:49
Author: djowel
Date: 2011-08-06 11:27:48 EDT (Sat, 06 Aug 2011)
New Revision: 73575
URL: http://svn.boost.org/trac/boost/changeset/73575
Log:
more tweaks
Text files modified:
trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp | 52 ++++++++++++++++++++++++++-------------
trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.hpp | 3 --
2 files changed, 34 insertions(+), 21 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:27:48 EDT (Sat, 06 Aug 2011)
@@ -144,20 +144,19 @@
value compiler::operator()(ast::identifier const& x)
{
// Look this variable up in the function.
- lvalue value = named_values[x.name];
- if (!value)
+ if (named_values.find(x.name) == named_values.end())
{
error_handler(x.id, "Undeclared variable: " + x.name);
- return 0;
+ return value();
}
- return value;
+ return named_values[x.name];
}
value compiler::operator()(ast::unary const& x)
{
value operand = boost::apply_visitor(*this, x.operand_);
if (!operand)
- return 0;
+ return value();
switch (x.operator_)
{
@@ -172,17 +171,31 @@
return operand;
case token_ids::plus_plus:
{
+ if (!operand.is_lvalue())
+ {
+ // $$$ JDG Error here $$$
+ return value();
+ }
+
value r = builder.CreateAdd(operand, value(1), "add_tmp");
operand.assign(r);
return operand;
}
case token_ids::minus_minus:
{
+ if (!operand.is_lvalue())
+ {
+ // $$$ JDG Error here $$$
+ return value();
+ }
+
value r = builder.CreateSub(operand, value(1), "sub_tmp");
operand.assign(r);
return operand;
}
- default: BOOST_ASSERT(0); return 0;
+ default:
+ BOOST_ASSERT(0);
+ return value();
}
}
@@ -192,13 +205,13 @@
if (!callee)
{
error_handler(x.function_name.id, "Function not found: " + x.function_name.name);
- return false;
+ return value();
}
if (callee->arg_size() != x.args.size())
{
error_handler(x.function_name.id, "Wrong number of arguments: " + x.function_name.name);
- return 0;
+ return value();
}
std::vector<llvm::Value*> args;
@@ -206,7 +219,7 @@
{
args.push_back((*this)(expr));
if (args.back() == 0)
- return 0;
+ return value();
}
return builder.CreateCall(callee, args.begin(), args.end(), "calltmp");
@@ -302,7 +315,10 @@
case token_ids::logical_or: return builder.CreateOr(lhs, rhs, "ortmp");
case token_ids::logical_and: return builder.CreateAnd(lhs, rhs, "andtmp");
- default: BOOST_ASSERT(0); return 0;
+
+ default:
+ BOOST_ASSERT(0);
+ return value();
}
}
@@ -319,7 +335,7 @@
token_ids::type op = rest_begin->operator_;
value rhs = boost::apply_visitor(*this, rest_begin->operand_);
if (!rhs)
- return 0;
+ return value();
++rest_begin;
while ((rest_begin != rest_end) &&
@@ -339,7 +355,7 @@
{
value lhs = boost::apply_visitor(*this, x.first);
if (!lhs)
- return 0;
+ return value();
std::list<ast::operation>::const_iterator rest_begin = x.rest.begin();
return compile_expression(0, lhs, rest_begin, x.rest.end());
}
@@ -349,13 +365,13 @@
if (named_values.find(x.lhs.name) == named_values.end())
{
error_handler(x.lhs.id, "Undeclared variable: " + x.lhs.name);
- return 0;
+ return value();
}
lvalue lhs = named_values[x.lhs.name];
value rhs = (*this)(x.rhs);
if (!rhs)
- return 0;
+ return value();
if (x.operator_ == token_ids::assign)
{
@@ -406,7 +422,7 @@
result = builder.CreateLShr(lhs, rhs, "shrtmp");
break;
- default: BOOST_ASSERT(0); return 0;
+ default: BOOST_ASSERT(0); return value();
}
lhs.assign(result);
@@ -471,7 +487,7 @@
{
value condition = (*this)(x.condition);
if (!condition)
- return 0;
+ return false;
llvm::Function* function = builder.GetInsertBlock()->getParent();
@@ -495,7 +511,7 @@
// Emit then value.
builder.SetInsertPoint(then_block);
if (!(*this)(x.then))
- return 0;
+ return false;
if (then_block->getTerminator() == 0)
{
if (exit_block == 0)
@@ -511,7 +527,7 @@
function->getBasicBlockList().push_back(else_block);
builder.SetInsertPoint(else_block);
if (!(*this)(*x.else_))
- return 0;
+ return false;
if (else_block->getTerminator() == 0)
{
if (exit_block == 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:27:48 EDT (Sat, 06 Aug 2011)
@@ -154,9 +154,6 @@
vmachine& vm;
llvm::FunctionPassManager fpm;
- llvm::LLVMContext& context() const
- { return llvm::getGlobalContext(); }
-
llvm::Module* init_llvm();
void init_fpm();
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