Merge remote-tracking branch 'origin/develop' into performance_test

This commit is contained in:
Jason Turner
2014-11-17 14:17:28 -07:00
3 changed files with 46 additions and 307 deletions

View File

@@ -787,7 +787,7 @@ namespace chaiscript
//If we've seen previous interpolation, add on instead of making a new one
m_match_stack.push_back(std::make_shared<eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
build_match(std::make_shared<eval::Addition_AST_Node>(), prev_stack_top);
build_match(std::make_shared<eval::Binary_Operator_AST_Node>("+"), prev_stack_top);
} else {
m_match_stack.push_back(std::make_shared<eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
}
@@ -824,7 +824,7 @@ namespace chaiscript
build_match(std::make_shared<eval::Inplace_Fun_Call_AST_Node>(), ev_stack_top);
build_match(std::make_shared<eval::Arg_List_AST_Node>(), ev_stack_top);
build_match(std::make_shared<eval::Fun_Call_AST_Node>(), tostr_stack_top);
build_match(std::make_shared<eval::Addition_AST_Node>(), prev_stack_top);
build_match(std::make_shared<eval::Binary_Operator_AST_Node>("+"), prev_stack_top);
} else {
throw exception::eval_error("Unclosed in-string eval", File_Position(prev_line, prev_col), *m_filename);
}
@@ -867,7 +867,7 @@ namespace chaiscript
if (is_interpolated) {
m_match_stack.push_back(std::make_shared<eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
build_match(std::make_shared<eval::Addition_AST_Node>(), prev_stack_top);
build_match(std::make_shared<eval::Binary_Operator_AST_Node>("+"), prev_stack_top);
} else {
m_match_stack.push_back(std::make_shared<eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
}
@@ -1835,72 +1835,24 @@ namespace chaiscript
/// Reads a unary prefixed expression from input
bool Prefix() {
bool retval = false;
const auto prev_stack_top = m_match_stack.size();
const std::vector<std::string> prefix_opers{"++", "--", "-", "+", "!", "~", "&"};
if (Symbol("++", true)) {
retval = true;
for (const auto &oper : prefix_opers)
{
bool is_char = oper.size() == 1;
if ((is_char && Char(oper[0], true)) || (!is_char && Symbol(oper.c_str(), true)))
{
if (!Operator(m_operators.size()-1)) {
throw exception::eval_error("Incomplete prefix '" + oper + "' expression", File_Position(m_line, m_col), *m_filename);
}
if (!Operator(m_operators.size()-1)) {
throw exception::eval_error("Incomplete '++' expression", File_Position(m_line, m_col), *m_filename);
build_match(std::make_shared<eval::Prefix_AST_Node>(Operators::to_operator(oper, true)), prev_stack_top);
return true;
}
build_match(std::make_shared<eval::Prefix_AST_Node>(), prev_stack_top);
} else if (Symbol("--", true)) {
retval = true;
if (!Operator(m_operators.size()-1)) {
throw exception::eval_error("Incomplete '--' expression", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Prefix_AST_Node>(), prev_stack_top);
} else if (Char('-', true)) {
retval = true;
if (!Operator(m_operators.size()-1)) {
throw exception::eval_error("Incomplete unary '-' expression", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Prefix_AST_Node>(), prev_stack_top);
} else if (Char('+', true)) {
retval = true;
if (!Operator(m_operators.size()-1)) {
throw exception::eval_error("Incomplete unary '+' expression", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Prefix_AST_Node>(), prev_stack_top);
}
else if (Char('!', true)) {
retval = true;
if (!Operator(m_operators.size()-1)) {
throw exception::eval_error("Incomplete '!' expression", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Prefix_AST_Node>(), prev_stack_top);
}
else if (Char('~', true)) {
retval = true;
if (!Operator(m_operators.size()-1)) {
throw exception::eval_error("Incomplete '~' expression", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Prefix_AST_Node>(), prev_stack_top);
}
else if (Char('&', true)) {
retval = true;
if (!Operator(m_operators.size()-1)) {
throw exception::eval_error("Incomplete '~' expression", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Prefix_AST_Node>(), prev_stack_top);
}
return retval;
return false;
}
/// Parses any of a group of 'value' style ast_node groups from input
@@ -1923,7 +1875,6 @@ namespace chaiscript
bool Operator(const size_t t_precedence = 0) {
bool retval = false;
AST_NodePtr oper;
const auto prev_stack_top = m_match_stack.size();
if (t_precedence < m_operators.size()) {
@@ -1938,10 +1889,9 @@ namespace chaiscript
File_Position(m_line, m_col), *m_filename);
}
AST_NodePtr oper = m_match_stack.at(m_match_stack.size()-2);
switch (m_operators[t_precedence]) {
case(AST_Node_Type::Comparison) :
build_match(std::make_shared<eval::Comparison_AST_Node>(), prev_stack_top);
break;
case(AST_Node_Type::Ternary_Cond) :
m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2,
m_match_stack.begin() + m_match_stack.size() - 1);
@@ -1959,52 +1909,26 @@ namespace chaiscript
File_Position(m_line, m_col), *m_filename);
}
break;
case(AST_Node_Type::Addition) :
oper = m_match_stack.at(m_match_stack.size()-2);
m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2,
m_match_stack.begin() + m_match_stack.size() - 1);
if (oper->text == "+") {
build_match(std::make_shared<eval::Addition_AST_Node>(), prev_stack_top);
}
else if (oper->text == "-") {
build_match(std::make_shared<eval::Subtraction_AST_Node>(), prev_stack_top);
}
break;
case(AST_Node_Type::Multiplication) :
oper = m_match_stack.at(m_match_stack.size()-2);
m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2,
m_match_stack.begin() + m_match_stack.size() - 1);
if (oper->text == "*") {
build_match(std::make_shared<eval::Multiplication_AST_Node>(), prev_stack_top);
}
else if (oper->text == "/") {
build_match(std::make_shared<eval::Division_AST_Node>(), prev_stack_top);
}
else if (oper->text == "%") {
build_match(std::make_shared<eval::Modulus_AST_Node>(), prev_stack_top);
}
break;
case(AST_Node_Type::Shift) :
build_match(std::make_shared<eval::Shift_AST_Node>(), prev_stack_top);
break;
case(AST_Node_Type::Equality) :
build_match(std::make_shared<eval::Equality_AST_Node>(), prev_stack_top);
break;
case(AST_Node_Type::Bitwise_And) :
build_match(std::make_shared<eval::Bitwise_And_AST_Node>(), prev_stack_top);
break;
case(AST_Node_Type::Bitwise_Xor) :
build_match(std::make_shared<eval::Bitwise_Xor_AST_Node>(), prev_stack_top);
break;
case(AST_Node_Type::Bitwise_Or) :
build_match(std::make_shared<eval::Bitwise_Or_AST_Node>(), prev_stack_top);
case(AST_Node_Type::Comparison) :
m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2, m_match_stack.begin() + m_match_stack.size() - 1);
build_match(std::make_shared<eval::Binary_Operator_AST_Node>(oper->text), prev_stack_top);
break;
case(AST_Node_Type::Logical_And) :
build_match(std::make_shared<eval::Logical_And_AST_Node>(), prev_stack_top);
break;
case(AST_Node_Type::Logical_Or) :
build_match(std::make_shared<eval::Logical_Or_AST_Node>(), prev_stack_top);
break;
default:
throw exception::eval_error("Internal error: unhandled ast_node", File_Position(m_line, m_col), *m_filename);
}
@@ -2111,14 +2035,7 @@ namespace chaiscript
while (has_more) {
const auto prev_line = m_line;
const auto prev_col = m_col;
if (Def(true)) {
if (!saw_eol) {
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
saw_eol = true;
} else if (Var_Decl(true)) {
if (Def(true) || Var_Decl(true)) {
if (!saw_eol) {
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
@@ -2147,7 +2064,7 @@ namespace chaiscript
while (has_more) {
int prev_line = m_line;
int prev_col = m_col;
if (Def()) {
if (Def() || Try() || If() || While() || Class() || For() || Switch()) {
if (!saw_eol) {
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
@@ -2155,55 +2072,7 @@ namespace chaiscript
retval = true;
saw_eol = true;
}
else if (Try()) {
if (!saw_eol) {
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
saw_eol = true;
}
else if (If()) {
if (!saw_eol) {
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
saw_eol = true;
}
else if (While()) {
if (!saw_eol) {
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
saw_eol = true;
}
else if (Class()) {
if (!saw_eol) {
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
saw_eol = true;
}
else if (For()) {
if (!saw_eol) {
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
saw_eol = true;
}
else if (Switch()) {
if (!saw_eol) {
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
saw_eol = true;
}
else if (Return()) {
else if (Return() || Break() || Continue() || Equation()) {
if (!saw_eol) {
throw exception::eval_error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
@@ -2211,36 +2080,7 @@ namespace chaiscript
retval = true;
saw_eol = false;
}
else if (Break()) {
if (!saw_eol) {
throw exception::eval_error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
saw_eol = false;
}
else if (Continue()) {
if (!saw_eol) {
throw exception::eval_error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
saw_eol = false;
}
else if (Block()) {
has_more = true;
retval = true;
saw_eol = true;
}
else if (Equation()) {
if (!saw_eol) {
throw exception::eval_error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
saw_eol = false;
}
else if (Eol()) {
else if (Block() || Eol()) {
has_more = true;
retval = true;
saw_eol = true;