Merge branch 'smaller_make_shared' into develop

This commit is contained in:
Jason Turner
2015-04-29 16:58:34 -06:00
25 changed files with 198 additions and 220 deletions

View File

@@ -9,8 +9,6 @@
#include <string>
#include "../dispatchkit/dispatchkit.hpp"
namespace chaiscript
{

View File

@@ -26,6 +26,7 @@ struct AST_Node;
namespace chaiscript
{
/// Signature of module entry point that all binary loadable modules must implement.
typedef ModulePtr (*Create_Module_Func)();
@@ -77,7 +78,7 @@ namespace chaiscript
{
/// Errors generated during parsing or evaluation
struct eval_error : public std::runtime_error {
struct eval_error : std::runtime_error {
std::string reason;
File_Position start_position;
File_Position end_position;
@@ -391,7 +392,7 @@ namespace chaiscript
/// Errors generated when loading a file
struct file_not_found_error : public std::runtime_error {
struct file_not_found_error : std::runtime_error {
file_not_found_error(const std::string &t_filename) CHAISCRIPT_NOEXCEPT
: std::runtime_error("File Not Found: " + t_filename)
{ }
@@ -465,6 +466,8 @@ namespace chaiscript
std::replace(children.begin(), children.end(), t_child, t_new_child);
}
virtual ~AST_Node() {}
protected:
AST_Node(std::string t_ast_node_text, int t_id, const std::shared_ptr<const std::string> &t_fname,
int t_start_line, int t_start_col, int t_end_line, int t_end_col) :
@@ -476,7 +479,6 @@ namespace chaiscript
AST_Node(std::string t_ast_node_text, int t_id, const std::shared_ptr<const std::string> &t_fname) :
identifier(t_id), text(std::move(t_ast_node_text)), filename(t_fname) {}
virtual ~AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &) const
{

View File

@@ -8,8 +8,6 @@
#define CHAISCRIPT_ENGINE_HPP_
#include <cassert>
#include <cstring>
#include <algorithm>
#include <exception>
#include <fstream>
#include <functional>
@@ -18,7 +16,6 @@
#include <mutex>
#include <set>
#include <stdexcept>
#include <string>
#include <vector>
#include "../chaiscript_defines.hpp"
@@ -363,10 +360,10 @@ namespace chaiscript
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::function_exists, std::ref(m_engine)), "function_exists");
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_function_objects, std::ref(m_engine)), "get_functions");
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_scripting_objects, std::ref(m_engine)), "get_objects");
m_engine.add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(
m_engine.add(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Dynamic_Proxy_Function>(
[this](const std::vector<Boxed_Value> &t_params) {
return m_engine.call_exists(t_params);
})), "call_exists");
}), "call_exists");
// m_engine.add(fun<Boxed_Value (const dispatch::Proxy_Function_Base *, const std::vector<Boxed_Value> &)>(std::bind(&chaiscript::dispatch::Proxy_Function_Base::operator(), std::placeholders::_1, std::placeholders::_2, std::ref(m_engine.conversions()))), "call");
//

View File

@@ -7,8 +7,6 @@
#ifndef CHAISCRIPT_EVAL_HPP_
#define CHAISCRIPT_EVAL_HPP_
#include <assert.h>
#include <cstdlib>
#include <exception>
#include <functional>
#include <limits>
@@ -21,7 +19,6 @@
#include "../chaiscript_defines.hpp"
#include "../dispatchkit/boxed_cast.hpp"
#include "../dispatchkit/boxed_cast_helper.hpp"
#include "../dispatchkit/boxed_number.hpp"
#include "../dispatchkit/boxed_value.hpp"
#include "../dispatchkit/dispatchkit.hpp"
@@ -803,12 +800,12 @@ namespace chaiscript
const auto &lambda_node = this->children.back();
return Boxed_Value(Proxy_Function(new dispatch::Dynamic_Proxy_Function(
return Boxed_Value(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Dynamic_Proxy_Function>(
[&t_ss, lambda_node, param_names, captures](const std::vector<Boxed_Value> &t_params)
{
return detail::eval_function(t_ss, lambda_node, param_names, t_params, captures);
},
static_cast<int>(numparams), lambda_node, param_types)));
static_cast<int>(numparams), lambda_node, param_types));
}
@@ -864,23 +861,23 @@ namespace chaiscript
std::shared_ptr<dispatch::Dynamic_Proxy_Function> guard;
if (guardnode) {
guard = std::shared_ptr<dispatch::Dynamic_Proxy_Function>
(new dispatch::Dynamic_Proxy_Function([&t_ss, guardnode, t_param_names](const std::vector<Boxed_Value> &t_params)
guard = std::make_shared<dispatch::Dynamic_Proxy_Function>
([&t_ss, guardnode, t_param_names](const std::vector<Boxed_Value> &t_params)
{
return detail::eval_function(t_ss, guardnode, t_param_names, t_params);
}, static_cast<int>(numparams), guardnode));
}, static_cast<int>(numparams), guardnode);
}
try {
const std::string & l_function_name = this->children[0]->text;
const std::string & l_annotation = this->annotation?this->annotation->text:"";
const auto & func_node = this->children.back();
t_ss.add(Proxy_Function
(new dispatch::Dynamic_Proxy_Function([&t_ss, guardnode, func_node, t_param_names](const std::vector<Boxed_Value> &t_params)
t_ss.add(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Dynamic_Proxy_Function>
([&t_ss, guardnode, func_node, t_param_names](const std::vector<Boxed_Value> &t_params)
{
return detail::eval_function(t_ss, func_node, t_param_names, t_params);
}, static_cast<int>(numparams), this->children.back(),
param_types, l_annotation, guard)), l_function_name);
param_types, l_annotation, guard), l_function_name);
}
catch (const exception::reserved_word_error &e) {
throw exception::eval_error("Reserved word used as function name '" + e.word() + "'");

View File

@@ -10,7 +10,6 @@
#include <cstdint>
#include <cstring>
#include <exception>
#include <fstream>
#include <iostream>
#include <memory>
#include <sstream>
@@ -229,7 +228,7 @@ namespace chaiscript
for (const auto &count : counts) {
// std::cout << " Fun Call Count: " << count.first << " " << count.second << '\n';
if (count.second > 1) {
children_to_add.push_back(std::make_shared<eval::Fun_Lookup_AST_Node>(count.first));
children_to_add.push_back(chaiscript::make_shared<AST_Node, eval::Fun_Lookup_AST_Node>(count.first));
}
}
c->children.back()->children.insert(c->children.back()->children.begin(), children_to_add.begin(), children_to_add.end());
@@ -277,7 +276,7 @@ namespace chaiscript
for (auto &c : p->children)
{
if (c->identifier == AST_Node_Type::Fun_Call && c->children.size() == 2 && c->children[1]->children.size() == 1) {
c = std::make_shared<eval::Unary_Fun_Call_AST_Node>(dynamic_cast<eval::Fun_Call_AST_Node &>(*c));
c = chaiscript::make_shared<AST_Node, eval::Unary_Fun_Call_AST_Node>(dynamic_cast<eval::Fun_Call_AST_Node &>(*c));
// std::cout << "optimized unary fun call\n";
}
optimize_fun_calls(c);
@@ -728,7 +727,7 @@ namespace chaiscript
if (has_more_input() && char_in_alphabet(*m_input_pos, detail::float_alphabet) ) {
if (Hex_()) {
std::string match(start, m_input_pos);
m_match_stack.emplace_back(std::make_shared<eval::Int_AST_Node>(std::move(match), buildInt(std::hex, match), m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.emplace_back(chaiscript::make_shared<AST_Node, eval::Int_AST_Node>(std::move(match), buildInt(std::hex, match), m_filename, prev_line, prev_col, m_line, m_col));
return true;
}
@@ -754,22 +753,22 @@ namespace chaiscript
i = const_var(temp_int);
}
m_match_stack.push_back(std::make_shared<eval::Int_AST_Node>(std::move(match), std::move(i), m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Int_AST_Node>(std::move(match), std::move(i), m_filename, prev_line, prev_col, m_line, m_col));
return true;
}
if (Float_()) {
std::string match(start, m_input_pos);
m_match_stack.push_back(std::make_shared<eval::Float_AST_Node>(std::move(match), buildFloat(match), m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Float_AST_Node>(std::move(match), buildFloat(match), m_filename, prev_line, prev_col, m_line, m_col));
return true;
}
else {
IntSuffix_();
std::string match(start, m_input_pos);
if (!match.empty() && (match[0] == '0')) {
m_match_stack.push_back(std::make_shared<eval::Int_AST_Node>(std::move(match), buildInt(std::oct, match), m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Int_AST_Node>(std::move(match), buildInt(std::oct, match), m_filename, prev_line, prev_col, m_line, m_col));
}
else {
m_match_stack.push_back(std::make_shared<eval::Int_AST_Node>(std::move(match), buildInt(std::dec, match), m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Int_AST_Node>(std::move(match), buildInt(std::dec, match), m_filename, prev_line, prev_col, m_line, m_col));
}
return true;
}
@@ -827,7 +826,7 @@ namespace chaiscript
const auto prev_col = m_col;
const auto prev_line = m_line;
if (Id_()) {
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>(
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Id_AST_Node>(
[&]()->std::string{
if (*start == '`') {
//Id Literal
@@ -858,7 +857,7 @@ namespace chaiscript
Id();
}
build_match(std::make_shared<eval::Arg_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Arg_AST_Node>(), prev_stack_top);
return true;
}
@@ -885,7 +884,7 @@ namespace chaiscript
} while (Symbol("#"));
std::string match(start, m_input_pos);
m_match_stack.push_back(std::make_shared<eval::Annotation_AST_Node>(std::move(match), m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Annotation_AST_Node>(std::move(match), m_filename, prev_line, prev_col, m_line, m_col));
return true;
}
else {
@@ -951,11 +950,11 @@ namespace chaiscript
if (is_interpolated) {
//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(chaiscript::make_shared<AST_Node, eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
build_match(std::make_shared<eval::Binary_Operator_AST_Node>("+"), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, 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));
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
}
//We've finished with the part of the string up to this point, so clear it
@@ -975,22 +974,22 @@ namespace chaiscript
const auto tostr_stack_top = m_match_stack.size();
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>("to_string", m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Id_AST_Node>("to_string", m_filename, prev_line, prev_col, m_line, m_col));
const auto ev_stack_top = m_match_stack.size();
/// \todo can we evaluate this in place and save the runtime cost of evaluating with each execution of the node?
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>("eval", m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Id_AST_Node>("eval", m_filename, prev_line, prev_col, m_line, m_col));
const auto arg_stack_top = m_match_stack.size();
m_match_stack.push_back(std::make_shared<eval::Quoted_String_AST_Node>(eval_match, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Quoted_String_AST_Node>(eval_match, m_filename, prev_line, prev_col, m_line, m_col));
build_match(std::make_shared<eval::Arg_List_AST_Node>(), arg_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::Fun_Call_AST_Node>(), tostr_stack_top);
build_match(std::make_shared<eval::Binary_Operator_AST_Node>("+"), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), arg_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Inplace_Fun_Call_AST_Node>(), ev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), ev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Fun_Call_AST_Node>(), tostr_stack_top);
build_match(chaiscript::make_shared<AST_Node, 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);
}
@@ -1031,11 +1030,11 @@ 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));
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
build_match(std::make_shared<eval::Binary_Operator_AST_Node>("+"), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, 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));
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
}
return true;
} else {
@@ -1114,7 +1113,7 @@ namespace chaiscript
is_escaped = false;
}
}
m_match_stack.push_back(std::make_shared<eval::Single_Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Single_Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
return true;
}
else {
@@ -1146,7 +1145,7 @@ namespace chaiscript
const auto prev_line = m_line;
if (Char_(t_c)) {
m_match_stack.push_back(
std::make_shared<eval::Char_AST_Node>(std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col));
chaiscript::make_shared<AST_Node, eval::Char_AST_Node>(std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col));
return true;
} else {
return false;
@@ -1190,7 +1189,7 @@ namespace chaiscript
}
if ( t_capture && retval ) {
m_match_stack.push_back(std::make_shared<eval::Str_AST_Node>(
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Str_AST_Node>(
std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col));
}
return retval;
@@ -1233,7 +1232,7 @@ namespace chaiscript
}
if ( t_capture && retval ) {
m_match_stack.push_back(std::make_shared<eval::Str_AST_Node>(
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Str_AST_Node>(
std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col));
}
@@ -1266,7 +1265,7 @@ namespace chaiscript
const auto prev_col = m_col;
const auto prev_line = m_line;
if (Eol_()) {
m_match_stack.push_back(std::make_shared<eval::Eol_AST_Node>(
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Eol_AST_Node>(
std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col));
return true;
} else {
@@ -1294,7 +1293,7 @@ namespace chaiscript
} while (Char(','));
}
}
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
SkipWS(true);
@@ -1320,7 +1319,7 @@ namespace chaiscript
} while (Char(','));
}
}
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
SkipWS(true);
@@ -1348,7 +1347,7 @@ namespace chaiscript
}
}
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
SkipWS(true);
@@ -1364,7 +1363,7 @@ namespace chaiscript
if (Value_Range()) {
retval = true;
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
} else if (Map_Pair()) {
retval = true;
while (Eol()) {}
@@ -1376,7 +1375,7 @@ namespace chaiscript
}
} while (Char(','));
}
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
} else if (Operator()) {
retval = true;
while (Eol()) {}
@@ -1388,7 +1387,7 @@ namespace chaiscript
}
} while (Char(','));
}
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
}
SkipWS(true);
@@ -1412,7 +1411,7 @@ namespace chaiscript
}
} else {
// make sure we always have the same number of nodes
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
}
if (Char('(')) {
@@ -1431,7 +1430,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete anonymous function", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Lambda_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Lambda_AST_Node>(), prev_stack_top);
}
return retval;
@@ -1489,9 +1488,9 @@ namespace chaiscript
}
if (is_method || t_class_context) {
build_match(std::make_shared<eval::Method_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Method_AST_Node>(), prev_stack_top);
} else {
build_match(std::make_shared<eval::Def_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Def_AST_Node>(), prev_stack_top);
}
if (annotation) {
@@ -1539,7 +1538,7 @@ namespace chaiscript
if (!Block()) {
throw exception::eval_error("Incomplete 'catch' block", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Catch_AST_Node>(), catch_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Catch_AST_Node>(), catch_stack_top);
has_matches = true;
}
}
@@ -1552,10 +1551,10 @@ namespace chaiscript
if (!Block()) {
throw exception::eval_error("Incomplete 'finally' block", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Finally_AST_Node>(), finally_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Finally_AST_Node>(), finally_stack_top);
}
build_match(std::make_shared<eval::Try_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Try_AST_Node>(), prev_stack_top);
}
return retval;
@@ -1591,7 +1590,7 @@ namespace chaiscript
if (Keyword("else", true)) {
if (Keyword("if")) {
const AST_NodePtr back(m_match_stack.back());
m_match_stack.back() = std::make_shared<eval::If_AST_Node>("else if");
m_match_stack.back() = chaiscript::make_shared<AST_Node, eval::If_AST_Node>("else if");
m_match_stack.back()->start = back->start;
m_match_stack.back()->end = back->end;
m_match_stack.back()->children = back->children;
@@ -1621,7 +1620,7 @@ namespace chaiscript
}
}
build_match(std::make_shared<eval::If_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::If_AST_Node>(), prev_stack_top);
}
return retval;
@@ -1647,7 +1646,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete 'class' block", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Class_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Class_AST_Node>(), prev_stack_top);
}
return retval;
@@ -1677,7 +1676,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete 'while' block", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::While_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::While_AST_Node>(), prev_stack_top);
}
return retval;
@@ -1692,7 +1691,7 @@ namespace chaiscript
{
throw exception::eval_error("'for' loop initial statment missing", File_Position(m_line, m_col), *m_filename);
} else {
m_match_stack.push_back(std::make_shared<eval::Noop_AST_Node>());
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Noop_AST_Node>());
}
}
@@ -1702,13 +1701,13 @@ namespace chaiscript
{
throw exception::eval_error("'for' loop condition missing", File_Position(m_line, m_col), *m_filename);
} else {
m_match_stack.push_back(std::make_shared<eval::Noop_AST_Node>());
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Noop_AST_Node>());
}
}
if (!Equation())
{
m_match_stack.push_back(std::make_shared<eval::Noop_AST_Node>());
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Noop_AST_Node>());
}
return true;
@@ -1739,7 +1738,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete 'for' block", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::For_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::For_AST_Node>(), prev_stack_top);
}
return retval;
@@ -1768,7 +1767,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete 'case' block", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Case_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Case_AST_Node>(), prev_stack_top);
} else if (Keyword("default")) {
while (Eol()) {}
@@ -1776,7 +1775,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete 'default' block", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Default_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Default_AST_Node>(), prev_stack_top);
}
return retval;
@@ -1816,7 +1815,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete block", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Switch_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Switch_AST_Node>(), prev_stack_top);
return true;
} else {
@@ -1841,10 +1840,10 @@ namespace chaiscript
}
if (m_match_stack.size() == prev_stack_top) {
m_match_stack.push_back(std::make_shared<eval::Noop_AST_Node>());
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Noop_AST_Node>());
}
build_match(std::make_shared<eval::Block_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Block_AST_Node>(), prev_stack_top);
}
return retval;
@@ -1865,10 +1864,10 @@ namespace chaiscript
}
if (m_match_stack.size() == prev_stack_top) {
m_match_stack.push_back(std::make_shared<eval::Noop_AST_Node>());
m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Noop_AST_Node>());
}
build_match(std::make_shared<eval::Block_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Block_AST_Node>(), prev_stack_top);
}
return retval;
@@ -1880,7 +1879,7 @@ namespace chaiscript
if (Keyword("return")) {
Operator();
build_match(std::make_shared<eval::Return_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Return_AST_Node>(), prev_stack_top);
return true;
} else {
return false;
@@ -1892,7 +1891,7 @@ namespace chaiscript
const auto prev_stack_top = m_match_stack.size();
if (Keyword("break")) {
build_match(std::make_shared<eval::Break_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Break_AST_Node>(), prev_stack_top);
return true;
} else {
return false;
@@ -1904,7 +1903,7 @@ namespace chaiscript
const auto prev_stack_top = m_match_stack.size();
if (Keyword("continue")) {
build_match(std::make_shared<eval::Continue_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Continue_AST_Node>(), prev_stack_top);
return true;
} else {
return false;
@@ -1933,7 +1932,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete function call", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Fun_Call_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Fun_Call_AST_Node>(), prev_stack_top);
/// \todo Work around for method calls until we have a better solution
if (!m_match_stack.back()->children.empty()) {
if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Dot_Access) {
@@ -1954,7 +1953,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete array access", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Array_Call_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Array_Call_AST_Node>(), prev_stack_top);
}
else if (Symbol(".", true)) {
has_more = true;
@@ -1962,7 +1961,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete array access", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Dot_Access_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Dot_Access_AST_Node>(), prev_stack_top);
}
}
}
@@ -1983,7 +1982,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Attr_Decl_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Attr_Decl_AST_Node>(), prev_stack_top);
} else if (Keyword("auto") || Keyword("var")) {
retval = true;
@@ -1991,7 +1990,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Var_Decl_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Var_Decl_AST_Node>(), prev_stack_top);
} else if (Keyword("attr")) {
retval = true;
@@ -2006,7 +2005,7 @@ namespace chaiscript
}
build_match(std::make_shared<eval::Attr_Decl_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Attr_Decl_AST_Node>(), prev_stack_top);
}
return retval;
@@ -2039,17 +2038,17 @@ namespace chaiscript
}
if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) {
if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) {
build_match(std::make_shared<eval::Inline_Range_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Inline_Range_AST_Node>(), prev_stack_top);
}
else if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Map_Pair) {
build_match(std::make_shared<eval::Inline_Map_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Inline_Map_AST_Node>(), prev_stack_top);
}
else {
build_match(std::make_shared<eval::Inline_Array_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Inline_Array_AST_Node>(), prev_stack_top);
}
}
else {
build_match(std::make_shared<eval::Inline_Array_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Inline_Array_AST_Node>(), prev_stack_top);
}
return true;
@@ -2067,7 +2066,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete '&' expression", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Reference_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Reference_AST_Node>(), prev_stack_top);
return true;
} else {
return false;
@@ -2088,7 +2087,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete prefix '" + oper + "' 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);
build_match(chaiscript::make_shared<AST_Node, eval::Prefix_AST_Node>(Operators::to_operator(oper, true)), prev_stack_top);
return true;
}
}
@@ -2138,7 +2137,7 @@ namespace chaiscript
+ std::string(ast_node_type_to_string(m_operators[t_precedence])) + " expression",
File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Ternary_Cond_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Ternary_Cond_AST_Node>(), prev_stack_top);
}
else {
throw exception::eval_error("Incomplete "
@@ -2157,14 +2156,14 @@ namespace chaiscript
case(AST_Node_Type::Comparison) :
assert(m_match_stack.size() > 1);
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);
build_match(chaiscript::make_shared<AST_Node, 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);
build_match(chaiscript::make_shared<AST_Node, 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);
build_match(chaiscript::make_shared<AST_Node, eval::Logical_Or_AST_Node>(), prev_stack_top);
break;
default:
@@ -2196,7 +2195,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete map pair", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Map_Pair_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Map_Pair_AST_Node>(), prev_stack_top);
}
else {
m_input_pos = prev_pos;
@@ -2225,7 +2224,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete value range", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Value_Range_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Value_Range_AST_Node>(), prev_stack_top);
}
else {
m_input_pos = prev_pos;
@@ -2256,7 +2255,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete equation", File_Position(m_line, m_col), *m_filename);
}
build_match(std::make_shared<eval::Equation_AST_Node>(), prev_stack_top);
build_match(chaiscript::make_shared<AST_Node, eval::Equation_AST_Node>(), prev_stack_top);
}
}
@@ -2350,7 +2349,7 @@ namespace chaiscript
if (m_input_pos != m_input_end) {
throw exception::eval_error("Unparsed input", File_Position(m_line, m_col), t_fname);
} else {
build_match(std::make_shared<eval::File_AST_Node>(), 0);
build_match(chaiscript::make_shared<AST_Node, eval::File_AST_Node>(), 0);
return true;
}
} else {