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

Conflicts:
	include/chaiscript/dispatchkit/bootstrap.hpp
This commit is contained in:
Jason Turner 2011-09-24 15:10:18 -06:00
commit e1e0561c7e
57 changed files with 83 additions and 78 deletions

View File

@ -406,7 +406,7 @@ namespace chaiscript
m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs"); m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs");
m->add(fun(&dispatch::Dynamic_Object::get_attr), "get_attr"); m->add(fun(&dispatch::Dynamic_Object::get_attr), "get_attr");
m->eval("def Dynamic_Object::clone() { auto &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() { auto &new_o = Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind([](new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }");
m->add(fun(&has_guard), "has_guard"); m->add(fun(&has_guard), "has_guard");
m->add(fun(&get_guard), "get_guard"); m->add(fun(&get_guard), "get_guard");

View File

@ -1119,7 +1119,11 @@ namespace chaiscript
size_t prev_stack_top = m_match_stack.size(); size_t prev_stack_top = m_match_stack.size();
if (Keyword("fun")) { //if (Keyword("fun")) {
if (Char('[')) {
if (!Char(']')) {
throw exception::eval_error("Closure list not currently supported", File_Position(m_line, m_col), *m_filename);
}
retval = true; retval = true;
if (Char('(')) { if (Char('(')) {
@ -1597,10 +1601,10 @@ namespace chaiscript
size_t prev_stack_top = m_match_stack.size(); size_t prev_stack_top = m_match_stack.size();
if (Char('[')) { if (Char('{')) {
retval = true; retval = true;
Container_Arg_List(); Container_Arg_List();
if (!Char(']')) { if (!Char('}')) {
throw exception::eval_error("Missing closing square bracket", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Missing closing square bracket", File_Position(m_line, m_col), *m_filename);
} }
if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) { if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) {

View File

@ -7,7 +7,7 @@
#ifndef CHAISCRIPT_PRELUDE_HPP_ #ifndef CHAISCRIPT_PRELUDE_HPP_
#define CHAISCRIPT_PRELUDE_HPP_ #define CHAISCRIPT_PRELUDE_HPP_
//Note, the expression "[x,y]" in "collate" is parsed as two separate expressions //Note, the expression "{x,y}" in "collate" is parsed as two separate expressions
//by C++, so CODE_STRING, takes two expressions and adds in the missing comma //by C++, so CODE_STRING, takes two expressions and adds in the missing comma
#define CODE_STRING(x, y) #x ", " #y #define CODE_STRING(x, y) #x ", " #y
@ -23,7 +23,7 @@ def to_string(x) : call_exists(first, x) && call_exists(second, x) { \n\
}\n\ }\n\
# to_string for containers\n\ # to_string for containers\n\
def to_string(x) : call_exists(range, x) && !x.is_type("string"){ \n\ def to_string(x) : call_exists(range, x) && !x.is_type("string"){ \n\
"[" + x.join(", ") + "]"; \n\ "{" + x.join(", ") + "}"; \n\
}\n\ }\n\
# Basic to_string function\n\ # Basic to_string function\n\
def to_string(x) { \n\ def to_string(x) { \n\
@ -259,7 +259,7 @@ def generate_range(x, y) { \n\
}\n\ }\n\
# Returns a new Vector with the first value to the second value as its elements\n\ # Returns a new Vector with the first value to the second value as its elements\n\
def collate(x, y) { \n\ def collate(x, y) { \n\
[x, y]; \n\ {x, y}; \n\
} \n\ } \n\
def zip_with(f, x, y, inserter) : call_exists(range, x) && call_exists(range, y) { \n\ def zip_with(f, x, y, inserter) : call_exists(range, x) && call_exists(range, y) { \n\
auto r_x = range(x); \n\ auto r_x = range(x); \n\
@ -305,10 +305,10 @@ def string::find_last_not_of(list) : is_type(list, "string") { \n\
int(find_last_not_of(this, list, -1)); \n\ int(find_last_not_of(this, list, -1)); \n\
} \n\ } \n\
def string::ltrim() { \n\ def string::ltrim() { \n\
drop_while(this, fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); \n\ drop_while(this, [](x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); \n\
} \n\ } \n\
def string::rtrim() { \n\ def string::rtrim() { \n\
reverse(drop_while(reverse(this), fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); \n\ reverse(drop_while(reverse(this), [](x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); \n\
} \n\ } \n\
def string::trim() { \n\ def string::trim() { \n\
ltrim(rtrim(this)); \n\ ltrim(rtrim(this)); \n\

View File

@ -1,2 +1,2 @@
assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 = 2 } ); assert_throws("Mismatched types in equation, lhs is const.", []() { 1 = 2 } );
assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 + 2 = 2 } ); assert_throws("Mismatched types in equation, lhs is const.", []() { 1 + 2 = 2 } );

View File

@ -1,2 +1,2 @@
auto 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

@ -1,4 +1,4 @@
auto 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 @@
//If the following succeeds, the test passes //If the following succeeds, the test passes
"Hello World".for_each(fun(x) { print(x) } ) "Hello World".for_each([](x) { print(x) } )

View File

@ -1,9 +1,9 @@
auto 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)
def Test::Test() { this.a = [1,2,3]; } def Test::Test() { this.a = {1,2,3}; }
attr Test::a; attr Test::a;
auto t = Test(); auto t = Test();

View File

@ -1 +1 @@
assert_equal([3,4], drop([1, 2, 3, 4], 2)) assert_equal({3,4}, drop({1, 2, 3, 4}, 2))

View File

@ -1 +1 @@
assert_equal([2, 3], drop_while([1, 2, 3], odd)) assert_equal({2, 3}, drop_while({1, 2, 3}, odd))

View File

@ -34,6 +34,6 @@ def while_doing()
} }
} }
auto f = fun() { while_doing(); } auto f = []() { 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 @@
auto results = []; auto results = {};
for (auto i = 2; i < 6; ++i) { for (auto i = 2; i < 6; ++i) {
try { try {
@ -31,4 +31,4 @@ catch {
results.push_back("defaultcatch"); results.push_back("defaultcatch");
} }
assert_equal(["c2: 2", "c2: 3", "c3: 4", "c3: 5", "defaultcatch"], results); assert_equal({"c2: 2", "c2: 3", "c3: 4", "c3: 5", "defaultcatch"}, results);

View File

@ -1 +1 @@
assert_equal([1,3], filter([1, 2, 3, 4], odd)) assert_equal({1,3}, filter({1, 2, 3, 4}, odd))

View File

@ -1 +1 @@
assert_equal(10, foldl([1, 2, 3, 4], `+`, 0)) assert_equal(10, foldl({1, 2, 3, 4}, `+`, 0))

View File

@ -1,7 +1,7 @@
auto ret = [] auto ret = {}
for (auto i = 0; i < 5; ++i) { for (auto i = 0; i < 5; ++i) {
ret.push_back(i); ret.push_back(i);
} }
assert_equal([0,1,2,3,4], ret); assert_equal({0,1,2,3,4}, ret);

View File

@ -1 +1 @@
for_each([1, 2, 3], print) for_each({1, 2, 3}, print)

View File

@ -1,3 +1,3 @@
auto v = [1,2,3]; auto v = {1,2,3};
auto r = range(v); auto r = range(v);
for_each(r, fun(x) { assert_equal(true, x>0); } ) for_each(r, [](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
auto v = [1,2,3]; auto v = {1,2,3};
auto r = retro(range(v)); auto r = retro(range(v));
for_each(r, print) for_each(r, print)

View File

@ -18,7 +18,7 @@ assert_equal(test_function, test_function);
assert_not_equal(test_function, `+`); assert_not_equal(test_function, `+`);
assert_equal(test_function.call([1]), 1); assert_equal(test_function.call({1}), 1);
// dynamic object function tests // dynamic object function tests
@ -67,10 +67,10 @@ 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())
assert_throws("Function does not have a guard", fun() { group[0].get_guard(); } ); assert_throws("Function does not have a guard", []() { 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", []() { without_guard.get_guard(); } );
auto 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", []() { guard.get_guard(); } );

View File

@ -1 +1 @@
assert_equal([1,2,3,4,5,6,7,8,9,10], generate_range(1, 10)) assert_equal({1,2,3,4,5,6,7,8,9,10}, generate_range(1, 10))

View File

@ -1,7 +1,7 @@
// tests more complex parses of the index operator // tests more complex parses of the index operator
def Bob::bob3() { return [1,2,3]; } def Bob::bob3() { return {1,2,3}; }
def Bob::Bob() {} def Bob::Bob() {}
auto b = Bob(); auto b = Bob();

View File

@ -1 +1 @@
assert_throws("Illegal const function assignment", fun() { clone = `-` } ); assert_throws("Illegal const function assignment", []() { clone = `-` } );

View File

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

View File

@ -1 +1 @@
assert_equal("1*2*3", join([1, 2, 3], "*")) assert_equal("1*2*3", join({1, 2, 3}, "*"))

View File

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

View File

@ -1,2 +1,2 @@
assert_throws("Parse failure", fun() { eval("[\"hello\":5,\"j\",\"k\"]") } ); assert_throws("Parse failure", []() { eval("{\"hello\":5,\"j\",\"k\"}") } );

View File

@ -1 +1 @@
assert_equal([true, false, true], map([1,2,3], odd)) assert_equal({true, false, true}, map({1,2,3}, odd))

View File

@ -1,2 +1,2 @@
auto 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 @@
auto x = ["bob":1, "fred":2] auto x = {"bob":1, "fred":2}
assert_equal(2, x.size()); assert_equal(2, x.size());

View File

@ -0,0 +1 @@
assert_equal(1, {"bob":1,"fred":2}["bob"])

View File

@ -1 +1 @@
assert_equal(6, [1, 2, 3].sum()) assert_equal(6, {1, 2, 3}.sum())

View File

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

View File

@ -13,4 +13,4 @@ assert_equal(0, i -= i)
assert_equal(3, j *= 1.5) assert_equal(3, j *= 1.5)
assert_equal(1.5, j /= 2) assert_equal(1.5, j /= 2)
assert_equal(2.5, j += 1) assert_equal(2.5, j += 1)
assert_throws("No modulous for float", fun() { k % 2 } ); assert_throws("No modulous for float", []() { k % 2 } );

View File

@ -1 +1 @@
assert_equal(24, product([1, 2, 3, 4])) assert_equal(24, product({1, 2, 3, 4}))

View File

@ -1,4 +1,4 @@
auto x = [1, 2, 3, 4] auto x = {1, 2, 3, 4}
auto 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 @@
auto x = [1, 2, 3, 4] auto x = {1, 2, 3, 4}
auto 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 @@
auto 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,4 +1,4 @@
auto v = [2, 1, "Hi", 5.5] auto v = {2, 1, "Hi", 5.5}
auto r = v.find("Hi"); auto r = v.find("Hi");
assert_equal("Hi", r.front()) assert_equal("Hi", r.front())

View File

@ -1 +1 @@
assert_equal([3,4,5,6], [3..6]) assert_equal({3,4,5,6}, {3..6})

View File

@ -1 +1 @@
assert_equal(10, reduce([1, 2, 3, 4], `+`)) assert_equal(10, reduce({1, 2, 3, 4}, `+`))

View File

@ -28,7 +28,7 @@ def my_fun()
assert_equal(true, my_fun.has_parse_tree()); assert_equal(true, my_fun.has_parse_tree());
assert_equal(false, `+`.has_parse_tree()); 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", []() { `+`.get_parse_tree(); } );
auto& parsetree = my_fun.get_parse_tree(); auto& parsetree = my_fun.get_parse_tree();

View File

@ -1,4 +1,4 @@
auto x = [1, 2, 3, 4] auto x = {1, 2, 3, 4}
auto 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,4 +1,4 @@
auto x = [1, 2, 3, 4] auto x = {1, 2, 3, 4}
auto r = retro(range(x)) auto r = retro(range(x))
r.pop_back() r.pop_back()
auto r2 = retro(r) auto r2 = retro(r)

View File

@ -1 +1 @@
assert_equal(10, sum([1, 2, 3, 4])) assert_equal(10, sum({1, 2, 3, 4}))

View File

@ -1 +1 @@
assert_equal(2, take([1, 2, 3, 4], 2).back()) assert_equal(2, take({1, 2, 3, 4}, 2).back())

View File

@ -1 +1 @@
assert_equal([1], take_while([1, 2, 3, 4], odd)) assert_equal({1}, take_while({1, 2, 3, 4}, odd))

View File

@ -1,2 +1,2 @@
auto 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 @@
auto 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 @@
auto 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 @@
auto 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 +1 @@
assert_equal(1, [1,2,3][0]) assert_equal(1, {1,2,3}[0])

View File

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

View File

@ -1 +1 @@
assert_equal(1, ([1,2,3])[0]) assert_equal(1, ({1,2,3})[0])

View File

@ -1,4 +1,4 @@
auto 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 @@
auto 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,5 +1,5 @@
auto 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])
assert_equal([3,6], z[2]) assert_equal({3,6}, z[2])

View File

@ -1,3 +1,3 @@
auto 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)