Eliminate branching in var decl
This commit is contained in:
parent
f3f84594ee
commit
cf2fa09d6c
@ -295,9 +295,8 @@ namespace chaiscript
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
if (lhs.is_undef()) {
|
if (lhs.is_undef()) {
|
||||||
if (!this->children.empty() &&
|
if (!this->children.empty()
|
||||||
!this->children[0]->children.empty()
|
&& this->children[0]->identifier == AST_Node_Type::Reference)
|
||||||
&& this->children[0]->children[0]->identifier == AST_Node_Type::Reference)
|
|
||||||
{
|
{
|
||||||
/// \todo This does not handle the case of an unassigned reference variable
|
/// \todo This does not handle the case of an unassigned reference variable
|
||||||
/// being assigned outside of its declaration
|
/// being assigned outside of its declaration
|
||||||
@ -379,27 +378,19 @@ namespace chaiscript
|
|||||||
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Var_Decl, std::move(t_loc), std::move(t_children)) { }
|
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Var_Decl, 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 {
|
||||||
if (this->children[0]->identifier == AST_Node_Type::Reference)
|
const std::string &idname = this->children[0]->text;
|
||||||
{
|
|
||||||
return this->children[0]->eval(t_ss);
|
|
||||||
} else {
|
|
||||||
const std::string &idname = this->children[0]->text;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Boxed_Value bv;
|
Boxed_Value bv;
|
||||||
t_ss.add_object(idname, bv);
|
t_ss.add_object(idname, bv);
|
||||||
return bv;
|
return bv;
|
||||||
}
|
}
|
||||||
catch (const exception::reserved_word_error &) {
|
catch (const exception::reserved_word_error &) {
|
||||||
throw exception::eval_error("Reserved word used as variable '" + idname + "'");
|
throw exception::eval_error("Reserved word used as variable '" + idname + "'");
|
||||||
} catch (const exception::name_conflict_error &e) {
|
} catch (const exception::name_conflict_error &e) {
|
||||||
throw exception::eval_error("Variable redefined '" + e.name() + "'");
|
throw exception::eval_error("Variable redefined '" + e.name() + "'");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1983,11 +1983,14 @@ namespace chaiscript
|
|||||||
} else if (Keyword("auto") || Keyword("var") ) {
|
} else if (Keyword("auto") || Keyword("var") ) {
|
||||||
retval = true;
|
retval = true;
|
||||||
|
|
||||||
if (!(Reference() || Id())) {
|
if (Reference()) {
|
||||||
|
// we built a reference node - continue
|
||||||
|
} else if (Id()) {
|
||||||
|
build_match<eval::Var_Decl_AST_Node>(prev_stack_top);
|
||||||
|
} else {
|
||||||
throw exception::eval_error("Incomplete variable declaration", File_Position(m_position.line, m_position.col), *m_filename);
|
throw exception::eval_error("Incomplete variable declaration", File_Position(m_position.line, m_position.col), *m_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
build_match<eval::Var_Decl_AST_Node>(prev_stack_top);
|
|
||||||
} else if (Keyword("GLOBAL") || Keyword("global")) {
|
} else if (Keyword("GLOBAL") || Keyword("global")) {
|
||||||
retval = true;
|
retval = true;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user