forked from M-Labs/artiq
compiler: Quote tuples as TTuple values
Previously, they would end up being TInstances, rendering them useless.
This commit is contained in:
parent
3634cfac86
commit
f9af058b96
|
@ -221,6 +221,17 @@ class ASTSynthesizer:
|
||||||
return asttyped.ListT(elts=elts, ctx=None, type=builtins.TList(),
|
return asttyped.ListT(elts=elts, ctx=None, type=builtins.TList(),
|
||||||
begin_loc=begin_loc, end_loc=end_loc,
|
begin_loc=begin_loc, end_loc=end_loc,
|
||||||
loc=begin_loc.join(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):
|
elif isinstance(value, numpy.ndarray):
|
||||||
begin_loc = self._add("numpy.array([")
|
begin_loc = self._add("numpy.array([")
|
||||||
elts = []
|
elts = []
|
||||||
|
|
|
@ -1566,6 +1566,11 @@ class LLVMIRGenerator:
|
||||||
lleltsptr = llglobal.bitcast(lleltsary.type.element.as_pointer())
|
lleltsptr = llglobal.bitcast(lleltsary.type.element.as_pointer())
|
||||||
llconst = ll.Constant(llty, [lleltsptr, ll.Constant(lli32, len(llelts))])
|
llconst = ll.Constant(llty, [lleltsptr, ll.Constant(lli32, len(llelts))])
|
||||||
return llconst
|
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):
|
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.
|
# RPC, C and builtin functions have no runtime representation.
|
||||||
return ll.Constant(llty, ll.Undefined)
|
return ll.Constant(llty, ll.Undefined)
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue