ARTIQIRGenerator: fix polymorphic print on closures.

This commit is contained in:
whitequark 2015-08-19 12:37:22 -07:00
parent 53b4d87647
commit afc3f36104
4 changed files with 20 additions and 4 deletions

View File

@ -203,6 +203,7 @@ def is_collection(typ):
def is_allocated(typ): def is_allocated(typ):
return not (is_none(typ) or is_bool(typ) or is_int(typ) or return not (is_none(typ) or is_bool(typ) or is_int(typ) or
is_float(typ) or is_range(typ) or is_float(typ) or is_range(typ) or
types._is_pointer(typ) or types.is_function(typ) or
types.is_c_function(typ) or types.is_rpc_function(typ) or types.is_c_function(typ) or types.is_rpc_function(typ) or
types.is_method(typ) or types.is_tuple(typ) or types.is_method(typ) or types.is_tuple(typ) or
types.is_value(typ)) types.is_value(typ))

View File

@ -1575,9 +1575,8 @@ class ARTIQIRGenerator(algorithm.Visitor):
format_string += ")" format_string += ")"
elif types.is_function(value.type): elif types.is_function(value.type):
format_string += "<closure %p(%p)>" format_string += "<closure %p(%p)>"
# We're relying on the internal layout of the closure here. args.append(self.append(ir.GetAttr(value, '__code__')))
args.append(self.append(ir.GetAttr(value, 0))) args.append(self.append(ir.GetAttr(value, '__closure__')))
args.append(self.append(ir.GetAttr(value, 1)))
elif builtins.is_none(value.type): elif builtins.is_none(value.type):
format_string += "None" format_string += "None"
elif builtins.is_bool(value.type): elif builtins.is_bool(value.type):

View File

@ -180,6 +180,8 @@ class LLVMIRGenerator:
return llvoid return llvoid
else: else:
return ll.LiteralStructType([]) return ll.LiteralStructType([])
elif types._is_pointer(typ):
return llptr
elif types.is_function(typ): elif types.is_function(typ):
envarg = llptr envarg = llptr
llty = ll.FunctionType(args=[envarg] + llty = ll.FunctionType(args=[envarg] +

View File

@ -176,6 +176,10 @@ class TTuple(Type):
def __ne__(self, other): def __ne__(self, other):
return not (self == other) return not (self == other)
class _TPointer(TMono):
def __init__(self):
super().__init__("pointer")
class TFunction(Type): class TFunction(Type):
""" """
A function type. A function type.
@ -188,7 +192,10 @@ class TFunction(Type):
return type return type
""" """
attributes = OrderedDict() attributes = OrderedDict([
('__code__', _TPointer()),
('__closure__', _TPointer()),
])
def __init__(self, args, optargs, ret): def __init__(self, args, optargs, ret):
assert isinstance(args, OrderedDict) assert isinstance(args, OrderedDict)
@ -245,6 +252,8 @@ class TRPCFunction(TFunction):
:ivar service: (int) RPC service number :ivar service: (int) RPC service number
""" """
attributes = OrderedDict()
def __init__(self, args, optargs, ret, service): def __init__(self, args, optargs, ret, service):
super().__init__(args, optargs, ret) super().__init__(args, optargs, ret)
self.service = service self.service = service
@ -265,6 +274,8 @@ class TCFunction(TFunction):
:ivar name: (str) C function name :ivar name: (str) C function name
""" """
attributes = OrderedDict()
def __init__(self, args, ret, name): def __init__(self, args, ret, name):
super().__init__(args, OrderedDict(), ret) super().__init__(args, OrderedDict(), ret)
self.name = name self.name = name
@ -422,6 +433,9 @@ def is_tuple(typ, elts=None):
else: else:
return isinstance(typ, TTuple) return isinstance(typ, TTuple)
def _is_pointer(typ):
return isinstance(typ.find(), _TPointer)
def is_function(typ): def is_function(typ):
return isinstance(typ.find(), TFunction) return isinstance(typ.find(), TFunction)