mirror of https://github.com/m-labs/artiq.git
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)
|
monomorphism_validator.visit(self.typedtree)
|
||||||
escape_validator.visit(self.typedtree)
|
escape_validator.visit(self.typedtree)
|
||||||
self.artiq_ir = artiq_ir_generator.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)
|
dead_code_eliminator.process(self.artiq_ir)
|
||||||
local_access_validator.process(self.artiq_ir)
|
local_access_validator.process(self.artiq_ir)
|
||||||
self.llvm_ir = llvm_ir_generator.process(self.artiq_ir)
|
self.llvm_ir = llvm_ir_generator.process(self.artiq_ir)
|
||||||
|
|
|
@ -1250,18 +1250,37 @@ class ARTIQIRGenerator(algorithm.Visitor):
|
||||||
else:
|
else:
|
||||||
typ = node.func.type.find()
|
typ = node.func.type.find()
|
||||||
func = self.visit(node.func)
|
func = self.visit(node.func)
|
||||||
args = [self.visit(arg) for arg in node.args]
|
args = [None] * (len(typ.args) + len(typ.optargs))
|
||||||
for index, optarg_name in enumerate(typ.optargs):
|
|
||||||
if len(typ.args) + index >= len(args):
|
for index, arg_node in enumerate(node.args):
|
||||||
optarg_typ = ir.TOption(typ.optargs[optarg_name])
|
arg = self.visit(arg_node)
|
||||||
for keyword in node.keywords:
|
if index < len(typ.args):
|
||||||
if keyword.arg == optarg_name:
|
args[index] = arg
|
||||||
value = self.append(ir.Alloc([self.visit(keyword.value)], optarg_typ))
|
else:
|
||||||
args.append(value)
|
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
|
break
|
||||||
else:
|
elif keyword.arg in typ.optargs:
|
||||||
value = self.append(ir.Alloc([], optarg_typ))
|
for index, optarg_name in enumerate(typ.optargs):
|
||||||
args.append(value)
|
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:
|
if self.unwind_target is None:
|
||||||
return self.append(ir.Call(func, args))
|
return self.append(ir.Call(func, args))
|
||||||
|
|
|
@ -519,7 +519,7 @@ class LLVMIRGenerator:
|
||||||
if builtins.is_none(insn.value().type):
|
if builtins.is_none(insn.value().type):
|
||||||
return self.llbuilder.ret_void()
|
return self.llbuilder.ret_void()
|
||||||
else:
|
else:
|
||||||
return self.llbuilder.ret(self.llmap[insn.value()])
|
return self.llbuilder.ret(self.map(insn.value()))
|
||||||
|
|
||||||
def process_Unreachable(self, insn):
|
def process_Unreachable(self, insn):
|
||||||
return self.llbuilder.unreachable()
|
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