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

@@ -37,7 +37,7 @@ namespace chaiscript
Comparison, Addition, Subtraction, Multiplication, Division, Modulus, Array_Call, Dot_Access, Quoted_String, Single_Quoted_String, Comparison, Addition, Subtraction, Multiplication, Division, Modulus, Array_Call, Dot_Access, Quoted_String, Single_Quoted_String,
Lambda, Block, Def, While, If, For, Inline_Array, Inline_Map, Return, File, Prefix, Break, Continue, Map_Pair, Value_Range, Lambda, Block, Def, While, If, For, Inline_Array, Inline_Map, Return, File, Prefix, Break, Continue, Map_Pair, Value_Range,
Inline_Range, Annotation, Try, Catch, Finally, Method, Attr_Decl, Shift, Equality, Bitwise_And, Bitwise_Xor, Bitwise_Or, Inline_Range, Annotation, Try, Catch, Finally, Method, Attr_Decl, Shift, Equality, Bitwise_And, Bitwise_Xor, Bitwise_Or,
Logical_And, Logical_Or, Reference, Switch, Case, Default, Ternary_Cond, Noop, Class Logical_And, Logical_Or, Reference, Switch, Case, Default, Ternary_Cond, Noop, Class, Binary
}; };
}; };
@@ -50,7 +50,7 @@ namespace chaiscript
"Comparison", "Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Array_Call", "Dot_Access", "Quoted_String", "Single_Quoted_String", "Comparison", "Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Array_Call", "Dot_Access", "Quoted_String", "Single_Quoted_String",
"Lambda", "Block", "Def", "While", "If", "For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix", "Break", "Continue", "Map_Pair", "Value_Range", "Lambda", "Block", "Def", "While", "If", "For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix", "Break", "Continue", "Map_Pair", "Value_Range",
"Inline_Range", "Annotation", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or", "Inline_Range", "Annotation", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or",
"Logical_And", "Logical_Or", "Reference", "Switch", "Case", "Default", "Ternary Condition", "Noop"}; "Logical_And", "Logical_Or", "Reference", "Switch", "Case", "Default", "Ternary Condition", "Noop", "Class", "Binary"};
return ast_node_types[ast_node_type]; return ast_node_types[ast_node_type];
} }

View File

@@ -63,25 +63,21 @@ namespace chaiscript
struct Binary_Operator_AST_Node : public AST_Node { struct Binary_Operator_AST_Node : public AST_Node {
public: public:
Binary_Operator_AST_Node(std::string t_ast_node_text, int t_id, const std::shared_ptr<std::string> &t_fname, int t_start_line, int t_start_col, int t_end_line, int t_end_col) : Binary_Operator_AST_Node(const std::string &t_oper) :
AST_Node(std::move(t_ast_node_text), t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) AST_Node(t_oper, AST_Node_Type::Binary, std::make_shared<std::string>(""), 0, 0, 0, 0),
m_oper(Operators::to_operator(t_oper))
{ } { }
virtual ~Binary_Operator_AST_Node() {} virtual ~Binary_Operator_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE { virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE {
return do_oper(t_ss, Operators::to_operator(children[1]->text), children[1]->text, return do_oper(t_ss, m_oper, text,
this->children[0]->eval(t_ss), this->children[0]->eval(t_ss),
this->children[2]->eval(t_ss)); this->children[1]->eval(t_ss));
} }
virtual std::string pretty_print() const CHAISCRIPT_OVERRIDE virtual std::string pretty_print() const CHAISCRIPT_OVERRIDE
{ {
if (children.size() == 3) return "(" + this->children[0]->pretty_print() + " " + text + " " + this->children[1]->pretty_print() + ")";
{
return "(" + this->children[0]->pretty_print() + " " + this->children[1]->text + " " + this->children[2]->pretty_print() + ")";
} else {
return "(" + this->children[0]->pretty_print() + " " + text + " " + this->children[1]->pretty_print() + ")";
}
} }
protected: protected:
@@ -110,6 +106,9 @@ namespace chaiscript
throw exception::eval_error("Can not find appropriate '" + t_oper_string + "' operator.", e.parameters, e.functions, false, t_ss); throw exception::eval_error("Can not find appropriate '" + t_oper_string + "' operator.", e.parameters, e.functions, false, t_ss);
} }
} }
private:
Operators::Opers m_oper;
}; };
struct Int_AST_Node : public AST_Node { struct Int_AST_Node : public AST_Node {
@@ -316,8 +315,6 @@ namespace chaiscript
} }
catch(const exception::bad_boxed_cast &){ catch(const exception::bad_boxed_cast &){
// handle the case where there is only 1 function to try to call and dispatch fails on it // handle the case where there is only 1 function to try to call and dispatch fails on it
std::vector<Const_Proxy_Function> funcs;
funcs.push_back(fn);
throw exception::eval_error("Error calling function '" + this->children[0]->text + "'", params, {fn}, false, t_ss); throw exception::eval_error("Error calling function '" + this->children[0]->text + "'", params, {fn}, false, t_ss);
} }
catch(const exception::arity_error &e){ catch(const exception::arity_error &e){
@@ -455,7 +452,7 @@ namespace chaiscript
{ {
return this->children[0]->eval(t_ss); return this->children[0]->eval(t_ss);
} else { } else {
std::string idname = this->children[0]->text; const std::string &idname = this->children[0]->text;
Boxed_Value bv; Boxed_Value bv;
try { try {
@@ -478,72 +475,6 @@ namespace chaiscript
}; };
struct Comparison_AST_Node : public Binary_Operator_AST_Node {
public:
Comparison_AST_Node(std::string t_ast_node_text = "", const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
Binary_Operator_AST_Node(std::move(t_ast_node_text), AST_Node_Type::Comparison, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Comparison_AST_Node() {}
};
struct Addition_AST_Node : public Binary_Operator_AST_Node {
public:
Addition_AST_Node(std::string t_ast_node_text = "+",
const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(),
int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
Binary_Operator_AST_Node(std::move(t_ast_node_text), AST_Node_Type::Addition, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Addition_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE {
return do_oper(t_ss, Operators::sum, "+", this->children[0]->eval(t_ss), this->children[1]->eval(t_ss));
}
};
struct Subtraction_AST_Node : public Binary_Operator_AST_Node {
public:
Subtraction_AST_Node(std::string t_ast_node_text = "-",
const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(), int t_start_line = 0,
int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
Binary_Operator_AST_Node(std::move(t_ast_node_text), AST_Node_Type::Subtraction, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Subtraction_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE {
return do_oper(t_ss, Operators::difference, "-", this->children[0]->eval(t_ss), this->children[1]->eval(t_ss));
}
};
struct Multiplication_AST_Node : public Binary_Operator_AST_Node {
public:
Multiplication_AST_Node(std::string t_ast_node_text = "*",
const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(), int t_start_line = 0,
int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
Binary_Operator_AST_Node(std::move(t_ast_node_text), AST_Node_Type::Multiplication, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Multiplication_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE {
return do_oper(t_ss, Operators::product, "*", this->children[0]->eval(t_ss), this->children[1]->eval(t_ss));
}
};
struct Division_AST_Node : public Binary_Operator_AST_Node {
public:
Division_AST_Node(std::string t_ast_node_text = "/",
const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(), int t_start_line = 0,
int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
Binary_Operator_AST_Node(std::move(t_ast_node_text), AST_Node_Type::Division, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Division_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE {
return do_oper(t_ss, Operators::quotient, "/", this->children[0]->eval(t_ss), this->children[1]->eval(t_ss));
}
};
struct Modulus_AST_Node : public Binary_Operator_AST_Node {
public:
Modulus_AST_Node(std::string t_ast_node_text = "%",
const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(), int t_start_line = 0,
int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
Binary_Operator_AST_Node(std::move(t_ast_node_text), AST_Node_Type::Modulus, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Modulus_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE {
return do_oper(t_ss, Operators::remainder, "%", this->children[0]->eval(t_ss), this->children[1]->eval(t_ss));
}
};
struct Array_Call_AST_Node : public AST_Node { struct Array_Call_AST_Node : public AST_Node {
public: public:
@@ -1145,8 +1076,9 @@ namespace chaiscript
struct Prefix_AST_Node : public AST_Node { struct Prefix_AST_Node : public AST_Node {
public: public:
Prefix_AST_Node(std::string t_ast_node_text = "", const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Prefix_AST_Node(Operators::Opers t_oper) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Prefix, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) AST_Node("", AST_Node_Type::Prefix, std::make_shared<std::string>(""), 0, 0, 0, 0),
m_oper(t_oper)
{ } { }
virtual ~Prefix_AST_Node() {} virtual ~Prefix_AST_Node() {}
@@ -1154,12 +1086,11 @@ namespace chaiscript
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss); chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
Boxed_Value bv(this->children[1]->eval(t_ss)); Boxed_Value bv(this->children[1]->eval(t_ss));
Operators::Opers oper = Operators::to_operator(children[0]->text, true);
try { try {
// short circuit arithmetic operations // short circuit arithmetic operations
if (bv.get_type_info().is_arithmetic() && oper != Operators::invalid) if (m_oper != Operators::invalid && bv.get_type_info().is_arithmetic())
{ {
return Boxed_Number::do_oper(oper, std::move(bv)); return Boxed_Number::do_oper(m_oper, std::move(bv));
} else { } else {
chaiscript::eval::detail::Stack_Push_Pop spp(t_ss); chaiscript::eval::detail::Stack_Push_Pop spp(t_ss);
fpp.save_params({bv}); fpp.save_params({bv});
@@ -1170,6 +1101,8 @@ namespace chaiscript
} }
} }
private:
Operators::Opers m_oper;
}; };
struct Break_AST_Node : public AST_Node { struct Break_AST_Node : public AST_Node {
@@ -1513,40 +1446,6 @@ namespace chaiscript
}; };
struct Shift_AST_Node : public Binary_Operator_AST_Node {
public:
Shift_AST_Node(const std::string &t_ast_node_text = "", const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
Binary_Operator_AST_Node(t_ast_node_text, AST_Node_Type::Shift, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Shift_AST_Node() {}
};
struct Equality_AST_Node : public Binary_Operator_AST_Node {
public:
Equality_AST_Node(const std::string &t_ast_node_text = "", const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
Binary_Operator_AST_Node(t_ast_node_text, AST_Node_Type::Equality, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Equality_AST_Node() {}
};
struct Bitwise_And_AST_Node : public Binary_Operator_AST_Node {
public:
Bitwise_And_AST_Node(const std::string &t_ast_node_text = "", const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
Binary_Operator_AST_Node(t_ast_node_text, AST_Node_Type::Bitwise_And, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Bitwise_And_AST_Node() {}
};
struct Bitwise_Xor_AST_Node : public Binary_Operator_AST_Node {
public:
Bitwise_Xor_AST_Node(const std::string &t_ast_node_text = "", const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
Binary_Operator_AST_Node(t_ast_node_text, AST_Node_Type::Bitwise_Xor, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Bitwise_Xor_AST_Node() {}
};
struct Bitwise_Or_AST_Node : public Binary_Operator_AST_Node {
public:
Bitwise_Or_AST_Node(const std::string &t_ast_node_text = "", const std::shared_ptr<std::string> &t_fname=std::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
Binary_Operator_AST_Node(t_ast_node_text, AST_Node_Type::Bitwise_Or, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Bitwise_Or_AST_Node() {}
};
struct Logical_And_AST_Node : public AST_Node { struct Logical_And_AST_Node : public AST_Node {
public: public:

View File

@@ -787,7 +787,7 @@ namespace chaiscript
//If we've seen previous interpolation, add on instead of making a new one //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)); 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 { } 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)); 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::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::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::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 { } else {
throw exception::eval_error("Unclosed in-string eval", File_Position(prev_line, prev_col), *m_filename); 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) { 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)); 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 { } 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)); 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 /// Reads a unary prefixed expression from input
bool Prefix() { bool Prefix() {
bool retval = false;
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{"++", "--", "-", "+", "!", "~", "&"};
if (Symbol("++", true)) { for (const auto &oper : prefix_opers)
retval = true; {
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)) { build_match(std::make_shared<eval::Prefix_AST_Node>(Operators::to_operator(oper, true)), prev_stack_top);
throw exception::eval_error("Incomplete '++' expression", File_Position(m_line, m_col), *m_filename); 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 /// 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 Operator(const size_t t_precedence = 0) {
bool retval = false; bool retval = false;
AST_NodePtr oper;
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 (t_precedence < m_operators.size()) {
@@ -1938,10 +1889,9 @@ namespace chaiscript
File_Position(m_line, m_col), *m_filename); 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]) { 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) : case(AST_Node_Type::Ternary_Cond) :
m_match_stack.erase(m_match_stack.begin() + 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); m_match_stack.begin() + m_match_stack.size() - 1);
@@ -1959,52 +1909,26 @@ namespace chaiscript
File_Position(m_line, m_col), *m_filename); File_Position(m_line, m_col), *m_filename);
} }
break; break;
case(AST_Node_Type::Addition) : 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) : 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) : case(AST_Node_Type::Shift) :
build_match(std::make_shared<eval::Shift_AST_Node>(), prev_stack_top);
break;
case(AST_Node_Type::Equality) : case(AST_Node_Type::Equality) :
build_match(std::make_shared<eval::Equality_AST_Node>(), prev_stack_top);
break;
case(AST_Node_Type::Bitwise_And) : 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) : 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) : 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; break;
case(AST_Node_Type::Logical_And) : case(AST_Node_Type::Logical_And) :
build_match(std::make_shared<eval::Logical_And_AST_Node>(), prev_stack_top); build_match(std::make_shared<eval::Logical_And_AST_Node>(), prev_stack_top);
break; break;
case(AST_Node_Type::Logical_Or) : case(AST_Node_Type::Logical_Or) :
build_match(std::make_shared<eval::Logical_Or_AST_Node>(), prev_stack_top); build_match(std::make_shared<eval::Logical_Or_AST_Node>(), prev_stack_top);
break; break;
default: default:
throw exception::eval_error("Internal error: unhandled ast_node", File_Position(m_line, m_col), *m_filename); 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) { while (has_more) {
const auto prev_line = m_line; const auto prev_line = m_line;
const auto prev_col = m_col; const auto prev_col = m_col;
if (Def(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);
}
has_more = true;
retval = true;
saw_eol = true;
} else if (Var_Decl(true)) {
if (!saw_eol) { if (!saw_eol) {
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename); 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) { while (has_more) {
int prev_line = m_line; int prev_line = m_line;
int prev_col = m_col; int prev_col = m_col;
if (Def()) { if (Def() || Try() || If() || While() || Class() || For() || Switch()) {
if (!saw_eol) { if (!saw_eol) {
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename); 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; retval = true;
saw_eol = true; saw_eol = true;
} }
else if (Try()) { else if (Return() || Break() || Continue() || Equation()) {
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()) {
if (!saw_eol) { if (!saw_eol) {
throw exception::eval_error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename); 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; retval = true;
saw_eol = false; saw_eol = false;
} }
else if (Break()) { else if (Block() || Eol()) {
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()) {
has_more = true; has_more = true;
retval = true; retval = true;
saw_eol = true; saw_eol = true;