ARTIQIRGenerator: fix non-nullary method calls.

This commit is contained in:
whitequark 2015-08-28 02:11:05 -05:00
parent ed236eb7f2
commit 9936768603
2 changed files with 11 additions and 6 deletions

View File

@ -1424,20 +1424,22 @@ class ARTIQIRGenerator(algorithm.Visitor):
func = self.visit(node.func) func = self.visit(node.func)
self_arg = None self_arg = None
fn_typ = typ fn_typ = typ
offset = 0
elif types.is_method(typ): elif types.is_method(typ):
method = self.visit(node.func) method = self.visit(node.func)
func = self.append(ir.GetAttr(method, "__func__")) func = self.append(ir.GetAttr(method, "__func__"))
self_arg = self.append(ir.GetAttr(method, "__self__")) self_arg = self.append(ir.GetAttr(method, "__self__"))
fn_typ = types.get_method_function(typ) fn_typ = types.get_method_function(typ)
offset = 1
args = [None] * (len(fn_typ.args) + len(fn_typ.optargs)) args = [None] * (len(fn_typ.args) + len(fn_typ.optargs))
for index, arg_node in enumerate(node.args): for index, arg_node in enumerate(node.args):
arg = self.visit(arg_node) arg = self.visit(arg_node)
if index < len(fn_typ.args): if index < len(fn_typ.args):
args[index] = arg args[index + offset] = arg
else: else:
args[index] = self.append(ir.Alloc([arg], ir.TOption(arg.type))) args[index + offset] = self.append(ir.Alloc([arg], ir.TOption(arg.type)))
for keyword in node.keywords: for keyword in node.keywords:
arg = self.visit(keyword.value) arg = self.visit(keyword.value)
@ -1445,19 +1447,19 @@ class ARTIQIRGenerator(algorithm.Visitor):
for index, arg_name in enumerate(fn_typ.args): for index, arg_name in enumerate(fn_typ.args):
if keyword.arg == arg_name: if keyword.arg == arg_name:
assert args[index] is None assert args[index] is None
args[index] = arg args[index + offset] = arg
break break
elif keyword.arg in fn_typ.optargs: elif keyword.arg in fn_typ.optargs:
for index, optarg_name in enumerate(fn_typ.optargs): for index, optarg_name in enumerate(fn_typ.optargs):
if keyword.arg == optarg_name: if keyword.arg == optarg_name:
assert args[len(fn_typ.args) + index] is None assert args[len(fn_typ.args) + index] is None
args[len(fn_typ.args) + index] = \ args[len(fn_typ.args) + index + offset] = \
self.append(ir.Alloc([arg], ir.TOption(arg.type))) self.append(ir.Alloc([arg], ir.TOption(arg.type)))
break break
for index, optarg_name in enumerate(fn_typ.optargs): for index, optarg_name in enumerate(fn_typ.optargs):
if args[len(fn_typ.args) + index] is None: if args[len(fn_typ.args) + index + offset] is None:
args[len(fn_typ.args) + index] = \ args[len(fn_typ.args) + index + offset] = \
self.append(ir.Alloc([], ir.TOption(fn_typ.optargs[optarg_name]))) self.append(ir.Alloc([], ir.TOption(fn_typ.optargs[optarg_name])))
if self_arg is not None: if self_arg is not None:

View File

@ -7,7 +7,10 @@ class c:
return 2 return 2
def g(self): def g(self):
return self.a + 5 return self.a + 5
def h(self, x):
return self.a + x
assert c.a == 1 assert c.a == 1
assert c.f() == 2 assert c.f() == 2
assert c().g() == 6 assert c().g() == 6
assert c().h(9) == 10