johnynek / bosatsu

A python-ish pure and total functional programming language
Apache License 2.0
222 stars 11 forks source link

Improve python code gen for top level names #1120

Closed johnynek closed 5 months ago

johnynek commented 5 months ago

Since function parameter names shadow the same in python and bosatsu, we can escape those directly rather than allocating new ones to simulate the scoping rules.

Here is a small diff:

--- pyout/Bosatsu/BinNat.py 2024-02-03 11:40:29
+++ pyout_new/Bosatsu/BinNat.py 2024-02-03 11:27:31
@@ -2,188 +2,180 @@
 import Bosatsu.Predef as ___iPredef1
 import unittest as ___iunittest2

-def ___btoInt0(___bb1):
-    if ___bb1[0] == 0:
+def toInt(b):
+    if b[0] == 0:
         return 0
-    elif ___bb1[0] == 1:
-        ___bn2 = ___bb1[1]
-        return (___btoInt0(___bn2) * 2) + 1
+    elif b[0] == 1:
+        ___bn0 = b[1]
+        return (toInt(___bn0) * 2) + 1
     else:
-        ___bn3 = ___bb1[1]
-        return (___btoInt0(___bn3) * 2) + 2
-toInt = ___btoInt0
+        ___bn1 = b[1]
+        return (toInt(___bn1) * 2) + 2

-def ___btoNat0(___bb3):
-    if ___bb3[0] == 0:
+def toNat(b):
+    if b[0] == 0:
         return 0
-    elif ___bb3[0] == 1:
-        ___bn6 = ___bb3[1]
-        return ___iNat0.times2(___btoNat0(___bn6)) + 1
+    elif b[0] == 1:
+        ___bn2 = b[1]
+        return ___iNat0.times2(toNat(___bn2)) + 1
     else:
-        ___bn7 = ___bb3[1]
-        return ___iNat0.times2(___btoNat0(___bn7)) + 2
-toNat = ___btoNat0
+        ___bn3 = b[1]
+        return ___iNat0.times2(toNat(___bn3)) + 2
codecov-commenter commented 5 months ago

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (e3c5ab6) 92.34% compared to head (57c678f) 92.25%.

Files Patch % Lines
...la/org/bykn/bosatsu/codegen/python/PythonGen.scala 83.78% 6 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1120 +/- ## ========================================== - Coverage 92.34% 92.25% -0.10% ========================================== Files 96 96 Lines 10978 10974 -4 Branches 2584 2605 +21 ========================================== - Hits 10138 10124 -14 - Misses 840 850 +10 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.