[Ironruby-core] Fixnum Patch

Peter Bacon Darwin bacondarwin at googlemail.com
Tue Dec 11 10:19:27 EST 2007


Overview:

The focus of this patch is to implement the Fixnum methods and to provide
RSpec tests for those methods.  In addition the Bignum methods have been
tweaked and the tests for Bignum have been improved by adding more edge
cases.  The implementation of the Fixnum methods required some methods in
other classes to be added or modified.  These have not been tested to the
same level as the Fixnum and Bignum methods and there may be edge cases that
have been missed.

To help with running the tests I added a small script, run_builtin.rb that
lets you run all the tests for a particular builtin class (such as Fixnum)
on both ruby.exe and rbx.exe side by side.  I found this particularly useful
when writing and testing the specs to see where the work was. Usage is as
follows: ruby run_builtin.rb {BuiltinType}, where {BuiltinType} is the name
of a folder below the BuiltIn folder containing the specs to run.  It
assumes that you are running it from the trunk/tests/ironruby folder and
that ruby.exe is in the path. E.g. ruby run_builtin.rb Fixnum.

Of course, bear in mind that until Bignum gets "switched on" none of the
Bignum related functionality will work.

Code Change Detail:

BignumOps.cs

.         This file has had a general tidy up.  The methods have been
reordered and group better.

.         The CoerceAndCall method has been moved to Numeric.

.         All exceptions are now created via Ruby.Runtime.RubyExceptions

.         A number of methods, notably BignumOps.Compare, now return an
object rather than a Float (int).  This is because these methods sometimes
are expected to return nil (null).

Comparable.cs

.         The major change here is that Protocols.Compare is no longer
assumed to return a bool and we first test for null before casting the
result to an int.

FloatOps.cs

.         Added a number of methods to support the post-coercion calling
from Bignum and Fixnum.  These methods are not expected to deal with all
cases yet.  Methods affected include: ceil, floor, to_i, to_int, truncate,
to_f and round.

.         Methods such as <=>, < and divmod have had additional checks put
in place to deal with unusual cases of Infinity and  NaN.  Possibly these
will be moved into the Protocols classes in due course?

Integer.cs

.         Added the "integer?" method.

Numeric.cs

.         Implemented all the Numeric instance methods.  These have not been
subject to rigorous unit testing yet.

.         Implemented a number of helper methods, used by the other Numeric
classes such as Bignum and Fixnum: CoerceAndCall, CoerceAndCallCompare,
CoerceAndCallRelationOperator, MakeCoercionError and MakeComparisonError.

.         Also added the singleton_method_added method.  But currently this
does not get called as it has not yet been defined in Object (Kernel).

NumericSites.cs

.         Added a number of additional sites to support the Numeric classes.

.         The NumericSites.Coerce method now does some additional checks on
what is returned from the invocation.

ObjectOps.cs

.         Added inspect and new methods.  These help creating the fixtures
for the Fixnum and Bignum tests.

SymbolOps.cs

.         Fixed ToString to return null if the symbol does not exist in the
SymbolTable.

.         Fixed Inspect accordingly.

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20071211/0ce0f0c4/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FixnumMethods.patch
Type: application/octet-stream
Size: 243956 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/ironruby-core/attachments/20071211/0ce0f0c4/attachment-0001.obj 


More information about the Ironruby-core mailing list