diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-07-12 06:06:50 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-07-12 06:06:50 +0000 |
commit | 76c6ead0c58c4184475a11405897ad6dd537728f (patch) | |
tree | a6d8875b358d977d674a83d08c204c71da255b0d | |
parent | f6287a8a746e16df2650f02e8382d8f602cd5f56 (diff) | |
download | ruby-76c6ead0c58c4184475a11405897ad6dd537728f.tar.gz ruby-76c6ead0c58c4184475a11405897ad6dd537728f.tar.xz ruby-76c6ead0c58c4184475a11405897ad6dd537728f.zip |
matz
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | bignum.c | 72 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | parse.y | 2 | ||||
-rw-r--r-- | variable.c | 50 |
5 files changed, 81 insertions, 58 deletions
@@ -1,3 +1,10 @@ +Wed Jul 12 15:06:28 2000 Yukihiro Matsumoto <matz@netlab.co.jp> + + * eval.c (rb_eval): use rb_const_get_at(). + + * variable.c (rb_const_get_at): retrieve toplevel constants only, + not ones of Object (and its included modules) in general. + Wed Jul 12 15:04:11 2000 Minero Aoki <aamine@dp.u-netsurf.ne.jp> * lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: 1.1.26. @@ -7,6 +14,12 @@ Wed Jul 12 15:04:11 2000 Minero Aoki <aamine@dp.u-netsurf.ne.jp> {Read,Write}Adapter, Command, Socket, SMTPCommand, POP3Command, APOPCommand, HTTPCommand +Wed Jul 12 13:10:30 2000 Yukihiro Matsumoto <matz@netlab.co.jp> + + * bignum.c (bigdivrem): defer bignorm(). + + * bignum.c (bignorm): accepts accidental fixnums. + Tue Jul 11 16:54:17 2000 Yukihiro Matsumoto <matz@netlab.co.jp> * parse.y (yylex): `@<digit>' is no longer a valid instance @@ -86,22 +86,24 @@ static VALUE bignorm(x) VALUE x; { - long len = RBIGNUM(x)->len; - USHORT *ds = BDIGITS(x); + if (!FIXNUM_P(x)) { + long len = RBIGNUM(x)->len; + USHORT *ds = BDIGITS(x); - while (len-- && !ds[len]) ; - RBIGNUM(x)->len = ++len; + while (len-- && !ds[len]) ; + RBIGNUM(x)->len = ++len; - if (len*sizeof(USHORT) <= sizeof(VALUE)) { - long num = 0; - while (len--) { - num = BIGUP(num) + ds[len]; - } - if (num >= 0) { - if (RBIGNUM(x)->sign) { - if (POSFIXABLE(num)) return INT2FIX(num); + if (len*sizeof(USHORT) <= sizeof(VALUE)) { + long num = 0; + while (len--) { + num = BIGUP(num) + ds[len]; + } + if (num >= 0) { + if (RBIGNUM(x)->sign) { + if (POSFIXABLE(num)) return INT2FIX(num); + } + else if (NEGFIXABLE(-(long)num)) return INT2FIX(-(long)num); } - else if (NEGFIXABLE(-(long)num)) return INT2FIX(-(long)num); } } return x; @@ -636,7 +638,7 @@ bigsub(x, y) i++; } - return bignorm(z); + return z; } static VALUE @@ -681,7 +683,7 @@ bigadd(x, y, sign) } BDIGITS(z)[i] = (USHORT)num; - return bignorm(z); + return z; } VALUE @@ -693,7 +695,7 @@ rb_big_plus(x, y) y = rb_int2big(FIX2LONG(y)); /* fall through */ case T_BIGNUM: - return bigadd(x, y, 1); + return bignorm(bigadd(x, y, 1)); case T_FLOAT: return rb_float_new(rb_big2dbl(x) + RFLOAT(y)->value); @@ -712,7 +714,7 @@ rb_big_minus(x, y) y = rb_int2big(FIX2LONG(y)); /* fall through */ case T_BIGNUM: - return bigadd(x, y, 0); + return bignorm(bigadd(x, y, 0)); case T_FLOAT: return rb_float_new(rb_big2dbl(x) - RFLOAT(y)->value); @@ -770,9 +772,9 @@ rb_big_mul(x, y) } static void -bigdivrem(x, y, div, mod) +bigdivrem(x, y, divp, modp) VALUE x, y; - VALUE *div, *mod; + VALUE *divp, *modp; { long nx = RBIGNUM(x)->len, ny = RBIGNUM(y)->len; long i, j; @@ -785,8 +787,8 @@ bigdivrem(x, y, div, mod) yds = BDIGITS(y); if (ny == 0 && yds[0] == 0) rb_num_zerodiv(); if (nx < ny || nx == ny && BDIGITS(x)[nx - 1] < BDIGITS(y)[ny - 1]) { - if (div) *div = INT2FIX(0); - if (mod) *mod = x; + if (divp) *divp = INT2FIX(0); + if (modp) *modp = x; return; } xds = BDIGITS(x); @@ -802,8 +804,8 @@ bigdivrem(x, y, div, mod) } RBIGNUM(z)->sign = RBIGNUM(x)->sign==RBIGNUM(y)->sign; if (!RBIGNUM(x)->sign) t2 = -(long)t2; - if (mod) *mod = rb_uint2big(t2); - if (div) *div = z; + if (modp) *modp = rb_uint2big(t2); + if (divp) *divp = z; return; } z = bignew(nx==ny?nx+2:nx+1, RBIGNUM(x)->sign==RBIGNUM(y)->sign); @@ -864,17 +866,17 @@ bigdivrem(x, y, div, mod) } zds[j] = q; } while (--j >= ny); - if (div) { /* move quotient down in z */ - *div = rb_big_clone(z); + if (divp) { /* move quotient down in z */ + *divp = rb_big_clone(z); zds = BDIGITS(*div); j = (nx==ny ? nx+2 : nx+1) - ny; for (i = 0;i < j;i++) zds[i] = zds[i+ny]; RBIGNUM(*div)->len = i; } - if (mod) { /* just normalize remainder */ - *mod = rb_big_clone(z); + if (modp) { /* just normalize remainder */ + *modp = rb_big_clone(z); if (dd) { - zds = BDIGITS(*mod); + zds = BDIGITS(*modp); t2 = 0; i = ny; while(i--) { t2 = BIGUP(t2) + zds[i]; @@ -882,8 +884,8 @@ bigdivrem(x, y, div, mod) t2 %= dd; } } - RBIGNUM(*mod)->len = ny; - RBIGNUM(*mod)->sign = RBIGNUM(x)->sign; + RBIGNUM(*modp)->len = ny; + RBIGNUM(*modp)->sign = RBIGNUM(x)->sign; } } @@ -900,8 +902,8 @@ bigdivmod(x, y, divp, modp) if (modp) *modp = bigadd(mod, y, 1); } else { - if (divp) *divp = bignorm(*divp); - if (modp) *modp = bignorm(mod); + if (divp) *divp = *divp; + if (modp) *modp = mod; } } @@ -927,7 +929,7 @@ rb_big_div(x, y) } bigdivmod(x, y, &z, 0); - return z; + return bignorm(z); } @@ -950,7 +952,7 @@ rb_big_modulo(x, y) } bigdivmod(x, y, 0, &z); - return z; + return bignorm(z); } static VALUE @@ -994,7 +996,7 @@ rb_big_divmod(x, y) } bigdivmod(x, y, &div, &mod); - return rb_assoc_new(div, mod); + return rb_assoc_new(bignorm(div), bignorm(mod)); } VALUE @@ -2630,7 +2630,7 @@ rb_eval(self, n) break; case NODE_COLON3: - result = rb_const_get(rb_cObject, node->nd_mid); + result = rb_const_get_at(rb_cObject, node->nd_mid); break; case NODE_NTH_REF: @@ -3443,7 +3443,7 @@ yylex() default: if (!is_identchar(c) || ISDIGIT(c)) { - rb_compile_error("Invalid char '%c'(%03o) in expression", c, c); + rb_compile_error("Invalid char `\\%03o' in expression", c); goto retry; } diff --git a/variable.c b/variable.c index 177f61c76..1a8d9ebd3 100644 --- a/variable.c +++ b/variable.c @@ -1011,6 +1011,33 @@ rb_obj_remove_instance_variable(obj, name) return val; } +static VALUE +top_const_get(klass, id) + VALUE klass; + ID id; +{ + VALUE value; + + /* pre-defined class */ + if (st_lookup(rb_class_tbl, id, &value)) return value; + + /* autoload */ + if (autoload_tbl && st_lookup(autoload_tbl, id, 0)) { + rb_autoload_load(id); + return rb_const_get(klass, id); + } + + /* Uninitialized constant */ + if (klass && klass != rb_cObject) + rb_raise(rb_eNameError, "uninitialized constant %s::%s", + RSTRING(rb_class_path(klass))->ptr, + rb_id2name(id)); + else { + rb_raise(rb_eNameError, "uninitialized constant %s",rb_id2name(id)); + } + return Qnil; /* not reached */ +} + VALUE rb_const_get_at(klass, id) VALUE klass; @@ -1022,7 +1049,7 @@ rb_const_get_at(klass, id) return value; } if (klass == rb_cObject) { - return rb_const_get(klass, id); + return top_const_get(klass, id); } rb_raise(rb_eNameError, "uninitialized constant %s::%s", RSTRING(rb_class_path(klass))->ptr, @@ -1030,7 +1057,6 @@ rb_const_get_at(klass, id) return Qnil; /* not reached */ } - void rb_autoload_load(id) ID id; @@ -1063,25 +1089,7 @@ rb_const_get(klass, id) if (BUILTIN_TYPE(klass) == T_MODULE) { return rb_const_get(rb_cObject, id); } - - /* pre-defined class */ - if (st_lookup(rb_class_tbl, id, &value)) return value; - - /* autoload */ - if (autoload_tbl && st_lookup(autoload_tbl, id, 0)) { - rb_autoload_load(id); - return rb_const_get(klass, id); - } - - /* Uninitialized constant */ - if (klass && klass != rb_cObject) - rb_raise(rb_eNameError, "uninitialized constant %s::%s", - RSTRING(rb_class_path(klass))->ptr, - rb_id2name(id)); - else { - rb_raise(rb_eNameError, "uninitialized constant %s",rb_id2name(id)); - } - return Qnil; /* not reached */ + return top_const_get(klass, id); } static int |