aboutsummaryrefslogtreecommitdiffstats
path: root/asm/creole.py
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2023-02-21 17:42:51 +0000
committerGravatar Peter McGoron 2023-02-21 17:42:51 +0000
commit6e0d124efd41b9c6df384a4c41343a65ade7fa87 (patch)
tree86eac3ac8328d1d59c7100fec8a6be0dbfe18815 /asm/creole.py
parenttest many jumps (diff)
add data parsing
Diffstat (limited to 'asm/creole.py')
-rw-r--r--asm/creole.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/asm/creole.py b/asm/creole.py
index a614701..e323432 100644
--- a/asm/creole.py
+++ b/asm/creole.py
@@ -72,10 +72,10 @@ class Argument:
class StringArgument(Argument):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- def __bytes__(self):
+ def __call__(self):
b = bytes()
for v in self.val:
- b = b + Argument(ArgType.IMM, v)()
+ b = b + Argument(ArgType.IMM, int(v, base=16))()
return b
class LabelArgument(Argument):
@@ -350,6 +350,19 @@ class Line:
class InstructionNotFoundException(Exception):
pass
+
+def _term_sep(s):
+ """ Split up the arguments of an instruction.
+ OP arg1 arg2 [data,data,data,...]
+ """
+
+ s = s.strip()
+ s_data = s.split('[')
+ if len(s_data) == 2:
+ return s_data[0].split() + [s_data[1].rstrip('] \t\n\r\v').split(',')]
+ else:
+ return s.split()
+
class Program:
def _asm_push_line(self, ins, args):
l = Line(ins, args)
@@ -361,7 +374,7 @@ class Program:
:param line: String containing the line.
:raises InstructionNotFoundException:
"""
- line = line.strip().split()
+ line = _term_sep(line)
line[0] = line[0].casefold()
if line[0][0] == '.':
self.asm.append(line[0])