diff --git a/Makefile b/Makefile index edf7867a..84d97ed4 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ XCPPFLAGS := $(CPPFLAGS) -Iinclude endif XLDFLAGS := $(LDFLAGS) $(GCLDFLAGS) -lm -XCFLAGS := -Wall -O2 -g $(CFLAGS) +XCFLAGS := -Wall -g $(CFLAGS) INCLUDES = include/chibi/sexp.h include/chibi/config.h include/chibi/install.h diff --git a/sexp.c b/sexp.c index 3321630c..b651dc15 100644 --- a/sexp.c +++ b/sexp.c @@ -42,6 +42,10 @@ static int digit_value (c) { return (((c)<='9') ? ((c) - '0') : ((toupper(c) - 'A') + 10)); } +static int hex_digit (n) { + return ((n<=9) ? ('0' + n) : ('A' + n - 10)); +} + static int is_separator(int c) { return 0>4), out); + sexp_write_char(ctx, hex_digit(sexp_unbox_character(obj)&0xF), out); } } else if (sexp_symbolp(obj)) { @@ -915,7 +921,7 @@ void sexp_write (sexp ctx, sexp obj, sexp out) { case (sexp_uint_t) SEXP_VOID: sexp_write_string(ctx, "#", out); break; default: - sexp_write_string(ctx, "#", out); + sexp_write_string(ctx, "#", out); } } } @@ -1005,7 +1011,7 @@ sexp sexp_read_float_tail(sexp ctx, sexp in, sexp_sint_t whole) { } sexp sexp_read_number(sexp ctx, sexp in, int base) { - sexp f; + sexp f, den; sexp_sint_t res = 0, negativep = 0, c; c = sexp_read_char(ctx, in); @@ -1017,6 +1023,7 @@ sexp sexp_read_number(sexp ctx, sexp in, int base) { if (base == 16) for (c=sexp_read_char(ctx, in); isxdigit(c); c=sexp_read_char(ctx, in)) res = res * base + digit_value(c); + else for (c=sexp_read_char(ctx, in); isdigit(c); c=sexp_read_char(ctx, in)) res = res * base + digit_value(c); @@ -1039,11 +1046,18 @@ sexp sexp_read_number(sexp ctx, sexp in, int base) { #endif return f; } + } else if (c=='/') { + den = sexp_read_number(ctx, in, base); + if (! sexp_integerp(den)) + return (sexp_exceptionp(den) + ? den : sexp_read_error(ctx, "invalid rational syntax", den, in)); + return sexp_make_flonum(ctx, (double)(negativep ? -res : res) + / (double)sexp_unbox_integer(den)); } else { - sexp_push_char(ctx, c, in); if ((c!=EOF) && ! is_separator(c)) return sexp_read_error(ctx, "invalid numeric syntax", - sexp_list1(ctx, sexp_make_character(c)), in); + sexp_make_character(c), in); + sexp_push_char(ctx, c, in); } return sexp_make_integer(negativep ? -res : res); @@ -1190,8 +1204,9 @@ sexp sexp_read_raw (sexp ctx, sexp in) { if (sexp_string_length(res) == 1) { res = sexp_make_character(c1); } else if ((c1 == 'x' || c1 == 'X') && - isxdigit(str[0]) && isxdigit(str[1]) && str[2] == '\0') { - res = sexp_make_character(16 * digit_value(c1) + digit_value(str[1])); + isxdigit(str[1]) && isxdigit(str[2]) && str[3] == '\0') { + res = sexp_make_character(16 * digit_value(str[1]) + + digit_value(str[2])); } else { if (strcasecmp(str, "space") == 0) res = sexp_make_character(' ');