Permalink
Browse files

Since scm_read_number can now handle leading plus, can simplify scm_r…

…ead significantly until symbols are introduced.
  • Loading branch information...
1 parent cb8afbc commit 77a0fc420f73f64b5c8059d8425b0835598cb6e9 @petermichaux committed Jul 30, 2011
Showing with 6 additions and 40 deletions.
  1. +1 −7 model.c
  2. +5 −31 read.c
  3. +0 −2 scm.h
View
8 model.c
@@ -1,9 +1,3 @@
#include "scm.h"
-/* Algebraic negation. Object storage is designed
- * so that changing the sign of a Scheme number is
- * always a safe operation.
- */
-scm_object scm_number_negate(scm_object o) {
- return scm_fixnum_make(-scm_fixnum_value(o));
-}
+/* nothing here yet */
View
36 read.c
@@ -72,50 +72,24 @@ static scm_object scm_read_number(FILE *in) {
}
scm_object scm_read(FILE *in) {
- int c0, c1;
+ int c;
scm_object result;
loop:
- switch (c0 = getc(in)) {
+ switch (c = getc(in)) {
case ' ': case '\t': case '\r': case '\n':
goto loop;
case '+': case '-':
- /* Because we want to peek at the next character
- * to determine if this is a number not a symbol,
- * we need to retain the sign character,
- * '+' or '-', in c0 as ungetc guarantees only
- * one character push back onto a stream. */
- c1 = getc(in);
- if (isdigit(c1)) {
- c1 = ungetc(c1, in);
- if (c1 == EOF) {
- scm_fatal("scm_read: could not ungetc");
- }
- result = scm_read_number(in);
- if (c0 == '-') {
- /* We know scm_read_number returns a
- * positive result in this case.
- */
- result = scm_number_negate(result);
- }
- }
- else {
- /* TODO Add symbol support for the symbols
- * '+', '-' and those starting with '+' '-'.
- */
- scm_fatal("scm_read: symbols not supported");
- }
- break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
- c0 = ungetc(c0, in);
- if (c0 == EOF) {
+ c = ungetc(c, in);
+ if (c == EOF) {
scm_fatal("scm_read: could not ungetc");
}
result = scm_read_number(in);
break;
default:
- scm_fatal("scm_read: unexpected char '\\%o'", c0);
+ scm_fatal("scm_read: unexpected char '\\%o'", c);
}
return result;
View
2 scm.h
@@ -37,8 +37,6 @@ typedef long scm_object;
((((scm_int)1)<<(8*sizeof(scm_object)-1))+1)
#define scm_fixnum_max (-(scm_fixnum_min))
-scm_object scm_number_negate(scm_object num);
-
/************************* read.c *************************/
scm_object scm_read(FILE *in);

0 comments on commit 77a0fc4

Please sign in to comment.