From 183514d103e7420a235139ef57a1d4dc766d5550 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 7 Oct 2018 00:58:31 +0200 Subject: [PATCH] core: reader: Support 64 bit. * src/reader.c (reader_read_identifier_or_number): Support 64 bit. (reader_read_binary): Likewise. (reader_read_octal): Likewise. (reader_read_hex): Likewise. --- src/reader.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/reader.c b/src/reader.c index 3d9355a0..b85c35bc 100644 --- a/src/reader.c +++ b/src/reader.c @@ -72,7 +72,7 @@ reader_read_identifier_or_number (int c) { char buf[MAX_STRING]; int i = 0; - int n = 0; + long n = 0; int negative_p = 0; if (c == '+' && isdigit (peekchar ())) c = readchar (); @@ -338,12 +338,12 @@ reader_read_character () SCM reader_read_binary () { - int n = 0; + long n = 0; int c = peekchar (); - int s = 1; + int negative_p = 0; if (c == '-') { - s = -1; + negative_p = 1; readchar (); c = peekchar (); } @@ -354,18 +354,20 @@ reader_read_binary () readchar (); c = peekchar (); } - return MAKE_NUMBER (s*n); + if (negative_p) + n = 0 - n; + return MAKE_NUMBER (n); } SCM reader_read_octal () { - int n = 0; + long n = 0; int c = peekchar (); - int s = 1; + int negative_p = 0; if (c == '-') { - s = -1; + negative_p = 1; readchar (); c = peekchar (); } @@ -376,18 +378,20 @@ reader_read_octal () readchar (); c = peekchar (); } - return MAKE_NUMBER (s*n); + if (negative_p) + n = 0 - n; + return MAKE_NUMBER (n); } SCM reader_read_hex () { - int n = 0; + long n = 0; int c = peekchar (); - int s = 1; + int negative_p = 0; if (c == '-') { - s = -1; + negative_p = 1; readchar (); c = peekchar (); } @@ -405,7 +409,9 @@ reader_read_hex () readchar (); c = peekchar (); } - return MAKE_NUMBER (s*n); + if (negative_p) + n = 0 - n; + return MAKE_NUMBER (n); } SCM