Fix some semantics of operator= to reduce dispatch, etc.
Also, add more bootstrapping support for some of the built in types.
This commit is contained in:
parent
a70af22eaf
commit
47052f710c
@ -75,7 +75,10 @@ namespace chaiscript
|
||||
dispatchkit::Boxed_Value lhs = eval_token(ss, node->children[i]);
|
||||
if (lhs.is_unknown() || dispatchkit::Bootstrap::type_match(lhs, retval)) {
|
||||
try {
|
||||
retval = dispatch(ss.get_function("clone"), dispatchkit::Param_List_Builder() << retval);
|
||||
if (lhs.is_unknown())
|
||||
{
|
||||
retval = dispatch(ss.get_function("clone"), dispatchkit::Param_List_Builder() << retval);
|
||||
}
|
||||
dispatchkit::Param_List_Builder plb;
|
||||
plb << lhs;
|
||||
plb << retval;
|
||||
@ -87,16 +90,7 @@ namespace chaiscript
|
||||
}
|
||||
}
|
||||
catch(const dispatchkit::dispatch_error &e){
|
||||
//throw EvalError("Can not clone right hand side of equation", node->children[i+1]);
|
||||
dispatchkit::Param_List_Builder plb;
|
||||
plb << lhs;
|
||||
plb << retval;
|
||||
try {
|
||||
retval = dispatch(ss.get_function("="), plb);
|
||||
}
|
||||
catch(const dispatchkit::dispatch_error &e){
|
||||
throw EvalError("Can not find appropriate '" + node->children[i+1]->text + "'", node->children[i+1]);
|
||||
}
|
||||
throw EvalError("Can not clone right hand side of equation", node->children[i+1]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -106,15 +100,7 @@ namespace chaiscript
|
||||
else if (node->children[i+1]->text == ":=") {
|
||||
dispatchkit::Boxed_Value lhs = eval_token(ss, node->children[i]);
|
||||
if (lhs.is_unknown() || dispatchkit::Bootstrap::type_match(lhs, retval)) {
|
||||
dispatchkit::Param_List_Builder plb;
|
||||
plb << lhs;
|
||||
plb << retval;
|
||||
try {
|
||||
retval = dispatch(ss.get_function("="), plb);
|
||||
}
|
||||
catch(const dispatchkit::dispatch_error &e){
|
||||
throw EvalError("Can not find appropriate '" + node->children[i+1]->text + "'", node->children[i+1]);
|
||||
}
|
||||
lhs.assign(retval);
|
||||
}
|
||||
else {
|
||||
throw EvalError("Mismatched types in equation", node->children[i+1]);
|
||||
|
@ -330,12 +330,18 @@ namespace dispatchkit
|
||||
register_function(s, &addsequal_pod<T>, "+=");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void add_copy_constructor(Dispatch_Engine &s, const std::string &type)
|
||||
{
|
||||
s.register_function(build_constructor<T, const T &>(), type);
|
||||
s.register_function(build_constructor<T, const T &>(), "clone");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void add_basic_constructors(Dispatch_Engine &s, const std::string &type)
|
||||
{
|
||||
s.register_function(build_constructor<T>(), type);
|
||||
s.register_function(build_constructor<T, const T &>(), type);
|
||||
s.register_function(build_constructor<T, const T &>(), "clone");
|
||||
add_copy_constructor<T>(s, type);
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
@ -489,7 +495,7 @@ namespace dispatchkit
|
||||
add_oper_add<std::string>(s);
|
||||
add_oper_add_equals <std::string>(s);
|
||||
add_opers_comparison<std::string>(s);
|
||||
|
||||
s.register_function(build_constructor<boost::shared_ptr<Proxy_Function>, const boost::shared_ptr<Proxy_Function> &>(), "clone");
|
||||
|
||||
register_function(s, &print, "print_string");
|
||||
register_function(s, &println, "println_string");
|
||||
|
@ -65,6 +65,7 @@ namespace dispatchkit
|
||||
register_function(system, &Input_Range<ContainerType>::empty, "empty");
|
||||
register_function(system, &Input_Range<ContainerType>::pop_front, "pop_front");
|
||||
register_function(system, &Input_Range<ContainerType>::front, "front");
|
||||
system.register_function(build_constructor<Input_Range<ContainerType>, const Input_Range<ContainerType> &>(), "clone");
|
||||
}
|
||||
|
||||
template<typename ContainerType>
|
||||
@ -92,6 +93,8 @@ namespace dispatchkit
|
||||
{
|
||||
system.register_function(
|
||||
boost::function<Assignable &(Assignable*, const Assignable&)>(&Assignable::operator=), "=");
|
||||
system.register_function(build_constructor<Assignable, const Assignable &>(), type);
|
||||
system.register_function(build_constructor<Assignable, const Assignable &>(), "clone");
|
||||
}
|
||||
|
||||
template<typename ContainerType>
|
||||
@ -153,10 +156,24 @@ namespace dispatchkit
|
||||
bootstrap_default_constructible<ContainerType>(system, type);
|
||||
}
|
||||
|
||||
template<typename PairType>
|
||||
void bootstrap_pair(Dispatch_Engine &system, const std::string &type)
|
||||
{
|
||||
register_member(system, &PairType::first, "first");
|
||||
register_member(system, &PairType::second, "second");
|
||||
|
||||
system.register_function(build_constructor<PairType >(), type);
|
||||
system.register_function(build_constructor<PairType, const PairType &>(), type);
|
||||
system.register_function(build_constructor<PairType, const PairType &>(), "clone");
|
||||
system.register_function(build_constructor<PairType, const typename PairType::first_type &, const typename PairType::second_type &>(), type);
|
||||
}
|
||||
|
||||
|
||||
template<typename ContainerType>
|
||||
void bootstrap_pair_associative_container(Dispatch_Engine &system, const std::string &type)
|
||||
{
|
||||
bootstrap_associative_container<ContainerType>(system, type);
|
||||
bootstrap_pair<typename ContainerType::value_type>(system, type + "_Pair");
|
||||
}
|
||||
|
||||
template<typename ContainerType>
|
||||
@ -166,16 +183,6 @@ namespace dispatchkit
|
||||
register_function(system, &ContainerType::count, "count");
|
||||
}
|
||||
|
||||
template<typename PairType>
|
||||
void bootstrap_pair(Dispatch_Engine &system, const std::string &type)
|
||||
{
|
||||
register_member(system, &PairType::first, "first");
|
||||
register_member(system, &PairType::second, "second");
|
||||
|
||||
system.register_function(build_constructor<PairType >(), type);
|
||||
system.register_function(build_constructor<PairType, const typename PairType::first_type &, const typename PairType::second_type &>(), type);
|
||||
}
|
||||
|
||||
template<typename ContainerType>
|
||||
void bootstrap_sorted_associative_container(Dispatch_Engine &system, const std::string &type)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user