def e(node): if isinstance(node, Term): return var(node, self.vm) if isinstance(node, ExpressionTree): _args = tuple(e(x) for x in node.children) _kwargs = {k: e(v) for k, v in iteritems_(node.named_children)} if node.operation not in self.vmcodeset.table: raise TypeError('I don\'t know how to translate %r' % node.operation) def op(): a = tuple(x for x in _args) kw = {k: x for k, x in iteritems_(_kwargs)} return self.vmcodeset.table[node.operation](self, *a, **kw) return vminstr.mylambda(op) return node # assumed to be as is
def log_signature(cls, self, method, *args, **kwargs): if self: # Since many of our objects implement __getattribute__, we get # into an infinite recursion, so let's avoid calling str and # repr. args = (('<{0} at {1:#x}>'.format(nameof(type(self)), id(self)), ) + args) arguments = ', '.join('%r' % a for a in args) if args else '' if kwargs: arguments += ', '.join('%s=%r' % (k, v) for k, v in iteritems_(kwargs)) if self: method_name = '{cls}.{method}'.format(cls=type(self), method=nameof(method)) else: method_name = nameof(method) message = '\t' * cls.get_padding() message += ('Calling {method}({arguments}) ...'.format( method=method_name, arguments=arguments)) cls.log_for(type(self) if self else None, message)
def log_signature(cls, self, method, *args, **kwargs): if self: # Since many of our objects implement __getattribute__, we get # into an infinite recursion, so let's avoid calling str and # repr. args = (('<{0} at {1:#x}>'.format(nameof(type(self)), id(self)), ) + args) arguments = ', '.join('%r' % a for a in args) if args else '' if kwargs: arguments += ', '.join('%s=%r' % (k, v) for k, v in iteritems_(kwargs)) if self: method_name = '{cls}.{method}'.format(cls=type(self), method=nameof(method)) else: method_name = nameof(method) message = '\t' * cls.get_padding() message += ('Calling {method}({arguments}) ...'. format(method=method_name, arguments=arguments)) cls.log_for(type(self) if self else None, message)
def op(): a = tuple(x for x in _args) kw = {k: x for k, x in iteritems_(_kwargs)} return self.vmcodeset.table[node.operation](self, *a, **kw)
def __init__(self, **attrs): for k, v in iteritems_(attrs): setattr(self, k, v)
def __hash__(self): from xoutil.compat import iteritems_ children_signature = tuple(hash(c) for c in self.children) named_children_signature = tuple(sorted((n, hash(c)) for n, c in iteritems_(self.named_children))) signature = (hash(self.operation), children_signature, named_children_signature) return hash(signature)