forked from M-Labs/artiq
Add tests for lambdas and functions.
This commit is contained in:
parent
f8c2709943
commit
acb8810e62
|
@ -32,6 +32,8 @@ class Module:
|
|||
monomorphism_validator.visit(self.typedtree)
|
||||
escape_validator.visit(self.typedtree)
|
||||
self.artiq_ir = artiq_ir_generator.visit(self.typedtree)
|
||||
print(self.artiq_ir[0])
|
||||
print(self.artiq_ir[1])
|
||||
dead_code_eliminator.process(self.artiq_ir)
|
||||
local_access_validator.process(self.artiq_ir)
|
||||
self.llvm_ir = llvm_ir_generator.process(self.artiq_ir)
|
||||
|
|
|
@ -1250,18 +1250,37 @@ class ARTIQIRGenerator(algorithm.Visitor):
|
|||
else:
|
||||
typ = node.func.type.find()
|
||||
func = self.visit(node.func)
|
||||
args = [self.visit(arg) for arg in node.args]
|
||||
for index, optarg_name in enumerate(typ.optargs):
|
||||
if len(typ.args) + index >= len(args):
|
||||
optarg_typ = ir.TOption(typ.optargs[optarg_name])
|
||||
for keyword in node.keywords:
|
||||
if keyword.arg == optarg_name:
|
||||
value = self.append(ir.Alloc([self.visit(keyword.value)], optarg_typ))
|
||||
args.append(value)
|
||||
args = [None] * (len(typ.args) + len(typ.optargs))
|
||||
|
||||
for index, arg_node in enumerate(node.args):
|
||||
arg = self.visit(arg_node)
|
||||
if index < len(typ.args):
|
||||
args[index] = arg
|
||||
else:
|
||||
args[index] = self.append(ir.Alloc([arg], ir.TOption(arg.type)))
|
||||
|
||||
for keyword in node.keywords:
|
||||
arg = self.visit(keyword.value)
|
||||
if keyword.arg in typ.args:
|
||||
for index, arg_name in enumerate(typ.args):
|
||||
if keyword.arg == arg_name:
|
||||
assert args[index] is None
|
||||
args[index] = arg
|
||||
break
|
||||
else:
|
||||
value = self.append(ir.Alloc([], optarg_typ))
|
||||
args.append(value)
|
||||
elif keyword.arg in typ.optargs:
|
||||
for index, optarg_name in enumerate(typ.optargs):
|
||||
if keyword.arg == optarg_name:
|
||||
assert args[len(typ.args) + index] is None
|
||||
args[len(typ.args) + index] = \
|
||||
self.append(ir.Alloc([arg], ir.TOption(arg.type)))
|
||||
break
|
||||
|
||||
for index, optarg_name in enumerate(typ.optargs):
|
||||
if args[len(typ.args) + index] is None:
|
||||
args[len(typ.args) + index] = \
|
||||
self.append(ir.Alloc([], ir.TOption(typ.optargs[optarg_name])))
|
||||
|
||||
assert None not in args
|
||||
|
||||
if self.unwind_target is None:
|
||||
return self.append(ir.Call(func, args))
|
||||
|
|
|
@ -519,7 +519,7 @@ class LLVMIRGenerator:
|
|||
if builtins.is_none(insn.value().type):
|
||||
return self.llbuilder.ret_void()
|
||||
else:
|
||||
return self.llbuilder.ret(self.llmap[insn.value()])
|
||||
return self.llbuilder.ret(self.map(insn.value()))
|
||||
|
||||
def process_Unreachable(self, insn):
|
||||
return self.llbuilder.unreachable()
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
# RUN: %python -m artiq.compiler.testbench.jit %s
|
||||
|
||||
def fib(x):
|
||||
if x == 1:
|
||||
return x
|
||||
else:
|
||||
return x * fib(x - 1)
|
||||
assert fib(5) == 120
|
||||
|
||||
# argument combinations handled in lambda.py
|
|
@ -0,0 +1,9 @@
|
|||
# RUN: %python -m artiq.compiler.testbench.jit %s
|
||||
|
||||
assert (lambda: 1)() == 1
|
||||
assert (lambda x: x)(1) == 1
|
||||
assert (lambda x, y: x + y)(1, 2) == 3
|
||||
assert (lambda x, y=1: x + y)(1) == 2
|
||||
assert (lambda x, y=1: x + y)(1, 2) == 3
|
||||
assert (lambda x, y=1: x + y)(x=3) == 4
|
||||
assert (lambda x, y=1: x + y)(y=2, x=3) == 5
|
Loading…
Reference in New Issue