Skip to content

Add runtime.quoted.Matcher #6042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Mar 7, 2019

This allows to match a quote against another quote while extracting the contents of defined holes. This will be used in as desugaring of quoted patterns.

def optimize(expr: Expr[Int]): Expr[Int] = expr match {
  case '{ 0 + $y } => optimize(y)
  case '{ ${Literal(a)} + ${Literal(b)} } => (a + b).toExpr
  case '{ ${x} + ${y @ Literal(_)} } => optimize('{ $y + $x })
  ...
  case expr => expr
}

Ints already have these optimization baked in, it is just a simple example. We would use this directly on any custom DSL instead.

This PR adds:

  • runtime logic for pattern matching on '{ ... }
  • Literal pattern to match a literal expression and extract its value
  • Binding pattern to match a reference to some val/var/def
  • Repeated pattern to match an explicit sequence of expressions

@nicolasstucki nicolasstucki self-assigned this Mar 7, 2019
@nicolasstucki nicolasstucki force-pushed the implement-quote-matcher branch 12 times, most recently from 02e6f88 to 6947983 Compare March 8, 2019 20:07
@nicolasstucki nicolasstucki force-pushed the implement-quote-matcher branch 17 times, most recently from 45ab279 to 052162d Compare March 25, 2019 14:45
@nicolasstucki nicolasstucki force-pushed the implement-quote-matcher branch 19 times, most recently from b8c67cf to 950e73d Compare March 28, 2019 17:58
@nicolasstucki nicolasstucki force-pushed the implement-quote-matcher branch from 950e73d to be60e48 Compare March 29, 2019 09:02
@nicolasstucki nicolasstucki force-pushed the implement-quote-matcher branch 3 times, most recently from ffe415f to 8c4ca02 Compare April 1, 2019 15:07
This allows to match a quote against another quote while extracting the contents of defined holes. This will be used in as desugaring of quoted patterns.

```scala
def optimize(expr: Expr[Int]): Expr[Int] = expr match {
  case '{ 0 + $y } => optimize(y)
  case '{ ${Literal(a)} + ${Literal(b)} } => (a + b).toExpr
  case '{ ${x} + ${y @ Literal(_)} } => optimize('{ $y + $x })
  ...
  case expr => expr
}
```

`Int`s already have these optimization baked in, it is just a simple example. We would use this directly on any custom DSL instead.

This PR adds:
* runtime logic for pattern matching on `'{ ... }`
* `Literal` pattern to match a literal expression and extract its value
* `Binding` pattern to match a reference to some val/var/def
* `Repeated` pattern to match an explicit sequence of expressions
@nicolasstucki nicolasstucki force-pushed the implement-quote-matcher branch from 0fe87eb to 105387c Compare April 2, 2019 09:21
@nicolasstucki
Copy link
Contributor Author

Split into smaller PRs (#6206, #6212, #6274 and others to come)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant