augustss / MicroHs

Haskell implemented with combinators
Other
367 stars 25 forks source link

Handle any number of constant arguments in `lazier`. #22

Closed jmaessen closed 10 months ago

jmaessen commented 10 months ago

Refactored "lazier" to handle any number of constant args. This is pretty clearly visible in the .comb dump of the compiler itself. Here's one example:

 :1561 @ A S' B @ B C'B @ B B _38 _73 @ @ @ _1556 @ @ @ S' B @ B C'B @ B B _38 _73 @ @ @ _1556 @ @ @ _1563 @ @
-:1562 @ A B Y @ S' C' S' S @ @ @ B B B C' S' @ B @ @ @ @ C' C' C' S' S' C @ @ @ @ @ B B B B B S' S' @ C < @ #1 @ @ @ @ @ @ @ C'B B S' S' S' S @ @ @ @ B B B B S' S' @ C < @ #19 @ @ @ @ @ @ B B B C' C'B @ C C == @ #19 @ @ @ @ @ @ B B B U @ @ @ B B S C' S' @ B @ B S' C'B @ C C == @ #19 @ @ @ @ B B U @ @ C' C' C @ @ B C @ _229 _323 @ @ @ _40 _73 @ _1721 @ @ @ @ @ @ @ @ B B C @ @ _1564 @ @ @ @ @ @ @ B B B S' C'B @ C C == @ #1 @ @ @ @ @ @ B B B B U @ @ @ @ B B C'B B' B @ @ @ @ B B C'B B' B C'B @ C C == @ #1 @ @ @ @ @ @ @ B B B B U @ @ @ @ S' S' C'B @ @ B B B C'B @ @ @ B B B _39 _73 @ @ @ @ @ @ I @ @ @ @ @ @ @ @ @ B B U @ @ C'B B @ S' B @ B C'B @ C C == @ #0 @ @ @ @ B B U @ @ C' C' C @ @ C' C @ _229 _1188 @ @ @ _40 _73 @ _1721 @ @ @ @ @ @ @ @ @ B B B S I @ @ @ @ S' S' S' C' C'B @ @ @ @ B B B B C C == @ #19 @ @ @ @ @ @ B B B B _38 _73 @ _79 _1446 @ @ @ @ @ @ B S' S' S' C @ @ @ C' C' C' C' S @ @ @ @ C' C' C' C' S @ @ @ @ B B B U @ @ @ _1714 @ @ I @ @ I @ @ @ C' C'B @ B B' @ B B _288 @ @ _1559 @ @ @ B B _514 fromUTF8 "cannot unify " @ @ @ @ C'B B _514 @ _1113 @ @ B _514 fromUTF8 " and " @ @ @ _1113 @ @ @ @ @ @ @ @ B B B U @ @ @ B B C @ @ _1564 @ @ @ @ @ @
+:1562 @ A B B Y @ @ S' S' C' S @ @ @ B B B C' S' @ B @ @ @ @ C' C' C' S' S' C @ @ @ @ @ B B B B B S' S' @ C < @ #1 @ @ @ @ @ @ @ C' C'B @ B B S' S' S @ @ @ @ B B B B S' S' @ C < @ #19 @ @ @ @ @ @ B B B C' C'B @ C C == @ #19 @ @ @ @ @ @ B B B U @ @ @ B B S C' S' @ B @ B S' C'B @ C C == @ #19 @ @ @ @ B B U @ @ C' C' C @ @ B C @ _229 _323 @ @ @ _40 _73 @ _1721 @ @ @ @ @ @ @ @ B B C @ @ _1564 @ @ @ @ @ @ @ B B S' C'B @ C C == @ #1 @ @ @ @ @ B B B U @ @ @ B C'B B' B @ @ @ B C'B B' B C'B @ C C == @ #1 @ @ @ @ @ @ B B B U @ @ @ S' C'B @ B B C'B @ @ B B _39 _73 @ @ @ @ @ I @ @ @ @ @ @ @ @ @ B B U @ @ C'B B @ S' B @ B C'B @ C C == @ #0 @ @ @ @ B B U @ @ C' C' C @ @ C' C @ _229 _1188 @ @ @ _40 _73 @ _1721 @ @ @ @ @ @ @ @ @ B B B S I @ @ @ @ S' S' S' C' C'B @ @ @ @ B B B B C C == @ #19 @ @ @ @ @ @ B B B B _38 _73 @ _79 _1446 @ @ @ @ @ @ B S' S' S' C @ @ @ C' C' C' C' S @ @ @ @ C' C' C' C' S @ @ @ @ B B B U @ @ @ _1714 @ @ I @ @ I @ @ @ C' C'B @ B B' @ B B _288 @ @ _1559 @ @ @ B B _514 fromUTF8 "cannot unify " @ @ @ @ C'B B _514 @ _1113 @ @ B _514 fromUTF8 " and " @ @ @ _1113 @ @ @ @ @ @ @ @ B B B U @ @ @ B B C @ @ _1564 @ @ @ @ @ @
 :1563 @ A B B S' B @ B _38 _73 @ @ _1554 @ @ @ @ S' S' C' S' P @ @ @ @ _1565 @ B B C @ @ _1562 @ @ @

The "@ A B Y" vs "@ A B B Y" shows that the newer compiler is abstracting two args rather than just one, the Y being the inner recursive lambda. This was the command I used to get the above snippet (of course I got a full diff):

diff -u <(sed 's/ :/\n:/g' mhs.comb) <(sed 's/ :/\n:/g' mhs-stage1.comb)
augustss commented 10 months ago

I think this is worthwhile, even though it made the compiler slightly larger (0.8%) and maybe slightly slower (0.25%).

augustss commented 10 months ago

And thank you for the patch!