summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-03-03 01:17:21 -0600
committerJohn Wiegley <johnw@newartisans.com>2012-03-05 05:03:51 -0600
commitc8c2a17e282c2cbf3c0edb1b756e16be58328331 (patch)
treedecf0c8d24db423a5415668727da26a6897800be
parent35ace8816adb76e80e99afb947d66777b31ba43f (diff)
downloadfork-ledger-c8c2a17e282c2cbf3c0edb1b756e16be58328331.tar.gz
fork-ledger-c8c2a17e282c2cbf3c0edb1b756e16be58328331.tar.bz2
fork-ledger-c8c2a17e282c2cbf3c0edb1b756e16be58328331.zip
Fixed invocation of lambda expressions
foo = x, y, z -> print(x, y, z) foo(1, 2, 3) However, this still does not work: (x, y, z -> print(x, y, z))(1, 2, 3)
-rw-r--r--src/op.cc2
-rw-r--r--src/scope.h24
-rw-r--r--test/baseline/cmd-script.test5
-rwxr-xr-xtools/proof4
4 files changed, 27 insertions, 8 deletions
diff --git a/src/op.cc b/src/op.cc
index 8e9df812..bd2cc32f 100644
--- a/src/op.cc
+++ b/src/op.cc
@@ -288,7 +288,7 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus, const int depth)
}
case O_LAMBDA: {
- call_scope_t& call_args(downcast<call_scope_t>(scope));
+ call_scope_t& call_args(find_scope<call_scope_t>(scope, true));
std::size_t args_count(call_args.size());
std::size_t args_index(0);
symbol_scope_t call_scope(call_args);
diff --git a/src/scope.h b/src/scope.h
index 90f9c37a..785ce284 100644
--- a/src/scope.h
+++ b/src/scope.h
@@ -227,15 +227,17 @@ private:
};
template <typename T>
-T * search_scope(scope_t * ptr)
+T * search_scope(scope_t * ptr, bool prefer_direct_parents = false)
{
if (T * sought = dynamic_cast<T *>(ptr))
return sought;
if (bind_scope_t * scope = dynamic_cast<bind_scope_t *>(ptr)) {
- if (T * sought = search_scope<T>(&scope->grandchild))
+ if (T * sought = search_scope<T>(prefer_direct_parents ?
+ scope->parent : &scope->grandchild))
return sought;
- return search_scope<T>(scope->parent);
+ return search_scope<T>(prefer_direct_parents ?
+ &scope->grandchild : scope->parent);
}
else if (child_scope_t * child_scope = dynamic_cast<child_scope_t *>(ptr)) {
return search_scope<T>(child_scope->parent);
@@ -244,9 +246,21 @@ T * search_scope(scope_t * ptr)
}
template <typename T>
-inline T& find_scope(child_scope_t& scope, bool skip_this = true)
+inline T& find_scope(child_scope_t& scope, bool skip_this = true,
+ bool prefer_direct_parents = false)
{
- if (T * sought = search_scope<T>(skip_this ? scope.parent : &scope))
+ if (T * sought = search_scope<T>(skip_this ? scope.parent : &scope,
+ prefer_direct_parents))
+ return *sought;
+
+ throw_(std::runtime_error, _("Could not find scope"));
+ return reinterpret_cast<T&>(scope); // never executed
+}
+
+template <typename T>
+inline T& find_scope(scope_t& scope, bool prefer_direct_parents = false)
+{
+ if (T * sought = search_scope<T>(&scope, prefer_direct_parents))
return *sought;
throw_(std::runtime_error, _("Could not find scope"));
diff --git a/test/baseline/cmd-script.test b/test/baseline/cmd-script.test
index 12e9c868..ce920ebb 100644
--- a/test/baseline/cmd-script.test
+++ b/test/baseline/cmd-script.test
@@ -10,3 +10,8 @@ end test
test eval 'total_expr=$100;amount_expr=$15;x=total_expr;x=x/5;x=amount_expr-x*5;x'
$-85
end test
+
+test eval 'foo = x, y, z -> print(x, y, z); foo(1, 2, 3)'
+123
+1
+end test
diff --git a/tools/proof b/tools/proof
index f37c1488..3b997143 100755
--- a/tools/proof
+++ b/tools/proof
@@ -15,12 +15,12 @@ ledger_proof() {
exit 0
fi
- rm -fr $DEST/ledger-proof
+ sudo rm -fr $DEST/ledger-proof
time nice -n 20 \
./acprep --debug --enable-doxygen --universal --clang -j16 proof 2>&1 | \
tee $LOGDIR/ledger-proof.log
- rm -fr $DEST/ledger-proof
+ sudo rm -fr $DEST/ledger-proof
time nice -n 20 \
./acprep --debug --enable-doxygen --universal --python --clang -j16 proof 2>&1 | \
tee -a $LOGDIR/ledger-proof.log