11#ifndef CHAISCRIPT_BOOTSTRAP_HPP_
12#define CHAISCRIPT_BOOTSTRAP_HPP_
22 template<typename T, typename = typename std::enable_if<std::is_array<T>::value>::type >
25 typedef typename std::remove_extent<T>::type ReturnType;
28 [](
T& t,
size_t index)->ReturnType &{
29 constexpr auto extent = std::extent<T>::value;
30 if (extent > 0 && index >= extent) {
31 throw std::range_error(
"Array index out of range. Received: " + std::to_string(index) +
" expected < " + std::to_string(extent));
40 [](
const T &t,
size_t index)->
const ReturnType &{
41 constexpr auto extent = std::extent<T>::value;
42 if (extent > 0 && index >= extent) {
43 throw std::range_error(
"Array index out of range. Received: " + std::to_string(index) +
" expected < " + std::to_string(extent));
53 constexpr auto extent = std::extent<T>::value;
113 template<
typename Input>
115 ->
typename std::enable_if<
116 !std::is_same<Input, wchar_t>::value
117 && !std::is_same<Input, char16_t>::value
118 && !std::is_same<Input, char32_t>::value,
121 std::stringstream ss(i);
127 template<
typename Input>
129 ->
typename std::enable_if<
130 std::is_same<Input, wchar_t>::value
131 || std::is_same<Input, char16_t>::value
132 || std::is_same<Input, char32_t>::value,
135 throw std::runtime_error(
"Parsing of wide characters is not yet supported");
149 m.
add(
fun([](
const T t){
return t; }),
"to_" +
name);
158 template<
typename Type>
165 template<
typename Type>
166 std::shared_ptr<typename std::remove_const<Type>::type>
shared_ptr_unconst_clone(
const std::shared_ptr<
typename std::add_const<Type>::type> &p)
168 return std::const_pointer_cast<typename std::remove_const<Type>::type>(p);
176 template<
typename Type>
205 static void print(
const std::string &s)
207 fwrite(s.c_str(), 1, s.size(), stdout);
210 static void println(
const std::string &s)
217 static void opers_arithmetic_pod(
Module& m)
256 static Boxed_Value bind_function(
const std::vector<Boxed_Value> ¶ms)
258 if (params.empty()) {
264 if (
f->get_arity() != -1 &&
size_t(
f->get_arity()) != params.size() - 1)
270 std::vector<Boxed_Value>(params.begin() + 1, params.end()))));
276 auto pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf);
277 return pf && pf->get_guard();
282 const auto pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf);
283 if (pf && pf->get_guard())
285 return pf->get_guard();
287 throw std::runtime_error(
"Function does not have a guard");
291 template<
typename FunctionType>
292 static std::vector<Boxed_Value> do_return_boxed_value_vector(FunctionType
f,
297 std::vector<Boxed_Value> vbv;
299 for (
const auto &o: v)
310 const auto pf = std::dynamic_pointer_cast<const chaiscript::dispatch::Dynamic_Proxy_Function>(t_pf);
316 const auto pf = std::dynamic_pointer_cast<const chaiscript::dispatch::Dynamic_Proxy_Function>(t_pf);
319 return pf->get_parse_tree();
321 throw std::runtime_error(
"Function does not have a parse tree");
325 template<
typename Function>
326 static auto return_boxed_value_vector(
const Function &
f)
329 return do_return_boxed_value_vector(
f, b);
349 m.
add(
fun(&dispatch::Proxy_Function_Base::operator==),
"==");
355 m.
add(
fun([](
const std::exception &
e){
return std::string(
e.what()); }),
"what");
366 m.
add(
constructor<std::runtime_error (
const std::string &)>(),
"runtime_error");
387 def Dynamic_Object::clone() {
388 auto &new_o = Dynamic_Object(this.get_type_name());
389 for_each(this.get_attrs(), fun[new_o](x) { new_o.get_attr(x.first) = x.second; } );
393 def `=`(Dynamic_Object lhs, Dynamic_Object rhs) : lhs.get_type_name() == rhs.get_type_name()
395 for_each(rhs.get_attrs(), fun[lhs](x) { lhs.get_attr(x.first) = clone(x.second); } );
398 def `!=`(Dynamic_Object lhs, Dynamic_Object rhs) : lhs.get_type_name() == rhs.get_type_name()
400 var rhs_attrs := rhs.get_attrs();
401 var lhs_attrs := lhs.get_attrs();
403 if (rhs_attrs.size() != lhs_attrs.size()) {
406 return any_of(rhs_attrs, fun[lhs](x) { !lhs.has_attr(x.first) || lhs.get_attr(x.first) != x.second; } );
410 def `==`(Dynamic_Object lhs, Dynamic_Object rhs) : lhs.get_type_name() == rhs.get_type_name()
412 var rhs_attrs := rhs.get_attrs();
413 var lhs_attrs := lhs.get_attrs();
415 if (rhs_attrs.size() != lhs_attrs.size()) {
418 return all_of(rhs_attrs, fun[lhs](x) { lhs.has_attr(x.first) && lhs.get_attr(x.first) == x.second; } );
423 m.add(fun(&has_guard), "has_guard");
424 m.
add(
fun(&get_guard),
"get_guard");
461 m.
add(
fun([](
const std::string &s) {
return s; }),
"to_string");
462 m.
add(
fun([](
const bool b) {
return std::string(b?
"true":
"false"); }),
"to_string");
463 m.
add(
fun(&unknown_assign),
"=");
466 m.
add(
fun([](
const char c) {
return std::string(1, c); }),
"to_string");
496 opers_arithmetic_pod(m);
509 m.
add(
fun(&print),
"print_string");
510 m.
add(
fun(&println),
"println_string");
515 m.
add(
fun(&
ptr_assign<std::remove_const<dispatch::Proxy_Function_Base>::type>),
"=");
516 m.
add(
fun(&
ptr_assign<std::add_const<dispatch::Proxy_Function_Base>::type>),
"=");
542 chaiscript::utility::add_class<chaiscript::exception::eval_error>(m,
548 std::vector<Boxed_Value> retval;
550 std::back_inserter(retval),
557 chaiscript::utility::add_class<chaiscript::File_Position>(m,
566 chaiscript::utility::add_class<AST_Node>(m,
576 std::vector<Boxed_Value> retval;
578 std::transform(children.begin(), children.end(),
579 std::back_inserter(retval),
580 &
chaiscript::var<
const std::reference_wrapper<chaiscript::AST_Node> &>);
Env e
Definition Common.cc:2
bool has_guard() const
Returns true if the function has a guard to it. Always returns false for a conglomerate function.
Function get_guard() const
Returns a function guard as function.
Represents any numeric type, generically. Used internally for generic operations between POD values.
Definition boxed_number.hpp:66
static bool not_equal(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:757
static Boxed_Number assign(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:797
static const Boxed_Number bitwise_complement(const Boxed_Number &t_lhs)
Definition boxed_number.hpp:832
static Boxed_Number assign_bitwise_and(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:792
static const Boxed_Number shift_left(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:871
static Boxed_Number pre_increment(Boxed_Number t_lhs)
Definition boxed_number.hpp:767
static Boxed_Number pre_decrement(Boxed_Number t_lhs)
Definition boxed_number.hpp:762
static Boxed_Number assign_product(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:847
static bool greater_than(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:742
static bool less_than(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:737
static const Boxed_Number bitwise_or(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:842
static const Boxed_Number unary_plus(const Boxed_Number &t_lhs)
Definition boxed_number.hpp:777
static const Boxed_Number quotient(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:866
static const Boxed_Number unary_minus(const Boxed_Number &t_lhs)
Definition boxed_number.hpp:782
static const Boxed_Number sum(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:772
std::string to_string() const
Definition boxed_number.hpp:686
static Boxed_Number assign_shift_left(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:817
static Boxed_Number assign_bitwise_xor(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:807
static Boxed_Number assign_difference(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:861
static const Boxed_Number bitwise_xor(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:837
static const Boxed_Number shift_right(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:886
static Boxed_Number assign_remainder(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:812
static bool greater_than_equal(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:747
static const Boxed_Number bitwise_and(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:827
static const Boxed_Number remainder(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:881
static Boxed_Number assign_sum(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:857
static const Boxed_Number product(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:876
static Boxed_Number assign_bitwise_or(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:802
static Boxed_Number assign_quotient(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:852
static Boxed_Number assign_shift_right(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:822
static bool equals(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:732
static bool less_than_equal(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:752
static const Boxed_Number difference(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
Definition boxed_number.hpp:787
Boxed_Number get_as(const Type_Info &inp_) const
Definition boxed_number.hpp:543
A wrapper for holding any valid C++ type. All types in ChaiScript are Boxed_Value objects.
Definition boxed_value.hpp:28
bool is_ref() const noexcept
Definition boxed_value.hpp:291
bool is_pointer() const noexcept
Definition boxed_value.hpp:306
Boxed_Value & clone_attrs(const Boxed_Value &t_obj)
Definition boxed_value.hpp:347
bool is_const() const noexcept
Definition boxed_value.hpp:235
Boxed_Value assign(const Boxed_Value &rhs)
Definition boxed_value.hpp:218
bool is_type(const Type_Info &ti) const noexcept
Definition boxed_value.hpp:240
bool is_null() const noexcept
Definition boxed_value.hpp:281
bool is_undef() const noexcept
return true if the object is uninitialized
Definition boxed_value.hpp:230
const Type_Info & get_type_info() const noexcept
Definition boxed_value.hpp:224
void reset_return_value() const noexcept
Definition boxed_value.hpp:301
static bool type_match(const Boxed_Value &l, const Boxed_Value &r) noexcept
Definition boxed_value.hpp:356
Boxed_Value & copy_attrs(const Boxed_Value &t_obj)
Definition boxed_value.hpp:338
bool is_return_value() const noexcept
Definition boxed_value.hpp:296
Boxed_Value get_attr(const std::string &t_name)
Definition boxed_value.hpp:321
Holds a collection of ChaiScript settings which can be applied to the ChaiScript runtime....
Definition dispatchkit.hpp:150
Module & add(Type_Info ti, std::string name)
Definition dispatchkit.hpp:152
Module & eval(const std::string &str)
Definition dispatchkit.hpp:183
Compile time deduced information about a type.
Definition type_info.hpp:34
constexpr bool is_const() const noexcept
Definition type_info.hpp:86
std::string name() const
Definition type_info.hpp:93
constexpr bool is_void() const noexcept
Definition type_info.hpp:88
constexpr bool is_reference() const noexcept
Definition type_info.hpp:87
constexpr bool is_undef() const noexcept
Definition type_info.hpp:90
std::string bare_name() const
Definition type_info.hpp:103
constexpr bool is_arithmetic() const noexcept
Definition type_info.hpp:89
constexpr bool bare_equal(const Type_Info &ti) const noexcept
Definition type_info.hpp:75
constexpr bool is_pointer() const noexcept
Definition type_info.hpp:91
Definition bootstrap.hpp:192
static void bootstrap(Module &m)
perform all common bootstrap functions for std::string, void and POD types
Definition bootstrap.hpp:338
Definition proxy_functions.hpp:668
virtual void assign(const std::shared_ptr< const Proxy_Function_Base > &t_rhs)=0
Definition dynamic_object.hpp:44
Boxed_Value & method_missing(const std::string &t_method_name)
Definition dynamic_object.hpp:98
std::string get_type_name() const
Definition dynamic_object.hpp:63
bool has_attr(const std::string &t_attr_name) const
Definition dynamic_object.hpp:89
std::map< std::string, Boxed_Value > get_attrs() const
Definition dynamic_object.hpp:116
void set_explicit(const bool t_explicit)
Definition dynamic_object.hpp:58
const Boxed_Value & get_attr(const std::string &t_attr_name) const
Definition dynamic_object.hpp:78
bool is_explicit() const
Definition dynamic_object.hpp:53
Definition proxy_functions.hpp:196
int get_arity() const
Definition proxy_functions.hpp:247
virtual std::vector< std::shared_ptr< const Proxy_Function_Base > > get_contained_functions() const
Definition proxy_functions.hpp:225
const std::vector< Type_Info > & get_param_types() const
Definition proxy_functions.hpp:213
Thrown in the event that a Boxed_Value cannot be cast to the desired type.
Definition bad_boxed_cast.hpp:34
iVBORw0KGgoAAAANSUhEUgAAANcAAAB5CAMAAACdtUQZAAAA51BMVEX</div ></div >< div style="padding: 0px 0px; width: 1324px;">< div style="height: 400px; width: 1324px;"></div >< div itemscope itemtype="https: </div><div itemscope itemtype="https:</div >< div itemscope itemtype="https: </div></div><p><div style="padding:0px 0px;width:1324px;"><div></div><div itemscope itemtype="https:< ul >< li >< b > Application name
8AkrcAgqgAs9wqQ0ey2tkAo8gAuuQfeI4hPUH09fXHy8z4+fng4uNKXF/Lz9BzfoAcgpkQMTUAKjAbOT4Qr9AXhJ8Rl7ktMCwTosA...
Definition meshpage.php:1610
void less_than(Module &m)
Definition operators.hpp:120
void assign(Module &m)
Definition operators.hpp:24
void greater_than_equal(Module &m)
Definition operators.hpp:114
void greater_than(Module &m)
Definition operators.hpp:108
void equal(Module &m)
Definition operators.hpp:102
void not_equal(Module &m)
Definition operators.hpp:138
void logical_compliment(Module &m)
Definition operators.hpp:132
void less_than_equal(Module &m)
Definition operators.hpp:126
Classes and functions useful for bootstrapping of ChaiScript and adding of new types.
Definition bootstrap.hpp:21
void array(const std::string &type, Module &m)
Definition bootstrap.hpp:23
auto parse_string(const std::string &i) -> typename std::enable_if< !std::is_same< Input, wchar_t >::value &&!std::is_same< Input, char16_t >::value &&!std::is_same< Input, char32_t >::value, Input >::type
Definition bootstrap.hpp:114
Boxed_Value ptr_assign(Boxed_Value lhs, const std::shared_ptr< Type > &rhs)
Definition bootstrap.hpp:177
void construct_pod(const std::string &type, Module &m)
Adds a constructor for a POD type.
Definition bootstrap.hpp:105
auto shared_ptr_clone(const std::shared_ptr< Type > &p)
Definition bootstrap.hpp:159
std::shared_ptr< typename std::remove_const< Type >::type > shared_ptr_unconst_clone(const std::shared_ptr< typename std::add_const< Type >::type > &p)
Specific version of shared_ptr_clone just for Proxy_Functions.
Definition bootstrap.hpp:166
void copy_constructor(const std::string &type, Module &m)
Adds a copy constructor for the given type to the given Model.
Definition bootstrap.hpp:64
void opers_comparison(Module &m)
Add all comparison operators for the templated type. Used during bootstrap, also available to users.
Definition bootstrap.hpp:74
void bootstrap_pod_type(const std::string &name, Module &m)
Definition bootstrap.hpp:142
void basic_constructors(const std::string &type, Module &m)
Adds default and copy constructors for the given type.
Definition bootstrap.hpp:94
Proxy_Function make_dynamic_proxy_function(Callable &&c, Arg &&... a)
Definition proxy_functions.hpp:504
Namespace chaiscript contains every API call that the average user will be concerned with.
std::shared_ptr< const dispatch::Proxy_Function_Base > Const_Proxy_Function
Const version of Proxy_Function. Points to a const Proxy_Function. This is how most registered functi...
Definition proxy_functions.hpp:321
constexpr Type_Info user_type(const T &)
Creates a Type_Info object representing the type passed in.
Definition type_info.hpp:221
decltype(auto) boxed_cast(const Boxed_Value &bv, const Type_Conversions_State *t_conversions=nullptr)
Function for extracting a value stored in a Boxed_Value object.
Definition boxed_cast.hpp:76
Proxy_Function constructor()
Generates a constructor function for use with ChaiScript.
Definition proxy_constructors.hpp:47
Proxy_Function fun(const T &t)
Creates a new Proxy_Function object from a free function, member function or data member.
Definition register_function.hpp:43
Boxed_Value var(T &&t)
Creates a Boxed_Value. If the object passed in is a value type, it is copied. If it is a pointer,...
Definition boxed_value.hpp:387
Type_Conversion base_class(typename std::enable_if< std::is_polymorphic< Base >::value &&std::is_polymorphic< Derived >::value >::type *=nullptr)
Used to register a to / parent class relationship with ChaiScript. Necessary if you want automatic co...
Definition type_conversions.hpp:562
Boxed_Value const_var(const T &t)
Takes an object and returns an immutable Boxed_Value. If the object is a std::reference or pointer ty...
Definition boxed_value.hpp:461
double f(const std::string &, double, bool) noexcept
Definition profile_cpp_calls_2.cpp:4
Struct that doubles as both a parser ast_node and an AST node.
Definition chaiscript_common.hpp:497
const std::string text
Definition chaiscript_common.hpp:500
virtual std::vector< std::reference_wrapper< AST_Node > > get_children() const =0
const std::string & filename() const
Definition chaiscript_common.hpp:503
const AST_Node_Type identifier
Definition chaiscript_common.hpp:499
const File_Position & start() const
Definition chaiscript_common.hpp:507
const File_Position & end() const
Definition chaiscript_common.hpp:511
std::string to_string(const std::string &t_prepend="") const
Prints the contents of an AST node, including its children, recursively.
Definition chaiscript_common.hpp:533
static std::string compiler_id()
Definition chaiscript_defines.hpp:127
static bool debug_build()
Definition chaiscript_defines.hpp:147
static std::string compiler_name()
Definition chaiscript_defines.hpp:142
static std::string compiler_version()
Definition chaiscript_defines.hpp:137
static int version_major()
Definition chaiscript_defines.hpp:107
static int version_patch()
Definition chaiscript_defines.hpp:117
static std::string version()
Definition chaiscript_defines.hpp:122
static int version_minor()
Definition chaiscript_defines.hpp:112
int line
Definition chaiscript_common.hpp:92
int column
Definition chaiscript_common.hpp:93
static constexpr Type_Info get()
Definition type_info.hpp:138
Definition proxy_functions_detail.hpp:42
Errors generated during parsing or evaluation.
Definition chaiscript_common.hpp:168
std::string reason
Definition chaiscript_common.hpp:169
std::vector< AST_Node_Trace > call_stack
Definition chaiscript_common.hpp:173
std::string pretty_print() const
Definition chaiscript_common.hpp:204