compiler: Quote tuples as TTuple values

Previously, they would end up being TInstances,
rendering them useless.
This commit is contained in:
David Nadlinger 2019-03-31 04:28:19 +01:00 committed by Sebastien Bourdeauducq
parent 01213e2381
commit 0c5fa373d5
3 changed files with 25 additions and 0 deletions

View File

@ -221,6 +221,17 @@ class ASTSynthesizer:
return asttyped.ListT(elts=elts, ctx=None, type=builtins.TList(),
begin_loc=begin_loc, end_loc=end_loc,
loc=begin_loc.join(end_loc))
elif isinstance(value, tuple):
begin_loc = self._add("(")
elts = []
for index, elt in enumerate(value):
elts.append(self.quote(elt))
self._add(", ")
end_loc = self._add(")")
return asttyped.TupleT(elts=elts, ctx=None,
type=types.TTuple([e.type for e in elts]),
begin_loc=begin_loc, end_loc=end_loc,
loc=begin_loc.join(end_loc))
elif isinstance(value, numpy.ndarray):
begin_loc = self._add("numpy.array([")
elts = []

View File

@ -1556,6 +1556,11 @@ class LLVMIRGenerator:
lleltsptr = llglobal.bitcast(lleltsary.type.element.as_pointer())
llconst = ll.Constant(llty, [lleltsptr, ll.Constant(lli32, len(llelts))])
return llconst
elif types.is_tuple(typ):
assert isinstance(value, tuple), fail_msg
llelts = [self._quote(v, t, lambda: path() + [str(i)])
for i, (v, t) in enumerate(zip(value, typ.elts))]
return ll.Constant(llty, llelts)
elif types.is_rpc(typ) or types.is_c_function(typ) or types.is_builtin_function(typ):
# RPC, C and builtin functions have no runtime representation.
return ll.Constant(llty, ll.Undefined)

View File

@ -0,0 +1,9 @@
# RUN: %python -m artiq.compiler.testbench.embedding %s
from artiq.language.core import *
values = (1, 2)
@kernel
def entrypoint():
assert values == (1, 2)