Change equation to clone rhs. Add := ref equation. Failed clones will ref copy
This commit is contained in:
parent
5f96b39c08
commit
27f6ec7b70
@ -71,6 +71,56 @@ namespace chaiscript
|
||||
retval = eval_token(ss, node->children.back());
|
||||
if (node->children.size() > 1) {
|
||||
for (i = node->children.size()-3; ((int)i) >= 0; i -= 2) {
|
||||
if (node->children[i+1]->text == "=") {
|
||||
dispatchkit::Boxed_Value lhs = eval_token(ss, node->children[i]);
|
||||
if (lhs.is_unknown() || dispatchkit::Bootstrap::type_match(lhs, retval)) {
|
||||
try {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
else if (node->children[i+1]->text == ":=") {
|
||||
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;
|
||||
@ -82,6 +132,7 @@ namespace chaiscript
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case (Token_Type::Var_Decl): {
|
||||
ss.add_object(node->children[0]->text, dispatchkit::Boxed_Value());
|
||||
|
@ -1180,7 +1180,7 @@ namespace chaiscript
|
||||
|
||||
if (Expression()) {
|
||||
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()) {
|
||||
throw Parse_Error("Incomplete equation", match_stack.back());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user