Better ranged vector, now generated from a new prelude function
This commit is contained in:
parent
cda30f3ed7
commit
a76cc16922
@ -255,51 +255,12 @@ namespace chaiscript
|
|||||||
break;
|
break;
|
||||||
case (Token_Type::Inline_Range) : {
|
case (Token_Type::Inline_Range) : {
|
||||||
try {
|
try {
|
||||||
retval = dispatch(ss.get_function("Vector"), dispatchkit::Param_List_Builder());
|
retval = dispatch(ss.get_function("generate_range"), dispatchkit::Param_List_Builder()
|
||||||
if (node->children.size() > 0) {
|
<< eval_token(ss, node->children[0]->children[0]->children[0])
|
||||||
dispatchkit::Boxed_Value range_iter = dispatch(ss.get_function("clone"), dispatchkit::Param_List_Builder() << eval_token(ss, node->children[0]->children[0]->children[0]));
|
<< eval_token(ss, node->children[0]->children[0]->children[1]));
|
||||||
dispatchkit::Boxed_Value range_stop = eval_token(ss, node->children[0]->children[0]->children[1]);
|
|
||||||
|
|
||||||
dispatchkit::Boxed_Value not_equal;
|
|
||||||
|
|
||||||
bool cond = true;
|
|
||||||
try {
|
|
||||||
not_equal = dispatch(ss.get_function("!="), dispatchkit::Param_List_Builder() << range_iter << range_stop);
|
|
||||||
cond = dispatchkit::boxed_cast<bool &>(not_equal);
|
|
||||||
}
|
|
||||||
catch (std::exception &e) {
|
|
||||||
throw EvalError("Range values missing != comparison", node->children[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch(ss.get_function("push_back"), dispatchkit::Param_List_Builder() << retval << range_iter);
|
|
||||||
not_equal = dispatch(ss.get_function("!="), dispatchkit::Param_List_Builder() << range_iter << range_stop);
|
|
||||||
try {
|
|
||||||
cond = dispatchkit::boxed_cast<bool &>(not_equal);
|
|
||||||
}
|
|
||||||
catch (std::exception &e) {
|
|
||||||
throw EvalError("Range values missing != comparison", node->children[0]);
|
|
||||||
}
|
|
||||||
while (cond) {
|
|
||||||
try {
|
|
||||||
range_iter = dispatch(ss.get_function("clone"), dispatchkit::Param_List_Builder() << range_iter);
|
|
||||||
range_iter = dispatch(ss.get_function("++"), dispatchkit::Param_List_Builder() << range_iter);
|
|
||||||
dispatch(ss.get_function("push_back"), dispatchkit::Param_List_Builder() << retval << range_iter);
|
|
||||||
not_equal = dispatch(ss.get_function("!="), dispatchkit::Param_List_Builder() << range_iter << range_stop);
|
|
||||||
try {
|
|
||||||
cond = dispatchkit::boxed_cast<bool &>(not_equal);
|
|
||||||
}
|
|
||||||
catch (std::exception &e) {
|
|
||||||
throw EvalError("Range values missing != comparison", node->children[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const dispatchkit::dispatch_error &inner_e) {
|
|
||||||
throw EvalError("Can not find appropriate range increment", node->children[0]->children[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (const dispatchkit::dispatch_error &e) {
|
catch (const dispatchkit::dispatch_error &e) {
|
||||||
throw EvalError("Can not find appropriate 'Vector()'", node);
|
throw EvalError("Unable to generate range vector", node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -134,6 +134,16 @@ def filter(container, f) : call_exists(range, container) { \n\
|
|||||||
} \n\
|
} \n\
|
||||||
retval \n\
|
retval \n\
|
||||||
} \n\
|
} \n\
|
||||||
|
def generate_range(x, y) { \n\
|
||||||
|
var i = x; \n\
|
||||||
|
var retval = Vector(); \n\
|
||||||
|
retval.push_back(clone(i)); \n\
|
||||||
|
while (i != y) { \n\
|
||||||
|
++i; \n\
|
||||||
|
retval.push_back(clone(i)); \n\
|
||||||
|
} \n\
|
||||||
|
retval \n\
|
||||||
|
} \n\
|
||||||
def collate(x, y) { \n\
|
def collate(x, y) { \n\
|
||||||
[x, y] \n\
|
[x, y] \n\
|
||||||
} \n\
|
} \n\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user