base2-runner: fix typos causing syntax errors
[base2-runner.git] / library.py
1 #!/usr/bin/python3
2
3 def enum(*sequential, **named):
4  """ simulation of C=style enum
5      credit: Alec Thomas, http://stackoverflow.com/questions/36932/how-can-i-represent-an-enum-in-python
6  """
7  enums = dict(zip(sequential, range(len(sequential))), **named)
8  print(enums)
9  reverse = dict((value, key) for key, value in enums.items())
10  enums['reverse_mapping'] = reverse
11  return type('Enum', (), enums)
12
13 # some commonly required enums
14 # C-style pseudo-enum representing the directions a segment might run
15 directions = enum('N', 'NE', 'E', 'SE', 'S' , 'SW', 'W' , 'NW')
16 positions = enum('NONE', 'START', 'MID', 'END')
17
18 # Common Integrated Circuit signal names
19 s = ['NC', 'GND', 'Vcc', 'Vdd']
20 # logic gate signal names (covers multi-gate components up to quad-gate)
21 for l in ('A', 'B', 'Y'):
22  for n in range(1, 5):
23   s.append("%s%s" % (n, l))
24 signals = enum(tuple(s))
25
26 # populate dictionary with common logic gate types
27 gates = enum('AND', 'OR', 'XOR', 'NOT', 'NAND', 'NOR')
28