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
+7 -9
View File
@@ -428,26 +428,24 @@ class Evaluator(object):
context = iterable.SequenceLiteralContext(self, context, atom) context = iterable.SequenceLiteralContext(self, context, atom)
return ContextSet(context) return ContextSet(context)
def eval_trailer(self, context, types, trailer): def eval_trailer(self, context, base_contexts, trailer):
trailer_op, node = trailer.children[:2] trailer_op, node = trailer.children[:2]
if node == ')': # `arglist` is optional. if node == ')': # `arglist` is optional.
node = () node = ()
if trailer_op == '[': if trailer_op == '[':
return iterable.py__getitem__(self, context, types, trailer) return iterable.py__getitem__(self, context, base_contexts, trailer)
else: else:
context_set = ContextSet() debug.dbg('eval_trailer: %s in %s', trailer, base_contexts)
for typ in types:
debug.dbg('eval_trailer: %s in scope %s', trailer, typ)
if trailer_op == '.': if trailer_op == '.':
context_set |= typ.py__getattribute__( return base_contexts.py__getattribute__(
name_context=context, name_context=context,
name_or_str=node name_or_str=node
) )
elif trailer_op == '(': else:
assert trailer_op == '('
arguments = param.TreeArguments(self, context, node, trailer) arguments = param.TreeArguments(self, context, node, trailer)
context_set |= self.execute(typ, arguments) return base_contexts.execute(arguments)
return context_set
@debug.increase_indent @debug.increase_indent
def execute(self, obj, arguments): def execute(self, obj, arguments):
+7
View File
@@ -61,9 +61,16 @@ class BuiltinMethod(object):
self._method = method self._method = method
self._builtin_func = builtin_func self._builtin_func = builtin_func
# TODO it seems kind of stupid that we have to overwrite 3 methods here.
def py__call__(self, params): def py__call__(self, params):
return self._method(self._builtin_context) 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): def __getattr__(self, name):
return getattr(self._builtin_func, name) return getattr(self._builtin_func, name)