forked from M-Labs/artiq
1
0
Fork 0

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 Sébastien Bourdeauducq
parent 3634cfac86
commit f9af058b96
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(), 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 = []

View File

@ -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)

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)