-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[textual] Adding closures -- parsing part
Summary: we provide Textual with a closure mechanism, in order to help frontend writers. The syntax for a closure construction is ``` n0 = fun (p1, p2, p3) -> C.foo(exp1, exp2, p1, p2, p3) ``` which has an "intuitive" semantics but is in fact quite constrained: * `C.foo` must be implemented (not only declare) in the same file * `p1, p2, p3` appear always twice. They are the closure parameters * `exp1, exp2` are the value of the captured expressions It is the responsability of the frontend to generate a "lambda-lifted" closure like that. We don't know which capture strategy it will use. *Example1*: let x = 3 in let f y = x + y in should generate something like n0 = fun (y) -> add(3, y) with ``` declare add(x: int, y: int) : int { #entry: ret __sil_plus(x, y) } ``` *Example2*: let x = ref 3 in let f y = !x + 3 in should generate something like n0 = fun (y) -> add(&x, y) with ``` declare add(x: *int, y: int) : int { #entry: n0 = load x ret __sil_plus(n0, y) } ``` **Parser horrors** At parsing time, an expression like `n0(0)`or `x(0)` is hard to parse. It could be a regular call on a function names `n0` (or `x`), or a closure application. We give priority to the second case, using variable declarations. This is implemented after parsing with a new transformation pass. Reviewed By: vsiles Differential Revision: D49370340 fbshipit-source-id: 381ba0e77c01dc9a84b10a2e8e3e260312e289d8
- Loading branch information
1 parent
a0207a9
commit db6e322
Showing
17 changed files
with
389 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.