From 4ce3e253c993bc26828be3ac52304e7c03ed34bc Mon Sep 17 00:00:00 2001 From: d6 Date: Mon, 20 Dec 2021 00:10:53 -0500 Subject: [PATCH] improve taldoc command --HG-- branch : pmacs2 --- mode/tal.py | 62 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/mode/tal.py b/mode/tal.py index 7b199d1..3a93034 100644 --- a/mode/tal.py +++ b/mode/tal.py @@ -69,36 +69,36 @@ class Taldoc(Method): 'NIP': ['Nip', [['a', 'b'], ['b']], None, 'remove the second value (a)'], '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'], - '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 - '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'], + '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'], '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'], # control flow - 'JMP': ['Jump', [['x'], []], None, 'modify the program counter using addr'], - 'JCN': ['Jump Conditional', [['bool^ addr'], []], None, 'if bool != 00, modify the program counter using addr'], - 'JSR': ['Jump Stash Return', [['addr'], []], [[], ['pc']], 'push program counter onto return stack, then modify the program counter using addr'], - 'STH': ['Stash', [['a'], []], [[], ['a']], 'pop the top of the stack and push it onto the return stack'], + 'JMP': ['Jump', [['x'], []], None, 'modify the pc using addr'], + 'JCN': ['Jump Conditional', [['bool^ addr'], []], None, 'if bool != 00, modify the pc using addr'], + 'JSR': ['Jump Stash Return', [['addr'], []], [[], ['pc']], 'store pc onto return stack; modify pc using addr'], + 'STH': ['Stash', [['a'], []], [[], ['a']], 'move the top of the stack to the return stack'], # 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'], - 'LDR': ['Load Relative', [['addr^'], ['val']], None, ''], - 'STR': ['Store Relative', [['val', 'addr^'], []], None, ''], - 'LDA': ['Load Absolute', [['addr*'], ['val']], None, ''], - 'STA': ['Store Absolute', [['val', 'addr*'], []], None, ''], - 'DEI': ['Device In', [['addr^'], ['val']], None, ''], - 'DEO': ['Device Out', [['val', 'addr^'], []], None, ''], + 'LDR': ['Load Relative', [['addr^'], ['val']], None, 'load relative address onto the stack'], + 'STR': ['Store Relative', [['val', 'addr^'], []], None, 'write top of stack to relative address'], + 'LDA': ['Load Absolute', [['addr*'], ['val']], None, 'load absolute address onto the stack'], + 'STA': ['Store Absolute', [['val', 'addr*'], []], None, 'write top of stack to absolute address'], + 'DEI': ['Device In', [['addr^'], ['val']], None, 'load from the given device onto the stack'], + 'DEO': ['Device Out', [['val', 'addr^'], []], None, 'write top of stack to the given device'], # arithmetic - 'ADD': ['Add', [['a', 'b'], ['a+b']], None, ''], - 'SUB': ['Subtract', [['a', 'b'], ['a-b']], None, ''], - 'MUL': ['Multiply', [['a', 'b'], ['a*b']], None, ''], - 'DIV': ['Divide', [['a', 'b'], ['a/b']], None, ''], + 'ADD': ['Add', [['a', 'b'], ['a+b']], None, 'addition (a + b)'], + 'SUB': ['Subtract', [['a', 'b'], ['a-b']], None, 'subtraction (a - b)'], + 'MUL': ['Multiply', [['a', 'b'], ['a*b']], None, 'multiplication (a * b)'], + 'DIV': ['Divide', [['a', 'b'], ['a/b']], None, 'division (a / b)'], # bitwise - 'AND': ['And', [['a', 'b'], ['a&b']], None, ''], - 'ORA': ['Or', [['a', 'b'], ['a|b']], None, ''], - 'EOR': ['Exclusive Or', [['a', 'b'], ['a^b']], None, ''], - 'SFT': ['Shift', [['a', 'b^'], ['c']], None, ''], + 'AND': ['And', [['a', 'b'], ['a&b']], None, 'bitwise-and (a & b)'], + 'ORA': ['Or', [['a', 'b'], ['a|b']], None, 'bitwise-or (a | b)'], + 'EOR': ['Exclusive Or', [['a', 'b'], ['a^b']], None, 'bitwise-xor (a ^ b)'], + '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?)$') addr_dict = { @@ -154,11 +154,25 @@ class Taldoc(Method): m = self.inst_re.match(word) if m and m.group(1) in self.ops: prefix, suffix = m.groups() + glyph = '^' name, ds, rs, desc = self.ops[prefix] - def stk(xs): - return ' -- '.join([' '.join(x) for x in xs]) + if 'r' in suffix: + 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: msg = '%s (%s) %s: %s' % (word, stk(ds), name, desc) + elif ds is None: + msg = '%s {%s} %: %s' % (word, stk(rs), name, desc) else: msg = '%s (%s) {%s} %s: %s' % (word, stk(ds), stk(rs), name, desc) w.set_error(msg)