[Ironruby-core] Code Review: Ruby custom actions, various bug fixes

Dino Viehland dinov at exchange.microsoft.com
Mon May 5 12:38:42 EDT 2008

Ruby changes look good.

I've got one comment based upon where the DLR is going with actions - not that you need to change anything now, just that it might make your life easier in the future if you find yourself adding more actions.  That is for some actions (e.g. ProtocolConversionAction) you have the rule production logic in the action it's self.  For others (e.g. Super) that logic lives in the RubyBinder.  Keeping all of it in the action's might make it easier when the DLR switches to having the action's (then called SiteBinders or whatever the final name is) produce the rule.  Of course you could always choose to forward them onto the RubyBinder yourself.

From: Tomas Matousek
Sent: Monday, May 05, 2008 12:54 AM
To: IronRuby External Code Reviewers; Rowan Code Reviewers
Cc: ironruby-core at rubyforge.org
Subject: Code Review: Ruby custom actions, various bug fixes

tfpt review /shelveset:Super17;REDMOND\tomat

DLR changes:

-          Removes InvokeMethodAttributes.

-          Makes ActionExpression factory public  - it's needed by a custom Ruby action (ProtocolConverterAction).

Ruby changes:

-          Adds InvokeSuperMemberAction custom action

-          Refactors handling of member invocation in RubyBinder.

-          Improves implementation of super call. This is how 'super' seems to work:

1.        Let s be the inner-most scope in the lexical scope hierarchy of the 'super' call site that is either

a.       a method scope, or

b.      a block definition scope of a block whose caller is a method created by 'define_method'

2.       If s is a method definition scope (1a) then this method's frame f is available: either it is

a.       the frame that invokes the 'super' call, or

b.      captured by a closure of the block that contains the 'super' call

3.       If s is a block (1b) then its caller's frame f is available.

                Use the arguments, self object and method name of the frame f for the 'super' invocation.

Implementation: the method defined by define_method passes its frame into the block it calls (in BlockParam object). Super call site traverses lexical hierarchy and finds scope s and frame f. All information necessary to perform the super call are on f. For super to work within eval some additional work needs to be done beyond this shelveset - arguments needs to be distinguishable from other local variables at run-time. Super in eval will then do dynamic local variable lookup on the argument names that it finds in the frame f. This change doesn't implement any optimizations though they are possible in some cases.

-          Adds ProtocolConverterAction custom action.

o   It's an abstract class for specific protocol conversions (to_proc, to_s, ...)

o   This shelveset adds only ConvertToProcAction <: ProtocolConverterAction so far, we can replace Protocols by these actions in future.

o   The protocol used for conversions is:

*         if obj.respond_to? :to_xxx
   result = obj.to_xxx
   if result.subclass_of Xxx then return result

o   The action implements an optimization that avoids 2 dynamic dispatches in case respond_to? is not overridden:

*         check class version of object obj in rule test

*         obj.class overrides respond_to? => no optimization (emit 2 dynamic dispatches to respond_to? and to_xxx)

*         otherwise: lookup to_xxx, not found => emit error, found => emit static call to to_xxx

*         check result of to_xxx

-          Implements to_proc conversion for & operator using ConvertToProcAction (fixes bug #19714: & operator should call to_proc)

-          Adds #method-definition closure local variable of type RubyMethodInfo:

o   Each method definition stores itself into this variable, which is used inside the method definition. This effectively enables any library/ops code to access the current method definition.

o   RubyMethodInfo now holds on the method's declaring local scope.

o   Adds DefinitionName to RubyMethodInfo - this is the name of the method definition. The method itself could be used under different names (if aliased). Some language operations care only about definition name (like super call).

-          Adds UndefineMethod attribute - it is used on library classes to undefined methods defined in base classes.

-          Fixes GetInstanceMethods to skip undefined method.

-          Implements Kernel#block_given?, Module#module_function methods. Fixes Kernel#private/public/protected methods.

-          Replaces VariableExpression and ParameterExpression by Expression where possible.

-          Simplifies code emitted per method definition.

-          Fixes bug #19907: class_eval not singleton.

-          Fixes bug #19672: Logical operator in method arguments won't parse.

-          Fixes bug #19803: rescue next syntax bug.

-          Fixes bug #19892: Proc cannot be used as Boolean.

-          Fixes bug #19706: alias method resolution bug.

-          Adds more unit tests and refactors unit test driver a little bit.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20080505/b940f958/attachment-0001.html>

More information about the Ironruby-core mailing list