improve taldoc command

--HG--
branch : pmacs2
This commit is contained in:
~d6 2021-12-20 00:10:53 -05:00
parent a14e510a34
commit 4ce3e253c9
1 changed files with 38 additions and 24 deletions

View File

@ -69,36 +69,36 @@ class Taldoc(Method):
'NIP': ['Nip', [['a', 'b'], ['b']], None, 'remove the second value (a)'], 'NIP': ['Nip', [['a', 'b'], ['b']], None, 'remove the second value (a)'],
'SWP': ['Swap', [['a', 'b'], ['b', 'a']], None, 'swap the top two stack values'], 'SWP': ['Swap', [['a', 'b'], ['b', 'a']], None, 'swap the top two stack values'],
'OVR': ['Over', [['a', 'b'], ['a', 'b', 'a']], None, 'duplicate the second value (a) to the top of the stack'], 'OVR': ['Over', [['a', 'b'], ['a', 'b', 'a']], None, 'duplicate the second value (a) to the top of the stack'],
'ROT': ['Rotate', [['a', 'b', 'c'], ['b', 'c', 'a']], None, 'left rotate the top three values'], 'ROT': ['Rotate', [['a', 'b', 'c'], ['b', 'c', 'a']], None, 'rotate the top three values to the left'],
# logic # logic
'EQU': ['Equal', [['a', 'b'], ['bool']], None, 'push 01 if a == b; push 00 otherwise'], 'EQU': ['Equal', [['a', 'b'], ['bool^']], None, 'push 01 if a == b; push 00 otherwise'],
'NEQ': ['Not Equal', [['a', 'b'], ['bool']], None, 'push 01 if a != b; push 00 otherwise'], 'NEQ': ['Not Equal', [['a', 'b'], ['bool^']], None, 'push 01 if a != b; push 00 otherwise'],
'GTH': ['Greater Than', [['a', 'b'], ['bool^']], None, 'push 01 if a > b; push 00 otherwise'], 'GTH': ['Greater Than', [['a', 'b'], ['bool^']], None, 'push 01 if a > b; push 00 otherwise'],
'LTH': ['Less Than', [['a', 'b'], ['bool^']], None, 'push 01 if a < b; push 00 otherwise'], 'LTH': ['Less Than', [['a', 'b'], ['bool^']], None, 'push 01 if a < b; push 00 otherwise'],
# control flow # control flow
'JMP': ['Jump', [['x'], []], None, 'modify the program counter using addr'], 'JMP': ['Jump', [['x'], []], None, 'modify the pc using addr'],
'JCN': ['Jump Conditional', [['bool^ addr'], []], None, 'if bool != 00, modify the program counter using addr'], 'JCN': ['Jump Conditional', [['bool^ addr'], []], None, 'if bool != 00, modify the pc using addr'],
'JSR': ['Jump Stash Return', [['addr'], []], [[], ['pc']], 'push program counter onto return stack, then modify the program counter using addr'], 'JSR': ['Jump Stash Return', [['addr'], []], [[], ['pc']], 'store pc onto return stack; modify pc using addr'],
'STH': ['Stash', [['a'], []], [[], ['a']], 'pop the top of the stack and push it onto the return stack'], 'STH': ['Stash', [['a'], []], [[], ['a']], 'move the top of the stack to the return stack'],
# memory # memory
'LDZ': ['Load Zero-Page', [['addr^'], ['val']], None, 'read value from first 256 bytes of memory onto the stack'], 'LDZ': ['Load Zero-Page', [['addr^'], ['val']], None, 'load value from first 256 bytes of memory onto the stack'],
'STZ': ['Store Zero-Page', [['val', 'addr^'], []], None, 'write top of stack into the first 256 bytes of memory'], 'STZ': ['Store Zero-Page', [['val', 'addr^'], []], None, 'write top of stack into the first 256 bytes of memory'],
'LDR': ['Load Relative', [['addr^'], ['val']], None, ''], 'LDR': ['Load Relative', [['addr^'], ['val']], None, 'load relative address onto the stack'],
'STR': ['Store Relative', [['val', 'addr^'], []], None, ''], 'STR': ['Store Relative', [['val', 'addr^'], []], None, 'write top of stack to relative address'],
'LDA': ['Load Absolute', [['addr*'], ['val']], None, ''], 'LDA': ['Load Absolute', [['addr*'], ['val']], None, 'load absolute address onto the stack'],
'STA': ['Store Absolute', [['val', 'addr*'], []], None, ''], 'STA': ['Store Absolute', [['val', 'addr*'], []], None, 'write top of stack to absolute address'],
'DEI': ['Device In', [['addr^'], ['val']], None, ''], 'DEI': ['Device In', [['addr^'], ['val']], None, 'load from the given device onto the stack'],
'DEO': ['Device Out', [['val', 'addr^'], []], None, ''], 'DEO': ['Device Out', [['val', 'addr^'], []], None, 'write top of stack to the given device'],
# arithmetic # arithmetic
'ADD': ['Add', [['a', 'b'], ['a+b']], None, ''], 'ADD': ['Add', [['a', 'b'], ['a+b']], None, 'addition (a + b)'],
'SUB': ['Subtract', [['a', 'b'], ['a-b']], None, ''], 'SUB': ['Subtract', [['a', 'b'], ['a-b']], None, 'subtraction (a - b)'],
'MUL': ['Multiply', [['a', 'b'], ['a*b']], None, ''], 'MUL': ['Multiply', [['a', 'b'], ['a*b']], None, 'multiplication (a * b)'],
'DIV': ['Divide', [['a', 'b'], ['a/b']], None, ''], 'DIV': ['Divide', [['a', 'b'], ['a/b']], None, 'division (a / b)'],
# bitwise # bitwise
'AND': ['And', [['a', 'b'], ['a&b']], None, ''], 'AND': ['And', [['a', 'b'], ['a&b']], None, 'bitwise-and (a & b)'],
'ORA': ['Or', [['a', 'b'], ['a|b']], None, ''], 'ORA': ['Or', [['a', 'b'], ['a|b']], None, 'bitwise-or (a | b)'],
'EOR': ['Exclusive Or', [['a', 'b'], ['a^b']], None, ''], 'EOR': ['Exclusive Or', [['a', 'b'], ['a^b']], None, 'bitwise-xor (a ^ b)'],
'SFT': ['Shift', [['a', 'b^'], ['c']], None, ''], 'SFT': ['Shift', [['a', 'b^'], ['c']], None, 'bitshift left (b >> 4) then right (b & 0xf)'],
} }
inst_re = re.compile(r'^([A-Z]{3})(2?k?r?)$') inst_re = re.compile(r'^([A-Z]{3})(2?k?r?)$')
addr_dict = { addr_dict = {
@ -154,11 +154,25 @@ class Taldoc(Method):
m = self.inst_re.match(word) m = self.inst_re.match(word)
if m and m.group(1) in self.ops: if m and m.group(1) in self.ops:
prefix, suffix = m.groups() prefix, suffix = m.groups()
glyph = '^'
name, ds, rs, desc = self.ops[prefix] name, ds, rs, desc = self.ops[prefix]
def stk(xs): if 'r' in suffix:
return ' -- '.join([' '.join(x) for x in xs]) rs, ds = ds, rs
if '2' in suffix:
glyph = '*'
if 'k' in suffix:
ds = [ds[0], ds[0] + ds[1]]
def mark(x):
if x.endswith('^') or x.endswith('*'):
return x
else:
return x + glyph
def stk(xss):
return ' -- '.join([' '.join([mark(x) for x in xs]) for xs in xss])
if rs is None: if rs is None:
msg = '%s (%s) %s: %s' % (word, stk(ds), name, desc) msg = '%s (%s) %s: %s' % (word, stk(ds), name, desc)
elif ds is None:
msg = '%s {%s} %: %s' % (word, stk(rs), name, desc)
else: else:
msg = '%s (%s) {%s} %s: %s' % (word, stk(ds), stk(rs), name, desc) msg = '%s (%s) {%s} %s: %s' % (word, stk(ds), stk(rs), name, desc)
w.set_error(msg) w.set_error(msg)