diff --git a/src/debug.h b/src/debug.h index f961d6e..babbaea 100644 --- a/src/debug.h +++ b/src/debug.h @@ -14,14 +14,14 @@ #define __debug_print_h #define DEBUG_ALLOC 1 -#define DEBUG_STACK 2 -#define DEBUG_ARITH 4 -#define DEBUG_EVAL 8 -#define DEBUG_LAMBDA 16 -#define DEBUG_BOOTSTRAP 32 -#define DEBUG_IO 64 +#define DEBUG_ARITH 2 +#define DEBUG_BIND 4 +#define DEBUG_BOOTSTRAP 8 +#define DEBUG_EVAL 16 +#define DEBUG_IO 32 +#define DEBUG_LAMBDA 64 #define DEBUG_REPL 128 -#define DEBUG_BIND 256 +#define DEBUG_STACK 256 extern int verbosity; diff --git a/src/memory/dump.c b/src/memory/dump.c index a5faa87..fc9175d 100644 --- a/src/memory/dump.c +++ b/src/memory/dump.c @@ -84,7 +84,7 @@ void dump_object( FILE * output, struct cons_pointer pointer ) { L"\t\tInteger cell: value %ld, count %u\n", cell.payload.integer.value, cell.count ); if ( !nilp( cell.payload.integer.more ) ) { - fputws( L"\t\tBIGNUM! More at\n:", output ); + fputws( L"\t\tBIGNUM! More at:\n", output ); dump_object( output, cell.payload.integer.more ); } break; diff --git a/unit-tests/bignum-add.sh b/unit-tests/bignum-add.sh new file mode 100644 index 0000000..678b766 --- /dev/null +++ b/unit-tests/bignum-add.sh @@ -0,0 +1,155 @@ +#!/bin/bash + +##################################################################### +# add two large numbers, not actally bignums to produce a smallnum +# (right on the boundary) +a=1152921504606846975 +b=1 +expected='1152921504606846976' +output=`echo "(+ $a $b)" | target/psse -v 2 2>psse.log` + +actual=`echo $output |\ + tail -1 |\ + sed 's/\,//g'` + +echo -n "adding $a to $b: " +if [ "${expected}" = "${actual}" ] +then + echo "OK" +else + echo "Fail: expected '${expected}', got '${actual}'" + exit 1 +fi + +echo -n "checking no bignum was created: " +grep -v 'BIGNUM!' psse.log > /dev/null +if [ $? -eq "0" ] +then + echo "OK" +else + echo "Fail" + exit 1 +fi + +##################################################################### +# add two numbers, not actally bignums to produce a bignum +# (just over the boundary) +a='1152921504606846976' +b=1 +expected='1152921504606846977' +output=`echo "(+ $a $b)" | target/psse -v 2 2>psse.log` + +actual=`echo $output |\ + tail -1 |\ + sed 's/\,//g'` + +echo -n "adding $a to $b: " +if [ "${expected}" = "${actual}" ] +then + echo "OK" +else + echo "Fail: expected '${expected}', got '${actual}'" + exit 1 +fi + +echo -n "checking a bignum was created: " +grep 'BIGNUM!' psse.log > /dev/null +if [ $? -eq "0" ] +then + echo "OK" +else + echo "Fail" + exit 1 +fi + +##################################################################### +# add a bignum and a smallnum to produce a bignum +# (just over the boundary) +a='1152921504606846977' +b=1 +expected='1152921504606846978' +output=`echo "(+ $a $b)" | target/psse -v 2 2>psse.log` + +actual=`echo $output |\ + tail -1 |\ + sed 's/\,//g'` + +echo -n "adding $a to $b: " +if [ "${expected}" = "${actual}" ] +then + echo "OK" +else + echo "Fail: expected '${expected}', got '${actual}'" + exit 1 +fi + +echo -n "checking a bignum was created: " +grep 'BIGNUM!' psse.log > /dev/null +if [ $? -eq "0" ] +then + echo "OK" +else + echo "Fail" + exit 1 +fi + +##################################################################### +# add a smallnum and a bignum to produce a bignum +# (just over the boundary) +a=1 +b=1152921504606846977 +expected='1152921504606846978' +output=`echo "(+ $a $b)" | target/psse -v 2 2>psse.log` + +actual=`echo $output |\ + tail -1 |\ + sed 's/\,//g'` + +echo -n "adding $a to $b: " +if [ "${expected}" = "${actual}" ] +then + echo "OK" +else + echo "Fail: expected '${expected}', got '${actual}'" + exit 1 +fi + +echo -n "checking a bignum was created: " +grep 'BIGNUM!' psse.log > /dev/null +if [ $? -eq "0" ] +then + echo "OK" +else + echo "Fail" + exit 1 +fi + +##################################################################### +# add two bignums to produce a bignum +a=10000000000000000000 +b=10000000000000000000 +expected='20000000000000000000' +output=`echo "(+ $a $b)" | target/psse -v 2 2>psse.log` + +actual=`echo $output |\ + tail -1 |\ + sed 's/\,//g'` + +echo -n "adding $a to $b: " +if [ "${expected}" = "${actual}" ] +then + echo "OK" +else + echo "Fail: expected '${expected}', got '${actual}'" + exit 1 +fi + +echo -n "checking a bignum was created: " +grep 'BIGNUM!' psse.log > /dev/null +if [ $? -eq "0" ] +then + echo "OK" +else + echo "Fail" + exit 1 +fi diff --git a/unit-tests/bignum-expt.sh b/unit-tests/bignum-expt.sh new file mode 100644 index 0000000..ab9cb24 --- /dev/null +++ b/unit-tests/bignum-expt.sh @@ -0,0 +1,135 @@ +#!/bin/bash + +##################################################################### +# last 'smallnum' value: +# sbcl calculates (expt 2 59) => 576460752303423488 +expected='576460752303423488' + +output=`target/psse < 1152921504606846976 +expected='1152921504606846976' + +output=`target/psse < 2305843009213693952 +expected='2305843009213693952' + +output=`target/psse < 18446744073709551616 +expected='18446744073709551616' + +output=`target/psse < 36893488147419103232 +expected='36893488147419103232' + +output=`target/psse <