forked from M-Labs/artiq
1
0
Fork 0

compiler: unbreak subscripts for bytes values (#714).

This commit is contained in:
whitequark 2017-06-09 06:50:48 +00:00
parent 66a683f583
commit 5b4fde30a8
3 changed files with 12 additions and 7 deletions

View File

@ -285,15 +285,13 @@ def is_exception(typ, name=None):
typ.name == name typ.name == name
def is_iterable(typ): def is_iterable(typ):
typ = typ.find() return is_listish(typ) or is_range(typ)
return isinstance(typ, types.TMono) and \
typ.name in ('list', 'array', 'range')
def get_iterable_elt(typ): def get_iterable_elt(typ):
if is_iterable(typ): if is_str(typ) or is_bytes(typ):
return typ.find()["elt"].find()
elif is_str(typ) or is_bytes(typ):
return TInt(types.TValue(8)) return TInt(types.TValue(8))
elif is_iterable(typ):
return typ.find()["elt"].find()
else: else:
assert False assert False

View File

@ -180,7 +180,10 @@ class Inferencer(algorithm.Visitor):
self.engine.process(diag) self.engine.process(diag)
def _unify_iterable(self, element, collection): def _unify_iterable(self, element, collection):
if builtins.is_iterable(collection.type): if builtins.is_bytes(collection.type):
self._unify(element.type, builtins.TInt(),
element.loc, None)
elif builtins.is_iterable(collection.type):
rhs_type = collection.type.find() rhs_type = collection.type.find()
rhs_wrapped_lhs_type = types.TMono(rhs_type.name, {"elt": element.type}) rhs_wrapped_lhs_type = types.TMono(rhs_type.name, {"elt": element.type})
self._unify(rhs_wrapped_lhs_type, rhs_type, self._unify(rhs_wrapped_lhs_type, rhs_type,

View File

@ -17,3 +17,7 @@ assert lst[0:3:2] == [0, 2]
lst = [0, 0, 0, 0, 0] lst = [0, 0, 0, 0, 0]
lst[0:5:2] = [1, 2, 3] lst[0:5:2] = [1, 2, 3]
assert lst == [1, 0, 2, 0, 3] assert lst == [1, 0, 2, 0, 3]
byt = b"abc"
assert byt[0] == 97
assert byt[1] == 98