def loop(iterable, consumer): """ Perform an iterative loop. """ # If the consumer is *not* a ScriptObject, then damn them to the slow # path. In order for the consumer to not be ScriptObject, though, the # compiler and optimizer must have decided that an object could be # directly passed to _loop(), which is currently impossible to do without # manual effort. It's really not a common pathway at all. if not isinstance(consumer, ScriptObject): return slowLoop(iterable, consumer) # Rarer path: If the consumer doesn't actually have RUN_2, then they're # not going to be JIT'd. Again, the compiler and optimizer won't ever do # this to us; it has to be intentional. code = consumer.codeScript.strategy.lookupMethod(RUN_2) if code is None: return slowLoop(iterable, consumer) iterator = iterable.call(u"_makeIterator", []) ej = Ejector() try: while True: # JIT merge point. loopDriver.jit_merge_point(code=code, consumer=consumer, ejector=ej, iterator=iterator) globals = promote(consumer.globals) if isinstance(consumer, BusyObject): machine = SmallCaps(code, consumer.closure, globals) else: machine = SmallCaps(code, None, globals) values = unwrapList(iterator.call(u"next", [ej])) # Push the arguments onto the stack, backwards. values.reverse() for arg in values: machine.push(arg) machine.push(NullObject) machine.push(EMPTY_MAP) machine.run() except Ejecting as e: if e.ejector is not ej: raise finally: ej.disable() return NullObject
def listFromIterable(obj): rv = [] iterator = obj.call(u"_makeIterator", []) ej = Ejector() while True: try: l = unwrapList(iterator.call(u"next", [ej])) if len(l) != 2: raise userError(u"makeList.fromIterable/1: Invalid iterator") rv.append(l[1]) except Ejecting as ex: if ex.ejector is ej: ej.disable() return rv raise
def listFromIterable(obj): rv = [] iterator = obj.call(u"_makeIterator", []) ej = Ejector() while True: try: l = unwrapList(iterator.call(u"next", [ej])) if len(l) != 2: raise userError(u"makeList.fromIterable/1: Invalid iterator") rv.append(l[1]) except Ejecting as ex: if ex.ejector is ej: ej.disable() return rv[:] raise
def loop(iterable, consumer): """ Perform an iterative loop. """ # If the consumer is *not* a ScriptObject, then damn them to the slow # path. In order for the consumer to not be ScriptObject, though, the # compiler and optimizer must have decided that an object could be # directly passed to _loop(), which is currently impossible to do without # manual effort. It's really not a common pathway at all. if not isinstance(consumer, ScriptObject): return slowLoop(iterable, consumer) # Rarer path: If the consumer doesn't actually have RUN_2, then they're # not going to be JIT'd. Again, the compiler and optimizer won't ever do # this to us; it has to be intentional. code = consumer.codeScript.strategy.lookupMethod(RUN_2) if code is None: return slowLoop(iterable, consumer) iterator = iterable.call(u"_makeIterator", []) ej = Ejector() try: while True: # JIT merge point. loopDriver.jit_merge_point(code=code, consumer=consumer, ejector=ej, iterator=iterator) globals = promote(consumer.globals) if isinstance(consumer, BusyObject): machine = SmallCaps(code, consumer.closure, globals) else: machine = SmallCaps(code, None, globals) values = unwrapList(iterator.call(u"next", [ej])) # Push the arguments onto the stack, backwards. values.reverse() for arg in values: machine.push(arg) machine.push(NullObject) machine.push(EMPTY_MAP) machine.run() except Ejecting as e: if e.ejector is not ej: raise finally: ej.disable() return NullObject
def loop(iterable, consumer): """ Perform an iterative loop. """ # If the consumer is *not* an InterpObject, then damn them to the slow # path. In order for the consumer to not be InterpObject, though, the # compiler and optimizer must have decided that an object could be # directly passed to _loop(), which is currently impossible to do without # manual effort. It's really not a common pathway at all. if not isinstance(consumer, InterpObject): return slowLoop(iterable, consumer) displayName = consumer.getDisplayName().encode("utf-8") # Rarer path: If the consumer doesn't actually have a method for run/2, # then they're not going to be JIT'd. Again, the compiler and optimizer # won't ever do this to us; it has to be intentional. method = consumer.getMethod(RUN_2) if method is None: return slowLoop(iterable, consumer) iterator = iterable.call(u"_makeIterator", []) # XXX We want to use a with-statement here, but we cannot because of # something weird about the merge point. ej = Ejector() try: while True: # JIT merge point. loopDriver.jit_merge_point(method=method, displayName=displayName, consumer=consumer, ejector=ej, iterator=iterator) values = unwrapList(iterator.call(u"next", [ej])) consumer.runMethod(method, values, EMPTY_MAP) except Ejecting as e: if e.ejector is not ej: raise finally: ej.disable() return NullObject
def loop(iterable, consumer): """ Perform an iterative loop. """ # If the consumer is *not* an InterpObject, then damn them to the slow # path. In order for the consumer to not be InterpObject, though, the # compiler and optimizer must have decided that an object could be # directly passed to _loop(), which is currently impossible to do without # manual effort. It's really not a common pathway at all. if not isinstance(consumer, InterpObject): return slowLoop(iterable, consumer) displayName = consumer.getDisplayName().encode("utf-8") # Rarer path: If the consumer doesn't actually have a method for run/2, # then they're not going to be JIT'd. Again, the compiler and optimizer # won't ever do this to us; it has to be intentional. method = consumer.getMethod(RUN_2) if method is None: return slowLoop(iterable, consumer) iterator = iterable.call(u"_makeIterator", []) ej = Ejector() try: while True: # JIT merge point. loopDriver.jit_merge_point(method=method, displayName=displayName, consumer=consumer, ejector=ej, iterator=iterator) values = unwrapList(iterator.call(u"next", [ej])) consumer.runMethod(method, values, EMPTY_MAP) except Ejecting as e: if e.ejector is not ej: raise finally: ej.disable() return NullObject
def testDisable(self): ej = Ejector() ej.disable() self.assertFalse(ej.active)