2022-11-02 17:39:35 +03:00
|
|
|
Tests cases that produced bad decompilation output previously. There
|
|
|
|
are three cases that need to be 'fixed up.'
|
|
|
|
|
2024-07-10 17:46:18 +03:00
|
|
|
1. lambda expressions with free variables need to be beta reduced
|
|
|
|
2. let defined functions need to have arguments removed and
|
|
|
|
occurrences rewritten.
|
|
|
|
3. let-rec defined functions need to have arguments removed, but
|
|
|
|
it is a more complicated process.
|
|
|
|
|
|
|
|
``` unison
|
2022-11-02 17:39:35 +03:00
|
|
|
> Any (w x -> let
|
|
|
|
f0 y = match y with
|
|
|
|
0 -> x
|
|
|
|
n -> 1 + f1 (drop y 1)
|
|
|
|
f1 y = match y with
|
|
|
|
0 -> w + x
|
|
|
|
n -> 1 + f0 (drop y 1)
|
|
|
|
f2 x = f2 x
|
|
|
|
f3 y = 1 + y + f2 x
|
2022-11-02 18:21:36 +03:00
|
|
|
g h = h 1 + x
|
|
|
|
g (z -> x + f0 z))
|
2022-11-02 17:39:35 +03:00
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2022-11-02 17:39:35 +03:00
|
|
|
|
2023-12-22 14:55:24 +03:00
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
2022-11-02 17:39:35 +03:00
|
|
|
✅
|
|
|
|
|
|
|
|
scratch.u changed.
|
|
|
|
|
|
|
|
Now evaluating any watch expressions (lines starting with
|
|
|
|
`>`)... Ctrl+C cancels.
|
|
|
|
|
|
|
|
1 | > Any (w x -> let
|
|
|
|
⧩
|
|
|
|
Any
|
|
|
|
(w x ->
|
2023-03-04 05:03:40 +03:00
|
|
|
let
|
|
|
|
use Nat + drop
|
2023-07-21 09:12:22 +03:00
|
|
|
f1 y = match y with
|
|
|
|
0 -> w + x
|
|
|
|
n -> 1 + f0 (drop y 1)
|
|
|
|
f0 y = match y with
|
|
|
|
0 -> x
|
|
|
|
n -> 1 + f1 (drop y 1)
|
2023-03-04 05:03:40 +03:00
|
|
|
f2 x = f2 x
|
|
|
|
f3 x y = 1 + y + f2 x
|
|
|
|
g h = h 1 + x
|
|
|
|
g (z -> x + f0 z))
|
2022-11-02 18:21:36 +03:00
|
|
|
|
|
|
|
```
|
|
|
|
Also check for some possible corner cases.
|
|
|
|
|
|
|
|
`f` should not have its `x` argument eliminated, because it doesn't
|
|
|
|
always occur with `x` as the first argument, but if we aren't careful,
|
|
|
|
we might do that, because we find the first occurrence of `f`, and
|
|
|
|
discard its arguments, where `f` also occurs.
|
|
|
|
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2022-11-02 18:21:36 +03:00
|
|
|
> Any (x -> let
|
|
|
|
f x y = match y with
|
|
|
|
0 -> 0
|
|
|
|
_ -> f x (f y (drop y 1))
|
|
|
|
|
|
|
|
f x 20)
|
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2022-11-02 18:21:36 +03:00
|
|
|
|
2023-12-22 14:55:24 +03:00
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
2022-11-02 18:21:36 +03:00
|
|
|
✅
|
|
|
|
|
|
|
|
scratch.u changed.
|
|
|
|
|
|
|
|
Now evaluating any watch expressions (lines starting with
|
|
|
|
`>`)... Ctrl+C cancels.
|
|
|
|
|
|
|
|
1 | > Any (x -> let
|
|
|
|
⧩
|
|
|
|
Any
|
|
|
|
(x ->
|
2023-03-04 05:03:40 +03:00
|
|
|
let
|
2023-07-21 09:12:22 +03:00
|
|
|
f x y = match y with
|
|
|
|
0 -> 0
|
|
|
|
_ -> f x (f y (Nat.drop y 1))
|
2023-03-04 05:03:40 +03:00
|
|
|
f x 20)
|
2022-11-02 17:39:35 +03:00
|
|
|
|
|
|
|
```
|