Eliminate branching in var decl
This commit is contained in:
parent
f3f84594ee
commit
cf2fa09d6c
@ -295,9 +295,8 @@ namespace chaiscript
|
||||
try {
|
||||
|
||||
if (lhs.is_undef()) {
|
||||
if (!this->children.empty() &&
|
||||
!this->children[0]->children.empty()
|
||||
&& this->children[0]->children[0]->identifier == AST_Node_Type::Reference)
|
||||
if (!this->children.empty()
|
||||
&& this->children[0]->identifier == AST_Node_Type::Reference)
|
||||
{
|
||||
/// \todo This does not handle the case of an unassigned reference variable
|
||||
/// being assigned outside of its declaration
|
||||
@ -379,10 +378,6 @@ namespace chaiscript
|
||||
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 {
|
||||
if (this->children[0]->identifier == AST_Node_Type::Reference)
|
||||
{
|
||||
return this->children[0]->eval(t_ss);
|
||||
} else {
|
||||
const std::string &idname = this->children[0]->text;
|
||||
|
||||
try {
|
||||
@ -396,10 +391,6 @@ namespace chaiscript
|
||||
throw exception::eval_error("Variable redefined '" + e.name() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -1983,11 +1983,14 @@ namespace chaiscript
|
||||
} else if (Keyword("auto") || Keyword("var") ) {
|
||||
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);
|
||||
}
|
||||
|
||||
build_match<eval::Var_Decl_AST_Node>(prev_stack_top);
|
||||
} else if (Keyword("GLOBAL") || Keyword("global")) {
|
||||
retval = true;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user