Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

This commit was generated by cvs2svn to compensate for changes in r11,

which included commits to RCS files with non-trunk default branches.


git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@12 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit d951f6555b1ff1e66e8edad2bdeb9e386c67951e 1 parent 986c389
matz authored
Showing with 8,846 additions and 8,177 deletions.
  1. +463 −3,937 ChangeLog
  2. +22 −4 MANIFEST
  3. +54 −74 Makefile.in
  4. +44 −25 README
  5. +46 −27 README.jp
  6. +263 −285 array.c
  7. +178 −180 bignum.c
  8. +256 −85 class.c
  9. +1 −1  defines.h
  10. +19 −21 dir.c
  11. +62 −9 dln.c
  12. +41 −27 enum.c
  13. +4 −2 env.h
  14. +15 −10 error.c
  15. +981 −595 eval.c
  16. +1 −1  ext/Setup
  17. +31 −36 ext/curses/curses.c
  18. +3 −5 ext/dbm/dbm.c
  19. +1 −1  ext/dbm/depend
  20. +1 −1  ext/etc/depend
  21. +44 −32 ext/extmk.rb.in
  22. +66 −49 ext/extmk.rb.nt
  23. +1 −1  ext/fcntl/depend
  24. +1 −1  ext/kconv/depend
  25. +100 −22 ext/kconv/kconv.c
  26. +1 −1  ext/md5/depend
  27. +1 −1  ext/socket/depend
  28. +13 −4 ext/socket/extconf.rb
  29. +299 −105 ext/socket/socket.c
  30. +1 −1  ext/tkutil/depend
  31. +121 −156 file.c
  32. +107 −61 gc.c
  33. +252 −108 hash.c
  34. +34 −2 inits.c
  35. +216 −87 io.c
  36. +6 −1 io.h
  37. +59 −18 lib/cgi-lib.rb
  38. +18 −18 lib/finalize.rb
  39. +21 −22 lib/mailread.rb
  40. +73 −17 lib/sync.rb
  41. +499 −74 lib/tk.rb
  42. +2 −2 lib/tktext.rb
  43. +18 −34 math.c
  44. +0 −63 missing/dir.h
  45. +9 −6 missing/nt.c
  46. +137 −0 missing/nt.h
  47. +73 −1 missing/setenv.c
  48. +35 −8 node.h
  49. +84 −92 numeric.c
  50. +317 −76 object.c
  51. +96 −37 pack.c
  52. +532 −306 parse.y
  53. +96 −36 process.c
  54. +2 −1  random.c
  55. +2 −1  range.c
  56. +305 −104 re.c
  57. +5 −2 re.h
  58. +1,021 −440 regex.c
  59. +3 −6 regex.h
  60. +109 −28 ruby.c
  61. +106 −44 ruby.h
  62. +1 −1  sample/exyacc.rb
  63. +6 −4 sample/fact.rb
  64. +1 −1  sample/mkproto.rb
  65. +8 −3 sample/ruby-mode.el
  66. +126 −118 sample/test.rb
  67. +7 −10 sample/tkhello.rb
  68. +21 −15 sample/uumerge.rb
  69. +6 −6 sprintf.c
  70. +464 −326 string.c
  71. +61 −66 struct.c
  72. +38 −27 time.c
  73. +3 −3 top.sed
  74. +42 −12 util.c
  75. +259 −136 variable.c
  76. +1 −1  version.c
  77. +2 −2 version.h
  78. +25 −17 win32/Makefile
  79. +404 −35 win32/ruby.def
View
4,400 ChangeLog
463 additions, 3,937 deletions not shown
View
26 MANIFEST
@@ -1,3 +1,4 @@
+COPYING
ChangeLog
MANIFEST
Makefile.in
@@ -32,10 +33,16 @@ glob.c
hash.c
inits.c
install-sh
+instruby.rb
+intern.h
io.c
io.h
+keywords
+lex.c
main.c
+marshal.c
math.c
+mkconfig.rb
node.h
numeric.c
object.c
@@ -51,6 +58,7 @@ regex.h
ruby.1
ruby.c
ruby.h
+rubytest.rb
sig.h
signal.c
sprintf.c
@@ -78,34 +86,41 @@ lib/cgi-lib.rb
lib/complex.rb
lib/date.rb
lib/debug.rb
+lib/delegate.rb
lib/e2mmap.rb
-lib/e2mmap1_0.rb
+lib/eregex.rb
lib/find.rb
lib/finalize.rb
lib/ftplib.rb
+lib/ftools.rb
lib/getopts.rb
+lib/importenv.rb
lib/jcode.rb
lib/mailread.rb
lib/mathn.rb
lib/matrix.rb
+lib/mkmf.rb
lib/mutex_m.rb
lib/observer.rb
+lib/ostruct.rb
lib/parsearg.rb
lib/parsedate.rb
lib/ping.rb
+lib/pstore.rb
lib/rational.rb
+lib/shellwords.rb
lib/sync.rb
lib/thread.rb
lib/thwait.rb
lib/tk.rb
-lib/tkcore.rb
lib/tkcanvas.rb
lib/tkclass.rb
+lib/tkdialog.rb
lib/tkentry.rb
lib/tkscrollbox.rb
lib/tktext.rb
-lib/tkthcore.rb
lib/tracer.rb
+lib/weakref.rb
missing/alloca.c
missing/crypt.c
missing/dir.h
@@ -126,6 +141,7 @@ missing/strtol.c
missing/strtoul.c
missing/x68.c
sample/biorhythm.rb
+sample/cbreak.rb
sample/clnt.rb
sample/dbmtest.rb
sample/dir.rb
@@ -141,7 +157,6 @@ sample/freq.rb
sample/from.rb
sample/fullpath.rb
sample/getopts.test
-sample/io.rb
sample/less.rb
sample/list.rb
sample/list2.rb
@@ -155,6 +170,7 @@ sample/occur.rb
sample/occur2.rb
sample/philos.rb
sample/pi.rb
+sample/rbc.rb
sample/rcs.awk
sample/rcs.dat
sample/rcs.rb
@@ -180,6 +196,8 @@ win32/Makefile
win32/config.h
win32/ntsetup.bat
win32/ruby.def
+win32/sdbm.c
+win32/sdbm.h
x68/fconvert.c
x68/select.c
x68/_dtos18.c
View
128 Makefile.in
@@ -7,9 +7,6 @@ VPATH = @srcdir@:@srcdir@/missing
CC = @CC@
YACC = @YACC@
-INSTALL = @INSTALL@
-INSTALL_PROGRAM = @INSTALL_PROGRAM@
-INSTALL_DATA = @INSTALL_DATA@
PURIFY =
@SET_MAKE@
@@ -18,14 +15,6 @@ LDFLAGS = @STATIC@ $(CFLAGS) @LDFLAGS@
LIBS = @LIBS@ $(EXTLIBS)
MISSING = @LIBOBJS@ @ALLOCA@
-program_transform_name = -e @program_transform_name@
-RUBY_INSTALL_NAME = `t='$(program_transform_name)'; echo ruby | sed $$t`
-
-prefix = @prefix@
-exec_prefix = @exec_prefix@
-bindir = @bindir@
-libdir = @libdir@/$(RUBY_INSTALL_NAME)
-
binsuffix = @binsuffix@
#### End of system configuration section. ####
@@ -33,7 +22,7 @@ binsuffix = @binsuffix@
LIBRUBY = libruby.a
-EXTOBJS = dmyext.o
+EXTOBJS =
MAINOBJ = main.o
@@ -54,6 +43,7 @@ OBJS = array.o \
inits.o \
io.o \
math.o \
+ marshal.o \
numeric.o \
object.o \
pack.o \
@@ -75,15 +65,12 @@ OBJS = array.o \
version.o \
$(MISSING)
-all: miniruby$(binsuffix) @srcdir@/ext/Setup
- @if test -z "$$UNDER_EXTMAKE_RB"; \
- then echo "Compiling ext modules"; \
- UNDER_EXTMAKE_RB=yes; export UNDER_EXTMAKE_RB; \
- cd ext; ../miniruby ./extmk.rb @EXTSTATIC@; fi
+all: miniruby$(binsuffix) rbconfig.rb
+ @cd ext; ../miniruby$(binsuffix) ./extmk.rb @EXTSTATIC@
-miniruby$(binsuffix): $(OBJS) $(MAINOBJ) $(EXTOBJS)
+miniruby$(binsuffix): $(OBJS) $(MAINOBJ) dmyext.o
@rm -f $@
- $(PURIFY) $(CC) $(LDFLAGS) $(MAINOBJ) $(OBJS) $(EXTOBJS) $(LIBS) -o miniruby
+ $(PURIFY) $(CC) $(LDFLAGS) $(MAINOBJ) $(OBJS) dmyext.o $(LIBS) -o miniruby
ruby$(binsuffix): $(LIBRUBY) $(MAINOBJ) $(EXTOBJS)
@rm -f $@
@@ -93,36 +80,31 @@ $(LIBRUBY): $(OBJS) dmyext.o
@AR@ rcu $(LIBRUBY) $(OBJS) dmyext.o
@-@RANLIB@ $(LIBRUBY) 2> /dev/null || true
-install:; $(INSTALL_PROGRAM) ruby$(binsuffix) $(bindir)/$(RUBY_INSTALL_NAME)$(binsuffix)
- @-@STRIP@ $(bindir)/$(RUBY_INSTALL_NAME)$(binsuffix)
- @test -d $(libdir) || mkdir $(libdir)
- cd ext; ../miniruby ./extmk.rb install
- @for rb in `grep '^lib/' @srcdir@/MANIFEST`; do \
- $(INSTALL_DATA) @srcdir@/$$rb $(libdir); \
- done
+install: rbconfig.rb
+ ./miniruby$(binsuffix) $(srcdir)/instruby.rb
-clean:; @rm -f $(OBJS) $(LIBRUBY) $(MAINOBJ)
+clean:; @rm -f $(OBJS) $(LIBRUBY) $(MAINOBJ) rbconfig.rb
@rm -f ext/extinit.c ext/extinit.o dmyext.o
- cd ext; ../miniruby ./extmk.rb clean
+ @if test -f ./miniruby; then cd ext; ../miniruby ./extmk.rb clean; fi
realclean: clean
- @rm -f Makefile ext/extmk.rb ext/config.cache parse.c
+ @rm -f Makefile ext/extmk.rb ext/config.cache
@rm -f config.cache config.h config.log config.status
- @rm -f core ruby$(binsuffix) miniruby$(binsuffix) parse.c *~ *.core gmon.out
-
-test:; @-./ruby @srcdir@/sample/test.rb > ./ruby_test 2>&1; \
- if grep '^end of test' ./ruby_test > /dev/null; then \
- echo "test succeeded"; \
- else \
- grep '^sample/test.rb' ./ruby_test; \
- grep '^not' ./ruby_test; \
- echo "test failed";\
- fi;\
- rm -f ./ruby_test
+ @rm -f parse.c lex.c *~ core *.core gmon.out
+ @rm -f ruby$(binsuffix) miniruby$(binsuffix)
+
+test: miniruby$(binsuffix)
+ @./miniruby$(binsuffix) $(srcdir)/rubytest.rb
+
+rbconfig.rb: config.status miniruby$(binsuffix)
+ @./miniruby$(binsuffix) $(srcdir)/mkconfig.rb rbconfig.rb
.c.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
+lex.c: keywords
+ gperf -p -j1 -i 1 -g -o -t -N rb_reserved_word -k1,3,$$ keywords > lex.c
+
parse.c: parse.y
$(YACC) $<
mv -f y.tab.c parse.c
@@ -178,42 +160,40 @@ x68.o: @srcdir@/missing/x68.c
# Prevent GNU make v3 from overflowing arg limit on SysV.
.NOEXPORT:
###
-parse.o : parse.y ruby.h defines.h config.h env.h node.h st.h regex.h
+parse.o : parse.y ruby.h defines.h config.h intern.h env.h node.h st.h regex.h lex.c
###
-array.o: array.c ruby.h config.h defines.h
-bignum.o: bignum.c ruby.h config.h defines.h
-class.o: class.c ruby.h config.h defines.h node.h st.h
-compar.o: compar.c ruby.h config.h defines.h
-dir.o: dir.c ruby.h config.h defines.h
+array.o: array.c ruby.h config.h defines.h intern.h
+bignum.o: bignum.c ruby.h config.h defines.h intern.h
+class.o: class.c ruby.h config.h defines.h intern.h node.h st.h
+compar.o: compar.c ruby.h config.h defines.h intern.h
+dir.o: dir.c ruby.h config.h defines.h intern.h
dln.o: dln.c config.h defines.h dln.h st.h
dmyext.o: dmyext.c
-enum.o: enum.c ruby.h config.h defines.h
-error.o: error.c ruby.h config.h defines.h env.h
-eval.o: eval.c ruby.h config.h defines.h env.h node.h sig.h st.h dln.h
-file.o: file.c ruby.h config.h defines.h io.h sig.h
-fnmatch.o: fnmatch.c config.h fnmatch.h
-gc.o: gc.c ruby.h config.h defines.h env.h sig.h st.h node.h re.h regex.h
-glob.o: glob.c config.h fnmatch.h
-hash.o: hash.c ruby.h config.h defines.h st.h
-inits.o: inits.c ruby.h config.h defines.h
-io.o: io.c ruby.h config.h defines.h io.h sig.h
+enum.o: enum.c ruby.h config.h defines.h intern.h
+error.o: error.c ruby.h config.h defines.h intern.h env.h
+eval.o: eval.c ruby.h config.h defines.h intern.h env.h node.h sig.h st.h dln.h
+file.o: file.c ruby.h config.h defines.h intern.h io.h sig.h
+gc.o: gc.c ruby.h config.h defines.h intern.h env.h sig.h st.h node.h re.h regex.h
+hash.o: hash.c ruby.h config.h defines.h intern.h st.h
+inits.o: inits.c ruby.h config.h defines.h intern.h
+io.o: io.c ruby.h config.h defines.h intern.h io.h sig.h
main.o: main.c
-math.o: math.c ruby.h config.h defines.h
-numeric.o: numeric.c ruby.h config.h defines.h
-object.o: object.c ruby.h config.h defines.h st.h
-pack.o: pack.c ruby.h config.h defines.h
-process.o: process.c ruby.h config.h defines.h sig.h st.h
-random.o: random.c ruby.h config.h defines.h
-range.o: range.c ruby.h config.h defines.h
-re.o: re.c ruby.h config.h defines.h re.h regex.h
-regex.o: regex.c config.h defines.h regex.h util.h
-ruby.o: ruby.c ruby.h config.h defines.h re.h regex.h dln.h
-signal.o: signal.c ruby.h config.h defines.h sig.h
-sprintf.o: sprintf.c ruby.h config.h defines.h
+marshal.o: marshal.c ruby.h config.h defines.h intern.h io.h sig.h st.h
+math.o: math.c ruby.h config.h defines.h intern.h
+numeric.o: numeric.c ruby.h config.h defines.h intern.h
+object.o: object.c ruby.h config.h defines.h intern.h st.h
+pack.o: pack.c ruby.h config.h defines.h intern.h
+process.o: process.c ruby.h config.h defines.h intern.h sig.h st.h
+random.o: random.c ruby.h config.h defines.h intern.h
+range.o: range.c ruby.h config.h defines.h intern.h
+re.o: re.c ruby.h config.h defines.h intern.h re.h regex.h
+ruby.o: ruby.c ruby.h config.h defines.h intern.h re.h regex.h dln.h
+signal.o: signal.c ruby.h config.h defines.h intern.h sig.h
+sprintf.o: sprintf.c ruby.h config.h defines.h intern.h
st.o: st.c config.h st.h
-string.o: string.c ruby.h config.h defines.h re.h regex.h
-struct.o: struct.c ruby.h config.h defines.h
-time.o: time.c ruby.h config.h defines.h
-util.o: util.c defines.h config.h util.h
-variable.o: variable.c ruby.h config.h defines.h env.h st.h
-version.o: version.c ruby.h config.h defines.h version.h
+string.o: string.c ruby.h config.h defines.h intern.h re.h regex.h
+struct.o: struct.c ruby.h config.h defines.h intern.h
+time.o: time.c ruby.h config.h defines.h intern.h
+util.o: util.c defines.h intern.h config.h util.h
+variable.o: variable.c ruby.h config.h defines.h intern.h env.h st.h
+version.o: version.c ruby.h config.h defines.h intern.h version.h
View
69 README
@@ -5,7 +5,7 @@ easy object-oriented programming. It has many features to
process text files and to do system management tasks (as in
perl). It is simple, straight-forward, and extensible.
-* Features of ruby
+* Features of Ruby
+ Simple Syntax
+ *Normal* Object-Oriented features(ex. class, method calls)
@@ -17,17 +17,15 @@ perl). It is simple, straight-forward, and extensible.
+ Dynamic Loading of Object files(on some architecture)
+ Highly Portable(works on many UNIX machines)
-* How to get ruby
+* How to get Ruby
-** by ftp
-
-The ruby distribution can be found on
+The Ruby distribution can be found on
ftp://ftp.netlab.co.jp/pub/lang/ruby/
* How to compile and install
-This is what you need to do to compile and install ruby:
+This is what you need to do to compile and install Ruby:
1. Run ./configure, which will generate config.h and Makefile.
@@ -41,40 +39,61 @@ This is what you need to do to compile and install ruby:
4. Run make.
- 5. Optionally, run 'make test' to check that the compiled ruby
+ 5. Optionally, run 'make test' to check that the compiled Ruby
interpreter works well. If you see the message "test succeeded",
- your ruby works as it should.
+ your Ruby works as it should (hopefully).
6. Run 'make install'
-If you fail to compile ruby, please send the detailed error report with
+If you fail to compile Ruby, please send the detailed error report with
the error log and machine/OS type, to help others.
* Copying
-Ruby is copyrighted by Yukihiro Matsumoto <matz@ruby.club.co.jp>.
+Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>.
+You can redistribute it and/or modify it under either the terms of the GPL
+(see COPYING file), or the conditions below:
+
+ 1. You may make and give away verbatim copies of the source form of the
+ software without restriction, provided that you duplicate all of the
+ original copyright notices and associated disclaimers.
+
+ 2. You may modify your copy of the software in any way, provided that
+ you do at least ONE of the following:
+
+ a) place your modifications in the Public Domain or otherwise make them
+ Freely Available, such as by posting said modifications to Usenet
+ or an equivalent medium, or by allowing the author to include your
+ modifications in the software.
+
+ b) use the modified software only within your corporation or organization.
+
+ c) rename any non-standard executables so the names do not conflict
+ with standard executables, which must also be provided.
+
+ d) make other distribution arrangements with the author.
-This source is distributed under the conditions blow:
+ 3. You may distribute the software in object code or executable
+ form, provided that you do at least ONE of the following:
- 1. You may make and give away verbatim copies of the source form of
- the software without restriction, provided that you do not modify
- the original distribution files.
+ a) distribute the executables and library files of the software,
+ together with instructions (in the manual page or equivalent)
+ on where to get the original distribution.
- If you want to distribute the modified version in any way, contact
- the author.
+ b) accompany the distribution with the machine-readable source of
+ the software.
- 2. You may distribute the software in object code or executable
- form, provided that you distribute it with instructions on where
- to get the software.
+ c) give non-standard executables non-standard names, with
+ instructions on where to get the original software
+ distribution.
- 3. You may modify the software in any way, provided that you do not
- distribute the modified version.
+ d) make other distribution arrangements with the author.
4. You may modify and include the part of the software into any other
software (possibly commercial). But some files in the distribution
are not written by the author, so that they are not under this terms.
- They are gc.c(partly)��utils.c(partly), regex.[ch]��fnmatch.[ch]��
- glob.c, st.[ch] and somme files under the ./missing directory. See
+ They are gc.c(partly), utils.c(partly), regex.[ch], fnmatch.[ch],
+ glob.c, st.[ch] and some files under the ./missing directory. See
each files for the copying condition.
5. The scripts and library files supplied as input to or produced as
@@ -88,9 +107,9 @@ This source is distributed under the conditions blow:
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
PURPOSE.
-* ruby home-page
+* Ruby home-page
- The URL of the ruby home-page is:
+The URL of the Ruby home-page is:
http://www.netlab.co.jp/ruby/
View
73 README.jp
@@ -9,6 +9,7 @@ Ruby
�Ǥ�������˥���ץ��ʸˡ�ȡ��㳰����䥤�ƥ졼���ʤɤε���
�ˤ�äơ����ʬ����䤹���ץ���ߥ󥰤�����ޤ���
+
* Ruby������
+ ����ץ��ʸˡ
@@ -21,6 +22,7 @@ Ruby
+ ����ʥߥå����ǥ��� (�������ƥ����ˤ��)
+ �ܿ�����⤤��¿����UNIX���ư��
+
* ����ˡ
** ftp��
@@ -29,6 +31,7 @@ Ruby
ftp://ftp.netlab.co.jp/pub/lang/ruby/
+
* �ۡ���ڡ���
Ruby�Υۡ���ڡ�����URL��
@@ -37,6 +40,7 @@ Ruby
�Ǥ���
+
* �ᥤ��󥰥ꥹ��
Ruby�˴ؤ������Τ���Υᥤ��󥰥ꥹ�Ȥ��ߤ��ޤ�������
@@ -46,6 +50,7 @@ Ruby
�Ǥ������Υ��ɥ쥹�˥ᥤ������С���ưŪ����Ͽ����ޤ���
+
* ����ѥ��롦���󥹥ȡ���
�ʲ��μ��ǹԤäƤ��������
@@ -80,13 +85,14 @@ Ruby
����OS�μ����ޤ�Ǥ������ܤ�����ݡ��Ȥ��Ԥ���äƤ�
������¾����Τ���ˤ�ʤ�ޤ���
+
* �ܿ�
UNIX�Ǥ����configure���ۤȤ�ɤκ��ۤ�ۼ�Ƥ����Ϥ���
�������פ�̸���Ȥ������ä����(����˰㤤�ʤ�)����Ԥˤ���
���Ȥ��ݡ��Ȥ���С����Ǥ��뤫���Τ�ޤ���
-�������ƥ����ˤ�äȤ��¸����Τ�GC��Ǥ���ruby��GC���о�
+�������ƥ����ˤ�äȤ��¸����Τ�GC��Ǥ���Ruby��GC���о�
�Υ������ƥ���㤬setjmp()�ˤ�ä���ƤΥ쥸������ jmp_buf��
��Ǽ���뤳�Ȥȡ�jmp_buf�ȥ����å���32bit���饤����Ȥ����
���뤳�Ȥ��ꤷ�Ƥ��ޤ����ä���Ԥ��Ω���ʤ������б�����
@@ -95,50 +101,63 @@ UNIX
�����륳���ɤ��ɲä������ǺѤߤޤ�����defined(THINK_C)�פ�
����Ƥ�����ʬ�򻲹ͤˤ��Ƥ������
-# �ºݤˤ�ruby��Think C�Ǥϥ���ѥ���Ǥ��ޤ���
+# �ºݤˤ�Ruby��Think C�Ǥϥ���ѥ���Ǥ��ޤ���
�쥸����������ɥ�����CPU�Ǥϡ��쥸����������ɥ��򥹥���
���˥ե�å��夹�륢����֥饳���ɤ��ɲä���ɬ�פ����뤫����
��ޤ���
+
* ���۾��
-��Ԥϰʲ��ξ��Τ�Ȥ�ruby�����ۤ��ޤ���
+RUby�ϥե꡼���եȥ������Ǥ���GPL(the GNU General Public
+Licence)�ޤ��ϰʲ��˼�������Ruby������ۤǤ��ޤ���GPL�ˤ�
+���Ƥ�COPYING�ե�����򻲾Ȥ��Ʋ�������
+
+ 1. ʣ�����¤ʤ���ͳ�Ǥ���
+
+ 2. �ʲ��ξ��Τ����줫�����������˼긵��Ruby�Υ�������
+ ͳ���ѹ��Ǥ��ޤ���
+
+ (a) �ͥåȥ˥塼���˥ݥ��Ȥ����ꡤ��Ԥ��ѹ������դ���
+ �ʤɤ���ˡ�ǡ��ѹ������
+
+ (b) �ѹ�����Ruby��ʬ�ν�°�����ȿ��������ǻȤ�
- + ������
+ (c) �ѹ��������������������եȥ�������̾����ѹ����롥
+ ���Υ��եȥ����������ۤ�����ˤϤ�Ȥ�Ruby��Ʊ����
+ ���ۤ���
- ���ۤ������֤�ݻ��¤꼫ͳ�Ǥ����ѹ���Ԥä���Τ��
- ���ۤ��뤳�Ȥ��˾������ˤϺ�Ԥ�Ϣ���Ƥ��������
+ (d) ����¾���ѹ������Ԥȹ�դ���
- �ѹ���Ԥʤ�ʤ�ruby�򥳥�ѥ��뤷���Х��ʥ�����ۤ϶ػ�
- ���ޤ��󤬡��Х��ʥ����ä��ͤ�������������Ǥ����
- ���ˡ�������������ˡ��������Ƥ��������
+ 3. �ʲ��ξ��Τ����줫������������Ruby�򥪥֥������ȥ���
+ �ɤ�¹Է���Ǥ����ۤǤ��ޤ���
- + �ѹ�
+ (a) �Х��ʥ����ä��ͤ�������������Ǥ���褦�˥���
+ ��������ˡ���������
- �����ۤ�Ԥ�ʤ��¤ꡤ�����ʤ���Ū�Ǥ��켫ͳ�Ǥ����������
- ��ǽ��ĥ��Х�����Ϻ�ԤؤΥե����ɥХå�����Ԥ��ޤ�
- (�������ǤϤ���ޤ���)��
+ (b) �������ɤʥ����������ɤ�ź�դ���
- + ¾�Υץ����ؤΰ���
+ (c) �ѹ���Ԥä��Х��ʥ��̾����ѹ�������������������
+ ����ˡ���������
- �����ʤ���Ū�Ǥ��켫ͳ�Ǥ����������ruby�˴ޤޤ��¾�κ�
- �Ԥˤ�륳���ɤϡ����줾��κ�Ԥΰո��ˤ����¤��ä���
- ��ޤ�������Ū�ˤ�gc.c(����)��util.c(����)��regex.[ch]��
- fnmatch.[ch]��glob.c��st.[ch]��./missing�ǥ��쥯�ȥ겼��
- �ե����뷲������ޤ���
+ (d) ����¾�����۾����Ԥȹ�դ���
- + Ruby������ץȤθ���
+ 4. ¾�Υץ����ؤΰ��ѤϤ����ʤ���Ū�Ǥ��켫ͳ�Ǥ�����
+ �����Ruby�˴ޤޤ��¾�κ�Ԥˤ�륳���ɤϡ����줾���
+ ��Ԥΰո��ˤ����¤��ä����ޤ�������Ū�ˤ�gc.c(����)��
+ util.c(����)��st.[ch]��regex.[ch], fnmatch.[ch], glob.c
+ �����./missing�ǥ��쥯�ȥ겼�Υե����뷲������ޤ���
- ��Ƥ�ruby������ץȤθ���Ϥ��줾������Ԥ�°���ޤ���
- ��ԤϤ����˴ؤ��ư��ڤθ�����ĥ���ޤ��󡥤ޤ�ruby��
- �Ȥ߹��ि��γ�ĥ�⥸�塼��˴ؤ��Ƥ�Ʊ�ͤǤ���
+ 5. Ruby�ؤ����ϤȤʤ륹����ץȤ���ӡ�Ruby����ν��Ϥθ�
+ ���Ruby�κ�ԤǤϤʤ������줾��������Ϥ��������ͤ�
+ °���ޤ����ޤ���Ruby���Ȥ߹��ि��γ�ĥ�⥸�塼��ˤ�
+ ���Ƥ�Ʊ�ͤǤ���
- + ̵�ݾ�
+ 6. Ruby��̵�ݾڤǤ�����Ԥ�Ruby�򥵥ݡ��Ȥ���ջ֤Ϥ����
+ ������Ruby���ȤΥХ����뤤��Ruby������ץȤΥХ��ʤɤ�
+ ��ȯ����뤤���ʤ�»�����Ф��Ƥ���Ǥ����ޤ���
- Ruby��̵�ݾڤǤ�����Ԥ�ruby�򥵥ݡ��Ȥ���ջ֤Ϥ���ޤ�
- ����ruby���ȤΥХ����뤤��ruby������ץȤΥХ��ʤɤ���ȯ
- ����뤤���ʤ�»�����Ф��Ƥ���Ǥ����ޤ���
* ���
View
548 array.c
@@ -12,9 +12,8 @@
#include "ruby.h"
-VALUE cArray;
-VALUE rb_to_a();
+VALUE cArray;
#define ARY_DEFAULT_SIZE 16
@@ -90,22 +89,22 @@ ary_new3(n, va_alist)
va_dcl
{
va_list ar;
- struct RArray* ary;
+ VALUE ary;
int i;
if (n < 0) {
IndexError("Negative number of items(%d)", n);
}
- ary = (struct RArray*)ary_new2(n<ARY_DEFAULT_SIZE?ARY_DEFAULT_SIZE:n);
+ ary = ary_new2(n<ARY_DEFAULT_SIZE?ARY_DEFAULT_SIZE:n);
va_start(ar);
for (i=0; i<n; i++) {
- ary->ptr[i] = va_arg(ar, VALUE);
+ RARRAY(ary)->ptr[i] = va_arg(ar, VALUE);
}
va_end(ar);
- ary->len = n;
- return (VALUE)ary;
+ RARRAY(ary)->len = n;
+ return ary;
}
VALUE
@@ -113,27 +112,27 @@ ary_new4(n, elts)
int n;
VALUE *elts;
{
- struct RArray* ary;
+ VALUE ary;
- ary = (struct RArray*)ary_new2(n);
- MEMCPY(ary->ptr, elts, VALUE, n);
- ary->len = n;
+ ary = ary_new2(n);
+ MEMCPY(RARRAY(ary)->ptr, elts, VALUE, n);
+ RARRAY(ary)->len = n;
- return (VALUE)ary;
+ return ary;
}
VALUE
assoc_new(car, cdr)
VALUE car, cdr;
{
- struct RArray* ary;
+ VALUE ary;
- ary = (struct RArray*)ary_new2(2);
- ary->ptr[0] = car;
- ary->ptr[1] = cdr;
- ary->len = 2;
+ ary = ary_new2(2);
+ RARRAY(ary)->ptr[0] = car;
+ RARRAY(ary)->ptr[1] = cdr;
+ RARRAY(ary)->len = 2;
- return (VALUE)ary;
+ return ary;
}
static VALUE
@@ -179,7 +178,7 @@ ary_s_create(argc, argv, class)
void
ary_store(ary, idx, val)
- struct RArray *ary;
+ VALUE ary;
int idx;
VALUE val;
{
@@ -188,69 +187,69 @@ ary_store(ary, idx, val)
IndexError("negative index for array");
}
- if (idx >= ary->capa) {
- ary->capa = idx + ARY_DEFAULT_SIZE;
- REALLOC_N(ary->ptr, VALUE, ary->capa);
+ if (idx >= RARRAY(ary)->capa) {
+ RARRAY(ary)->capa = idx + ARY_DEFAULT_SIZE;
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
}
- if (idx > ary->len) {
- memclear(ary->ptr+ary->len, idx-ary->len+1);
+ if (idx > RARRAY(ary)->len) {
+ memclear(RARRAY(ary)->ptr+RARRAY(ary)->len, idx-RARRAY(ary)->len+1);
}
- if (idx >= ary->len) {
- ary->len = idx + 1;
+ if (idx >= RARRAY(ary)->len) {
+ RARRAY(ary)->len = idx + 1;
}
- ary->ptr[idx] = val;
+ RARRAY(ary)->ptr[idx] = val;
}
VALUE
ary_push(ary, item)
- struct RArray *ary;
+ VALUE ary;
VALUE item;
{
- ary_store(ary, ary->len, item);
- return (VALUE)ary;
+ ary_store(ary, RARRAY(ary)->len, item);
+ return ary;
}
static VALUE
ary_push_method(argc, argv, ary)
int argc;
VALUE *argv;
- struct RArray *ary;
+ VALUE ary;
{
while (argc--) {
- ary_store(ary, ary->len, *argv++);
+ ary_store(ary, RARRAY(ary)->len, *argv++);
}
- return (VALUE)ary;
+ return ary;
}
VALUE
ary_pop(ary)
- struct RArray *ary;
+ VALUE ary;
{
- if (ary->len == 0) return Qnil;
- if (ary->len * 10 < ary->capa && ary->capa > ARY_DEFAULT_SIZE) {
- ary->capa = ary->len * 2;
- REALLOC_N(ary->ptr, VALUE, ary->capa);
+ if (RARRAY(ary)->len == 0) return Qnil;
+ if (RARRAY(ary)->len * 10 < RARRAY(ary)->capa && RARRAY(ary)->capa > ARY_DEFAULT_SIZE) {
+ RARRAY(ary)->capa = RARRAY(ary)->len * 2;
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
}
- return ary->ptr[--ary->len];
+ return RARRAY(ary)->ptr[--RARRAY(ary)->len];
}
VALUE
ary_shift(ary)
- struct RArray *ary;
+ VALUE ary;
{
VALUE top;
- if (ary->len == 0) return Qnil;
+ if (RARRAY(ary)->len == 0) return Qnil;
- top = ary->ptr[0];
- ary->len--;
+ top = RARRAY(ary)->ptr[0];
+ RARRAY(ary)->len--;
/* sliding items */
- MEMMOVE(ary->ptr, ary->ptr+1, VALUE, ary->len);
- if (ary->len * 10 < ary->capa && ary->capa > ARY_DEFAULT_SIZE) {
- ary->capa = ary->len * 2;
- REALLOC_N(ary->ptr, VALUE, ary->capa);
+ MEMMOVE(RARRAY(ary)->ptr, RARRAY(ary)->ptr+1, VALUE, RARRAY(ary)->len);
+ if (RARRAY(ary)->len * 10 < RARRAY(ary)->capa && RARRAY(ary)->capa > ARY_DEFAULT_SIZE) {
+ RARRAY(ary)->capa = RARRAY(ary)->len * 2;
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
}
return top;
@@ -258,65 +257,64 @@ ary_shift(ary)
VALUE
ary_unshift(ary, item)
- struct RArray *ary;
- int item;
+ VALUE ary, item;
{
ary_modify(ary);
- if (ary->len >= ary->capa) {
- ary->capa+=ARY_DEFAULT_SIZE;
- REALLOC_N(ary->ptr, VALUE, ary->capa);
+ if (RARRAY(ary)->len >= RARRAY(ary)->capa) {
+ RARRAY(ary)->capa+=ARY_DEFAULT_SIZE;
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
}
/* sliding items */
- MEMMOVE(ary->ptr+1, ary->ptr, VALUE, ary->len);
+ MEMMOVE(RARRAY(ary)->ptr+1, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
- ary->len++;
- return ary->ptr[0] = item;
+ RARRAY(ary)->len++;
+ return RARRAY(ary)->ptr[0] = item;
}
VALUE
ary_entry(ary, offset)
- struct RArray *ary;
+ VALUE ary;
int offset;
{
- if (ary->len == 0) return Qnil;
+ if (RARRAY(ary)->len == 0) return Qnil;
if (offset < 0) {
- offset = ary->len + offset;
+ offset = RARRAY(ary)->len + offset;
}
- if (offset < 0 || ary->len <= offset) {
+ if (offset < 0 || RARRAY(ary)->len <= offset) {
return Qnil;
}
- return ary->ptr[offset];
+ return RARRAY(ary)->ptr[offset];
}
static VALUE
ary_subseq(ary, beg, len)
- struct RArray *ary;
+ VALUE ary;
int beg, len;
{
- struct RArray *ary2;
+ VALUE ary2;
if (beg < 0) {
- beg = ary->len + beg;
+ beg = RARRAY(ary)->len + beg;
if (beg < 0) beg = 0;
}
if (len < 0) {
- IndexError("negative length %d", ary->len);
+ IndexError("negative length %d", RARRAY(ary)->len);
}
if (len == 0) {
return ary_new2(0);
}
- if (beg + len > ary->len) {
- len = ary->len - beg;
+ if (beg + len > RARRAY(ary)->len) {
+ len = RARRAY(ary)->len - beg;
}
- ary2 = (struct RArray*)ary_new2(len);
- MEMCPY(ary2->ptr, ary->ptr+beg, VALUE, len);
- ary2->len = len;
+ ary2 = ary_new2(len);
+ MEMCPY(RARRAY(ary2)->ptr, RARRAY(ary)->ptr+beg, VALUE, len);
+ RARRAY(ary2)->len = len;
- return (VALUE)ary2;
+ return ary2;
}
static VALUE
@@ -346,7 +344,6 @@ beg_len(range, begp, lenp, len)
end = len + end;
if (end < 0) end = -1;
}
- if (end > len) end = len;
if (beg > end) {
*lenp = 0;
}
@@ -357,11 +354,11 @@ beg_len(range, begp, lenp, len)
return TRUE;
}
-static VALUE
+VALUE
ary_aref(argc, argv, ary)
int argc;
VALUE *argv;
- struct RArray *ary;
+ VALUE ary;
{
VALUE arg1, arg2;
int beg, len;
@@ -381,7 +378,7 @@ ary_aref(argc, argv, ary)
}
else {
/* check if idx is Range */
- if (beg_len(arg1, &beg, &len, ary->len)) {
+ if (beg_len(arg1, &beg, &len, RARRAY(ary)->len)) {
return ary_subseq(ary, beg, len);
}
}
@@ -393,13 +390,13 @@ ary_aref(argc, argv, ary)
static VALUE
ary_index(ary, val)
- struct RArray *ary;
+ VALUE ary;
VALUE val;
{
int i;
- for (i=0; i<ary->len; i++) {
- if (rb_equal(ary->ptr[i], val))
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ if (rb_equal(RARRAY(ary)->ptr[i], val))
return INT2FIX(i);
}
return Qnil;
@@ -407,7 +404,7 @@ ary_index(ary, val)
static VALUE
ary_indexes(ary, args)
- struct RArray *ary, *args;
+ VALUE ary, args;
{
VALUE *p, *pend;
VALUE new_ary;
@@ -417,9 +414,9 @@ ary_indexes(ary, args)
return ary_new2(0);
}
- new_ary = ary_new2(args->len);
+ new_ary = ary_new2(RARRAY(args)->len);
- p = args->ptr; pend = p + args->len;
+ p = RARRAY(args)->ptr; pend = p + RARRAY(args)->len;
while (p < pend) {
ary_store(new_ary, i++, ary_entry(ary, NUM2INT(*p)));
p++;
@@ -429,49 +426,49 @@ ary_indexes(ary, args)
static void
ary_replace(ary, beg, len, rpl)
- struct RArray *ary, *rpl;
+ VALUE ary, rpl;
int beg, len;
{
ary_modify(ary);
if (TYPE(rpl) != T_ARRAY) {
- rpl = (struct RArray*)rb_to_a(rpl);
+ rpl = rb_Array(rpl);
}
if (beg < 0) {
- beg = ary->len + beg;
+ beg = RARRAY(ary)->len + beg;
if (beg < 0) beg = 0;
}
- if (beg >= ary->len) {
- len = beg + rpl->len;
- if (len >= ary->capa) {
- ary->capa=len;
- REALLOC_N(ary->ptr, VALUE, ary->capa);
+ if (beg >= RARRAY(ary)->len) {
+ len = beg + RARRAY(rpl)->len;
+ if (len >= RARRAY(ary)->capa) {
+ RARRAY(ary)->capa=len;
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
}
- memclear(ary->ptr+ary->len, beg-ary->len);
- MEMCPY(ary->ptr+beg, rpl->ptr, VALUE, rpl->len);
- ary->len = len;
+ memclear(RARRAY(ary)->ptr+RARRAY(ary)->len, beg-RARRAY(ary)->len);
+ MEMCPY(RARRAY(ary)->ptr+beg, RARRAY(rpl)->ptr, VALUE, RARRAY(rpl)->len);
+ RARRAY(ary)->len = len;
}
else {
int alen;
- if (beg + len > ary->len) {
- len = ary->len - beg;
+ if (beg + len > RARRAY(ary)->len) {
+ len = RARRAY(ary)->len - beg;
}
if (len < 0) {
- IndexError("negative length %d", ary->len);
+ IndexError("negative length %d", RARRAY(ary)->len);
}
- alen = ary->len + rpl->len - len;
- if (alen >= ary->capa) {
- ary->capa=alen;
- REALLOC_N(ary->ptr, VALUE, ary->capa);
+ alen = RARRAY(ary)->len + RARRAY(rpl)->len - len;
+ if (alen >= RARRAY(ary)->capa) {
+ RARRAY(ary)->capa=alen;
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
}
if (len != RARRAY(rpl)->len) {
- MEMMOVE(ary->ptr+beg+rpl->len, ary->ptr+beg+len,
- VALUE, ary->len-(beg+len));
- ary->len = alen;
+ MEMMOVE(RARRAY(ary)->ptr+beg+RARRAY(rpl)->len, RARRAY(ary)->ptr+beg+len,
+ VALUE, RARRAY(ary)->len-(beg+len));
+ RARRAY(ary)->len = alen;
}
- MEMCPY(ary->ptr+beg, rpl->ptr, VALUE, rpl->len);
+ MEMCPY(RARRAY(ary)->ptr+beg, RARRAY(rpl)->ptr, VALUE, RARRAY(rpl)->len);
}
}
@@ -479,10 +476,9 @@ static VALUE
ary_aset(argc, argv, ary)
int argc;
VALUE *argv;
- struct RArray *ary;
+ VALUE ary;
{
- VALUE arg1, arg2;
- struct RArray *arg3;
+ VALUE arg1, arg2, arg3;
int offset;
int beg, len;
@@ -490,13 +486,13 @@ ary_aset(argc, argv, ary)
beg = NUM2INT(arg1);
len = NUM2INT(arg2);
ary_replace(ary, beg, len, arg3);
- return (VALUE)arg3;
+ return arg3;
}
else if (FIXNUM_P(arg1)) {
offset = FIX2INT(arg1);
goto fixnum;
}
- else if (beg_len(arg1, &beg, &len, ary->len)) {
+ else if (beg_len(arg1, &beg, &len, RARRAY(ary)->len)) {
/* check if idx is Range */
ary_replace(ary, beg, len, arg2);
return arg2;
@@ -508,7 +504,7 @@ ary_aset(argc, argv, ary)
offset = NUM2INT(arg1);
fixnum:
if (offset < 0) {
- offset = ary->len + offset;
+ offset = RARRAY(ary)->len + offset;
}
ary_store(ary, offset, arg2);
return arg2;
@@ -516,23 +512,23 @@ ary_aset(argc, argv, ary)
VALUE
ary_each(ary)
- struct RArray *ary;
+ VALUE ary;
{
int i;
- for (i=0; i<ary->len; i++) {
- rb_yield(ary->ptr[i]);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ rb_yield(RARRAY(ary)->ptr[i]);
}
return Qnil;
}
static VALUE
ary_each_index(ary)
- struct RArray *ary;
+ VALUE ary;
{
int i;
- for (i=0; i<ary->len; i++) {
+ for (i=0; i<RARRAY(ary)->len; i++) {
rb_yield(INT2FIX(i));
}
return Qnil;
@@ -540,69 +536,76 @@ ary_each_index(ary)
static VALUE
ary_reverse_each(ary)
- struct RArray *ary;
+ VALUE ary;
{
- int len = ary->len;
+ int len = RARRAY(ary)->len;
while (len--) {
- rb_yield(ary->ptr[len]);
+ rb_yield(RARRAY(ary)->ptr[len]);
}
return Qnil;
}
static VALUE
ary_length(ary)
- struct RArray *ary;
+ VALUE ary;
{
- return INT2FIX(ary->len);
+ return INT2FIX(RARRAY(ary)->len);
}
static VALUE
ary_empty_p(ary)
- struct RArray *ary;
+ VALUE ary;
{
- if (ary->len == 0)
+ if (RARRAY(ary)->len == 0)
return TRUE;
return FALSE;
}
static VALUE
ary_clone(ary)
- struct RArray *ary;
+ VALUE ary;
{
- VALUE ary2 = ary_new2(ary->len);
+ VALUE ary2 = ary_new2(RARRAY(ary)->len);
CLONESETUP(ary2, ary);
- MEMCPY(RARRAY(ary2)->ptr, ary->ptr, VALUE, ary->len);
- RARRAY(ary2)->len = ary->len;
+ MEMCPY(RARRAY(ary2)->ptr, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
+ RARRAY(ary2)->len = RARRAY(ary)->len;
return ary2;
}
+static VALUE
+ary_dup(ary)
+ VALUE ary;
+{
+ return ary_new4(RARRAY(ary)->len, RARRAY(ary)->ptr);
+}
+
extern VALUE OFS;
VALUE
ary_join(ary, sep)
- struct RArray *ary;
- struct RString *sep;
+ VALUE ary;
+ VALUE sep;
{
int i;
VALUE result, tmp;
- if (ary->len == 0) return str_new(0, 0);
+ if (RARRAY(ary)->len == 0) return str_new(0, 0);
- switch (TYPE(ary->ptr[0])) {
+ switch (TYPE(RARRAY(ary)->ptr[0])) {
case T_STRING:
- result = str_dup(ary->ptr[0]);
+ result = str_dup(RARRAY(ary)->ptr[0]);
break;
case T_ARRAY:
- result = ary_join(ary->ptr[0], sep);
+ result = ary_join(RARRAY(ary)->ptr[0], sep);
break;
default:
- result = obj_as_string(ary->ptr[0]);
+ result = obj_as_string(RARRAY(ary)->ptr[0]);
break;
}
- for (i=1; i<ary->len; i++) {
- tmp = ary->ptr[i];
+ for (i=1; i<RARRAY(ary)->len; i++) {
+ tmp = RARRAY(ary)->ptr[i];
switch (TYPE(tmp)) {
case T_STRING:
break;
@@ -612,7 +615,7 @@ ary_join(ary, sep)
default:
tmp = obj_as_string(tmp);
}
- if (!NIL_P(sep)) str_cat(result, sep->ptr, sep->len);
+ if (!NIL_P(sep)) str_cat(result, RSTRING(sep)->ptr, RSTRING(sep)->len);
str_cat(result, RSTRING(tmp)->ptr, RSTRING(tmp)->len);
if (str_tainted(tmp)) str_taint(result);
}
@@ -624,7 +627,7 @@ static VALUE
ary_join_method(argc, argv, ary)
int argc;
VALUE *argv;
- struct RArray *ary;
+ VALUE ary;
{
VALUE sep;
@@ -644,35 +647,19 @@ ary_to_s(ary)
return str;
}
-VALUE
-ary_print_on(ary, port)
- struct RArray *ary;
- VALUE port;
-{
- int i;
-
- for (i=0; i<ary->len; i++) {
- if (!NIL_P(OFS) && i>0) {
- io_write(port, OFS);
- }
- io_write(port, ary->ptr[i]);
- }
- return port;
-}
-
static VALUE
ary_inspect(ary)
- struct RArray *ary;
+ VALUE ary;
{
int i, len;
VALUE s, str;
- if (ary->len == 0) return str_new2("[]");
+ if (RARRAY(ary)->len == 0) return str_new2("[]");
str = str_new2("[");
len = 1;
- for (i=0; i<ary->len; i++) {
- s = rb_inspect(ary->ptr[i]);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ s = rb_inspect(RARRAY(ary)->ptr[i]);
if (i > 0) str_cat(str, ", ", 2);
str_cat(str, RSTRING(s)->ptr, RSTRING(s)->len);
len += RSTRING(s)->len + 2;
@@ -690,26 +677,14 @@ ary_to_a(ary)
}
VALUE
-rb_to_a(obj)
- VALUE obj;
-{
- if (TYPE(obj) == T_ARRAY) return obj;
- obj = rb_funcall(obj, rb_intern("to_a"), 0);
- if (TYPE(obj) != T_ARRAY) {
- Bug("`to_a' did not return Array");
- }
- return obj;
-}
-
-VALUE
ary_reverse(ary)
- struct RArray *ary;
+ VALUE ary;
{
VALUE *p1, *p2;
VALUE tmp;
- p1 = ary->ptr;
- p2 = p1 + ary->len - 1; /* points last item */
+ p1 = RARRAY(ary)->ptr;
+ p2 = p1 + RARRAY(ary)->len - 1; /* points last item */
while (p1 < p2) {
tmp = *p1;
@@ -718,12 +693,12 @@ ary_reverse(ary)
p1++; p2--;
}
- return (VALUE)ary;
+ return ary;
}
static VALUE
ary_reverse_method(ary)
- struct RArray *ary;
+ VALUE ary;
{
return ary_reverse(ary_clone(ary));
}
@@ -757,11 +732,11 @@ sort_2(a, b)
VALUE
ary_sort_bang(ary)
- struct RArray *ary;
+ VALUE ary;
{
ary_modify(ary);
- qsort(ary->ptr, ary->len, sizeof(VALUE), iterator_p()?sort_1:sort_2);
- return (VALUE)ary;
+ qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), iterator_p()?sort_1:sort_2);
+ return ary;
}
VALUE
@@ -773,25 +748,25 @@ ary_sort(ary)
VALUE
ary_delete(ary, item)
- struct RArray *ary;
+ VALUE ary;
VALUE item;
{
int i1, i2;
ary_modify(ary);
- for (i1 = i2 = 0; i1 < ary->len; i1++) {
- if (rb_equal(ary->ptr[i1], item)) continue;
+ for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
+ if (rb_equal(RARRAY(ary)->ptr[i1], item)) continue;
if (i1 != i2) {
- ary->ptr[i2] = ary->ptr[i1];
+ RARRAY(ary)->ptr[i2] = RARRAY(ary)->ptr[i1];
}
i2++;
}
- if (ary->len == i2) {
+ if (RARRAY(ary)->len == i2) {
if (iterator_p()) rb_yield(item);
return Qnil;
}
else {
- ary->len = i2;
+ RARRAY(ary)->len = i2;
}
return item;
@@ -799,7 +774,7 @@ ary_delete(ary, item)
VALUE
ary_delete_at(ary, at)
- struct RArray *ary;
+ VALUE ary;
VALUE at;
{
int i1, i2, pos;
@@ -807,184 +782,184 @@ ary_delete_at(ary, at)
ary_modify(ary);
pos = NUM2INT(at);
- for (i1 = i2 = 0; i1 < ary->len; i1++) {
+ for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
if (i1 == pos) {
- del = ary->ptr[i1];
+ del = RARRAY(ary)->ptr[i1];
continue;
}
if (i1 != i2) {
- ary->ptr[i2] = ary->ptr[i1];
+ RARRAY(ary)->ptr[i2] = RARRAY(ary)->ptr[i1];
}
i2++;
}
- ary->len = i2;
+ RARRAY(ary)->len = i2;
return del;
}
static VALUE
ary_delete_if(ary)
- struct RArray *ary;
+ VALUE ary;
{
int i1, i2;
ary_modify(ary);
- for (i1 = i2 = 0; i1 < ary->len; i1++) {
- if (rb_yield(ary->ptr[i1])) continue;
+ for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
+ if (rb_yield(RARRAY(ary)->ptr[i1])) continue;
if (i1 != i2) {
- ary->ptr[i2] = ary->ptr[i1];
+ RARRAY(ary)->ptr[i2] = RARRAY(ary)->ptr[i1];
}
i2++;
}
- ary->len = i2;
+ RARRAY(ary)->len = i2;
- return (VALUE)ary;
+ return ary;
}
#if 0
static VALUE
ary_replace(ary)
- struct RArray *ary;
+ VALUE ary;
{
int i;
- for (i = 0; i < ary->len; i++) {
- ary->ptr[i] = rb_yield(ary->ptr[i]);
+ for (i = 0; i < RARRAY(ary)->len; i++) {
+ RARRAY(ary)->ptr[i] = rb_yield(RARRAY(ary)->ptr[i]);
}
- return (VALUE)ary;
+ return ary;
}
#endif
static VALUE
ary_clear(ary)
- struct RArray *ary;
+ VALUE ary;
{
- ary->len = 0;
- if (ARY_DEFAULT_SIZE*3 < ary->capa) {
- ary->capa = ARY_DEFAULT_SIZE * 2;
- REALLOC_N(ary->ptr, VALUE, ary->capa);
+ RARRAY(ary)->len = 0;
+ if (ARY_DEFAULT_SIZE*3 < RARRAY(ary)->capa) {
+ RARRAY(ary)->capa = ARY_DEFAULT_SIZE * 2;
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
}
- return (VALUE)ary;
+ return ary;
}
static VALUE
ary_fill(argc, argv, ary)
int argc;
VALUE *argv;
- struct RArray *ary;
+ VALUE ary;
{
VALUE item, arg1, arg2;
int beg, len, end;
VALUE *p, *pend;
rb_scan_args(argc, argv, "12", &item, &arg1, &arg2);
- if (NIL_P(arg2) && beg_len(arg1, &beg, &len, ary->len)) {
+ if (NIL_P(arg2) && beg_len(arg1, &beg, &len, RARRAY(ary)->len)) {
/* beg and len set already */
}
else {
beg = NUM2INT(arg1);
if (beg < 0) {
- beg = ary->len + beg;
+ beg = RARRAY(ary)->len + beg;
if (beg < 0) beg = 0;
}
- if (arg2) {
+ if (!NIL_P(arg2)) {
len = NUM2INT(arg2);
}
else {
- len = ary->len - beg;
+ len = RARRAY(ary)->len - beg;
}
}
end = beg + len;
- if (end > ary->len) {
- if (end >= ary->capa) {
- ary->capa=end;
- REALLOC_N(ary->ptr, VALUE, ary->capa);
+ if (end > RARRAY(ary)->len) {
+ if (end >= RARRAY(ary)->capa) {
+ RARRAY(ary)->capa=end;
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
}
- if (beg > ary->len) {
- memclear(ary->ptr+ary->len, end-ary->len);
+ if (beg > RARRAY(ary)->len) {
+ memclear(RARRAY(ary)->ptr+RARRAY(ary)->len, end-RARRAY(ary)->len);
}
- ary->len = end;
+ RARRAY(ary)->len = end;
}
- p = ary->ptr + beg; pend = p + len;
+ p = RARRAY(ary)->ptr + beg; pend = p + len;
while (p < pend) {
*p++ = item;
}
- return (VALUE)ary;
+ return ary;
}
VALUE
ary_plus(x, y)
- struct RArray *x, *y;
+ VALUE x, y;
{
- struct RArray *z;
+ VALUE z;
if (TYPE(y) != T_ARRAY) {
- return ary_plus(x, rb_to_a(y));
+ return ary_plus(x, rb_Array(y));
}
- z = (struct RArray*)ary_new2(x->len + y->len);
- MEMCPY(z->ptr, x->ptr, VALUE, x->len);
- MEMCPY(z->ptr+x->len, y->ptr, VALUE, y->len);
- z->len = x->len + RARRAY(y)->len;
- return (VALUE)z;
+ z = ary_new2(RARRAY(x)->len + RARRAY(y)->len);
+ MEMCPY(RARRAY(z)->ptr, RARRAY(x)->ptr, VALUE, RARRAY(x)->len);
+ MEMCPY(RARRAY(z)->ptr+RARRAY(x)->len, RARRAY(y)->ptr, VALUE, RARRAY(y)->len);
+ RARRAY(z)->len = RARRAY(x)->len + RARRAY(y)->len;
+ return z;
}
VALUE
ary_concat(x, y)
- struct RArray *x, *y;
+ VALUE x, y;
{
VALUE *p, *pend;
if (TYPE(y) != T_ARRAY) {
- return ary_concat(x, rb_to_a(y));
+ return ary_concat(x, rb_Array(y));
}
- p = y->ptr;
- pend = p + y->len;
+ p = RARRAY(y)->ptr;
+ pend = p + RARRAY(y)->len;
while (p < pend) {
- ary_store(x, x->len, *p);
+ ary_store(x, RARRAY(x)->len, *p);
p++;
}
- return (VALUE)x;
+ return x;
}
static VALUE
ary_times(ary, times)
- struct RArray *ary;
+ VALUE ary;
VALUE times;
{
- struct RArray *ary2;
+ VALUE ary2;
int i, len;
if (TYPE(times) == T_STRING) {
return ary_join(ary, times);
}
- len = NUM2INT(times) * ary->len;
- ary2 = (struct RArray*)ary_new2(len);
- ary2->len = len;
+ len = NUM2INT(times) * RARRAY(ary)->len;
+ ary2 = ary_new2(len);
+ RARRAY(ary2)->len = len;
if (len < 0) {
ArgError("negative argument");
}
- for (i=0; i<len; i+=ary->len) {
- MEMCPY(ary2->ptr+i, ary->ptr, VALUE, ary->len);
+ for (i=0; i<len; i+=RARRAY(ary)->len) {
+ MEMCPY(RARRAY(ary2)->ptr+i, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
}
- return (VALUE)ary2;
+ return ary2;
}
VALUE
ary_assoc(ary, key)
- struct RArray *ary;
+ VALUE ary;
VALUE key;
{
VALUE *p, *pend;
- p = ary->ptr; pend = p + ary->len;
+ p = RARRAY(ary)->ptr; pend = p + RARRAY(ary)->len;
while (p < pend) {
if (TYPE(*p) == T_ARRAY
&& RARRAY(*p)->len > 1
@@ -997,12 +972,12 @@ ary_assoc(ary, key)
VALUE
ary_rassoc(ary, value)
- struct RArray *ary;
+ VALUE ary;
VALUE value;
{
VALUE *p, *pend;
- p = ary->ptr; pend = p + ary->len;
+ p = RARRAY(ary)->ptr; pend = p + RARRAY(ary)->len;
while (p < pend) {
if (TYPE(*p) == T_ARRAY
&& RARRAY(*p)->len > 1
@@ -1015,14 +990,14 @@ ary_rassoc(ary, value)
static VALUE
ary_equal(ary1, ary2)
- struct RArray *ary1, *ary2;
+ VALUE ary1, ary2;
{
int i;
if (TYPE(ary2) != T_ARRAY) return FALSE;
- if (ary1->len != ary2->len) return FALSE;
- for (i=0; i<ary1->len; i++) {
- if (!rb_equal(ary1->ptr[i], ary2->ptr[i]))
+ if (RARRAY(ary1)->len != RARRAY(ary2)->len) return FALSE;
+ for (i=0; i<RARRAY(ary1)->len; i++) {
+ if (!rb_equal(RARRAY(ary1)->ptr[i], RARRAY(ary2)->ptr[i]))
return FALSE;
}
return TRUE;
@@ -1030,14 +1005,15 @@ ary_equal(ary1, ary2)
static VALUE
ary_eql(ary1, ary2)
- struct RArray *ary1, *ary2;
+ VALUE ary1, ary2;
{
int i;
if (TYPE(ary2) != T_ARRAY) return FALSE;
- if (ary1->len != ary2->len) return FALSE;
- for (i=0; i<ary1->len; i++) {
- if (!rb_eql(ary1->ptr[i], ary2->ptr[i]))
+ if (RARRAY(ary1)->len != RARRAY(ary2)->len)
+ return FALSE;
+ for (i=0; i<RARRAY(ary1)->len; i++) {
+ if (!rb_eql(RARRAY(ary1)->ptr[i], RARRAY(ary2)->ptr[i]))
return FALSE;
}
return TRUE;
@@ -1045,25 +1021,25 @@ ary_eql(ary1, ary2)
static VALUE
ary_hash(ary)
- struct RArray *ary;
+ VALUE ary;
{
int h, i;
- h = ary->len;
- for (i=0; i<ary->len; i++) {
- h ^= rb_hash(ary->ptr[i]);
+ h = RARRAY(ary)->len;
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ h ^= rb_hash(RARRAY(ary)->ptr[i]);
}
return INT2FIX(h);
}
VALUE
ary_includes(ary, item)
- struct RArray *ary;
+ VALUE ary;
VALUE item;
{
int i;
- for (i=0; i<ary->len; i++) {
- if (rb_equal(ary->ptr[i], item)) {
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ if (rb_equal(RARRAY(ary)->ptr[i], item)) {
return TRUE;
}
}
@@ -1072,34 +1048,34 @@ ary_includes(ary, item)
static VALUE
ary_diff(ary1, ary2)
- struct RArray *ary1, *ary2;
+ VALUE ary1, ary2;
{
VALUE ary3;
int i;
Check_Type(ary2, T_ARRAY);
ary3 = ary_new();
- for (i=0; i<ary1->len; i++) {
- if (ary_includes(ary2, ary1->ptr[i])) continue;
- if (ary_includes(ary3, ary1->ptr[i])) continue;
- ary_push(ary3, ary1->ptr[i]);
+ for (i=0; i<RARRAY(ary1)->len; i++) {
+ if (ary_includes(ary2, RARRAY(ary1)->ptr[i])) continue;
+ if (ary_includes(ary3, RARRAY(ary1)->ptr[i])) continue;
+ ary_push(ary3, RARRAY(ary1)->ptr[i]);
}
return ary3;
}
static VALUE
ary_and(ary1, ary2)
- struct RArray *ary1, *ary2;
+ VALUE ary1, ary2;
{
VALUE ary3;
int i;
Check_Type(ary2, T_ARRAY);
ary3 = ary_new();
- for (i=0; i<ary1->len; i++) {
- if (ary_includes(ary2, ary1->ptr[i])
- && !ary_includes(ary3, ary1->ptr[i])) {
- ary_push(ary3, ary1->ptr[i]);
+ for (i=0; i<RARRAY(ary1)->len; i++) {
+ if (ary_includes(ary2, RARRAY(ary1)->ptr[i])
+ && !ary_includes(ary3, RARRAY(ary1)->ptr[i])) {
+ ary_push(ary3, RARRAY(ary1)->ptr[i]);
}
}
return ary3;
@@ -1107,63 +1083,63 @@ ary_and(ary1, ary2)
static VALUE
ary_or(ary1, ary2)
- struct RArray *ary1, *ary2;
+ VALUE ary1, ary2;
{
VALUE ary3;
int i;
if (TYPE(ary2) != T_ARRAY) {
- if (ary_includes(ary1, ary2)) return (VALUE)ary1;
+ if (ary_includes(ary1, ary2)) return ary1;
else return ary_plus(ary1, ary2);
}
ary3 = ary_new();
- for (i=0; i<ary1->len; i++) {
- if (!ary_includes(ary3, ary1->ptr[i]))
- ary_push(ary3, ary1->ptr[i]);
+ for (i=0; i<RARRAY(ary1)->len; i++) {
+ if (!ary_includes(ary3, RARRAY(ary1)->ptr[i]))
+ ary_push(ary3, RARRAY(ary1)->ptr[i]);
}
- for (i=0; i<ary2->len; i++) {
- if (!ary_includes(ary3, ary2->ptr[i]))
- ary_push(ary3, ary2->ptr[i]);
+ for (i=0; i<RARRAY(ary2)->len; i++) {
+ if (!ary_includes(ary3, RARRAY(ary2)->ptr[i]))
+ ary_push(ary3, RARRAY(ary2)->ptr[i]);
}
return ary3;
}
static VALUE
ary_compact_bang(ary)
- struct RArray *ary;
+ VALUE ary;
{
VALUE *p, *t, *end;
ary_modify(ary);
- p = t = ary->ptr;
- end = p + ary->len;
+ p = t = RARRAY(ary)->ptr;
+ end = p + RARRAY(ary)->len;
while (t < end) {
if (NIL_P(*t)) t++;
else *p++ = *t++;
}
- ary->len = ary->capa = (p - ary->ptr);
- REALLOC_N(ary->ptr, VALUE, ary->len);
+ RARRAY(ary)->len = RARRAY(ary)->capa = (p - RARRAY(ary)->ptr);
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
- return (VALUE)ary;
+ return ary;
}
static VALUE
ary_compact(ary)
- struct RArray *ary;
+ VALUE ary;
{
return ary_compact_bang(ary_clone(ary));
}
static VALUE
ary_nitems(ary)
- struct RArray *ary;
+ VALUE ary;
{
int n = 0;
VALUE *p, *pend;
- p = ary->ptr;
- pend = p + ary->len;
+ p = RARRAY(ary)->ptr;
+ pend = p + RARRAY(ary)->len;
while (p < pend) {
if (!NIL_P(*p)) n++;
p++;
@@ -1209,6 +1185,7 @@ Init_Array()
rb_define_method(cArray, "index", ary_index, 1);
rb_define_method(cArray, "indexes", ary_indexes, -2);
rb_define_method(cArray, "clone", ary_clone, 0);
+ rb_define_method(cArray, "dup", ary_dup, 0);
rb_define_method(cArray, "join", ary_join_method, -1);
rb_define_method(cArray, "reverse", ary_reverse_method, 0);
rb_define_method(cArray, "reverse!", ary_reverse, 0);
@@ -1223,6 +1200,7 @@ Init_Array()
rb_define_method(cArray, "clear", ary_clear, 0);
rb_define_method(cArray, "fill", ary_fill, -1);
rb_define_method(cArray, "include?", ary_includes, 1);
+ rb_define_method(cArray, "===", ary_includes, 1);
rb_define_method(cArray, "assoc", ary_assoc, 1);
rb_define_method(cArray, "rassoc", ary_rassoc, 1);
View
358 bignum.c
@@ -18,8 +18,8 @@ VALUE cBignum;
#define BDIGITS(x) RBIGNUM(x)->digits
#define BITSPERDIG (sizeof(USHORT)*CHAR_BIT)
#define BIGRAD (1L << BITSPERDIG)
-#define DIGSPERLONG ((UINT)(sizeof(long)/sizeof(USHORT)))
-#define BIGUP(x) ((unsigned long)(x) << BITSPERDIG)
+#define DIGSPERINT ((UINT)(sizeof(INT)/sizeof(USHORT)))
+#define BIGUP(x) ((UINT)(x) << BITSPERDIG)
#define BIGDN(x) ((x) >> BITSPERDIG)
#define BIGLO(x) ((x) & (BIGRAD-1))
@@ -42,19 +42,19 @@ bignew_1(class, len, sign)
VALUE
big_clone(x)
- struct RBignum *x;
+ VALUE x;
{
- VALUE z = bignew_1(CLASS_OF(x), x->len, x->sign);
+ VALUE z = bignew_1(CLASS_OF(x), RBIGNUM(x)->len, RBIGNUM(x)->sign);
- MEMCPY(BDIGITS(z), BDIGITS(x), USHORT, x->len);
- return (VALUE)z;
+ MEMCPY(BDIGITS(z), BDIGITS(x), USHORT, RBIGNUM(x)->len);
+ return z;
}
void
big_2comp(x) /* get 2's complement */
- struct RBignum *x;
+ VALUE x;
{
- UINT i = x->len;
+ UINT i = RBIGNUM(x)->len;
USHORT *ds = BDIGITS(x);
long num;
@@ -64,26 +64,26 @@ big_2comp(x) /* get 2's complement */
num += (long)ds[i];
ds[i++] = BIGLO(num);
num = BIGDN(num);
- } while (i < x->len);
+ } while (i < RBIGNUM(x)->len);
if (ds[0] == 1 || ds[0] == 0) {
- for (i=1;i<x->len;i++) {
+ for (i=1;i<RBIGNUM(x)->len;i++) {
if (ds[i] != 0) return;
}
- REALLOC_N(BDIGITS(x), USHORT, x->len++);
+ REALLOC_N(BDIGITS(x), USHORT, RBIGNUM(x)->len++);
ds = BDIGITS(x);
- ds[x->len-1] = 1;
+ ds[RBIGNUM(x)->len-1] = 1;
}
}
static VALUE
bignorm(x)
- struct RBignum *x;
+ VALUE x;
{
- UINT len = x->len;
+ UINT len = RBIGNUM(x)->len;
USHORT *ds = BDIGITS(x);
while (len-- && !ds[len]) ;
- x->len = ++len;
+ RBIGNUM(x)->len = ++len;
if (len*sizeof(USHORT) < sizeof(VALUE) ||
(len*sizeof(USHORT) == sizeof(VALUE) &&
@@ -92,19 +92,19 @@ bignorm(x)
while (len--) {
num = BIGUP(num) + ds[len];
}
- if (x->sign) {
+ if (RBIGNUM(x)->sign) {
if (POSFIXABLE(num)) return INT2FIX(num);
}
else if (NEGFIXABLE(-num)) return INT2FIX(-num);
}
- return (VALUE)x;
+ return x;
}
VALUE
big_norm(x)
VALUE x;
{
- return bignorm(x);
+ return bignorm(RBIGNUM(x));
}
VALUE
@@ -113,38 +113,38 @@ uint2big(n)
{
UINT i = 0;
USHORT *digits;
- struct RBignum *big;
+ VALUE big;
i = 0;
- big = (struct RBignum*)bignew(DIGSPERLONG, 1);
+ big = bignew(DIGSPERINT, 1);
digits = BDIGITS(big);
- while (i < DIGSPERLONG) {
+ while (i < DIGSPERINT) {
digits[i++] = BIGLO(n);
n = BIGDN(n);
}
- i = DIGSPERLONG;
+ i = DIGSPERINT;
while (i-- && !digits[i]) ;
- big->len = i+1;
- return (VALUE)big;
+ RBIGNUM(big)->len = i+1;
+ return big;
}
VALUE
int2big(n)
- int n;
+ INT n;
{
- int neg = 0;
- struct RBignum *big;
+ INT neg = 0;
+ VALUE big;
if (n < 0) {
n = -n;
neg = 1;
}
- big = (struct RBignum*)uint2big(n);
+ big = uint2big(n);
if (neg) {
- big->sign = 0;
+ RBIGNUM(big)->sign = 0;
}
- return (VALUE)big;
+ return big;
}
VALUE
@@ -157,7 +157,7 @@ uint2inum(n)
VALUE
int2inum(n)
- int n;
+ INT n;
{
if (FIXABLE(n)) return INT2FIX(n);
return int2big(n);
@@ -209,7 +209,7 @@ str2inum(str, base)
if (POSFIXABLE(val)) {
if (sign) return INT2FIX(val);
else {
- int result = -(int)val;
+ INT result = -(INT)val;
return INT2FIX(result);
}
}
@@ -219,7 +219,7 @@ str2inum(str, base)
return big;
}
}
- len = (len/(sizeof(USHORT)*CHAR_BIT))+1;
+ len = (len/BITSPERDIG)+1;
z = bignew(len, sign);
zds = BDIGITS(z);
@@ -264,7 +264,7 @@ str2inum(str, base)
static char hexmap[] = "0123456789abcdef";
VALUE
big2str(x, base)
- struct RBignum *x;
+ VALUE x;
int base;
{
VALUE t;
@@ -276,7 +276,7 @@ big2str(x, base)
if (FIXNUM_P(x)) {
return fix2str(x, base);
}
- i = x->len;
+ i = RBIGNUM(x)->len;
if (i == 0) return str_new2("0");
if (base == 10) {
j = (sizeof(USHORT)/sizeof(char)*CHAR_BIT*i*241L)/800+2;
@@ -305,7 +305,7 @@ big2str(x, base)
ss = str_new(0, j);
s = RSTRING(ss)->ptr;
- s[0] = x->sign ? '+' : '-';
+ s[0] = RBIGNUM(x)->sign ? '+' : '-';
while (i && j) {
int k = i;
unsigned long num = 0;
@@ -324,8 +324,8 @@ big2str(x, base)
}
}
while (s[j] == '0') j++;
- RSTRING(ss)->len -= x->sign?j:j-1;
- memmove(x->sign?s:s+1, s+j, RSTRING(ss)->len);
+ RSTRING(ss)->len -= RBIGNUM(x)->sign?j:j-1;
+ memmove(RBIGNUM(x)->sign?s:s+1, s+j, RSTRING(ss)->len);
s[RSTRING(ss)->len] = '\0';
return ss;
@@ -333,17 +333,17 @@ big2str(x, base)
static VALUE
big_to_s(x)
- struct RBignum *x;
+ VALUE x;
{
return big2str(x, 10);
}
-int
+INT
big2int(x)
- struct RBignum *x;
+ VALUE x;
{
- unsigned long num;
- UINT len = x->len;
+ UINT num;
+ UINT len = RBIGNUM(x)->len;
USHORT *ds;
if (len > sizeof(long)/sizeof(USHORT))
@@ -354,7 +354,7 @@ big2int(x)
num = BIGUP(num);
num += ds[len];
}
- if (!x->sign) return -num;
+ if (!RBIGNUM(x)->sign) return -num;
return num;
}
@@ -393,16 +393,16 @@ dbl2big(d)
double
big2dbl(x)
- struct RBignum *x;
+ VALUE x;
{
double d = 0.0;
- UINT i = x->len;
+ UINT i = RBIGNUM(x)->len;
USHORT *ds = BDIGITS(x);
while (i--) {
d = ds[i] + BIGRAD*d;
}
- if (!x->sign) d = -d;
+ if (!RBIGNUM(x)->sign) d = -d;
return d;
}
@@ -415,13 +415,13 @@ big_to_f(x)
static VALUE
big_cmp(x, y)
- struct RBignum *x, *y;
+ VALUE x, y;
{
- int xlen = x->len;
+ int xlen = RBIGNUM(x)->len;
switch (TYPE(y)) {
case T_FIXNUM:
- y = (struct RBignum*)int2big(FIX2INT(y));
+ y = int2big(FIX2INT(y));
break;
case T_BIGNUM:
@@ -431,18 +431,18 @@ big_cmp(x, y)
return num_coerce_bin(x, y);
}
- if (x->sign > y->sign) return INT2FIX(1);
- if (x->sign < y->sign) return INT2FIX(-1);
- if (xlen < y->len)
- return (x->sign) ? INT2FIX(-1) : INT2FIX(1);
- if (xlen > y->len)
- return (x->sign) ? INT2FIX(1) : INT2FIX(-1);
+ if (RBIGNUM(x)->sign > RBIGNUM(y)->sign) return INT2FIX(1);
+ if (RBIGNUM(x)->sign < RBIGNUM(y)->sign) return INT2FIX(-1);
+ if (xlen < RBIGNUM(y)->len)
+ return (RBIGNUM(x)->sign) ? INT2FIX(-1) : INT2FIX(1);
+ if (xlen > RBIGNUM(y)->len)
+ return (RBIGNUM(x)->sign) ? INT2FIX(1) : INT2FIX(-1);
while(xlen-- && (BDIGITS(x)[xlen]==BDIGITS(y)[xlen]));
if (-1 == xlen) return INT2FIX(0);
return (BDIGITS(x)[xlen] > BDIGITS(y)[xlen]) ?
- (x->sign ? INT2FIX(1) : INT2FIX(-1)) :
- (x->sign ? INT2FIX(-1) : INT2FIX(1));
+ (RBIGNUM(x)->sign ? INT2FIX(1) : INT2FIX(-1)) :
+ (RBIGNUM(x)->sign ? INT2FIX(-1) : INT2FIX(1));
}
static VALUE
@@ -455,26 +455,26 @@ big_eq(x, y)
static VALUE
big_uminus(x)
- struct RBignum *x;
+ VALUE x;
{
VALUE z = big_clone(x);
- RBIGNUM(z)->sign = !x->sign;
+ RBIGNUM(z)->sign = !RBIGNUM(x)->sign;
return bignorm(z);
}
static VALUE
big_neg(x)
- struct RBignum *x;
+ VALUE x;
{
VALUE z = big_clone(x);
- UINT i = x->len;
+ UINT i = RBIGNUM(x)->len;
USHORT *ds = BDIGITS(z);
- if (!x->sign) big_2comp(z);
+ if (!RBIGNUM(x)->sign) big_2comp(z);
while (i--) ds[i] = ~ds[i];
- if (x->sign) big_2comp(z);
+ if (RBIGNUM(x)->sign) big_2comp(z);
RBIGNUM(z)->sign = !RBIGNUM(z)->sign;
return bignorm(z);
@@ -482,19 +482,19 @@ big_neg(x)
static VALUE
bigsub(x, y)
- struct RBignum *x, *y;
+ VALUE x, y;
{
- struct RBignum *z = 0;
+ VALUE z = 0;
USHORT *zds;
long num;
UINT i;
- i = x->len;
+ i = RBIGNUM(x)->len;
/* if x is larger than y, swap */
- if (x->len < y->len) {
+ if (RBIGNUM(x)->len < RBIGNUM(y)->len) {
z = x; x = y; y = z; /* swap x y */
}
- else if (x->len == y->len) {
+ else if (RBIGNUM(x)->len == RBIGNUM(y)->len) {
while (i > 0) {
i--;
if (BDIGITS(x)[i] > BDIGITS(y)[i]) {
@@ -507,20 +507,20 @@ bigsub(x, y)
}
}
- z = (struct RBignum*)bignew(x->len, (z == 0)?1:0);
+ z = bignew(RBIGNUM(x)->len, (z == 0)?1:0);
zds = BDIGITS(z);
- for (i = 0, num = 0; i < y->len; i++) {
+ for (i = 0, num = 0; i < RBIGNUM(y)->len; i++) {
num += (long)BDIGITS(x)[i] - BDIGITS(y)[i];
zds[i] = BIGLO(num);
num = BIGDN(num);
}
- while (num && i < x->len) {
+ while (num && i < RBIGNUM(x)->len) {
num += BDIGITS(x)[i];
zds[i++] = BIGLO(num);
num = BIGDN(num);
}
- while (i < x->len) {
+ while (i < RBIGNUM(x)->len) {
zds[i] = BDIGITS(x)[i];
i++;
}
@@ -530,39 +530,40 @@ bigsub(x, y)
static VALUE
bigadd(x, y, sign)
- struct RBignum *x, *y;
+ VALUE x, y;
char sign;
{
- struct RBignum *z;
+ VALUE z;
long num;
UINT i, len;
- if (x->sign == (y->sign ^ sign)) {
- if (y->sign == sign) return bigsub(y, x);
+
+ if (RBIGNUM(x)->sign == (RBIGNUM(y)->sign ^ sign)) {
+ if (RBIGNUM(y)->sign == sign) return bigsub(y, x);
return bigsub(x, y);
}
- if (x->len > y->len) {
- len = x->len + 1;
+ if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
+ len = RBIGNUM(x)->len + 1;
+ z = x; x = y; y = z;
}
else {
- len = y->len + 1;
+ len = RBIGNUM(y)->len + 1;
}
- z = (struct RBignum*)bignew(len, sign==y->sign);
+ z = bignew(len, sign==RBIGNUM(y)->sign);
- if (x->len > y->len) {
- struct RBignum* t = x; x = y; y = t;
- }
- for (i = 0, num = 0; i < x->len; i++) {
- num += (long)(BDIGITS(x)[i]) + BDIGITS(y)[i];
+ len = RBIGNUM(x)->len;
+ for (i = 0, num = 0; i < len; i++) {
+ num += (long)(BDIGITS(x)[i] + BDIGITS(y)[i]);
BDIGITS(z)[i] = BIGLO(num);
num = BIGDN(num);
}
- while (num && i < y->len) {
+ len = RBIGNUM(y)->len;
+ while (num && i < len) {
num += BDIGITS(y)[i];
BDIGITS(z)[i++] = BIGLO(num);
num = BIGDN(num);
}
- while (i < y->len) {
+ while (i < len) {
BDIGITS(z)[i] = BDIGITS(y)[i];
i++;
}
@@ -611,17 +612,17 @@ big_minus(x, y)
VALUE
big_mul(x, y)
- struct RBignum *x, *y;
+ VALUE x, y;
{
UINT i = 0, j;
unsigned long n = 0;
VALUE z;
USHORT *zds;
- if (FIXNUM_P(x)) x = (struct RBignum*)int2big(FIX2INT(x));
+ if (FIXNUM_P(x)) x = int2big(FIX2INT(x));
switch (TYPE(y)) {
case T_FIXNUM:
- y = (struct RBignum*)int2big(FIX2INT(y));
+ y = int2big(FIX2INT(y));
break;
case T_BIGNUM:
@@ -634,15 +635,15 @@ big_mul(x, y)
return num_coerce_bin(x, y);
}
- j = x->len + y->len + 1;
- z = bignew(j, x->sign==y->sign);
+ j = RBIGNUM(x)->len + RBIGNUM(y)->len + 1;