diff --git a/pyasm/asm_tests/test_harness b/pyasm/asm_tests/test_harness index 3fdee7b..fecd6cc 100755 --- a/pyasm/asm_tests/test_harness +++ b/pyasm/asm_tests/test_harness @@ -35,6 +35,34 @@ BlockloaderSize = 8 * 16 # 8 lines of 16 bytes HighBitMask = 0100000 +def eval_expr(dot, expr): + """Evaluate an expression that may contain '.'. + + dot the current value of 'dot' + expr the expression string to avaluate + + Returns the value of the expression. + Raises ArithmeticError if something is wrong. + """ + + # replace any "." value with "dot" defined in the symbol table + expr = string.replace(expr, '.', 'DOT') + + # evaluate the expression + globs = {'DOT': dot} # passed environment contains 'DOT' + try: + result = eval(expr, globs) + except (TypeError, NameError) as e: + Undefined = e.message + if 'is not defined' in e.message: + Undefined = e.message[len("name '"):-len("' is not defined")] + msg = "Test expression has '%s' undefined" % Undefined + raise ArithmeticError(msg) + msg = "Test expression has an error" + raise ArithmeticError(msg) + + return result + def oct_dec_int(s): """Convert string 's' to binary integer.""" @@ -187,7 +215,7 @@ def test_file(filename): else: # have label, $n or octal/decimal? # set 'dot' either way - (label, value) = test.split() + (label, value) = test.split(' ', 1) if label[0] == '$': org_num = int(label[1:]) try: @@ -200,7 +228,9 @@ def test_file(filename): else: address = oct_dec_int(label) dot = address - value = oct_dec_int(value) + + # evaluate the value field + value = eval_expr(dot, value) if address is None: warn("File '%s' has label '%s' with bad ORG number" @@ -224,9 +254,6 @@ def test_file(filename): dot += 1 -# if errors: -# print("File '%s' had errors" % filename) - def warn(msg): """Print error message and continue.""" diff --git a/pyasm/asm_tests/tests/aalpha b/pyasm/asm_tests/tests/aalpha index 63eb235..3834eb2 100644 --- a/pyasm/asm_tests/tests/aalpha +++ b/pyasm/asm_tests/tests/aalpha @@ -1,4 +1,4 @@ -; test file +; test file, old syntax tests org 0100 law 1 hlt diff --git a/pyasm/asm_tests/tests/aalpha.NEW b/pyasm/asm_tests/tests/aalpha.NEW index 4b05e2e..dfacfad 100644 --- a/pyasm/asm_tests/tests/aalpha.NEW +++ b/pyasm/asm_tests/tests/aalpha.NEW @@ -1,7 +1,7 @@ -; test file +; test file, new syntax org 0100 law 1 hlt end -;|$1 004001 +;|$1 004000 + 1 ;| 000000 diff --git a/pyasm/asm_tests/tests/alpha.NEW b/pyasm/asm_tests/tests/alpha.NEW new file mode 100644 index 0000000..fe21ce6 --- /dev/null +++ b/pyasm/asm_tests/tests/alpha.NEW @@ -0,0 +1,9 @@ +; deliberate errors at lines 7 and 9 + org 0100 + law 1 + hlt + end + +;|$1 004000 + 2 ; is actually 004001 +;| 000000 +;| 000001 ; address outside block diff --git a/pyasm/asm_tests/tests/beta.NEW b/pyasm/asm_tests/tests/beta.NEW new file mode 100644 index 0000000..64c52f8 --- /dev/null +++ b/pyasm/asm_tests/tests/beta.NEW @@ -0,0 +1,12 @@ +; test file with two ORG blocks + org 0100 + law 1 + hlt + org 0200 + law 2 + hlt + end +;|$1 004000 + 1 +;| 000000 +;|$2 004000 + 2 +;| 000000 diff --git a/pyasm/asm_tests/tests/delta b/pyasm/asm_tests/tests/delta.NEW similarity index 75% rename from pyasm/asm_tests/tests/delta rename to pyasm/asm_tests/tests/delta.NEW index c3c0d0e..a9a2b78 100644 --- a/pyasm/asm_tests/tests/delta +++ b/pyasm/asm_tests/tests/delta.NEW @@ -4,5 +4,5 @@ hlt end -;|$2 004001 ; bad ORG number +;|$3 004001 ; bad ORG number ;| 000000 diff --git a/pyasm/asm_tests/tests/kappa.NEW b/pyasm/asm_tests/tests/kappa.NEW new file mode 100644 index 0000000..a306c3b --- /dev/null +++ b/pyasm/asm_tests/tests/kappa.NEW @@ -0,0 +1,14 @@ +; test file with two adjacent ORG blocks + org 0100 + law 1 + hlt + + org 0102 + law 2 + hlt + end + +;|$1 004000 + 1 +;| 000000 +;| 004000 + 2 +;| 000000