Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2c99e6cd32 | ||
![]() |
a38b254a98 | ||
![]() |
77231461ca | ||
![]() |
0d4a99af82 | ||
![]() |
9f30d84f39 | ||
![]() |
508729ec77 | ||
![]() |
ab07872857 | ||
![]() |
23c13e6570 | ||
![]() |
7339ff2c2f | ||
![]() |
665125665a | ||
![]() |
d1c7645a4e | ||
![]() |
58faea1cf2 | ||
![]() |
8b7fe33bf1 | ||
![]() |
21495ebb40 | ||
![]() |
bec1b91b7b | ||
![]() |
4b81a24a0a | ||
![]() |
cefb4d3c78 |
@@ -103,7 +103,7 @@ set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/description.txt"
|
|||||||
|
|
||||||
set(CPACK_PACKAGE_VERSION_MAJOR 5)
|
set(CPACK_PACKAGE_VERSION_MAJOR 5)
|
||||||
set(CPACK_PACKAGE_VERSION_MINOR 8)
|
set(CPACK_PACKAGE_VERSION_MINOR 8)
|
||||||
set(CPACK_PACKAGE_VERSION_PATCH 2)
|
set(CPACK_PACKAGE_VERSION_PATCH 6)
|
||||||
|
|
||||||
set(CPACK_PACKAGE_EXECUTABLES "chai;ChaiScript Eval")
|
set(CPACK_PACKAGE_EXECUTABLES "chai;ChaiScript Eval")
|
||||||
set(CPACK_PACKAGE_VENDOR "ChaiScript.com")
|
set(CPACK_PACKAGE_VENDOR "ChaiScript.com")
|
||||||
|
@@ -84,6 +84,33 @@ chai.add(chaiscript::user_type<MyClass>(), "MyClass");
|
|||||||
|
|
||||||
User defined type conversions are possible, defined in either script or in C++.
|
User defined type conversions are possible, defined in either script or in C++.
|
||||||
|
|
||||||
|
|
||||||
|
### ChaiScript Defined Conversions
|
||||||
|
|
||||||
|
Function objects (including lambdas) can be used to add type conversions
|
||||||
|
from inside of ChaiScript:
|
||||||
|
|
||||||
|
```
|
||||||
|
add_type_conversion(type("string"), type("Type_Info"), fun(s) { return type(s); });
|
||||||
|
```
|
||||||
|
|
||||||
|
### C++ Defined Conversions
|
||||||
|
|
||||||
|
Invoking a C++ type conversion possible with `static_cast`
|
||||||
|
|
||||||
|
```
|
||||||
|
chai.add(chaiscript::type_conversion<T, bool>());
|
||||||
|
```
|
||||||
|
|
||||||
|
Calling a user defined type conversion that takes a lambda
|
||||||
|
|
||||||
|
```
|
||||||
|
chai.add(chaiscript::type_conversion<TestBaseType, Type2>([](const TestBaseType &t_bt) { /* return converted thing */ }));
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Helpers
|
||||||
|
|
||||||
A helper function exists for strongly typed and ChaiScript `Vector` function conversion definition:
|
A helper function exists for strongly typed and ChaiScript `Vector` function conversion definition:
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -97,6 +124,7 @@ chai.add(chaiscript::map_conversion<std::map<std::string, int>>());
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
This allows you to pass a ChaiScript function to a function requiring `std::vector<int>`
|
This allows you to pass a ChaiScript function to a function requiring `std::vector<int>`
|
||||||
|
|
||||||
## Adding Objects
|
## Adding Objects
|
||||||
|
@@ -99,7 +99,7 @@
|
|||||||
namespace chaiscript {
|
namespace chaiscript {
|
||||||
static const int version_major = 5;
|
static const int version_major = 5;
|
||||||
static const int version_minor = 8;
|
static const int version_minor = 8;
|
||||||
static const int version_patch = 2;
|
static const int version_patch = 6;
|
||||||
|
|
||||||
static const char *compiler_version = CHAISCRIPT_COMPILER_VERSION;
|
static const char *compiler_version = CHAISCRIPT_COMPILER_VERSION;
|
||||||
static const char *compiler_name = CHAISCRIPT_COMPILER_NAME;
|
static const char *compiler_name = CHAISCRIPT_COMPILER_NAME;
|
||||||
|
@@ -430,7 +430,8 @@ namespace chaiscript
|
|||||||
};
|
};
|
||||||
|
|
||||||
Dispatch_Engine()
|
Dispatch_Engine()
|
||||||
: m_stack_holder(this)
|
: m_stack_holder(this),
|
||||||
|
m_method_missing_loc(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -962,14 +963,20 @@ namespace chaiscript
|
|||||||
|
|
||||||
This_Foist fi(*this, l_params.front());
|
This_Foist fi(*this, l_params.front());
|
||||||
|
|
||||||
auto func = boxed_cast<std::shared_ptr<const dispatch::Proxy_Function_Base>>(bv);
|
|
||||||
try {
|
try {
|
||||||
return (*func)({l_params.begin() + l_num_params, l_params.end()}, l_conversions);
|
auto func = boxed_cast<std::shared_ptr<const dispatch::Proxy_Function_Base>>(bv);
|
||||||
|
try {
|
||||||
|
return (*func)({l_params.begin() + l_num_params, l_params.end()}, l_conversions);
|
||||||
|
} catch (const chaiscript::exception::bad_boxed_cast &) {
|
||||||
|
} catch (const chaiscript::exception::arity_error &) {
|
||||||
|
} catch (const chaiscript::exception::guard_error &) {
|
||||||
|
}
|
||||||
|
throw chaiscript::exception::dispatch_error({l_params.begin() + l_num_params, l_params.end()}, std::vector<Const_Proxy_Function>{func});
|
||||||
} catch (const chaiscript::exception::bad_boxed_cast &) {
|
} catch (const chaiscript::exception::bad_boxed_cast &) {
|
||||||
} catch (const chaiscript::exception::arity_error &) {
|
// unable to convert bv into a Proxy_Function_Base
|
||||||
} catch (const chaiscript::exception::guard_error &) {
|
throw chaiscript::exception::dispatch_error({l_params.begin() + l_num_params, l_params.end()},
|
||||||
|
std::vector<Const_Proxy_Function>(l_funs.begin(), l_funs.end()));
|
||||||
}
|
}
|
||||||
throw chaiscript::exception::dispatch_error({l_params.begin() + l_num_params, l_params.end()}, std::vector<Const_Proxy_Function>{func});
|
|
||||||
} else {
|
} else {
|
||||||
return bv;
|
return bv;
|
||||||
}
|
}
|
||||||
|
@@ -846,7 +846,8 @@ namespace chaiscript
|
|||||||
plist.begin(),
|
plist.begin(),
|
||||||
std::back_inserter(newplist),
|
std::back_inserter(newplist),
|
||||||
[](const Type_Info &ti, const Boxed_Value ¶m) -> Boxed_Value {
|
[](const Type_Info &ti, const Boxed_Value ¶m) -> Boxed_Value {
|
||||||
if (ti.is_arithmetic() && param.get_type_info().is_arithmetic()) {
|
if (ti.is_arithmetic() && param.get_type_info().is_arithmetic()
|
||||||
|
&& param.get_type_info() != ti) {
|
||||||
return Boxed_Number(param).get_as(ti).bv;
|
return Boxed_Number(param).get_as(ti).bv;
|
||||||
} else {
|
} else {
|
||||||
return param;
|
return param;
|
||||||
@@ -854,8 +855,6 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return (*(matching_func->second))(newplist, t_conversions);
|
return (*(matching_func->second))(newplist, t_conversions);
|
||||||
} catch (const exception::bad_boxed_cast &) {
|
} catch (const exception::bad_boxed_cast &) {
|
||||||
|
@@ -60,6 +60,16 @@ namespace chaiscript
|
|||||||
return m_type_info < ti.m_type_info;
|
return m_type_info < ti.m_type_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHAISCRIPT_CONSTEXPR bool operator!=(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT
|
||||||
|
{
|
||||||
|
return !(operator==(ti));
|
||||||
|
}
|
||||||
|
|
||||||
|
CHAISCRIPT_CONSTEXPR bool operator!=(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT
|
||||||
|
{
|
||||||
|
return !(operator==(ti));
|
||||||
|
}
|
||||||
|
|
||||||
CHAISCRIPT_CONSTEXPR bool operator==(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT
|
CHAISCRIPT_CONSTEXPR bool operator==(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return ti.m_type_info == m_type_info
|
return ti.m_type_info == m_type_info
|
||||||
|
@@ -489,9 +489,9 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool get_bool_condition(const Boxed_Value &t_bv) {
|
static bool get_bool_condition(const Boxed_Value &t_bv, const chaiscript::detail::Dispatch_State &t_ss) {
|
||||||
try {
|
try {
|
||||||
return boxed_cast<bool>(t_bv);
|
return t_ss->boxed_cast<bool>(t_bv);
|
||||||
}
|
}
|
||||||
catch (const exception::bad_boxed_cast &) {
|
catch (const exception::bad_boxed_cast &) {
|
||||||
throw exception::eval_error("Condition not boolean");
|
throw exception::eval_error("Condition not boolean");
|
||||||
|
@@ -85,7 +85,8 @@ namespace chaiscript
|
|||||||
public:
|
public:
|
||||||
Binary_Operator_AST_Node(const std::string &t_oper, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
Binary_Operator_AST_Node(const std::string &t_oper, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
||||||
AST_Node(t_oper, AST_Node_Type::Binary, std::move(t_loc), std::move(t_children)),
|
AST_Node(t_oper, AST_Node_Type::Binary, std::move(t_loc), std::move(t_children)),
|
||||||
m_oper(Operators::to_operator(t_oper))
|
m_oper(Operators::to_operator(t_oper)),
|
||||||
|
m_loc(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual ~Binary_Operator_AST_Node() {}
|
virtual ~Binary_Operator_AST_Node() {}
|
||||||
@@ -166,7 +167,7 @@ namespace chaiscript
|
|||||||
Id_AST_Node(const std::string &t_ast_node_text, Parse_Location t_loc) :
|
Id_AST_Node(const std::string &t_ast_node_text, Parse_Location t_loc) :
|
||||||
AST_Node(t_ast_node_text, AST_Node_Type::Id, std::move(t_loc)),
|
AST_Node(t_ast_node_text, AST_Node_Type::Id, std::move(t_loc)),
|
||||||
m_value(get_value(t_ast_node_text)), m_loc(0)
|
m_value(get_value(t_ast_node_text)), m_loc(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual ~Id_AST_Node() {}
|
virtual ~Id_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE {
|
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE {
|
||||||
@@ -393,7 +394,10 @@ namespace chaiscript
|
|||||||
public:
|
public:
|
||||||
Equation_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
Equation_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
||||||
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Equation, std::move(t_loc), std::move(t_children)),
|
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Equation, std::move(t_loc), std::move(t_children)),
|
||||||
m_oper(Operators::to_operator(children[1]->text))
|
m_oper(Operators::to_operator(children[1]->text)),
|
||||||
|
m_loc(0),
|
||||||
|
m_clone_loc(0)
|
||||||
|
|
||||||
{ assert(children.size() == 3); }
|
{ assert(children.size() == 3); }
|
||||||
|
|
||||||
Operators::Opers m_oper;
|
Operators::Opers m_oper;
|
||||||
@@ -535,7 +539,7 @@ namespace chaiscript
|
|||||||
struct Array_Call_AST_Node : public AST_Node {
|
struct Array_Call_AST_Node : public AST_Node {
|
||||||
public:
|
public:
|
||||||
Array_Call_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
Array_Call_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
||||||
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Array_Call, std::move(t_loc), std::move(t_children)) { }
|
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Array_Call, std::move(t_loc), std::move(t_children)), m_loc(0) { }
|
||||||
virtual ~Array_Call_AST_Node() {}
|
virtual ~Array_Call_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE{
|
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE{
|
||||||
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
|
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
|
||||||
@@ -574,6 +578,8 @@ namespace chaiscript
|
|||||||
public:
|
public:
|
||||||
Dot_Access_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
Dot_Access_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
||||||
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Dot_Access, std::move(t_loc), std::move(t_children)),
|
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Dot_Access, std::move(t_loc), std::move(t_children)),
|
||||||
|
m_loc(0),
|
||||||
|
m_array_loc(0),
|
||||||
m_fun_name(
|
m_fun_name(
|
||||||
((children[2]->identifier == AST_Node_Type::Fun_Call) || (children[2]->identifier == AST_Node_Type::Array_Call))?
|
((children[2]->identifier == AST_Node_Type::Fun_Call) || (children[2]->identifier == AST_Node_Type::Array_Call))?
|
||||||
children[2]->children[0]->text:children[2]->text) { }
|
children[2]->children[0]->text:children[2]->text) { }
|
||||||
@@ -803,7 +809,7 @@ namespace chaiscript
|
|||||||
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
|
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (get_bool_condition(this->children[0]->eval(t_ss))) {
|
while (get_bool_condition(this->children[0]->eval(t_ss), t_ss)) {
|
||||||
try {
|
try {
|
||||||
this->children[1]->eval(t_ss);
|
this->children[1]->eval(t_ss);
|
||||||
} catch (detail::Continue_Loop &) {
|
} catch (detail::Continue_Loop &) {
|
||||||
@@ -845,7 +851,7 @@ namespace chaiscript
|
|||||||
{ assert(children.size() == 3); }
|
{ assert(children.size() == 3); }
|
||||||
virtual ~Ternary_Cond_AST_Node() {}
|
virtual ~Ternary_Cond_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE {
|
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE {
|
||||||
if (get_bool_condition(children[0]->eval(t_ss))) {
|
if (get_bool_condition(children[0]->eval(t_ss), t_ss)) {
|
||||||
return children[1]->eval(t_ss);
|
return children[1]->eval(t_ss);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -862,7 +868,7 @@ namespace chaiscript
|
|||||||
virtual ~If_AST_Node() {}
|
virtual ~If_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE{
|
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE{
|
||||||
|
|
||||||
if (get_bool_condition(children[0]->eval(t_ss))) {
|
if (get_bool_condition(children[0]->eval(t_ss), t_ss)) {
|
||||||
return children[1]->eval(t_ss);
|
return children[1]->eval(t_ss);
|
||||||
} else {
|
} else {
|
||||||
if (children.size() > 2) {
|
if (children.size() > 2) {
|
||||||
@@ -872,7 +878,7 @@ namespace chaiscript
|
|||||||
return children[i+1]->eval(t_ss);
|
return children[i+1]->eval(t_ss);
|
||||||
}
|
}
|
||||||
else if (children[i]->text == "else if") {
|
else if (children[i]->text == "else if") {
|
||||||
if (get_bool_condition(children[i+1]->eval(t_ss))) {
|
if (get_bool_condition(children[i+1]->eval(t_ss), t_ss)) {
|
||||||
return children[i+2]->eval(t_ss);
|
return children[i+2]->eval(t_ss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -899,7 +905,7 @@ namespace chaiscript
|
|||||||
try {
|
try {
|
||||||
for (
|
for (
|
||||||
children[0]->eval(t_ss);
|
children[0]->eval(t_ss);
|
||||||
get_bool_condition(children[1]->eval(t_ss));
|
get_bool_condition(children[1]->eval(t_ss), t_ss);
|
||||||
children[2]->eval(t_ss)
|
children[2]->eval(t_ss)
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
@@ -923,7 +929,7 @@ namespace chaiscript
|
|||||||
struct Switch_AST_Node : public AST_Node {
|
struct Switch_AST_Node : public AST_Node {
|
||||||
public:
|
public:
|
||||||
Switch_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
Switch_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
||||||
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Switch, std::move(t_loc), std::move(t_children)) { }
|
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Switch, std::move(t_loc), std::move(t_children)), m_loc(0) { }
|
||||||
virtual ~Switch_AST_Node() {}
|
virtual ~Switch_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE {
|
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE {
|
||||||
bool breaking = false;
|
bool breaking = false;
|
||||||
@@ -999,7 +1005,10 @@ namespace chaiscript
|
|||||||
struct Inline_Array_AST_Node : public AST_Node {
|
struct Inline_Array_AST_Node : public AST_Node {
|
||||||
public:
|
public:
|
||||||
Inline_Array_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
Inline_Array_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
||||||
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Inline_Array, std::move(t_loc), std::move(t_children)) { }
|
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Inline_Array, std::move(t_loc), std::move(t_children)),
|
||||||
|
m_loc(0)
|
||||||
|
{ }
|
||||||
|
|
||||||
virtual ~Inline_Array_AST_Node() {}
|
virtual ~Inline_Array_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE {
|
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE {
|
||||||
try {
|
try {
|
||||||
@@ -1033,7 +1042,7 @@ namespace chaiscript
|
|||||||
struct Inline_Map_AST_Node : public AST_Node {
|
struct Inline_Map_AST_Node : public AST_Node {
|
||||||
public:
|
public:
|
||||||
Inline_Map_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
Inline_Map_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
||||||
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Inline_Map, std::move(t_loc), std::move(t_children)) { }
|
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Inline_Map, std::move(t_loc), std::move(t_children)), m_loc(0) { }
|
||||||
virtual ~Inline_Map_AST_Node() {}
|
virtual ~Inline_Map_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE{
|
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE{
|
||||||
try {
|
try {
|
||||||
@@ -1123,7 +1132,8 @@ namespace chaiscript
|
|||||||
public:
|
public:
|
||||||
Prefix_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
Prefix_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
||||||
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Prefix, std::move(t_loc), std::move(t_children)),
|
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Prefix, std::move(t_loc), std::move(t_children)),
|
||||||
m_oper(Operators::to_operator(children[0]->text, true))
|
m_oper(Operators::to_operator(children[0]->text, true)),
|
||||||
|
m_loc(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual ~Prefix_AST_Node() {}
|
virtual ~Prefix_AST_Node() {}
|
||||||
@@ -1204,7 +1214,7 @@ namespace chaiscript
|
|||||||
struct Inline_Range_AST_Node : public AST_Node {
|
struct Inline_Range_AST_Node : public AST_Node {
|
||||||
public:
|
public:
|
||||||
Inline_Range_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
Inline_Range_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
||||||
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Inline_Range, std::move(t_loc), std::move(t_children)) { }
|
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Inline_Range, std::move(t_loc), std::move(t_children)), m_loc(0) { }
|
||||||
virtual ~Inline_Range_AST_Node() {}
|
virtual ~Inline_Range_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE{
|
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE{
|
||||||
try {
|
try {
|
||||||
@@ -1303,11 +1313,8 @@ namespace chaiscript
|
|||||||
try {
|
try {
|
||||||
retval = this->children[0]->eval(t_ss);
|
retval = this->children[0]->eval(t_ss);
|
||||||
}
|
}
|
||||||
catch (exception::eval_error &) {
|
catch (const exception::eval_error &e) {
|
||||||
if (this->children.back()->identifier == AST_Node_Type::Finally) {
|
retval = handle_exception(t_ss, Boxed_Value(std::ref(e)));
|
||||||
this->children.back()->children[0]->eval(t_ss);
|
|
||||||
}
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
catch (const std::runtime_error &e) {
|
catch (const std::runtime_error &e) {
|
||||||
retval = handle_exception(t_ss, Boxed_Value(std::ref(e)));
|
retval = handle_exception(t_ss, Boxed_Value(std::ref(e)));
|
||||||
@@ -1488,8 +1495,8 @@ namespace chaiscript
|
|||||||
|
|
||||||
virtual ~Logical_And_AST_Node() {}
|
virtual ~Logical_And_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE{
|
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE{
|
||||||
return const_var(get_bool_condition(children[0]->eval(t_ss))
|
return const_var(get_bool_condition(children[0]->eval(t_ss), t_ss)
|
||||||
&& get_bool_condition(children[2]->eval(t_ss)));
|
&& get_bool_condition(children[2]->eval(t_ss), t_ss));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string pretty_print() const CHAISCRIPT_OVERRIDE
|
virtual std::string pretty_print() const CHAISCRIPT_OVERRIDE
|
||||||
@@ -1505,8 +1512,8 @@ namespace chaiscript
|
|||||||
{ assert(children.size() == 3); }
|
{ assert(children.size() == 3); }
|
||||||
virtual ~Logical_Or_AST_Node() {}
|
virtual ~Logical_Or_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE{
|
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE{
|
||||||
return const_var(get_bool_condition(children[0]->eval(t_ss))
|
return const_var(get_bool_condition(children[0]->eval(t_ss), t_ss)
|
||||||
|| get_bool_condition(children[2]->eval(t_ss)));
|
|| get_bool_condition(children[2]->eval(t_ss), t_ss));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string pretty_print() const CHAISCRIPT_OVERRIDE
|
virtual std::string pretty_print() const CHAISCRIPT_OVERRIDE
|
||||||
|
@@ -219,6 +219,10 @@ namespace chaiscript
|
|||||||
m_operators.emplace_back(AST_Node_Type::Multiplication);
|
m_operators.emplace_back(AST_Node_Type::Multiplication);
|
||||||
m_operator_matches.emplace_back(std::initializer_list<std::string>({"*", "/", "%"}));
|
m_operator_matches.emplace_back(std::initializer_list<std::string>({"*", "/", "%"}));
|
||||||
|
|
||||||
|
// Prefix placeholder
|
||||||
|
m_operators.emplace_back(AST_Node_Type::Prefix);
|
||||||
|
m_operator_matches.emplace_back(std::initializer_list<std::string>({}));
|
||||||
|
|
||||||
for (auto & elem : m_alphabet) {
|
for (auto & elem : m_alphabet) {
|
||||||
std::fill(std::begin(elem), std::end(elem), false);
|
std::fill(std::begin(elem), std::end(elem), false);
|
||||||
}
|
}
|
||||||
@@ -343,7 +347,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
for (auto &c : p->children)
|
for (auto &c : p->children)
|
||||||
{
|
{
|
||||||
if (c->identifier == AST_Node_Type::Def && c->children.size() > 0) {
|
if ( (c->identifier == AST_Node_Type::Def || c->identifier == AST_Node_Type::Lambda) && c->children.size() > 0) {
|
||||||
auto &last_child = c->children.back();
|
auto &last_child = c->children.back();
|
||||||
if (last_child->identifier == AST_Node_Type::Block) {
|
if (last_child->identifier == AST_Node_Type::Block) {
|
||||||
auto &block_last_child = last_child->children.back();
|
auto &block_last_child = last_child->children.back();
|
||||||
@@ -1696,12 +1700,16 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reads a class block from input
|
/// Reads a class block from input
|
||||||
bool Class() {
|
bool Class(const bool t_class_allowed) {
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
|
||||||
size_t prev_stack_top = m_match_stack.size();
|
size_t prev_stack_top = m_match_stack.size();
|
||||||
|
|
||||||
if (Keyword("class")) {
|
if (Keyword("class")) {
|
||||||
|
if (!t_class_allowed) {
|
||||||
|
throw exception::eval_error("Class definitions only allowed at top scope", File_Position(m_position.line, m_position.col), *m_filename);
|
||||||
|
}
|
||||||
|
|
||||||
retval = true;
|
retval = true;
|
||||||
|
|
||||||
if (!Id()) {
|
if (!Id()) {
|
||||||
@@ -2160,7 +2168,7 @@ namespace chaiscript
|
|||||||
/// Reads a unary prefixed expression from input
|
/// Reads a unary prefixed expression from input
|
||||||
bool Prefix() {
|
bool Prefix() {
|
||||||
const auto prev_stack_top = m_match_stack.size();
|
const auto prev_stack_top = m_match_stack.size();
|
||||||
const std::vector<std::string> prefix_opers{"++", "--", "-", "+", "!", "~", "&"};
|
const std::vector<std::string> prefix_opers{"++", "--", "-", "+", "!", "~"};
|
||||||
|
|
||||||
for (const auto &oper : prefix_opers)
|
for (const auto &oper : prefix_opers)
|
||||||
{
|
{
|
||||||
@@ -2197,7 +2205,7 @@ namespace chaiscript
|
|||||||
bool retval = false;
|
bool retval = false;
|
||||||
const auto prev_stack_top = m_match_stack.size();
|
const auto prev_stack_top = m_match_stack.size();
|
||||||
|
|
||||||
if (t_precedence < m_operators.size()) {
|
if (m_operators[t_precedence] != AST_Node_Type::Prefix) {
|
||||||
if (Operator(t_precedence+1)) {
|
if (Operator(t_precedence+1)) {
|
||||||
retval = true;
|
retval = true;
|
||||||
if (Operator_Helper(t_precedence)) {
|
if (Operator_Helper(t_precedence)) {
|
||||||
@@ -2257,8 +2265,7 @@ namespace chaiscript
|
|||||||
} while (Operator_Helper(t_precedence));
|
} while (Operator_Helper(t_precedence));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return Value();
|
return Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2372,7 +2379,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Top level parser, starts parsing of all known parses
|
/// Top level parser, starts parsing of all known parses
|
||||||
bool Statements() {
|
bool Statements(const bool t_class_allowed = false) {
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
|
||||||
bool has_more = true;
|
bool has_more = true;
|
||||||
@@ -2380,7 +2387,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
while (has_more) {
|
while (has_more) {
|
||||||
const auto start = m_position;
|
const auto start = m_position;
|
||||||
if (Def() || Try() || If() || While() || Class() || For() || Switch()) {
|
if (Def() || Try() || If() || While() || Class(t_class_allowed) || For() || Switch()) {
|
||||||
if (!saw_eol) {
|
if (!saw_eol) {
|
||||||
throw exception::eval_error("Two function definitions missing line separator", File_Position(start.line, start.col), *m_filename);
|
throw exception::eval_error("Two function definitions missing line separator", File_Position(start.line, start.col), *m_filename);
|
||||||
}
|
}
|
||||||
@@ -2421,7 +2428,7 @@ namespace chaiscript
|
|||||||
/// \todo respect // -*- coding: utf-8 -*- on line 1 or 2 see: http://evanjones.ca/python-utf8.html)
|
/// \todo respect // -*- coding: utf-8 -*- on line 1 or 2 see: http://evanjones.ca/python-utf8.html)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Statements()) {
|
if (Statements(true)) {
|
||||||
if (m_position.has_more()) {
|
if (m_position.has_more()) {
|
||||||
throw exception::eval_error("Unparsed input", File_Position(m_position.line, m_position.col), t_fname);
|
throw exception::eval_error("Unparsed input", File_Position(m_position.line, m_position.col), t_fname);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -1,6 +1,24 @@
|
|||||||
Notes:
|
Notes:
|
||||||
=======
|
=======
|
||||||
Current Version: 5.8.2
|
|
||||||
|
Current Version: 5.8.6
|
||||||
|
|
||||||
|
### Changes since 5.8.5
|
||||||
|
* Optimize away `return` statements in lambdas also
|
||||||
|
* Allow conversions to bool in conditionals
|
||||||
|
* Don't allow `class` statements inside of scopes
|
||||||
|
* Properly error when a dynamic object non-function member is called
|
||||||
|
|
||||||
|
### Changes since 5.8.4
|
||||||
|
* Fix order of operations for prefix operators
|
||||||
|
* Make sure atomics are initialized properly
|
||||||
|
* Remove parsing of unused prefix `&` operator
|
||||||
|
|
||||||
|
### Changes since 5.8.3
|
||||||
|
* Fix case with some numeric conversions mixed with numerics that do not need conversion
|
||||||
|
|
||||||
|
### Changes since 5.8.2
|
||||||
|
* Add support for reference of pointer return types
|
||||||
|
|
||||||
### Changes since 5.8.1
|
### Changes since 5.8.1
|
||||||
* Allow casting to non-const & std::shared_ptr<T>
|
* Allow casting to non-const & std::shared_ptr<T>
|
||||||
|
8
unittests/class_inside_scope.chai
Normal file
8
unittests/class_inside_scope.chai
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
parse("{ class C { var data; def C() {} } }")
|
||||||
|
assert_false(true)
|
||||||
|
} catch (e) {
|
||||||
|
assert_true(true)
|
||||||
|
}
|
@@ -950,4 +950,34 @@ TEST_CASE("Parse floats with non-posix locale")
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool FindBitmap(int &ox, int &oy, long) {
|
||||||
|
ox = 1;
|
||||||
|
oy = 2;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Mismatched numeric types only convert necessary params")
|
||||||
|
{
|
||||||
|
chaiscript::ChaiScript chai;
|
||||||
|
|
||||||
|
chai.add(chaiscript::fun(&FindBitmap), "FindBitmap");
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
chai.add(chaiscript::var(&x), "x");
|
||||||
|
chai.add(chaiscript::var(&y), "y");
|
||||||
|
chai.eval( "if ( FindBitmap ( x, y, 0) ) { print(\"found at \" + to_string(x) + \", \" + to_string(y))}" );
|
||||||
|
CHECK(x == 1);
|
||||||
|
CHECK(y == 2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("type_conversion to bool")
|
||||||
|
{
|
||||||
|
auto module = std::make_shared<chaiscript::Module>();
|
||||||
|
struct T {
|
||||||
|
operator bool() const { return true; }
|
||||||
|
};
|
||||||
|
module->add(chaiscript::type_conversion<T, bool>());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
17
unittests/conversion_to_bool.chai
Normal file
17
unittests/conversion_to_bool.chai
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
// all we care is that this executes, really
|
||||||
|
|
||||||
|
add_type_conversion(type("int"), type("bool"), fun(int i) { return i != 0; });
|
||||||
|
|
||||||
|
if (0) {
|
||||||
|
assert_true(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (0) {
|
||||||
|
assert_true(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; 0; ) {
|
||||||
|
assert_true(false);
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
4
unittests/precedence_4.chai
Normal file
4
unittests/precedence_4.chai
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
var i = 2;
|
||||||
|
|
||||||
|
assert_equal(++i * i, 9)
|
Reference in New Issue
Block a user