Change equation to clone rhs. Add := ref equation. Failed clones will ref copy
This commit is contained in:
parent
5f96b39c08
commit
27f6ec7b70
@ -71,14 +71,65 @@ namespace chaiscript
|
|||||||
retval = eval_token(ss, node->children.back());
|
retval = eval_token(ss, node->children.back());
|
||||||
if (node->children.size() > 1) {
|
if (node->children.size() > 1) {
|
||||||
for (i = node->children.size()-3; ((int)i) >= 0; i -= 2) {
|
for (i = node->children.size()-3; ((int)i) >= 0; i -= 2) {
|
||||||
dispatchkit::Param_List_Builder plb;
|
if (node->children[i+1]->text == "=") {
|
||||||
plb << eval_token(ss, node->children[i]);
|
dispatchkit::Boxed_Value lhs = eval_token(ss, node->children[i]);
|
||||||
plb << retval;
|
if (lhs.is_unknown() || dispatchkit::Bootstrap::type_match(lhs, retval)) {
|
||||||
try {
|
try {
|
||||||
retval = dispatch(ss.get_function(node->children[i+1]->text), plb);
|
retval = dispatch(ss.get_function("clone"), dispatchkit::Param_List_Builder() << retval);
|
||||||
|
dispatchkit::Param_List_Builder plb;
|
||||||
|
plb << lhs;
|
||||||
|
plb << retval;
|
||||||
|
try {
|
||||||
|
retval = dispatch(ss.get_function(node->children[i+1]->text), plb);
|
||||||
|
}
|
||||||
|
catch(const dispatchkit::dispatch_error &e){
|
||||||
|
throw EvalError("Can not find appropriate '" + node->children[i+1]->text + "'", node->children[i+1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const dispatchkit::dispatch_error &e){
|
||||||
|
//throw EvalError("Can not clone right hand side of equation", node->children[i+1]);
|
||||||
|
dispatchkit::Param_List_Builder plb;
|
||||||
|
plb << lhs;
|
||||||
|
plb << retval;
|
||||||
|
try {
|
||||||
|
retval = dispatch(ss.get_function("="), plb);
|
||||||
|
}
|
||||||
|
catch(const dispatchkit::dispatch_error &e){
|
||||||
|
throw EvalError("Can not find appropriate '" + node->children[i+1]->text + "'", node->children[i+1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw EvalError("Mismatched types in equation", node->children[i+1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(const dispatchkit::dispatch_error &e){
|
else if (node->children[i+1]->text == ":=") {
|
||||||
throw EvalError("Can not find appropriate '" + node->children[i+1]->text + "'", node->children[i+1]);
|
dispatchkit::Boxed_Value lhs = eval_token(ss, node->children[i]);
|
||||||
|
if (lhs.is_unknown() || dispatchkit::Bootstrap::type_match(lhs, retval)) {
|
||||||
|
dispatchkit::Param_List_Builder plb;
|
||||||
|
plb << lhs;
|
||||||
|
plb << retval;
|
||||||
|
try {
|
||||||
|
retval = dispatch(ss.get_function("="), plb);
|
||||||
|
}
|
||||||
|
catch(const dispatchkit::dispatch_error &e){
|
||||||
|
throw EvalError("Can not find appropriate '" + node->children[i+1]->text + "'", node->children[i+1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw EvalError("Mismatched types in equation", node->children[i+1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dispatchkit::Param_List_Builder plb;
|
||||||
|
plb << eval_token(ss, node->children[i]);
|
||||||
|
plb << retval;
|
||||||
|
try {
|
||||||
|
retval = dispatch(ss.get_function(node->children[i+1]->text), plb);
|
||||||
|
}
|
||||||
|
catch(const dispatchkit::dispatch_error &e){
|
||||||
|
throw EvalError("Can not find appropriate '" + node->children[i+1]->text + "'", node->children[i+1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1180,7 +1180,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
if (Expression()) {
|
if (Expression()) {
|
||||||
retval = true;
|
retval = true;
|
||||||
if (Symbol("=", true) || Symbol("+=", true) || Symbol("-=", true) || Symbol("*=", true) || Symbol("/=", true)) {
|
if (Symbol("=", true) || Symbol(":=", true) || Symbol("+=", true) || Symbol("-=", true) || Symbol("*=", true) || Symbol("/=", true)) {
|
||||||
if (!Equation()) {
|
if (!Equation()) {
|
||||||
throw Parse_Error("Incomplete equation", match_stack.back());
|
throw Parse_Error("Incomplete equation", match_stack.back());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user