From b2bf87ae68681faada60c89e842f7c37472a0320 Mon Sep 17 00:00:00 2001 From: d6 Date: Sun, 26 Dec 2021 00:47:13 -0500 Subject: [PATCH] lots of tests! --- math32.tal | 26 ++++++++++++++++++++------ tester.py | 2 ++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/math32.tal b/math32.tal index 603bae8..c846f83 100644 --- a/math32.tal +++ b/math32.tal @@ -74,6 +74,8 @@ RTN ;buf LDA LIT '^ EQU ;test-xor32 JCN2 ;buf LDA LIT '~ EQU ;test-complement32 JCN2 ;buf LDA LIT 'N EQU ;test-negate32 JCN2 + ;buf LDA LIT '= EQU ;test-eq32 JCN2 + ;buf LDA LIT '! EQU ;test-ne32 JCN2 LIT '? EMIT NEWLINE RESET-POS BRK ( format: ". xxxxxxxx" ) @@ -115,6 +117,20 @@ RTN @test-complement32 ;complement32 UNARY-32-TEST @test-negate32 ;negate32 UNARY-32-TEST +@test-eq32 + ( format: "= xxxxxxxx yyyyyyyy" ) + ;buf #0002 ADD2 ;read-long JSR2 + ;buf #000b ADD2 ;read-long JSR2 + ;eq32 JSR2 ;emit-byte JSR2 + NEWLINE RESET-POS BRK + +@test-ne32 + ( format: "= xxxxxxxx yyyyyyyy" ) + ;buf #0002 ADD2 ;read-long JSR2 + ;buf #000b ADD2 ;read-long JSR2 + ;ne32 JSR2 ;emit-byte JSR2 + NEWLINE RESET-POS BRK + @bitcount8 ( x^ -> n^ ) #00 SWP ( n x ) &loop @@ -149,9 +165,8 @@ RTN RTN @eq32 ( xhi* xlo* yhi* ylo* -> bool^ ) - ROT2 EQU2 ,&maybe JCN - POP4 #00 RTN - &maybe EQU2 + ROT2 EQU2 #00 TOR2 + EQU2 SWP POP AND RTN @eq-zero32 ( x** -> bool^ ) @@ -159,9 +174,8 @@ RTN RTN @ne32 ( xhi* xlo* yhi* ylo* -> bool^ ) - ROT2 EQU2 ,&maybe JCN - POP4 #01 RTN - &maybe NEQ2 + ROT2 NEQ2 #00 TOR2 + NEQ2 SWP POP ORA RTN @ne-zero32 ( x** -> bool^ ) diff --git a/tester.py b/tester.py index c5842ec..da1ae3a 100644 --- a/tester.py +++ b/tester.py @@ -71,6 +71,8 @@ def main(): test(p, runs, b'^', [('x', u32), ('y', u32)], u32, lambda x, y: x ^ y) test(p, runs, b'~', [('x', u32)], u32, lambda x: ~x) test(p, runs, b'N', [('x', u32)], u32, lambda x: -x) + test(p, runs, b'=', [('x', u32), ('y', u32)], u8, lambda x, y: int(x == y)) + test(p, runs, b'!', [('x', u32), ('y', u32)], u8, lambda x, y: int(x != y)) p.stdin.close() p.stdout.close()