From 3050be90042a07f0bad8c9199733c31a5025b6f5 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 9 Jun 2022 18:59:42 -0700 Subject: [PATCH] Stage testing of bignum2_plus_unsigned --- include/cyclone/types.h | 1 + runtime.c | 2 +- test-bn.scm | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 0f2cc61a..7fcc6084 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -1607,6 +1607,7 @@ void Cyc_int2bignum(int n, mp_int *bn); object Cyc_int2bignum2(gc_thread_data *data, int n); // TODO: debug only, remove this function from here! string_type *bignum2string(void *data, bignum2_type *bn, int base); +object bignum2_plus_unsigned(void *data, bignum2_type *x, bignum2_type *y, int negp); /* Remaining GC prototypes that require objects to be defined */ void *gc_alloc_from_bignum(gc_thread_data *data, bignum_type *src); diff --git a/runtime.c b/runtime.c index 6aee21b5..858d6793 100644 --- a/runtime.c +++ b/runtime.c @@ -2762,7 +2762,7 @@ object bignum2_plus_unsigned(void *data, bignum2_type *x, bignum2_type *y, int n assert(scan_r <= end_r); // TODO: return C_bignum_simplify(result); - return NULL; // DEBUG only! + return result; // TODO: no, could be a fixnum. need to simplify using above! } object Cyc_symbol2string(void *data, object cont, object sym) diff --git a/test-bn.scm b/test-bn.scm index 5ced339d..be548b60 100644 --- a/test-bn.scm +++ b/test-bn.scm @@ -1,6 +1,13 @@ ; ./sync.sh runtime.c gc.c include/cyclone/*.h test-bn.scm && cd ../cyclone-bootstrap && rm -f cyclone libcyclone.a ; ./install.sh && ./cyclone -L. -I. test-bn.scm && ./test-bn && cd ../cyclone (import (scheme base) (scheme write) (scheme repl)) + (define-c test-plus + "(void *data, int argc, closure _, object k, object fx1, object fx2)" + " object bn1 = Cyc_int2bignum2(data, obj_obj2int(fx1)); + object bn2 = Cyc_int2bignum2(data, obj_obj2int(fx2)); + object result = bignum2_plus_unsigned(data, bn1, bn2, 0); // TODO: int negp); + return_closcall1(data, k, result); + ") (define-c test-bn "(void *data, int argc, closure _, object k, object fx)" " object bn = Cyc_int2bignum2(data, obj_obj2int(fx)); @@ -25,11 +32,15 @@ (write row) (newline)) (list + (test-plus 1 2) + (test-plus -1 2) + (test-plus #x0FFFffff #x0FFFffff) (test-bn 123456789 ) (test-bn 123456789 ) (test-larger-bn 0 #x0FFF0001 ) (test-bn #x0FFF0001 ) + (test-bn 0 ) ;; TODO: 0 is broken right now! (test-bn -10 ) (test-bn 163264 ) (test-bn 16326 )