# Code Review: InitAndScopes6

**URL:** <https://www.ruby-forum.com/t/code-review-initandscopes6/157045>\
**Category:** IronRuby\
**Created:** [January 6, 2009, 8:51pm UTC](https://www.ruby-forum.com/t/code-review-initandscopes6/157045 "2009-01-06T20:51:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [January 6, 2009, 8:51pm UTC](https://www.ruby-forum.com/t/code-review-initandscopes6/157045/1 "2009-01-06T20:51:37Z")

</div>

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

Outer-ring DLR changes (Hosting API implementation):

Any code compilation/execution without explicitly given scope should  
eventually call SourceUnit.Compile overload that creates a new scope for  
the execution, so that a) the creation of an implicit empty scope is  
implemented on a single place and b) the language can adjust compilation  
based upon whether the code is executed against a scope or not  
(different overloads of LanguageContext.GetCompilerOptions are called).

Adds SourceUnit.Execute overload taking ErrorSink parameter to match  
Compile overloads.

Ruby changes:

Enables sharing of Ruby top-level binding across multiple executions  
against the same DLR Scope, which enables local variables in a console  
implemented via DLR Hosting API.

Refactors control flow handling in rules:

- Methods that build rules are of two kinds: BuildXxxNoFlow and  
BuildXxx, where the former produces a rule w/o control flow and  
optionally stores a control flow builder delegate on MetaObjectBuilder  
if CF handling is needed. The latter calls the former and if there has  
been a CF builder registered applies it on the resulting meta object.  
This allows to compose rules w/o CF and then apply CF handling once on  
the final result.

- Fixes IO#open not to dynamically dispatch to “new”. The  
implementation requires the above rule composition.

Scope cleanup:

- Renames GlobalScopeExtension to RubyGlobalScope.

- Removes unnecessary dependencies on RubyScope where RubyContext is  
sufficient.

- Replaces uses of Scope where RubyGlobalScope is more suitable.

- Removes RubyContext.DefaultGlobalScope and adds Ruby.RequireFile  
taking a ScriptScope.

Replaces Booleans on RubyCompilerOptions with an enum.

Fixes method definition in module\_eval or define\_method.

Adds /py option to unit test driver, which enables tests dependent on  
IronPython.

Tomas

---

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [January 6, 2009, 10:42pm UTC](https://www.ruby-forum.com/t/code-review-initandscopes6/157045/2 "2009-01-06T22:42:12Z")

</div>

Awesome! Ruby changes are good (other than a typo “bidning” in a  
comment in HostingTests.cs :)).

From: Tomas M.  
Sent: Tuesday, January 06, 2009 11:17 AM  
To: IronRuby External Code R.; DLR Code Reviews  
Cc: removed\_email\_address@domain.invalid  
Subject: Code Review: InitAndScopes6

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

Outer-ring DLR changes (Hosting API implementation):

Any code compilation/execution without explicitly given scope should  
eventually call SourceUnit.Compile overload that creates a new scope for  
the execution, so that a) the creation of an implicit empty scope is  
implemented on a single place and b) the language can adjust compilation  
based upon whether the code is executed against a scope or not  
(different overloads of LanguageContext.GetCompilerOptions are called).

Adds SourceUnit.Execute overload taking ErrorSink parameter to match  
Compile overloads.

Ruby changes:

Enables sharing of Ruby top-level binding across multiple executions  
against the same DLR Scope, which enables local variables in a console  
implemented via DLR Hosting API.

Refactors control flow handling in rules:

- Methods that build rules are of two kinds: BuildXxxNoFlow and  
BuildXxx, where the former produces a rule w/o control flow and  
optionally stores a control flow builder delegate on MetaObjectBuilder  
if CF handling is needed. The latter calls the former and if there has  
been a CF builder registered applies it on the resulting meta object.  
This allows to compose rules w/o CF and then apply CF handling once on  
the final result.

- Fixes IO#open not to dynamically dispatch to “new”. The  
implementation requires the above rule composition.

Scope cleanup:

- Renames GlobalScopeExtension to RubyGlobalScope.

- Removes unnecessary dependencies on RubyScope where RubyContext is  
sufficient.

- Replaces uses of Scope where RubyGlobalScope is more suitable.

- Removes RubyContext.DefaultGlobalScope and adds Ruby.RequireFile  
taking a ScriptScope.

Replaces Booleans on RubyCompilerOptions with an enum.

Fixes method definition in module\_eval or define\_method.

Adds /py option to unit test driver, which enables tests dependent on  
IronPython.

Tomas

---

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [January 6, 2009, 10:52pm UTC](https://www.ruby-forum.com/t/code-review-initandscopes6/157045/3 "2009-01-06T22:52:10Z")

</div>

DLR changes look good too.

From: Curt H.  
Sent: Tuesday, January 06, 2009 1:41 PM  
To: Tomas M.; IronRuby External Code R.; DLR Code Reviews  
Cc: removed\_email\_address@domain.invalid  
Subject: RE: Code Review: InitAndScopes6

Awesome! Ruby changes are good (other than a typo “bidning” in a  
comment in HostingTests.cs :)).

From: Tomas M.  
Sent: Tuesday, January 06, 2009 11:17 AM  
To: IronRuby External Code R.; DLR Code Reviews  
Cc: removed\_email\_address@domain.invalid  
Subject: Code Review: InitAndScopes6

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

Outer-ring DLR changes (Hosting API implementation):

Any code compilation/execution without explicitly given scope should  
eventually call SourceUnit.Compile overload that creates a new scope for  
the execution, so that a) the creation of an implicit empty scope is  
implemented on a single place and b) the language can adjust compilation  
based upon whether the code is executed against a scope or not  
(different overloads of LanguageContext.GetCompilerOptions are called).

Adds SourceUnit.Execute overload taking ErrorSink parameter to match  
Compile overloads.

Ruby changes:

Enables sharing of Ruby top-level binding across multiple executions  
against the same DLR Scope, which enables local variables in a console  
implemented via DLR Hosting API.

Refactors control flow handling in rules:

- Methods that build rules are of two kinds: BuildXxxNoFlow and  
BuildXxx, where the former produces a rule w/o control flow and  
optionally stores a control flow builder delegate on MetaObjectBuilder  
if CF handling is needed. The latter calls the former and if there has  
been a CF builder registered applies it on the resulting meta object.  
This allows to compose rules w/o CF and then apply CF handling once on  
the final result.

- Fixes IO#open not to dynamically dispatch to “new”. The  
implementation requires the above rule composition.

Scope cleanup:

- Renames GlobalScopeExtension to RubyGlobalScope.

- Removes unnecessary dependencies on RubyScope where RubyContext is  
sufficient.

- Replaces uses of Scope where RubyGlobalScope is more suitable.

- Removes RubyContext.DefaultGlobalScope and adds Ruby.RequireFile  
taking a ScriptScope.

Replaces Booleans on RubyCompilerOptions with an enum.

Fixes method definition in module\_eval or define\_method.

Adds /py option to unit test driver, which enables tests dependent on  
IronPython.

Tomas
