Mercurial > repos > blastem
comparison cpu_dsl.py @ 2440:338c78da3fff
Added a little syntax sugar to CPU DSL and started updating new Z80 core to use it
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 11 Feb 2024 17:26:52 -0800 |
parents | 7d4df6b74263 |
children | 4435abe5db5e |
comparison
equal
deleted
inserted
replaced
2439:a66916828c9b | 2440:338c78da3fff |
---|---|
1 #!/usr/bin/env python3 | 1 #!/usr/bin/env python3 |
2 | 2 |
3 | 3 assignmentOps = { |
4 '=': 'mov', | |
5 '+=': 'add', | |
6 '-=': 'sub', | |
7 '<<=': 'lsl', | |
8 '>>=': 'lsr', | |
9 '&=': 'and', | |
10 '|=': 'or', | |
11 '^=': 'xor' | |
12 } | |
4 class Block: | 13 class Block: |
5 def addOp(self, op): | 14 def addOp(self, op): |
6 pass | 15 pass |
7 | 16 |
8 def processLine(self, parts): | 17 def processLine(self, parts): |
15 self.addOp(o) | 24 self.addOp(o) |
16 return o | 25 return o |
17 elif parts[0] == 'end': | 26 elif parts[0] == 'end': |
18 raise Exception('end is only allowed inside a switch or if block') | 27 raise Exception('end is only allowed inside a switch or if block') |
19 else: | 28 else: |
29 if len(parts) > 1 and parts[1] in assignmentOps: | |
30 dst = parts[0] | |
31 op = parts[1] | |
32 parts = [assignmentOps[op]] + parts[2:] | |
33 if op != '=': | |
34 if op == '<<=' or op == '>>=': | |
35 parts.insert(1, dst) | |
36 else: | |
37 parts.append(dst) | |
38 parts.append(dst) | |
20 self.addOp(NormalOp(parts)) | 39 self.addOp(NormalOp(parts)) |
21 return self | 40 return self |
22 | 41 |
23 def processOps(self, prog, fieldVals, output, otype, oplist): | 42 def processOps(self, prog, fieldVals, output, otype, oplist): |
24 for i in range(0, len(oplist)): | 43 for i in range(0, len(oplist)): |
1764 parts = [] | 1783 parts = [] |
1765 while sep: | 1784 while sep: |
1766 before,sep,after = line.partition('"') | 1785 before,sep,after = line.partition('"') |
1767 before = before.strip() | 1786 before = before.strip() |
1768 if before: | 1787 if before: |
1769 parts += [el.strip() for el in before.split(' ')] | 1788 parts += [el.strip() for el in before.split(' ') if el.strip()] |
1770 if sep: | 1789 if sep: |
1771 #TODO: deal with escaped quotes | 1790 #TODO: deal with escaped quotes |
1772 inside,sep,after = after.partition('"') | 1791 inside,sep,after = after.partition('"') |
1773 parts.append('"' + inside + '"') | 1792 parts.append('"' + inside + '"') |
1774 line = after | 1793 line = after |