summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin@c9x.me>2018-01-18 11:46:13 +0000
committerOri Bernstein <ori@eigenstate.org>2018-01-26 22:39:56 -0800
commit6fb0d750b296506f31cfd0871fdac82ee878834b (patch)
tree0d6bab181652f7859c6eef913285abfc41d1bc38 /test
parent24a566ff1751b246c8b6efd8adea3447975b9efa (diff)
downloadmc-6fb0d750b296506f31cfd0871fdac82ee878834b.tar.gz
New auto operator.
Summary: -------- During the Myrcon in September Ori suggested an 'auto' operator that would evaluate what it applies to, store the result in a temporary t, and call __dispose__(t) when the current block exits. This patch implements this idea under the form of a unary operator. This, for instance, allows to have: impl disposable regex# = __dispose__ = {r; regex.free(r)} ;; regex.exec(auto std.try(regex.compile("f..bar")), "foobar") Like before, it is guaranteed that __dispose__ is called in reverse order of auto appearance. Backward compatibility: ----------------------- Nope. Auto variables are now gone. This should not be a problem, simply rewrite: var auto x = foo() into: var x = auto foo() Implementation: --------------- It largely reuses the code I had written for 'auto' variables but needs a little finer grain tracking because we don't always want to call __dispose__ for *all* auto expression results when leaving a block (some might not be evaluated yet). For example: auto 1 if b -> void ;; auto 2 Only __dispose__(1) must be called when '-> void' is executed. If the block falls through, __dispose__(2) and __dispose__(1) will be called in sequence. TODO: ----- - Err when goto jumps in/out of a block that has auto expressions. - Support auto in patterns. match ... | `std.Some (auto x): ... is essentially rewritten to: match ... | `std.Some (auto x): auto x ... - Test edge cases (e.g., auto in loop condition) Actually, test. Cheers,
Diffstat (limited to 'test')
-rw-r--r--test/pkgtrait.myr3
1 files changed, 1 insertions, 2 deletions
diff --git a/test/pkgtrait.myr b/test/pkgtrait.myr
index 40eb594..3882634 100644
--- a/test/pkgtrait.myr
+++ b/test/pkgtrait.myr
@@ -8,7 +8,6 @@ impl disposable regex.regex# =
;;
const main = {
- var auto r : regex.regex#
- r = std.try(regex.compile(".*"))
+ auto std.try(regex.compile(".*"))
std.exit(42)
}