Mercurial > lcfOS
comparison python/ppci/target/token.py @ 394:988f3fb861e4
c3 code generator rewrite
author | Windel Bouwman |
---|---|
date | Thu, 22 May 2014 08:14:12 +0200 |
parents | 86b02c98a717 |
children | c0d9837acde8 |
comparison
equal
deleted
inserted
replaced
393:6ae782a085e0 | 394:988f3fb861e4 |
---|---|
11 | 11 |
12 def val2bit(v, bits): | 12 def val2bit(v, bits): |
13 b = [] | 13 b = [] |
14 for i in range(bits): | 14 for i in range(bits): |
15 b.append(bool((1<<i) & v)) | 15 b.append(bool((1<<i) & v)) |
16 #b.reverse() | |
17 return b | 16 return b |
18 | 17 |
19 | 18 |
20 def bit_range(b, e): | 19 def bit_range(b, e): |
21 """ Property generator function """ | 20 """ Property generator function """ |
46 if type(key) is int: | 45 if type(key) is int: |
47 self.set_bit(key, value) | 46 self.set_bit(key, value) |
48 elif type(key) is slice: | 47 elif type(key) is slice: |
49 assert key.step is None | 48 assert key.step is None |
50 bits = key.stop - key.start | 49 bits = key.stop - key.start |
50 assert value < (2**bits) | |
51 value_bits = val2bit(value, bits) | 51 value_bits = val2bit(value, bits) |
52 for i in range(key.start, key.stop): | 52 for i in range(key.start, key.stop): |
53 self.set_bit(i, value_bits[i - key.start]) | 53 self.set_bit(i, value_bits[i - key.start]) |
54 else: | 54 else: |
55 raise KeyError() | 55 raise KeyError() |