From 236a20e92316535bc75dde63d51431875e253bfb Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 9 Dec 2011 22:25:51 -0800 Subject: Bignum support, here we go! Bignums, based on Michael Fromberger's MPI library, are integrated into the input syntax, stream output, equality testing, the garbage collector, and hashing. The plus operation handles transitions between fixnums and bignums. Other operations are still fixnum only. * Makefile (CFLAGS): Add mpi directory to include file search. (OBJS): Include new arith.o module and all of MPI_OBJS. (MPI_OBJS, MPI_OBJS_BASE): New variables. * configure (mpi_version, have_quilt, have_patch): New variables. Script detects whether patch and quilt are available. Unpacks mpi library, applies patches. Detects 128 bit integer type. Records more information in config.h about the sizes of types. * dep.mk: Updated. * depend.txr: Make work with paths that have directory components. * eval.c (eval_init): Rename of nump to fixnump. * gc.c (finalize, mark_obj): Handle BGNUM case. * hash.c: (hash_c_str): Changed to return unsigned long instead of long. (equal_hash): Handle BGNUM case. (eql_hash): Handle bignums with equal-hash, but other objects as eq. * lib.c (num_s): Variable renamed to fixnum_s. (bignum_s): New symbol variable. (code2type): Follow rename of num_s. Handle BGNUM case. (typeof): Follow rename of num_s. (eql): Handle bignums using equal, and other types using eq. (equal): Handle BGNUM case. (chk_calloc): New function. (c_num): Wording change in error message: is not a fixnum. (nump): Renamed to fixnump. (bignump): New function. (plus): Function removed, reimplemented in arith.c. (int_str): Handle integers which are too large for wcstol using bignum conversion. Base 0 is no longer passed to wcstol but converted to 10 because the special semantics for 0 would be inconsistent for bignums. (obj_init): Follow rename of num_s. Initialize bignum_s. --- parser.l | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'parser.l') diff --git a/parser.l b/parser.l index 53644a03..e7881a30 100644 --- a/parser.l +++ b/parser.l @@ -146,6 +146,7 @@ static wchar_t num_esc(char *num) %option noinput SYM [a-zA-Z0-9_]+ +NUM [+\-]?[0-9]+ NSCHR [a-zA-Z0-9!$%&*+\-<=>?\\^_~] NSYM {NSCHR}({NSCHR}|#)* TOK :?{SYM} @@ -170,12 +171,19 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} %% -{TOK} | -{NTOK} { - cnum val; - char *errp; +{NUM} { + val str = string_own(utf8_dup_from(yytext)); + if (yy_top_state() == INITIAL + || yy_top_state() == QSILIT) + yy_pop_state(); + yylval.num = int_str(str, num(10)); + return NUMBER; + } + +{TOK} | +{NTOK} { if (yy_top_state() == INITIAL || yy_top_state() == QSILIT) yy_pop_state(); @@ -188,28 +196,9 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} yylval.lexeme = utf8_dup_from(yytext + 1); return METAVAR; default: - break; - } - - errno = 0; - - val = strtol(yytext, &errp, 10); - - if (*errp != 0) { - /* not a number */ yylval.lexeme = utf8_dup_from(yytext); return IDENT; } - - if ((val == LONG_MAX || val == LONG_MIN) - && errno == ERANGE) - yyerror("numeric overflow in token"); - - if (val < NUM_MIN || val > NUM_MAX) - yyerror("numeric overflow in token"); - - yylval.num = val; - return NUMBER; } \({WS}all{WS}\) { -- cgit v1.2.3