From 29ab08bb695a3651adca37d329cc1dadb686b5af Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sat, 19 Oct 2019 23:40:19 +0200 Subject: [PATCH] Process LD IX/IY + n always with + LD (IX + n), n uses always '+' now implicitly. The sign of the offset is calculated within the expression. So LD (IX - 100), 0 is actually assembled as LD (IX + (-100)), 0. This makes things more consistent. --- asmparse.py | 35 +++++++++++++++++++++++++++-------- tests/functional/ldix.asm | 4 ++++ tests/functional/ldix.bin | Bin 0 -> 8 bytes tests/functional/ldix1.asm | 3 +++ tests/functional/ldix1.bin | Bin 0 -> 4 bytes tests/functional/ldix2.asm | 3 +++ tests/functional/ldix3.asm | 3 +++ tests/functional/ldix4.asm | 3 +++ zxbasm.py | 2 +- 9 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 tests/functional/ldix.asm create mode 100644 tests/functional/ldix.bin create mode 100644 tests/functional/ldix1.asm create mode 100644 tests/functional/ldix1.bin create mode 100644 tests/functional/ldix2.asm create mode 100644 tests/functional/ldix3.asm create mode 100644 tests/functional/ldix4.asm diff --git a/asmparse.py b/asmparse.py index 4731c5f41..c9e153275 100755 --- a/asmparse.py +++ b/asmparse.py @@ -284,6 +284,9 @@ def try_eval(self): if item == '-' and len(self.children) == 1: return -self.left.try_eval() + if item == '+' and len(self.children) == 1: + return self.left.try_eval() + try: return self.funct[item](self.left.try_eval(), self.right.try_eval()) except ZeroDivisionError: @@ -788,18 +791,33 @@ def p_reg8_hl(p): def p_ind8_I(p): - """ reg8_I : LP IX PLUS expr RP - | LP IX MINUS expr RP - | LP IY PLUS expr RP - | LP IY MINUS expr RP + """ reg8_I : LP IX expr RP + | LP IY expr RP | LP IX PLUS pexpr RP | LP IX MINUS pexpr RP | LP IY PLUS pexpr RP | LP IY MINUS pexpr RP """ - expr = p[4] - if p[3] == '-': - expr = Expr.makenode(Container('-', p.lineno(3)), expr) + if len(p) == 6: + expr = p[4] + sign = p[3] + else: + expr = p[3] + gen_ = expr.inorder() + first_expr = next(gen_, '') + if first_expr and first_expr.parent: + if len(first_expr.parent.children) == 2: + first_token = first_expr.symbol.item + else: + first_token = first_expr.parent.symbol.item + else: + first_token = '' + if first_token not in ('-', '+'): + error(p.lineno(2), "Unexpected token '{}'. Expected '+' or '-'".format(first_token)) + sign = '+' + + if sign == '-': + expr = Expr.makenode(Container(sign, p.lineno(2)), expr) p[0] = ('(%s+N)' % p[2], expr) @@ -1355,8 +1373,9 @@ def p_expr_lprp(p): def p_expr_uminus(p): """ expr : MINUS expr %prec UMINUS + | PLUS expr %prec UMINUS """ - p[0] = Expr.makenode(Container('-', p.lineno(1)), p[2]) + p[0] = Expr.makenode(Container(p[1], p.lineno(1)), p[2]) def p_expr_int(p): diff --git a/tests/functional/ldix.asm b/tests/functional/ldix.asm new file mode 100644 index 000000000..2c368cf53 --- /dev/null +++ b/tests/functional/ldix.asm @@ -0,0 +1,4 @@ + +ld (ix - 12 + 5), 0 +ld (ix + (-12 + 5)), 0 + diff --git a/tests/functional/ldix.bin b/tests/functional/ldix.bin new file mode 100644 index 0000000000000000000000000000000000000000..a3020100c5388898d103f57652e62592b266615d GIT binary patch literal 8 Ocmca>_LJc*5CZ@dNCX)G literal 0 HcmV?d00001 diff --git a/tests/functional/ldix1.asm b/tests/functional/ldix1.asm new file mode 100644 index 000000000..34bc5c4dd --- /dev/null +++ b/tests/functional/ldix1.asm @@ -0,0 +1,3 @@ + +ld (ix - 12), 0 + diff --git a/tests/functional/ldix1.bin b/tests/functional/ldix1.bin new file mode 100644 index 0000000000000000000000000000000000000000..a3f6fe66fa83d67ceb84575723b16f9bf0f43e61 GIT binary patch literal 4 Lcmca>_Jsie1_A;I literal 0 HcmV?d00001 diff --git a/tests/functional/ldix2.asm b/tests/functional/ldix2.asm new file mode 100644 index 000000000..bfd2876b7 --- /dev/null +++ b/tests/functional/ldix2.asm @@ -0,0 +1,3 @@ + +ld (ix (- 12 + 5)), 0 + diff --git a/tests/functional/ldix3.asm b/tests/functional/ldix3.asm new file mode 100644 index 000000000..b3e0aeb6e --- /dev/null +++ b/tests/functional/ldix3.asm @@ -0,0 +1,3 @@ + +ld (ix 12 + 5), 0 + diff --git a/tests/functional/ldix4.asm b/tests/functional/ldix4.asm new file mode 100644 index 000000000..92c3716f2 --- /dev/null +++ b/tests/functional/ldix4.asm @@ -0,0 +1,3 @@ + +ld (ix * 12), 0 + diff --git a/zxbasm.py b/zxbasm.py index 904ddc4b6..15fd0a7a5 100755 --- a/zxbasm.py +++ b/zxbasm.py @@ -24,7 +24,7 @@ from api import global_ # Release version -VERSION = '1.12.0' +VERSION = '1.13.0' def main(args=None):