JSAbrahams / mamba

🐍 The Mamba programming language, because we care about safety
MIT License
88 stars 4 forks source link

Add desugaring of `foward` #74

Closed JSAbrahams closed 5 years ago

JSAbrahams commented 5 years ago

Relevant issues

...

Summary

We have the forward keyword, similar to Perl. This allows us to easily forward methods of the contained object (remember, we use composition, not inheritance). This is only a partial implementation however, we still have no way of checking what arguments the method of the contained object requires. Once we have a way of building a context which contains information about each identifier's type and the accompanying methods we can look up which arguments are required for a forward.

In short, the following:

# a is a method which takes no arguments, b takes two arguments
def private my_class <- MyClass() forward a, b

Is essentially desugared to the following:

_my_class = MyClass()
def a(self): self.my_class.a()
def b(self, arg1, arg2): self.my_class.b(arg1, arg2)

Although currently, due to not knowing any information about methods a and b, it is for now (incorrectly) desugared to:

_my_class = MyClass()
def a(self): self.my_class.a()
def b(self): self.my_class.b()

Added Tests

Test to check that desugaring of a foward produces a block with:

Additional Context

...

codecov[bot] commented 5 years ago

Codecov Report

Merging #74 into master will increase coverage by 0.31%. The diff coverage is 87.12%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #74      +/-   ##
==========================================
+ Coverage    80.2%   80.52%   +0.31%     
==========================================
  Files          60       60              
  Lines        3925     3974      +49     
==========================================
+ Hits         3148     3200      +52     
+ Misses        777      774       -3
Impacted Files Coverage Δ
tests/output/syntax.rs 46.66% <ø> (+2.91%) :arrow_up:
src/parser/ast.rs 23.94% <100%> (-0.71%) :arrow_down:
tests/parser/valid/definition.rs 90.35% <100%> (+0.8%) :arrow_up:
src/parser/definition.rs 82.43% <100%> (ø) :arrow_up:
tests/desugar/definition.rs 86.89% <82.92%> (-2.11%) :arrow_down:
src/desugar/definition.rs 85% <86.36%> (+0.9%) :arrow_up:
src/core/construct.rs 32.98% <0%> (+12.37%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 4766388...d51c77e. Read the comment docs.