path: root/parse/parse.h
diff options
authorQuentin Carbonneaux <>2018-01-18 11:46:13 +0000
committerOri Bernstein <>2018-01-26 22:39:56 -0800
commit6fb0d750b296506f31cfd0871fdac82ee878834b (patch)
tree0d6bab181652f7859c6eef913285abfc41d1bc38 /parse/parse.h
parent24a566ff1751b246c8b6efd8adea3447975b9efa (diff)
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.exec(auto std.try(regex.compile("")), "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 'parse/parse.h')
1 files changed, 4 insertions, 3 deletions
diff --git a/parse/parse.h b/parse/parse.h
index c7b94aa..90dd771 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -108,10 +108,12 @@ struct Stab {
Htab *lbl; /* labels */
Htab *impl; /* trait implementations: really a set of implemented traits. */
- Node **autodcl; /* declarations in dcl marked 'auto' */
- size_t nautodcl;
+ /* See mi/flatten.c for the following. */
+ Node **autotmp; /* temporaries for 'auto' expressions */
+ size_t nautotmp;
Node *exit[Nexits];
+ size_t ndisposed[Nexits];
struct Tyenv {
@@ -331,7 +333,6 @@ struct Node {
char isnoret;
char isexportinit;
char isinit;
- char isauto;
} decl;
struct {