generator basics - but not yet working with next, etc. need the bultins therefore

This commit is contained in:
David Halter
2012-05-10 16:54:45 +02:00
parent 7e3592ee29
commit 2efe3b0b57
2 changed files with 30 additions and 16 deletions

View File

@@ -7,7 +7,6 @@ follow_statement -> follow_call -> follow_paths -> follow_path
TODO doc TODO doc
TODO list comprehensions, priority? TODO list comprehensions, priority?
TODO evaluate asserts (type safety) TODO evaluate asserts (type safety)
TODO generators
python 3 stuff: python 3 stuff:
TODO class decorators TODO class decorators
@@ -392,7 +391,7 @@ class Execution(Executable):
return func return func
@memoize_default(default=[]) @memoize_default(default=[])
def get_return_types(self): def get_return_types(self, evaluate_generator=False):
""" """
Get the return vars of a function. Get the return vars of a function.
""" """
@@ -408,21 +407,24 @@ class Execution(Executable):
# don't do this with exceptions, as usual, because some deeper # don't do this with exceptions, as usual, because some deeper
# exceptions could be catched - and I wouldn't know what happened. # exceptions could be catched - and I wouldn't know what happened.
if hasattr(func, 'returns'): if hasattr(func, 'returns'):
self.set_param_cb(func) if func.is_generator:
self.base.is_decorated = True return [Generator(func)]
ret = func.returns else:
for s in ret: self.set_param_cb(func)
#temp, s.parent = s.parent, self self.base.is_decorated = True
stmts += follow_statement(s) ret = func.returns
#s.parent = temp for s in ret:
#temp, s.parent = s.parent, self
stmts += follow_statement(s)
#s.parent = temp
# reset the callback function on exit # reset the callback function on exit
# TODO how can we deactivate this again? # TODO how can we deactivate this again?
#self.base.param_cb = None #self.base.param_cb = None
# func could have changed because of decorators, so clear them # func could have changed because of decorators, so clear them
# again # again
self.base.is_decorated = False self.base.is_decorated = False
else: else:
debug.warning("no execution possible", func) debug.warning("no execution possible", func)
@@ -435,6 +437,17 @@ class Execution(Executable):
(self.__class__.__name__, self.base) (self.__class__.__name__, self.base)
class Generator(object):
def __init__(self, execution):
super(Generator, self).__init__()
self.execution = execution
def get_defined_names(self):
return []
# TODO add generator names (__next__, send, close, throw, next?)
#self.execution.get_return_types()
class Array(object): class Array(object):
""" """
Used as a mirror to parsing.Array, if needed. It defines some getter Used as a mirror to parsing.Array, if needed. It defines some getter

View File

@@ -237,4 +237,5 @@ def gen():
yield "" yield ""
exe = gen() exe = gen()
exe. #? ['upper']
exe.upper