add is_undef functionality to boxed_value
This commit is contained in:
parent
4e5c972e66
commit
fe5a935abd
@ -558,7 +558,7 @@ namespace chaiscript
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
Boxed_Value ptr_assign(Boxed_Value lhs, const boost::shared_ptr<typename boost::add_const<Type>::type> &rhs)
|
Boxed_Value ptr_assign(Boxed_Value lhs, const boost::shared_ptr<typename boost::add_const<Type>::type> &rhs)
|
||||||
{
|
{
|
||||||
if (lhs.is_unknown()
|
if (lhs.is_undef()
|
||||||
|| (!lhs.get_type_info().is_const() && lhs.get_type_info().bare_equal(chaiscript::detail::Get_Type_Info<Type>::get())))
|
|| (!lhs.get_type_info().is_const() && lhs.get_type_info().bare_equal(chaiscript::detail::Get_Type_Info<Type>::get())))
|
||||||
{
|
{
|
||||||
lhs.assign(Boxed_Value(rhs));
|
lhs.assign(Boxed_Value(rhs));
|
||||||
@ -580,7 +580,7 @@ namespace chaiscript
|
|||||||
*/
|
*/
|
||||||
static Boxed_Value unknown_assign(Boxed_Value lhs, Boxed_Value rhs)
|
static Boxed_Value unknown_assign(Boxed_Value lhs, Boxed_Value rhs)
|
||||||
{
|
{
|
||||||
if (lhs.is_unknown())
|
if (lhs.is_undef())
|
||||||
{
|
{
|
||||||
return (lhs.assign(rhs));
|
return (lhs.assign(rhs));
|
||||||
} else {
|
} else {
|
||||||
@ -708,6 +708,7 @@ namespace chaiscript
|
|||||||
m->add(fun(&Dynamic_Object::get_attr), "get_attr");
|
m->add(fun(&Dynamic_Object::get_attr), "get_attr");
|
||||||
m->eval("def Dynamic_Object::clone() { var new_o := Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }");
|
m->eval("def Dynamic_Object::clone() { var new_o := Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }");
|
||||||
|
|
||||||
|
m->add(fun(&Boxed_Value::is_undef), "is_undef");
|
||||||
|
|
||||||
basic_constructors<bool>("bool", m);
|
basic_constructors<bool>("bool", m);
|
||||||
oper_assign<std::string>(m);
|
oper_assign<std::string>(m);
|
||||||
|
@ -293,9 +293,9 @@ namespace chaiscript
|
|||||||
/**
|
/**
|
||||||
* return true if the object is uninitialized
|
* return true if the object is uninitialized
|
||||||
*/
|
*/
|
||||||
bool is_unknown() const
|
bool is_undef() const
|
||||||
{
|
{
|
||||||
return m_data->m_type_info.is_unknown();
|
return m_data->m_type_info.is_undef();
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::any get() const
|
boost::any get() const
|
||||||
@ -594,7 +594,7 @@ namespace chaiscript
|
|||||||
Boxed_POD_Value(const Boxed_Value &v)
|
Boxed_POD_Value(const Boxed_Value &v)
|
||||||
: d(0), i(0), m_isfloat(false)
|
: d(0), i(0), m_isfloat(false)
|
||||||
{
|
{
|
||||||
if (v.get_type_info().is_unknown())
|
if (v.get_type_info().is_undef())
|
||||||
{
|
{
|
||||||
throw boost::bad_any_cast();
|
throw boost::bad_any_cast();
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
const Type_Info &ti = types[1];
|
const Type_Info &ti = types[1];
|
||||||
|
|
||||||
if (ti.is_unknown() || vals[0].get_type_info().is_unknown()
|
if (ti.is_undef() || vals[0].get_type_info().is_undef()
|
||||||
|| ti.bare_equal(user_type<Boxed_Value>())
|
|| ti.bare_equal(user_type<Boxed_Value>())
|
||||||
|| ti.bare_equal(user_type<Boxed_POD_Value>())
|
|| ti.bare_equal(user_type<Boxed_POD_Value>())
|
||||||
|| ti.bare_equal(vals[0].get_type_info()))
|
|| ti.bare_equal(vals[0].get_type_info()))
|
||||||
|
@ -29,14 +29,14 @@ namespace chaiscript
|
|||||||
: m_is_const(t_is_const), m_is_reference(t_is_reference), m_is_pointer(t_is_pointer),
|
: m_is_const(t_is_const), m_is_reference(t_is_reference), m_is_pointer(t_is_pointer),
|
||||||
m_is_void(t_is_void),
|
m_is_void(t_is_void),
|
||||||
m_type_info(t_ti), m_bare_type_info(t_bareti),
|
m_type_info(t_ti), m_bare_type_info(t_bareti),
|
||||||
m_is_unknown(false)
|
m_is_undef(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Type_Info()
|
Type_Info()
|
||||||
: m_is_const(false), m_is_reference(false), m_is_pointer(false),
|
: m_is_const(false), m_is_reference(false), m_is_pointer(false),
|
||||||
m_is_void(false), m_type_info(0), m_bare_type_info(0),
|
m_is_void(false), m_type_info(0), m_bare_type_info(0),
|
||||||
m_is_unknown(true)
|
m_is_undef(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ namespace chaiscript
|
|||||||
m_is_pointer(ti.m_is_pointer),
|
m_is_pointer(ti.m_is_pointer),
|
||||||
m_is_void(ti.m_is_void), m_type_info(ti.m_type_info),
|
m_is_void(ti.m_is_void), m_type_info(ti.m_type_info),
|
||||||
m_bare_type_info(ti.m_bare_type_info),
|
m_bare_type_info(ti.m_bare_type_info),
|
||||||
m_is_unknown(ti.m_is_unknown)
|
m_is_undef(ti.m_is_undef)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ namespace chaiscript
|
|||||||
m_is_void = ti.m_is_void;
|
m_is_void = ti.m_is_void;
|
||||||
m_type_info = ti.m_type_info;
|
m_type_info = ti.m_type_info;
|
||||||
m_bare_type_info = ti.m_bare_type_info;
|
m_bare_type_info = ti.m_bare_type_info;
|
||||||
m_is_unknown = ti.m_is_unknown;
|
m_is_undef = ti.m_is_undef;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ namespace chaiscript
|
|||||||
bool is_const() const { return m_is_const; }
|
bool is_const() const { return m_is_const; }
|
||||||
bool is_reference() const { return m_is_reference; }
|
bool is_reference() const { return m_is_reference; }
|
||||||
bool is_void() const { return m_is_void; }
|
bool is_void() const { return m_is_void; }
|
||||||
bool is_unknown() const { return m_is_unknown || m_bare_type_info == 0; }
|
bool is_undef() const { return m_is_undef || m_bare_type_info == 0; }
|
||||||
|
|
||||||
std::string bare_name() const
|
std::string bare_name() const
|
||||||
{
|
{
|
||||||
@ -105,7 +105,7 @@ namespace chaiscript
|
|||||||
bool m_is_void;
|
bool m_is_void;
|
||||||
const std::type_info *m_type_info;
|
const std::type_info *m_type_info;
|
||||||
const std::type_info *m_bare_type_info;
|
const std::type_info *m_bare_type_info;
|
||||||
bool m_is_unknown;
|
bool m_is_undef;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
|
@ -171,7 +171,7 @@ namespace chaiscript
|
|||||||
Boxed_Value lhs = eval_token(ss, node->children[i]);
|
Boxed_Value lhs = eval_token(ss, node->children[i]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (lhs.is_unknown())
|
if (lhs.is_undef())
|
||||||
{
|
{
|
||||||
retval = ss.call_function("clone", Param_List_Builder() << retval);
|
retval = ss.call_function("clone", Param_List_Builder() << retval);
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
else if (node->children[i+1]->text == ":=") {
|
else if (node->children[i+1]->text == ":=") {
|
||||||
Boxed_Value lhs = eval_token(ss, node->children[i]);
|
Boxed_Value lhs = eval_token(ss, node->children[i]);
|
||||||
if (lhs.is_unknown() || type_match(lhs, retval)) {
|
if (lhs.is_undef() || type_match(lhs, retval)) {
|
||||||
lhs.assign(retval);
|
lhs.assign(retval);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
4
unittests/is_undef.chai
Normal file
4
unittests/is_undef.chai
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
var i;
|
||||||
|
print(i.is_undef());
|
||||||
|
i = 5;
|
||||||
|
print(i.is_undef());
|
2
unittests/is_undef.txt
Normal file
2
unittests/is_undef.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
true
|
||||||
|
false
|
Loading…
x
Reference in New Issue
Block a user