Merge branch 'release-5.x' into develop

This commit is contained in:
Jason Turner
2016-10-07 09:13:19 -06:00
8 changed files with 66 additions and 53 deletions

View File

@@ -450,7 +450,6 @@ namespace chaiscript
Dispatch_Engine(chaiscript::parser::ChaiScript_Parser_Base &parser) Dispatch_Engine(chaiscript::parser::ChaiScript_Parser_Base &parser)
: m_stack_holder(this), : m_stack_holder(this),
m_parser(parser) m_parser(parser)
{ {
} }
@@ -1498,7 +1497,7 @@ namespace chaiscript
chaiscript::detail::threading::Thread_Storage<Stack_Holder> m_stack_holder; chaiscript::detail::threading::Thread_Storage<Stack_Holder> m_stack_holder;
std::reference_wrapper<parser::ChaiScript_Parser_Base> m_parser; std::reference_wrapper<parser::ChaiScript_Parser_Base> m_parser;
mutable std::atomic_uint_fast32_t m_method_missing_loc; mutable std::atomic_uint_fast32_t m_method_missing_loc = {0};
State m_state; State m_state;
}; };

View File

@@ -64,7 +64,9 @@ namespace chaiscript
Logical_And, Logical_Or, Reference, Switch, Case, Default, Ternary_Cond, Noop, Class, Binary, Arg, Global_Decl, Constant, Compiled Logical_And, Logical_Or, Reference, Switch, Case, Default, Ternary_Cond, Noop, Class, Binary, Arg, Global_Decl, Constant, Compiled
}; };
enum class Operator_Precidence { Ternary_Cond, Logical_Or, Logical_And, Bitwise_Or, Bitwise_Xor, Bitwise_And, Equality, Comparison, Shift, Addition, Multiplication }; enum class Operator_Precidence { Ternary_Cond, Logical_Or,
Logical_And, Bitwise_Or, Bitwise_Xor, Bitwise_And,
Equality, Comparison, Shift, Addition, Multiplication, Prefix };
namespace namespace
{ {

View File

@@ -86,8 +86,6 @@ namespace chaiscript
} }
} }
template<typename T> template<typename T>
struct AST_Node_Impl : AST_Node struct AST_Node_Impl : AST_Node
{ {
@@ -147,8 +145,7 @@ namespace chaiscript
Fold_Right_Binary_Operator_AST_Node(const std::string &t_oper, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children, Boxed_Value t_rhs) : Fold_Right_Binary_Operator_AST_Node(const std::string &t_oper, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children, Boxed_Value t_rhs) :
AST_Node_Impl<T>(t_oper, AST_Node_Type::Binary, std::move(t_loc), std::move(t_children)), AST_Node_Impl<T>(t_oper, AST_Node_Type::Binary, std::move(t_loc), std::move(t_children)),
m_oper(Operators::to_operator(t_oper)), m_oper(Operators::to_operator(t_oper)),
m_rhs(std::move(t_rhs)), m_rhs(std::move(t_rhs))
m_loc(0)
{ } { }
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
@@ -184,7 +181,7 @@ namespace chaiscript
private: private:
Operators::Opers m_oper; Operators::Opers m_oper;
Boxed_Value m_rhs; Boxed_Value m_rhs;
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc = {0};
}; };
@@ -192,8 +189,7 @@ namespace chaiscript
struct Binary_Operator_AST_Node : AST_Node_Impl<T> { struct Binary_Operator_AST_Node : AST_Node_Impl<T> {
Binary_Operator_AST_Node(const std::string &t_oper, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) : Binary_Operator_AST_Node(const std::string &t_oper, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) :
AST_Node_Impl<T>(t_oper, AST_Node_Type::Binary, std::move(t_loc), std::move(t_children)), AST_Node_Impl<T>(t_oper, AST_Node_Type::Binary, std::move(t_loc), std::move(t_children)),
m_oper(Operators::to_operator(t_oper)), m_oper(Operators::to_operator(t_oper))
m_loc(0)
{ } { }
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
@@ -230,7 +226,7 @@ namespace chaiscript
private: private:
Operators::Opers m_oper; Operators::Opers m_oper;
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc = {0};
}; };
@@ -258,8 +254,7 @@ namespace chaiscript
template<typename T> template<typename T>
struct Id_AST_Node final : AST_Node_Impl<T> { struct Id_AST_Node final : AST_Node_Impl<T> {
Id_AST_Node(const std::string &t_ast_node_text, Parse_Location t_loc) : Id_AST_Node(const std::string &t_ast_node_text, Parse_Location t_loc) :
AST_Node_Impl<T>(t_ast_node_text, AST_Node_Type::Id, std::move(t_loc)), AST_Node_Impl<T>(t_ast_node_text, AST_Node_Type::Id, std::move(t_loc))
m_loc(0)
{ } { }
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
@@ -272,7 +267,7 @@ namespace chaiscript
} }
private: private:
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc = {0};
}; };
@@ -514,8 +509,8 @@ namespace chaiscript
private: private:
Operators::Opers m_oper; Operators::Opers m_oper;
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc = {0};
mutable std::atomic_uint_fast32_t m_clone_loc; mutable std::atomic_uint_fast32_t m_clone_loc = {0};
}; };
template<typename T> template<typename T>
@@ -579,7 +574,7 @@ namespace chaiscript
private: private:
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc = {0};
}; };
template<typename T> template<typename T>
@@ -635,8 +630,8 @@ namespace chaiscript
} }
private: private:
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc = {0};
mutable std::atomic_uint_fast32_t m_array_loc; mutable std::atomic_uint_fast32_t m_array_loc = {0};
const std::string m_fun_name; const std::string m_fun_name;
}; };
@@ -850,11 +845,7 @@ namespace chaiscript
template<typename T> template<typename T>
struct Ranged_For_AST_Node final : AST_Node_Impl<T> { struct Ranged_For_AST_Node final : AST_Node_Impl<T> {
Ranged_For_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) : Ranged_For_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) :
AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Ranged_For, std::move(t_loc), std::move(t_children)), AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Ranged_For, std::move(t_loc), std::move(t_children))
m_range_loc(0),
m_empty_loc(0),
m_front_loc(0),
m_pop_front_loc(0)
{ assert(this->children.size() == 3); } { assert(this->children.size() == 3); }
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
@@ -921,12 +912,11 @@ namespace chaiscript
} }
private: private:
mutable std::atomic_uint_fast32_t m_range_loc; mutable std::atomic_uint_fast32_t m_range_loc = {0};
mutable std::atomic_uint_fast32_t m_empty_loc; mutable std::atomic_uint_fast32_t m_empty_loc = {0};
mutable std::atomic_uint_fast32_t m_front_loc; mutable std::atomic_uint_fast32_t m_front_loc = {0};
mutable std::atomic_uint_fast32_t m_pop_front_loc; mutable std::atomic_uint_fast32_t m_pop_front_loc = {0};
}; };
@@ -1004,7 +994,7 @@ private:
return void_var(); return void_var();
} }
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc = {0};
}; };
template<typename T> template<typename T>
@@ -1065,7 +1055,7 @@ private:
} }
private: private:
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc = {0};
}; };
template<typename T> template<typename T>
@@ -1073,7 +1063,8 @@ private:
Inline_Map_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) : Inline_Map_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) :
AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Inline_Map, std::move(t_loc), std::move(t_children)) { } AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Inline_Map, std::move(t_loc), std::move(t_children)) { }
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override
{
try { try {
std::map<std::string, Boxed_Value> retval; std::map<std::string, Boxed_Value> retval;
@@ -1094,7 +1085,7 @@ private:
} }
private: private:
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc = {0};
}; };
template<typename T> template<typename T>
@@ -1176,8 +1167,8 @@ private:
} }
private: private:
Operators::Opers m_oper; Operators::Opers m_oper = Operators::Opers::invalid;
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc = {0};
}; };
template<typename T> template<typename T>
@@ -1243,7 +1234,7 @@ private:
} }
private: private:
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc = {0};
}; };
template<typename T> template<typename T>

View File

@@ -199,15 +199,16 @@ namespace chaiscript
{"<<", ">>"}, {"<<", ">>"},
//We share precedence here but then separate them later //We share precedence here but then separate them later
{"+", "-"}, {"+", "-"},
{"*", "/", "%"} {"*", "/", "%"},
{"++", "--", "-", "+", "!", "~"}
}; };
return operator_matches; return operator_matches;
} }
static const std::array<Operator_Precidence, 11> &create_operators() { static const std::array<Operator_Precidence, 12> &create_operators() {
static const std::array<Operator_Precidence, 11> operators = { { static const std::array<Operator_Precidence, 12> operators = { {
Operator_Precidence::Ternary_Cond, Operator_Precidence::Ternary_Cond,
Operator_Precidence::Logical_Or, Operator_Precidence::Logical_Or,
Operator_Precidence::Logical_And, Operator_Precidence::Logical_And,
@@ -218,7 +219,8 @@ namespace chaiscript
Operator_Precidence::Comparison, Operator_Precidence::Comparison,
Operator_Precidence::Shift, Operator_Precidence::Shift,
Operator_Precidence::Addition, Operator_Precidence::Addition,
Operator_Precidence::Multiplication Operator_Precidence::Multiplication,
Operator_Precidence::Prefix
} }; } };
return operators; return operators;
} }
@@ -230,7 +232,7 @@ namespace chaiscript
const std::array<std::array<bool, detail::lengthof_alphabet>, detail::max_alphabet> &m_alphabet = create_alphabet(); const std::array<std::array<bool, detail::lengthof_alphabet>, detail::max_alphabet> &m_alphabet = create_alphabet();
const std::vector<std::vector<std::string>> &m_operator_matches = create_operator_matches(); const std::vector<std::vector<std::string>> &m_operator_matches = create_operator_matches();
const std::array<Operator_Precidence, 11> &m_operators = create_operators(); const std::array<Operator_Precidence, 12> &m_operators = create_operators();
std::shared_ptr<std::string> m_filename; std::shared_ptr<std::string> m_filename;
std::vector<eval::AST_Node_Impl_Ptr<Tracer>> m_match_stack; std::vector<eval::AST_Node_Impl_Ptr<Tracer>> m_match_stack;
@@ -358,7 +360,6 @@ namespace chaiscript
ChaiScript_Parser(ChaiScript_Parser &&) = default; ChaiScript_Parser(ChaiScript_Parser &&) = default;
ChaiScript_Parser &operator=(ChaiScript_Parser &&) = delete; ChaiScript_Parser &operator=(ChaiScript_Parser &&) = delete;
/// test a char in an m_alphabet /// test a char in an m_alphabet
bool char_in_alphabet(char c, detail::Alphabet a) const { return m_alphabet[a][static_cast<uint8_t>(c)]; } bool char_in_alphabet(char c, detail::Alphabet a) const { return m_alphabet[a][static_cast<uint8_t>(c)]; }
@@ -2175,15 +2176,15 @@ namespace chaiscript
/// Reads a unary prefixed expression from input /// Reads a unary prefixed expression from input
bool Prefix() { bool Prefix() {
const auto prev_stack_top = m_match_stack.size(); const auto prev_stack_top = m_match_stack.size();
const std::vector<std::string> prefix_opers{"++", "--", "-", "+", "!", "~", "&"}; constexpr const std::array<const char *, 6> prefix_opers{"++", "--", "-", "+", "!", "~"};
for (const auto &oper : prefix_opers) for (const auto &oper : prefix_opers)
{ {
bool is_char = oper.size() == 1; bool is_char = strlen(oper) == 1;
if ((is_char && Char(oper[0])) || (!is_char && Symbol(oper.c_str()))) if ((is_char && Char(oper[0])) || (!is_char && Symbol(oper)))
{ {
if (!Operator(m_operators.size()-1)) { if (!Operator(m_operators.size()-1)) {
throw exception::eval_error("Incomplete prefix '" + oper + "' expression", File_Position(m_position.line, m_position.col), *m_filename); throw exception::eval_error("Incomplete prefix '" + std::string(oper) + "' expression", File_Position(m_position.line, m_position.col), *m_filename);
} }
build_match<eval::Prefix_AST_Node<Tracer>>(prev_stack_top, oper); build_match<eval::Prefix_AST_Node<Tracer>>(prev_stack_top, oper);
@@ -2213,7 +2214,7 @@ namespace chaiscript
bool retval = false; bool retval = false;
const auto prev_stack_top = m_match_stack.size(); const auto prev_stack_top = m_match_stack.size();
if (t_precedence < m_operators.size()) { if (m_operators[t_precedence] != Operator_Precidence::Prefix) {
if (Operator(t_precedence+1)) { if (Operator(t_precedence+1)) {
retval = true; retval = true;
std::string oper; std::string oper;
@@ -2256,14 +2257,16 @@ namespace chaiscript
case(Operator_Precidence::Logical_Or) : case(Operator_Precidence::Logical_Or) :
build_match<eval::Logical_Or_AST_Node<Tracer>>(prev_stack_top, oper); build_match<eval::Logical_Or_AST_Node<Tracer>>(prev_stack_top, oper);
break; break;
case(Operator_Precidence::Prefix) :
assert(false); // cannot reach here because of if() statement at the top
break;
// default: // default:
// throw exception::eval_error("Internal error: unhandled ast_node", File_Position(m_position.line, m_position.col), *m_filename); // throw exception::eval_error("Internal error: unhandled ast_node", File_Position(m_position.line, m_position.col), *m_filename);
} }
} }
} }
} } else {
else {
return Value(); return Value();
} }

View File

@@ -2,7 +2,7 @@ Notes:
======= =======
Current Version: 6.0.0 Current Version: 6.0.0
### Changes since 5.8.3 ### Changes since 5.8.5
*6.0.0 is a massive rework compared to 5.x. It now requires a C++14 enabled compiler* *6.0.0 is a massive rework compared to 5.x. It now requires a C++14 enabled compiler*
@@ -38,6 +38,10 @@ Current Version: 6.0.0
* File location tracking has been rewritten; this currently means error location reporting is not as good as it was * File location tracking has been rewritten; this currently means error location reporting is not as good as it was
* Tracing capability needs to be tested and vetted * Tracing capability needs to be tested and vetted
### Changes since 5.8.4
* Fix order of operations for prefix operators
* Make sure atomics are initialized properly
### Changes since 5.8.3 ### Changes since 5.8.3
* Fix case with some numeric conversions mixed with numerics that do not need conversion * Fix case with some numeric conversions mixed with numerics that do not need conversion

View File

@@ -960,7 +960,7 @@ bool FindBitmap(int &ox, int &oy, long) {
TEST_CASE("Mismatched numeric types only convert necessary params") TEST_CASE("Mismatched numeric types only convert necessary params")
{ {
chaiscript::ChaiScript chai; chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(),create_chaiscript_parser());
chai.add(chaiscript::fun(&FindBitmap), "FindBitmap"); chai.add(chaiscript::fun(&FindBitmap), "FindBitmap");
int x = 0; int x = 0;
@@ -973,3 +973,13 @@ TEST_CASE("Mismatched numeric types only convert necessary params")
} }
TEST_CASE("type_conversion to bool")
{
auto module = std::make_shared<chaiscript::Module>();
struct T {
operator bool() const { return true; }
};
module->add(chaiscript::type_conversion<T, bool>());
}

View File

@@ -16,7 +16,7 @@ int expected_value(int num_iters)
return i; return i;
} }
void do_work(chaiscript::ChaiScript &c, const size_t id) void do_work(chaiscript::ChaiScript_Basic &c, const size_t id)
{ {
try{ try{
std::stringstream ss; std::stringstream ss;

View File

@@ -0,0 +1,4 @@
var i = 2;
assert_equal(++i * i, 9)