Skip to content

Commit acb8810

Browse files
author
whitequark
committedJul 23, 2015
Add tests for lambdas and functions.
·
8.01.0rc1
1 parent f8c2709 commit acb8810

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed
 

‎artiq/compiler/module.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def __init__(self, source_buffer, engine=None):
3232
monomorphism_validator.visit(self.typedtree)
3333
escape_validator.visit(self.typedtree)
3434
self.artiq_ir = artiq_ir_generator.visit(self.typedtree)
35+
print(self.artiq_ir[0])
36+
print(self.artiq_ir[1])
3537
dead_code_eliminator.process(self.artiq_ir)
3638
local_access_validator.process(self.artiq_ir)
3739
self.llvm_ir = llvm_ir_generator.process(self.artiq_ir)

‎artiq/compiler/transforms/artiq_ir_generator.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,18 +1250,37 @@ def visit_CallT(self, node):
12501250
else:
12511251
typ = node.func.type.find()
12521252
func = self.visit(node.func)
1253-
args = [self.visit(arg) for arg in node.args]
1254-
for index, optarg_name in enumerate(typ.optargs):
1255-
if len(typ.args) + index >= len(args):
1256-
optarg_typ = ir.TOption(typ.optargs[optarg_name])
1257-
for keyword in node.keywords:
1253+
args = [None] * (len(typ.args) + len(typ.optargs))
1254+
1255+
for index, arg_node in enumerate(node.args):
1256+
arg = self.visit(arg_node)
1257+
if index < len(typ.args):
1258+
args[index] = arg
1259+
else:
1260+
args[index] = self.append(ir.Alloc([arg], ir.TOption(arg.type)))
1261+
1262+
for keyword in node.keywords:
1263+
arg = self.visit(keyword.value)
1264+
if keyword.arg in typ.args:
1265+
for index, arg_name in enumerate(typ.args):
1266+
if keyword.arg == arg_name:
1267+
assert args[index] is None
1268+
args[index] = arg
1269+
break
1270+
elif keyword.arg in typ.optargs:
1271+
for index, optarg_name in enumerate(typ.optargs):
12581272
if keyword.arg == optarg_name:
1259-
value = self.append(ir.Alloc([self.visit(keyword.value)], optarg_typ))
1260-
args.append(value)
1273+
assert args[len(typ.args) + index] is None
1274+
args[len(typ.args) + index] = \
1275+
self.append(ir.Alloc([arg], ir.TOption(arg.type)))
12611276
break
1262-
else:
1263-
value = self.append(ir.Alloc([], optarg_typ))
1264-
args.append(value)
1277+
1278+
for index, optarg_name in enumerate(typ.optargs):
1279+
if args[len(typ.args) + index] is None:
1280+
args[len(typ.args) + index] = \
1281+
self.append(ir.Alloc([], ir.TOption(typ.optargs[optarg_name])))
1282+
1283+
assert None not in args
12651284

12661285
if self.unwind_target is None:
12671286
return self.append(ir.Call(func, args))

‎artiq/compiler/transforms/llvm_ir_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def process_Return(self, insn):
519519
if builtins.is_none(insn.value().type):
520520
return self.llbuilder.ret_void()
521521
else:
522-
return self.llbuilder.ret(self.llmap[insn.value()])
522+
return self.llbuilder.ret(self.map(insn.value()))
523523

524524
def process_Unreachable(self, insn):
525525
return self.llbuilder.unreachable()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: %python -m artiq.compiler.testbench.jit %s
2+
3+
def fib(x):
4+
if x == 1:
5+
return x
6+
else:
7+
return x * fib(x - 1)
8+
assert fib(5) == 120
9+
10+
# argument combinations handled in lambda.py
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# RUN: %python -m artiq.compiler.testbench.jit %s
2+
3+
assert (lambda: 1)() == 1
4+
assert (lambda x: x)(1) == 1
5+
assert (lambda x, y: x + y)(1, 2) == 3
6+
assert (lambda x, y=1: x + y)(1) == 2
7+
assert (lambda x, y=1: x + y)(1, 2) == 3
8+
assert (lambda x, y=1: x + y)(x=3) == 4
9+
assert (lambda x, y=1: x + y)(y=2, x=3) == 5

0 commit comments

Comments
 (0)
Please sign in to comment.