Work-around for negate and not. Boolean print isn't working

This commit is contained in:
Jonathan Turner
2009-06-11 03:29:42 +00:00
parent 8c689d2017
commit 82daa9b63b
2 changed files with 29 additions and 5 deletions

View File

@@ -526,11 +526,11 @@ void bootstrap(BoxedCPP_System &s)
add_oper_add<std::string>(s);
add_oper_add_equals <std::string>(s);
register_function(s, &print<int>, "print");
register_function(s, &print<const bool>, "print");
register_function(s, &print<std::string>, "print");
register_function(s, &print<double>, "print");
register_function(s, &print<float>, "print");
register_function(s, &print<bool>, "print");
register_function(s, &print<size_t>, "print");
register_function(s, &print<int>, "print");
s.register_function(boost::function<void ()>(boost::bind(&dump_system, boost::ref(s))), "dump_system");
s.register_function(boost::function<void (Boxed_Value)>(boost::bind(&dump_object, _1)), "dump_object");

View File

@@ -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<bool &>()(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;