Merge branch '2011-09-09-CxScript' of https://github.com/ChaiScript/ChaiScript into 2011-09-09-CxScript

This commit is contained in:
Jonathan Turner
2011-09-24 12:26:17 -06:00
80 changed files with 163 additions and 165 deletions

View File

@@ -72,10 +72,6 @@ namespace chaiscript
class Thread_Storage class Thread_Storage
{ {
public: public:
~Thread_Storage()
{
}
inline T *operator->() const inline T *operator->() const
{ {
return get_tls().get(); return get_tls().get();
@@ -92,7 +88,7 @@ namespace chaiscript
{ {
unique_lock<mutex> lock(m_mutex); unique_lock<mutex> lock(m_mutex);
typename std::map<std::thread::id, std::shared_ptr<T> >::iterator itr = m_instances.find(std::this_thread::get_id()); auto itr = m_instances.find(std::this_thread::get_id());
if (itr != m_instances.end()) { return itr->second; } if (itr != m_instances.end()) { return itr->second; }

View File

@@ -19,15 +19,15 @@ namespace chaiscript {
class bad_any_cast : public std::bad_cast class bad_any_cast : public std::bad_cast
{ {
public: public:
bad_any_cast() throw() bad_any_cast() noexcept
: m_what("bad any cast") : m_what("bad any cast")
{ {
} }
virtual ~bad_any_cast() throw() {} virtual ~bad_any_cast() noexcept {}
/// \brief Description of what error occured /// \brief Description of what error occured
virtual const char * what() const throw() virtual const char * what() const noexcept
{ {
return m_what.c_str(); return m_what.c_str();
} }
@@ -79,7 +79,7 @@ namespace chaiscript {
public: public:
// construct/copy/destruct // construct/copy/destruct
Any() {} Any() = default;
Any(const Any &t_any) Any(const Any &t_any)
{ {

View File

@@ -22,25 +22,25 @@ namespace chaiscript
{ {
public: public:
bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to, bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to,
const std::string &t_what) throw() const std::string &t_what) noexcept
: from(t_from), to(&t_to), m_what(t_what) : from(t_from), to(&t_to), m_what(t_what)
{ {
} }
bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to) throw() bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to) noexcept
: from(t_from), to(&t_to), m_what("Cannot perform boxed_cast") : from(t_from), to(&t_to), m_what("Cannot perform boxed_cast")
{ {
} }
bad_boxed_cast(const std::string &t_what) throw() bad_boxed_cast(const std::string &t_what) noexcept
: m_what(t_what) : m_what(t_what)
{ {
} }
virtual ~bad_boxed_cast() throw() {} virtual ~bad_boxed_cast() noexcept {}
/// \brief Description of what error occured /// \brief Description of what error occured
virtual const char * what() const throw() virtual const char * what() const noexcept
{ {
return m_what.c_str(); return m_what.c_str();
} }

View File

@@ -289,7 +289,7 @@ namespace chaiscript
static bool has_guard(const Const_Proxy_Function &t_pf) static bool has_guard(const Const_Proxy_Function &t_pf)
{ {
std::shared_ptr<const dispatch::Dynamic_Proxy_Function> pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf); auto pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf);
if (pf) if (pf)
{ {
return bool(pf->get_guard()); return bool(pf->get_guard());
@@ -300,7 +300,7 @@ namespace chaiscript
static Const_Proxy_Function get_guard(const Const_Proxy_Function &t_pf) static Const_Proxy_Function get_guard(const Const_Proxy_Function &t_pf)
{ {
std::shared_ptr<const dispatch::Dynamic_Proxy_Function> pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf); auto pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf);
if (pf) if (pf)
{ {
if (pf->get_guard()) if (pf->get_guard())
@@ -318,7 +318,9 @@ namespace chaiscript
throw bv; throw bv;
} }
static std::shared_ptr<chaiscript::detail::Dispatch_Engine> bootstrap2(std::shared_ptr<chaiscript::detail::Dispatch_Engine> e = std::shared_ptr<chaiscript::detail::Dispatch_Engine> (new chaiscript::detail::Dispatch_Engine())) static std::shared_ptr<chaiscript::detail::Dispatch_Engine> bootstrap2(
std::shared_ptr<chaiscript::detail::Dispatch_Engine> e
= std::shared_ptr<chaiscript::detail::Dispatch_Engine> (new chaiscript::detail::Dispatch_Engine()))
{ {
e->add(user_type<void>(), "void"); e->add(user_type<void>(), "void");
return e; return e;

View File

@@ -41,12 +41,12 @@ namespace chaiscript
class reserved_word_error : public std::runtime_error class reserved_word_error : public std::runtime_error
{ {
public: public:
reserved_word_error(const std::string &t_word) throw() reserved_word_error(const std::string &t_word) noexcept
: std::runtime_error("Reserved word not allowed in object name: " + t_word), m_word(t_word) : std::runtime_error("Reserved word not allowed in object name: " + t_word), m_word(t_word)
{ {
} }
virtual ~reserved_word_error() throw() {} virtual ~reserved_word_error() noexcept {}
std::string word() const std::string word() const
{ {
@@ -64,12 +64,12 @@ namespace chaiscript
class global_non_const : public std::runtime_error class global_non_const : public std::runtime_error
{ {
public: public:
global_non_const() throw() global_non_const() noexcept
: std::runtime_error("a global object must be const") : std::runtime_error("a global object must be const")
{ {
} }
virtual ~global_non_const() throw() {} virtual ~global_non_const() noexcept {}
}; };
} }

View File

@@ -20,22 +20,22 @@ namespace chaiscript
{ {
public: public:
bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to, bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to,
const std::string &t_what) throw() const std::string &t_what) noexcept
: bad_boxed_cast(t_from, t_to, t_what) : bad_boxed_cast(t_from, t_to, t_what)
{ {
} }
bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to) throw() bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to) noexcept
: bad_boxed_cast(t_from, t_to) : bad_boxed_cast(t_from, t_to)
{ {
} }
bad_boxed_dynamic_cast(const std::string &w) throw() bad_boxed_dynamic_cast(const std::string &w) noexcept
: bad_boxed_cast(w) : bad_boxed_cast(w)
{ {
} }
virtual ~bad_boxed_dynamic_cast() throw() {} virtual ~bad_boxed_dynamic_cast() noexcept {}
}; };
} }

View File

@@ -188,11 +188,11 @@ namespace chaiscript
class guard_error : public std::runtime_error class guard_error : public std::runtime_error
{ {
public: public:
guard_error() throw() guard_error() noexcept
: std::runtime_error("Guard evaluation failed") : std::runtime_error("Guard evaluation failed")
{ } { }
virtual ~guard_error() throw() virtual ~guard_error() noexcept
{ } { }
}; };
} }
@@ -587,17 +587,17 @@ namespace chaiscript
class dispatch_error : public std::runtime_error class dispatch_error : public std::runtime_error
{ {
public: public:
dispatch_error() throw() dispatch_error() noexcept
: std::runtime_error("No matching function to dispatch to") : std::runtime_error("No matching function to dispatch to")
{ {
} }
dispatch_error(bool is_const) throw() dispatch_error(bool is_const) noexcept
: std::runtime_error(std::string("No matching function to dispatch to") + (is_const?", parameter is const":"")) : std::runtime_error(std::string("No matching function to dispatch to") + (is_const?", parameter is const":""))
{ {
} }
virtual ~dispatch_error() throw() {} virtual ~dispatch_error() noexcept {}
}; };
} }

View File

@@ -32,7 +32,7 @@ namespace chaiscript
{ {
} }
virtual ~arity_error() throw() {} virtual ~arity_error() noexcept {}
int got; int got;
int expected; int expected;

View File

@@ -70,17 +70,17 @@ namespace chaiscript
std::string filename; std::string filename;
std::vector<AST_NodePtr> call_stack; std::vector<AST_NodePtr> call_stack;
eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) throw() : eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) noexcept :
std::runtime_error(format(t_why, t_where, t_fname)), std::runtime_error(format(t_why, t_where, t_fname)),
reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname) reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname)
{ } { }
eval_error(const std::string &t_why) throw() eval_error(const std::string &t_why) noexcept
: std::runtime_error("Error: \"" + t_why + "\" "), : std::runtime_error("Error: \"" + t_why + "\" "),
reason(t_why) reason(t_why)
{} {}
virtual ~eval_error() throw() {} virtual ~eval_error() noexcept {}
private: private:
static std::string format(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) static std::string format(const std::string &t_why, const File_Position &t_where, const std::string &t_fname)
@@ -98,11 +98,11 @@ namespace chaiscript
* Errors generated when loading a file * Errors generated when loading a file
*/ */
struct file_not_found_error : public std::runtime_error { struct file_not_found_error : public std::runtime_error {
file_not_found_error(const std::string &t_filename) throw() file_not_found_error(const std::string &t_filename) noexcept
: std::runtime_error("File Not Found: " + t_filename) : std::runtime_error("File Not Found: " + t_filename)
{ } { }
virtual ~file_not_found_error() throw() {} virtual ~file_not_found_error() noexcept {}
}; };
} }

View File

@@ -35,12 +35,12 @@ namespace chaiscript
/// \brief Thrown if an error occurs while attempting to load a binary module /// \brief Thrown if an error occurs while attempting to load a binary module
struct load_module_error : std::runtime_error struct load_module_error : std::runtime_error
{ {
load_module_error(const std::string &t_reason) throw() load_module_error(const std::string &t_reason) noexcept
: std::runtime_error(t_reason) : std::runtime_error(t_reason)
{ {
} }
virtual ~load_module_error() throw() virtual ~load_module_error() noexcept
{ {
} }
}; };

View File

@@ -1,2 +1,2 @@
var prod = bind(foldl, _, `*`, 1.0) auto prod = bind(foldl, _, `*`, 1.0)
assert_equal(60, prod([3, 4, 5])) assert_equal(60, prod([3, 4, 5]))

View File

@@ -6,11 +6,11 @@ def add(x, y)
assert_equal(2, add.get_arity()); assert_equal(2, add.get_arity());
var b = bind(add, 2, _); auto b = bind(add, 2, _);
assert_equal(1, b.get_arity()); assert_equal(1, b.get_arity());
var c = bind(b, 3); auto c = bind(b, 3);
assert_equal(0, c.get_arity()); assert_equal(0, c.get_arity());
@@ -22,13 +22,13 @@ def concat2(a,b,c,d)
return to_string(a) + to_string(b) + to_string(c) + to_string(d); return to_string(a) + to_string(b) + to_string(c) + to_string(d);
} }
var d = bind(concat2, _, " Hello ", _, " World"); auto d = bind(concat2, _, " Hello ", _, " World");
assert_equal(2, d.get_arity()); assert_equal(2, d.get_arity());
assert_equal("1 Hello 3 World", d(1,3)); assert_equal("1 Hello 3 World", d(1,3));
var e = bind(`<`, _, 5); auto e = bind(`<`, _, 5);
var types = e.get_param_types(); auto types = e.get_param_types();
assert_equal(2, types.size()); assert_equal(2, types.size());
assert_equal(true, types[0].bare_equal(bool_type)); assert_equal(true, types[0].bare_equal(bool_type));

View File

@@ -1,4 +1,4 @@
var i = 0 auto i = 0
while (i < 10) { while (i < 10) {
if (++i == 5) { if (++i == 5) {
break break

View File

@@ -3,5 +3,5 @@ assert_equal(false, 1.is_var_reference());
assert_equal(true, 1.is_var_pointer()); assert_equal(true, 1.is_var_pointer());
assert_equal(false, 1.is_var_null()); assert_equal(false, 1.is_var_null());
assert_equal(false, 1.is_var_undef()); assert_equal(false, 1.is_var_undef());
var i; auto i;
assert_equal(true, i.is_var_undef()); assert_equal(true, i.is_var_undef());

View File

@@ -1,3 +1,3 @@
var v = collate(1, 2) auto v = collate(1, 2)
assert_equal(1, v[0]) assert_equal(1, v[0])
assert_equal(2, v[1]) assert_equal(2, v[1])

View File

@@ -1,4 +1,4 @@
var v = concat([1, 2], [3, 4]); auto v = concat([1, 2], [3, 4]);
assert_equal(4, v.size()); assert_equal(4, v.size());
assert_equal(1, v[0]); assert_equal(1, v[0]);

View File

@@ -1,4 +1,4 @@
var a = [1,2,3, [4,5,6] ] auto a = [1,2,3, [4,5,6] ]
assert_equal(a[3][0], 4) assert_equal(a[3][0], 4)
@@ -6,6 +6,6 @@ assert_equal(a[3][0], 4)
def Test::Test() { this.a = [1,2,3]; } def Test::Test() { this.a = [1,2,3]; }
attr Test::a; attr Test::a;
var t = Test(); auto t = Test();
assert_equal(t.a[0], 1) assert_equal(t.a[0], 1)

View File

@@ -6,6 +6,6 @@ assert_equal(get_arity.get_contained_functions().size(), 0);
assert_equal(get_arity.get_arity(), 1); assert_equal(get_arity.get_arity(), 1);
assert_equal(get_arity.get_param_types().size(), 2); assert_equal(get_arity.get_param_types().size(), 2);
var paramtypes = get_arity.get_param_types(); auto paramtypes = get_arity.get_param_types();
assert_equal(true, paramtypes[1].bare_equal(Function_type)); assert_equal(true, paramtypes[1].bare_equal(Function_type));

View File

@@ -17,7 +17,7 @@ int main()
chaiscript::ChaiScript chai; chaiscript::ChaiScript chai;
chai("attr bob::z; def bob::bob() { this.z = 10 }; var x = bob()"); chai("attr bob::z; def bob::bob() { this.z = 10 }; auto x = bob()");
chaiscript::dispatch::Dynamic_Object &mydo = chai.eval<chaiscript::dispatch::Dynamic_Object &>("x"); chaiscript::dispatch::Dynamic_Object &mydo = chai.eval<chaiscript::dispatch::Dynamic_Object &>("x");

View File

@@ -1,4 +1,4 @@
var x=.5 auto x=.5
assert_equal(.5, x) assert_equal(.5, x)
var y=-.5 auto y=-.5
assert_equal(-.5, y) assert_equal(-.5, y)

View File

@@ -20,7 +20,7 @@ def func()
def doing() def doing()
{ {
for (var i = 0; i < 10; ++i) for (auto i = 0; i < 10; ++i)
{ {
func(); func();
} }
@@ -34,6 +34,6 @@ def while_doing()
} }
} }
var f = fun() { while_doing(); } auto f = fun() { while_doing(); }
assert_equal(get_eval_error(f).call_stack.size(), 16) assert_equal(get_eval_error(f).call_stack.size(), 16)

View File

@@ -1,4 +1,4 @@
var x = 1 auto x = 1
try { try {
throw(x) throw(x)
x = 2 x = 2

View File

@@ -1,4 +1,4 @@
var finallyone = false; auto finallyone = false;
try { try {
throw(3) throw(3)
@@ -12,9 +12,9 @@ finally {
assert_equal(true, finallyone); assert_equal(true, finallyone);
var try2 = false; auto try2 = false;
var catch2 = false; auto catch2 = false;
var finally2 = false; auto finally2 = false;
try { try {

View File

@@ -1,6 +1,6 @@
var results = []; auto results = [];
for (var i = 2; i < 6; ++i) { for (auto i = 2; i < 6; ++i) {
try { try {
throw(i) throw(i)
} }

View File

@@ -1,6 +1,6 @@
var ret = [] auto ret = []
for (var i = 0; i < 5; ++i) { for (auto i = 0; i < 5; ++i) {
ret.push_back(i); ret.push_back(i);
} }

View File

@@ -1,3 +1,3 @@
var v = [1,2,3]; auto v = [1,2,3];
var r = range(v); auto r = range(v);
for_each(r, fun(x) { assert_equal(true, x>0); } ) for_each(r, fun(x) { assert_equal(true, x>0); } )

View File

@@ -1,4 +1,4 @@
// Don't bother checking the output from this one, just makes sure it executes // Don't bother checking the output from this one, just makes sure it executes
var v = [1,2,3]; auto v = [1,2,3];
var r = retro(range(v)); auto r = retro(range(v));
for_each(r, print) for_each(r, print)

View File

@@ -31,7 +31,7 @@ assert_equal(test_fun.get_arity(), 1);
assert_equal(test_fun.get_contained_functions.size(), 1); assert_equal(test_fun.get_contained_functions.size(), 1);
assert_equal(test_fun.get_param_types().size(), 2); assert_equal(test_fun.get_param_types().size(), 2);
assert_equal(test_fun, test_fun); assert_equal(test_fun, test_fun);
var test_fun_types = test_fun.get_param_types(); auto test_fun_types = test_fun.get_param_types();
assert_equal(true, test_fun_types[0].bare_equal(Object_type)); assert_equal(true, test_fun_types[0].bare_equal(Object_type));
assert_equal(true, test_fun_types[1].bare_equal(int_type)); assert_equal(true, test_fun_types[1].bare_equal(int_type));
@@ -42,7 +42,7 @@ assert_equal(2, `==`.get_arity());
// < should be the merging of two functions bool <(PODObject, PODObject) and bool <(string, string) // < should be the merging of two functions bool <(PODObject, PODObject) and bool <(string, string)
// we want to peel it apart and make sure that's true // we want to peel it apart and make sure that's true
var types = `<`.get_param_types(); auto types = `<`.get_param_types();
assert_equal(3, types.size()); assert_equal(3, types.size());
assert_equal(true, types[0].bare_equal(bool_type)); assert_equal(true, types[0].bare_equal(bool_type));
assert_equal(true, types[1].bare_equal(Object_type)); assert_equal(true, types[1].bare_equal(Object_type));
@@ -62,7 +62,7 @@ assert_equal(true, with_guard.has_guard());
assert_equal(false, without_guard.has_guard()); assert_equal(false, without_guard.has_guard());
assert_equal(2, group_guard.get_contained_functions().size()); assert_equal(2, group_guard.get_contained_functions().size());
var group = group_guard.get_contained_functions(); auto group = group_guard.get_contained_functions();
assert_equal(true, group[0].has_guard()) assert_equal(true, group[0].has_guard())
assert_equal(false, group[1].has_guard()) assert_equal(false, group[1].has_guard())
@@ -70,7 +70,7 @@ assert_equal(false, group[1].has_guard())
assert_throws("Function does not have a guard", fun() { group[0].get_guard(); } ); assert_throws("Function does not have a guard", fun() { group[0].get_guard(); } );
assert_throws("Function does not have a guard", fun() { without_guard.get_guard(); } ); assert_throws("Function does not have a guard", fun() { without_guard.get_guard(); } );
var guard = with_guard.get_guard(); auto guard = with_guard.get_guard();
assert_equal(false, guard.has_guard()); assert_equal(false, guard.has_guard());
assert_throws("Function does not have a guard", fun() { guard.get_guard(); } ); assert_throws("Function does not have a guard", fun() { guard.get_guard(); } );

View File

@@ -22,7 +22,7 @@ int main()
chai.add(chaiscript::fun(&test_two), "test_fun"); chai.add(chaiscript::fun(&test_two), "test_fun");
int res1 = chai.eval<int>("test_fun(1)"); int res1 = chai.eval<int>("test_fun(1)");
int res2 = chai.eval<int>("var i = 1; test_fun(i)"); int res2 = chai.eval<int>("auto i = 1; test_fun(i)");
int res3 = chai.eval<int>("test_fun(\"bob\")"); int res3 = chai.eval<int>("test_fun(\"bob\")");
int res4 = chai.eval<int>("test_fun(\"hi\")"); int res4 = chai.eval<int>("test_fun(\"hi\")");

View File

@@ -1,3 +1,3 @@
var x = `+` auto x = `+`
x = `-` x = `-`
assert_equal(1, x(5,4)) assert_equal(1, x(5,4))

View File

@@ -1,4 +1,4 @@
var t = false; auto t = false;
if (true) { if (true) {
t = true; t = true;

View File

@@ -1,6 +1,6 @@
var i = 3 auto i = 3
var b1 = false; auto b1 = false;
var b2 = false; auto b2 = false;
if (i == 2) { if (i == 2) {
b1 = true; b1 = true;

View File

@@ -1,8 +1,8 @@
var b1 = false; auto b1 = false;
var b2 = false; auto b2 = false;
var b3 = false; auto b3 = false;
var i = 3 auto i = 3
if (i == 2) { if (i == 2) {
b1 = true; b1 = true;
} }

View File

@@ -1,5 +1,5 @@
var i = 3 auto i = 3
var b = false auto b = false
if (i == 2) { if (i == 2) {
assert_equal(false, true) assert_equal(false, true)
} }

View File

@@ -3,7 +3,7 @@
def Bob::bob3() { return [1,2,3]; } def Bob::bob3() { return [1,2,3]; }
def Bob::Bob() {} def Bob::Bob() {}
var b = Bob(); auto b = Bob();
assert_equal(b.bob3()[0], 1); assert_equal(b.bob3()[0], 1);

View File

@@ -1,7 +1,7 @@
load_module("test_module") load_module("test_module")
var t0 = TestBaseType() auto t0 = TestBaseType()
var t = TestDerivedType(); auto t = TestDerivedType();
assert_equal(t0.func(), 0); assert_equal(t0.func(), 0);
assert_equal(t.func(), 1); assert_equal(t.func(), 1);

View File

@@ -1,3 +1,3 @@
var bob = 5.5 auto bob = 5.5
assert_equal("5.5", "${bob}") assert_equal("5.5", "${bob}")
assert_equal("val: 8 and 8", "val: ${5.5 + 2.5} and ${bob + 2.5}") assert_equal("val: 8 and 8", "val: ${5.5 + 2.5} and ${bob + 2.5}")

View File

@@ -1 +1 @@
assert_throws("Invalid function reassignment", fun() { var x = 5; x = `-`; } ); assert_throws("Invalid function reassignment", fun() { auto x = 5; x = `-`; } );

View File

@@ -1,4 +1,4 @@
var i; auto i;
assert_equal(true, i.is_var_undef()); assert_equal(true, i.is_var_undef());
i = 5; i = 5;
assert_equal(false, i.is_var_undef()); assert_equal(false, i.is_var_undef());

View File

@@ -1,2 +1,2 @@
var bob = fun(x) { x + 1 } auto bob = fun(x) { x + 1 }
assert_equal(4, bob(3)); assert_equal(4, bob(3));

View File

@@ -1,6 +1,6 @@
load_module("stl_extra") load_module("stl_extra")
var x = List() auto x = List()
x.push_back(3) x.push_back(3)
x.push_back("A") x.push_back("A")

View File

@@ -1,6 +1,6 @@
load_module("stl_extra") load_module("stl_extra")
var x = List() auto x = List()
x.push_front(3) x.push_front(3)
x.push_front("A") x.push_front("A")

View File

@@ -1,7 +1,7 @@
var total = 0 auto total = 0
for (var i = 0; i < 10; ++i) { for (auto i = 0; i < 10; ++i) {
for (var j = 0; j < 10; ++j) { for (auto j = 0; j < 10; ++j) {
total += 1 total += 1
} }
} }

View File

@@ -1,2 +1,2 @@
var x = ["bob":2, "fred":3] auto x = ["bob":2, "fred":3]
assert_equal(3, x["fred"]) assert_equal(3, x["fred"])

View File

@@ -1,3 +1,3 @@
var x = ["bob":1, "fred":2] auto x = ["bob":1, "fred":2]
assert_equal(2, x.size()); assert_equal(2, x.size());

View File

@@ -1,3 +1,3 @@
var i = 3 auto i = 3
assert_equal(2, --i) assert_equal(2, --i)
assert_equal(2, i) assert_equal(2, i)

View File

@@ -1,3 +1,3 @@
var i = 3 auto i = 3
assert_equal(4, ++i) assert_equal(4, ++i)
assert_equal(4, i) assert_equal(4, i)

View File

@@ -8,5 +8,5 @@ def Vector3::Vector3(x, y, z) {
this.z = z this.z = z
} }
var v = Vector3(1,2,3); auto v = Vector3(1,2,3);
assert_equal(1, v.x); assert_equal(1, v.x);

View File

@@ -1,9 +1,9 @@
var x = [1, 2, auto x = [1, 2,
3, 4] 3, 4]
assert_equal(1, x[0]) assert_equal(1, x[0])
var y = map(x, auto y = map(x,
fun(x) { x + 1 }) fun(x) { x + 1 })
assert_equal(2, y[0]) assert_equal(2, y[0])

View File

@@ -1,6 +1,6 @@
attr bob::z attr bob::z
def bob::bob() { this.z = 10 } def bob::bob() { this.z = 10 }
var x = bob() auto x = bob()
def bob::fred(x) { this.z - x } def bob::fred(x) { this.z - x }
assert_equal(7, x.fred(3)) assert_equal(7, x.fred(3))

View File

@@ -1,10 +1,10 @@
attr bob::z attr bob::z
def bob::bob() { } def bob::bob() { }
var x = bob(); auto x = bob();
x.z = 10; x.z = 10;
var y = clone(x); auto y = clone(x);
y.z = 20; y.z = 20;
assert_equal(10, x.z) assert_equal(10, x.z)

View File

@@ -3,8 +3,8 @@ attr bob::val
def bob::bob(x) : x < 10 { this.val = "Less Than Ten: " + x.to_string(); } def bob::bob(x) : x < 10 { this.val = "Less Than Ten: " + x.to_string(); }
def bob::bob(x) { this.val = "Any Other Value: " + x.to_string(); } def bob::bob(x) { this.val = "Any Other Value: " + x.to_string(); }
var b = bob(12) auto b = bob(12)
var c = bob(3) auto c = bob(3)
assert_equal("Any Other Value: 12", b.val ) assert_equal("Any Other Value: 12", b.val )
assert_equal("Less Than Ten: 3", c.val ) assert_equal("Less Than Ten: 3", c.val )

View File

@@ -42,15 +42,15 @@ int main()
int count = chai.eval<int>("count()"); int count = chai.eval<int>("count()");
int count2 = chai.eval<int>("var i = 0; { var t = Test(); } return i;"); int count2 = chai.eval<int>("auto i = 0; { auto t = Test(); } return i;");
int count3 = chai.eval<int>("var i = 0; { var t = Test(); i = count(); } return i;"); int count3 = chai.eval<int>("auto i = 0; { auto t = Test(); i = count(); } return i;");
int count4 = chai.eval<int>("var i = 0; { var t = Test(); { var t2 = Test(); i = count(); } } return i;"); int count4 = chai.eval<int>("auto i = 0; { auto t = Test(); { auto t2 = Test(); i = count(); } } return i;");
int count5 = chai.eval<int>("var i = 0; { var t = Test(); { var t2 = Test(); } i = count(); } return i;"); int count5 = chai.eval<int>("auto i = 0; { auto t = Test(); { auto t2 = Test(); } i = count(); } return i;");
int count6 = chai.eval<int>("var i = 0; { var t = Test(); { var t2 = Test(); } } i = count(); return i;"); int count6 = chai.eval<int>("auto i = 0; { auto t = Test(); { auto t2 = Test(); } } i = count(); return i;");
if (count == 0 if (count == 0
&& count2 == 0 && count2 == 0

View File

@@ -2,6 +2,6 @@ def bob::bob() { }
def bob::fred(e) : e < 10 { assert_equal(true, e<10) } def bob::fred(e) : e < 10 { assert_equal(true, e<10) }
def bob::fred(e) { assert_equal(true, e >= 10) } def bob::fred(e) { assert_equal(true, e >= 10) }
var b = bob() auto b = bob()
b.fred(3) b.fred(3)
b.fred(12) b.fred(12)

View File

@@ -1,8 +1,8 @@
def Bob::`+`(y) { this.x + y.x } def Bob::`+`(y) { this.x + y.x }
def Bob::Bob() { } def Bob::Bob() { }
attr Bob::x attr Bob::x
var b = Bob() auto b = Bob()
var c = Bob() auto c = Bob()
b.x = 4 b.x = 4
c.x = 5 c.x = 5

View File

@@ -1,8 +1,8 @@
def Bob::Bob() { } def Bob::Bob() { }
attr Bob::x attr Bob::x
def `-`(a, b) : is_type(a, "Bob") && is_type(b, "Bob") { a.x - b.x } def `-`(a, b) : is_type(a, "Bob") && is_type(b, "Bob") { a.x - b.x }
var b = Bob() auto b = Bob()
var c = Bob() auto c = Bob()
b.x = 4 b.x = 4
c.x = 5 c.x = 5

View File

@@ -1,6 +1,6 @@
var i = 1.0; auto i = 1.0;
var j = 2.0; auto j = 2.0;
var k = 3.0; auto k = 3.0;
assert_equal(3, i + j) assert_equal(3, i + j)
assert_equal(1.0, +i) assert_equal(1.0, +i)

View File

@@ -1,6 +1,6 @@
var i = 1; auto i = 1;
var j = 2; auto j = 2;
var k = 3; auto k = 3;
assert_equal(3, i + j); assert_equal(3, i + j);
assert_equal(1, +i); assert_equal(1, +i);

View File

@@ -1,4 +1,4 @@
var p = Pair("Hello", "World") auto p = Pair("Hello", "World")
assert_equal(p.first, "Hello") assert_equal(p.first, "Hello")
assert_equal(p.second, "World") assert_equal(p.second, "World")

View File

@@ -1,8 +1,8 @@
load_module("test_module") load_module("test_module")
var i = 1; auto i = 1;
var t0 = TestBaseType(i); auto t0 = TestBaseType(i);
var t1 = TestBaseType(get_new_int()) auto t1 = TestBaseType(get_new_int())

View File

@@ -1,3 +1,3 @@
var x = var y = 4 auto x = auto y = 4
assert_equal(4, x); assert_equal(4, x);
assert_equal(4, y); assert_equal(4, y);

View File

@@ -1,4 +1,4 @@
var x = [1, 2, 3, 4] auto x = [1, 2, 3, 4]
var r = range(x) auto r = range(x)
r.pop_front() r.pop_front()
assert_equal(2, r.front()); assert_equal(2, r.front());

View File

@@ -1,4 +1,4 @@
var x = [1, 2, 3, 4] auto x = [1, 2, 3, 4]
var r = range(x) auto r = range(x)
r.pop_back() r.pop_back()
assert_equal(3, r.back()) assert_equal(3, r.back())

View File

@@ -1,4 +1,4 @@
var v = [1,2,"hi", "world", 5.5] auto v = [1,2,"hi", "world", 5.5]
assert_equal(true, v.contains(5.5)) assert_equal(true, v.contains(5.5))
assert_equal(false, v.contains(0)) assert_equal(false, v.contains(0))
assert_equal(false, v.contains(1, lt)) assert_equal(false, v.contains(1, lt))

View File

@@ -1,6 +1,6 @@
var v = [2, 1, "Hi", 5.5] auto v = [2, 1, "Hi", 5.5]
var r = v.find("Hi"); auto r = v.find("Hi");
assert_equal("Hi", r.front()) assert_equal("Hi", r.front())
var r2 = v.find(2, `<`); auto r2 = v.find(2, `<`);
assert_equal(1, r2.front()); assert_equal(1, r2.front());

View File

@@ -1,5 +1,5 @@
var i = 3 auto i = 3
var j := i auto j := i
j = 4 j = 4
assert_equal(4, i) assert_equal(4, i)

View File

@@ -1,14 +1,14 @@
load_module("reflection") load_module("reflection")
var parser := ChaiScript_Parser() auto parser := ChaiScript_Parser()
var parse_success = parser.parse("3 + 4", "INPUT") auto parse_success = parser.parse("3 + 4", "INPUT")
var a := parser.ast() auto a := parser.ast()
assert_equal(eval(a), 7) assert_equal(eval(a), 7)
var childs := a.children.front().children auto childs := a.children.front().children
var node := childs[0] auto node := childs[0]
var parser2 := ChaiScript_Parser() auto parser2 := ChaiScript_Parser()
parser2.parse("9", "INPUT") parser2.parse("9", "INPUT")
@@ -30,7 +30,7 @@ assert_equal(false, `+`.has_parse_tree());
assert_throws("Function does not have a parse tree", fun() { `+`.get_parse_tree(); } ); assert_throws("Function does not have a parse tree", fun() { `+`.get_parse_tree(); } );
var parsetree := my_fun.get_parse_tree(); auto parsetree := my_fun.get_parse_tree();
assert_equal(1, eval(parsetree)); assert_equal(1, eval(parsetree));

View File

@@ -1,4 +1,4 @@
var x = [1, 2, 3, 4] auto x = [1, 2, 3, 4]
var r = retro(range(x)) auto r = retro(range(x))
r.pop_front() r.pop_front()
assert_equal(3, r.front()) assert_equal(3, r.front())

View File

@@ -1,7 +1,7 @@
var x = [1, 2, 3, 4] auto x = [1, 2, 3, 4]
var r = retro(range(x)) auto r = retro(range(x))
r.pop_back() r.pop_back()
var r2 = retro(r) auto r2 = retro(r)
r2.pop_front() r2.pop_front()
assert_equal(2, r.back()) assert_equal(2, r.back())
assert_equal(3, r2.front()) assert_equal(3, r2.front())

View File

@@ -1,4 +1,4 @@
var caught = false auto caught = false
try { try {
throw(runtime_error("error")) throw(runtime_error("error"))

View File

@@ -35,9 +35,9 @@ int main()
chaiscript::ChaiScript chai; chaiscript::ChaiScript chai;
chai.add(m); chai.add(m);
if (chai.eval<std::string>("var t = Test(); t.function2(); ") == "Function2" if (chai.eval<std::string>("auto t = Test(); t.function2(); ") == "Function2"
&& chai.eval<std::string>("var t = Test(); t.functionOverload(1); ") == "int" && chai.eval<std::string>("auto t = Test(); t.functionOverload(1); ") == "int"
&& chai.eval<std::string>("var t = Test(); t.functionOverload(1.1); ") == "double") && chai.eval<std::string>("auto t = Test(); t.functionOverload(1.1); ") == "double")
{ {
chai.eval("t = Test();"); chai.eval("t = Test();");
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@@ -1,2 +1,2 @@
var x = [1, 2, 3] auto x = [1, 2, 3]
assert_equal(3, x[2]) assert_equal(3, x[2])

View File

@@ -1,3 +1,3 @@
var x = [1, 2, 3] auto x = [1, 2, 3]
x.erase_at(1) x.erase_at(1)
assert_equal([1,3], x); assert_equal([1,3], x);

View File

@@ -1,2 +1,2 @@
var x = [1, 2, 3] auto x = [1, 2, 3]
assert_equal(3, x.size()) assert_equal(3, x.size())

View File

@@ -1,3 +1,3 @@
var x = [1, 2, 3] auto x = [1, 2, 3]
x.insert_at(1, 6) x.insert_at(1, 6)
assert_equal([1,6,2,3], x); assert_equal([1,6,2,3], x);

View File

@@ -1,2 +1,2 @@
var x = [1] auto x = [1]
assert_equal(1, x[0]) assert_equal(1, x[0])

View File

@@ -1,4 +1,4 @@
var x = [1, 2] auto x = [1, 2]
x.push_back(3) x.push_back(3)
assert_equal(3, x.size()) assert_equal(3, x.size())
assert_equal(3, x.back()) assert_equal(3, x.back())

View File

@@ -1,4 +1,4 @@
var bob = [] auto bob = []
bob.push_back(3) bob.push_back(3)
assert_equal(1, bob.size()) assert_equal(1, bob.size())
assert_equal(3, bob.front()) assert_equal(3, bob.front())

View File

@@ -1,4 +1,4 @@
var z = zip([1, 2, 3], [4, 5, 6]) auto z = zip([1, 2, 3], [4, 5, 6])
assert_equal([1,4], z[0]) assert_equal([1,4], z[0])
assert_equal([2,5], z[1]) assert_equal([2,5], z[1])

View File

@@ -1,3 +1,3 @@
var z = zip_with(`+`, [1, 2, 3], [4, 5, 6]) auto z = zip_with(`+`, [1, 2, 3], [4, 5, 6])
assert_equal([5,7,9], z) assert_equal([5,7,9], z)