core: reader: Support binary #b101.
* src/reader.c (reader_read_binary): New function. (reader_read_hash): Use it. * tests/scm.test ("binary"): Test it.
This commit is contained in:
parent
10bd43d222
commit
04860cca6b
19
src/reader.c
19
src/reader.c
|
@ -224,6 +224,8 @@ reader_read_hash (int c, SCM a)
|
|||
cons (reader_read_sexp_ (readchar (), a), cell_nil));
|
||||
case ':':
|
||||
return MAKE_KEYWORD (CAR (reader_read_sexp_ (readchar (), a)));
|
||||
case 'b':
|
||||
return reader_read_binary ();
|
||||
case 'o':
|
||||
return reader_read_octal ();
|
||||
case 'x':
|
||||
|
@ -319,6 +321,23 @@ reader_read_character ()
|
|||
return MAKE_CHAR (c);
|
||||
}
|
||||
|
||||
SCM
|
||||
reader_read_binary ()
|
||||
{
|
||||
int n = 0;
|
||||
int c = peekchar ();
|
||||
int s = 1;
|
||||
if (c == '-') {s = -1; readchar (); c = peekchar ();}
|
||||
while (c == '0' || c == '1')
|
||||
{
|
||||
n <<= 1;
|
||||
n+= c - '0';
|
||||
readchar ();
|
||||
c = peekchar ();
|
||||
}
|
||||
return MAKE_NUMBER (s*n);
|
||||
}
|
||||
|
||||
SCM
|
||||
reader_read_octal ()
|
||||
{
|
||||
|
|
|
@ -155,4 +155,8 @@ exit $?
|
|||
|
||||
(pass-if "make-vector 2" (sequal? (make-vector 3 1) #(1 1 1)))
|
||||
|
||||
(pass-if-equal "binary" 5 #b101)
|
||||
(pass-if-equal "octal" 65 #o101)
|
||||
(pass-if-equal "hex" 257 #x101)
|
||||
|
||||
(result 'report)
|
||||
|
|
Loading…
Reference in a new issue