예제 #1
0
파일: iterator.py 프로젝트: youaani/hippyvm
    this.check_state(interp)
    if this.valid(interp):
        interp.call_method(this.inner, 'next', [])
    while not this.valid(interp):
        interp.call_method(this.w_iterators, 'next', [])
        w_valid = interp.call_method(this.w_iterators, 'valid', [])
        if interp.space.is_true(w_valid):
            this.inner = interp.call_method(this.w_iterators, 'current', [])
            interp.call_method(this.inner, 'rewind', [])
        else:
            return


k_FilterIterator = def_class('FilterIterator', [
    'rewind', 'next',
    new_abstract_method(["interp"], name="FilterIterator::accept")
],
                             extends=k_IteratorIterator,
                             flags=consts.ACC_ABSTRACT)


@k_FilterIterator.def_method(['interp', 'this'])
def rewind(interp, this):
    interp.call_method(this.inner, 'rewind', [])
    is_true = interp.space.is_true
    while is_true(interp.call_method(this.inner, 'valid', [])):
        if is_true(interp.call_method(this, 'accept', [])):
            return
        interp.call_method(this.inner, 'next', [])

예제 #2
0
파일: iterator.py 프로젝트: cklein/hippyvm
    this.check_state(interp)
    if this.valid(interp):
        interp.call_method(this.inner, 'next', [])
    while not this.valid(interp):
        interp.call_method(this.w_iterators, 'next', [])
        w_valid = interp.call_method(this.w_iterators, 'valid', [])
        if interp.space.is_true(w_valid):
            this.inner = interp.call_method(this.w_iterators, 'current', [])
            interp.call_method(this.inner, 'rewind', [])
        else:
            return

k_FilterIterator = def_class(
    'FilterIterator',
    ['rewind', 'next',
     new_abstract_method(["interp"], name="FilterIterator::accept")],
    extends=k_IteratorIterator,
    flags=consts.ACC_ABSTRACT)


@k_FilterIterator.def_method(['interp', 'this'])
def rewind(interp, this):
    interp.call_method(this.inner, 'rewind', [])
    is_true = interp.space.is_true
    while is_true(interp.call_method(this.inner, 'valid', [])):
        if is_true(interp.call_method(this, 'accept', [])):
            return
        interp.call_method(this.inner, 'next', [])


@k_FilterIterator.def_method(['interp', 'this'])
예제 #3
0
파일: iterator.py 프로젝트: CodeOps/hippyvm
    this.check_state(interp)
    if this.valid(interp):
        interp.call_method(this.inner, "next", [])
    while not this.valid(interp):
        interp.call_method(this.w_iterators, "next", [])
        w_valid = interp.call_method(this.w_iterators, "valid", [])
        if interp.space.is_true(w_valid):
            this.inner = interp.call_method(this.w_iterators, "current", [])
            interp.call_method(this.inner, "rewind", [])
        else:
            return


k_FilterIterator = def_class(
    "FilterIterator",
    ["rewind", "next", new_abstract_method(["interp"], name="FilterIterator::accept")],
    extends=k_IteratorIterator,
    flags=consts.ACC_ABSTRACT,
)


@k_FilterIterator.def_method(["interp", "this"])
def rewind(interp, this):
    interp.call_method(this.inner, "rewind", [])
    is_true = interp.space.is_true
    while is_true(interp.call_method(this.inner, "valid", [])):
        if is_true(interp.call_method(this, "accept", [])):
            return
        interp.call_method(this.inner, "next", [])

예제 #4
0
"""Interfaces defined by the SPL extension"""

from hippy import consts
from hippy.klass import def_class
from hippy.builtin_klass import new_abstract_method, k_Iterator

k_Countable = def_class('Countable',
    [new_abstract_method(["interp"], name="Countable::count")],
    flags=consts.ACC_INTERFACE | consts.ACC_ABSTRACT)


k_OuterIterator = def_class('OuterIterator',
    [new_abstract_method(["interp"], name="OuterIterator::getInnerIterator")],
    flags=consts.ACC_INTERFACE | consts.ACC_ABSTRACT, extends=k_Iterator)


k_RecursiveIterator = def_class('RecursiveIterator',
    [new_abstract_method(["interp"], name="RecursiveIterator::hasChildren"),
     new_abstract_method(["interp"], name="RecursiveIterator::getChildren")],
    flags=consts.ACC_INTERFACE | consts.ACC_ABSTRACT, extends=k_Iterator)


k_SeekableIterator = def_class('SeekableIterator',
    [new_abstract_method(["interp"], name="SeekableIterator::seek")],
    flags=consts.ACC_INTERFACE | consts.ACC_ABSTRACT, extends=k_Iterator)