From 9936768603f4b8d9f08eb5ebecdc7b6d033b4be9 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 28 Aug 2015 02:11:05 -0500 Subject: [PATCH] ARTIQIRGenerator: fix non-nullary method calls. --- artiq/compiler/transforms/artiq_ir_generator.py | 14 ++++++++------ lit-test/test/integration/class.py | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/artiq/compiler/transforms/artiq_ir_generator.py b/artiq/compiler/transforms/artiq_ir_generator.py index 6f6b626f3..f2b8ae062 100644 --- a/artiq/compiler/transforms/artiq_ir_generator.py +++ b/artiq/compiler/transforms/artiq_ir_generator.py @@ -1424,20 +1424,22 @@ class ARTIQIRGenerator(algorithm.Visitor): func = self.visit(node.func) self_arg = None fn_typ = typ + offset = 0 elif types.is_method(typ): method = self.visit(node.func) func = self.append(ir.GetAttr(method, "__func__")) self_arg = self.append(ir.GetAttr(method, "__self__")) fn_typ = types.get_method_function(typ) + offset = 1 args = [None] * (len(fn_typ.args) + len(fn_typ.optargs)) for index, arg_node in enumerate(node.args): arg = self.visit(arg_node) if index < len(fn_typ.args): - args[index] = arg + args[index + offset] = arg 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: arg = self.visit(keyword.value) @@ -1445,19 +1447,19 @@ class ARTIQIRGenerator(algorithm.Visitor): for index, arg_name in enumerate(fn_typ.args): if keyword.arg == arg_name: assert args[index] is None - args[index] = arg + args[index + offset] = arg break elif keyword.arg in fn_typ.optargs: for index, optarg_name in enumerate(fn_typ.optargs): if keyword.arg == optarg_name: 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))) break for index, optarg_name in enumerate(fn_typ.optargs): - if args[len(fn_typ.args) + index] is None: - args[len(fn_typ.args) + index] = \ + if args[len(fn_typ.args) + index + offset] is None: + args[len(fn_typ.args) + index + offset] = \ self.append(ir.Alloc([], ir.TOption(fn_typ.optargs[optarg_name]))) if self_arg is not None: diff --git a/lit-test/test/integration/class.py b/lit-test/test/integration/class.py index 3d9048a1b..205210ea0 100644 --- a/lit-test/test/integration/class.py +++ b/lit-test/test/integration/class.py @@ -7,7 +7,10 @@ class c: return 2 def g(self): return self.a + 5 + def h(self, x): + return self.a + x assert c.a == 1 assert c.f() == 2 assert c().g() == 6 +assert c().h(9) == 10