Compare commits

...

11 Commits

Author SHA1 Message Date
Jason Turner
d8213a4206 Convert from #warning to #pragma message for notification of thread safety being disabled, so support more compilers portably 2010-01-19 01:54:00 +00:00
Jason Turner
3a4421a57c Fix empty array unit test by reimplementing the node->children.size() test erroneously removed in r466 2010-01-07 01:47:04 +00:00
Jonathan Turner
31fec2202c Add the answer to the unittest I added earlier 2010-01-06 19:42:09 +00:00
Jonathan Turner
13178e55e1 Add unit test that dies after r465 2010-01-06 19:39:04 +00:00
Jason Turner
968da650b2 Clean up leaking #define's for iterations (n, m) that could mess up subsequently included files such as boost/signals2.hpp 2010-01-03 15:48:17 +00:00
Jason Turner
fb5ba0be26 Remove std::swap implementation that was not supported for multiple file compilation. 2010-01-03 15:03:26 +00:00
Jason Turner
39a2c39d90 Minor fixes to example.cpp to avoid exceptions 2009-12-30 15:29:36 +00:00
Jason Turner
70047424f9 Get compiling with Visual Studio 10 beta 2. Had to work around issues with conflicts between boost::function and VisualStudio's std::tr1::mem_fn (http://social.msdn.microsoft.com/Forums/en/vcprerelease/thread/e04d93ed-d686-4ef6-9939-26e34c0955eb). Also had to work around non-standard overloaded std member functions in std::map (http://msdn.microsoft.com/en-us/library/fe72hft9(VS.100).aspx)
Strongly consider rolling this back when the issues are resolved between microsoft and boost. Also, needs to be tested across all platforms.
2009-12-28 17:16:03 +00:00
Jason Turner
2805af1ed2 move from std::numeric_limits::min() to boost::integer_traits::const_min - avoids runtime overhead of the function call. 2009-12-11 15:35:59 +00:00
Jonathan Turner
e5a29ede5f Added 0b1010 binary format. Fixed hex and octal to allow negative ints 2009-12-11 14:46:12 +00:00
Jason Turner
0c0df2c982 VS 2008 related corrections. 2009-12-08 15:57:31 +00:00
14 changed files with 121 additions and 46 deletions

View File

@@ -4,7 +4,7 @@
#ifndef CHAISCRIPT_NO_THREADS
#include <boost/thread.hpp>
#else
#warning "ChaiScript is compiling without thread safety."
#pragma message ("ChaiScript is compiling without thread safety.")
#endif
namespace chaiscript

View File

@@ -35,14 +35,14 @@ namespace chaiscript
boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))>
bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const O &o)
{
return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _));
return boost::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _));
}
template<typename Ret, typename O, typename Class BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))>
bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param))const, const O &o)
{
return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _));
return boost::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _));
}
template<typename Ret,typename O BOOST_PP_COMMA_IF(m) BOOST_PP_ENUM_PARAMS(m, typename Param) >
@@ -58,8 +58,9 @@ namespace chaiscript
{
return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _));
}
}
#undef n
#undef m
#endif

View File

@@ -134,7 +134,7 @@ namespace chaiscript
//In the interest of runtime safety for the m, we prefer the at() method for [] access,
//to throw an exception in an out of bounds condition.
m->add(
fun(boost::function<typename ContainerType::reference (ContainerType *, int)>(static_cast<indexoper>(&ContainerType::at))), "[]");
fun(boost::function<typename ContainerType::reference (ContainerType *, int)>(boost::mem_fn(static_cast<indexoper>(&ContainerType::at)))), "[]");
return m;
}
@@ -158,7 +158,7 @@ namespace chaiscript
template<typename ContainerType>
ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
{
m->add(fun(boost::function<int (const ContainerType *)>(&ContainerType::size)), "size");
m->add(fun(boost::function<int (const ContainerType *)>(boost::mem_fn(&ContainerType::size))), "size");
m->add(fun<bool (ContainerType::*)() const>(&ContainerType::empty), "empty");
m->add(fun<void (ContainerType::*)()>(&ContainerType::clear), "clear");
@@ -252,7 +252,8 @@ namespace chaiscript
push_back_name = "push_back";
}
m->add(fun(&ContainerType::push_back), push_back_name);
typedef void (ContainerType::*pushback)(const typename ContainerType::value_type &);
m->add(fun(static_cast<pushback>(&ContainerType::push_back)), push_back_name);
m->add(fun(&ContainerType::pop_back), "pop_back");
return m;
}
@@ -319,8 +320,7 @@ namespace chaiscript
template<typename ContainerType>
ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
{
// m->add(fun<size_t (ContainerType::*)(const typename ContainerType::key_type &) const>(&ContainerType::count), "count");
m->add(fun(boost::function<int (const ContainerType *, const typename ContainerType::key_type &)>(&ContainerType::count)), "count");
m->add(fun(boost::function<int (const ContainerType *, const typename ContainerType::key_type &)>(boost::mem_fn(&ContainerType::count))), "count");
return m;
}
@@ -333,7 +333,9 @@ namespace chaiscript
ModulePtr map_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
{
m->add(user_type<MapType>(), type);
m->add(fun(&MapType::operator[]), "[]");
typedef typename MapType::mapped_type &(MapType::*elemaccess)(const typename MapType::key_type &);
m->add(fun(static_cast<elemaccess>(&MapType::operator[])), "[]");
container_type<MapType>(type, m);
assignable_type<MapType>(type, m);
@@ -384,7 +386,6 @@ namespace chaiscript
return m;
}
/**
* Add a String container
* http://www.sgi.com/tech/stl/basic_string.html
@@ -417,12 +418,12 @@ namespace chaiscript
typedef boost::function<int (const String *, const String &, int)> find_func;
m->add(fun(find_func(static_cast<find_func_ptr>(&String::find))), "find");
m->add(fun(find_func(static_cast<find_func_ptr>(&String::rfind))), "rfind");
m->add(fun(find_func(static_cast<find_func_ptr>(&String::find_first_of))), "find_first_of");
m->add(fun(find_func(static_cast<find_func_ptr>(&String::find_last_of))), "find_last_of");
m->add(fun(find_func(static_cast<find_func_ptr>(&String::find_first_not_of))), "find_first_not_of");
m->add(fun(find_func(static_cast<find_func_ptr>(&String::find_last_not_of))), "find_last_not_of");
m->add(fun(find_func(boost::mem_fn(static_cast<find_func_ptr>(&String::find)))), "find");
m->add(fun(find_func(boost::mem_fn(static_cast<find_func_ptr>(&String::rfind)))), "rfind");
m->add(fun(find_func(boost::mem_fn(static_cast<find_func_ptr>(&String::find_first_of)))), "find_first_of");
m->add(fun(find_func(boost::mem_fn(static_cast<find_func_ptr>(&String::find_last_of)))), "find_last_of");
m->add(fun(find_func(boost::mem_fn(static_cast<find_func_ptr>(&String::find_first_not_of)))), "find_first_not_of");
m->add(fun(find_func(boost::mem_fn(static_cast<find_func_ptr>(&String::find_last_not_of)))), "find_last_not_of");
return m;
}

View File

@@ -17,6 +17,7 @@
#include <boost/bind.hpp>
#include <boost/cstdint.hpp>
#include <boost/type_traits/add_const.hpp>
#include <boost/integer_traits.hpp>
namespace chaiscript
{
@@ -817,8 +818,8 @@ namespace chaiscript
Boxed_Value smart_size(boost::int64_t i) const
{
if (i < std::numeric_limits<int>::min()
|| i > std::numeric_limits<int>::max())
if (i < boost::integer_traits<int>::const_min
|| i > boost::integer_traits<int>::const_max)
{
return Boxed_Value(i);
} else {
@@ -904,13 +905,7 @@ namespace chaiscript
}
}
namespace std
{
template<> void swap(chaiscript::Boxed_Value &lhs, chaiscript::Boxed_Value &rhs)
{
lhs.swap(rhs);
}
}
#endif

View File

@@ -93,6 +93,7 @@ namespace chaiscript
}
}
#undef n
#endif

View File

@@ -61,6 +61,7 @@ namespace chaiscript
}
}
}
#undef n
#endif

View File

@@ -130,4 +130,6 @@ namespace chaiscript
}
#undef n
#endif

View File

@@ -14,12 +14,13 @@
#include <boost/function_types/components.hpp>
#include <boost/function_types/function_type.hpp>
#include <boost/function_types/is_member_object_pointer.hpp>
#include <boost/function_types/is_member_function_pointer.hpp>
namespace chaiscript
{
namespace detail
{
template<bool Object>
template<bool Object, bool MemFn>
struct Fun_Helper
{
template<typename T>
@@ -31,11 +32,27 @@ namespace chaiscript
boost::function<
typename boost::function_types::function_type<boost::function_types::components<T> >::type
>(t)));
}
};
}
};
template<>
struct Fun_Helper<true>
struct Fun_Helper<false, true>
{
template<typename T>
static Proxy_Function go(T t)
{
return Proxy_Function(
new Proxy_Function_Impl<
typename boost::function_types::function_type<boost::function_types::components<T> >::type> (
boost::function<
typename boost::function_types::function_type<boost::function_types::components<T> >::type
>(boost::mem_fn(t))));
}
};
template<>
struct Fun_Helper<true, false>
{
template<typename T, typename Class>
static Proxy_Function go(T Class::* m)
@@ -55,7 +72,7 @@ namespace chaiscript
template<typename T>
Proxy_Function fun(T t)
{
return detail::Fun_Helper<boost::function_types::is_member_object_pointer<T>::value>::go(t);
return detail::Fun_Helper<boost::function_types::is_member_object_pointer<T>::value, boost::function_types::is_member_function_pointer<T>::value>::go(t);
}
template<typename T, typename Q>

View File

@@ -186,7 +186,7 @@ namespace chaiscript
Loadable_Module(const std::string &t_module_name, const std::string &t_filename)
: m_dlmodule(t_filename), m_func(m_dlmodule, "create_chaiscript_module_" + t_module_name),
m_moduleptr(m_func.m_symbol());
m_moduleptr(m_func.m_symbol())
{
}

View File

@@ -345,12 +345,14 @@ namespace chaiscript
try {
Boxed_Value retval = ss.call_function("Vector");
for (i = 0; i < node->children[0]->children.size(); ++i) {
try {
ss.call_function("push_back", retval, eval_token(ss, node->children[0]->children[i]));
}
catch (const dispatch_error &) {
throw Eval_Error("Can not find appropriate 'push_back'", node->children[0]->children[i]);
if (node->children.size() > 0) {
for (i = 0; i < node->children[0]->children.size(); ++i) {
try {
ss.call_function("push_back", retval, eval_token(ss, node->children[0]->children[i]));
}
catch (const dispatch_error &) {
throw Eval_Error("Can not find appropriate 'push_back'", node->children[0]->children[i]);
}
}
}
@@ -973,7 +975,7 @@ namespace chaiscript
return retval;
}
}
catch (const chaiscript::Return_Value &rv) {
catch (const chaiscript::Return_Value &/*rv*/) {
ss.pop_scope();
throw;
}

View File

@@ -275,6 +275,38 @@ namespace chaiscript
return retval;
}
/**
* Reads a floating point value from input, without skipping initial whitespace
*/
bool Binary_() {
bool retval = false;
if ((input_pos != input_end) && (*input_pos == '0')) {
++input_pos;
++col;
if ((input_pos != input_end) && ((*input_pos == 'b') || (*input_pos == 'B'))) {
++input_pos;
++col;
if ((input_pos != input_end) && ((*input_pos >= '0') && (*input_pos <= '1'))) {
retval = true;
while ((input_pos != input_end) && ((*input_pos >= '0') && (*input_pos <= '1'))) {
++input_pos;
++col;
}
}
else {
--input_pos;
--col;
}
}
else {
--input_pos;
--col;
}
}
return retval;
}
/**
* Reads a number from the input, detecting if it's an integer or floating point
@@ -293,9 +325,28 @@ namespace chaiscript
if (Hex_()) {
std::string match(start, input_pos);
std::stringstream ss(match);
int temp_int;
unsigned int temp_int;
ss >> std::hex >> temp_int;
std::ostringstream out_int;
out_int << int(temp_int);
TokenPtr t(new Token(out_int.str(), Token_Type::Int, filename, prev_line, prev_col, line, col));
match_stack.push_back(t);
return true;
}
if (Binary_()) {
std::string match(start, input_pos);
int temp_int = 0;
unsigned int pos = 0, end = match.length();
while ((pos < end) && (pos < (2 + sizeof(int) * 8))) {
temp_int <<= 1;
if (match[pos] == '1') {
temp_int += 1;
}
++pos;
}
std::ostringstream out_int;
out_int << temp_int;
TokenPtr t(new Token(out_int.str(), Token_Type::Int, filename, prev_line, prev_col, line, col));
@@ -312,11 +363,11 @@ namespace chaiscript
std::string match(start, input_pos);
if ((match.size() > 0) && (match[0] == '0')) {
std::stringstream ss(match);
int temp_int;
unsigned int temp_int;
ss >> std::oct >> temp_int;
std::ostringstream out_int;
out_int << temp_int;
out_int << int(temp_int);
TokenPtr t(new Token(out_int.str(), Token_Type::Int, filename, prev_line, prev_col, line, col));
match_stack.push_back(t);
}

View File

@@ -144,7 +144,7 @@ int main(int argc, char *argv[]) {
log("Functor test output", boost::lexical_cast<std::string>(x));
chai.add(var(boost::shared_ptr<int>()), "nullvar");
chai("print(\"This should be true.\"); print(nullvar.is_null())");
chai("print(\"This should be true.\"); print(nullvar.is_var_null())");
// test the global const action
chai.add_global_const(const_var(1), "constvar");
@@ -168,8 +168,8 @@ int main(int argc, char *argv[]) {
chai.add(fun(boost::function<Boxed_Value (Dynamic_Object &)>(boost::bind(&Dynamic_Object_Attribute::func, "TestType", "attr", _1))), "attr");
chai.eval("var x = TestType()");
chai.eval("x.attr = \"hi\"");
chai.eval("print(x.attr)");
// chai.eval("x.attr = \"hi\"");
// chai.eval("print(x.attr)");
chai.eval("x.hello_world()");
}

View File

@@ -0,0 +1,3 @@
var bob = []
bob.push_back(3)
print(bob)

View File

@@ -0,0 +1 @@
[3]