Use a different way of executing functions.

This commit is contained in:
Dave Halter
2017-09-27 16:07:24 +02:00
parent 025951089a
commit 313e1b3875
2 changed files with 19 additions and 14 deletions

View File

@@ -428,26 +428,24 @@ class Evaluator(object):
context = iterable.SequenceLiteralContext(self, context, atom)
return ContextSet(context)
def eval_trailer(self, context, types, trailer):
def eval_trailer(self, context, base_contexts, trailer):
trailer_op, node = trailer.children[:2]
if node == ')': # `arglist` is optional.
node = ()
if trailer_op == '[':
return iterable.py__getitem__(self, context, types, trailer)
return iterable.py__getitem__(self, context, base_contexts, trailer)
else:
context_set = ContextSet()
for typ in types:
debug.dbg('eval_trailer: %s in scope %s', trailer, typ)
if trailer_op == '.':
context_set |= typ.py__getattribute__(
name_context=context,
name_or_str=node
)
elif trailer_op == '(':
arguments = param.TreeArguments(self, context, node, trailer)
context_set |= self.execute(typ, arguments)
return context_set
debug.dbg('eval_trailer: %s in %s', trailer, base_contexts)
if trailer_op == '.':
return base_contexts.py__getattribute__(
name_context=context,
name_or_str=node
)
else:
assert trailer_op == '('
arguments = param.TreeArguments(self, context, node, trailer)
return base_contexts.execute(arguments)
@debug.increase_indent
def execute(self, obj, arguments):

View File

@@ -61,9 +61,16 @@ class BuiltinMethod(object):
self._method = method
self._builtin_func = builtin_func
# TODO it seems kind of stupid that we have to overwrite 3 methods here.
def py__call__(self, params):
return self._method(self._builtin_context)
def execute(self, *args, **kwargs):
return self._builtin_context.evaluator.execute(self, *args, **kwargs)
def execute_evaluated(self, *args, **kwargs):
return self._builtin_context.evaluator.execute_evaluated(self, *args, **kwargs)
def __getattr__(self, name):
return getattr(self._builtin_func, name)