bosatsu icon indicating copy to clipboard operation
bosatsu copied to clipboard

Improving pattern compilation

Open johnynek opened this issue 1 year ago • 1 comments

See: https://compiler.club/compiling-pattern-matching/

Currently in Matchless we compile pattern matches into nest if/else. But a better algorithm can pretty much always compile into a switch which can be encoded in Python with a dict or directly in C or Java.

johnynek avatar Feb 03 '24 17:02 johnynek

One nice thing would be automatic expanding out tuple matches:

match (a, b, c):
  case (Foo(x), Bar(_), Baz(_)): ..

could be nested to avoid the allocation and deallocation of the intermediate tuple:

match a:
  case Foo(x):
    match b:
      ...

To do this, we have to make sure we expand out the product match in the correct order.

johnynek avatar Apr 10 '24 03:04 johnynek