Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Python iterators #2688

Merged
merged 81 commits into from Sep 7, 2022
Merged

Conversation

fabiomadge
Copy link
Collaborator

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@fabiomadge
Copy link
Collaborator Author

fabiomadge commented Sep 2, 2022

No changes to the tests, as they use %testDafnyForEachCompiler.

class Iter:
    def  __init__(self, X):
        self.X = X
        self.a: _dafny.Array = _dafny.Array.empty(1)
        self.stop: TypeVar('X') = self.X()
        self.x: TypeVar('X') = self.X()
        self._iter = None
        pass

    def __dafnystr__(self) -> str:
        return "Iter"
    def ctor__(self, a, stop):
        self.a = a
        self.stop = stop
        self._iter = self.TheIterator()
    def MoveNext(self):
        try:
            next(self._iter)
            return True
        except (StopIteration, TypeError) as e:
            return False
    def TheIterator(self):
        _1_i_: int
        _1_i_ = 0
        with _dafny.label("0"):
            while (_1_i_) < (len(((self).a))):
                with _dafny.c_label("0"):
                    if (_dafny.euclidian_modulus(_1_i_, 2)) == (0):
                        (self).x = ((self).a)[_1_i_]
                        yield
                    (self).x = ((self).a)[_1_i_]
                    if ((self).x) == ((self).stop):
                        raise _dafny.Break("0")
                    if (_dafny.euclidian_modulus(_1_i_, 2)) == (1):
                        yield
                    _1_i_ = (_1_i_) + (1)

@fabiomadge fabiomadge marked this pull request as ready for review September 2, 2022 20:55
Source/Dafny/Compilers/Compiler-python.cs Outdated Show resolved Hide resolved
Source/Dafny/Compilers/Compiler-python.cs Show resolved Hide resolved
Source/Dafny/Compilers/Compiler-python.cs Show resolved Hide resolved
@fabiomadge fabiomadge self-assigned this Sep 6, 2022
@fabiomadge fabiomadge merged commit d0ec2ed into dafny-lang:master Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants