From 82daa9b63bc3bba76899b665979069dd7f3006b4 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 11 Jun 2009 03:29:42 +0000 Subject: [PATCH] Work-around for negate and not. Boolean print isn't working --- boxedcpp/bootstrap.hpp | 6 +++--- wesley/wesley_eval.hpp | 28 ++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/boxedcpp/bootstrap.hpp b/boxedcpp/bootstrap.hpp index 83b1c0c..8500b8f 100644 --- a/boxedcpp/bootstrap.hpp +++ b/boxedcpp/bootstrap.hpp @@ -526,11 +526,11 @@ void bootstrap(BoxedCPP_System &s) add_oper_add(s); add_oper_add_equals (s); - register_function(s, &print, "print"); + register_function(s, &print, "print"); register_function(s, &print, "print"); register_function(s, &print, "print"); - register_function(s, &print, "print"); - register_function(s, &print, "print"); + register_function(s, &print, "print"); + register_function(s, &print, "print"); s.register_function(boost::function(boost::bind(&dump_system, boost::ref(s))), "dump_system"); s.register_function(boost::function(boost::bind(&dump_object, _1)), "dump_object"); diff --git a/wesley/wesley_eval.hpp b/wesley/wesley_eval.hpp index 9849970..fe9aa02 100644 --- a/wesley/wesley_eval.hpp +++ b/wesley/wesley_eval.hpp @@ -140,8 +140,32 @@ Boxed_Value eval_token(Eval_System &ss, TokenPtr node) { } } break; - case (TokenType::Negate) : - case (TokenType::Not) : + case (TokenType::Negate) : { + retval = eval_token(ss, node->children[1]); + Param_List_Builder plb; + plb << retval; + plb << Boxed_Value(-1); + + try { + retval = dispatch(ss.get_function("*"), plb); + } + catch(std::exception &e){ + throw EvalError("Can not find appropriate negation", node->children[0]); + } + } + break; + case (TokenType::Not) : { + bool cond; + try { + retval = eval_token(ss, node->children[1]); + cond = Cast_Helper()(retval); + } + catch (std::exception) { + throw EvalError("Boolean not('!') condition not boolean", node->children[0]); + } + retval = Boxed_Value(!cond); + } + break; case (TokenType::Prefix) : { retval = eval_token(ss, node->children[1]); Param_List_Builder plb;