1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* bignum.c (get2comp): need to specify to carry or not.

* io.c (rb_io_inspect): embed path info.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2002-02-22 10:28:47 +00:00
parent 9ce7325615
commit 088d04d88e
5 changed files with 49 additions and 22 deletions

View file

@ -1,3 +1,9 @@
Fri Feb 22 03:34:38 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* bignum.c (get2comp): need to specify to carry or not.
* io.c (rb_io_inspect): embed path info.
Fri Feb 22 11:30:01 2002 Tanaka Akira <akr@m17n.org>
* prettyprint.rb: FillGroup implemented.

View file

@ -69,9 +69,10 @@ rb_big_clone(x)
return z;
}
void
rb_big_2comp(x) /* get 2's complement */
static void
get2comp(x, carry) /* get 2's complement */
VALUE x;
int carry;
{
long i = RBIGNUM(x)->len;
BDIGIT *ds = BDIGITS(x);
@ -84,7 +85,9 @@ rb_big_2comp(x) /* get 2's complement */
ds[i++] = BIGLO(num);
num = BIGDN(num);
} while (i < RBIGNUM(x)->len);
if (!carry) return;
if (ds[0] == 1 || ds[0] == 0) {
if (RBIGNUM(x)->len == 1) return;
for (i=1; i<RBIGNUM(x)->len; i++) {
if (ds[i] != 0) return;
}
@ -94,6 +97,13 @@ rb_big_2comp(x) /* get 2's complement */
}
}
void
rb_big_2comp(x) /* get 2's complement */
VALUE x;
{
return get2comp(x, Qtrue);
}
static VALUE
bignorm(x)
VALUE x;
@ -795,9 +805,9 @@ rb_big_neg(x)
long i = RBIGNUM(x)->len;
BDIGIT *ds = BDIGITS(z);
if (!RBIGNUM(x)->sign) rb_big_2comp(z);
if (!RBIGNUM(x)->sign) get2comp(z, Qtrue);
while (i--) ds[i] = ~ds[i];
if (RBIGNUM(x)->sign) rb_big_2comp(z);
if (RBIGNUM(x)->sign) get2comp(z, Qfalse);
RBIGNUM(z)->sign = !RBIGNUM(z)->sign;
return bignorm(z);
@ -1284,11 +1294,11 @@ rb_big_and(x, y)
if (!RBIGNUM(y)->sign) {
y = rb_big_clone(y);
rb_big_2comp(y);
get2comp(y, Qtrue);
}
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
rb_big_2comp(x);
get2comp(x, Qtrue);
}
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
l1 = RBIGNUM(y)->len;
@ -1313,7 +1323,7 @@ rb_big_and(x, y)
for (; i<l2; i++) {
zds[i] = sign?0:ds2[i];
}
if (!RBIGNUM(z)->sign) rb_big_2comp(z);
if (!RBIGNUM(z)->sign) get2comp(z, Qfalse);
return bignorm(z);
}
@ -1335,11 +1345,11 @@ rb_big_or(x, y)
if (!RBIGNUM(y)->sign) {
y = rb_big_clone(y);
rb_big_2comp(y);
get2comp(y, Qtrue);
}
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
rb_big_2comp(x);
get2comp(x, Qtrue);
}
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
l1 = RBIGNUM(y)->len;
@ -1364,7 +1374,7 @@ rb_big_or(x, y)
for (; i<l2; i++) {
zds[i] = sign?ds2[i]:(BIGRAD-1);
}
if (!RBIGNUM(z)->sign) rb_big_2comp(z);
if (!RBIGNUM(z)->sign) get2comp(z, Qfalse);
return bignorm(z);
}
@ -1387,11 +1397,11 @@ rb_big_xor(x, y)
if (!RBIGNUM(y)->sign) {
y = rb_big_clone(y);
rb_big_2comp(y);
get2comp(y, Qtrue);
}
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
rb_big_2comp(x);
get2comp(x, Qtrue);
}
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
l1 = RBIGNUM(y)->len;
@ -1418,7 +1428,7 @@ rb_big_xor(x, y)
for (; i<l2; i++) {
zds[i] = sign?ds2[i]:~ds2[i];
}
if (!RBIGNUM(z)->sign) rb_big_2comp(z);
if (!RBIGNUM(z)->sign) get2comp(z, Qfalse);
return bignorm(z);
}
@ -1477,7 +1487,7 @@ rb_big_rshift(x, y)
}
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
rb_big_2comp(x);
get2comp(x, Qtrue);
}
xds = BDIGITS(x);
i = RBIGNUM(x)->len; j = i - s1;
@ -1489,7 +1499,7 @@ rb_big_rshift(x, y)
num = BIGUP(xds[i]);
}
if (!RBIGNUM(x)->sign) {
rb_big_2comp(z);
get2comp(z, Qfalse);
}
return bignorm(z);
}
@ -1515,7 +1525,7 @@ rb_big_aref(x, y)
if (!RBIGNUM(x)->sign) {
if (s1 >= RBIGNUM(x)->len) return INT2FIX(1);
x = rb_big_clone(x);
rb_big_2comp(x);
get2comp(x, Qtrue);
}
else {
if (s1 >= RBIGNUM(x)->len) return INT2FIX(0);

1
file.c
View file

@ -2593,7 +2593,6 @@ Init_File()
rb_file_const("LOCK_NB", INT2FIX(LOCK_NB));
rb_define_method(rb_cFile, "path", rb_file_path, 0);
rb_define_global_function("test", rb_f_test, -1);
rb_cStat = rb_define_class_under(rb_cFile, "Stat", rb_cObject);

16
io.c
View file

@ -490,6 +490,21 @@ rb_io_pid(io)
return INT2FIX(fptr->pid);
}
static VALUE
rb_io_inspect(obj)
VALUE obj;
{
OpenFile *fptr;
char *buf, *cname;
GetOpenFile(obj, fptr);
if (!fptr->path) return rb_any_to_s(obj);
cname = rb_class2name(CLASS_OF(obj));
buf = ALLOCA_N(char, strlen(cname) + strlen(fptr->path) + 5);
sprintf(buf, "#<%s:%s>", cname, fptr->path);
return rb_str_new2(buf);
}
static VALUE
rb_io_to_io(io)
VALUE io;
@ -3691,6 +3706,7 @@ Init_IO()
rb_define_method(rb_cIO, "ioctl", rb_io_ioctl, -1);
rb_define_method(rb_cIO, "fcntl", rb_io_fcntl, -1);
rb_define_method(rb_cIO, "pid", rb_io_pid, 0);
rb_define_method(rb_cIO, "inspect", rb_io_inspect, 0);
rb_stdin = orig_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO);
rb_define_hooked_variable("$stdin", &rb_stdin, 0, set_stdin);

View file

@ -116,11 +116,7 @@ class Shell
attr_reader :process_controller
def expand_path(path)
if /^[\/~]/ =~ path
File.expand_path(path)
else
File.expand_path(File.join(@cwd, path))
end
File.expand_path(path)
end
# Most Shell commands are defined via CommandProcessor