forked from M-Labs/artiq
ARTIQIRGenerator: fix polymorphic print on closures.
This commit is contained in:
parent
53b4d87647
commit
afc3f36104
|
@ -203,6 +203,7 @@ def is_collection(typ):
|
|||
def is_allocated(typ):
|
||||
return not (is_none(typ) or is_bool(typ) or is_int(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_method(typ) or types.is_tuple(typ) or
|
||||
types.is_value(typ))
|
||||
|
|
|
@ -1575,9 +1575,8 @@ class ARTIQIRGenerator(algorithm.Visitor):
|
|||
format_string += ")"
|
||||
elif types.is_function(value.type):
|
||||
format_string += "<closure %p(%p)>"
|
||||
# We're relying on the internal layout of the closure here.
|
||||
args.append(self.append(ir.GetAttr(value, 0)))
|
||||
args.append(self.append(ir.GetAttr(value, 1)))
|
||||
args.append(self.append(ir.GetAttr(value, '__code__')))
|
||||
args.append(self.append(ir.GetAttr(value, '__closure__')))
|
||||
elif builtins.is_none(value.type):
|
||||
format_string += "None"
|
||||
elif builtins.is_bool(value.type):
|
||||
|
|
|
@ -180,6 +180,8 @@ class LLVMIRGenerator:
|
|||
return llvoid
|
||||
else:
|
||||
return ll.LiteralStructType([])
|
||||
elif types._is_pointer(typ):
|
||||
return llptr
|
||||
elif types.is_function(typ):
|
||||
envarg = llptr
|
||||
llty = ll.FunctionType(args=[envarg] +
|
||||
|
|
|
@ -176,6 +176,10 @@ class TTuple(Type):
|
|||
def __ne__(self, other):
|
||||
return not (self == other)
|
||||
|
||||
class _TPointer(TMono):
|
||||
def __init__(self):
|
||||
super().__init__("pointer")
|
||||
|
||||
class TFunction(Type):
|
||||
"""
|
||||
A function type.
|
||||
|
@ -188,7 +192,10 @@ class TFunction(Type):
|
|||
return type
|
||||
"""
|
||||
|
||||
attributes = OrderedDict()
|
||||
attributes = OrderedDict([
|
||||
('__code__', _TPointer()),
|
||||
('__closure__', _TPointer()),
|
||||
])
|
||||
|
||||
def __init__(self, args, optargs, ret):
|
||||
assert isinstance(args, OrderedDict)
|
||||
|
@ -245,6 +252,8 @@ class TRPCFunction(TFunction):
|
|||
:ivar service: (int) RPC service number
|
||||
"""
|
||||
|
||||
attributes = OrderedDict()
|
||||
|
||||
def __init__(self, args, optargs, ret, service):
|
||||
super().__init__(args, optargs, ret)
|
||||
self.service = service
|
||||
|
@ -265,6 +274,8 @@ class TCFunction(TFunction):
|
|||
:ivar name: (str) C function name
|
||||
"""
|
||||
|
||||
attributes = OrderedDict()
|
||||
|
||||
def __init__(self, args, ret, name):
|
||||
super().__init__(args, OrderedDict(), ret)
|
||||
self.name = name
|
||||
|
@ -422,6 +433,9 @@ def is_tuple(typ, elts=None):
|
|||
else:
|
||||
return isinstance(typ, TTuple)
|
||||
|
||||
def _is_pointer(typ):
|
||||
return isinstance(typ.find(), _TPointer)
|
||||
|
||||
def is_function(typ):
|
||||
return isinstance(typ.find(), TFunction)
|
||||
|
||||
|
|
Loading…
Reference in New Issue