Forum: IronRuby Code Review: CompositeConversions3

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tomas M. (Guest)
on 2009-01-10 02:09
(Received via mailing list)
Attachment: CompositeConversions3.diff (0 Bytes)
tfpt review "/shelveset:CompositeConversions3;REDMOND\tomat"

DLR change (interpreter)

Fixes interpretation of UnaryExpresion cast with a custom method.

Ruby changes

1)
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.

2)
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);
}

3)
Refactors protocol conversion classes.

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

5)
Changes format mode in runrspec to "dotted". It doesn't produce so much
noise.

Tomas
John M. (Guest)
on 2009-01-10 03:03
(Received via mailing list)
Interpreter change looks good.

From: Tomas M.
Sent: Friday, January 09, 2009 4:08 PM
To: IronRuby External Code R.; DLR Code Reviews
Cc: removed_email_address@domain.invalid
Subject: Code Review: CompositeConversions3


tfpt review "/shelveset:CompositeConversions3;REDMOND\tomat"

DLR change (interpreter)

Fixes interpretation of UnaryExpresion cast with a custom method.

Ruby changes

1)
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.

2)
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);
}

3)
Refactors protocol conversion classes.

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

5)
Changes format mode in runrspec to "dotted". It doesn't produce so much
noise.

Tomas
Martin Maly (Guest)
on 2009-01-10 03:51
(Received via mailing list)
Outer ring looks good.

From: Tomas M.
Sent: Friday, January 09, 2009 4:08 PM
To: IronRuby External Code R.; DLR Code Reviews
Cc: removed_email_address@domain.invalid
Subject: Code Review: CompositeConversions3


tfpt review "/shelveset:CompositeConversions3;REDMOND\tomat"

DLR change (interpreter)

Fixes interpretation of UnaryExpresion cast with a custom method.

Ruby changes

1)
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.

2)
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);
}

3)
Refactors protocol conversion classes.

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

5)
Changes format mode in runrspec to "dotted". It doesn't produce so much
noise.

Tomas
Curt H. (Guest)
on 2009-01-12 23:29
(Received via mailing list)
Ruby changes look good.

From: Tomas M.
Sent: Friday, January 09, 2009 4:08 PM
To: IronRuby External Code R.; DLR Code Reviews
Cc: removed_email_address@domain.invalid
Subject: Code Review: CompositeConversions3


tfpt review "/shelveset:CompositeConversions3;REDMOND\tomat"

DLR change (interpreter)

Fixes interpretation of UnaryExpresion cast with a custom method.

Ruby changes

1)
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.

2)
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);
}

3)
Refactors protocol conversion classes.

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

5)
Changes format mode in runrspec to "dotted". It doesn't produce so much
noise.

Tomas
This topic is locked and can not be replied to.