diff 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
line wrap: on
line diff
--- a/cpu_dsl.py	Sun Feb 11 15:44:01 2024 -0800
+++ b/cpu_dsl.py	Sun Feb 11 17:26:52 2024 -0800
@@ -1,6 +1,15 @@
 #!/usr/bin/env python3
 
-
+assignmentOps = {
+	'=': 'mov',
+	'+=': 'add',
+	'-=': 'sub',
+	'<<=': 'lsl',
+	'>>=': 'lsr',
+	'&=': 'and',
+	'|=': 'or',
+	'^=': 'xor'
+}
 class Block:
 	def addOp(self, op):
 		pass
@@ -17,6 +26,16 @@
 		elif parts[0] == 'end':
 			raise Exception('end is only allowed inside a switch or if block')
 		else:
+			if len(parts) > 1 and parts[1] in assignmentOps:
+				dst = parts[0]
+				op = parts[1]
+				parts = [assignmentOps[op]] + parts[2:]
+				if op != '=':
+					if op == '<<=' or op == '>>=':
+						parts.insert(1, dst)
+					else:
+						parts.append(dst)
+				parts.append(dst)
 			self.addOp(NormalOp(parts))
 		return self
 		
@@ -1766,7 +1785,7 @@
 					before,sep,after = line.partition('"')
 					before = before.strip()
 					if before:
-						parts += [el.strip() for el in before.split(' ')]
+						parts += [el.strip() for el in before.split(' ') if el.strip()]
 					if sep:
 						#TODO: deal with escaped quotes
 						inside,sep,after = after.partition('"')