Make vector inplace construction consistent with map
- Clone elements into both vector and map - Be sure to drop dependencies after elements are cloned in
This commit is contained in:
@@ -185,7 +185,7 @@ if(BUILD_TESTING)
|
|||||||
|
|
||||||
add_executable(short_comparison_test unittests/short_comparison_test.cpp)
|
add_executable(short_comparison_test unittests/short_comparison_test.cpp)
|
||||||
target_link_libraries(short_comparison_test ${LIBS})
|
target_link_libraries(short_comparison_test ${LIBS})
|
||||||
add_test(NAME short_comparison_test COMMAND short_comparison_test)
|
add_test(NAME Short_Comparison_Test COMMAND short_comparison_test)
|
||||||
|
|
||||||
|
|
||||||
add_executable(multifile_test unittests/multifile_test_main.cpp unittests/multifile_test_chai.cpp
|
add_executable(multifile_test unittests/multifile_test_main.cpp unittests/multifile_test_chai.cpp
|
||||||
|
@@ -831,14 +831,21 @@ namespace chaiscript
|
|||||||
AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
|
AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
|
||||||
virtual ~Inline_Array_AST_Node() {}
|
virtual ~Inline_Array_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){
|
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||||
std::vector<Boxed_Value> vec;
|
try {
|
||||||
if (this->children.size() > 0) {
|
std::vector<Boxed_Value> vec;
|
||||||
for (size_t i = 0; i < this->children[0]->children.size(); ++i) {
|
if (this->children.size() > 0) {
|
||||||
vec.push_back(this->children[0]->children[i]->eval(t_ss));
|
for (size_t i = 0; i < this->children[0]->children.size(); ++i) {
|
||||||
|
Boxed_Value bv = t_ss.call_function("clone", this->children[0]->children[i]->eval(t_ss));
|
||||||
|
bv.clear_dependencies();
|
||||||
|
vec.push_back(bv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return const_var(vec);
|
||||||
|
}
|
||||||
|
catch (const exception::dispatch_error &) {
|
||||||
|
throw exception::eval_error("Can not find appropriate 'clone' or copy constructor for vector elements");
|
||||||
}
|
}
|
||||||
|
|
||||||
return const_var(vec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -852,13 +859,15 @@ namespace chaiscript
|
|||||||
try {
|
try {
|
||||||
std::map<std::string, Boxed_Value> retval;
|
std::map<std::string, Boxed_Value> retval;
|
||||||
for (size_t i = 0; i < this->children[0]->children.size(); ++i) {
|
for (size_t i = 0; i < this->children[0]->children.size(); ++i) {
|
||||||
|
Boxed_Value bv = t_ss.call_function("clone", this->children[0]->children[i]->children[1]->eval(t_ss));
|
||||||
|
bv.clear_dependencies();
|
||||||
retval[boxed_cast<std::string>(this->children[0]->children[i]->children[0]->eval(t_ss))]
|
retval[boxed_cast<std::string>(this->children[0]->children[i]->children[0]->eval(t_ss))]
|
||||||
= t_ss.call_function("clone", this->children[0]->children[i]->children[1]->eval(t_ss));
|
= bv;
|
||||||
}
|
}
|
||||||
return const_var(retval);
|
return const_var(retval);
|
||||||
}
|
}
|
||||||
catch (const exception::dispatch_error &) {
|
catch (const exception::dispatch_error &) {
|
||||||
throw exception::eval_error("Can not find appropriate 'Map()'");
|
throw exception::eval_error("Can not find appropriate 'clone' or copy constructor for map elements");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,14 @@
|
|||||||
var x = ["bob":1, "fred":2]
|
var x = ["bob":1, "fred":2]
|
||||||
|
|
||||||
assert_equal(2, x.size());
|
assert_equal(2, x.size());
|
||||||
|
|
||||||
|
|
||||||
|
// Make sure vector elements are copied into place for consistency with
|
||||||
|
// map inplace construction
|
||||||
|
var i = 1;
|
||||||
|
var y = ["a":i];
|
||||||
|
|
||||||
|
assert_equal(1, y["a"]);
|
||||||
|
i = 3;
|
||||||
|
assert_equal(3, i);
|
||||||
|
assert_equal(1, y["a"]);
|
||||||
|
@@ -1,2 +1,14 @@
|
|||||||
var x = [1, 2, 3]
|
var x = [1, 2, 3]
|
||||||
assert_equal(3, x.size())
|
assert_equal(3, x.size())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Make sure vector elements are copied into place for consistency with
|
||||||
|
// map inplace construction
|
||||||
|
var i = 1;
|
||||||
|
var y = [i];
|
||||||
|
|
||||||
|
assert_equal(1, y[0]);
|
||||||
|
i = 3;
|
||||||
|
assert_equal(3, i);
|
||||||
|
assert_equal(1, y[0]);
|
||||||
|
Reference in New Issue
Block a user