Allow for parse time evaluation of const values.

The goal is to allow for more evaluation at parse time, in general, to
increase eval time performance.

 - Make AST_Node non-constructable except by derived classes.
 - Make data in AST_Node const (as much as possible).
 - Replace reflection "text = " with replace_child() (where the
   replacement must be with a new parse tree).
 - Evaluate floats, strings, ints, chars at parse time to avoid repeat
   evaluations (~10% speed up in loops in -O3)
This commit is contained in:
Jason Turner
2011-03-27 08:17:04 -06:00
parent bbe89e61bc
commit d6b8e32373
5 changed files with 84 additions and 51 deletions

View File

@@ -1312,7 +1312,12 @@ namespace chaiscript
has_matches = false;
if (Keyword("else", true)) {
if (Keyword("if")) {
m_match_stack.back()->text = "else if";
AST_NodePtr back(m_match_stack.back());
m_match_stack.back() = AST_NodePtr(new eval::If_AST_Node("else if", back->identifier));
m_match_stack.back()->start = back->start;
m_match_stack.back()->end = back->end;
m_match_stack.back()->children = back->children;
m_match_stack.back()->annotation = back->annotation;
if (!Char('(')) {
throw exception::eval_error("Incomplete 'else if' expression", File_Position(m_line, m_col), *m_filename);
}