Code Review: CompositeConversions3

tfpt review “/shelveset:CompositeConversions3;REDMOND\tomat”

DLR change (interpreter)

Fixes interpretation of UnaryExpresion cast with a custom method.

Ruby changes

Implements composite conversions and defines default composite protocol
conversions. A composite conversion is basically a combination of at
least 2 protocol conversions. For example, some methods convert to an
integer using “to_int” if available and if not “to_i” is tried. Other
methods try “to_str” first and “to_int” then or vice versa to convert to
String or Fixnum.

For example, File#new’s first parameter performs to_str-to_int
conversion. To declare such a parameter a library function uses a
parameter of type Union<T1, T2> marked by [DefaultProtocol]:

public static RubyFile/!/ CreateFile(RubyClass/!/ self,
[DefaultProtocol]Union<int, MutableString> descriptorOrPath,
[Optional, DefaultProtocol]MutableString mode, [Optional]int permission)
{

if (descriptorOrPath.IsFixnum()) { … } else { … }
}

This says that default protocol for Int32 and for MutableString should
be performed in the order specified by the type parameters.

Some methods use CastToInteger protocol. This protocol calls to_int,
similarly to CastToFixnum, but the result could be both Fixnum or
Bignum. This is not a composite conversion since only one conversion is
called (to_int) however the type of the result could be either Int32 or
BigInteger. There are also other places where we need to pass around a
union of Int32 and BigInteger. IntegerValue struct serves this purpose.
A default protocol for IntegerValue is CastToInteger. An example of use
is Bignum#<<:

[RubyMethod("<<")]
public static object/!/ LeftShift(RubyContext/!/ context,
BigInteger/!/ self, [DefaultProtocol]IntegerValue other) {
return other.IsFixnum ? LeftShift(self, other.Fixnum) :
LeftShift(self, other.Bignum);
}

Refactors protocol conversion classes.

Fixes File#open, IO#open, IO#for_fd.
Fixes String#to_i and Kernel#Integer.
Tokenizer now returns whitespace tokens in verbatim mode.

Changes format mode in runrspec to “dotted”. It doesn’t produce so much
noise.

Tomas

Interpreter change looks good.

From: Tomas M.
Sent: Friday, January 09, 2009 4:08 PM
To: IronRuby External Code R.; DLR Code Reviews
Cc: [email protected]
Subject: Code Review: CompositeConversions3

tfpt review “/shelveset:CompositeConversions3;REDMOND\tomat”

DLR change (interpreter)

Fixes interpretation of UnaryExpresion cast with a custom method.

Ruby changes

Implements composite conversions and defines default composite protocol
conversions. A composite conversion is basically a combination of at
least 2 protocol conversions. For example, some methods convert to an
integer using “to_int” if available and if not “to_i” is tried. Other
methods try “to_str” first and “to_int” then or vice versa to convert to
String or Fixnum.

For example, File#new’s first parameter performs to_str-to_int
conversion. To declare such a parameter a library function uses a
parameter of type Union<T1, T2> marked by [DefaultProtocol]:

public static RubyFile/!/ CreateFile(RubyClass/!/ self,
[DefaultProtocol]Union<int, MutableString> descriptorOrPath,
[Optional, DefaultProtocol]MutableString mode, [Optional]int permission)
{

if (descriptorOrPath.IsFixnum()) { … } else { … }
}

This says that default protocol for Int32 and for MutableString should
be performed in the order specified by the type parameters.

Some methods use CastToInteger protocol. This protocol calls to_int,
similarly to CastToFixnum, but the result could be both Fixnum or
Bignum. This is not a composite conversion since only one conversion is
called (to_int) however the type of the result could be either Int32 or
BigInteger. There are also other places where we need to pass around a
union of Int32 and BigInteger. IntegerValue struct serves this purpose.
A default protocol for IntegerValue is CastToInteger. An example of use
is Bignum#<<:

[RubyMethod("<<")]
public static object/!/ LeftShift(RubyContext/!/ context,
BigInteger/!/ self, [DefaultProtocol]IntegerValue other) {
return other.IsFixnum ? LeftShift(self, other.Fixnum) :
LeftShift(self, other.Bignum);
}

Refactors protocol conversion classes.

Fixes File#open, IO#open, IO#for_fd.
Fixes String#to_i and Kernel#Integer.
Tokenizer now returns whitespace tokens in verbatim mode.

Changes format mode in runrspec to “dotted”. It doesn’t produce so much
noise.

Tomas

Outer ring looks good.

From: Tomas M.
Sent: Friday, January 09, 2009 4:08 PM
To: IronRuby External Code R.; DLR Code Reviews
Cc: [email protected]
Subject: Code Review: CompositeConversions3

tfpt review “/shelveset:CompositeConversions3;REDMOND\tomat”

DLR change (interpreter)

Fixes interpretation of UnaryExpresion cast with a custom method.

Ruby changes

Implements composite conversions and defines default composite protocol
conversions. A composite conversion is basically a combination of at
least 2 protocol conversions. For example, some methods convert to an
integer using “to_int” if available and if not “to_i” is tried. Other
methods try “to_str” first and “to_int” then or vice versa to convert to
String or Fixnum.

For example, File#new’s first parameter performs to_str-to_int
conversion. To declare such a parameter a library function uses a
parameter of type Union<T1, T2> marked by [DefaultProtocol]:

public static RubyFile/!/ CreateFile(RubyClass/!/ self,
[DefaultProtocol]Union<int, MutableString> descriptorOrPath,
[Optional, DefaultProtocol]MutableString mode, [Optional]int permission)
{

if (descriptorOrPath.IsFixnum()) { … } else { … }
}

This says that default protocol for Int32 and for MutableString should
be performed in the order specified by the type parameters.

Some methods use CastToInteger protocol. This protocol calls to_int,
similarly to CastToFixnum, but the result could be both Fixnum or
Bignum. This is not a composite conversion since only one conversion is
called (to_int) however the type of the result could be either Int32 or
BigInteger. There are also other places where we need to pass around a
union of Int32 and BigInteger. IntegerValue struct serves this purpose.
A default protocol for IntegerValue is CastToInteger. An example of use
is Bignum#<<:

[RubyMethod("<<")]
public static object/!/ LeftShift(RubyContext/!/ context,
BigInteger/!/ self, [DefaultProtocol]IntegerValue other) {
return other.IsFixnum ? LeftShift(self, other.Fixnum) :
LeftShift(self, other.Bignum);
}

Refactors protocol conversion classes.

Fixes File#open, IO#open, IO#for_fd.
Fixes String#to_i and Kernel#Integer.
Tokenizer now returns whitespace tokens in verbatim mode.

Changes format mode in runrspec to “dotted”. It doesn’t produce so much
noise.

Tomas

Ruby changes look good.

From: Tomas M.
Sent: Friday, January 09, 2009 4:08 PM
To: IronRuby External Code R.; DLR Code Reviews
Cc: [email protected]
Subject: Code Review: CompositeConversions3

tfpt review “/shelveset:CompositeConversions3;REDMOND\tomat”

DLR change (interpreter)

Fixes interpretation of UnaryExpresion cast with a custom method.

Ruby changes

Implements composite conversions and defines default composite protocol
conversions. A composite conversion is basically a combination of at
least 2 protocol conversions. For example, some methods convert to an
integer using “to_int” if available and if not “to_i” is tried. Other
methods try “to_str” first and “to_int” then or vice versa to convert to
String or Fixnum.

For example, File#new’s first parameter performs to_str-to_int
conversion. To declare such a parameter a library function uses a
parameter of type Union<T1, T2> marked by [DefaultProtocol]:

public static RubyFile/!/ CreateFile(RubyClass/!/ self,
[DefaultProtocol]Union<int, MutableString> descriptorOrPath,
[Optional, DefaultProtocol]MutableString mode, [Optional]int permission)
{

if (descriptorOrPath.IsFixnum()) { … } else { … }
}

This says that default protocol for Int32 and for MutableString should
be performed in the order specified by the type parameters.

Some methods use CastToInteger protocol. This protocol calls to_int,
similarly to CastToFixnum, but the result could be both Fixnum or
Bignum. This is not a composite conversion since only one conversion is
called (to_int) however the type of the result could be either Int32 or
BigInteger. There are also other places where we need to pass around a
union of Int32 and BigInteger. IntegerValue struct serves this purpose.
A default protocol for IntegerValue is CastToInteger. An example of use
is Bignum#<<:

[RubyMethod("<<")]
public static object/!/ LeftShift(RubyContext/!/ context,
BigInteger/!/ self, [DefaultProtocol]IntegerValue other) {
return other.IsFixnum ? LeftShift(self, other.Fixnum) :
LeftShift(self, other.Bignum);
}

Refactors protocol conversion classes.

Fixes File#open, IO#open, IO#for_fd.
Fixes String#to_i and Kernel#Integer.
Tokenizer now returns whitespace tokens in verbatim mode.

Changes format mode in runrspec to “dotted”. It doesn’t produce so much
noise.

Tomas