<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/dir/getwd_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/dir/pwd_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/string/capitalize_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/string/delete_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/string/downcase_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/string/next_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/string/reverse_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/string/succ_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/string/swapcase_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/string/upcase_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/openssl/pkey/rsa/new_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/openssl/x509/certificate/issuer_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/openssl/x509/certificate/new_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/openssl/x509/certificate/not_after_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/openssl/x509/certificate/not_before_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/openssl/x509/certificate/public_key_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/openssl/x509/certificate/serial_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/openssl/x509/certificate/signature_algorithm_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/openssl/x509/certificate/subject_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/openssl/x509/certificate/version_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/openssl/x509/name/new_tags.txt</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/.gitattributes</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/enumerator/kernel/enum_for_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/enumerator/kernel/to_enum_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/enumerator/shared/enum_for.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/open3/popen3_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/openssl/pkey/rsa/new_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/openssl/x509/certificate/issuer_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/openssl/x509/certificate/new_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/openssl/x509/certificate/not_after_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/openssl/x509/certificate/not_before_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/openssl/x509/certificate/public_key_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/openssl/x509/certificate/serial_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/openssl/x509/certificate/signature_algorithm_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/openssl/x509/certificate/subject_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/openssl/x509/certificate/version_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/openssl/x509/name/new_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/bin/specrb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/bin/specrb.bat</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/cache/test-spec-0.10.0.gem</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/README</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/ROADMAP</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/Rakefile</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/SPECS</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/TODO</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/bin/specrb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/examples/stack.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/examples/stack_spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/lib/test/spec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/lib/test/spec/dox.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/lib/test/spec/rdox.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/lib/test/spec/should-output.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/lib/test/spec/version.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/test/spec_dox.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/test/spec_flexmock.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/test/spec_mocha.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/test/spec_nestedcontexts.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/test/spec_new_style.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/test/spec_should-output.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/test/spec_testspec.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/test/spec_testspec_order.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/gems/test-spec-0.10.0/test/test_testunit.rb</filename>
    </added>
    <added>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/Ruby/ruby-1.8.6p287/lib/ruby/gems/1.8/specifications/test-spec-0.10.0.gemspec</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/RunnableScriptCode.cs</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/IComConvertible.cs</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Experimental/IO/FileModes.rb</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Experimental/IO/fd_reuse.rb</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Experimental/IO/io_init.rb</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Experimental/IO/io_init_destroys_fd.rb</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Experimental/IO/stream_sharing.rb</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Experimental/IO/stringio_init.rb</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Experimental/Unicode/names.rb</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/PrintOps.cs</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/RubyPipe.cs</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Open3/Open3.cs</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Libs/open3.rb</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/IOMode.cs</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/LibraryInitializer.cs</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyBufferedStream.cs</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyFile.cs</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Samples/Tutorial/wpf/SplashScreen.cs</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Samples/Tutorial/wpf/SplashScreen.dll</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Samples/Tutorial/wpf/SplashScreen.png</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Scripts/bin/tutorial.bat</filename>
    </added>
    <added>
      <filename>Merlin/Main/Languages/Ruby/Scripts/tags_stats.rb</filename>
    </added>
    <added>
      <filename>Merlin/Main/Scripts/Bat/Alias.ps1</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -53,7 +53,12 @@ class RubyGemTestCase &lt; MiniTest::Unit::TestCase
 
     @ui = MockGemUi.new
     tmpdir = nil
-    Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp
+    if defined? RUBY_ENGINE and RUBY_ENGINE == &quot;ironruby&quot;
+      # workaround for http://rubyforge.org/tracker/?func=detail&amp;group_id=126&amp;aid=24169&amp;atid=575
+      tmpdir = Dir.tmpdir
+    else
+      Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp
+    end
     @tempdir = File.join tmpdir, &quot;test_rubygems_#{$$}&quot;
     @tempdir.untaint
     @gemhome = File.join @tempdir, &quot;gemhome&quot;</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/RubyGems-1_3_1-test/gemutilities.rb</filename>
    </modified>
    <modified>
      <diff>@@ -24,6 +24,7 @@ using Microsoft.Scripting.Runtime;
 using System.Runtime.InteropServices;
 using Microsoft.Scripting.Generation;
 using System.Collections.Generic;
+using System.Globalization;
 
 namespace IronRuby.StandardLibrary.Yaml {
 
@@ -37,7 +38,7 @@ namespace IronRuby.StandardLibrary.Yaml {
             BinaryOpStorage/*!*/ greaterThanStorage,
             object self) {
             return ArrayOps.SortInPlace(comparisonStorage, lessThanStorage, greaterThanStorage,
-                null, KernelOps.InstanceVariables(comparisonStorage.Context, self)
+                KernelOps.InstanceVariables(comparisonStorage.Context, self)
             );
         }
 
@@ -59,11 +60,10 @@ namespace IronRuby.StandardLibrary.Yaml {
         }
 
         [RubyMethod(&quot;taguri&quot;)]
-        public static MutableString TagUri(RubyContext/*!*/ context, object self) {
-            MutableString str = MutableString.Create(&quot;!ruby/object:&quot;);
-            str.Append(context.GetClassName(self));
-            str.Append(' ');
-            return str;
+        public static MutableString/*!*/ TagUri(RubyContext/*!*/ context, object self) {
+            return MutableString.Create(&quot;!ruby/object:&quot;, RubyEncoding.ClassName).
+                Append(context.GetClassName(self)).
+                Append(' ');
         }
     }
 
@@ -93,8 +93,8 @@ namespace IronRuby.StandardLibrary.Yaml {
         }
 
         [RubyMethod(&quot;taguri&quot;)]
-        public static MutableString TagUri(RubyContext/*!*/ context, object self) {
-            return MutableString.Create(&quot;tag:yaml.org,2002:map&quot;);
+        public static MutableString/*!*/ TagUri(RubyContext/*!*/ context, object self) {
+            return MutableString.CreateAscii(&quot;tag:yaml.org,2002:map&quot;);
         }
     }
 
@@ -106,8 +106,8 @@ namespace IronRuby.StandardLibrary.Yaml {
         }
 
         [RubyMethod(&quot;taguri&quot;)]
-        public static MutableString TagUri(RubyContext/*!*/ context, object self) {
-            return MutableString.Create(&quot;tag:yaml.org,2002:seq&quot;);
+        public static MutableString/*!*/ TagUri(RubyContext/*!*/ context, object self) {
+            return MutableString.CreateAscii(&quot;tag:yaml.org,2002:seq&quot;);
         }
     }
 
@@ -118,15 +118,16 @@ namespace IronRuby.StandardLibrary.Yaml {
             var fieldNames = self.GetNames();
             var map = new Dictionary&lt;MutableString, object&gt;(fieldNames.Count);
             for (int i = 0; i &lt; fieldNames.Count; i++) {
-                map[MutableString.Create(fieldNames[i])] = self.GetValue(i);
+                // TODO: symbol encodings
+                map[MutableString.Create(fieldNames[i], RubyEncoding.UTF8)] = self.GetValue(i);
             }
             rep.AddYamlProperties(self, map);
             return rep.Map(self, map);
         }
 
         [RubyMethod(&quot;taguri&quot;)]
-        public static MutableString TagUri(RubyStruct/*!*/ self) {
-            MutableString str = MutableString.Create(&quot;tag:ruby.yaml.org,2002:struct:&quot;);
+        public static MutableString/*!*/ TagUri(RubyStruct/*!*/ self) {
+            MutableString str = MutableString.CreateMutable(&quot;tag:ruby.yaml.org,2002:struct:&quot;, RubyEncoding.ClassName);
             string name = self.ImmediateClass.GetNonSingletonClass().Name;
             if (name != null) {
                 string structPrefix = &quot;Struct::&quot;;
@@ -146,7 +147,7 @@ namespace IronRuby.StandardLibrary.Yaml {
 
             var site = messageStorage.GetCallSite(&quot;message&quot;, 0);
             var map = new Dictionary&lt;MutableString, object&gt;() {
-                { MutableString.Create(&quot;message&quot;), site.Target(site, self) }
+                { MutableString.CreateAscii(&quot;message&quot;), site.Target(site, self) }
             };
             
             rep.AddYamlProperties(self, map);
@@ -155,9 +156,9 @@ namespace IronRuby.StandardLibrary.Yaml {
 
         [RubyMethod(&quot;taguri&quot;)]
         public static MutableString TagUri(RubyContext/*!*/ context, object self) {
-            MutableString str = MutableString.Create(&quot;!ruby/exception:&quot;);
-            str.Append(context.GetClassName(self));
-            return str;
+            return MutableString.CreateMutable(RubyEncoding.ClassName).
+                Append(&quot;!ruby/exception:&quot;).
+                Append(context.GetClassName(self));
         }
     }
 
@@ -221,7 +222,7 @@ namespace IronRuby.StandardLibrary.Yaml {
             }
 
             var map = new Dictionary&lt;MutableString, object&gt;() {
-                { MutableString.Create(&quot;str&quot;), str }
+                { MutableString.CreateAscii(&quot;str&quot;), str }
             };
             rep.AddYamlProperties(self, map, props);
             return rep.Map(self, map);
@@ -229,7 +230,7 @@ namespace IronRuby.StandardLibrary.Yaml {
 
         [RubyMethod(&quot;taguri&quot;)]
         public static MutableString/*!*/ TagUri(object self) {
-            return MutableString.Create(&quot;tag:yaml.org,2002:str&quot;);
+            return MutableString.CreateAscii(&quot;tag:yaml.org,2002:str&quot;);
         }
     }
 
@@ -242,7 +243,7 @@ namespace IronRuby.StandardLibrary.Yaml {
 
         [RubyMethod(&quot;taguri&quot;)]
         public static MutableString/*!*/ TagUri(object self) {
-            return MutableString.Create(&quot;tag:yaml.org,2002:int&quot;);
+            return MutableString.CreateAscii(&quot;tag:yaml.org,2002:int&quot;);
         }
     }
 
@@ -254,8 +255,8 @@ namespace IronRuby.StandardLibrary.Yaml {
         } 
 
         [RubyMethod(&quot;taguri&quot;)]
-        public static MutableString/*!*/ TagUri([NotNull]BigInteger self) {     
-            return MutableString.Create(&quot;tag:yaml.org,2002:int:Bignum&quot;);            
+        public static MutableString/*!*/ TagUri([NotNull]BigInteger self) {
+            return MutableString.CreateAscii(&quot;tag:yaml.org,2002:int:Bignum&quot;);            
         }
     }
 
@@ -266,11 +267,11 @@ namespace IronRuby.StandardLibrary.Yaml {
             MutableString str = Protocols.ConvertToString(tosConversion, self);
             if (str != null) {
                 if (str.Equals(&quot;Infinity&quot;)) {
-                    str = MutableString.Create(&quot;.Inf&quot;);
+                    str = MutableString.CreateAscii(&quot;.Inf&quot;);
                 } else if (str.Equals(&quot;-Infinity&quot;)) {
-                    str = MutableString.Create(&quot;-.Inf&quot;);
+                    str = MutableString.CreateAscii(&quot;-.Inf&quot;);
                 } else if (str.Equals(&quot;NaN&quot;)) {
-                    str = MutableString.Create(&quot;.NaN&quot;);
+                    str = MutableString.CreateAscii(&quot;.NaN&quot;);
                 }
             }
             return rep.Scalar(self, str);
@@ -278,7 +279,7 @@ namespace IronRuby.StandardLibrary.Yaml {
 
         [RubyMethod(&quot;taguri&quot;)]
         public static MutableString/*!*/ TagUri(double self) {
-            return MutableString.Create(&quot;tag:yaml.org,2002:float&quot;);
+            return MutableString.CreateAscii(&quot;tag:yaml.org,2002:float&quot;);
         }
     }
 
@@ -292,9 +293,9 @@ namespace IronRuby.StandardLibrary.Yaml {
             var end = endStorage.GetCallSite(&quot;end&quot;);
 
             var map = new Dictionary&lt;MutableString, object&gt;() {
-                { MutableString.Create(&quot;begin&quot;), begin.Target(begin, self) },
-                { MutableString.Create(&quot;end&quot;), end.Target(end, self) },
-                { MutableString.Create(&quot;excl&quot;), self.ExcludeEnd },
+                { MutableString.CreateAscii(&quot;begin&quot;), begin.Target(begin, self) },
+                { MutableString.CreateAscii(&quot;end&quot;), end.Target(end, self) },
+                { MutableString.CreateAscii(&quot;excl&quot;), self.ExcludeEnd },
             };
 
             rep.AddYamlProperties(self, map);
@@ -303,7 +304,7 @@ namespace IronRuby.StandardLibrary.Yaml {
 
         [RubyMethod(&quot;taguri&quot;)]
         public static MutableString TagUri([NotNull]Range self) {
-            return MutableString.Create(&quot;tag:ruby.yaml.org,2002:range&quot;);
+            return MutableString.CreateAscii(&quot;tag:ruby.yaml.org,2002:range&quot;);
         }
     }
 
@@ -316,7 +317,7 @@ namespace IronRuby.StandardLibrary.Yaml {
 
         [RubyMethod(&quot;taguri&quot;)]
         public static MutableString/*!*/ TagUri(RubyRegex/*!*/ self) {
-            return MutableString.Create(&quot;tag:ruby.yaml.org,2002:regexp&quot;);
+            return MutableString.CreateAscii(&quot;tag:ruby.yaml.org,2002:regexp&quot;);
         }
     }
 
@@ -325,12 +326,12 @@ namespace IronRuby.StandardLibrary.Yaml {
         [RubyMethod(&quot;to_yaml_node&quot;, RubyMethodAttributes.PrivateInstance)]
         public static Node/*!*/ ToYaml(DateTime self, [NotNull]RubyRepresenter/*!*/ rep) {
             string format = (self.Millisecond != 0) ? &quot;yyyy-MM-dd HH:mm:ss.fffffff K&quot; : &quot;yyyy-MM-dd HH:mm:ss K&quot;;
-            return rep.Scalar(self, MutableString.Create(self.ToString(format)));
+            return rep.Scalar(self, MutableString.CreateAscii(self.ToString(format, CultureInfo.InvariantCulture)));
         }
 
         [RubyMethod(&quot;taguri&quot;)]
         public static MutableString/*!*/ TagUri(DateTime self) {
-            return MutableString.Create(&quot;tag:yaml.org,2002:timestamp&quot;);
+            return MutableString.CreateAscii(&quot;tag:yaml.org,2002:timestamp&quot;);
         }
     }
 
@@ -343,7 +344,7 @@ namespace IronRuby.StandardLibrary.Yaml {
         
         [RubyMethod(&quot;taguri&quot;)]
         public static MutableString/*!*/ TagUri(object self) {
-            return MutableString.Create(&quot;tag:yaml.org,2002:str&quot;);
+            return MutableString.CreateAscii(&quot;tag:yaml.org,2002:str&quot;);
         }
     }
 
@@ -356,7 +357,7 @@ namespace IronRuby.StandardLibrary.Yaml {
 
         [RubyMethod(&quot;taguri&quot;)]
         public static MutableString/*!*/ TagUri(object self) {
-            return MutableString.Create(&quot;tag:yaml.org,2002:bool&quot;);
+            return MutableString.CreateAscii(&quot;tag:yaml.org,2002:bool&quot;);
         }
     }
 
@@ -369,7 +370,7 @@ namespace IronRuby.StandardLibrary.Yaml {
 
         [RubyMethod(&quot;taguri&quot;)]
         public static MutableString/*!*/ TagUri(object self) {
-            return MutableString.Create(&quot;tag:yaml.org,2002:bool&quot;);
+            return MutableString.CreateAscii(&quot;tag:yaml.org,2002:bool&quot;);
         }
     }
 
@@ -382,7 +383,7 @@ namespace IronRuby.StandardLibrary.Yaml {
 
         [RubyMethod(&quot;taguri&quot;)]
         public static MutableString/*!*/ TagUri(object self) {
-            return MutableString.Create(&quot;tag:yaml.org,2002:null&quot;);
+            return MutableString.CreateAscii(&quot;tag:yaml.org,2002:null&quot;);
         }
     }
 </diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/BuiltinsOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -61,7 +61,7 @@ namespace IronRuby.StandardLibrary.Yaml {
 
         private bool _inFlowSequence = false;
 
-        public Scanner(TextReader reader) {
+        public Scanner(TextReader/*!*/ reader) {
             _reader = reader;
             FetchStreamStart();
         }</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/Engine/Scanner.cs</filename>
    </modified>
    <modified>
      <diff>@@ -294,19 +294,19 @@ namespace IronRuby.StandardLibrary.Yaml {
             );
             
             module.DefineLibraryMethod(&quot;each_document&quot;, 0x21, 
-                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.EachDocument)
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RespondToStorage, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.EachDocument)
             );
             
             module.DefineLibraryMethod(&quot;each_node&quot;, 0x21, 
-                new System.Func&lt;IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.ParseDocuments)
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RespondToStorage, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.ParseDocuments)
             );
             
             module.DefineLibraryMethod(&quot;load&quot;, 0x21, 
-                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.Load)
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RespondToStorage, IronRuby.Runtime.RubyScope, IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.Load)
             );
             
             module.DefineLibraryMethod(&quot;load_documents&quot;, 0x21, 
-                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.EachDocument)
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RespondToStorage, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.EachDocument)
             );
             
             module.DefineLibraryMethod(&quot;load_file&quot;, 0x21, 
@@ -314,15 +314,15 @@ namespace IronRuby.StandardLibrary.Yaml {
             );
             
             module.DefineLibraryMethod(&quot;load_stream&quot;, 0x21, 
-                new System.Func&lt;IronRuby.Runtime.UnaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyScope, IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.LoadStream)
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RespondToStorage, IronRuby.Runtime.UnaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyScope, IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.LoadStream)
             );
             
             module.DefineLibraryMethod(&quot;parse&quot;, 0x21, 
-                new System.Func&lt;IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.Parse)
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RespondToStorage, IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.Parse)
             );
             
             module.DefineLibraryMethod(&quot;parse_documents&quot;, 0x21, 
-                new System.Func&lt;IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.ParseDocuments)
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RespondToStorage, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyModule, System.Object, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.ParseDocuments)
             );
             
             module.DefineLibraryMethod(&quot;parse_file&quot;, 0x21, 
@@ -330,7 +330,7 @@ namespace IronRuby.StandardLibrary.Yaml {
             );
             
             module.DefineLibraryMethod(&quot;quick_emit&quot;, 0x21, 
-                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyModule, System.Object, IronRuby.Builtins.Hash, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.QuickEmit), 
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyModule, System.Object, IronRuby.Builtins.Hash, System.Object&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.QuickEmit), 
                 new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyModule, System.Object, IronRuby.StandardLibrary.Yaml.RubyRepresenter, IronRuby.StandardLibrary.Yaml.Node&gt;(IronRuby.StandardLibrary.Yaml.RubyYaml.QuickEmit)
             );
             </diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/Initializer.Generated.cs</filename>
    </modified>
    <modified>
      <diff>@@ -17,30 +17,32 @@ using System;
 using System.IO;
 using System.Text;
 using IronRuby.Builtins;
+using Microsoft.Scripting.Utils;
 
 namespace IronRuby.StandardLibrary.Yaml {
 
     internal class MutableStringWriter : TextWriter {
-        private readonly MutableString _str = MutableString.Create(&quot;&quot;);
+        private readonly MutableString _storage;
 
-        public override Encoding Encoding {
-            get {
-                // TODO: return MutableString encoding
-                throw new NotImplementedException();
-            }
+        public MutableStringWriter(MutableString/*!*/ storage) {
+            Assert.NotNull(storage);
+            _storage = storage;
+        }
+
+        public override Encoding/*!*/ Encoding {
+            get { return _storage.Encoding.Encoding; }
         }
 
         public override void  Write(char value) {
-            _str.Append(value);
+            _storage.Append(value);
         }
 
-        public override void Write(char[] buffer, int index, int count) {
-            // TODO: MutableString needs Append(char[], index, count)
-            _str.Append(new string(buffer), index, count);
+        public override void Write(char[]/*!*/ buffer, int index, int count) {
+            _storage.Append(buffer, index, count);
         }
 
-        internal MutableString String {
-            get { return _str; }
+        internal MutableString/*!*/ String {
+            get { return _storage; }
         }
     }
 }</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/MutableStringWriter.cs</filename>
    </modified>
    <modified>
      <diff>@@ -38,3 +38,6 @@ using IronRuby.Runtime;
 [assembly: AllowPartiallyTrustedCallers]
 [assembly: SecurityTransparent]
 
+#if CLR4
+[assembly: SecurityRules(SecurityRuleSet.Level1)]
+#endif
\ No newline at end of file</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/Properties/AssemblyInfo.cs</filename>
    </modified>
    <modified>
      <diff>@@ -116,7 +116,7 @@ namespace IronRuby.StandardLibrary.Yaml {
 
             public object Construct(BaseConstructor ctor, string tag, Node node) {                
                 object result;
-                _block.Yield(MutableString.Create(tag), ctor.ConstructPrimitive(node), out result);
+                _block.Yield(MutableString.Create(tag, RubyEncoding.UTF8), ctor.ConstructPrimitive(node), out result);
                 return result;                
             }
 
@@ -145,7 +145,7 @@ namespace IronRuby.StandardLibrary.Yaml {
             }
             string str = value as string;
             if (str != null) {
-                return MutableString.Create(str);
+                return MutableString.Create(str, RubyEncoding.UTF8);
             }
             return value;
         }</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/RubyConstructor.cs</filename>
    </modified>
    <modified>
      <diff>@@ -36,11 +36,11 @@ namespace IronRuby.StandardLibrary.Yaml {
         }
 
         public override void Write(char value) {
-            _io.Write(new string(value, 1));
+            _io.WriteBytes(new string(value, 1));
         }
 
         public override void Write(char[] buffer, int index, int count) {
-            _io.Write(buffer, index, count);
+            _io.WriteBytes(buffer, index, count);
         }
 
         public override void Flush() {</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/RubyIOWriter.cs</filename>
    </modified>
    <modified>
      <diff>@@ -168,8 +168,9 @@ namespace IronRuby.StandardLibrary.Yaml {
 
         internal void AddYamlProperties(object self, Dictionary&lt;MutableString, object&gt;/*!*/ map, RubyArray/*!*/ props) {
             foreach (object prop in props) {
+                // TODO: ToString? encoding?
                 string p = prop.ToString();
-                map[MutableString.Create(p.Substring(1))] = KernelOps.InstanceVariableGet(_context, self, p);
+                map[MutableString.Create(p.Substring(1), RubyEncoding.UTF8)] = KernelOps.InstanceVariableGet(_context, self, p);
             }
         }
     }</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/RubyRepresenter.cs</filename>
    </modified>
    <modified>
      <diff>@@ -22,6 +22,8 @@ using IronRuby.Builtins;
 using IronRuby.Runtime;
 using Microsoft.Scripting;
 using Microsoft.Scripting.Runtime;
+using IronRuby.Runtime.Conversions;
+using System.Text;
 
 namespace IronRuby.StandardLibrary.Yaml {
 
@@ -60,32 +62,33 @@ namespace IronRuby.StandardLibrary.Yaml {
 
         private static Hash CreateDefaultTagMapping(RubyContext/*!*/ context) {
             Hash taggedClasses = new Hash(context.EqualityComparer);
-            taggedClasses.Add(MutableString.Create(&quot;tag:ruby.yaml.org,2002:array&quot;), context.GetClass(typeof(RubyArray)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:ruby.yaml.org,2002:exception&quot;), context.GetClass(typeof(Exception)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:ruby.yaml.org,2002:hash&quot;), context.GetClass(typeof(Hash)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:ruby.yaml.org,2002:object&quot;), context.GetClass(typeof(object)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:ruby.yaml.org,2002:range&quot;), context.GetClass(typeof(Range)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:ruby.yaml.org,2002:regexp&quot;), context.GetClass(typeof(RubyRegex)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:ruby.yaml.org,2002:string&quot;), context.GetClass(typeof(MutableString)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:ruby.yaml.org,2002:struct&quot;), context.GetClass(typeof(RubyStruct)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:ruby.yaml.org,2002:sym&quot;), context.GetClass(typeof(SymbolId)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:ruby.yaml.org,2002:symbol&quot;), context.GetClass(typeof(SymbolId)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:ruby.yaml.org,2002:time&quot;), context.GetClass(typeof(DateTime)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:binary&quot;), context.GetClass(typeof(MutableString)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:bool#no&quot;), context.FalseClass);
-            taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:bool#yes&quot;), context.TrueClass);
-            taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:float&quot;), context.GetClass(typeof(Double)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:int&quot;), context.GetClass(typeof(Integer)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:map&quot;), context.GetClass(typeof(Hash)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:null&quot;), context.NilClass);            
-            taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:seq&quot;), context.GetClass(typeof(RubyArray)));            
-            taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:str&quot;), context.GetClass(typeof(MutableString)));
-            taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:timestamp&quot;), context.GetClass(typeof(DateTime)));
-            //Currently not supported
-            //taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:omap&quot;), ec.GetClass(typeof()));
-            //taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:pairs&quot;),//    ec.GetClass(typeof()));
-            //taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:set&quot;),//    ec.GetClass(typeof()));
-            //taggedClasses.Add(MutableString.Create(&quot;tag:yaml.org,2002:timestamp#ymd'&quot;), );
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:ruby.yaml.org,2002:array&quot;), context.GetClass(typeof(RubyArray)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:ruby.yaml.org,2002:exception&quot;), context.GetClass(typeof(Exception)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:ruby.yaml.org,2002:hash&quot;), context.GetClass(typeof(Hash)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:ruby.yaml.org,2002:object&quot;), context.GetClass(typeof(object)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:ruby.yaml.org,2002:range&quot;), context.GetClass(typeof(Range)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:ruby.yaml.org,2002:regexp&quot;), context.GetClass(typeof(RubyRegex)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:ruby.yaml.org,2002:string&quot;), context.GetClass(typeof(MutableString)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:ruby.yaml.org,2002:struct&quot;), context.GetClass(typeof(RubyStruct)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:ruby.yaml.org,2002:sym&quot;), context.GetClass(typeof(SymbolId)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:ruby.yaml.org,2002:symbol&quot;), context.GetClass(typeof(SymbolId)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:ruby.yaml.org,2002:time&quot;), context.GetClass(typeof(DateTime)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:binary&quot;), context.GetClass(typeof(MutableString)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:float&quot;), context.GetClass(typeof(Double)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:int&quot;), context.GetClass(typeof(Integer)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:map&quot;), context.GetClass(typeof(Hash)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:seq&quot;), context.GetClass(typeof(RubyArray)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:str&quot;), context.GetClass(typeof(MutableString)));
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:timestamp&quot;), context.GetClass(typeof(DateTime)));
+                                                 
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:bool#no&quot;), context.FalseClass);
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:bool#yes&quot;), context.TrueClass);
+            taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:null&quot;), context.NilClass);
+            //Currently not supported             
+            //taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:omap&quot;), ec.GetClass(typeof()));
+            //taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:pairs&quot;),//    ec.GetClass(typeof()));
+            //taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:set&quot;),//    ec.GetClass(typeof()));
+            //taggedClasses.Add(MutableString.CreateAscii(&quot;tag:yaml.org,2002:timestamp#ymd'&quot;), );
             return taggedClasses;
         }
 
@@ -110,8 +113,10 @@ namespace IronRuby.StandardLibrary.Yaml {
             if (io != null) {
                 writer = new RubyIOWriter(io);
             } else {
-                writer = new MutableStringWriter();
+                // TODO: encoding?
+                writer = new MutableStringWriter(MutableString.CreateMutable(RubyEncoding.UTF8));
             }
+
             YamlOptions cfg = YamlOptions.DefaultOptions;
             using (Serializer s = new Serializer(new Emitter(writer, cfg), cfg)) {
                 RubyRepresenter r = new RubyRepresenter(context, s, cfg);
@@ -119,7 +124,8 @@ namespace IronRuby.StandardLibrary.Yaml {
                     r.Represent(obj);
                 }
             }
-            if (null != io) {
+
+            if (io != null) {
                 return io;
             } else {
                 return ((MutableStringWriter)writer).String;
@@ -127,9 +133,11 @@ namespace IronRuby.StandardLibrary.Yaml {
         }
 
         [RubyMethod(&quot;load&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static object Load(RubyScope/*!*/ scope, RubyModule/*!*/ self, object io) {
+        public static object Load(ConversionStorage&lt;MutableString&gt;/*!*/ toStr, RespondToStorage/*!*/ respondTo,
+            RubyScope/*!*/ scope, RubyModule/*!*/ self, object io) {
+
             try {
-                foreach (object obj in MakeConstructor(scope.GlobalScope, CheckYamlPort(io))) {
+                foreach (object obj in MakeConstructor(scope.GlobalScope, CheckYamlPort(toStr, respondTo, io))) {
                     return obj;
                 }
                 return null;
@@ -143,13 +151,19 @@ namespace IronRuby.StandardLibrary.Yaml {
 
         [RubyMethod(&quot;load_file&quot;, RubyMethodAttributes.PublicSingleton)]
         public static object LoadFile(RubyScope/*!*/ scope, RubyModule/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path) {
-            return Load(scope, self, new RubyFile(self.Context, path.ConvertToString(), &quot;r&quot;));
+            using (RubyFile file = new RubyFile(self.Context, path.ConvertToString(), IOMode.Default)) {
+                foreach (object obj in MakeConstructor(scope.GlobalScope, file.GetReadableStream())) {
+                    return obj;
+                }
+            }
+            return null;
         }
 
         [RubyMethod(&quot;each_document&quot;, RubyMethodAttributes.PublicSingleton)]
         [RubyMethod(&quot;load_documents&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static object EachDocument(RubyScope/*!*/ scope, BlockParam block, RubyModule/*!*/ self, object io) {
-            RubyConstructor rc = MakeConstructor(scope.GlobalScope, CheckYamlPort(io));
+        public static object EachDocument(ConversionStorage&lt;MutableString&gt;/*!*/ toStr, RespondToStorage/*!*/ respondTo, 
+            RubyScope/*!*/ scope, BlockParam block, RubyModule/*!*/ self, object io) {
+            RubyConstructor rc = MakeConstructor(scope.GlobalScope, CheckYamlPort(toStr, respondTo, io));
             if (block == null &amp;&amp; rc.CheckData()) {
                 throw RubyExceptions.NoBlockGiven();
             }
@@ -164,10 +178,11 @@ namespace IronRuby.StandardLibrary.Yaml {
         }
 
         [RubyMethod(&quot;load_stream&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static object LoadStream(UnaryOpStorage/*!*/ newStorage, BinaryOpStorage/*!*/ addStorage, RubyScope/*!*/ scope, 
+        public static object LoadStream(ConversionStorage&lt;MutableString&gt;/*!*/ toStr, RespondToStorage/*!*/ respondTo, 
+            UnaryOpStorage/*!*/ newStorage, BinaryOpStorage/*!*/ addStorage, RubyScope/*!*/ scope, 
             RubyModule/*!*/ self, object io) {
             
-            RubyConstructor rc = MakeConstructor(scope.GlobalScope, CheckYamlPort(io));
+            RubyConstructor rc = MakeConstructor(scope.GlobalScope, CheckYamlPort(toStr, respondTo, io));
 
             // TODO: only if io was converted to a string:
             io = CreateDefaultStream(newStorage, scope, self);
@@ -190,24 +205,31 @@ namespace IronRuby.StandardLibrary.Yaml {
         }
 
         [RubyMethod(&quot;parse&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static object Parse(RubyModule self, object io) {
-            try {
-                foreach (object obj in MakeComposer(CheckYamlPort(io))) {
+        public static object Parse(ConversionStorage&lt;MutableString&gt;/*!*/ toStr, RespondToStorage/*!*/ respondTo, RubyModule/*!*/ self, object io) {
+            using (Stream stream = CheckYamlPort(toStr, respondTo, io)) {
+                foreach (object obj in MakeComposer(stream)) {
                     return obj;
                 }
-                return null;
-            } finally {
-                RubyIO rio = io as RubyIO;
-                if (rio != null) {
-                    rio.Close();
+            }
+            return null;
+        }
+
+        [RubyMethod(&quot;parse_file&quot;, RubyMethodAttributes.PublicSingleton)]
+        public static object ParseFile(RubyModule/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path) {
+            using (Stream stream = new RubyFile(self.Context, path.ConvertToString(), IOMode.Default).GetReadableStream()) {
+                foreach (object obj in MakeComposer(stream)) {
+                    return obj;
                 }
             }
+            return null;
         }
 
         [RubyMethod(&quot;parse_documents&quot;, RubyMethodAttributes.PublicSingleton)]
         [RubyMethod(&quot;each_node&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static object ParseDocuments(BlockParam block, RubyModule self, object io) {
-            Composer c = MakeComposer(CheckYamlPort(io));
+        public static object ParseDocuments(ConversionStorage&lt;MutableString&gt;/*!*/ toStr, RespondToStorage/*!*/ respondTo,
+            BlockParam block, RubyModule/*!*/ self, object io) {
+
+            Composer c = MakeComposer(CheckYamlPort(toStr, respondTo, io));
             if (block == null &amp;&amp; c.CheckNode()) {
                 throw RubyExceptions.NoBlockGiven();
             }
@@ -220,11 +242,6 @@ namespace IronRuby.StandardLibrary.Yaml {
             return null;
         }
 
-        [RubyMethod(&quot;parse_file&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static object ParseFile(RubyModule/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path) {
-            return Parse(self, new RubyFile(self.Context, path.ConvertToString(), &quot;r&quot;));
-        }
-
         [RubyMethod(&quot;dump_stream&quot;, RubyMethodAttributes.PublicSingleton)]
         public static object DumpStream(UnaryOpStorage/*!*/ newStorage, BinaryOpStorage/*!*/ addStorage, UnaryOpStorage/*!*/ emitStorage,
             RubyScope/*!*/ scope, RubyModule/*!*/ self, [NotNull]params object[] args) {
@@ -247,17 +264,22 @@ namespace IronRuby.StandardLibrary.Yaml {
         }
 
         [RubyMethod(&quot;quick_emit&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static MutableString QuickEmit(RubyContext/*!*/ context, [NotNull]BlockParam/*!*/ block, RubyModule/*!*/ self, object objectId, [NotNull]Hash/*!*/ opts) {
+        public static object QuickEmit(RubyContext/*!*/ context, [NotNull]BlockParam/*!*/ block, RubyModule/*!*/ self, object objectId, [NotNull]Hash/*!*/ opts) {
             YamlOptions cfg = YamlOptions.DefaultOptions;
-            MutableStringWriter writer = new MutableStringWriter();
+            
+            // TODO: encoding
+            MutableStringWriter writer = new MutableStringWriter(MutableString.CreateMutable(RubyEncoding.UTF8));
             Emitter emitter = new Emitter(writer, cfg);
 
             using (Serializer s = new Serializer(emitter, cfg)) {
                 RubyRepresenter r = new RubyRepresenter(context, s, cfg);
                 object result;
-                block.Yield(r, out result);
-                s.Serialize(result as Node);
 
+                if (block.Yield(r, out result)) {
+                    return result;
+                }
+
+                s.Serialize(result as Node);
                 return writer.String;
             }
         }
@@ -272,7 +294,7 @@ namespace IronRuby.StandardLibrary.Yaml {
         [RubyMethod(&quot;tagurize&quot;, RubyMethodAttributes.PublicSingleton)]
         public static object Tagurize(ConversionStorage&lt;MutableString&gt;/*!*/ stringTryCast, RubyModule/*!*/ self, object arg) {
             var str = Protocols.TryCastToString(stringTryCast, arg);
-            return (str != null) ? MutableString.Create(&quot;tag:yaml.org,2002:&quot;).Append(str) : arg;
+            return (str != null) ? MutableString.CreateMutable(str.Encoding).Append(&quot;tag:yaml.org,2002:&quot;).Append(str) : arg;
         }
 
         [RubyMethod(&quot;add_domain_type&quot;, RubyMethodAttributes.PublicSingleton)]
@@ -280,10 +302,14 @@ namespace IronRuby.StandardLibrary.Yaml {
             MutableString/*!*/ domainAndDate, MutableString/*!*/ typeName) {
             if (block == null) {
                 throw RubyExceptions.NoBlockGiven();
-            }                        
-            MutableString tag = MutableString.Create(&quot;tag:&quot;).
-                                Append(domainAndDate).Append(&quot;:&quot;).
-                                Append(typeName);
+            }
+
+            MutableString tag = MutableString.CreateMutable(typeName.Encoding).
+                Append(&quot;tag:&quot;).
+                Append(domainAndDate).
+                Append(&quot;:&quot;).
+                Append(typeName);
+
             RubyConstructor.AddExternalConstructor(tag.ConvertToString(), block);            
             return null;
         }
@@ -293,42 +319,44 @@ namespace IronRuby.StandardLibrary.Yaml {
             MutableString/*!*/ domainAndDate, RubyRegex/*!*/ typeRegex) {
             if (block == null) {
                 throw RubyExceptions.NoBlockGiven();
-            }                        
-            MutableString tag = MutableString.Create(&quot;tag:&quot;).
-                                Append(domainAndDate).Append(&quot;:&quot;).
-                                Append(typeRegex.GetPattern());
+            }
+
+            MutableString pattern = typeRegex.GetPattern();
+            MutableString tag = MutableString.CreateMutable(pattern.Encoding).
+                Append(&quot;tag:&quot;).
+                Append(domainAndDate).
+                Append(':').
+                Append(pattern);
+
             RubyConstructor.AddExternalMultiConstructor(tag.ConvertToString(), block);
             return null;
         }
 
-        private static RubyConstructor/*!*/ MakeConstructor(RubyGlobalScope/*!*/ scope, TextReader/*!*/ reader) {
-            return new RubyConstructor(scope, MakeComposer(reader));
+        private static RubyConstructor/*!*/ MakeConstructor(RubyGlobalScope/*!*/ scope, Stream/*!*/ stream) {
+            return new RubyConstructor(scope, MakeComposer(stream));
+        }
+
+        internal static Composer/*!*/ MakeComposer(Stream/*!*/ stream) {
+            return MakeComposer(new StreamReader(stream, Encoding.UTF8));
         }
 
         internal static Composer/*!*/ MakeComposer(TextReader/*!*/ reader) {
             return new Composer(new Parser(new Scanner(reader), YamlOptions.DefaultOptions.Version));
         }
 
-        private static TextReader CheckYamlPort(object port) {
-            // TODO: should do try-to_str conversion and create IOWrapper if not convertible to string
-
-            MutableString ms = port as MutableString;
-            if (ms != null) {
-                return new MutableStringReader(ms);
-            }
-
-            string str = port as string;
+        private static Stream/*!*/ CheckYamlPort(ConversionStorage&lt;MutableString&gt;/*!*/ toStr, RespondToStorage/*!*/ respondTo, object port) {
+            var toStrSite = toStr.GetSite(TryConvertToStrAction.Make(toStr.Context));
+            MutableString str = toStrSite.Target(toStrSite, port);
             if (str != null) {
-                return new StringReader(str);
+                return new MutableStringStream(str);
             }
 
-            RubyIO io = port as RubyIO;
-            if (io != null) {
-                RubyIOOps.Binmode(io);
-                return new RubyIOReader(io);
+            IOWrapper wrapper = RubyIOOps.CreateIOWrapper(respondTo, port, FileAccess.Read);
+            if (!wrapper.CanRead) {
+                throw RubyExceptions.CreateTypeError(&quot;instance of IO needed&quot;);
             }
 
-            throw RubyExceptions.CreateTypeError(&quot;instance of IO needed&quot;);
+            return wrapper;
         }
    
     }</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/RubyYaml.cs</filename>
    </modified>
    <modified>
      <diff>@@ -102,7 +102,7 @@ namespace IronRuby.StandardLibrary.Yaml {
 
             [RubyMethod(&quot;inspect&quot;)]
             public static MutableString/*!*/ Inspect(RubyContext/*!*/ context, YamlStream/*!*/ self) {
-                MutableString result = MutableString.CreateMutable(&quot;#&lt;YAML::Stream:&quot;);
+                MutableString result = MutableString.CreateMutable(&quot;#&lt;YAML::Stream:&quot;, RubyEncoding.Binary);
                 RubyUtils.AppendFormatHexObjectId(result, RubyUtils.GetObjectId(context, self))
                 .Append(&quot; @documents=&quot;)
                 .Append(context.Inspect(self._documents))</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/YamlStream.cs</filename>
    </modified>
    <modified>
      <diff>@@ -1,2 +1 @@
-fails:File::Stat#initialize raises an exception if the file doesn't exist
 fails:File::Stat#initialize creates a File::Stat object for the given file</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/file/stat/new_tags.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,2 @@
-fails:IO#eof? raises IOError on stream closed for reading by close_read
 fails:IO#eof? returns true on receiving side of Pipe when writing side is closed
 fails:IO#eof? returns false on receiving side of Pipe when writing side wrote some data</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/io/eof_tags.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1 @@
-fails:IO.for_fd returns a new IO object
-fails:IO.for_fd associates new IO with the old descriptor so each IO directly affects the other
-fails:IO.for_fd raises EBADF if the file descriptor given is not a valid and open one
-fails:IO.for_fd raises EINVAL if mode is not compatible with the descriptor's current mode
-fails:IO.for_fd raises IOError on closed stream
 fails:IO.for_fd emits a warning if given a block
-fails:IO.for_fd cannot open an IO with incompatible flags</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/io/for_fd_tags.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1 @@
-fails:IO.new returns a new IO object
-fails:IO.new associates new IO with the old descriptor so each IO directly affects the other
-fails:IO.new raises EBADF if the file descriptor given is not a valid and open one
-fails:IO.new raises EINVAL if mode is not compatible with the descriptor's current mode
-fails:IO.new raises IOError on closed stream
-fails:IO.new emits a warning if given a block
-fails:IO.new cannot open an IO with incompatible flags
+fails:IO.new emits a warning if given a block
\ No newline at end of file</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/io/new_tags.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1 @@
-fails:IO.open returns a new IO object
-fails:IO.open associates new IO with the old descriptor so each IO directly affects the other
-fails:IO.open raises EBADF if the file descriptor given is not a valid and open one
-fails:IO.open raises EINVAL if mode is not compatible with the descriptor's current mode
-fails:IO.open raises IOError on closed stream
-fails:IO.open emits a warning if given a block
-fails:IO.open cannot open an IO with incompatible flags
-fails:IO.open with a block invokes close on opened IO object when exiting the block
-fails:IO.open with a block propagates non-StandardErrors produced by close
+fails:IO.open emits a warning if given a block
\ No newline at end of file</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/io/open_tags.txt</filename>
    </modified>
    <modified>
      <diff>@@ -4,8 +4,3 @@ fails:IO.select returns nil after timeout if there are no objects ready for I/O
 fails:IO.select returns supplied objects when they are ready for I/O
 fails:IO.select returns supplied objects correctly even when monitoring the same object in different arrays
 fails:IO.select invokes to_io on supplied objects that are not IO
-fails:IO.select raises TypeError if supplied objects are not IO
-fails:IO.select raises TypeError if the specified timeout value is not Numeric
-fails:IO.select raises TypeError if the first three arguments are not Arrays
-fails:IO.select does not raise errors if the first three arguments are nil
-fails:IO.select does not accept negative timeouts</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/io/select_tags.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,2 @@
-fails:IO#sysseek on a file moves the read position relative to the current position with SEEK_CUR
 fails:IO#sysseek on a file raises an error when called after buffered reads
 fails:IO#sysseek on a file warns if called immediately after a buffered IO#write
-fails:IO#sysseek on a file moves the read position relative to the start with SEEK_SET
-fails:IO#sysseek on a file moves the read position relative to the end with SEEK_END
-fails:IO#sysseek on a file can handle any numerical argument without breaking and can seek past EOF
-fails:IO#sysseek on a file raises IOError on closed stream</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/io/sysseek_tags.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1 @@
-fails:IO#ungetc pushes back one character onto stream
-fails:IO#ungetc pushes back one character when invoked at the end of the stream
-fails:IO#ungetc pushes back one character when invoked at the start of the stream
-fails:IO#ungetc pushes back one character when invoked on empty stream
-fails:IO#ungetc affects EOF state
-fails:IO#ungetc adjusts the stream position
-fails:IO#ungetc makes subsequent unbuffered operations to raise IOError
 fails:IO#ungetc raises IOError when invoked on stream that was not yet read
-fails:IO#ungetc raises IOError on closed stream</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/io/ungetc_tags.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1 +1,2 @@
 fails:Time#_load loads a time object in the old UNIX timestamp based format
+fails:Time#_load loads local time</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/time/_load_tags.txt</filename>
    </modified>
    <modified>
      <diff>@@ -23,13 +23,10 @@ core\array\equal_value_tags.txt:0:critical:Array#== properly handles recursive a
 core\array\hash_tags.txt:0:critical:Array#hash properly handles recursive arrays
 core\array\hash_tags.txt:0:critical:Array#hash properly handles recursive arrays
 core\array\intersection_tags.txt:0:critical:Array#&amp; properly handles recursive arrays
-core\array\join_tags.txt:0:critical:Array#join raises a NoMethodError if an element does not respond to #to_s 
 core\array\join_tags.txt:0:critical:Array#join does not separates elements when the passed separator is nil
-core\array\multiply_tags.txt:0:critical:Array#* raises a NoMethodError if an element does not respond to #to_s
 core\array\union_tags.txt:0:critical:Array#| properly handles recursive arrays
 core\array\uniq_tags.txt:0:critical:Array#uniq properly handles recursive arrays
 core\array\uniq_tags.txt:0:critical:Array#uniq! properly handles recursive arrays
-core\kernel\sleep_tags.txt:3:critical:Kernel#sleep pauses execution indefinitely if not given a duration
 core\process\times_tags.txt:0:unstable:Process.times returns current cpu times
 core\string\process\wait_tags.txt:0:critical:Process.wait
 core\string\process\wait2_tags.txt:0:critical:Process.wait2
@@ -44,11 +41,23 @@ core\thread\critical_tags.txt:0:critical:Thread.critical= can be mismatched
 core\thread\raise_tags.txt:0:critical:Thread#raise on another thread re-raises active exception
 core\thread\critical_tags.txt:0:unstable:Thread.critical= does not change status of other existing threads
 language\method_tags.txt:0:critical:Calling a method fails with both lambda and block argument
+library\net\ftp\get_tags.txt:0:critical:Net::FTP#get (binary mode)
+library\net\ftp\getbinaryfile_tags.txt:0:critical:Net::FTP#getbinaryfile
+library\net\ftp\retrbinary_tags.txt:0:critical:Net::FTP#retrbinary
+library\net\http\http\get_print_tags.txt:0:critical:Net::HTTP.get_print when passed URI it prints the body of the specified uri to $stdout
+library\net\http\http\get_print_tags.txt:0:critical:Net::HTTP.get_print when passed host, path, port it prints the body of the specified uri to $stdout
+library\net\http\http\lock_tags.txt:0:critical:Net::HTTP#lock sends a LOCK request to the passed path and returns the response
+library\net\http\http\post_form_tags.txt:0:critical:Net::HTTP.post_form when passed URI POSTs the passed form data to the given uri
+library\net\http\http\post_tags.txt:0:critical:Net::HTTP#post
+library\net\http\http\propfind_tags.txt:0:critical:Net::HTTP#propfind
+library\net\http\http\proppatch_tags.txt:0:critical:Net::HTTP#proppatch
+library\net\http\http\put_tags.txt:0:critical:Net::HTTP#put
+library\net\http\http\request_tags.txt:0:critical:Net::HTTP#request
+library\net\http\http\send_request_tags.txt:0:critical:Net::HTTP#send_request
+library\net\http\http\unlock_tags.txt:0:critical:Net::HTTP#unlock
 library\resolv\get_address_tags.txt:0:critical:Resolv#getaddress
 library\resolv\get_addresses_tags.txt:0:critical:Resolv#getaddresses
 library\resolv\get_name_tags.txt:0:critical:Resolv#getname
 library\resolv\get_names_tags.txt:0:critical:Resolv#getnames
 library\scanf\io\block_scanf_tags.txt:0:critical:IO#block_scanf passes each match to the block as an array
 library\scanf\io\scanf_tags.txt:0:critical:IO#scanf with block passes each match to the block as an array
-library\socket\basicsocket\recv_tags.txt:0:critical:BasicSocket#recv receives a specified number of bytes of a message from another socket
-library\socket\basicsocket\recv_tags.txt:0:critical:BasicSocket#recv accepts flags to specify unusual receiving behaviour</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/critical_tags.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1 @@
-fails:StringIO#each_line when passed a separator returns self
-fails:StringIO#each_line when passed a separator yields each paragraph when passed an empty String as separator
-fails:StringIO#each_line when passed no arguments returns self
-fails:StringIO#each_line when self is not readable raises an IOError
+fails:StringIO#each_line when passed a separator yields each paragraph when passed an empty String as separator
\ No newline at end of file</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/stringio/each_line_tags.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1 @@
-fails:StringIO#each when passed a separator returns self
 fails:StringIO#each when passed a separator yields each paragraph when passed an empty String as separator
-fails:StringIO#each when passed no arguments returns self
-fails:StringIO#each when self is not readable raises an IOError</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/stringio/each_tags.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,15 +1,2 @@
-fails:StringIO.open when passed [Object, mode] uses the passed Object as the StringIO backend
-fails:StringIO.open when passed [Object, mode] even closes self when an exception is raised while yielding
 fails:StringIO.open when passed [Object, mode] sets self's string to nil after yielding
-fails:StringIO.open when passed [Object, mode] even sets self's string to nil when an exception is raised while yielding
-fails:StringIO.open when passed [Object, mode] sets the mode based on the passed mode
-fails:StringIO.open when passed [Object, mode] allows passing the mode as an Integer
-fails:StringIO.open when passed [Object, mode] raises a TypeError when passed a frozen String in truncate mode as StringIO backend
-fails:StringIO.open when passed [Object, mode] tries to convert the passed mode to a String using #to_str
-fails:StringIO.open when passed [Object, mode] raises an Errno::EACCES error when passed a frozen string with a write-mode
-fails:StringIO.open when passed [Object] uses the passed Object as the StringIO backend
-fails:StringIO.open when passed [Object] sets the mode to read-write
-fails:StringIO.open when passed [Object] tries to convert the passed Object to a String using #to_str
-fails:StringIO.open when passed [Object] automatically sets the mode to read-only when passed a frozen string
-fails:StringIO.open when passed no arguments sets the mode to read-write
-fails:StringIO.open when passed no arguments uses an empty String as the StringIO backend
+fails:StringIO.open when passed [Object, mode] even sets self's string to nil when an exception is raised while yielding
\ No newline at end of file</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/stringio/open_tags.txt</filename>
    </modified>
    <modified>
      <diff>@@ -32,7 +32,7 @@ class ComplainMatcher
     if @complaint.nil?
       [&quot;Expected a warning&quot;, &quot;but received none&quot;]
     elsif @complaint.kind_of? Regexp
-      [&quot;Expected warning to match:&quot;, @complaint.inspect]
+      [&quot;Expected warning to match: #{@complaint.inspect}&quot;, &quot;but got: #{@stderr.chomp.inspect}&quot;]
     else
       [&quot;Expected warning: #{@complaint.inspect}&quot;, &quot;but got: #{@stderr.chomp.inspect}&quot;]
     end
@@ -42,7 +42,7 @@ class ComplainMatcher
     if @complaint.nil?
       [&quot;Unexpected warning: &quot;, @stderr.chomp.inspect]
     elsif @complaint.kind_of? Regexp
-      [&quot;Expected warning not to match:&quot;, @complaint.inspect]
+      [&quot;Expected warning not to match: #{@complaint.inspect}&quot;, &quot;but got: #{@stderr.chomp.inspect}&quot;]
     else
       [&quot;Expected warning: #{@complaint.inspect}&quot;, &quot;but got: #{@stderr.chomp.inspect}&quot;]
     end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/mspec/lib/mspec/matchers/complain.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,10 @@ require File.dirname(__FILE__) + '/../spec_helper'
 
 describe &quot;The -e command line option&quot; do
   it &quot;evaluates the given string&quot; do
-    ruby_exe(&quot;puts 'foo'&quot;).chomp.should == &quot;foo&quot;
+    [%Q{-e &quot;puts 'hello'&quot;},
+     %Q{-e&quot;puts 'hello'&quot;}].each do |cmd|
+      ruby_exe(nil, :args =&gt; cmd).chomp.should == &quot;hello&quot;
+    end
   end
 
   it &quot;joins multiple strings with newlines&quot; do</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/command_line/dash_e_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,9 @@ require File.dirname(__FILE__) + '/../spec_helper'
 
 describe &quot;The -r command line option&quot; do
   it &quot;requires the specified file&quot; do
-    ruby_exe(&quot;fixtures/require.rb&quot;, :options =&gt; &quot;-r fixtures/test_file&quot;, :dir =&gt; File.dirname(__FILE__)).chomp.should include(&quot;fixtures/test_file.rb&quot;)
+    [&quot;-r fixtures/test_file&quot;,
+     &quot;-rfixtures/test_file&quot;].each do |o|
+      ruby_exe(&quot;fixtures/require.rb&quot;, :options =&gt; o, :dir =&gt; File.dirname(__FILE__)).chomp.should include(&quot;fixtures/test_file.rb&quot;)
+    end
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/command_line/dash_r_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,12 +2,40 @@ require File.dirname(__FILE__) + '/../spec_helper'
 
 describe &quot;The -I command line option&quot; do
   it &quot;adds the path to the load path ($:)&quot; do
-    ruby_exe(&quot;fixtures/loadpath.rb&quot;, :options =&gt; '-I fixtures', :dir =&gt; File.dirname(__FILE__)).should include(&quot;fixtures&quot;)
+    ruby_exe(&quot;fixtures/loadpath.rb&quot;, :options =&gt; '-I fixtures', :dir =&gt; File.dirname(__FILE__)).should =~ /^fixtures$/
   end
   
   it &quot;allows different formats&quot; do
-    ['-I fixtures', '-Ifixtures', '-I&quot;fixtures&quot;', '-I./fixtures', '-I.\fixtures'].each do |format|
-      ruby_exe(&quot;fixtures/loadpath.rb&quot;, :options =&gt; format, :dir =&gt; File.dirname(__FILE__)).should include(&quot;fixtures&quot;)
+    [['-I fixtures',  'fixtures'],
+     ['-Ifixtures',   'fixtures'],
+     ['-I&quot;fixtures&quot;', 'fixtures'],
+     ['-I./fixtures', './fixtures'],
+     ['-I.\fixtures', '.\fixtures']].each do |command_line, resulting_path|
+      ruby_exe(&quot;fixtures/loadpath.rb&quot;, :options =&gt; command_line, :dir =&gt; File.dirname(__FILE__)).should =~ /^#{Regexp.escape(resulting_path)}$/
     end
   end
+
+  it &quot;allows quoted paths with spaces&quot; do
+    ruby_exe(&quot;fixtures/loadpath.rb&quot;, :options =&gt; '-I&quot;foo bar&quot;', :dir =&gt; File.dirname(__FILE__)).should =~ /^foo bar$/
+  end
+
+  it &quot;concatenates adjacent quoted strings&quot; do
+    ruby_exe(&quot;fixtures/loadpath.rb&quot;, :options =&gt; '-Ifoo&quot;bar&quot;baz', :dir =&gt; File.dirname(__FILE__)).should =~ /^foobarbaz$/
+  end
+
+  it &quot;allows multiple paths separated with ;&quot; do
+    ruby_exe(&quot;fixtures/loadpath.rb&quot;, :options =&gt; '-Ifoo;bar', :dir =&gt; File.dirname(__FILE__)).should =~ /^bar$/
+  end
+
+  it &quot;treats ; as a separator even within a quoted string&quot; do
+    ruby_exe(&quot;fixtures/loadpath.rb&quot;, :options =&gt; '-I&quot;foo ; bar&quot;', :dir =&gt; File.dirname(__FILE__)).should =~ /^foo $/
+  end
+
+  it &quot;concatenates adjacent quoted strings, but separates at ;&quot; do
+    ruby_exe(&quot;fixtures/loadpath.rb&quot;, :options =&gt; '-Ifoo&quot;bar;baz&quot;', :dir =&gt; File.dirname(__FILE__)).should =~ /^foobar$/
+  end
+
+  it &quot;allows non-existent paths&quot; do
+    ruby_exe(&quot;fixtures/loadpath.rb&quot;, :options =&gt; '-Inon-existent', :dir =&gt; File.dirname(__FILE__)).should =~ /^non-existent$/
+  end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/command_line/dash_upper_i_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -29,7 +29,7 @@ describe &quot;Array#rindex&quot; do
 
   it &quot;does not fail when removing elements from block&quot; do
     sentinel = mock('sentinel')
-    ary = [0, 0, 1, 1, 3, 2, 1, sentinel, 4]
+    ary = [0, 0, 1, 1, 3, 2, 1, sentinel]
 
     sentinel.instance_variable_set(:@ary, ary)
     def sentinel.==(o) @ary.slice!(1..-1); false; end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/array/rindex_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -64,7 +64,7 @@ describe &quot;Dir.chdir&quot; do
     end
   end
 
-  it &quot;always returns to the original directory when given a block&quot; do
+  it &quot;always returns to the original directory when given a block (raise)&quot; do
     begin
       Dir.chdir(DirSpecs.mock_dir) do
         raise StandardError, &quot;something bad happened&quot;
@@ -74,4 +74,12 @@ describe &quot;Dir.chdir&quot; do
 
     Dir.pwd.should == @original
   end
+  
+  it &quot;always returns to the original directory when given a block ()&quot; do
+    Dir.chdir(DirSpecs.mock_dir) do
+      break
+    end
+
+    Dir.pwd.should == @original
+  end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/dir/chdir_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,6 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 require File.dirname(__FILE__) + '/fixtures/common'
 require File.dirname(__FILE__) + '/shared/pwd'
 
-describe &quot;Dir.pwd&quot; do
+describe &quot;Dir.getwd&quot; do
   it_behaves_like :dir_pwd, :getwd
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/dir/getwd_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,4 +12,15 @@ describe :dir_pwd, :shared =&gt; true do
       File.stat(Dir.send(@method)).ino.should == File.stat(File.expand_path(`cd`.chomp)).ino
     end
   end
+
+  platform_is :windows do
+    it &quot;can return short and long file names, with mixed case&quot; do
+      name = tmp(&quot;a path/with spaces&quot;)
+      short_name = tmp(&quot;a pAtH/WiThSp~1&quot;)
+      FileUtils.mkdir_p(name) if not File.directory?(name)
+      Dir.chdir(short_name) do
+        Dir.send(@method).should == short_name
+      end
+    end
+  end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/dir/shared/pwd.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,8 +2,11 @@ module EnvSpecs
   def self.with_temp_ENV()
     orig = ENV.to_hash
     comspec = ENV['COMSPEC']
+    sysroot = ENV['SYSTEMROOT']
     begin
       ENV.clear
+      # Probably a CLR bug - the child process blows up while loading ir.exe assembly if SYSTEMROOT is not set:
+      ENV['SYSTEMROOT'] = sysroot
       yield
     ensure
       ENV.replace orig</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/env/fixtures/classes.rb</filename>
    </modified>
    <modified>
      <diff>@@ -30,15 +30,17 @@ describe &quot;File.new&quot; do
     File.exists?(@file).should be_true
   end
 
-  it &quot;return a new File with modus num and permissions&quot; do
-    File.delete(@file)
-    File.umask(0011)
-    @fh = File.new(@file, @flags, 0755)
-    @fh.class.should == File
-    File.stat(@file).mode.to_s(8).should == &quot;100744&quot;
-    File.exists?(@file).should be_true
+  platform_is_not :windows do
+    it &quot;return a new File with modus num and permissions&quot; do
+      File.delete(@file)
+      File.umask(0011)
+      @fh = File.new(@file, @flags, 0755)
+      @fh.class.should == File
+      File.stat(@file).mode.to_s(8).should == &quot;100744&quot;
+      File.exists?(@file).should be_true
+    end
   end
-
+  
   it &quot;creates the file and returns writable descriptor when called with 'w' mode and r-o permissions&quot; do
     # it should be possible to write to such a file via returned descriptior,
     # even though the file permissions are r-r-r.
@@ -54,21 +56,23 @@ describe &quot;File.new&quot; do
     File.read(@file).should == &quot;test\n&quot;
   end
 
-  it &quot;opens the existing file, does not change permissions even when they are specified&quot; do
-    File.chmod(0664, @file)           # r-w perms
-    orig_perms = File.stat(@file).mode.to_s(8)
-    begin
-      f = File.new(@file, &quot;w&quot;, 0444)    # r-o perms, but they should be ignored
-      f.puts(&quot;test&quot;)
-    ensure
-      f.close
+  platform_is_not :windows do
+    it &quot;opens the existing file, does not change permissions even when they are specified&quot; do
+      File.chmod(0664, @file)           # r-w perms
+      orig_perms = File.stat(@file).mode.to_s(8)
+      begin
+        f = File.new(@file, &quot;w&quot;, 0444)    # r-o perms, but they should be ignored
+        f.puts(&quot;test&quot;)
+      ensure
+        f.close
+      end
+      File.stat(@file).mode.to_s(8).should == orig_perms
+
+      # it should be still possible to read from the file
+      File.read(@file).should == &quot;test\n&quot;
     end
-    File.stat(@file).mode.to_s(8).should == orig_perms
-
-    # it should be still possible to read from the file
-    File.read(@file).should == &quot;test\n&quot;
   end
-
+  
   it &quot;return a new File with modus fd &quot; do
     begin
       @fh_orig = File.new(@file)
@@ -128,7 +132,7 @@ describe &quot;File.new&quot; do
   it &quot;coerces filename using to_str&quot; do
     name = mock(&quot;file&quot;)
     name.should_receive(:to_str).and_return(@file)
-    File.new(name, &quot;w&quot;) { }
+    @fh = File.new(name, &quot;w&quot;)
     File.exists?(@file).should be_true
   end
 
@@ -140,9 +144,11 @@ describe &quot;File.new&quot; do
     lambda { File.new(@file, File::CREAT, 0755, 'test') }.should raise_error(ArgumentError)
   end
 
-  # You can't alter mode or permissions when opening a file descriptor
-  it &quot;can't alter mode or permissions when opening a file&quot; do
-    @fh = File.new(@file)
-    lambda { File.new(@fh.fileno, @flags) }.should raise_error(Errno::EINVAL)
+  platform_is_not :windows do
+    # You can't alter mode or permissions when opening a file descriptor
+    it &quot;can't alter mode or permissions when opening a file&quot; do
+      @fh = File.new(@file)
+      lambda { File.new(@fh.fileno, @flags) }.should raise_error(Errno::EINVAL)
+    end
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/new_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,9 +10,17 @@ describe &quot;File::Stat#blksize&quot; do
     File.delete(@file) if File.exist?(@file)
   end
   
-  it &quot;should be able to determine the blksize on a File::Stat object&quot; do
-    st = File.stat(@file)
-    st.blksize.is_a?(Integer).should == true
-    st.blksize.should &gt; 0
+  platform_is_not :windows do
+    it &quot;should be able to determine the blksize on a File::Stat object&quot; do
+      st = File.stat(@file)
+      st.blksize.is_a?(Integer).should == true
+      st.blksize.should &gt; 0
+    end
+  end
+
+  platform_is :windows do
+    it &quot;returns nil&quot; do
+      File.stat(@file).blksize.should be_nil
+    end
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/blksize_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,9 +10,17 @@ describe &quot;File::Stat#blocks&quot; do
     File.delete(@file) if File.exist?(@file)
   end
   
-  it &quot;should be able to determine the blocks on a File::Stat object&quot; do
-    st = File.stat(@file)
-    st.blocks.is_a?(Integer).should == true
-    st.blocks.should &gt; 0
+  platform_is_not :windows do
+    it &quot;should be able to determine the blocks on a File::Stat object&quot; do
+      st = File.stat(@file)
+      st.blocks.is_a?(Integer).should == true
+      st.blocks.should &gt; 0
+    end
+  end
+
+  platform_is :windows do
+    it &quot;returns nil&quot; do
+      File.stat(@file).blocks.should be_nil
+    end
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/blocks_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,38 +4,45 @@ describe &quot;File::Stat#&lt;=&gt;&quot; do
   before :each do
     @name1 = tmp(&quot;i_exist&quot;)
     @name2 = tmp(&quot;i_exist_too&quot;)
-    @file1 = File.new @name1, &quot;w&quot;
-    @file2 = File.new @name2, &quot;w&quot;
+    File.open(@name1, &quot;w&quot;) {}
+    File.open(@name2, &quot;w&quot;) {}
+    @stat1 = File.stat(@name1)
+    @stat2 = File.stat(@name2)
   end
 
   after :each do
-    @file1.close unless @file1.closed?
-    @file2.close unless @file2.closed?
     File.delete @name1
     File.delete @name2
   end
 
   it &quot;is able to compare files by the same modification times&quot; do
-    (@file1.stat &lt;=&gt; @file2.stat).should == 0
+    res = false
+    10.times do
+      File.open(@name1, &quot;w&quot;) {}
+      File.open(@name2, &quot;w&quot;) {}
+      res ||= ((File.stat(@name1) &lt;=&gt; File.stat(@name2)) == 0)
+      break if res
+    end
+    res.should be_true
   end
 
   it &quot;is able to compare files by different modification times&quot; do
     File.utime(Time.now, Time.now + 100, @name2)
-    (@file1.stat &lt;=&gt; @file2.stat).should == -1
+    (File.stat(@name1) &lt;=&gt; File.stat(@name2)).should == -1
 
     File.utime(Time.now, Time.now - 100, @name2)
-    (@file1.stat &lt;=&gt; @file2.stat).should == 1
+    (File.stat(@name1) &lt;=&gt; File.stat(@name2)).should == 1
   end
 
   it &quot;should also include Comparable and thus == shows mtime equality between two File::Stat objects&quot; do
-    (@file1.stat == @file2.stat).should == true
-    (@file1.stat == @file1.stat).should == true
-    (@file2.stat == @file2.stat).should == true
+    (@stat1 == @stat2).should == true
+    (@stat1 == @stat1).should == true
+    (@stat2 == @stat2).should == true
 
     File.utime(Time.now, Time.now + 100, @name2)
 
-    (@file1.stat == @file2.stat).should == false
-    (@file1.stat == @file1.stat).should == true
-    (@file2.stat == @file2.stat).should == true
+    (File.stat(@name1) == File.stat(@name2)).should == false
+    (File.stat(@name1) == File.stat(@name1)).should == true
+    (File.stat(@name2) == File.stat(@name2)).should == true
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/comparison_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,15 @@
 require File.dirname(__FILE__) + '/../../../spec_helper'
 
 describe &quot;File::Stat#dev_major&quot; do
-  it &quot;returns the major part of File::Stat#dev&quot; do
-    File.stat('/dev/null').dev_major.should be_kind_of(Integer)
+  platform_is_not :windows do
+    it &quot;returns the major part of File::Stat#dev&quot; do
+      File.stat(FileStatSpecs.null_device).dev_major.should be_kind_of(Integer)
+    end
+  end
+
+  platform_is :windows do
+    it &quot;returns the number of the device on which the file exists&quot; do
+      File.stat(FileStatSpecs.null_device).dev_major.should be_nil
+    end
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/dev_major_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,15 @@
 require File.dirname(__FILE__) + '/../../../spec_helper'
 
 describe &quot;File::Stat#dev_minor&quot; do
-  it &quot;returns the minor part of File::Stat#dev&quot; do
-    File.stat('/dev/null').dev_minor.should be_kind_of(Integer)
+  platform_is_not :windows do
+    it &quot;returns the minor part of File::Stat#dev&quot; do
+      File.stat(FileStatSpecs.null_device).dev_minor.should be_kind_of(Integer)
+    end
+  end
+  
+  platform_is :windows do
+    it &quot;returns the number of the device on which the file exists&quot; do
+      File.stat(FileStatSpecs.null_device).dev_major.should be_nil
+    end
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/dev_minor_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,8 @@
 require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes'
 
 describe 'File::Stat#dev' do
   it &quot;returns the number of the device on which the file exists&quot; do
-    File.stat('/dev/null').dev.should be_kind_of(Integer)
+    File.stat(FileStatSpecs.null_device).dev.should be_kind_of(Integer)
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/dev_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,3 +3,14 @@ class FileStat
     File.lstat(file).send(meth)
   end
 end
+
+module FileStatSpecs
+  def self.null_device
+    platform_is_not :windows do
+      return '/dev/null'
+    end
+    platform_is :windows do
+      return 'nul'
+    end
+  end
+end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/fixtures/classes.rb</filename>
    </modified>
    <modified>
      <diff>@@ -20,13 +20,15 @@ describe &quot;File::Stat#ftype&quot; do
     end
   end
 
-  it &quot;returns 'characterSpecial' when the file is a char&quot;  do
-    FileSpecs.character_device do |char|
-      File.lstat(char).ftype.should == 'characterSpecial'
+  platform_is_not :windows do
+    it &quot;returns 'characterSpecial' when the file is a char&quot;  do
+      FileSpecs.character_device do |char|
+        File.lstat(char).ftype.should == 'characterSpecial'
+      end
     end
   end
 
-  platform_is_not :freebsd do  # FreeBSD does not have block devices
+  platform_is_not :freebsd, :windows do  # FreeBSD does not have block devices
     it &quot;returns 'blockSpecial' when the file is a block&quot; do
       FileSpecs.block_device do |block|
         File.lstat(block).ftype.should == 'blockSpecial'
@@ -34,15 +36,19 @@ describe &quot;File::Stat#ftype&quot; do
     end
   end
 
-  it &quot;returns 'link' when the file is a link&quot; do
-    FileSpecs.symlink do |link|
-      File.lstat(link).ftype.should == 'link'
+  platform_is_not :windows do
+    it &quot;returns 'link' when the file is a link&quot; do
+      FileSpecs.symlink do |link|
+        File.lstat(link).ftype.should == 'link'
+      end
     end
   end
 
-  it &quot;returns fifo when the file is a fifo&quot; do
-    FileSpecs.fifo do |fifo|
-      File.lstat(fifo).ftype.should == 'fifo'
+  platform_is_not :windows do
+    it &quot;returns fifo when the file is a fifo&quot; do
+      FileSpecs.fifo do |fifo|
+        File.lstat(fifo).ftype.should == 'fifo'
+      end
     end
   end
 
@@ -50,9 +56,11 @@ describe &quot;File::Stat#ftype&quot; do
   # can be found. However, if you are running X, there is
   # a good chance that if nothing else, at least the X
   # Server socket exists.
-  it &quot;returns 'socket' when the file is a socket&quot; do
-    FileSpecs.socket do |socket|
-      File.lstat(socket).ftype.should == 'socket'
+  platform_is_not :windows do
+    it &quot;returns 'socket' when the file is a socket&quot; do
+      FileSpecs.socket do |socket|
+        File.lstat(socket).ftype.should == 'socket'
+     end
     end
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/ftype_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,9 +10,20 @@ describe &quot;File::Stat#ino&quot; do
     File.delete(@file) if File.exist?(@file)
   end
   
-  it &quot;should be able to determine the ino on a File::Stat object&quot; do
+  it &quot;returns an Integer&quot; do
     st = File.stat(@file)
     st.ino.is_a?(Integer).should == true
-    st.ino.should &gt; 0
+  end
+  
+  platform_is_not :windows do
+    it &quot;should be able to determine the ino on a File::Stat object&quot; do
+      File.stat(@file).ino.should &gt; 0
+    end
+  end
+
+  platform_is :windows do
+    it &quot;should be able to determine the ino on a File::Stat object&quot; do
+      File.stat(@file).ino.should == 0
+    end
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/ino_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,9 +13,22 @@ describe &quot;File::Stat#inspect&quot; do
   
   it &quot;produces a nicely formatted description of a File::Stat object&quot; do
     st = File.stat(@file)  
-    #p &quot;#&lt;File::Stat dev=0x#{st.dev.to_s(16)}, ino=#{st.ino}, mode=#{sprintf(&quot;%06s&quot;, st.mode.to_s(8))}, nlink=#{st.nlink}, uid=#{st.uid}, gid=#{st.gid}, rdev=0x#{st.rdev.to_s(16)}, size=#{st.size}, blksize=#{st.blksize}, blocks=#{st.blocks}, atime=#{st.atime}, mtime=#{st.mtime}, ctime=#{st.ctime}&gt;&quot;
-    st.inspect.should == &quot;#&lt;File::Stat dev=0x#{st.dev.to_s(16)}, ino=#{st.ino}, mode=#{sprintf(&quot;%07d&quot;, st.mode.to_s(8).to_i)}, nlink=#{st.nlink}, uid=#{st.uid}, gid=#{st.gid}, rdev=0x#{st.rdev.to_s(16)}, size=#{st.size}, blksize=#{st.blksize}, blocks=#{st.blocks}, atime=#{st.atime}, mtime=#{st.mtime}, ctime=#{st.ctime}&gt;&quot;
-    
+    st.inspect.should =~ /
+      \#&lt;File::Stat \s
+      dev=0x#{st.dev.to_s(16)}, \s
+      ino=#{st.ino}, \s
+      mode=#{sprintf(&quot;%07d&quot;, st.mode.to_s(8).to_i)}, \s
+      nlink=#{st.nlink}, \s
+      uid=#{st.uid}, \s
+      gid=#{st.gid}, \s
+      rdev=0x#{st.rdev.to_s(16)}, \s
+      size=#{st.size}, \s
+      blksize=(#{st.blksize}|nil), \s
+      blocks=(#{st.blocks}|nil), \s
+      atime=#{Regexp.escape(st.atime.to_s)}, \s
+      mtime=#{Regexp.escape(st.mtime.to_s)}, \s
+      ctime=#{Regexp.escape(st.ctime.to_s)}&gt;
+      /x
   end
 
 </diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/inspect_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,6 +14,11 @@ describe &quot;File::Stat#mode&quot; do
   it &quot;should be able to determine the mode through a File::Stat object&quot; do
     st = File.stat(@file)
     st.mode.is_a?(Integer).should == true
-    st.mode.should == 33261
+    platform_is_not :windows do
+      st.mode.should == 33261
+    end
+    platform_is :windows do
+      st.mode.should == 33188
+    end
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/mode_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,10 +12,12 @@ describe &quot;File::Stat#nlink&quot; do
     File.delete(@link) rescue nil
   end
 
-  it &quot;returns the number of links to a file&quot; do
-    File::Stat.new(@file).nlink.should == 1
-    File.link(@file, @link)
-    File::Stat.new(@file).nlink.should == 2
-    File.delete(@link)
+  platform_is_not :windows do
+    it &quot;returns the number of links to a file&quot; do
+      File::Stat.new(@file).nlink.should == 1
+      File.link(@file, @link)
+      File::Stat.new(@file).nlink.should == 2
+      File.delete(@link)
+    end
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/nlink_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,16 @@
 require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes'
 
 describe &quot;File::Stat#rdev_major&quot; do
-  it &quot;returns the major part of File::Stat#rdev&quot; do
-    File.stat('/dev/null').rdev_major.should be_kind_of(Integer)
+  platform_is_not :windows do
+    it &quot;returns the major part of File::Stat#rdev&quot; do
+      File.stat(FileStatSpecs.null_device).rdev_major.should be_kind_of(Integer)
+    end
+  end
+
+  platform_is :windows do
+    it &quot;returns nil&quot; do
+      File.stat(FileStatSpecs.null_device).rdev_major.should be_nil
+    end
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/rdev_major_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,16 @@
 require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes'
 
 describe &quot;File::Stat#rdev_minor&quot; do
-  it &quot;returns the minor part of File::Stat#rdev&quot; do
-    File.stat('/dev/null').rdev_minor.should be_kind_of(Integer)
+  platform_is_not :windows do
+    it &quot;returns the minor part of File::Stat#rdev&quot; do
+      File.stat(FileStatSpecs.null_device).rdev_minor.should be_kind_of(Integer)
+    end
+  end
+
+  platform_is :windows do
+    it &quot;returns nil&quot; do
+      File.stat(FileStatSpecs.null_device).rdev_major.should be_nil
+    end
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/rdev_minor_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,8 @@
 require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes'
 
 describe 'File::Stat#rdev' do
   it &quot;returns the number of the device this file represents which the file exists&quot; do
-    File.stat('/dev/null').rdev.should be_kind_of(Integer)
+    File.stat(FileStatSpecs.null_device).rdev.should be_kind_of(Integer)
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/stat/rdev_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,12 +3,10 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 describe &quot;File.truncate&quot; do
   before :each do
     @name = &quot;test.txt&quot;
-    @file  = File.open(@name, 'w')
     File.open(@name,&quot;w&quot;) { |f| f.write(&quot;1234567890&quot;) }
   end
 
   after :each do
-    @file.close
     File.delete(@name) if File.exist?(@name)
     @name = nil
   end
@@ -170,6 +168,7 @@ describe &quot;File#truncate&quot; do
   it &quot;raises an IOError if file is not opened for writing&quot; do
     file = File.new(@name, 'r')
     lambda { file.truncate(42) }.should raise_error(IOError)
+    file.close
   end
 
   it &quot;raises a TypeError if not passed an Integer type for the for the argument&quot; do</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/file/truncate_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,15 @@ require 'fileutils'
 describe &quot;IO#close_read&quot; do
 
   before :each do
-    @io = IO.popen 'cat', &quot;r+&quot;
+    # TODO: rewrite the specs so that they don't depend on platform specific utilities
+    platform_is :windows do
+      @io = IO.popen 'dir', &quot;r+&quot;
+    end
+    
+    platform_is_not :windows do
+      @io = IO.popen 'cat', &quot;r+&quot;
+    end
+    
     @path = tmp('io.close.txt')
   end
 </diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/io/close_read_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -43,35 +43,37 @@ describe &quot;IO#close&quot; do
 end
 
 describe &quot;IO#close on an IO.popen stream&quot; do
+  
+  # TODO: rewrite the specs so thay don't depend on platform specific utilities (&quot;yes&quot;, &quot;true&quot;)
+  platform_is_not :windows do
+    it &quot;clears #pid&quot; do
+      io = IO.popen 'yes', 'r'
 
-  it &quot;clears #pid&quot; do
-    io = IO.popen 'yes', 'r'
+      io.pid.should_not == 0
 
-    io.pid.should_not == 0
+      io.close
 
-    io.close
+      lambda { io.pid }.should raise_error(IOError)
+    end
 
-    lambda { io.pid }.should raise_error(IOError)
-  end
-
-  it &quot;sets $?&quot; do
-    io = IO.popen 'true', 'r'
-    io.close
+    it &quot;sets $?&quot; do
+      io = IO.popen 'true', 'r'
+      io.close
 
-    $?.exitstatus.should == 0
+      $?.exitstatus.should == 0
 
-    io = IO.popen 'false', 'r'
-    io.close
+      io = IO.popen 'false', 'r'
+      io.close
 
-    $?.exitstatus.should == 1
-  end
+      $?.exitstatus.should == 1
+    end
 
-  it &quot;waits for the child to exit&quot; do
-    io = IO.popen 'yes', 'r'
-    io.close
+    it &quot;waits for the child to exit&quot; do
+      io = IO.popen 'yes', 'r'
+      io.close
 
-    $?.exitstatus.should_not == 0 # SIGPIPE/EPIPE
+      $?.exitstatus.should_not == 0 # SIGPIPE/EPIPE
+    end
   end
-
 end
 </diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/io/close_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,15 @@ require File.dirname(__FILE__) + '/fixtures/classes'
 describe &quot;IO#close_write&quot; do
 
   before :each do
-    @io = IO.popen 'cat', 'r+'
+    # TODO: rewrite the specs so thay don't depend on platform specific utilities (&quot;yes&quot;, &quot;true&quot;)
+    platform_is :windows do
+      @io = IO.popen 'more', &quot;r+&quot;
+    end
+    
+    platform_is_not :windows do
+      @io = IO.popen 'cat', &quot;r+&quot;
+    end
+    
     @path = tmp('io.close.txt')
   end
 
@@ -50,12 +58,24 @@ describe &quot;IO#close_write&quot; do
     File.unlink @path
   end
 
-  it &quot;flushes and closes the write stream&quot; do
-    @io.puts '12345'
+  platform_is :windows do
+    it &quot;flushes and closes the write stream&quot; do
+      @io.puts '12345'
 
-    @io.close_write
+      @io.close_write
+
+      @io.read.should == &quot;12345\n\n&quot;
+    end
+  end
+  
+  platform_is_not :windows do
+    it &quot;flushes and closes the write stream&quot; do
+      @io.puts '12345'
 
-    @io.read.should == &quot;12345\n&quot;
+      @io.close_write
+
+      @io.read.should == &quot;12345\n&quot;
+    end
   end
 
   it &quot;raises IOError on closed stream&quot; do</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/io/close_write_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -166,14 +166,16 @@ describe &quot;IO#gets&quot; do
     lambda { IOSpecs.closed_file.gets }.should raise_error(IOError)
   end
 
-  it &quot;fails on cloned opened streams&quot; do
+  it &quot;fails on cloned write-only cloned streams&quot; do
     f = File.open(tmp(&quot;gets_specs&quot;), &quot;w&quot;)
-    f.puts(&quot;heh&quot;)
-    g = IO.new(f.fileno)
-    f.fileno.should == g.fileno
-    lambda { g.gets }.should raise_error(IOError)
-    g.close
-    File.unlink(tmp(&quot;gets_specs&quot;))
+    begin
+      f.puts(&quot;heh&quot;)
+      g = IO.new(f.fileno)
+      lambda { g.gets }.should raise_error(Errno::EBADF)
+    ensure
+      f.close
+      File.unlink(tmp(&quot;gets_specs&quot;))
+    end  
   end
 
   it &quot;accepts a separator&quot; do</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/io/gets_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,7 @@
 require File.dirname(__FILE__) + '/../../spec_helper'
 
 describe &quot;IO::popen&quot; do
+  # TODO: rewrite to not depend on platform specific utilities
   # NOTE: cause Errno::EBADF on 1.8.6
   #ruby_bug &quot;#&quot;, &quot;1.8.6&quot; do
     it &quot;reads from a read-only pipe&quot; do
@@ -41,16 +42,34 @@ describe &quot;IO::popen&quot; do
       end
     end
 
-    it &quot;allows the io to be closed inside the block&quot; do
-      io = IO.popen('yes', 'r') do |io|
-        io.close
+    platform_is :windows do
+      it &quot;allows the io to be closed inside the block&quot; do
+      
+        io = IO.popen('dir', 'r') do |io|
+          io.close
 
-        io.closed?.should == true
+          io.closed?.should == true
+
+          io
+        end
 
-        io
+        io.closed?.should == true
       end
+    end
+    
+    platform_is_not :windows do
+      it &quot;allows the io to be closed inside the block&quot; do
+      
+        io = IO.popen('ls', 'r') do |io|
+          io.close
 
-      io.closed?.should == true
+          io.closed?.should == true
+
+          io
+        end
+
+        io.closed?.should == true
+      end
     end
   #end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/io/popen_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -75,7 +75,7 @@ describe &quot;IO#reopen&quot; do
     @file1.reopen(@file2)
     @file1.pos.should == pos
 
-    # MRI behavior: after reopen the buffers are not corrected,
+    # MRI bug: after reopen the buffers are not corrected,
     # so we need the following line, or next gets wourd return nil.
     @file1.pos = pos
 
@@ -111,6 +111,11 @@ describe &quot;IO#reopen&quot; do
     @file1.reopen(@file2)
     @file1.gets
     @file1.gets
-    @file1.reopen(@file2).gets.should == &quot;Line 1: One\n&quot;
+    
+    # MRI bug: after reopen the buffers are not corrected,
+    # so we need the following line, or next gets wourd return nil.
+    @file1.pos = @file1.pos
+    
+    @file1.reopen(@file2).gets.should == &quot;Line 3: Three\n&quot;
   end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/io/reopen_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -68,9 +68,18 @@ describe :io_new, :shared =&gt; true do
     lambda { IO.send(@method, fd, 'w') }.should raise_error(Errno::EBADF)
   end
 
-  it &quot;raises EINVAL if mode is not compatible with the descriptor's current mode&quot; do
-    lambda { IO.send(@method, @file.fileno, 'r') }.should raise_error(Errno::EINVAL)
-    lambda { io = IO.send(@method, @file.fileno, 'w'); io.close }.should_not raise_error
+  platform_is :windows do
+    it &quot;doesn't raise EINVAL even if mode is not compatible with the descriptor's current mode&quot; do
+      lambda { IO.send(@method, @file.fileno, 'r') }.should_not raise_error
+      lambda { io = IO.send(@method, @file.fileno, 'w'); io.close }.should_not raise_error
+    end
+  end
+  
+  platform_is_not :windows do
+    it &quot;doesn't raise EINVAL even if mode is not compatible with the descriptor's current mode&quot; do
+      lambda { IO.send(@method, @file.fileno, 'r') }.should_not raise_error
+     lambda { io = IO.send(@method, @file.fileno, 'w'); io.close }.should_not raise_error
+    end
   end
 
   it &quot;raises IOError on closed stream&quot; do
@@ -106,7 +115,9 @@ describe :io_new, :shared =&gt; true do
     io.close
   end
 
+  platform_is_not :windows do
     it &quot;cannot open an IO with incompatible flags&quot; do
       lambda { IO.new(@file.fileno, &quot;r&quot;) }.should raise_error
     end
+  end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/io/shared/new.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,9 +2,16 @@ require File.dirname(__FILE__) + '/../fixtures/classes'
 
 describe :io_tty, :shared =&gt; true do
   with_tty do
-    # Yeah, this will probably break.
-    it &quot;returns true if this stream is a terminal device (TTY)&quot; do
-      File.open('/dev/tty') {|f| f.send @method }.should == true
+    platform_is_not :windows do
+      it &quot;returns true if this stream is a terminal device (TTY)&quot; do
+        File.open('/dev/tty') {|f| f.send @method }.should == true
+      end
+    end
+    
+    platform_is :windows do
+      it &quot;returns true if this stream is a terminal device (TTY)&quot; do
+        File.open('NUL') {|f| f.send @method }.should == true
+      end
     end
   end
 </diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/io/shared/tty.rb</filename>
    </modified>
    <modified>
      <diff>@@ -37,7 +37,7 @@ describe &quot;IO#syswrite on a file&quot; do
   end
 
   it &quot;does not warn if called after IO#write with intervening IO#sysread&quot; do
-    @file.syswrite(&quot;abcde&quot;)
+    @file.write(&quot;abcde&quot;)
     @file.sysread(5)
     lambda { @file.syswrite(&quot;fghij&quot;) }.should_not complain
   end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/io/syswrite_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,7 +6,7 @@ describe &quot;IO#write_nonblock on a file&quot; do
   before :each do
     @filename = tmp(&quot;IO_syswrite_file&quot;) + $$.to_s
     File.open(@filename, &quot;w&quot;) do |file|
-      file.write_nonblock(&quot;012345678901234567890123456789&quot;)
+      file.write(&quot;012345678901234567890123456789&quot;)
     end
     @file = File.open(@filename, &quot;r+&quot;)
     @readonly_file = File.open(@filename)
@@ -18,22 +18,32 @@ describe &quot;IO#write_nonblock on a file&quot; do
     File.delete(@filename)
   end
 
-  it &quot;writes all of the string's bytes but does not buffer them&quot; do
-    written = @file.write_nonblock(&quot;abcde&quot;)
-    written.should == 5
-    File.open(@filename) do |file|
-      file.sysread(10).should == &quot;abcde56789&quot;
-      file.seek(0)
-      @file.fsync
-      file.sysread(10).should == &quot;abcde56789&quot;
+  platform_is_not :windows do
+    it &quot;writes all of the string's bytes but does not buffer them&quot; do
+      written = @file.write_nonblock(&quot;abcde&quot;)
+      written.should == 5
+      File.open(@filename) do |file|
+        file.sysread(10).should == &quot;abcde56789&quot;
+        file.seek(0)
+        @file.fsync
+        file.sysread(10).should == &quot;abcde56789&quot;
+      end
     end
-  end
 
-  it &quot;checks if the file is writable if writing zero bytes&quot; do
-    lambda { @readonly_file.write_nonblock(&quot;&quot;) }.should raise_error
+    it &quot;checks if the file is writable if writing zero bytes&quot; do
+      lambda { @readonly_file.write_nonblock(&quot;&quot;) }.should raise_error
+    end
+  end
+  
+  platform_is :windows do
+    it &quot;raises Errno::EBADF&quot; do
+      lambda { @file.write_nonblock(&quot;abcde&quot;) }.should raise_error(Errno::EBADF)
+    end
   end
 end
 
 describe &quot;IO#write_nonblock&quot; do
-  it_behaves_like :io_write, :write_nonblock
+  platform_is_not :windows do
+    it_behaves_like :io_write, :write_nonblock
+  end
 end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/io/write_nonblock_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,3 +8,21 @@ module HMACConstants
   BlankSHA1HexDigest = &quot;da39a3ee5e6b4b0d3255bfef95601890afd80709&quot;
   SHA1Hexdigest      = &quot;9e12d3e11f9eb26ee409fa3a044aa2d8afb8f3b4&quot;
 end
+
+module X509Constants 
+  X509CERT           = &quot;-----BEGIN CERTIFICATE-----\nMIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy\nYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu\nZXQwHhcNMDcxMjIxMDIwNDE0WhcNMDgxMjIwMDIwNDE0WjBBMRAwDgYDVQQDDAdk\ncmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ\nFgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbbgLrGLGIDE76\nLV/cvxdEzCuYuS3oG9PrSZnuDweySUfdp/so0cDq+j8bqy6OzZSw07gdjwFMSd6J\nU5ddZCVywn5nnAQ+Ui7jMW54CYt5/H6f2US6U0hQOjJR6cpfiymgxGdfyTiVcvTm\nGj/okWrQl0NjYOYBpDi+9PPmaH2RmLJu0dB/NylsDnW5j6yN1BEI8MfJRR+HRKZY\nmUtgzBwF1V4KIZQ8EuL6I/nHVu07i6IkrpAgxpXUfdJQJi0oZAqXurAV3yTxkFwd\ng62YrrW26mDe+pZBzR6bpLE+PmXCzz7UxUq3AE0gPHbiMXie3EFE0oxnsU3lIduh\nsCANiQ8BAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW\nBBS5k4Z75VSpdM0AclG2UvzFA/VW5DANBgkqhkiG9w0BAQUFAAOCAQEAHagT4lfX\nkP/hDaiwGct7XPuVGbrOsKRVD59FF5kETBxEc9UQ1clKWngf8JoVuEoKD774dW19\nbU0GOVWO+J6FMmT/Cp7nuFJ79egMf/gy4gfUfQMuvfcr6DvZUPIs9P/TlK59iMYF\nDIOQ3DxdF3rMzztNUCizN4taVscEsjCcgW6WkUJnGdqlu3OHWpQxZBJkBTjPCoc6\nUW6on70SFPmAy/5Cq0OJNGEWBfgD9q7rrs/X8GGwUWqXb85RXnUVi/P8Up75E0ag\n14jEc90kN+C7oI/AGCBN0j6JnEtYIEJZibjjDJTSMWlUKKkj30kq7hlUC2CepJ4v\nx52qPcexcYZR7w==\n-----END CERTIFICATE-----\n&quot;
+  X509Subject        = &quot;/CN=drbrain/DC=segment7/DC=net&quot;
+  X509Issuer         = &quot;/CN=drbrain/DC=segment7/DC=net&quot;
+  X509NotBefore      = &quot;Fri Dec 21 02:04:14 UTC 2007&quot;
+  X509NotAfter       = &quot;Sat Dec 20 02:04:14 UTC 2008&quot;
+  X509Serial	     = 0
+  X509Version        = 2
+  X509Signature      = &quot;sha1WithRSAEncryption&quot;
+  X509PublicKey      = &quot;-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAm24C6xixiAxO+i1f3L8XRMwrmLkt6BvT60mZ7g8HsklH3af7KNHA\n6vo/G6sujs2UsNO4HY8BTEneiVOXXWQlcsJ+Z5wEPlIu4zFueAmLefx+n9lEulNI\nUDoyUenKX4spoMRnX8k4lXL05ho/6JFq0JdDY2DmAaQ4vvTz5mh9kZiybtHQfzcp\nbA51uY+sjdQRCPDHyUUfh0SmWJlLYMwcBdVeCiGUPBLi+iP5x1btO4uiJK6QIMaV\n1H3SUCYtKGQKl7qwFd8k8ZBcHYOtmK61tupg3vqWQc0em6SxPj5lws8+1MVKtwBN\nIDx24jF4ntxBRNKMZ7FN5SHbobAgDYkPAQIDAQAB\n-----END RSA PUBLIC KEY-----\n&quot;
+end
+
+module PrivateKeyConstants
+  RSAKey             = &quot;-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAm24C6xixiAxO+i1f3L8XRMwrmLkt6BvT60mZ7g8HsklH3af7\nKNHA6vo/G6sujs2UsNO4HY8BTEneiVOXXWQlcsJ+Z5wEPlIu4zFueAmLefx+n9lE\nulNIUDoyUenKX4spoMRnX8k4lXL05ho/6JFq0JdDY2DmAaQ4vvTz5mh9kZiybtHQ\nfzcpbA51uY+sjdQRCPDHyUUfh0SmWJlLYMwcBdVeCiGUPBLi+iP5x1btO4uiJK6Q\nIMaV1H3SUCYtKGQKl7qwFd8k8ZBcHYOtmK61tupg3vqWQc0em6SxPj5lws8+1MVK\ntwBNIDx24jF4ntxBRNKMZ7FN5SHbobAgDYkPAQIDAQABAoIBAGQilgK8X/PUajVH\nclEXU3hhSV0VQHwfIYKeYms6h6zXBVPKW0dLC0zXeDztJgueasMZQ67XaPCrTpGO\npx/l2zJ6F1HM8/bqn4aDXDY9f/xRLYryQRMBgL8fHzgitNylHWaT4j2Vt7yg2SI9\nmxrMRNKqASJPVR+Nm3l6+n9gpjVb99wEucWplPPHI6KhXLYPZOqSwt+zaH5roz3k\nUQmMs0Bs4hF1SzVl0n+KNoXHOwswVrmBWXgWvm2OhnwY2e26jfejc8toJc/ShAJ7\nC9exnrdimcgEKbd22Sum4G00CDYhcrG5LHHqkgwifcAEVctrvBZBZHGgpxlO8a8U\neF2Vr7kCgYEAykdrBlzp7Fn9xzUInBQ3NXTTYAq51lpuJdmHQmPuTSY0buoHkd9f\nxbUCZ2qR9QAesrx4hI0qGLetc8IOKDoWx2rPepCCvO3Kx61o1SB5fAvBue03qVoq\nHqACX3Uk24Em8zAz9xuP13ETH/wU7sUbUxRHMCre6ZDmlxn4g5l+Nl8CgYEAxLVl\n22yBx0dfRr3UsHY9rxll2gIlnfnYfiJzq8wetzt/TfztRV5ILz7FyWqL5d7IoqkA\nfT2V4HAasRJASnKohwJe7z5M/H2ExwkGNFvY+jefb2CoUl5WouK9AlhbqBk3zmHi\nsY5GqQkAp/kHMntEin+sErJw6mkgAGdser3a9p8CgYEAqi31w++tunRnxw4+RRnY\n7Pdx0k6T1NxV6TAe1ONAHNY0rM/mOHqml65W7GzDiU1lhlh8SIB/VzZJDqfHw15D\nxdh94A7uf0bMILwrA4wDyTIW9Xa3Kpq57vQNqwPiU25QN69pOM+Ob+IpBfLOJafc\n+kOINOUMj5Kh/aQS6Zzci58CgYEAk24dlFKEBjbRCvU2FrfYTYcsljPru7ZJc2gg\n588J6m0WYf5CWy5pzbcviGFpzvSlzXv7GOLylQ+QgcxbETFUbDPzsT4xd0AgJwj1\ndIKuYgMUZOa94VZBer2TydEtiRS1heJJhKhM/1329u4nXceTvHYqIq1JAfeee48I\neAoZtaMCgYBz1FjWFQnMTD5nmyPEEZneoBPAR5+9jwOps+IYOoHtazoMFszzd0qo\nJZW3Ihn9KRrVSxfFApKS/ZwjiZ+tJUk7DE/v/0l0sszefY7s8b0pL1lpeZSoL71e\nQoG1WLXUiDV3BRlmyOAF1h3p12KRTLgwubN51ajECwcs3QwE+ZT8Gg==\n-----END RSA PRIVATE KEY-----\n&quot;
+  RSABlank           = &quot;-----BEGIN RSA PUBLIC KEY-----\nMAA=\n-----END RSA PUBLIC KEY-----\n&quot;
+  RSA2048            = &quot;-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEA39VVfbyLJXGj8LXo91N3lkin8s228giuNhQtTv/mDqAOuRbP\n/T/z4PPCJXJrisftY1WV5TxBBQaR3D1SgW+KdZHYOiCjLxp0gHBODvw+1DsNb7Ma\n1KsmMOue5DyT7MC0faVAD47MEYCj3bT1wesHHasy0Q5noArVKNtayFfN09as6OOu\nFy3MEg/2cQ08njQenjWUnHwwKhyTtpKm7W4zrWxOyeVyt/R3y1phP/xizJckEV4k\nzt/Gh7fVpBT4MIMlt5L5xwVeqtwORarRgT2vHRBR05TMOT4NCeo/1vaUrTnovyHy\nVv5NYh486BHjvFyctxOP7D9elS9kX58KD5/G6wIDAQABAoIBAQDBIe5WQ608bcWr\nGQse/OIexipEEsRcKqlG+DnwBFWZIPoTMl/cgKYJ38oRTZ0FbmSiZWKlHUxs7bJF\nepQKIxgxQdp0rVygdA86E60GuRftP9bkHoJ0JgkaBPRgsvRgQBZ8o22W/vuNzpWV\n42J6JDVLoECEqg03xqEOU9cNLtXmhaPZ+TuRPXPauwi5ZyL5SzSqRwlqMM2UA0TU\nVw3/MMxEY5nXbreOZW5tnATpbcTzCt4FiTd58Ul/hwqMNgZNSKSpvbm2a+RyDnGV\nKQeY1iopyYr7oV8RuP4IXFlYwKaeQVxjVat/Z/adh5XyTDAaPbQVOHLLZidPaq4l\nj3ue6a/hAoGBAPkByy89IAVHY4IkGVjIeIwJYRm+HqXBMRFwCsI3sKN0XEQ/rxlk\nECCxST1S0C0gine5Q3voRBHReEdwYRSNEA8ugDgeqC0aSz5rjDZIhtmPnb7CufRP\nh3idI6S8miX2WzOrTCvAs70/FGh4Qj/tJ/5kLDxlNswN9wzh3W7NtLWFAoGBAOYe\njqDic5iBaWICT19Z4PUxj3zoyS2+sjWyRujUGIZd0tMGCSeYwQ+mZZZGb313+GMK\nAW4Wkv+M+f3FmbFj90V2P2oe1ztjiOsSJ1AnP+brNvnTia/ca9jZ0IDlHO3Ewl+o\nD9+Egtpt6DkKA3SgMAtqFIHG/QsIgX45aEo6qz2vAoGAHbc+FTQZNygO0wAV2keK\nQ0P3R4gtxiApB+i0D/tvZAJF5IspDUGovw4JLH1OhKQmgiUkzYupW+sAjJ33p+kx\nqm4lNQ1Lip5hrmBNSkkbdqkx7Qr2ABbhlt5B2636Q1+EAMWHgI0tpf76I4F+fnyB\n0lUIBmkZwf5Epk/qCggYcbUCgYEAnLZcnXX6EPa4pLU8Box35aMdu4vwTYXbaTQC\nlFa0aPUGOQ2YOG4PtC+2aPOIw6Jq9k9/D9CxxPTl3ouuEh8o6xYPM57TJq+vM58G\nRNCl9QVkSBhmYOw0SdZz5wOggtAHKwuR278rOcO1bPrDxa29aliQpJy2AMiHH0XL\nHxn7OiMCgYEAnHuH/1ngxSCeCtdJbRS0A3jgGC/LOyEMgN+3xBO71lXKAuo51Mi7\ndg8OxxMJPFeMtxljVWHr7xjofvvl+xW9sYXuIybRd6QayylQGTsjIH2dAGbadxpT\nGki9fX8PoZ2hW8jUcGaVljU+zM1ljJDmZHK5Jo5fXzGkxPK2dm8ngG4=\n-----END RSA PRIVATE KEY-----\n&quot;
+end</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/library/openssl/shared/constants.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,8 @@
 describe :file_directory, :shared =&gt; true do
   before :each do
     platform_is :windows do
-      @dir  = &quot;C:\\&quot;
-      @file = &quot;C:\\winnt\\notepad.exe&quot;
+      @dir  = &quot;#{ENV['SystemDrive']}\\&quot;
+      @file = &quot;#{ENV['SystemRoot']}\\notepad.exe&quot;
     end
 
     platform_is_not :windows do</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/shared/file/directory.rb</filename>
    </modified>
    <modified>
      <diff>@@ -22,10 +22,10 @@ describe :file_executable_real, :shared =&gt; true do
       @object.send(@method, @file1).should == true
       @object.send(@method, @file2).should == false
     end
-  end
 
-  it &quot;returns true if named file is readable by the real user id of the process, otherwise false&quot; do
-    @object.send(@method, @file1).should == true
+    it &quot;returns true if named file is readable by the real user id of the process, otherwise false&quot; do
+      @object.send(@method, @file1).should == true
+    end
   end
 
   it &quot;raises an ArgumentError if not passed one argument&quot; do</diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/shared/file/executable_real.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,9 +7,11 @@ describe :file_readable, :shared =&gt; true do
     File.delete(@file) if File.exists?(@file)
   end
 
-  it &quot;returns true if named file is readable by the effective user id of the process, otherwise false&quot; do
-    @object.send(@method, '/etc/passwd').should == true
-    File.open(@file,'w') { @object.send(@method, @file).should == true }
+  platform_is_not :windows do
+    it &quot;returns true if named file is readable by the effective user id of the process, otherwise false&quot; do
+      @object.send(@method, '/etc/passwd').should == true
+      File.open(@file,'w') { @object.send(@method, @file).should == true }
+    end
   end
 end
 </diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/shared/file/readable.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,9 +7,11 @@ describe :file_writable, :shared =&gt; true do
     File.delete(@file) if File.exists?(@file)
   end
 
-  it &quot;returns true if named file is writable by the effective user id of the process, otherwise false&quot; do
-    @object.send(@method, '/etc/passwd').should == false
-    File.open(@file,'w') { @object.send(@method, @file).should == true }
+  platform_is_not :windows do
+    it &quot;returns true if named file is writable by the effective user id of the process, otherwise false&quot; do
+      @object.send(@method, '/etc/passwd').should == false
+      File.open(@file,'w') { @object.send(@method, @file).should == true }
+    end
   end
 end
 </diff>
      <filename>Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/shared/file/writable.rb</filename>
    </modified>
    <modified>
      <diff>@@ -51,6 +51,9 @@ using System.Security;
 // You can specify all the values or you can default the Revision and Build Numbers 
 // by using the '*' as shown below:
 [assembly: SecurityTransparent]
+#if CLR4
+[assembly: SecurityRules(SecurityRuleSet.Level1)]
+#endif
 
 [assembly: System.Resources.NeutralResourcesLanguage(&quot;en-US&quot;)]
 </diff>
      <filename>Merlin/Main/Debugging/Microsoft.Scripting.Debugging/AssemblyInfo.cs</filename>
    </modified>
    <modified>
      <diff></diff>
      <filename>Merlin/Main/Debugging/Microsoft.Scripting.Debugging/Microsoft.Scripting.Debugging.Build.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Library&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Debugging/Microsoft.Scripting.Debugging/Microsoft.Scripting.Debugging.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;9.0.30729&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{78345AFF-EDEB-4951-B5DC-4AD97FF0C649}&lt;/ProjectGuid&gt;
     &lt;ProjectTypeGuids&gt;{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}&lt;/ProjectTypeGuids&gt;</diff>
      <filename>Merlin/Main/Hosts/IronRuby.Rack/IronRuby.Rack.Example/IronRuby.Rack.Example.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;9.0.30729&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{25A6FCEF-1DB4-4ECF-98B4-7975E5AF9CC6}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Library&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Hosts/IronRuby.Rack/IronRuby.Rack.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{7D07B0CE-FFA3-4402-BFF2-5F42B4267D2A}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Exe&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Hosts/SilverLight/Chiron/Chiron.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{C86A7A7B-3086-4136-9B56-17E8DCB38C8D}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Library&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/Microsoft.Scripting.Silverlight.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{155CE436-1669-4A48-8095-410F2430237F}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Library&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython.Modules/IronPython.Modules.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -779,9 +779,7 @@ namespace IronPython.Modules {
             int ri;
             if (r != null) {
                 ri = Converter.ConvertToInt32(r);
-                if (ri &gt; data.Count) {
-                    throw PythonOps.ValueError(&quot;r cannot be bigger than the iterable&quot;);
-                } else if (ri &lt; 0) {
+                if (ri &lt; 0) {
                     throw PythonOps.ValueError(&quot;r cannot be negative&quot;);
                 }
             } else {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython.Modules/IterTools.cs</filename>
    </modified>
    <modified>
      <diff>@@ -55,9 +55,6 @@ using System.Security;
 [assembly: AllowPartiallyTrustedCallers]
 #endif
 
-
-// hack in order to pass AssemblyInfoTask 
-// AssemblyVersion attribute has been decorated in AssemblyVersion.cs
-#if FALSE
-[assembly: AssemblyVersion(&quot;2.0.0.00&quot;)]
+#if CLR4
+[assembly: SecurityRules(SecurityRuleSet.Level1)]
 #endif</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython.Modules/Properties/AssemblyInfo.cs</filename>
    </modified>
    <modified>
      <diff>@@ -52,79 +52,113 @@ namespace IronPython.Modules {
 
             private Stream _readStream;
             private Stream _writeStream;
-            private bool _closed;
+            private bool _closed, _closefd;
             private string _mode;
             private WeakRefTracker _tracker;
             private PythonContext _context;
 
+            public _FileIO(CodeContext/*!*/ context, int fd, [DefaultParameterValue(&quot;r&quot;)]string mode, [DefaultParameterValue(true)]bool closefd) {
+                if (fd &lt; 0) {
+                    throw PythonOps.ValueError(&quot;fd must be &gt;= 0&quot;);
+                }
+
+                PythonContext pc = PythonContext.GetContext(context);
+                _FileIO file = (_FileIO)pc.FileManager.GetObjectFromId(pc, fd);
+                Console.WriteLine(file);
+
+                _context = pc;
+                switch (mode) {
+                    case &quot;r&quot;: _mode = &quot;rb&quot;; break;
+                    case &quot;w&quot;: _mode = &quot;wb&quot;; break;
+                    case &quot;a&quot;: _mode = &quot;w&quot;; break;
+                    case &quot;r+&quot;:
+                    case &quot;+r&quot;: _mode = &quot;rb+&quot;; break;
+                    case &quot;w+&quot;:
+                    case &quot;+w&quot;: _mode = &quot;rb+&quot;; break;
+                    case &quot;a+&quot;:
+                    case &quot;+a&quot;: _mode = &quot;r+&quot;; break;
+                    default:
+                        BadMode(mode);
+                        break;
+                }
+                _readStream = file._readStream;
+                _writeStream = file._writeStream;
+                _closefd = closefd;
+            }
+            
             public _FileIO(CodeContext/*!*/ context, string name, [DefaultParameterValue(&quot;r&quot;)]string mode, [DefaultParameterValue(true)]bool closefd) {
                 if (!closefd) {
                     throw PythonOps.ValueError(&quot;Cannot use closefd=False with file name&quot;);
                 }
-                
+                _closefd = true;
                 PlatformAdaptationLayer pal = PythonContext.GetContext(context).DomainManager.Platform;
 
                 switch (mode) {
                     case &quot;r&quot;:
-                        _readStream = _writeStream = OpenFile(pal, name, FileMode.Open, FileAccess.Read, FileShare.None);
-                        _mode = &quot;r&quot;;
+                        _readStream = _writeStream = OpenFile(context, pal, name, FileMode.Open, FileAccess.Read, FileShare.None);
+                        _mode = &quot;rb&quot;;
                         break;
                     case &quot;w&quot;:
-                        _readStream = _writeStream = OpenFile(pal, name, FileMode.Create, FileAccess.Write, FileShare.None);
-                        _mode = &quot;w&quot;;
+                        _readStream = _writeStream = OpenFile(context, pal, name, FileMode.Create, FileAccess.Write, FileShare.None);
+                        _mode = &quot;wb&quot;;
                         break;
                     case &quot;a&quot;:
-                        _readStream = _writeStream = OpenFile(pal, name, FileMode.Append, FileAccess.Write, FileShare.None);
+                        _readStream = _writeStream = OpenFile(context, pal, name, FileMode.Append, FileAccess.Write, FileShare.None);
                         _mode = &quot;w&quot;;
                         break;
                     case &quot;r+&quot;:
                     case &quot;+r&quot;:
-                        _readStream = _writeStream = OpenFile(pal, name, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
-                        _mode = &quot;r+&quot;;
+                        _readStream = _writeStream = OpenFile(context, pal, name, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
+                        _mode = &quot;rb+&quot;;
                         break;
                     case &quot;w+&quot;:
                     case &quot;+w&quot;:
-                        _readStream = _writeStream = OpenFile(pal, name, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
-                        _mode = &quot;r+&quot;;
+                        _readStream = _writeStream = OpenFile(context, pal, name, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
+                        _mode = &quot;rb+&quot;;
                         break;
                     case &quot;a+&quot;:
                     case &quot;+a&quot;:
-                        _readStream = OpenFile(pal, name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
-                        _writeStream = OpenFile(pal, name, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
+                        _readStream = OpenFile(context, pal, name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
+                        _writeStream = OpenFile(context, pal, name, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                         _mode = &quot;r+&quot;;
                         break;
                     default:
-                        bool foundMode = false, foundPlus = false;
-                        foreach (char c in mode) {
-                            switch (c) {
-                                case 'r':
-                                case 'w':
-                                case 'a':
-                                    if (foundMode) {
-                                        throw PythonOps.ValueError(&quot;Must have exactly one of read/write/append mode&quot;);
-                                    } else {
-                                        foundMode = true;
-                                        continue;
-                                    }
-                                case '+':
-                                    if (foundPlus) {
-                                        throw PythonOps.ValueError(&quot;Must have exactly one of read/write/append mode&quot;);
-                                    } else {
-                                        foundPlus = true;
-                                        continue;
-                                    }
-                                default:
-                                    throw PythonOps.ValueError(&quot;invalid mode: {0}&quot;, mode);
-                            }
-                        }
-
-                        throw PythonOps.ValueError(&quot;Must have exactly one of read/write/append mode&quot;);
+                        BadMode(mode);
+                        break;
                 }
 
                 _closed = false;
                 _context = PythonContext.GetContext(context);
             }
 
+            private static void BadMode(string mode) {
+                bool foundMode = false, foundPlus = false;
+                foreach (char c in mode) {
+                    switch (c) {
+                        case 'r':
+                        case 'w':
+                        case 'a':
+                            if (foundMode) {
+                                throw PythonOps.ValueError(&quot;Must have exactly one of read/write/append mode&quot;);
+                            } else {
+                                foundMode = true;
+                                continue;
+                            }
+                        case '+':
+                            if (foundPlus) {
+                                throw PythonOps.ValueError(&quot;Must have exactly one of read/write/append mode&quot;);
+                            } else {
+                                foundPlus = true;
+                                continue;
+                            }
+                        default:
+                            throw PythonOps.ValueError(&quot;invalid mode: {0}&quot;, mode);
+                    }
+                }
+
+                throw PythonOps.ValueError(&quot;Must have exactly one of read/write/append mode&quot;);
+            }
+
             #endregion
 
             #region Public API
@@ -159,6 +193,12 @@ namespace IronPython.Modules {
                     _writeStream.Close();
                     _writeStream.Dispose();
                 }
+
+
+                PythonFileManager myManager = _context.RawFileManager;
+                if (myManager != null) {
+                    myManager.Remove(this);
+                }
             }
 
             [Documentation(&quot;True if the file is closed&quot;)]
@@ -168,6 +208,12 @@ namespace IronPython.Modules {
                 }
             }
 
+            public bool closefd {
+                get {
+                    return _closefd;
+                }
+            }
+
             [Documentation(&quot;fileno() -&gt; int. \&quot;file descriptor\&quot;.\n\n&quot;
                 + &quot;This is needed for lower-level file interfaces, such as the fcntl module.&quot;
                 )]
@@ -386,11 +432,6 @@ namespace IronPython.Modules {
 
             void IDisposable.Dispose() {
                 close();
-
-                PythonFileManager myManager = _context.RawFileManager;
-                if (myManager != null) {
-                    myManager.Remove(this);
-                }
             }
 
             #endregion
@@ -414,12 +455,15 @@ namespace IronPython.Modules {
 
             #region Private implementation details
 
-            private static Stream OpenFile(PlatformAdaptationLayer pal, string name, FileMode fileMode, FileAccess fileAccess, FileShare fileShare) {
-                if (pal.DirectoryExists(name)) {
-                    // TODO: properly set errno
-                    throw PythonOps.IOError(&quot;[Errno 13] Permission denied&quot;);
+            private static Stream OpenFile(CodeContext context, PlatformAdaptationLayer pal, string name, FileMode fileMode, FileAccess fileAccess, FileShare fileShare) {
+                try {
+                    return pal.OpenInputFileStream(name, fileMode, fileAccess, fileShare);
+                } catch (UnauthorizedAccessException e) {
+                    throw PythonFile.ToIoException(context, name, e);
+                } catch (IOException e) {
+                    PythonFile.AddFilename(context, name, e);
+                    throw e;
                 }
-                return pal.OpenInputFileStream(name, fileMode, fileAccess, fileShare);
             }
             
             private void EnsureOpen() {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython.Modules/_fileio.cs</filename>
    </modified>
    <modified>
      <diff>@@ -30,6 +30,7 @@ using IronPython.Runtime;
 using IronPython.Runtime.Exceptions;
 using IronPython.Runtime.Operations;
 using IronPython.Runtime.Types;
+using IronPython.Runtime.Binding;
 
 [assembly: PythonModule(&quot;_struct&quot;, typeof(IronPython.Modules.PythonStruct))]
 namespace IronPython.Modules {
@@ -168,12 +169,12 @@ namespace IronPython.Modules {
                             break;
                         case FormatType.UnsignedInt:
                             for (int j = 0; j &lt; curFormat.Count; j++) {
-                                WriteUInt(res, _isLittleEndian, GetUIntValue(context, _isStandardized, curObj++, values));
+                                WriteUInt(res, _isLittleEndian, GetULongValue(context, _isStandardized, curObj++, values, &quot;unsigned int&quot;));
                             }
                             break;
                         case FormatType.UnsignedLong:
                             for (int j = 0; j &lt; curFormat.Count; j++) {
-                                WriteUInt(res, _isLittleEndian, GetULongValue(context, _isStandardized, curObj++, values));
+                                WriteUInt(res, _isLittleEndian, GetULongValue(context, _isStandardized, curObj++, values, &quot;unsigned long&quot;));
                             }
                             break;
                         case FormatType.Pointer:
@@ -962,19 +963,52 @@ namespace IronPython.Modules {
             return 0;
         }
 
-        internal static uint GetULongValue(CodeContext/*!*/ context, bool isStandardized, int index, object[] args) {
+        internal static uint GetULongValue(CodeContext/*!*/ context, bool isStandardized, int index, object[] args, string type) {
             object val = GetValue(context, index, args);
             uint res;
-            if (Converter.TryConvertToUInt32(val, out res)) {
-                return res;
+            if (val is int) {
+                res = (uint)(int)val;
+                WarnRange(context, (int)val, isStandardized, type);
+            } else if (val is BigInteger) {
+                res = (uint)(((BigInteger)val) &amp; 0xffffffff);
+                WarnRange(context, (BigInteger)val, isStandardized, type);                
+            } else if (val is Extensible&lt;int&gt;) {
+                res = (uint)((Extensible&lt;int&gt;)val).Value;
+                WarnRange(context, ((Extensible&lt;int&gt;)val).Value, isStandardized, type);
+            } else if (val is Extensible&lt;BigInteger&gt;) {
+                res = (uint)(((Extensible&lt;BigInteger&gt;)val).Value &amp; 0xffffffff);
+                BigInteger bi = ((Extensible&lt;BigInteger&gt;)val).Value;
+                WarnRange(context, bi, isStandardized, type);                
+            } else {
+                PythonOps.Warn(context, PythonExceptions.DeprecationWarning, &quot;struct integer overflow masking is deprecated&quot;);
+                
+                object maskedValue = PythonContext.GetContext(context).Operation(PythonOperationKind.BitwiseAnd, val, (BigInteger)4294967295);
+                if (!Converter.TryConvertToUInt32(maskedValue, out res)) {
+                    throw PythonOps.OverflowError(&quot;can't convert to &quot; + type);
+                }
+            }
+
+            return res;
+        }
+
+        private static void WarnRange(CodeContext context, int val, bool isStandardized, string type) {
+            if (val &lt; 0) {
+                WarnRange(context, isStandardized, type);
             }
+        }
 
+        private static void WarnRange(CodeContext context, BigInteger bi, bool isStandardized, string type) {
+            if (bi &lt; 0 || bi &gt; 4294967295) {
+                WarnRange(context, isStandardized, type);
+            }
+        }
+
+        private static void WarnRange(CodeContext context, bool isStandardized, string type) {
             if (isStandardized) {
-                throw Error(context, &quot;expected unsigned long value&quot;);
+                throw Error(context, &quot;expected &quot; + type + &quot; value&quot;);
             }
 
-            PythonOps.Warn(context, PythonExceptions.DeprecationWarning, &quot;'L' format requires 0 &lt;= number &lt;= 4294967295&quot;);
-            return (uint)0;
+            PythonOps.Warn(context, PythonExceptions.DeprecationWarning, (type == &quot;unsigned long&quot; ? &quot;'L'&quot; : &quot;'I'&quot;) + &quot; format requires 0 &lt;= number &lt;= 4294967295&quot;);
         }
 
         internal static IntPtr GetPointer(CodeContext/*!*/ context, int index, object[] args) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython.Modules/_struct.cs</filename>
    </modified>
    <modified>
      <diff>@@ -274,7 +274,7 @@ namespace IronPython.Modules {
             public void fromunicode(CodeContext/*!*/ context, string s) {
                 if (s == null) throw PythonOps.TypeError(&quot;expected string&quot;);
                 if (s.Length == 0) throw PythonOps.ValueError(&quot;empty string&quot;);
-                if ((s.Length % itemsize) != 0) throw PythonOps.ValueError(&quot;string length not a multiple of itemsize&quot;);
+                if (_typeCode != 'u' &amp;&amp; (s.Length % itemsize) != 0) throw PythonOps.ValueError(&quot;string length not a multiple of itemsize&quot;);
                 MemoryStream ms = new MemoryStream(PythonContext.GetContext(context).DefaultEncoding.GetBytes(s));
 
                 FromStream(ms);
@@ -305,8 +305,8 @@ namespace IronPython.Modules {
                         case 'x': // pad byte
                         case 's': // null-terminated string
                         case 'p': // Pascal string
-                        case 'u': // unicode char
                             return 1;
+                        case 'u': // unicode char
                         case 'h': // signed short
                         case 'H': // unsigned short
                             return 2;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython.Modules/array.cs</filename>
    </modified>
    <modified>
      <diff>@@ -803,7 +803,26 @@ namespace IronPython.Modules {
                 }
 
                 if (needMark) Write(context, Opcode.Mark);
-                foreach (object o in t) Save(context, o);
+                foreach (object o in t) {
+                    Save(context, o);
+                }
+
+                if (_memo.Contains(PythonOps.Id(obj))) {
+                    // recursive tuple
+                    if (_protocol == 1) {
+                        Write(context, Opcode.PopMark);
+                    } else {
+                        if (_protocol == 0) {
+                            Write(context, Opcode.Pop);
+                        }
+                        for (int i = 0; i &lt; t.__len__(); i++) {
+                            Write(context, Opcode.Pop);
+                        }
+                    }
+                    WriteGet(context, obj);
+                    return;
+                }
+
                 Write(context, opcode);
 
                 if (t.__len__() &gt; 0) {
@@ -836,10 +855,7 @@ namespace IronPython.Modules {
             /// &lt;/summary&gt;
             private void WriteFloatAsString(CodeContext/*!*/ context, object value) {                
                 Debug.Assert(DynamicHelpers.GetPythonType(value).Equals(TypeCache.Double));
-                // 17 digits of precision are necessary for accurate roundtripping
-                StringFormatter sf = new StringFormatter(context, &quot;%.17g&quot;, value);
-                sf._TrailingZeroAfterWholeFloat = true;
-                Write(context, sf.Format());
+                Write(context, DoubleOps.__repr__(context, (double)value));
                 Write(context, Newline);
             }
 
@@ -1173,12 +1189,13 @@ namespace IronPython.Modules {
                     msgBuilder.Append(&quot;: &quot;);
                     msgBuilder.Append(String.Format(format, args));
                 }
-                return PythonExceptions.CreateThrowable(PicklingError(context), msgBuilder.ToString());
+                return PythonExceptions.CreateThrowable(PickleError(context), msgBuilder.ToString());
             }
 
             private void Memoize(object obj) {
-                Debug.Assert(!_memo.Contains(PythonOps.Id(obj)));
-                _memo[PythonOps.Id(obj)] = PythonTuple.MakeTuple(_memo.Count, obj);
+                if (!_memo.Contains(PythonOps.Id(obj))) {
+                    _memo[PythonOps.Id(obj)] = PythonTuple.MakeTuple(_memo.Count, obj);
+                }
             }
 
             /// &lt;summary&gt;
@@ -1396,7 +1413,11 @@ namespace IronPython.Modules {
             }
 
             private string Read(CodeContext/*!*/ context, int size) {
-                return _file.Read(context, size);
+                string res = _file.Read(context, size);
+                if (res.Length &lt; size) {
+                    throw PythonOps.EofError(&quot;unexpected EOF while unpickling&quot;);
+                }
+                return res;
             }
 
             private string ReadLineNoNewline(CodeContext/*!*/ context) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython.Modules/cPickle.cs</filename>
    </modified>
    <modified>
      <diff>@@ -209,6 +209,7 @@ namespace IronPython.Modules {
             }
 
             public bool isatty() {
+                ThrowIfClosed();
                 return false;
             }
 
@@ -363,6 +364,7 @@ namespace IronPython.Modules {
             }
 
             public bool isatty() {
+                ThrowIfClosed();
                 return false;
             }
 </diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython.Modules/cStringIO.cs</filename>
    </modified>
    <modified>
      <diff>@@ -30,10 +30,10 @@ namespace IronPython.Modules {
 
         #region Public marshal APIs
         public static void dump(object value, PythonFile/*!*/ file) {
-            dump(value, file, null);
+            dump(value, file, version);
         }
 
-        public static void dump(object value, PythonFile/*!*/ file, object version) {
+        public static void dump(object value, PythonFile/*!*/ file, int version) {
             if (file == null) throw PythonOps.TypeError(&quot;expected file, found None&quot;);
 
             file.write(dumps(value, version));
@@ -46,11 +46,11 @@ namespace IronPython.Modules {
         }
 
         public static object dumps(object value) {
-            return dumps(value, null);
+            return dumps(value, version);
         }
 
-        public static string dumps(object value, object version) {
-            byte[] bytes = ObjectToBytes(value);
+        public static string dumps(object value, int version) {
+            byte[] bytes = ObjectToBytes(value, version);
             StringBuilder sb = new StringBuilder(bytes.Length);
             for (int i = 0; i &lt; bytes.Length; i++) {
                 sb.Append((char)bytes[i]);
@@ -62,13 +62,13 @@ namespace IronPython.Modules {
             return BytesToObject(StringEnumerator(@string));
         }
 
-        public const int version = 1;
+        public const int version = 2;
         #endregion
 
         #region Implementation details
 
-        private static byte[] ObjectToBytes(object o) {
-            MarshalWriter mw = new MarshalWriter();
+        private static byte[] ObjectToBytes(object o, int version) {
+            MarshalWriter mw = new MarshalWriter(version);
             mw.WriteObject(o);
             return mw.GetBytes();
         }
@@ -103,6 +103,7 @@ namespace IronPython.Modules {
          * Dict:  '{',key item, value item, '0' terminator
          * Int :  'i',4 bytes
          * float: 'f', 1 byte len, float in string
+         * float: 'g', 8 bytes - float in binary form
          * BigInt:  'l', int encodingSize
          *      if the value is negative then the size is negative
          *      and needs to be subtracted from int.MaxValue
@@ -115,6 +116,7 @@ namespace IronPython.Modules {
          * Float: 'f', str len, float in str
          * string: 't', int len, bytes  (ascii)
          * string: 'u', int len, bytes (unicode)
+         * string: 'R' &lt;id&gt; - refer to interned string
          * StopIteration: 'S'   
          * None: 'N'
          * Long: 'I' followed by 8 bytes (little endian 64-bit value)
@@ -124,10 +126,16 @@ namespace IronPython.Modules {
          * 
          */
         private class MarshalWriter {
-            List&lt;byte&gt; _bytes;
+            private readonly List&lt;byte&gt; _bytes;
+            private readonly int _version;
+            private readonly Dictionary&lt;string, int&gt; _strings;
 
-            public MarshalWriter() {
+            public MarshalWriter(int version) {
                 _bytes = new List&lt;byte&gt;();
+                _version = version;
+                if (_version &gt; 0) {
+                    _strings = new Dictionary&lt;string, int&gt;();
+                }
             }
 
             public void WriteObject(object o) {
@@ -162,25 +170,27 @@ namespace IronPython.Modules {
             }
 
             private void WriteFloat(float f) {
-                _bytes.Add((byte)'f');
-                WriteFloatString(f);
+                if (_version &gt; 1) {
+                    _bytes.Add((byte)'g');
+                    _bytes.AddRange(BitConverter.GetBytes((double)f));
+                } else {
+                    _bytes.Add((byte)'f');
+                    WriteDoubleString(f);
+                }
             }
 
             private void WriteFloat(double f) {
-                _bytes.Add((byte)'f');
-                WriteDoubleString(f);
-            }
-
-            private void WriteFloatString(float f) {
-                string s = f.ToString(&quot;G17&quot;);   // get maximum percision
-                _bytes.Add((byte)s.Length);
-                for (int i = 0; i &lt; s.Length; i++) {
-                    _bytes.Add((byte)s[i]);
+                if (_version &gt; 1) {
+                    _bytes.Add((byte)'g');
+                    _bytes.AddRange(BitConverter.GetBytes(f));
+                } else {
+                    _bytes.Add((byte)'f');
+                    WriteDoubleString(f);
                 }
             }
 
             private void WriteDoubleString(double d) {
-                string s = d.ToString(&quot;G17&quot;);  // get maximum percision
+                string s = DoubleOps.__repr__(DefaultContext.Default, d);
                 _bytes.Add((byte)s.Length);
                 for (int i = 0; i &lt; s.Length; i++) {
                     _bytes.Add((byte)s[i]);
@@ -298,11 +308,25 @@ namespace IronPython.Modules {
                         _bytes.Add(utfBytes[i]);
                     }
                 } else {
-                    byte[] strBytes = PythonAsciiEncoding.Instance.GetBytes(s);
-                    _bytes.Add((byte)'t');
-                    WriteInt32(strBytes.Length);
-                    for (int i = 0; i &lt; strBytes.Length; i++) {
-                        _bytes.Add(strBytes[i]);
+                    int index;
+                    if (_strings != null &amp;&amp; _strings.TryGetValue(s, out index)) {
+                        _bytes.Add((byte)'R');
+                        WriteInt32(index);
+                    } else {
+                        byte[] strBytes = PythonAsciiEncoding.Instance.GetBytes(s);
+                        if (_strings != null) {
+                            _bytes.Add((byte)'t');
+                        } else {
+                            _bytes.Add((byte)'s');
+                        }
+                        WriteInt32(strBytes.Length);
+                        for (int i = 0; i &lt; strBytes.Length; i++) {
+                            _bytes.Add(strBytes[i]);
+                        }
+
+                        if (_strings != null) {
+                            _strings[s] = _strings.Count;
+                        }
                     }
                 }
             }
@@ -362,10 +386,12 @@ namespace IronPython.Modules {
         private class MarshalReader {
             private IEnumerator&lt;byte&gt; _myBytes;
             private Stack&lt;ProcStack&gt; _stack;
+            private readonly Dictionary&lt;int, string&gt; _strings;
             private object _result;
 
             public MarshalReader(IEnumerator&lt;byte&gt; bytes) {
                 _myBytes = bytes;
+                _strings = new Dictionary&lt;int, string&gt;();
             }
 
             public object ReadObject() {
@@ -561,11 +587,13 @@ namespace IronPython.Modules {
                     case 'x': res = ReadComplex(); break;
                     case 's': res = ReadBuffer(); break;
                     case 'I': res = ReadLong(); break;
+                    case 'R': res = _strings[ReadInt32()]; break;
+                    case 'g': res = ReadBinaryFloat(); break;
                     default: throw PythonOps.ValueError(&quot;bad marshal data&quot;);
                 }
                 return res;
             }
-            
+
             private byte[] ReadBytes(int len) {
                 byte[] bytes = new byte[len];
                 for (int i = 0; i &lt; len; i++) {
@@ -637,8 +665,14 @@ namespace IronPython.Modules {
                 return ReadFloatStr();
             }
 
+            private object ReadBinaryFloat() {
+                return BitConverter.ToDouble(ReadBytes(8), 0);
+            }
+            
             private object ReadAsciiString() {
-                return DecodeString(PythonAsciiEncoding.Instance, ReadBytes(ReadInt32()));
+                string res = DecodeString(PythonAsciiEncoding.Instance, ReadBytes(ReadInt32()));
+                _strings[_strings.Count] = res;
+                return res;
             }
 
             private object ReadUnicodeString() {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython.Modules/marshal.cs</filename>
    </modified>
    <modified>
      <diff>@@ -1096,6 +1096,7 @@ namespace IronPython.Modules {
 
         public static string strerror(int code) {
             switch(code) {
+                case 0: return &quot;No error&quot;;
                 case PythonErrorNumber.E2BIG: return &quot;Arg list too long&quot;;
                 case PythonErrorNumber.EACCES: return &quot;Permission denied&quot;;
                 case PythonErrorNumber.EAGAIN: return &quot;Resource temporarily unavailable&quot;;
@@ -1158,12 +1159,16 @@ namespace IronPython.Modules {
             ProcessStartInfo psi = GetProcessInfo(command);
             psi.CreateNoWindow = false;
 
-            Process process = Process.Start(psi);
-            if (process == null) {
-                return -1;
+            try {
+                Process process = Process.Start(psi);
+                if (process == null) {
+                    return -1;
+                }
+                process.WaitForExit();
+                return process.ExitCode;
+            } catch (Win32Exception) {
+                return 1;
             }
-            process.WaitForExit();
-            return process.ExitCode;
         }
 
         public static string tempnam(CodeContext/*!*/ context) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython.Modules/nt.cs</filename>
    </modified>
    <modified>
      <diff>@@ -1156,6 +1156,11 @@ namespace IronPython.Modules {
             ExtensibleString es = str as ExtensibleString;
             if (es != null) return es.Value;
 
+            PythonBuffer buf = str as PythonBuffer;
+            if (buf != null) {
+                return buf.ToString();
+            }
+
             throw PythonOps.TypeError(&quot;expected string for parameter '{0}' but got '{1}'&quot;, param, PythonOps.GetPythonTypeName(str));
         }
 </diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython.Modules/re.cs</filename>
    </modified>
    <modified>
      <diff>@@ -44,7 +44,7 @@ namespace IronPython.Compiler.Ast {
         private readonly Scope _scope;
         private readonly GlobalArrayConstant _array;
         internal static readonly MSAst.ParameterExpression/*!*/ _globalContext = Ast.Parameter(typeof(CodeContext), &quot;$globalContext&quot;);
-        internal static readonly ReadOnlyCollection&lt;MSAst.ParameterExpression&gt; _globalContextList = new ReadOnlyCollectionBuilder&lt;MSAst.ParameterExpression&gt;(new[] { _globalContext }).ToReadOnlyCollection();
+        internal static readonly ReadOnlyCollection&lt;MSAst.ParameterExpression&gt; _arrayFuncParams = new ReadOnlyCollectionBuilder&lt;MSAst.ParameterExpression&gt;(new[] { _globalContext, AstGenerator._functionCode }).ToReadOnlyCollection();
 
         public ArrayGlobalAllocator(PythonContext/*!*/ context) {
             _globalArray = Ast.Parameter(typeof(PythonGlobal[]), &quot;$globalArray&quot;);
@@ -68,7 +68,7 @@ namespace IronPython.Compiler.Ast {
 
             // finally build the funcion that's closed over the array and
             string name = ((PythonCompilerOptions)context.Options).ModuleName ?? &quot;&lt;unnamed&gt;&quot;;
-            var func = Ast.Lambda&lt;Func&lt;object&gt;&gt;(
+            var func = Ast.Lambda&lt;Func&lt;FunctionCode, object&gt;&gt;(
                 Ast.Block(
                     new[] { _globalArray, _globalContext },
                     Ast.Assign(_globalArray, Ast.Constant(globalArray)),
@@ -76,7 +76,7 @@ namespace IronPython.Compiler.Ast {
                     Utils.Convert(body, typeof(object))
                 ),
                 name,
-                new MSAst.ParameterExpression[0]
+                new [] { AstGenerator._functionCode }
             );
 
             return new RuntimeScriptCode(context, func, ast, _context);</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/ArrayGlobalAllocator.cs</filename>
    </modified>
    <modified>
      <diff>@@ -61,6 +61,7 @@ namespace IronPython.Compiler.Ast {
         private Dictionary&lt;PythonVariable, MSAst.Expression&gt; _localLifted; // expressions for how we refer to lifted variables locally
         internal bool _isEmittingFinally;                               // true if we're emitting a finally (used for proper handling of exception tracking during rethrow)
         private readonly bool _isGenerator;                             // true if we're a generator
+        private readonly DelayedFunctionCode _funcCodeExpr;             // expression that refers to the function code for this AstGenerator
         
         internal int _loopOrFinallyId;                                  // unique id used to identify a loop
         private Dictionary&lt;int, bool&gt; _loopIds;                         // hashset of current loopids        
@@ -73,8 +74,13 @@ namespace IronPython.Compiler.Ast {
         internal static readonly MSAst.Expression[] EmptyExpression = new MSAst.Expression[0];
         internal static readonly MSAst.BlockExpression EmptyBlock = Ast.Block(AstUtils.Empty());
         internal static readonly LabelTarget GeneratorLabel = Ast.Label(typeof(object), &quot;generatorLabel&quot;);
+        internal static MSAst.ParameterExpression _functionStack = Ast.Variable(typeof(List&lt;FunctionStack&gt;), &quot;funcStack&quot;);
+        internal static MSAst.ParameterExpression _functionCode = Ast.Variable(typeof(FunctionCode), &quot;functionCode&quot;);
         private const string NameForExec = &quot;module: &lt;exec&gt;&quot;;
 
+        /// &lt;summary&gt;
+        /// Provides common initialization between top-level and class/function definition ast generators.
+        /// &lt;/summary&gt;
         private AstGenerator(string name, bool generator, string profilerName, bool print) {
             _print = print;
             _isGenerator = generator;
@@ -92,8 +98,12 @@ namespace IronPython.Compiler.Ast {
             } else {
                 _profilerName = profilerName;
             }
+            _funcCodeExpr = new DelayedFunctionCode();
         }
 
+        /// &lt;summary&gt;
+        /// Creates a new AstGenerator for a class or function definition.
+        /// &lt;/summary&gt;
         internal AstGenerator(AstGenerator/*!*/ parent, string name, bool generator, string profilerName)
             : this(name, generator, profilerName, false) {
             Assert.NotNull(parent);
@@ -106,13 +116,17 @@ namespace IronPython.Compiler.Ast {
             _globals = parent._globals;
         }
 
+        /// &lt;summary&gt;
+        /// Creates a new AstGenerator for top-level (module) code.
+        /// &lt;/summary&gt;
         internal AstGenerator(CompilationMode mode, CompilerContext/*!*/ context, SourceSpan span, string name, bool generator, bool print)
             : this(name, generator, null, print) {
             Assert.NotNull(context);
             _context = context;
             _pythonContext = (PythonContext)context.SourceUnit.LanguageContext;
             _document = _context.SourceUnit.Document ?? Ast.SymbolDocument(name, PyContext.LanguageGuid, PyContext.VendorGuid);
-            
+            _funcCodeExpr.Code = _functionCode;
+
             switch (mode) {
                 case CompilationMode.Collectable: _globals = new ArrayGlobalAllocator(_pythonContext); break;
                 case CompilationMode.Lookup: _globals = new DictionaryGlobalAllocator(); break;
@@ -601,6 +615,7 @@ namespace IronPython.Compiler.Ast {
                 return Ast.Call(
                     _UpdateStackTrace,
                     LocalContext,
+                    _funcCodeExpr,
                     _GetCurrentMethod,
                     AstUtils.Constant(Name),
                     AstUtils.Constant(Context.SourceUnit.Path ?? &quot;&lt;string&gt;&quot;),
@@ -632,6 +647,7 @@ namespace IronPython.Compiler.Ast {
                         Ast.Call(
                             _UpdateStackTrace,
                             LocalContext,
+                            _funcCodeExpr,
                             _GetCurrentMethod,
                             AstUtils.Constant(Name),
                             AstUtils.Constant(Context.SourceUnit.Path ?? &quot;&lt;string&gt;&quot;),
@@ -954,6 +970,37 @@ namespace IronPython.Compiler.Ast {
             return body;
         }
 
+        /// &lt;summary&gt;
+        /// Creates a method frame for tracking purposes and enforces recursion
+        /// &lt;/summary&gt;
+        internal static MSAst.Expression AddFrame(MSAst.Expression localContext, MSAst.Expression codeObject, MSAst.Expression body) {
+            body = AstUtils.Try(
+                Ast.Assign(
+                    _functionStack,
+                    Ast.Call(
+                        typeof(PythonOps).GetMethod(&quot;PushFrame&quot;),
+                        localContext,
+                        codeObject
+                    )
+                ),
+                body
+            ).Finally(
+                Ast.Call(
+                    _functionStack,
+                    typeof(List&lt;FunctionStack&gt;).GetMethod(&quot;RemoveAt&quot;),
+                    Ast.Add(
+                        Ast.Property(
+                            _functionStack,
+                            &quot;Count&quot;
+                        ),
+                        Ast.Constant(-1)
+                    )
+                )
+            );
+
+            return body;
+        }
+
         internal bool ShouldInterpret {
             get {
                 if (_globals is DictionaryGlobalAllocator) {
@@ -969,6 +1016,12 @@ namespace IronPython.Compiler.Ast {
             }
         }
 
+        internal MSAst.SymbolDocumentInfo Document {
+            get {
+                return _document;
+            }
+        }
+
         internal ScriptCode MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast) {
             if (_locals.Count &gt; 0) {
                 body = Ast.Block(_locals.ToReadOnlyCollection(), body);
@@ -976,6 +1029,70 @@ namespace IronPython.Compiler.Ast {
             return Globals.MakeScriptCode(body, context, ast);
         }
 
+        internal MSAst.Expression FuncCodeExpr {
+            get {
+                return _funcCodeExpr.Code;
+            }
+            set {
+                _funcCodeExpr.Code = value;
+            }
+        }
+
+        /// &lt;summary&gt;
+        /// Provides a place holder for the expression which represents
+        /// a FunctionCode.  For functions/classes this gets updated after
+        /// the AST has been generated because the FunctionCode needs to
+        /// know about the tree which gets generated.  For modules we 
+        /// immediately have the value because it always comes in as a parameter.
+        /// &lt;/summary&gt;
+        class DelayedFunctionCode : MSAst.Expression {
+            private MSAst.Expression _funcCode;
+
+            public override bool CanReduce {
+                get {
+                    return true;
+                }
+            }
+
+            public MSAst.Expression Code {
+                get {
+                    return _funcCode;
+                }
+                set {
+                    _funcCode = value;
+                }
+            }
+
+            public override Type Type {
+                get {
+                    return typeof(FunctionCode);
+                }
+            }
+
+            protected override System.Linq.Expressions.Expression VisitChildren(ExpressionVisitor visitor) {
+                if (_funcCode != null) {
+                    MSAst.Expression funcCode = visitor.Visit(_funcCode);
+                    if (funcCode != _funcCode) {
+                        DelayedFunctionCode res = new DelayedFunctionCode();
+                        res._funcCode = funcCode;
+                        return res;
+                    }
+                }
+                return this;
+            }
+
+            public override System.Linq.Expressions.Expression Reduce() {
+                Debug.Assert(_funcCode != null);
+                return _funcCode;
+            }
+
+            public override ExpressionType NodeType {
+                get {
+                    return ExpressionType.Extension;
+                }
+            }
+        }
+
         #region Binder Factories
 
         public MSAst.Expression/*!*/ Invoke(Type/*!*/ resultType, CallSignature signature, params MSAst.Expression/*!*/[]/*!*/ args) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/Ast/AstGenerator.cs</filename>
    </modified>
    <modified>
      <diff>@@ -119,6 +119,7 @@ namespace IronPython.Compiler.Ast {
             for (ScopeStatement parent = Parent; parent != null; parent = parent.Parent) {
                 if (parent.TryBindOuter(name, out variable)) {
                     variable.AccessedInNestedScope = true;
+                    UpdateReferencedVariables(name, variable, parent);
                     return variable;
                 }
             }
@@ -160,9 +161,32 @@ namespace IronPython.Compiler.Ast {
                 );
             }
 
+            FunctionCode funcCodeObj = new FunctionCode(
+                ag.PyContext,
+                null,
+                null,
+                SymbolTable.IdToString(Name),
+                ag.GetDocumentation(_body),
+                ArrayUtils.EmptyStrings,
+                FunctionAttributes.None,
+                Span,
+                ag.Context.SourceUnit.Path,
+                ag.EmitDebugSymbols,
+                ag.ShouldInterpret,
+                FreeVariables,
+                GlobalVariables,
+                CellVariables,
+                AppendVariables(new List&lt;SymbolId&gt;()),
+                Variables == null ? 0 : Variables.Count,
+                classGen.LoopLocationsNoCreate,
+                classGen.HandlerLocationsNoCreate
+            );
+            MSAst.Expression funcCode = classGen.Globals.GetConstant(funcCodeObj);
+            classGen.FuncCodeExpr = funcCode;
+
             if (_body.CanThrow &amp;&amp; ag.PyContext.PythonOptions.Frames) {
-                bodyStmt = FunctionDefinition.AddFrame(classGen.LocalContext, Ast.Constant(null, typeof(PythonFunction)), bodyStmt);
-                classGen.AddHiddenVariable(FunctionDefinition._functionStack);
+                bodyStmt = AstGenerator.AddFrame(classGen.LocalContext, funcCode, bodyStmt);
+                classGen.AddHiddenVariable(AstGenerator._functionStack);
             }
 
             bodyStmt = classGen.WrapScopeStatements(
@@ -181,6 +205,10 @@ namespace IronPython.Compiler.Ast {
                 classGen.Name + &quot;$&quot; + _classId++,
                 classGen.Parameters
             );
+            
+            if (funcCodeObj != null) {
+                funcCodeObj.Code = lambda;
+            }
 
             MSAst.Expression classDef = Ast.Call(
                 AstGenerator.GetHelperMethod(&quot;MakeClass&quot;),</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/Ast/ClassDefinition.cs</filename>
    </modified>
    <modified>
      <diff>@@ -18,6 +18,9 @@ using MSAst = System.Linq.Expressions;
 
 namespace IronPython.Compiler.Ast {
     public class ErrorExpression : Expression {
+        public ErrorExpression() {
+        }
+
         internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
             return null;
         }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/Ast/ErrorExpression.cs</filename>
    </modified>
    <modified>
      <diff>@@ -56,7 +56,6 @@ namespace IronPython.Compiler.Ast {
         private List&lt;SymbolId&gt; _closureVars;
 
         private static MSAst.ParameterExpression _functionParam = Ast.Parameter(typeof(PythonFunction), &quot;$function&quot;);
-        internal static MSAst.ParameterExpression _functionStack = Ast.Variable(typeof(List&lt;FunctionStack&gt;), &quot;funcStack&quot;);
 
         public bool IsLambda {
             get {
@@ -308,6 +307,8 @@ namespace IronPython.Compiler.Ast {
             List&lt;MSAst.Expression&gt; names = new List&lt;MSAst.Expression&gt;();
 
             List&lt;MSAst.Expression&gt; init = new List&lt;MSAst.Expression&gt;();
+            init.Add(Ast.ClearDebugInfo(ag.Document));
+
             TransformParameters(ag, bodyGen, defaults, names, needsWrapperMethod, init);
 
             MSAst.Expression parentContext;
@@ -387,8 +388,8 @@ namespace IronPython.Compiler.Ast {
             }
 
             if (_body.CanThrow &amp;&amp; ag.PyContext.PythonOptions.Frames) {
-                body = AddFrame(bodyGen.LocalContext, _functionParam, body);
-                bodyGen.AddHiddenVariable(_functionStack);
+                body = AstGenerator.AddFrame(bodyGen.LocalContext, Ast.Property(_functionParam, typeof(PythonFunction).GetProperty(&quot;__code__&quot;)), body);
+                bodyGen.AddHiddenVariable(AstGenerator._functionStack);
             }
 
             body = bodyGen.AddProfiling(body);
@@ -415,16 +416,15 @@ namespace IronPython.Compiler.Ast {
             );
 
             Delegate originalDelegate;
-            MSAst.LambdaExpression code; code = Ast.Lambda(
+            MSAst.LambdaExpression code = Ast.Lambda(
                 GetDelegateType(_parameters, needsWrapperMethod, out originalDelegate),
                 AstGenerator.AddDefaultReturn(bodyStmt, typeof(object)),
                 bodyGen.Name + &quot;$&quot; + _lambdaId++,
                 bodyGen.Parameters
             );
-            
 
             // create the function code object which all function instances will share
-            MSAst.Expression funcCode = Ast.Constant(
+            MSAst.Expression funcCode = ag.Globals.GetConstant(
                 new FunctionCode(
                     ag.PyContext,
                     ag.EmitDebugSymbols ? null : originalDelegate,
@@ -442,6 +442,7 @@ namespace IronPython.Compiler.Ast {
                     bodyGen.HandlerLocationsNoCreate
                 )                
             );
+            bodyGen.FuncCodeExpr = funcCode;
 
             MSAst.Expression ret;
             if (ag.EmitDebugSymbols &amp;&amp; !ag.PyContext.EnableTracing) {
@@ -477,36 +478,6 @@ namespace IronPython.Compiler.Ast {
             return ret;
         }
 
-        /// &lt;summary&gt;
-        /// Creates a method frame for tracking purposes and enforces recursion
-        /// &lt;/summary&gt;
-        internal static MSAst.Expression AddFrame(MSAst.Expression localContext, MSAst.Expression function, MSAst.Expression body) {
-            body = AstUtils.Try(
-                Ast.Assign(
-                    _functionStack,
-                    Ast.Call(
-                        typeof(PythonOps).GetMethod(&quot;PushFrame&quot;),
-                        localContext,
-                        function
-                    )
-                ),
-                body
-            ).Finally(
-                Ast.Call(
-                    _functionStack,
-                    typeof(List&lt;FunctionStack&gt;).GetMethod(&quot;RemoveAt&quot;),
-                    Ast.Add(
-                        Ast.Property(
-                            _functionStack,
-                            &quot;Count&quot;
-                        ),
-                        Ast.Constant(-1)
-                    )
-                )                
-            );
-
-            return body;
-        }
 
         private void TransformParameters(AstGenerator outer, AstGenerator inner, List&lt;MSAst.Expression&gt; defaults, List&lt;MSAst.Expression&gt; names, bool needsWrapperMethod, List&lt;MSAst.Expression&gt; init) {
             inner.Parameter(_functionParam);</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/Ast/FunctionDefinition.cs</filename>
    </modified>
    <modified>
      <diff>@@ -193,17 +193,6 @@ namespace IronPython.Compiler.Ast {
                 }
             }
 
-            if (ag.PyContext.PythonOptions.Frames) {
-                body = Ast.Block(
-                    new[] { FunctionDefinition._functionStack },
-                    FunctionDefinition.AddFrame(
-                        ag.LocalContext, 
-                        Ast.Constant(null, typeof(PythonFunction)), 
-                        body
-                    )
-                );
-            }
-
             body = ag.AddProfiling(body);
             body = ag.AddReturnTarget(body);
 </diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/Ast/PythonAst.cs</filename>
    </modified>
    <modified>
      <diff>@@ -15,6 +15,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Runtime.CompilerServices;
 
 using Microsoft.Scripting;
 using Microsoft.Scripting.Actions;
@@ -82,28 +83,33 @@ namespace IronPython.Compiler.Ast {
         internal override MSAst.Expression Transform(AstGenerator ag) {            
             MSAst.ParameterExpression lineUpdated = ag.GetTemporary(&quot;$lineUpdated_with&quot;, typeof(bool));
             // Five statements in the result...
-            MSAst.Expression[] statements = new MSAst.Expression[6];
+            ReadOnlyCollectionBuilder&lt;MSAst.Expression&gt; statements = new ReadOnlyCollectionBuilder&lt;MSAst.Expression&gt;(6);
+            
 
             //******************************************************************
             // 1. mgr = (EXPR)
             //******************************************************************
             MSAst.ParameterExpression manager = ag.GetTemporary(&quot;with_manager&quot;);
-            statements[0] = ag.MakeAssignment(
-                manager,
-                ag.Transform(_contextManager),
-                new SourceSpan(Start, _header)
+            statements.Add(
+                ag.MakeAssignment(
+                    manager,
+                    ag.Transform(_contextManager),
+                    new SourceSpan(Start, _header)
+                )
             );
 
             //******************************************************************
             // 2. exit = mgr.__exit__  # Not calling it yet
             //******************************************************************
             MSAst.ParameterExpression exit = ag.GetTemporary(&quot;with_exit&quot;);
-            statements[1] = ag.MakeAssignment(
-                exit,
-                ag.Get(
-                    typeof(object),
-                    &quot;__exit__&quot;,
-                    manager
+            statements.Add(
+                ag.MakeAssignment(
+                    exit,
+                    ag.Get(
+                        typeof(object),
+                        &quot;__exit__&quot;,
+                        manager
+                    )
                 )
             );
 
@@ -111,29 +117,33 @@ namespace IronPython.Compiler.Ast {
             // 3. value = mgr.__enter__()
             //******************************************************************
             MSAst.ParameterExpression value = ag.GetTemporary(&quot;with_value&quot;);
-            statements[2] = ag.AddDebugInfo(
-                ag.MakeAssignment(
-                    value,
-                    ag.Invoke(
-                        typeof(object),
-                        new CallSignature(0),
-                        ag.Get(
+            statements.Add(
+                ag.AddDebugInfo(
+                    ag.MakeAssignment(
+                        value,
+                        ag.Invoke(
                             typeof(object),
-                            &quot;__enter__&quot;,
-                            manager
+                            new CallSignature(0),
+                            ag.Get(
+                                typeof(object),
+                                &quot;__enter__&quot;,
+                                manager
+                            )
                         )
-                    )
-                ),
-                new SourceSpan(Start, _header)
+                    ),
+                    new SourceSpan(Start, _header)
+                )
             );
 
             //******************************************************************
             // 4. exc = True
             //******************************************************************
             MSAst.ParameterExpression exc = ag.GetTemporary(&quot;with_exc&quot;, typeof(bool));
-            statements[3] = ag.MakeAssignment(
-                exc,
-                AstUtils.Constant(true)
+            statements.Add(
+                ag.MakeAssignment(
+                    exc,
+                    AstUtils.Constant(true)
+                )
             );
 
             //******************************************************************
@@ -156,23 +166,20 @@ namespace IronPython.Compiler.Ast {
 
             MSAst.ParameterExpression exception = ag.GetTemporary(&quot;exception&quot;, typeof(Exception));
             MSAst.ParameterExpression nestedFrames = ag.GetTemporary(&quot;$nestedFrames&quot;, typeof(List&lt;DynamicStackFrame&gt;));
-            statements[4] =
+            statements.Add(
                 // try:
                 AstUtils.Try(
                     AstUtils.Try(// try statement body
                         ag.PushLineUpdated(false, lineUpdated),
                         _var != null ?
-                            ag.AddDebugInfo(
-                                Ast.Block(
-                    // VAR = value
-                                    _var.TransformSet(ag, SourceSpan.None, value, PythonOperationKind.None),
-                    // BLOCK
-                                    ag.Transform(_body),
-                                    AstUtils.Empty()
-                                ),
-                                _body.Span
+                            Ast.Block(
+                                // VAR = value
+                                _var.TransformSet(ag, SourceSpan.None, value, PythonOperationKind.None),
+                                // BLOCK
+                                ag.Transform(_body),
+                                AstUtils.Empty()
                             ) :
-                    // BLOCK
+                            // BLOCK
                             ag.Transform(_body) // except:, // try statement location
                     ).Catch(exception,
                     // Python specific exception handling code
@@ -251,11 +258,11 @@ namespace IronPython.Compiler.Ast {
                             _contextManager.Span
                         )
                     )
-                );
-            statements[4] = ag.AddDebugInfo(statements[4], Span);
+                )
+            );
 
-            statements[5] = AstUtils.Empty();
-            return ag.AddDebugInfo(Ast.Block(statements), _body.Span);
+            statements.Add(AstUtils.Empty());
+            return Ast.Block(statements.ToReadOnlyCollection());
         }
 
         private MSAst.Expression MakeExitCall(AstGenerator ag, MSAst.ParameterExpression exit, MSAst.Expression exception) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/Ast/WithStatement.cs</filename>
    </modified>
    <modified>
      <diff>@@ -44,16 +44,16 @@ namespace IronPython.Compiler.Ast {
 
             if (body is MSAst.ConstantExpression) {
                 object value = ((MSAst.ConstantExpression)body).Value;
-                return new PythonScriptCode(codeCtx =&gt; value, context.SourceUnit);
+                return new PythonScriptCode(context, (codeCtx, functionCode) =&gt; value, context.SourceUnit);
             }
 
-            var lambda = Ast.Lambda&lt;Func&lt;CodeContext, object&gt;&gt;(
+            var lambda = Ast.Lambda&lt;Func&lt;CodeContext, FunctionCode, object&gt;&gt;(
                 Utils.Convert(body, typeof(object)),
                 pco.ModuleName ?? &quot;&lt;unnamed&gt;&quot;,
-                ArrayGlobalAllocator._globalContextList
+                ArrayGlobalAllocator._arrayFuncParams
             );
 
-            Func&lt;CodeContext, object&gt; func;
+            Func&lt;CodeContext, FunctionCode, object&gt; func;
 
             if (pc.ShouldInterpret(pco, context.SourceUnit)) {
                 func = CompilerHelpers.LightCompile(lambda);
@@ -61,7 +61,7 @@ namespace IronPython.Compiler.Ast {
                 func = lambda.Compile(context.SourceUnit.EmitDebugSymbols);
             }
 
-            return new PythonScriptCode(func, context.SourceUnit);
+            return new PythonScriptCode(context, func, context.SourceUnit);
         }
 
         public override MSAst.Expression/*!*/ GlobalContext {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/DictionaryGlobalAllocator.cs</filename>
    </modified>
    <modified>
      <diff>@@ -22,24 +22,31 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting;
 
 using IronPython.Runtime;
+using IronPython.Runtime.Operations;
 
 namespace IronPython.Compiler {
     /// &lt;summary&gt;
     /// A ScriptCode which has been loaded from an assembly which is saved on disk.
     /// &lt;/summary&gt;
-    class OnDiskScriptCode : ScriptCode {
-        private readonly Func&lt;Scope, LanguageContext, object&gt; _code;
+    class OnDiskScriptCode : RunnableScriptCode {
+        private readonly Func&lt;CodeContext, FunctionCode, object&gt; _code;
         private Scope _optimizedScope;
         private readonly string _moduleName;
 
-        public OnDiskScriptCode(Func&lt;Scope, LanguageContext, object&gt; code, SourceUnit sourceUnit, string moduleName) :
+        public OnDiskScriptCode(Func&lt;CodeContext, FunctionCode, object&gt; code, SourceUnit sourceUnit, string moduleName) :
             base(sourceUnit) {
             _code = code;
             _moduleName = moduleName;
         }
 
         public override object Run() {
-            return _code(CreateScope(), SourceUnit.LanguageContext);
+            CodeContext ctx = CreateTopLevelCodeContext(CreateScope(), (PythonContext)SourceUnit.LanguageContext);
+            try {
+                PushFrame(ctx, _code);
+                return _code(ctx, EnsureFunctionCode(_code));
+            } finally {
+                PopFrame();
+            }
         }
 
         public override object Run(Scope scope) {
@@ -56,6 +63,10 @@ namespace IronPython.Compiler {
             }
         }
 
+        public override FunctionCode GetFunctionCode() {
+            return EnsureFunctionCode(_code);
+        }
+
         public override Scope CreateScope() {
             if (_optimizedScope == null) {
                 CachedOptimizedCodeAttribute[] attrs = (CachedOptimizedCodeAttribute[])_code.Method.GetCustomAttributes(typeof(CachedOptimizedCodeAttribute), false);</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/OnDiskScriptCode.cs</filename>
    </modified>
    <modified>
      <diff>@@ -28,13 +28,15 @@ namespace IronPython.Compiler {
     /// arbitrary Scope objects.  This is used for code when the user runs against
     /// a particular scope as well as for exec and eval code as well.
     /// &lt;/summary&gt;
-    class PythonScriptCode : ScriptCode {
-        private readonly Func&lt;CodeContext/*!*/, object&gt;/*!*/ _target;
+    class PythonScriptCode : RunnableScriptCode {
+        private readonly Func&lt;CodeContext/*!*/, FunctionCode/*!*/, object&gt;/*!*/ _target;
+        private readonly CompilerContext/*!*/ _context;
 
-        public PythonScriptCode(Func&lt;CodeContext/*!*/, object&gt;/*!*/ target, SourceUnit/*!*/ sourceUnit)
+        public PythonScriptCode(CompilerContext/*!*/ context, Func&lt;CodeContext/*!*/, FunctionCode/*!*/, object&gt;/*!*/ target, SourceUnit/*!*/ sourceUnit)
             : base(sourceUnit) {
-            Assert.NotNull(target);
+            Assert.NotNull(target, context);
 
+            _context = context;
             _target = target;
         }
 
@@ -42,7 +44,14 @@ namespace IronPython.Compiler {
             if (SourceUnit.Kind == SourceCodeKind.Expression) {
                 return EvalWrapper(new Scope());
             }
-            return _target(PythonOps.CreateTopLevelCodeContext(new Scope(), SourceUnit.LanguageContext));
+            
+            CodeContext ctx = CreateTopLevelCodeContext(new Scope(), SourceUnit.LanguageContext);
+            PushFrame(ctx, _target);
+            try {
+                return _target(ctx, EnsureFunctionCode(_target));
+            } finally {
+                PopFrame();
+            }
         }
 
         public override object Run(Scope scope) {
@@ -50,19 +59,39 @@ namespace IronPython.Compiler {
                 return EvalWrapper(scope);
             }
 
-            return _target(PythonOps.CreateTopLevelCodeContext(scope, SourceUnit.LanguageContext));
+            CodeContext ctx = CreateTopLevelCodeContext(scope, SourceUnit.LanguageContext);
+            PushFrame(ctx, _target);
+            try {
+                return _target(ctx, EnsureFunctionCode(_target));
+            } finally {
+                PopFrame();
+            }
+        }
+
+        public override FunctionCode GetFunctionCode() {
+            return EnsureFunctionCode(_target);
         }
 
         public override Scope/*!*/ CreateScope() {
             return new Scope();
         }
 
+        protected override FunctionAttributes GetCodeAttributes() {
+            return GetCodeAttributes(_context);
+        }
+
         // wrapper so we can do minimal code gen for eval code
         private object EvalWrapper(Scope scope) {
             try {
-                return _target(PythonOps.CreateTopLevelCodeContext(scope, SourceUnit.LanguageContext));
+                CodeContext ctx = CreateTopLevelCodeContext(scope, SourceUnit.LanguageContext);
+                try {
+                    PushFrame(ctx, _target);
+                    return _target(ctx, EnsureFunctionCode(_target));
+                } finally {
+                    PopFrame();
+                }
             } catch (Exception) {
-                PythonOps.UpdateStackTrace(new CodeContext(scope, (PythonContext)SourceUnit.LanguageContext), _target.Method, &quot;&lt;module&gt;&quot;, &quot;&lt;string&gt;&quot;, 0);
+                PythonOps.UpdateStackTrace(new CodeContext(scope, (PythonContext)SourceUnit.LanguageContext), Code, _target.Method, &quot;&lt;module&gt;&quot;, &quot;&lt;string&gt;&quot;, 0);
                 throw;
             }
         }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/PythonScriptCode.cs</filename>
    </modified>
    <modified>
      <diff>@@ -32,16 +32,16 @@ namespace IronPython.Compiler {
     /// Represents a script code which can be consumed at runtime as-is.  This code has
     /// no external dependencies and is closed over it's scope.  
     /// &lt;/summary&gt;
-    class RuntimeScriptCode : ScriptCode {
+    class RuntimeScriptCode : RunnableScriptCode {
         private readonly CompilerContext/*!*/ _context;
         private readonly PythonAst/*!*/ _ast;
         private readonly CodeContext/*!*/ _optimizedContext;
-        private readonly MSAst.Expression&lt;Func&lt;object&gt;&gt; _code;
-        private Func&lt;object&gt; _optimizedTarget;
+        private readonly MSAst.Expression&lt;Func&lt;FunctionCode, object&gt;&gt; _code;
+        private Func&lt;FunctionCode, object&gt; _optimizedTarget;
 
         private ScriptCode _unoptimizedCode;
 
-        public RuntimeScriptCode(CompilerContext/*!*/ context, MSAst.Expression&lt;Func&lt;object&gt;&gt;/*!*/ expression, PythonAst/*!*/ ast, CodeContext/*!*/ codeContext)
+        public RuntimeScriptCode(CompilerContext/*!*/ context, MSAst.Expression&lt;Func&lt;FunctionCode, object&gt;&gt;/*!*/ expression, PythonAst/*!*/ ast, CodeContext/*!*/ codeContext)
             : base(context.SourceUnit) {
             _code = expression;
             _ast = ast;
@@ -57,14 +57,25 @@ namespace IronPython.Compiler {
             return InvokeTarget(_code, scope);
         }
 
+        public override FunctionCode GetFunctionCode() {
+            EnsureCompiled();
+
+            return EnsureFunctionCode(_optimizedTarget);
+        }
+
         private object InvokeTarget(MSAst.LambdaExpression code, Scope scope) {
             if (scope == _optimizedContext.Scope) {
                 EnsureCompiled();
 
-                if (_context.SourceUnit.Kind == SourceCodeKind.Expression) {
-                    return OptimizedEvalWrapper();
+                PushFrame(_optimizedContext, _optimizedTarget);
+                try {
+                    if (_context.SourceUnit.Kind == SourceCodeKind.Expression) {
+                        return OptimizedEvalWrapper();
+                    }
+                    return _optimizedTarget(EnsureFunctionCode(_optimizedTarget));
+                } finally {
+                    PopFrame();
                 }
-                return _optimizedTarget();
             }
 
             // if we're running different code then re-compile the code under a new scope
@@ -78,27 +89,17 @@ namespace IronPython.Compiler {
                 );
             }
 
-            if (_context.SourceUnit.Kind == SourceCodeKind.Expression) {
-                return EvalWrapper(scope);
-            }
+            // This is a brand new ScriptCode which also handles all appropriate ScriptCode
+            // things such as pushing a function code or updating the stack trace for
+            // exec/eval code.  Therefore we don't need to do any of that here.
             return _unoptimizedCode.Run(scope);
         }
-
-        // wrappers so we can do minimal code gen for eval code
-        private object EvalWrapper(Scope scope) {
-            try {
-                return _unoptimizedCode.Run(scope);
-            } catch (Exception) {
-                PythonOps.UpdateStackTrace(new CodeContext(scope, (PythonContext)_optimizedContext.LanguageContext), _optimizedTarget.Method, &quot;&lt;module&gt;&quot;, &quot;&lt;string&gt;&quot;, 0);
-                throw;
-            }
-        }
-
+        
         private object OptimizedEvalWrapper() {
             try {
-                return _optimizedTarget();
+                return _optimizedTarget(EnsureFunctionCode(_optimizedTarget));
             } catch (Exception) {
-                PythonOps.UpdateStackTrace(_optimizedContext, _optimizedTarget.Method, &quot;&lt;module&gt;&quot;, &quot;&lt;string&gt;&quot;, 0);
+                PythonOps.UpdateStackTrace(_optimizedContext, Code, _optimizedTarget.Method, &quot;&lt;module&gt;&quot;, &quot;&lt;string&gt;&quot;, 0);
                 throw;
             }
         }
@@ -113,7 +114,11 @@ namespace IronPython.Compiler {
             }
         }
 
-        private Func&lt;object&gt;/*!*/ Compile() {
+        protected override FunctionAttributes GetCodeAttributes() {
+            return GetCodeAttributes(_context);
+        }
+
+        private Func&lt;FunctionCode, object&gt;/*!*/ Compile() {
             var pco = (PythonCompilerOptions)_context.Options;
             var pc = (PythonContext)SourceUnit.LanguageContext;
             </diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/RuntimeScriptCode.cs</filename>
    </modified>
    <modified>
      <diff>@@ -54,25 +54,22 @@ namespace IronPython.Compiler.Ast {
         }
 
         public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast) {
-            MSAst.ParameterExpression scope = Ast.Parameter(typeof(Scope), &quot;$scope&quot;);
-            MSAst.ParameterExpression language = Ast.Parameter(typeof(LanguageContext), &quot;$language &quot;);
-
-            // finally build the funcion that's closed over the array and
-            var func = Ast.Lambda&lt;Func&lt;Scope, LanguageContext, object&gt;&gt;(
+            // finally build the funcion that's closed over the array
+            var func = Ast.Lambda&lt;Func&lt;CodeContext, FunctionCode, object&gt;&gt;(
                 Ast.Block(
                     new[] { GlobalArray },
                     Ast.Assign(
                         GlobalArray, 
                         Ast.Call(
                             null,
-                            typeof(PythonOps).GetMethod(&quot;GetGlobalArray&quot;),
-                            scope
+                            typeof(PythonOps).GetMethod(&quot;GetGlobalArrayFromContext&quot;),
+                            IronPython.Compiler.Ast.ArrayGlobalAllocator._globalContext 
                         )
                     ),
                     Utils.Convert(body, typeof(object))
                 ),
                 ((PythonCompilerOptions)context.Options).ModuleName,
-                new MSAst.ParameterExpression[] { scope, language }
+                ArrayGlobalAllocator._arrayFuncParams
             );
 
             PythonCompilerOptions pco = context.Options as PythonCompilerOptions;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/SavableGlobalAllocator.cs</filename>
    </modified>
    <modified>
      <diff>@@ -23,6 +23,7 @@ using Microsoft.Scripting;
 using Microsoft.Scripting.Generation;
 using Microsoft.Scripting.Runtime;
 
+using IronPython.Runtime;
 using IronPython.Runtime.Operations;
 
 namespace IronPython.Compiler {
@@ -31,11 +32,11 @@ namespace IronPython.Compiler {
     /// the clr.CompileModules API.  This ScriptCode does not support running.
     /// &lt;/summary&gt;
     class SavableScriptCode : ScriptCode, ICustomScriptCodeData {
-        private readonly Expression&lt;Func&lt;Scope, LanguageContext, object&gt;&gt; _code;
+        private readonly Expression&lt;Func&lt;CodeContext, FunctionCode, object&gt;&gt; _code;
         private readonly string[] _names;
         private readonly string _moduleName;
         
-        public SavableScriptCode(Expression&lt;Func&lt;Scope, LanguageContext, object&gt;&gt; code, SourceUnit sourceUnit, string[] names, string moduleName)
+        public SavableScriptCode(Expression&lt;Func&lt;CodeContext, FunctionCode, object&gt;&gt; code, SourceUnit sourceUnit, string[] names, string moduleName)
             : base(sourceUnit) {
             _code = code;
             _names = names;
@@ -45,24 +46,6 @@ namespace IronPython.Compiler {
         protected override KeyValuePair&lt;MethodBuilder, Type&gt; CompileForSave(TypeGen typeGen, Dictionary&lt;SymbolId, FieldBuilder&gt; symbolDict) {
             var lambda = RewriteForSave(typeGen, _code);
 
-            lambda = Expression.Lambda&lt;Func&lt;Scope, LanguageContext, object&gt;&gt;(
-                Expression.Block(
-                    new[] { IronPython.Compiler.Ast.ArrayGlobalAllocator._globalContext },
-                    Expression.Assign(
-                        IronPython.Compiler.Ast.ArrayGlobalAllocator._globalContext,
-                        Expression.Call(
-                            null,
-                            typeof(PythonOps).GetMethod(&quot;CreateTopLevelCodeContext&quot;),
-                            lambda.Parameters[0],
-                            lambda.Parameters[1]
-                        )
-                    ),
-                    lambda.Body
-                ),
-                lambda.Name,
-                lambda.Parameters
-            );
-
             MethodBuilder mb = typeGen.TypeBuilder.DefineMethod(lambda.Name ?? &quot;lambda_method&quot;, CompilerHelpers.PublicStatic | MethodAttributes.SpecialName);
             lambda.CompileToMethod(mb, false);
 
@@ -71,7 +54,7 @@ namespace IronPython.Compiler {
                 new object[] { _names }
             ));
 
-            return new KeyValuePair&lt;MethodBuilder, Type&gt;(mb, typeof(Func&lt;Scope, LanguageContext, object&gt;));
+            return new KeyValuePair&lt;MethodBuilder, Type&gt;(mb, typeof(Func&lt;CodeContext, FunctionCode, object&gt;));
         }
 
         public override object Run() {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/SavableScriptCode.cs</filename>
    </modified>
    <modified>
      <diff>@@ -95,7 +95,7 @@ namespace IronPython.Compiler.Ast {
             ScriptingRuntimeHelpers.InitializeSymbols(t);
 
             string name = ((PythonCompilerOptions)compilerContext.Options).ModuleName ?? &quot;&lt;unnamed&gt;&quot;;
-            var func = Ast.Lambda&lt;Func&lt;object&gt;&gt;(Utils.Convert(lambda, typeof(object)), name, new MSAst.ParameterExpression[0]);
+            var func = Ast.Lambda&lt;Func&lt;FunctionCode, object&gt;&gt;(Utils.Convert(lambda, typeof(object)), name, new [] { AstGenerator._functionCode });
             return new RuntimeScriptCode(compilerContext, func, ast, _context);
         }
 
@@ -299,7 +299,13 @@ namespace IronPython.Compiler.Ast {
             ConstantInfo ci;
             if (!_constants.TryGetValue(value, out ci)) {
                 string name = &quot;Constant &quot; + (_constantsCreated++) + CompilerHelpers.GetType(value).Name;
-                FieldBuilder field = _typeGen.AddStaticField(typeof(object), FieldAttributes.Public, name);
+
+                Type constType = value.GetType();
+                if (constType.IsValueType) {
+                    constType = typeof(object);
+                }
+
+                FieldBuilder field = _typeGen.AddStaticField(constType, FieldAttributes.Public, name);
 
                 _constants[value] = ci = new ConstantInfo(field, CreateFieldBuilderExpression(field));
             }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/StaticGlobalAllocator.cs</filename>
    </modified>
    <modified>
      <diff>@@ -671,11 +671,6 @@ namespace IronPython.Compiler {
                         // backup over the eoln:
                         _buffer.SeekRelative(-eol_size);
 
-                        if (_verbatim) {
-                            complete = false;
-                            break;
-                        }
-
                         _buffer.MarkTokenEnd(multi_line);
                         UnexpectedEndOfString(isTriple, false);
                         return new ErrorToken((quote == '&quot;') ? Resources.NewLineInDoubleQuotedString : Resources.NewLineInSingleQuotedString);</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Compiler/Tokenizer.cs</filename>
    </modified>
    <modified>
      <diff>@@ -143,6 +143,9 @@ namespace IronPython.Hosting {
                 case &quot;-X:FullFrames&quot;:
                     LanguageSetup.Options[&quot;Frames&quot;] = LanguageSetup.Options[&quot;FullFrames&quot;] = ScriptingRuntimeHelpers.True;
                     break;
+                case &quot;-X:Tracing&quot;:
+                    LanguageSetup.Options[&quot;Tracing&quot;] = ScriptingRuntimeHelpers.True;
+                    break;
                 case &quot;-X:GCStress&quot;:
                     int gcStress;
                     if (!StringUtils.TryParseInt32(PopNextArg(), out gcStress) || (gcStress &lt; 0 || gcStress &gt; GC.MaxGeneration)) {
@@ -239,6 +242,7 @@ namespace IronPython.Hosting {
 
                 { &quot;-X:Frames&quot;,              &quot;Enable basic sys._getframe support&quot; },
                 { &quot;-X:FullFrames&quot;,          &quot;Enable sys._getframe with access to locals&quot; },
+                { &quot;-X:Tracing&quot;,             &quot;Enable support for tracing all methods even before sys.settrace is called&quot; },
                 { &quot;-X:GCStress&quot;,            &quot;Specifies the GC stress level (the generation to collect each statement)&quot; },
                 { &quot;-X:MaxRecursion&quot;,        &quot;Set the maximum recursion level&quot; },
                 { &quot;-X:Debug&quot;,               &quot;Enable application debugging (preferred over -D)&quot; },</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Hosting/PythonOptionsParser.cs</filename>
    </modified>
    <modified>
      <diff></diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/IronPython.Build.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{95289EA9-5778-489D-AB48-F81F2CE2DA32}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Library&lt;/OutputType&gt;
@@ -104,6 +103,7 @@
     &lt;Compile Include=&quot;Compiler\Ast\AssignmentStatement.cs&quot; /&gt;
     &lt;Compile Include=&quot;Compiler\Ast\AstGenerator.cs&quot; /&gt;
     &lt;Compile Include=&quot;Compiler\Ast\BinaryExpression.Generated.cs&quot; /&gt;
+    &lt;Compile Include=&quot;Compiler\RunnableScriptCode.cs&quot; /&gt;
     &lt;Compile Include=&quot;Modules\imp.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\CodeContext.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\DontMapIEnumerableToIterAttribute.cs&quot; /&gt;
@@ -310,7 +310,6 @@
     &lt;Compile Include=&quot;Runtime\Exceptions\ObjectException.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\Exceptions\OldInstanceException.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\Exceptions\OSException.Generated.cs&quot; /&gt;
-    &lt;Compile Include=&quot;Runtime\Exceptions\OverflowWarningException.Generated.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\Exceptions\PendingDeprecationWarningException.Generated.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\Exceptions\PythonExceptions.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\Exceptions\PythonExceptions.Generated.cs&quot; /&gt;
@@ -341,7 +340,6 @@
     &lt;Compile Include=&quot;Runtime\Binding\PythonOperationBinder.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\MissingParameter.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\ModuleDictionaryStorage.cs&quot; /&gt;
-    &lt;Compile Include=&quot;Runtime\Operations\ScriptScopeOps.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\Operations\DBNullOps.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\Operations\DictionaryOfTOps.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\Operations\ListOfTOps.cs&quot; /&gt;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/IronPython.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -17,6 +17,7 @@
 
 import sys
 import time
+import cStringIO
 
 from iptest.test_env import *
 from iptest import options, l
@@ -569,21 +570,37 @@ def AddReferenceToDlrCore():
     if not is_silverlight:
         clr.AddReference(&quot;Microsoft.Dynamic&quot;)
 
-    
+
 class stderr_trapper(object):
-    class myfile(object):
-        def __init__(self, messages):
-            self.messages = messages
-        def write(self, *args):
-            self.messages.append(args)
     def __init__(self):
-        self.messages = []
+        self.stderr = cStringIO.StringIO()
     def __enter__(self):
-        self.oldstderr, sys.stderr = sys.stderr, stderr_trapper.myfile(self.messages)
+        self.oldstderr = sys.stderr
+        sys.stderr = self.stderr
         return self
     def __exit__(self, *args):
+        self.stderr.flush()
+        self.stderr.reset()
+        self.messages = self.stderr.readlines()
+        self.messages = [x.rstrip() for x in self.messages]
+        self.stderr.close()
         sys.stderr = self.oldstderr
 
+class stdout_trapper(object):
+    def __init__(self):
+        self.stdout = cStringIO.StringIO()
+    def __enter__(self):
+        self.oldstdout, sys.stdout = sys.stdout, self.stdout
+        return self
+    def __exit__(self, *args):
+        self.stdout.flush()
+        self.stdout.reset()
+        self.messages = self.stdout.readlines()
+        self.messages = [x.rstrip() for x in self.messages]
+        self.stdout.close()
+        sys.stdout = self.oldstdout
+
+
 #------------------------------------------------------------------------------
 MAX_FAILURE_RETRY = 3
 </diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Lib/iptest/assert_util.py</filename>
    </modified>
    <modified>
      <diff>@@ -286,16 +286,15 @@ namespace IronPython.Modules {
             string unitPath = String.IsNullOrEmpty(filename) ? null : filename;
 
             switch (mode) {
-                case &quot;exec&quot;: sourceUnit = context.LanguageContext.CreateSnippet(source, unitPath, SourceCodeKind.Statements); break;
-                case &quot;eval&quot;: sourceUnit = context.LanguageContext.CreateSnippet(source, unitPath, SourceCodeKind.Expression); break;
-                case &quot;single&quot;: sourceUnit = context.LanguageContext.CreateSnippet(source, unitPath, SourceCodeKind.InteractiveCode); break;
+                case &quot;exec&quot;: sourceUnit = context.LanguageContext.CreateSnippet(source, filename, SourceCodeKind.Statements); break;
+                case &quot;eval&quot;: sourceUnit = context.LanguageContext.CreateSnippet(source, filename, SourceCodeKind.Expression); break;
+                case &quot;single&quot;: sourceUnit = context.LanguageContext.CreateSnippet(source, filename, SourceCodeKind.InteractiveCode); break;
                 default:
                     throw PythonOps.ValueError(&quot;compile() arg 3 must be 'exec' or 'eval' or 'single'&quot;);
             }
 
-            ScriptCode compiledCode = sourceUnit.Compile(opts, ThrowingErrorSink.Default);
-
-            return new FunctionCode(compiledCode, cflags, filename);
+            var compiledCode = (RunnableScriptCode)sourceUnit.Compile(opts, ThrowingErrorSink.Default);
+            return compiledCode.GetFunctionCode();
         }
 
         private static string RemoveBom(string source) {
@@ -1736,8 +1735,9 @@ namespace IronPython.Modules {
         /// 
         /// The method binder would usally report an OverflowError in this case.
         /// &lt;/summary&gt;
-        public static List range(double stop) {
-            return range(GetRangeAsInt(stop, &quot;stop&quot;));
+        public static List range(CodeContext/*!*/ context, double stop) {
+            PythonOps.Warn(context, PythonExceptions.DeprecationWarning, &quot;range: integer argument expected, got float&quot;);
+            return range(GetRangeAsInt(stop, &quot;end&quot;));
         }
 
         /// &lt;summary&gt;
@@ -1745,12 +1745,13 @@ namespace IronPython.Modules {
         /// 
         /// The method binder would usally report an OverflowError in this case.
         /// &lt;/summary&gt;
-        public static List range(double start, double stop, [DefaultParameterValue(1.0)]double step) {
-            return range(GetRangeAsInt(start, &quot;start&quot;), GetRangeAsInt(stop, &quot;stop&quot;), GetRangeAsInt(step, &quot;step&quot;));
+        public static List range(CodeContext/*!*/ context, double start, double stop, [DefaultParameterValue(1.0)]double step) {
+            PythonOps.Warn(context, PythonExceptions.DeprecationWarning, &quot;range: integer argument expected, got float&quot;);
+            return range(GetRangeAsInt(start, &quot;start&quot;), GetRangeAsInt(stop, &quot;end&quot;), GetRangeAsInt(step, &quot;step&quot;));
         }
 
         private static int GetRangeAsInt(double index, string name) {
-            if (index &lt; Int32.MaxValue || index &gt; Int32.MaxValue) {
+            if (index &lt; Int32.MinValue || index &gt; Int32.MaxValue) {
                 throw PythonOps.TypeError(&quot;expected integer for &quot; + name + &quot; argument, got float&quot;);
             }
             return (int)index;
@@ -2040,7 +2041,11 @@ namespace IronPython.Modules {
                 } else {
                     pco = new PythonCompilerOptions(PythonLanguageFeatures.Default);
                 }
-            } else if (((cflags &amp; (CompileFlags.CO_FUTURE_DIVISION | CompileFlags.CO_FUTURE_ABSOLUTE_IMPORT | CompileFlags.CO_FUTURE_WITH_STATEMENT)) != 0)) {
+            } else {
+                pco = DefaultContext.DefaultPythonContext.GetPythonCompilerOptions();
+            }
+            
+            if (((cflags &amp; (CompileFlags.CO_FUTURE_DIVISION | CompileFlags.CO_FUTURE_ABSOLUTE_IMPORT | CompileFlags.CO_FUTURE_WITH_STATEMENT)) != 0)) {
                 PythonLanguageFeatures langFeat = PythonLanguageFeatures.Default;
                 if ((cflags &amp; CompileFlags.CO_FUTURE_DIVISION) != 0) {
                     langFeat |= PythonLanguageFeatures.TrueDivision;
@@ -2051,10 +2056,8 @@ namespace IronPython.Modules {
                 if ((cflags &amp; CompileFlags.CO_FUTURE_ABSOLUTE_IMPORT) != 0) {
                     langFeat |= PythonLanguageFeatures.AbsoluteImports;
                 }
-                pco = new PythonCompilerOptions(langFeat);
-            } else {
-                pco = DefaultContext.DefaultPythonContext.GetPythonCompilerOptions();
-            }
+                pco.LanguageFeatures |= langFeat;
+            } 
 
             // The options created this way never creates
             // optimized module (exec, compile)</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Modules/Builtin.cs</filename>
    </modified>
    <modified>
      <diff>@@ -144,22 +144,39 @@ namespace IronPython.Modules {
 
             if (depth &lt; stack.Count) {
                 TraceBackFrame cur = null;
+                TraceThread thread = PythonTracebackListener.GetCurrentThread();
+                List&lt;TraceBackFrame&gt; frames = null;
+                int curTraceFrame = -1;
+                if (thread != null) {
+                    frames = thread.Frames;
+                    curTraceFrame = thread.Frames.Count - stack.Count;
+                }
+                
                 for (int i = 0; i &lt; stack.Count - depth; i++) {
                     var elem = stack[i];
 
                     if (elem.Frame != null) {
+                        // we previously handed out a frame here, hand out the same one now
                         cur = elem.Frame;
+                    } else if (frames != null &amp;&amp; curTraceFrame &gt;= 0) {
+                        // tracing is enabled and it created a frame
+                        cur = frames[curTraceFrame];
+
+                        stack[i] = new FunctionStack(elem.Context, elem.Code, cur);
                     } else {
-                        cur = elem.Frame = new TraceBackFrame(
+                        // create a new frame and save it for future calls
+                        cur = new TraceBackFrame(
                             context,
                             Builtin.globals(elem.Context),
                             Builtin.locals(elem.Context),
-                            elem.Function != null ?
-                                elem.Function.func_code :
-                                null,
+                            elem.Code,
                             cur
                         );
+
+                        stack[i] = new FunctionStack(elem.Context, elem.Code, cur);
                     }
+
+                    curTraceFrame++;
                 }
                 return cur; 
             }
@@ -247,7 +264,7 @@ namespace IronPython.Modules {
                 // We're following CPython behavior here.
                 // If CurrentPythonFrame is not null then we're currently inside a traceback, and
                 // enabling trace while inside a traceback is only allowed through sys.call_tracing()
-                var pyThread = pyContext.TracebackListener.GetCurrentThread();
+                var pyThread = PythonTracebackListener.GetCurrentThread();
                 if (pyThread == null || !pyThread.InTraceback) {
                     pyContext.PushTracebackHandler(new PythonTracebackListener((PythonContext)context.LanguageContext));
                     pyContext.RegisterTracebackHandler();</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Modules/sys.cs</filename>
    </modified>
    <modified>
      <diff>@@ -54,3 +54,6 @@ using System;
 #endif
 [assembly: SecurityTransparent]
 [assembly: CLSCompliant(false)]
+#if CLR4
+[assembly: SecurityRules(SecurityRuleSet.Level1)]
+#endif</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Properties/AssemblyInfo.cs</filename>
    </modified>
    <modified>
      <diff>@@ -338,6 +338,9 @@ namespace IronPython.Runtime.Binding {
         public bool BoolConversion(CallSite site, object value) {
             if (value is bool) {
                 return (bool)value;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on bool &amp; None
+                return false;
             }
 
             return ((CallSite&lt;Func&lt;CallSite, object, bool&gt;&gt;)site).Update(site, value);
@@ -346,6 +349,9 @@ namespace IronPython.Runtime.Binding {
         public bool IntToBoolConversion(CallSite site, object value) {
             if (value is int) {
                 return (int)value != 0;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on int &amp; None
+                return false;
             }
 
             return ((CallSite&lt;Func&lt;CallSite, object, bool&gt;&gt;)site).Update(site, value);
@@ -354,6 +360,9 @@ namespace IronPython.Runtime.Binding {
         public bool StringToBoolConversion(CallSite site, object value) {
             if (value is string) {
                 return ((string)value).Length &gt; 0;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on str &amp; None
+                return false;
             }
 
             return ((CallSite&lt;Func&lt;CallSite, object, bool&gt;&gt;)site).Update(site, value);
@@ -370,6 +379,9 @@ namespace IronPython.Runtime.Binding {
         public bool ObjectToBoolConversion(CallSite site, object value) {
             if (value != null &amp;&amp; value.GetType() == typeof(Object)) {
                 return true;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on object &amp; None
+                return false;
             }
 
             return ((CallSite&lt;Func&lt;CallSite, object, bool&gt;&gt;)site).Update(site, value);</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/ConversionBinder.cs</filename>
    </modified>
    <modified>
      <diff>@@ -34,7 +34,7 @@ namespace IronPython.Runtime.Binding {
     using Ast = System.Linq.Expressions.Expression;
     using AstUtils = Microsoft.Scripting.Ast.Utils;
 
-    class MetaPythonFunction : MetaPythonObject, IPythonInvokable, IPythonOperable, IPythonConvertible, IInferableInvokable, IConvertibleMetaObject {
+    class MetaPythonFunction : MetaPythonObject, IPythonInvokable, IPythonOperable, IPythonConvertible, IInferableInvokable, IConvertibleMetaObject, IPythonGetable {
         public MetaPythonFunction(Expression/*!*/ expression, BindingRestrictions/*!*/ restrictions, PythonFunction/*!*/ value)
             : base(expression, BindingRestrictions.Empty, value) {
             Assert.NotNull(value);
@@ -47,11 +47,57 @@ namespace IronPython.Runtime.Binding {
         }
 
         #endregion
-        
+
+
+        #region IPythonGetable Members
+
+        public DynamicMetaObject GetMember(PythonGetMemberBinder member, DynamicMetaObject codeContext) {
+            return BindGetMemberWorker(member, member.Name, codeContext);
+        }
+
+        #endregion
+
         #region MetaObject Overrides
 
         public override DynamicMetaObject/*!*/ BindInvokeMember(InvokeMemberBinder/*!*/ action, DynamicMetaObject/*!*/[]/*!*/ args) {
-            return BindingHelpers.GenericInvokeMember(action, null, this, args);
+            ParameterExpression tmp = Expression.Parameter(typeof(object));
+
+            // first get the default binder value
+            DynamicMetaObject fallback = action.FallbackInvokeMember(this, args);
+
+            // then fallback w/ an error suggestion that does a late bound lookup.
+            return action.FallbackInvokeMember(
+                this,
+                args,
+                new DynamicMetaObject(
+                    Ast.Block(
+                        new[] { tmp },
+                        Ast.Condition(
+                            Ast.NotEqual(
+                                Ast.Assign(
+                                    tmp,
+                                    Ast.Call(
+                                        typeof(PythonOps).GetMethod(&quot;PythonFunctionGetMember&quot;),
+                                        AstUtils.Convert(
+                                            Expression,
+                                            typeof(PythonFunction)
+                                        ),
+                                        Expression.Constant(SymbolTable.StringToId(action.Name))
+                                    )
+                                ),
+                                Ast.Constant(OperationFailed.Value)
+                            ),
+                            action.FallbackInvoke(
+                                new DynamicMetaObject(tmp, BindingRestrictions.Empty),
+                                args,
+                                null
+                            ).Expression,
+                            AstUtils.Convert(fallback.Expression, typeof(object))
+                        )
+                    ),
+                    BindingRestrictions.GetTypeRestriction(Expression, typeof(PythonFunction)).Merge(fallback.Restrictions)
+                )
+            );
         }
 
         public override DynamicMetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ call, params DynamicMetaObject/*!*/[]/*!*/ args) {
@@ -80,6 +126,143 @@ namespace IronPython.Runtime.Binding {
                 }
             }
         }
+
+        public override DynamicMetaObject BindGetMember(GetMemberBinder binder) {
+            return BindGetMemberWorker(binder, binder.Name, PythonContext.GetCodeContextMO(binder));
+        }
+
+        private DynamicMetaObject BindGetMemberWorker(DynamicMetaObjectBinder binder, string name, DynamicMetaObject codeContext) {
+            ParameterExpression tmp = Expression.Parameter(typeof(object));
+
+            // first get the default binder value
+            DynamicMetaObject fallback = FallbackGetMember(binder, this, codeContext);
+
+            // then fallback w/ an error suggestion that does a late bound lookup.
+            return FallbackGetMember(
+                binder,
+                this,
+                codeContext,
+                new DynamicMetaObject(
+                    Ast.Block(
+                        new[] { tmp },
+                        Ast.Condition(
+                            Ast.NotEqual(
+                                Ast.Assign(
+                                    tmp,
+                                    Ast.Call(
+                                        typeof(PythonOps).GetMethod(&quot;PythonFunctionGetMember&quot;),
+                                        AstUtils.Convert(
+                                            Expression,
+                                            typeof(PythonFunction)
+                                        ),
+                                        Expression.Constant(SymbolTable.StringToId(name))
+                                    )
+                                ),
+                                Ast.Constant(OperationFailed.Value)
+                            ),
+                            tmp,
+                            AstUtils.Convert(fallback.Expression, typeof(object))
+                        )
+                    ),
+                    BindingRestrictions.GetTypeRestriction(Expression, typeof(PythonFunction)).Merge(fallback.Restrictions)
+                )
+            );
+        }
+
+        private DynamicMetaObject FallbackGetMember(DynamicMetaObjectBinder binder, DynamicMetaObject self, DynamicMetaObject codeContext) {
+            return FallbackGetMember(binder, self, codeContext, null);
+        }
+
+        private DynamicMetaObject FallbackGetMember(DynamicMetaObjectBinder binder, DynamicMetaObject self, DynamicMetaObject codeContext, DynamicMetaObject errorSuggestion) {
+            PythonGetMemberBinder pyGetMem = binder as PythonGetMemberBinder;
+            if (pyGetMem != null) {
+                return pyGetMem.Fallback(self, codeContext, errorSuggestion);
+            }
+
+            return ((GetMemberBinder)binder).FallbackGetMember(self, errorSuggestion);
+        }
+
+        public override DynamicMetaObject BindSetMember(SetMemberBinder binder, DynamicMetaObject value) {
+            ParameterExpression tmp = Expression.Parameter(typeof(bool));
+
+            // fallback w/ an error suggestion that does a late bound set
+            return binder.FallbackSetMember(
+                this,
+                value,
+                new DynamicMetaObject(
+                    Ast.Call(
+                        typeof(PythonOps).GetMethod(&quot;PythonFunctionSetMember&quot;),
+                        AstUtils.Convert(
+                            Expression,
+                            typeof(PythonFunction)
+                        ),
+                        Expression.Constant(SymbolTable.StringToId(binder.Name)),
+                        AstUtils.Convert(
+                            value.Expression,
+                            typeof(object)
+                        )
+                    ),
+                    BindingRestrictions.GetTypeRestriction(Expression, typeof(PythonFunction))
+                )
+            );
+        }
+
+        public override DynamicMetaObject BindDeleteMember(DeleteMemberBinder binder) {
+            switch (binder.Name) {
+                case &quot;func_dict&quot;:
+                case &quot;__dict__&quot;:
+                    return new DynamicMetaObject(
+                        Expression.Call(
+                            typeof(PythonOps).GetMethod(&quot;PythonFunctionDeleteDict&quot;)
+                        ),
+                        BindingRestrictions.GetTypeRestriction(Expression, typeof(PythonFunction))
+                    );
+                case &quot;__doc__&quot;:
+                case &quot;func_doc&quot;:
+                    return new DynamicMetaObject(
+                        Expression.Call(
+                            typeof(PythonOps).GetMethod(&quot;PythonFunctionDeleteDoc&quot;),
+                            Expression.Convert(Expression, typeof(PythonFunction))
+                        ),
+                        BindingRestrictions.GetTypeRestriction(Expression, typeof(PythonFunction))
+                    );
+                case &quot;func_defaults&quot;:
+                    return new DynamicMetaObject(
+                        Expression.Call(
+                            typeof(PythonOps).GetMethod(&quot;PythonFunctionDeleteDefaults&quot;),
+                            Expression.Convert(Expression, typeof(PythonFunction))
+                        ),
+                        BindingRestrictions.GetTypeRestriction(Expression, typeof(PythonFunction))
+                    ); 
+            }
+
+            // first get the default binder value
+            DynamicMetaObject fallback = binder.FallbackDeleteMember(this);
+
+            // then fallback w/ an error suggestion that does a late bound delete
+            return binder.FallbackDeleteMember(
+                this,
+                new DynamicMetaObject(
+                    Expression.Condition(
+                        Ast.Call(
+                            typeof(PythonOps).GetMethod(&quot;PythonFunctionDeleteMember&quot;),
+                            AstUtils.Convert(
+                                Expression,
+                                typeof(PythonFunction)
+                            ),
+                            Expression.Constant(SymbolTable.StringToId(binder.Name))
+                        ),
+                        Expression.Default(typeof(void)),       // we deleted the member
+                        AstUtils.Convert(
+                            fallback.Expression,                // report language specific error,
+                            typeof(void)
+                        )
+                    ),
+                    BindingRestrictions.GetTypeRestriction(Expression, typeof(PythonFunction)).Merge(fallback.Restrictions)
+                )
+            );
+        }
+
         #endregion
 
         #region Calls</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/MetaPythonFunction.cs</filename>
    </modified>
    <modified>
      <diff>@@ -39,6 +39,11 @@ namespace IronPython.Runtime.Binding {
         #region IPythonInvokable Members
 
         public DynamicMetaObject/*!*/ Invoke(PythonInvokeBinder/*!*/ pythonInvoke, Expression/*!*/ codeContext, DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args) {
+            DynamicMetaObject translated = BuiltinFunction.TranslateArguments(pythonInvoke, codeContext, target, args, false, Value.Name);
+            if (translated != null) {
+                return translated;
+            }
+
             return InvokeWorker(pythonInvoke, args, codeContext);
         }
 
@@ -47,6 +52,17 @@ namespace IronPython.Runtime.Binding {
         #region MetaObject Overrides
 
         public override DynamicMetaObject/*!*/ BindInvokeMember(InvokeMemberBinder/*!*/ action, DynamicMetaObject/*!*/[]/*!*/ args) {
+            foreach (PythonType pt in Value.ResolutionOrder) {
+                PythonTypeSlot dummy;
+                if (pt.IsSystemType) {
+                    return action.FallbackInvokeMember(this, args);
+                } else if (
+                    pt.TryResolveSlot(DefaultContext.DefaultCLS, SymbolTable.StringToId(action.Name), out dummy) ||
+                    pt.IsOldClass) {
+                    break;
+                }
+            }
+
             return BindingHelpers.GenericInvokeMember(action, null, this, args);
         }
 
@@ -413,7 +429,7 @@ namespace IronPython.Runtime.Binding {
 
             public override DynamicMetaObject/*!*/ GetExpression(PythonBinder/*!*/ binder) {
                 PythonOverloadResolver resolver;
-                if (_creating.IsSystemType) {
+                if (_creating.IsSystemType || _creating.HasSystemCtor) {
                     resolver = new PythonOverloadResolver(binder, DynamicMetaObject.EmptyMetaObjects, new CallSignature(0), CodeContext);
                 } else {
                     resolver = new PythonOverloadResolver(binder, new[] { Arguments.Self }, new CallSignature(1), CodeContext);
@@ -434,7 +450,7 @@ namespace IronPython.Runtime.Binding {
             public override DynamicMetaObject/*!*/ GetExpression(PythonBinder/*!*/ binder) {
                 PythonOverloadResolver resolve;
 
-                if (_creating.IsSystemType) {
+                if (_creating.IsSystemType || _creating.HasSystemCtor) {
                     resolve = new PythonOverloadResolver(
                         binder, 
                         Arguments.Arguments, 
@@ -622,10 +638,10 @@ namespace IronPython.Runtime.Binding {
                     // this is a type we can't create ANY instances of, give the user a half-way decent error message
                     message = &quot;cannot create instances of &quot; + Value.Name;
                 } else {
-                    message = &quot;default __new__ does not take parameters&quot;;
+                    message = InstanceOps.ObjectNewNoParameters;
                 }
             } else {
-                message = &quot;default __new__ does not take parameters&quot;;
+                message = InstanceOps.ObjectNewNoParameters;
             }
 
             return BindingHelpers.AddDynamicTestAndDefer(</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/MetaPythonType.Calls.cs</filename>
    </modified>
    <modified>
      <diff>@@ -126,7 +126,20 @@ namespace IronPython.Runtime.Binding {
 
         private DynamicMetaObject/*!*/ InvokeWorker(DynamicMetaObjectBinder/*!*/ action, Expression/*!*/ codeContext, DynamicMetaObject/*!*/[] args) {
             ValidationInfo typeTest = BindingHelpers.GetValidationInfo(this, Value.PythonType);
-            
+
+            if (Value is PythonType) {
+                PythonContext context = PythonContext.GetPythonContext(action);
+                // optimization for meta classes.  Don't dispatch to type.__call__ if it's inherited,
+                // instead produce a normal type call rule.
+                PythonTypeSlot callSlot, typeCallSlot;
+                if (Value.PythonType.TryResolveMixedSlot(context.SharedContext, Symbols.Call, out callSlot) &amp;&amp;
+                    TypeCache.PythonType.TryResolveSlot(context.SharedContext, Symbols.Call, out typeCallSlot) &amp;&amp;
+                    callSlot == typeCallSlot) {
+                    
+                    return InvokeFallback(action, codeContext, args);
+                }
+            }
+
             return BindingHelpers.AddDynamicTestAndDefer(
                 action,
                 PythonProtocol.Call(action, this, args) ?? InvokeFallback(action, codeContext, args),</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/MetaUserObject.cs</filename>
    </modified>
    <modified>
      <diff>@@ -50,8 +50,8 @@ namespace IronPython.Runtime.Binding {
                         signature,
                         contextExpression
                     ), 
-                    CompilerHelpers.GetConstructors(t, PrivateBinding), 
-                    BindingRestrictions.Empty
+                    CompilerHelpers.GetConstructors(t, PrivateBinding),
+                    target.Restrictions.Merge(BindingRestrictions.GetInstanceRestriction(target.Expression, target.Value))
                 );
             }
 </diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/PythonBinder.Create.cs</filename>
    </modified>
    <modified>
      <diff>@@ -645,7 +645,7 @@ namespace IronPython.Runtime.Binding {
         }
 
         private static Expression ReturnPropertyTracker(PropertyTracker propertyTracker, bool privateBinding) {
-            return AstUtils.Constant(PythonTypeOps.GetReflectedProperty(propertyTracker, null, privateBinding));
+            return AstUtils.Constant(PythonTypeOps.GetReflectedProperty(propertyTracker, new MemberGroup(propertyTracker), privateBinding));
         }
 
         private static DynamicMetaObject ReturnTypeTracker(TypeTracker memberTracker) {
@@ -704,8 +704,7 @@ namespace IronPython.Runtime.Binding {
             res[typeof(char)] = new Type[] { typeof(CharOps) };
             res[typeof(decimal)] = new Type[] { typeof(DecimalOps) };
             res[typeof(float)] = new Type[] { typeof(SingleOps) };
-            res[typeof(ScriptScope)] = new Type[] { typeof(ScriptScopeOps) };   // ScriptScope extensions should go away but we still need a methods for dir() support.
-
+            
             return res;
         }
 
@@ -766,12 +765,6 @@ namespace IronPython.Runtime.Binding {
             return _sysTypes.ContainsKey(t) || t.IsDefined(typeof(PythonTypeAttribute), false);
         }
 
-        public bool WarnOnPython3000 {
-            get {
-                return _context.PythonOptions.WarnPython30;
-            }
-        }
-
         /// &lt;summary&gt;
         /// Event handler for when our domain manager has an assembly loaded by the user hosting the script
         /// runtime.  Here we can gather any information regarding extension methods.  </diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/PythonBinder.cs</filename>
    </modified>
    <modified>
      <diff>@@ -70,7 +70,7 @@ namespace IronPython.Runtime.Binding {
             if (icc != null) {
                 // get the member using our interface which also supports CodeContext.
                 return icc.GetMember(this, cc);
-            } else if (target.Value is IDynamicMetaObjectProvider &amp;&amp; !(target is MetaPythonObject)) {
+            } else if (target.Value is IDynamicMetaObjectProvider) {
                 return GetForeignObject(target);
             }
 #if !SILVERLIGHT
@@ -523,6 +523,11 @@ namespace IronPython.Runtime.Binding {
             return FallbackWorker(_context, self, codeContext, Name, _options, this, null);
         }
 
+        public DynamicMetaObject/*!*/ Fallback(DynamicMetaObject/*!*/ self, DynamicMetaObject/*!*/ codeContext, DynamicMetaObject errorSuggestion) {
+            // Python always provides an extra arg to GetMember to flow the context.
+            return FallbackWorker(_context, self, codeContext, Name, _options, this, errorSuggestion);
+        }
+
         internal static DynamicMetaObject FallbackWorker(PythonContext context, DynamicMetaObject/*!*/ self, DynamicMetaObject/*!*/ codeContext, string name, GetMemberOptions options, DynamicMetaObjectBinder action, DynamicMetaObject errorSuggestion) {
             if (self.NeedsDeferral()) {
                 return action.Defer(self);</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/PythonGetMemberBinder.cs</filename>
    </modified>
    <modified>
      <diff>@@ -137,25 +137,29 @@ namespace IronPython.Runtime.Binding {
                     }
                     break;
                 case PythonOperationKind.NotRetObject:
-                    if (CompilerHelpers.GetType(args[0]) == typeof(string)) {
+                    if (args[0] == null) {
+                        if (typeof(T) == typeof(Func&lt;CallSite, object, object&gt;)) {
+                            return (T)(object)new Func&lt;CallSite, object, object&gt;(NoneIsFalse);
+                        }
+                    } else if (args[0].GetType() == typeof(string)) {
                         if (typeof(T) == typeof(Func&lt;CallSite, object, object&gt;)) {
                             return (T)(object)new Func&lt;CallSite, object, object&gt;(StringIsFalse);
                         }
-                    } else if (CompilerHelpers.GetType(args[0]) == typeof(bool)) {
+                    } else if (args[0].GetType() == typeof(bool)) {
                         if (typeof(T) == typeof(Func&lt;CallSite, object, object&gt;)) {
                             return (T)(object)new Func&lt;CallSite, object, object&gt;(BoolIsFalse);
                         }
-                    } else if (CompilerHelpers.GetType(args[0]) == typeof(List)) {
+                    } else if (args[0].GetType() == typeof(List)) {
                         if (typeof(T) == typeof(Func&lt;CallSite, object, object&gt;)) {
                             return (T)(object)new Func&lt;CallSite, object, object&gt;(ListIsFalse);
                         }
-                    } else if (CompilerHelpers.GetType(args[0]) == typeof(PythonTuple)) {
+                    } else if (args[0].GetType() == typeof(PythonTuple)) {
                         if (typeof(T) == typeof(Func&lt;CallSite, object, object&gt;)) {
                             return (T)(object)new Func&lt;CallSite, object, object&gt;(TupleIsFalse);
                         }
-                    } else if (args[0] == null) {
+                    } else if (args[0].GetType() == typeof(int)) {
                         if (typeof(T) == typeof(Func&lt;CallSite, object, object&gt;)) {
-                            return (T)(object)new Func&lt;CallSite, object, object&gt;(NoneIsFalse);
+                            return (T)(object)new Func&lt;CallSite, object, object&gt;(IntIsFalse);
                         }
                     }
                     break;
@@ -167,6 +171,9 @@ namespace IronPython.Runtime.Binding {
             string strVal = value as string;
             if (strVal != null) {
                 return strVal.Length == 0 ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on str &amp; None
+                return true;
             }
 
             return ((CallSite&lt;Func&lt;CallSite, object, object&gt;&gt;)site).Update(site, value);
@@ -175,6 +182,9 @@ namespace IronPython.Runtime.Binding {
         private object ListIsFalse(CallSite site, object value) {
             if (value != null &amp;&amp; value.GetType() == typeof(List)) {
                 return ((List)value).Count == 0 ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on list &amp; None
+                return true;
             }
 
             return ((CallSite&lt;Func&lt;CallSite, object, object&gt;&gt;)site).Update(site, value);
@@ -191,6 +201,9 @@ namespace IronPython.Runtime.Binding {
         private object TupleIsFalse(CallSite site, object value) {
             if (value != null &amp;&amp; value.GetType() == typeof(PythonTuple)) {
                 return ((PythonTuple)value).Count == 0 ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on tuple &amp; None
+                return true;
             }
 
             return ((CallSite&lt;Func&lt;CallSite, object, object&gt;&gt;)site).Update(site, value);
@@ -199,11 +212,24 @@ namespace IronPython.Runtime.Binding {
         private object BoolIsFalse(CallSite site, object value) {
             if (value is bool) {
                 return !(bool)value ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on bool &amp; None
+                return true;
+            }
+
+            return ((CallSite&lt;Func&lt;CallSite, object, object&gt;&gt;)site).Update(site, value);
+        }
+
+        private object IntIsFalse(CallSite site, object value) {
+            if (value is int) {
+                return (int)value == 0 ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on int &amp; None
+                return true;
             }
 
             return ((CallSite&lt;Func&lt;CallSite, object, object&gt;&gt;)site).Update(site, value);
         }
-        
         private IEnumerator GetListEnumerator(CallSite site, List value) {
             return new ListIterator(value);
         }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/PythonOperationBinder.cs</filename>
    </modified>
    <modified>
      <diff>@@ -119,6 +119,9 @@ namespace IronPython.Runtime.Binding {
                 case ExpressionType.OnesComplement:
                     res = BindingHelpers.AddPythonBoxing(MakeUnaryOperation(operation, arg, Symbols.OperatorOnesComplement));
                     break;
+                case ExpressionType.Not:
+                    res = MakeUnaryNotOperation(operation, arg, typeof(object));
+                    break;
                 case ExpressionType.IsFalse:
                     res = MakeUnaryNotOperation(operation, arg, typeof(bool));
                     retType = typeof(bool);
@@ -1121,11 +1124,18 @@ namespace IronPython.Runtime.Binding {
             SlotOrFunction.GetCombinedTargets(fop, rop, out fop, out rop);
             SlotOrFunction.GetCombinedTargets(cmp, rcmp, out cmp, out rcmp);
 
+            bool shouldWarn = false;
+            WarningInfo info = null;
+
             // first try __op__ or __rop__ and return the value
+            shouldWarn = fop.ShouldWarn(state, out info);
             if (MakeOneCompareGeneric(fop, false, types, MakeCompareReturn, bodyBuilder, typeof(object))) {
+                shouldWarn = shouldWarn || rop.ShouldWarn(state, out info);
                 if (MakeOneCompareGeneric(rop, true, types, MakeCompareReturn, bodyBuilder, typeof(object))) {
 
                     // then try __cmp__ or __rcmp__ and compare the resulting int appropriaetly
+                    shouldWarn = shouldWarn || cmp.ShouldWarn(state, out info);
+
                     if (ShouldCoerce(state, opString, xType, yType, true)) {
                         DoCoerce(state, bodyBuilder, PythonOperationKind.Compare, types, false, delegate(Expression e) {
                             return GetCompareTest(op, e, false);
@@ -1142,6 +1152,8 @@ namespace IronPython.Runtime.Binding {
                         bodyBuilder,
                         typeof(object))) {
 
+                        shouldWarn = shouldWarn || rcmp.ShouldWarn(state, out info);
+
                         if (ShouldCoerce(state, opString, yType, xType, true)) {
                             DoCoerce(state, bodyBuilder, PythonOperationKind.Compare, rTypes, true, delegate(Expression e) {
                                 return GetCompareTest(op, e, true);
@@ -1163,7 +1175,12 @@ namespace IronPython.Runtime.Binding {
                 }
             }
 
-            return bodyBuilder.GetMetaObject(types);
+            DynamicMetaObject res = bodyBuilder.GetMetaObject(types);
+            if (!shouldWarn || res == null) {
+                return res;
+            } else {
+                return info.AddWarning(Ast.Constant(state.SharedContext), res);
+            }
         }
 
         /// &lt;summary&gt;
@@ -1711,7 +1728,7 @@ namespace IronPython.Runtime.Binding {
                     }
 
                     WarningInfo info;
-                    if (BindingWarnings.ShouldWarn(Binder, target.Method, out info)) {
+                    if (BindingWarnings.ShouldWarn(Binder.Context, target.Method, out info)) {
                         res = info.AddWarning(Ast.Constant(PythonContext.SharedContext), res);
                     }
                 } else if (customFailure == null || (res = customFailure()) == null) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/PythonProtocol.Operations.cs</filename>
    </modified>
    <modified>
      <diff>@@ -51,7 +51,7 @@ namespace IronPython.Runtime.Binding {
                 return com;
             }
 #endif
-            return Context.Binder.SetMember(Name, self, value, new PythonOverloadResolverFactory(_context.Binder, AstUtils.Constant(Context.SharedContext)));
+            return Context.Binder.SetMember(Name, self, value, errorSuggestion, new PythonOverloadResolverFactory(_context.Binder, AstUtils.Constant(Context.SharedContext)));
         }
 
         public override T BindDelegate&lt;T&gt;(CallSite&lt;T&gt; site, object[] args) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/PythonSetMemberBinder.cs</filename>
    </modified>
    <modified>
      <diff>@@ -62,25 +62,29 @@ namespace IronPython.Runtime.Binding {
                     }
                     break;
                 case ExpressionType.IsFalse:
-                    if (CompilerHelpers.GetType(args[0]) == typeof(string)) {
+                    if (args[0] == null) {
+                        if (typeof(T) == typeof(Func&lt;CallSite, object, bool&gt;)) {
+                            return (T)(object)new Func&lt;CallSite, object, bool&gt;(NoneIsFalse);
+                        }
+                    } else if (args[0].GetType() == typeof(string)) {
                         if (typeof(T) == typeof(Func&lt;CallSite, object, bool&gt;)) {
                             return (T)(object)new Func&lt;CallSite, object, bool&gt;(StringIsFalse);
                         }
-                    } else if (CompilerHelpers.GetType(args[0]) == typeof(bool)) {
+                    } else if (args[0].GetType() == typeof(bool)) {
                         if (typeof(T) == typeof(Func&lt;CallSite, object, bool&gt;)) {
                             return (T)(object)new Func&lt;CallSite, object, bool&gt;(BoolIsFalse);
                         }
-                    } else if (CompilerHelpers.GetType(args[0]) == typeof(List)) {
+                    } else if (args[0].GetType() == typeof(List)) {
                         if (typeof(T) == typeof(Func&lt;CallSite, object, bool&gt;)) {
                             return (T)(object)new Func&lt;CallSite, object, bool&gt;(ListIsFalse);
                         }
-                    } else if (CompilerHelpers.GetType(args[0]) == typeof(PythonTuple)) {
+                    } else if (args[0].GetType() == typeof(PythonTuple)) {
                         if (typeof(T) == typeof(Func&lt;CallSite, object, bool&gt;)) {
                             return (T)(object)new Func&lt;CallSite, object, bool&gt;(TupleIsFalse);
                         }
-                    } else if (args[0] == null) {
+                    } else if (args[0].GetType() == typeof(int)) {
                         if (typeof(T) == typeof(Func&lt;CallSite, object, bool&gt;)) {
-                            return (T)(object)new Func&lt;CallSite, object, bool&gt;(NoneIsFalse);
+                            return (T)(object)new Func&lt;CallSite, object, bool&gt;(IntIsFalse);
                         }
                     } 
                     break;
@@ -101,6 +105,9 @@ namespace IronPython.Runtime.Binding {
             string strVal = value as string;
             if (strVal != null) {
                 return strVal.Length == 0;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on str &amp; None
+                return true;
             }
 
             return ((CallSite&lt;Func&lt;CallSite, object, bool&gt;&gt;)site).Update(site, value);
@@ -109,6 +116,9 @@ namespace IronPython.Runtime.Binding {
         private bool ListIsFalse(CallSite site, object value) {
             if (value != null &amp;&amp; value.GetType() == typeof(List)) {
                 return ((List)value).Count == 0;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on list &amp; None
+                return true;
             }
 
             return ((CallSite&lt;Func&lt;CallSite, object, bool&gt;&gt;)site).Update(site, value);
@@ -122,9 +132,23 @@ namespace IronPython.Runtime.Binding {
             return ((CallSite&lt;Func&lt;CallSite, object, bool&gt;&gt;)site).Update(site, value);
         }
 
+        private bool IntIsFalse(CallSite site, object value) {
+            if (value is int) {
+                return (int)value == 0;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on int &amp; None
+                return true;
+            }
+
+            return ((CallSite&lt;Func&lt;CallSite, object, bool&gt;&gt;)site).Update(site, value);
+        }
+
         private bool TupleIsFalse(CallSite site, object value) {
             if (value != null &amp;&amp; value.GetType() == typeof(PythonTuple)) {
                 return ((PythonTuple)value).Count == 0;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on tuple &amp; None
+                return true;
             }
 
             return ((CallSite&lt;Func&lt;CallSite, object, bool&gt;&gt;)site).Update(site, value);
@@ -133,6 +157,9 @@ namespace IronPython.Runtime.Binding {
         private bool BoolIsFalse(CallSite site, object value) {
             if (value is bool) {
                 return !(bool)value;
+            } else if (value == null) {
+                // improve perf of sites just polymorphic on bool &amp; None
+                return true;
             }
 
             return ((CallSite&lt;Func&lt;CallSite, object, bool&gt;&gt;)site).Update(site, value);</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/PythonUnaryOperationBinder.cs</filename>
    </modified>
    <modified>
      <diff>@@ -38,7 +38,7 @@ namespace IronPython.Runtime.Binding {
     /// callable object we will setup a nested dynamic site for performing the additional
     /// dispatch.
     /// 
-    /// TODO: Wwe could probably do a specific binding to the object if it's another IDyanmicObject.
+    /// TODO: We could probably do a specific binding to the object if it's another IDyanmicObject.
     /// &lt;/summary&gt;
     sealed class SlotOrFunction {
         private readonly BindingTarget _function;
@@ -147,6 +147,15 @@ namespace IronPython.Runtime.Binding {
             return true;
         }
 
+        public bool ShouldWarn(PythonContext context, out WarningInfo info) {
+            if (_function != null) {
+                return BindingWarnings.ShouldWarn(context, _function.Method, out info);
+            }
+
+            info = null;
+            return false;
+        }
+
         public static SlotOrFunction/*!*/ GetSlotOrFunction(PythonContext/*!*/ state, SymbolId op, params DynamicMetaObject[] types) {
             PythonTypeSlot slot;
             SlotOrFunction res;
@@ -202,7 +211,7 @@ namespace IronPython.Runtime.Binding {
         }
 
         /// &lt;summary&gt;
-        /// Trys to geta MethodBinder associated the slot for the specified type.
+        /// Tries to get a MethodBinder associated with the slot for the specified type.
         /// 
         /// If a method is found the binder is set and true is returned.
         /// If nothing is found binder is null and true is returned.
@@ -298,7 +307,8 @@ namespace IronPython.Runtime.Binding {
             if (xBf != null) {
                 bool returnsValue = false;
                 foreach (MethodBase mb in xBf.Targets) {
-                    if (CompilerHelpers.GetReturnType(mb) != typeof(NotImplementedType)) {
+                    if (CompilerHelpers.GetReturnType(mb) != typeof(NotImplementedType) ||
+                        mb.IsDefined(typeof(Python3WarningAttribute), true)) {
                         returnsValue = true;
                         break;
                     }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/SlotOrFunction.cs</filename>
    </modified>
    <modified>
      <diff>@@ -29,7 +29,7 @@ namespace IronPython.Runtime.Binding {
     /// Provides support for emitting warnings when built in methods are invoked at runtime.
     /// &lt;/summary&gt;
     internal static class BindingWarnings {
-        public static bool ShouldWarn(PythonBinder/*!*/ binder, MethodBase/*!*/ method, out WarningInfo info) {
+        public static bool ShouldWarn(PythonContext/*!*/ context, MethodBase/*!*/ method, out WarningInfo info) {
             Assert.NotNull(method);
 
             ObsoleteAttribute[] os = (ObsoleteAttribute[])method.GetCustomAttributes(typeof(ObsoleteAttribute), true);
@@ -46,7 +46,7 @@ namespace IronPython.Runtime.Binding {
                 return true;
             }
 
-            if (binder.WarnOnPython3000) {
+            if (context.PythonOptions.WarnPython30) {
                 Python3WarningAttribute[] py3kwarnings = (Python3WarningAttribute[])method.GetCustomAttributes(typeof(Python3WarningAttribute), true);
                 if (py3kwarnings.Length &gt; 0) {
                     info = new WarningInfo(</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/BindingWarnings.cs</filename>
    </modified>
    <modified>
      <diff>@@ -413,7 +413,7 @@ namespace IronPython.Runtime {
 
                 Bucket bucket = buckets[hc % buckets.Length];
                 while (bucket != null) {
-                    if (bucket.HashCode == hc &amp;&amp; eqFunc(key, bucket.Key)) {
+                    if (bucket.HashCode == hc &amp;&amp; (Object.ReferenceEquals(key, bucket.Key) || eqFunc(key, bucket.Key))) {
                         value = bucket.Value;
                         return true;
                     }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/CommonDictionaryStorage.cs</filename>
    </modified>
    <modified>
      <diff>@@ -109,6 +109,15 @@ namespace IronPython.Runtime {
                         [DefaultParameterValue(null)]object fdel,
                         [DefaultParameterValue(null)]object doc) {
             _fget = fget; _fset = fset; _fdel = fdel; _doc = doc;
+            if (GetType() != typeof(PythonProperty) &amp;&amp; _fget is PythonFunction) {
+                // http://bugs.python.org/issue5890
+                IAttributesCollection dict = UserTypeOps.GetDictionary((IPythonObject)this);
+                if (dict == null) {
+                    throw PythonOps.AttributeError(&quot;{0} object has no __doc__ attribute&quot;, PythonTypeOps.GetName(this));
+                }
+
+                dict[Symbols.Doc] = ((PythonFunction)_fget).__doc__;
+            }
         }
 
         internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Descriptors.cs</filename>
    </modified>
    <modified>
      <diff>@@ -72,6 +72,7 @@ namespace IronPython.Runtime.Exceptions {
     public class TraceBackFrame {
         private readonly PythonTracebackListener _traceAdapter;
         private TracebackDelegate _trace;
+        private object _traceObject;
         internal int _lineNo;
         private readonly PythonDebuggingPayload _debugProperties;
         private readonly Func&lt;Scope&gt; _scopeCallback;
@@ -104,25 +105,37 @@ namespace IronPython.Runtime.Exceptions {
             _debugProperties = debugProperties;
             _scopeCallback = scopeCallback;
         }
-        
-        public TracebackDelegate f_trace {
-            get {
+
+        [SpecialName, PropertyMethod]
+        public object Getf_trace() {
                 if (_traceAdapter != null) {
-                    return _trace;
+                    return _traceObject;
                 } else {
                     return null;
                 }
-            }
-            set {
-                if (_traceAdapter != null) {
-                    _trace = value;
-                }
+        }
+
+        [SpecialName, PropertyMethod]
+        public void Setf_trace(object value) {
+            if (_traceAdapter != null) {
+                _traceObject = value;
+                _trace = (TracebackDelegate)Converter.ConvertToDelegate(value, typeof(TracebackDelegate));
             }
         }
 
-        [SpecialName]
+        [SpecialName, PropertyMethod]
         public void Deletef_trace() {
-            f_trace = null;
+            Setf_trace(null);
+        }
+
+        internal TracebackDelegate TraceDelegate {
+            get {
+                if (_traceAdapter != null) {
+                    return _trace;
+                } else {
+                    return null;
+                }
+            }
         }
 
         public object f_globals {
@@ -205,8 +218,8 @@ namespace IronPython.Runtime.Exceptions {
         }
 
         private void SetLineNumber(int newLineNum) {
-            var pyThread = _traceAdapter.GetCurrentThread();
-            if (pyThread == null || !Type.ReferenceEquals(this, pyThread.Frames.Peek())) {
+            var pyThread = PythonTracebackListener.GetCurrentThread();
+            if (!TracingThisFrame(pyThread)) {
                 throw PythonOps.ValueError(&quot;f_lineno can only be set by a trace function&quot;);
             }
 
@@ -269,6 +282,10 @@ namespace IronPython.Runtime.Exceptions {
             throw PythonOps.ValueError(&quot;line {0} is invalid jump location ({1} - {2} are valid)&quot;, originalNewLine, funcCode.Span.Start.Line, funcCode.Span.End.Line);
         }
 
+        private bool TracingThisFrame(TraceThread pyThread) {
+            return pyThread != null &amp;&amp;  pyThread.Frames.Count != 0 &amp;&amp; Type.ReferenceEquals(this, pyThread.Frames[pyThread.Frames.Count - 1]);
+        }
+
         private static Exception BadForOrFinallyJump(int newLineNum, Dictionary&lt;int, bool&gt; jumpIntoLoopIds) {
             foreach (bool isFinally in jumpIntoLoopIds.Values) {
                 if (isFinally) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Exceptions/TraceBack.cs</filename>
    </modified>
    <modified>
      <diff>@@ -28,6 +28,7 @@ using Microsoft.Scripting.Utils;
 
 using IronPython.Compiler;
 using IronPython.Runtime.Operations;
+using IronPython.Runtime.Types;
 
 namespace IronPython.Runtime {
     /// &lt;summary&gt;
@@ -41,18 +42,19 @@ namespace IronPython.Runtime {
         public Delegate Target;                                     // the current target for the function.  This can change based upon adaptive compilation, recursion enforcement, and tracing.
         private Delegate _normalDelegate;                           // the normal delegate - this can be a compiled or interpreted delegate.
 
-        private readonly ScriptCode _code;
         private readonly string _filename;                          // the filename that created the function co
         private readonly FunctionAttributes _flags;                 // future division, generator
-        private readonly LambdaExpression _lambda;                  // the original DLR lambda that contains the code
+        private LambdaExpression _lambda;                           // the original DLR lambda that contains the code
         private readonly bool _shouldInterpret;                     // true if we should interpret the code
         private readonly bool _debuggable;                          // true if the code should be compiled as debuggable code
         private readonly SourceSpan _span;                          // the source span for the source code
         private readonly string[] _argNames;                        // the argument names for the function
-        private readonly PythonTuple _closureVars;                  // a tuple of variable names which have been closed over
+        private readonly PythonTuple _freevars, _names;             // a tuple of variable names which have been closed over and global variables that have been accessed
+        private readonly PythonTuple _cellvars;                     // variables which are accessed by nested functions
         private readonly string _name;                              // the name of the function
+        private readonly int _localCount;                           // the number of local variables in the code
         internal readonly string _initialDoc;                       // the initial doc string
-        private PythonTuple _varnames;                              // lazily computed variable names
+        private readonly PythonTuple _varnames;                     // variable names (parameters and locals)
 
         // debugging/tracing support
         private readonly Dictionary&lt;int, bool&gt; _handlerLocations; // list of exception handler locations for debugging
@@ -70,17 +72,6 @@ namespace IronPython.Runtime {
         /// &lt;/summary&gt;
         private static CodeList _CodeCreateAndUpdateDelegateLock = new CodeList();
 
-        internal FunctionCode() {
-            _closureVars = PythonTuple.EMPTY;
-        }
-
-        internal FunctionCode(string name, string filename, int lineNo) {
-            _name = name;
-            _filename = filename;
-            _span = new SourceSpan(new SourceLocation(0, lineNo == 0 ? 1 : lineNo, 1), new SourceLocation(0, lineNo == 0 ? 1 : lineNo, 1));
-            _closureVars = PythonTuple.EMPTY;
-        }
-
         /// &lt;summary&gt;
         /// Constructor used to create a FunctionCode for code that's been serialized to disk.  
         /// 
@@ -88,7 +79,7 @@ namespace IronPython.Runtime {
         /// 
         /// Function codes created this way do support recursion enforcement and are therefore registered in the global function code registry.
         /// &lt;/summary&gt;
-        internal FunctionCode(PythonContext context, Delegate code, string name, string documentation, string[] argNames, FunctionAttributes flags, SourceSpan span, string path, string[] closureVars) {
+        internal FunctionCode(PythonContext context, Delegate code, string name, string documentation, string[] argNames, FunctionAttributes flags, SourceSpan span, string path, string[] freeVars, string[] names, string[] cellVars, string[] varNames, int localCount) {
             _name = name;
             _span = span;
             _initialDoc = documentation;
@@ -96,11 +87,11 @@ namespace IronPython.Runtime {
             _flags = flags;
             _span = span;
             _filename = path;
-            if (_closureVars != null) {
-                _closureVars = PythonTuple.MakeTuple((object[])closureVars);
-            } else {
-                _closureVars = PythonTuple.EMPTY;
-            }
+            _freevars = StringArrayToTuple(freeVars);
+            _names = StringArrayToTuple(names);
+            _cellvars = StringArrayToTuple(cellVars);
+            _varnames = StringArrayToTuple(varNames);
+            _localCount = localCount;
 
             _normalDelegate = code;
 
@@ -122,7 +113,7 @@ namespace IronPython.Runtime {
         /// 
         /// the initial delegate provided here should NOT be the actual code.  It should always be a delegate which updates our Target lazily.
         /// &lt;/summary&gt;
-        internal FunctionCode(PythonContext context, Delegate initialDelegate, LambdaExpression code, string name, string documentation, string[] argNames, FunctionAttributes flags, SourceSpan span, string path, bool isDebuggable, bool shouldInterpret, IList&lt;SymbolId&gt; closureVars, Dictionary&lt;int, Dictionary&lt;int, bool&gt;&gt; loopLocations, Dictionary&lt;int, bool&gt; handlerLocations) {
+        internal FunctionCode(PythonContext context, Delegate initialDelegate, LambdaExpression code, string name, string documentation, string[] argNames, FunctionAttributes flags, SourceSpan span, string path, bool isDebuggable, bool shouldInterpret, IList&lt;SymbolId&gt; freeVars, IList&lt;SymbolId&gt; names, IList&lt;SymbolId&gt; cellVars, IList&lt;SymbolId&gt; varNames, int localCount, Dictionary&lt;int, Dictionary&lt;int, bool&gt;&gt; loopLocations, Dictionary&lt;int, bool&gt; handlerLocations) {
             _lambda = code;
             _name = name;
             _span = span;
@@ -133,11 +124,12 @@ namespace IronPython.Runtime {
             _filename = path ?? &quot;&lt;string&gt;&quot;;
 
             _shouldInterpret = shouldInterpret;
-            if (closureVars != null) {
-                _closureVars = PythonTuple.MakeTuple(SymbolTable.IdsToStrings(closureVars));
-            } else {
-                _closureVars = PythonTuple.EMPTY;
-            }
+            _freevars = SymbolListToTuple(freeVars);
+            _names = SymbolListToTuple(names);
+            _cellvars = SymbolListToTuple(cellVars);
+            _varnames = SymbolListToTuple(varNames);
+            _localCount = localCount;
+
             _handlerLocations = handlerLocations;
             _loopAndFinallyLocations = loopLocations;
 
@@ -147,19 +139,20 @@ namespace IronPython.Runtime {
             RegisterFunctionCode(context);
         }
 
-        internal FunctionCode(ScriptCode code, CompileFlags compilerFlags, string fileName)
-            : this(code) {
-
-            if ((compilerFlags &amp; CompileFlags.CO_FUTURE_DIVISION) != 0) {
-                _flags |= FunctionAttributes.FutureDivision;
+        private static PythonTuple SymbolListToTuple(IList&lt;SymbolId&gt; vars) {
+            if (vars != null) {
+                return PythonTuple.MakeTuple(SymbolTable.IdsToStrings(vars));
+            } else {
+                return PythonTuple.EMPTY;
             }
-            _filename = fileName;
-            _closureVars = PythonTuple.EMPTY;
         }
 
-        internal FunctionCode(ScriptCode code) {
-            _code = code;
-            _closureVars = PythonTuple.EMPTY;
+        private static PythonTuple StringArrayToTuple(string[] closureVars) {
+            if (closureVars != null) {
+                return PythonTuple.MakeTuple((object[])closureVars);
+            } else {
+                return PythonTuple.EMPTY;
+            }
         }
 
         /// &lt;summary&gt;
@@ -181,6 +174,10 @@ namespace IronPython.Runtime {
         /// number of code objects are alive.
         /// &lt;/summary&gt;
         private void RegisterFunctionCode(PythonContext context) {
+            if (_lambda == null) {
+                return;
+            }
+
             WeakReference codeRef = new WeakReference(this, true);
             CodeList prevCode;
             lock (_CodeCreateAndUpdateDelegateLock) {
@@ -376,11 +373,8 @@ namespace IronPython.Runtime {
 
         #region Public Python API Surface
 
-        public object co_varnames {
+        public PythonTuple co_varnames {
             get {
-                if (_varnames == null) {
-                    _varnames = GetArgNames();
-                }
                 return _varnames;
             }
         }
@@ -394,18 +388,32 @@ namespace IronPython.Runtime {
             }
         }
 
-        public object co_cellvars {
+        /// &lt;summary&gt;
+        /// Returns a list of variable names which are accessed from nested functions.
+        /// &lt;/summary&gt;
+        public PythonTuple co_cellvars {
             get {
-                throw PythonOps.NotImplementedError(&quot;&quot;);
+                return _cellvars;
             }
         }
 
+        /// &lt;summary&gt;
+        /// Returns the byte code.  IronPython does not implement this and always
+        /// returns an empty string for byte code.
+        /// &lt;/summary&gt;
         public object co_code {
             get {
-                throw PythonOps.NotImplementedError(&quot;&quot;);
+                return String.Empty;
             }
         }
 
+        /// &lt;summary&gt;
+        /// Returns a list of constants used by the function.
+        /// 
+        /// The first constant is the doc string, or None if no doc string is provided.
+        /// 
+        /// IronPython currently does not include any other constants than the doc string.
+        /// &lt;/summary&gt;
         public PythonTuple co_consts {
             get {
                 if (this._initialDoc != null) {
@@ -416,59 +424,95 @@ namespace IronPython.Runtime {
             }
         }
 
+        /// &lt;summary&gt;
+        /// Returns the filename that the code object was defined in.
+        /// &lt;/summary&gt;
         public string co_filename {
             get {
                 return _filename;
             }
         }
 
+        /// &lt;summary&gt;
+        /// Returns the 1st line number of the code object.
+        /// &lt;/summary&gt;
         public int co_firstlineno {
             get {
                 return _span.Start.Line;
             }
         }
 
+        /// &lt;summary&gt;
+        /// Returns a set of flags for the function.
+        /// 
+        ///     0x04 is set if the function used *args
+        ///     0x08 is set if the function used **args
+        ///     0x20 is set if the function is a generator
+        /// &lt;/summary&gt;
         public int co_flags {
             get {
                 return (int)_flags;
             }
         }
 
-        public object co_freevars {
+        /// &lt;summary&gt;
+        /// Returns a list of free variables (variables accessed
+        /// from an outer scope).  This does not include variables
+        /// accessed in the global scope.
+        /// &lt;/summary&gt;
+        public PythonTuple co_freevars {
             get {
-                return _closureVars;
+                return _freevars;
             }
         }
 
+        /// &lt;summary&gt;
+        /// Returns a mapping between byte code and line numbers.  IronPython does
+        /// not implement this because byte code is not available.
+        /// &lt;/summary&gt;
         public object co_lnotab {
             get {
                 throw PythonOps.NotImplementedError(&quot;&quot;);
             }
         }
 
+        /// &lt;summary&gt;
+        /// Returns the name of the code (function name, class name, or &amp;lt;module&amp;gt;).
+        /// &lt;/summary&gt;
         public string co_name {
             get {
                 return _name;
             }
         }
 
-        public object co_names {
+        /// &lt;summary&gt;
+        /// Returns a list of global variable names accessed by the code.
+        /// &lt;/summary&gt;
+        public PythonTuple co_names {
             get {
-                throw PythonOps.NotImplementedError(&quot;&quot;);
+                return _names;
             }
         }
 
+        /// &lt;summary&gt;
+        /// Returns the number of local varaibles defined in the function.
+        /// &lt;/summary&gt;
         public object co_nlocals {
             get {
-                throw PythonOps.NotImplementedError(&quot;&quot;);
+                return _localCount;
             }
         }
 
+        /// &lt;summary&gt;
+        /// Returns the stack size.  IronPython does not implement this
+        /// because byte code is not supported.
+        /// &lt;/summary&gt;
         public object co_stacksize {
             get {
                 throw PythonOps.NotImplementedError(&quot;&quot;);
             }
         }
+
         #endregion
 
         #region Internal API Surface
@@ -477,15 +521,33 @@ namespace IronPython.Runtime {
             get {
                 return _lambda;
             }
+            set {
+                _lambda = value;
+            }
         }
 
         internal object Call(CodeContext/*!*/ context, Scope/*!*/ scope) {
-            if (_code != null) {
-                return _code.Run(scope);
+            if (_freevars != PythonTuple.EMPTY) {
+                throw PythonOps.TypeError(&quot;cannot exec code object that contains free variables: {0}&quot;, _freevars.__repr__(context));
             }
 
-            if (_closureVars != PythonTuple.EMPTY) {
-                throw PythonOps.TypeError(&quot;cannot exec code object that contains free variables&quot;);
+            if (Target == null) {
+                UpdateDelegate(context.LanguageContext, true);
+            }
+
+            Func&lt;CodeContext, CodeContext&gt; classTarget = Target as Func&lt;CodeContext, CodeContext&gt;;
+            if (classTarget != null) {
+                return classTarget(new CodeContext(scope, context.LanguageContext));
+            }
+
+            Func&lt;CodeContext, FunctionCode, object&gt; moduleCode = Target as Func&lt;CodeContext, FunctionCode, object&gt;;
+            if (moduleCode != null) {
+                return moduleCode(new CodeContext(scope, context.LanguageContext), this);
+            }
+
+            Func&lt;FunctionCode, object&gt; optimizedModuleCode = Target as Func&lt;FunctionCode, object&gt;;
+            if (optimizedModuleCode != null) {
+                return optimizedModuleCode(this);
             }
 
             var func = new PythonFunction(context, this, null, ArrayUtils.EmptyObjects, new MutableTuple&lt;object&gt;());
@@ -497,29 +559,6 @@ namespace IronPython.Runtime {
 
         #region Private helper functions
 
-        private PythonTuple GetArgNames() {
-            if (_code != null) return PythonTuple.MakeTuple();
-
-            List&lt;string&gt; names = new List&lt;string&gt;();
-            List&lt;PythonTuple&gt; nested = new List&lt;PythonTuple&gt;();
-
-
-            for (int i = 0; i &lt; ArgNames.Length; i++) {
-                if (ArgNames[i].IndexOf('#') != -1 &amp;&amp; ArgNames[i].IndexOf('!') != -1) {
-                    names.Add(&quot;.&quot; + (i * 2));
-                    // TODO: need to get local variable names here!!!
-                    //nested.Add(FunctionDefinition.DecodeTupleParamName(func.ArgNames[i]));
-                } else {
-                    names.Add(ArgNames[i]);
-                }
-            }
-
-            for (int i = 0; i &lt; nested.Count; i++) {
-                ExpandArgsTuple(names, nested[i]);
-            }
-            return PythonTuple.Make(names);
-        }
-
         private void ExpandArgsTuple(List&lt;string&gt; names, PythonTuple toExpand) {
             for (int i = 0; i &lt; toExpand.__len__(); i++) {
                 if (toExpand[i] is PythonTuple) {
@@ -533,22 +572,47 @@ namespace IronPython.Runtime {
         #endregion
 
         public override bool Equals(object obj) {
-            FunctionCode other = obj as FunctionCode;
-            if (other == null) return false;
+            // overridden because CPython defines this on code objects
+            return base.Equals(obj);
+        }
+
+        public override int GetHashCode() {
+            // overridden because CPython defines this on code objects
+            return base.GetHashCode();
+        }
 
-            if (_code != null) {
-                return _code == other._code;
+        public int __cmp__(CodeContext/*!*/ context, [NotNull]FunctionCode/*!*/  other) {
+            if (other == this) {
+                return 0;
             }
 
-            return _lambda == other._lambda;
+            long lres = IdDispenser.GetId(this) - IdDispenser.GetId(other);
+            return lres &gt; 0 ? 1 : -1;
         }
 
-        public override int GetHashCode() {
-            if (_code != null) {
-                return _code.GetHashCode();
-            }
+        // these are present in CPython but always return NotImplemented.
+        [return: MaybeNotImplemented]
+        [Python3Warning(&quot;code inequality comparisons not supported in 3.x&quot;)]
+        public static NotImplementedType operator &gt;(FunctionCode self, FunctionCode other) {
+            return PythonOps.NotImplemented;
+        }
+
+        [return: MaybeNotImplemented]
+        [Python3Warning(&quot;code inequality comparisons not supported in 3.x&quot;)]
+        public static NotImplementedType operator &lt;(FunctionCode self, FunctionCode other) {
+            return PythonOps.NotImplemented;
+        }
 
-            return _lambda.GetHashCode();
+        [return: MaybeNotImplemented]
+        [Python3Warning(&quot;code inequality comparisons not supported in 3.x&quot;)]
+        public static NotImplementedType operator &gt;=(FunctionCode self, FunctionCode other) {
+            return PythonOps.NotImplemented;
+        }
+
+        [return: MaybeNotImplemented]
+        [Python3Warning(&quot;code inequality comparisons not supported in 3.x&quot;)]
+        public static NotImplementedType operator &lt;=(FunctionCode self, FunctionCode other) {
+            return PythonOps.NotImplemented;
         }
 
         /// &lt;summary&gt;
@@ -574,7 +638,7 @@ namespace IronPython.Runtime {
         internal void UpdateDelegate(PythonContext context, bool forceCreation) {
             Delegate finalTarget;
 
-            if (context._enableTracing &amp;&amp; _lambda != null) {
+            if (context.EnableTracing &amp;&amp; _lambda != null) {
                 if (_tracingLambda == null) {
                     if (!forceCreation) {
                         // the user just called sys.settrace(), don't force re-compilation of every method in the system.  Instead
@@ -804,15 +868,23 @@ namespace IronPython.Runtime {
                 ),
                 Expression.Constant(_filename),
                 GetGeneratorOrNormalLambda(),
-                _closureVars.Count &gt; 0 ?
-                    (Expression)Expression.NewArrayInit(
-                        typeof(string),
-                        ArrayUtils.ConvertAll(_closureVars._data, (x) =&gt; Expression.Constant(x))
-                    ) :
-                    (Expression)Expression.Constant(null, typeof(string[]))
+                TupleToStringArray(_freevars),
+                TupleToStringArray(_names),
+                TupleToStringArray(_cellvars),
+                TupleToStringArray(_varnames),
+                Expression.Constant(_localCount)
             );
         }
 
+        private Expression TupleToStringArray(PythonTuple tuple) {
+            return tuple.Count &gt; 0 ?
+                (Expression)Expression.NewArrayInit(
+                    typeof(string),
+                    ArrayUtils.ConvertAll(tuple._data, (x) =&gt; Expression.Constant(x))
+                ) :
+                (Expression)Expression.Constant(null, typeof(string[]));
+        }
+
         #endregion
 
         /// &lt;summary&gt;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/FunctionCode.cs</filename>
    </modified>
    <modified>
      <diff>@@ -407,11 +407,15 @@ namespace IronPython.Runtime {
             if (Active) {
                 // A generator could catch this exception and continue executing, so this does
                 // not necessarily close the generator.
-                throw PythonOps.ValueError(&quot;generator already executing&quot;);
+                AlreadyExecuting();
             }
             Active = true;
         }
 
+        private static void AlreadyExecuting() {
+            throw PythonOps.ValueError(&quot;generator already executing&quot;);
+        }
+
         /// &lt;summary&gt;
         /// Helper called from PythonOps after the yield statement
         /// Keepin this in a helper method:</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Generator.cs</filename>
    </modified>
    <modified>
      <diff>@@ -102,8 +102,15 @@ namespace IronPython.Runtime {
                 NamespaceTracker nt;
                 if (scope != null) {
                     object ret;
-                    if (scope.TryGetVariable(SymbolTable.StringToId(name), out ret)) {
-                        return ret;
+                    if (scope.GetType() == typeof(Scope)) {
+                        if (scope.TryGetVariable(SymbolTable.StringToId(name), out ret)) {
+                            return ret;
+                        }
+                    } else {
+                        // subclass of module, it could have overridden __getattr__ or __getattribute__
+                        if (PythonOps.TryGetBoundAttr(context, scope, SymbolTable.StringToId(name), out ret)) {
+                            return ret;
+                        }
                     }
 
                     object path;
@@ -615,10 +622,13 @@ namespace IronPython.Runtime {
                 return ret;
             }
 
-            if (TryGetNestedModule(context, scope, name, out ret)) { return ret; }
+            if (TryGetNestedModule(context, scope, name, out ret)) { 
+                return ret; 
+            }
 
-            object importedScope = ImportFromPath(context, name, fullName, path);
-            if (importedScope != null) {
+            ImportFromPath(context, name, fullName, path);
+            object importedScope;
+            if (PythonContext.GetContext(context).SystemStateModules.TryGetValue(fullName, out importedScope)) {
                 module.Scope.SetVariable(SymbolTable.StringToId(name), importedScope);
                 return importedScope;
             }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Importer.cs</filename>
    </modified>
    <modified>
      <diff>@@ -347,6 +347,8 @@ namespace IronPython.Runtime {
             return false;
         }
 
+        public const object __hash__ = null;
+
         #region ISequence Members
 
         internal void AddRange&lt;T&gt;(ICollection&lt;T&gt; otherList) {
@@ -480,7 +482,17 @@ namespace IronPython.Runtime {
                     // try to assign back to self: make a copy first
                     if (this == value) value = new List(value);
 
-                    slice.DoSliceAssign(this.SliceAssign, _size, value);
+                    if (ValueRequiresNoLocks(value)) {
+                        // we don't need to worry about lock ordering of accesses to the 
+                        // RHS &amp; ourselves.  We can lock once and avoid repeatedly locking/unlocking
+                        // on each assign.
+                        lock (this) {
+                            slice.DoSliceAssign(this.SliceAssignNoLock, _size, value);
+                        }
+                    } else {
+                        slice.DoSliceAssign(this.SliceAssign, _size, value);
+                    }
+
                 } else {
                     int start, stop, step;
                     slice.indices(_size, out start, out stop, out step);
@@ -495,6 +507,10 @@ namespace IronPython.Runtime {
             }
         }
 
+        private static bool ValueRequiresNoLocks(object value) {
+            return value is PythonTuple || value is Array || value is FrozenSetCollection;
+        }
+
         private void SliceNoStep(int start, int stop, List other) {
             // We don't lock other here - instead we read it's object array
             // and size therefore having a stable view even if it resizes.
@@ -582,6 +598,10 @@ namespace IronPython.Runtime {
             this[index] = value;
         }
 
+        private void SliceAssignNoLock(int index, object value) {
+            _data[index] = value;
+        }
+
         public virtual void __delitem__(int index) {
             lock (this) RawDelete(PythonOps.FixIndex(index, _size));
         }
@@ -1396,7 +1416,7 @@ namespace IronPython.Runtime {
         public bool MoveNext() {
             if (_iterating) {
                 _index++;
-                _iterating = (_index &lt;= _list._size - 1);
+                _iterating = (_index &lt; _list._size);
             }
             return _iterating;
         }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/List.cs</filename>
    </modified>
    <modified>
      <diff>@@ -93,6 +93,14 @@ namespace IronPython.Runtime {
             return res;
         }
 
+        public override int Count {
+            get {
+                // need to ensure we're fully populated
+                GetItems();
+                return base.Count;
+            }
+        }
+
         public override bool TryGetValue(SymbolId key, out object value) {
             if (base.TryGetValue(key, out value)) {
                 if (value == Uninitialized.Instance) {
@@ -126,11 +134,10 @@ namespace IronPython.Runtime {
                             return true;
                         case MemberTypes.Method:
                             if (!((MethodInfo)members[0]).IsSpecialName) {
-                                value = BuiltinFunction.MakeMethod(
+                                value = BuiltinFunction.MakeFunction(
                                     name,
                                     ArrayUtils.ConvertAll&lt;MemberInfo, MethodInfo&gt;(members, delegate(MemberInfo mi) { return (MethodInfo)mi; }),
-                                    members[0].DeclaringType,
-                                    FunctionType.AlwaysVisible | FunctionType.Function
+                                    members[0].DeclaringType
                                     );
 
                                 if (publish) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/ModuleDictionaryStorage.cs</filename>
    </modified>
    <modified>
      <diff>@@ -15,10 +15,11 @@
 
 using System.Diagnostics;
 using Microsoft.Scripting.Utils;
+using Microsoft.Scripting.Runtime;
 using System.Linq.Expressions;
 using System;
 
-namespace Microsoft.Scripting.Runtime {
+namespace IronPython.Runtime {
     /// &lt;summary&gt;
     /// Cached global value.  Created and maintained on a per-language basis.  Default
     /// implementation returns a singleton which indicates caching is not occuring.</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/ModuleGlobalCache.cs</filename>
    </modified>
    <modified>
      <diff>@@ -365,6 +365,10 @@ namespace IronPython.Runtime {
                         // handle computed format specifiers
                         formatSpec = ReplaceComputedFormats(formatSpec);
 
+                        if (argValue == null) {
+                            throw PythonOps.ValueError(&quot;NoneType does not have __format__ method&quot;);
+                        }
+
                         // append the string
                         builder.Append(Builtin.format(_context.SharedContext, argValue, formatSpec));
                     }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/NewStringFormatter.cs</filename>
    </modified>
    <modified>
      <diff>@@ -45,6 +45,10 @@ namespace IronPython.Runtime.Operations {
                 if (x is string) {
                     return ParseFloat((string)x);
                 } else if (x is Extensible&lt;string&gt;) {
+                    object res;
+                    if (PythonTypeOps.TryInvokeUnaryOperator(context, x, Symbols.ConvertToFloat, out res)) {
+                        return res;
+                    }
                     return ParseFloat(((Extensible&lt;string&gt;)x).Value);
                 } else if (x is char) {
                     return ParseFloat(ScriptingRuntimeHelpers.CharToString((char)x));
@@ -93,12 +97,16 @@ namespace IronPython.Runtime.Operations {
             }
             return PythonTuple.MakeTuple((BigInteger)self, dem);
         }
+        
+        private static char[] _whitespace = new[] { ' ', '\t', '\n', '\f', '\v', '\r' };
 
         [ClassMethod, StaticExtensionMethod]
         public static object fromhex(CodeContext/*!*/ context, PythonType/*!*/ cls, string self) {
             if (String.IsNullOrEmpty(self)) {
                 throw PythonOps.ValueError(&quot;expected non empty string&quot;);
             }
+            
+            self = self.Trim(_whitespace);
 
             // look for inf, infinity, nan, etc...
             double? specialRes = TryParseSpecialFloat(self);
@@ -674,9 +682,20 @@ namespace IronPython.Runtime.Operations {
         }
 
         public static string __repr__(CodeContext/*!*/ context, double self) {
+            if (Double.IsNaN(self)) {
+                return &quot;nan&quot;;
+            }
+
+            // first format using Python's specific formatting rules...
             StringFormatter sf = new StringFormatter(context, &quot;%.17g&quot;, self);
             sf._TrailingZeroAfterWholeFloat = true;
-            return sf.Format();
+            string res = sf.Format();
+            if (LiteralParser.ParseFloat(res) == self) {
+                return res;
+            }
+
+            // if it's not round trippable though use .NET's round-trip format
+            return self.ToString(&quot;R&quot;, CultureInfo.InvariantCulture);
         }
 
         public static BigInteger/*!*/ __long__(double self) {
@@ -877,7 +896,7 @@ namespace IronPython.Runtime.Operations {
                     }
                     break;
                 default:
-                    throw PythonOps.ValueError(&quot;Unknown conversion type {0}&quot;, spec.Type.ToString());
+                    throw PythonOps.ValueError(&quot;Unknown format code '{0}' for object of type 'float'&quot;, spec.Type.ToString());
             }
 
             return digits;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Operations/FloatOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -519,15 +519,18 @@ namespace IronPython.Runtime.Operations {
             return formattable.ToString(format, null);
         }
 
+        internal const string ObjectNewNoParameters = &quot;object.__new__() takes no parameters&quot;;
+
+
         internal static void CheckNewArgs(CodeContext context, IAttributesCollection dict, object[] args, PythonType pt) {
             if (((args != null &amp;&amp; args.Length &gt; 0) || (dict != null &amp;&amp; dict.Count &gt; 0))) {
                 bool hasObjectInit = pt.HasObjectInit(context);
                 bool hasObjectNew = pt.HasObjectNew(context);
 
                 if (hasObjectInit &amp;&amp; hasObjectNew) {
-                    throw PythonOps.TypeError(&quot;default __new__ does not take parameters&quot;);
+                    throw PythonOps.TypeError(ObjectNewNoParameters);
                 } else if (!hasObjectNew &amp;&amp; !hasObjectInit) {
-                    PythonOps.Warn(context, PythonExceptions.DeprecationWarning, &quot;object.__new__() takes no parameters&quot;);
+                    PythonOps.Warn(context, PythonExceptions.DeprecationWarning, ObjectNewNoParameters);
                 }
             }
         }
@@ -560,7 +563,7 @@ namespace IronPython.Runtime.Operations {
             for (int i = 0; i &lt; methods.Length; i++) {
                 methods[i] = typeof(InstanceOps).GetMethod(methodNames[i]);
             }
-            return BuiltinFunction.MakeMethod(name, methods, typeof(object), FunctionType.Function | FunctionType.AlwaysVisible);
+            return BuiltinFunction.MakeFunction(name, methods, typeof(object));
         }
 
         private static void GetKeywordArgs(IAttributesCollection dict, object[] args, out object[] finalArgs, out string[] names) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Operations/InstanceOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -490,7 +490,7 @@ namespace IronPython.Runtime.Operations {
                     digits = Builtin.chr(self);
                     break;
                 default:
-                    throw PythonOps.ValueError(&quot;Unknown conversion type {0}&quot;, spec.Type.ToString());
+                    throw PythonOps.ValueError(&quot;Unknown format code '{0}'&quot;, spec.Type.ToString());
             }
 
             if (self &lt; 0 &amp;&amp; digits[0] == '-') {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Operations/IntOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -694,7 +694,7 @@ namespace IronPython.Runtime.Operations {
                     digits = Builtin.chr(iVal);
                     break;
                 default:
-                    throw PythonOps.ValueError(&quot;Unknown conversion type {0}&quot;, spec.Type.ToString());
+                    throw PythonOps.ValueError(&quot;Unknown format code '{0}'&quot;, spec.Type.ToString());
             }
 
             Debug.Assert(digits[0] != '-');</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Operations/LongOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -234,7 +234,7 @@ namespace IronPython.Runtime.Operations {
             StringFormatSpec spec = StringFormatSpec.FromString(formatSpec);
 
             if (spec.Type != null &amp;&amp; spec.Type != 's') {
-                throw PythonOps.ValueError(&quot;Unknown conversion type {0}&quot;, spec.Type.Value.ToString());
+                throw PythonOps.ValueError(&quot;Unknown format code '{0}' for object of type 'str'&quot;, spec.Type.Value.ToString());
             } else if (spec.Sign != null) {
                 throw PythonOps.ValueError(&quot;Sign not allowed in string format specifier&quot;);
             } else if (spec.Alignment == '=') {
@@ -349,7 +349,9 @@ namespace IronPython.Runtime.Operations {
             if (hasGetState) {
                 state = PythonOps.CallWithContext(context, getState);
             } else {
-                PythonOps.TryGetBoundAttr(context, self, Symbols.Dict, out state);
+                if (!PythonOps.TryGetBoundAttr(context, self, Symbols.Dict, out state)) {
+                    state = null;
+                }
             }
             if (!PythonOps.IsTrue(state)) state = null;
 </diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Operations/ObjectOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -1244,11 +1244,17 @@ namespace IronPython.Runtime.Operations {
         }
 
         public static object MakeClass(object body, CodeContext/*!*/ parentContext, string name, object[] bases, string selfNames) {
+            Func&lt;CodeContext, CodeContext&gt; func = GetClassCode(body);
+
+            return MakeClass(parentContext, name, bases, selfNames, func(parentContext).Scope.Dict);
+        }
+
+        private static Func&lt;CodeContext, CodeContext&gt; GetClassCode(object body) {
             Func&lt;CodeContext, CodeContext&gt; func = body as Func&lt;CodeContext, CodeContext&gt;;
             if (func == null) {
                 func = ((Compiler.LazyCode&lt;Func&lt;CodeContext, CodeContext&gt;&gt;)body).EnsureDelegate();
             }
-            return MakeClass(parentContext, name, bases, selfNames, func(parentContext).Scope.Dict);
+            return func;
         }
 
         internal static object MakeClass(CodeContext context, string name, object[] bases, string selfNames, IAttributesCollection vars) {
@@ -1382,6 +1388,9 @@ namespace IronPython.Runtime.Operations {
         /// Python Runtime Helper for enumerator unpacking (tuple assignments, ...)
         /// Creates enumerator from the input parameter e, and then extracts 
         /// expected number of values, returning them as array
+        /// 
+        /// If the input is a Python tuple returns the tuples underlying data array.  Callers
+        /// should not mutate the resulting tuple.
         /// &lt;/summary&gt;
         /// &lt;param name=&quot;context&quot;&gt;The code context of the AST getting enumerator values.&lt;/param&gt;
         /// &lt;param name=&quot;e&quot;&gt;object to enumerate&lt;/param&gt;
@@ -1391,6 +1400,11 @@ namespace IronPython.Runtime.Operations {
         /// Otherwise throws exception
         /// &lt;/returns&gt;
         public static object[] GetEnumeratorValues(CodeContext/*!*/ context, object e, int expected) {
+            if (e != null &amp;&amp; e.GetType() == typeof(PythonTuple)) {
+                // fast path for tuples, avoid enumerating &amp; copying the tuple.
+                return GetEnumeratorValuesFromTuple((PythonTuple)e, expected);
+            }
+
             IEnumerator ie = PythonOps.GetEnumeratorForUnpack(context, e);
 
             int count = 0;
@@ -1411,6 +1425,14 @@ namespace IronPython.Runtime.Operations {
             return values;
         }
 
+        private static object[] GetEnumeratorValuesFromTuple(PythonTuple pythonTuple, int expected) {
+            if (pythonTuple.Count == expected) {
+                return pythonTuple._data;
+            }
+
+            throw PythonOps.ValueErrorForUnpackMismatch(expected, pythonTuple.Count);
+        }
+
         /// &lt;summary&gt;
         /// Python runtime helper to create instance of Slice object
         /// &lt;/summary&gt;
@@ -1431,7 +1453,7 @@ namespace IronPython.Runtime.Operations {
                 f = pc.SystemStandardOut;
             }
             if (f == null || f == Uninitialized.Instance) {
-                throw PythonOps.RuntimeError(&quot;lost sys.std_out&quot;);
+                throw PythonOps.RuntimeError(&quot;lost sys.stdout&quot;);
             }
 
             PythonFile pf = f as PythonFile;
@@ -1772,7 +1794,7 @@ namespace IronPython.Runtime.Operations {
                 SourceUnit source;
 
                 if (noLineFeed) {
-                    source = pythonContext.CreateSourceUnit(new NoLineFeedSourceContentProvider(strCode), null, SourceCodeKind.Statements);
+                    source = pythonContext.CreateSourceUnit(new NoLineFeedSourceContentProvider(strCode), &quot;&lt;string&gt;&quot;, SourceCodeKind.Statements);
                 } else {
                     source = pythonContext.CreateSnippet(strCode, SourceCodeKind.Statements);
                 }
@@ -1780,12 +1802,12 @@ namespace IronPython.Runtime.Operations {
                 PythonCompilerOptions compilerOptions = Builtin.GetRuntimeGeneratedCodeCompilerOptions(context, true, 0);
 
                 // do interpretation only on strings -- not on files, streams, or code objects
-                code = new FunctionCode(pythonContext.CompilePythonCode(Compiler.CompilationMode.Lookup, source, compilerOptions, ThrowingErrorSink.Default));
+                code = ((RunnableScriptCode)pythonContext.CompilePythonCode(Compiler.CompilationMode.Lookup, source, compilerOptions, ThrowingErrorSink.Default)).GetFunctionCode();
             }
 
             FunctionCode fc = code as FunctionCode;
             if (fc == null) {
-                throw PythonOps.TypeError(&quot;arg 1 must be a string, file, Stream, or code object&quot;);
+                throw PythonOps.TypeError(&quot;arg 1 must be a string, file, Stream, or code object, not {0}&quot;, PythonTypeOps.GetName(code));
             }
 
             if (locals == null) locals = globals;
@@ -1796,7 +1818,16 @@ namespace IronPython.Runtime.Operations {
             }
 
             Scope execScope = Builtin.GetExecEvalScope(context, globals, Builtin.GetAttrLocals(context, locals), true, false);
-            fc.Call(context, execScope);
+            if (context.LanguageContext.PythonOptions.Frames) {
+                List&lt;FunctionStack&gt; stack = PushFrame(new CodeContext(execScope, context.LanguageContext), fc);
+                try {
+                    fc.Call(context, execScope);
+                } finally {
+                    stack.RemoveAt(stack.Count - 1);
+                }
+            } else {
+                fc.Call(context, execScope);
+            }
         }
 
         #endregion
@@ -2021,26 +2052,19 @@ namespace IronPython.Runtime.Operations {
                 }
 
                 PythonDynamicStackFrame pyFrame = frame as PythonDynamicStackFrame;
-                CodeContext context;
                 if (pyFrame != null) {
-                    context = pyFrame.CodeContext;
-                } else {
-                    context = DefaultContext.Default;
-                }
-
-                // TODO?: We could consider scanning our weak list of function codes and getting the
-                // live function code associated with this code.  But that won't necessarily always
-                // work and might be very slow.
+                    CodeContext context = pyFrame.CodeContext;
+                    FunctionCode code = pyFrame.Code;
 
-                FunctionCode code = new FunctionCode(name, frame.GetFileName(), frame.GetFileLineNumber());
-                TraceBackFrame tbf = new TraceBackFrame(
-                    context,
-                    new PythonDictionary(new GlobalScopeDictionaryStorage(context.Scope)),
-                    context.Scope.Dict,
-                    code);
+                    TraceBackFrame tbf = new TraceBackFrame(
+                        context,
+                        new PythonDictionary(new GlobalScopeDictionaryStorage(context.Scope)),
+                        context.Scope.Dict,
+                        code);
 
-                tb = new TraceBack(tb, tbf);
-                tb.SetLine(frame.GetFileLineNumber());
+                    tb = new TraceBack(tb, tbf);
+                    tb.SetLine(frame.GetFileLineNumber());
+                }
             }
 
             e.Data[typeof(TraceBack)] = tb;
@@ -2391,6 +2415,37 @@ namespace IronPython.Runtime.Operations {
             return true;
         }
 
+        public static object PythonFunctionGetMember(PythonFunction function, SymbolId name) {
+            object res;
+            if (function._dict != null &amp;&amp; function._dict.TryGetValue(name, out res)) {
+                return res;
+            }
+
+            return OperationFailed.Value;
+        }
+
+        public static object PythonFunctionSetMember(PythonFunction function, SymbolId name, object value) {
+            return function.__dict__[name] = value;
+        }
+
+        public static void PythonFunctionDeleteDict() {
+            throw PythonOps.TypeError(&quot;function's dictionary may not be deleted&quot;);
+        }
+
+        public static void PythonFunctionDeleteDoc(PythonFunction function) {
+            function.__doc__ = null;
+        }
+
+        public static void PythonFunctionDeleteDefaults(PythonFunction function) {
+            function.__defaults__ = null;
+        }
+
+        public static bool PythonFunctionDeleteMember(PythonFunction function, SymbolId name) {
+            if (function._dict == null) return false;
+
+            return function._dict.Remove(name);
+        }
+
         /// &lt;summary&gt;
         /// Creates a new array the values set to Uninitialized.Instance.  The array
         /// is large enough to hold for all of the slots allocated for the type and
@@ -3701,12 +3756,7 @@ namespace IronPython.Runtime.Operations {
             throw NameError(name);
         }
 
-        public static CodeContext/*!*/ CreateTopLevelCodeContext(Scope/*!*/ scope, LanguageContext/*!*/ context) {
-            context.EnsureScopeExtension(CodeContext.GetModuleScope(scope));
-            return new CodeContext(scope, (PythonContext)context);
-        }
-
-        public static PythonGlobal/*!*/[]/*!*/ GetGlobalArray(Scope/*!*/ scope) {
+        private static PythonGlobal/*!*/[]/*!*/ GetGlobalArray(Scope/*!*/ scope) {
             return ((GlobalDictionaryStorage)((PythonDictionary)scope.Dict)._storage).Data;
         }
 
@@ -3886,9 +3936,10 @@ namespace IronPython.Runtime.Operations {
 
         public static SyntaxErrorException BadSourceError(byte badByte, SourceSpan span, string path) {
             SyntaxErrorException res = new SyntaxErrorException(
-                String.Format(&quot;Non-ASCII character '\\x{0:x}' in file x.py on line {1}, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details&quot;,
+                String.Format(&quot;Non-ASCII character '\\x{0:x2}' in file {2} on line {1}, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details&quot;,
                     badByte,
-                    span.Start.Line
+                    span.Start.Line,
+                    path
                 ),
                 path,
                 null,
@@ -4094,7 +4145,7 @@ namespace IronPython.Runtime.Operations {
             return _funcStack.GetOrCreate(Creator);
         }
 
-        public static List&lt;FunctionStack&gt; PushFrame(CodeContext context, PythonFunction function) {
+        public static List&lt;FunctionStack&gt; PushFrame(CodeContext context, FunctionCode function) {
             List&lt;FunctionStack&gt; stack = GetFunctionStack();
             stack.Add(new FunctionStack(context, function));
             return stack;
@@ -4109,7 +4160,7 @@ namespace IronPython.Runtime.Operations {
             );
         }
 
-        public static void UpdateStackTrace(CodeContext context, MethodBase method, string funcName, string filename, int line) {
+        public static void UpdateStackTrace(CodeContext context, FunctionCode funcCode, MethodBase method, string funcName, string filename, int line) {
             if (line != -1) {
                 Debug.Assert(filename != null);
                 if (ExceptionHelpers.DynamicStackFrames == null) {
@@ -4118,22 +4169,32 @@ namespace IronPython.Runtime.Operations {
 
                 Debug.Assert(line != SourceLocation.None.Line);
 
-                ExceptionHelpers.DynamicStackFrames.Add(new PythonDynamicStackFrame(context, method, funcName, filename, line));
+                ExceptionHelpers.DynamicStackFrames.Add(new PythonDynamicStackFrame(context, funcCode, method, funcName, filename, line));
             }
         }
 
     }
 
     public struct FunctionStack {
-        public readonly CodeContext Context;
-        public readonly PythonFunction Function;
+        public readonly CodeContext/*!*/ Context;
+        public readonly FunctionCode/*!*/ Code;
         public TraceBackFrame Frame;
 
-        public FunctionStack(CodeContext/*!*/ context, PythonFunction/*!*/ function) {
+        internal FunctionStack(CodeContext/*!*/ context, FunctionCode/*!*/ code) {
+            Assert.NotNull(context, code);
+
             Context = context;
-            Function = function;
+            Code = code;
             Frame = null;
         }
+
+        internal FunctionStack(CodeContext/*!*/ context, FunctionCode/*!*/ code, TraceBackFrame frame) {
+            Assert.NotNull(context, code);
+
+            Context = context;
+            Code = code;
+            Frame = frame;
+        }
     }
 
 }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Operations/PythonOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -28,7 +28,7 @@ using Microsoft.Scripting.Utils;
 
 namespace IronPython.Runtime.Operations {
     internal static class PythonTypeOps {
-        private static readonly Dictionary&lt;FieldInfo, ReflectedField&gt; _fieldCache = new Dictionary&lt;FieldInfo, ReflectedField&gt;();
+        private static readonly Dictionary&lt;FieldInfo, PythonTypeSlot&gt; _fieldCache = new Dictionary&lt;FieldInfo, PythonTypeSlot&gt;();
         private static readonly Dictionary&lt;BuiltinFunction, BuiltinMethodDescriptor&gt; _methodCache = new Dictionary&lt;BuiltinFunction, BuiltinMethodDescriptor&gt;();
         private static readonly Dictionary&lt;BuiltinFunction, ClassMethodDescriptor&gt; _classMethodCache = new Dictionary&lt;BuiltinFunction, ClassMethodDescriptor&gt;();
         internal static readonly Dictionary&lt;BuiltinFunctionKey, BuiltinFunction&gt; _functions = new Dictionary&lt;BuiltinFunctionKey, BuiltinFunction&gt;();
@@ -365,27 +365,33 @@ namespace IronPython.Runtime.Operations {
         }
 
         internal static BuiltinFunction GetConstructorFunction(Type type, string name) {
-            BuiltinFunction reflectedCtors = null;
+            List&lt;MethodBase&gt; methods = new List&lt;MethodBase&gt;();
             bool hasDefaultConstructor = false;
 
             foreach (ConstructorInfo ci in type.GetConstructors(BindingFlags.Public | BindingFlags.Instance)) {
                 if (ci.IsPublic) {
-                    if (ci.GetParameters().Length == 0) hasDefaultConstructor = true;
-                    reflectedCtors = BuiltinFunction.MakeOrAdd(reflectedCtors, name, ci, type, FunctionType.Function);
+                    if (ci.GetParameters().Length == 0) {
+                        hasDefaultConstructor = true;
+                    }
+
+                    methods.Add(ci);
                 }
             }
             
             if (type.IsValueType &amp;&amp; !hasDefaultConstructor &amp;&amp; type != typeof(void)) {
                 try {
-                    MethodInfo mi = typeof(ScriptingRuntimeHelpers).GetMethod(&quot;CreateInstance&quot;, Type.EmptyTypes).MakeGenericMethod(type);
-
-                    reflectedCtors = BuiltinFunction.MakeOrAdd(reflectedCtors, name, mi, type, FunctionType.Function);
+                    methods.Add(typeof(ScriptingRuntimeHelpers).GetMethod(&quot;CreateInstance&quot;, Type.EmptyTypes).MakeGenericMethod(type));
                 } catch (BadImageFormatException) {
                     // certain types (e.g. ArgIterator) won't survive the above call.
                     // we won't let you create instances of these types.
                 }
             }
-            return reflectedCtors;
+
+            if (methods.Count &gt; 0) {
+                return BuiltinFunction.MakeFunction(name, methods.ToArray(), type);
+            }
+
+            return null;
         }
 
         internal static ReflectedEvent GetReflectedEvent(EventTracker tracker) {
@@ -494,6 +500,20 @@ namespace IronPython.Runtime.Operations {
 
                 lock (_functions) {
                     if (!_functions.TryGetValue(cache, out res)) {
+                        if (PythonTypeOps.GetFinalSystemType(type) == type) {
+                            IList&lt;MethodInfo&gt; overriddenMethods = NewTypeMaker.GetOverriddenMethods(type, cacheName);
+
+                            if (overriddenMethods.Count &gt; 0) {
+                                List&lt;MemberInfo&gt; newMems = new List&lt;MemberInfo&gt;(mems);
+
+                                foreach (MethodInfo mi in overriddenMethods) {
+                                    newMems.Add(mi);
+                                }
+
+                                mems = newMems.ToArray();
+                            }
+                        }
+
                         _functions[cache] = res = BuiltinFunction.MakeMethod(pythonName, ReflectionUtils.GetMethodInfos(mems), type, ft);
                     }
                 }
@@ -664,8 +684,8 @@ namespace IronPython.Runtime.Operations {
                 (mi.DeclaringType.IsAssignableFrom(type) || mi.IsDefined(typeof(StaticExtensionMethodAttribute), false)); // or it's not an extension method or it's a static extension method
         }
 
-        internal static ReflectedField GetReflectedField(FieldInfo info) {
-            ReflectedField res;
+        internal static PythonTypeSlot GetReflectedField(FieldInfo info) {
+            PythonTypeSlot res;
 
             NameType nt = NameType.Field;
             if (!PythonBinder.IsExtendedType(info.DeclaringType) &amp;&amp; 
@@ -675,7 +695,28 @@ namespace IronPython.Runtime.Operations {
 
             lock (_fieldCache) {
                 if (!_fieldCache.TryGetValue(info, out res)) {
-                    _fieldCache[info] = res = new ReflectedField(info, nt);
+                    if (nt == NameType.PythonField &amp;&amp; info.IsLiteral) {
+                        if (info.FieldType == typeof(int)) {
+                            res = new PythonTypeUserDescriptorSlot(
+                                ScriptingRuntimeHelpers.Int32ToObject((int)info.GetRawConstantValue()),
+                                true
+                            );
+                        } else if (info.FieldType == typeof(bool)) {
+                            res = new PythonTypeUserDescriptorSlot(
+                                ScriptingRuntimeHelpers.BooleanToObject((bool)info.GetRawConstantValue()),
+                                true
+                            );
+                        } else {
+                            res = new PythonTypeUserDescriptorSlot(
+                                info.GetValue(null),
+                                true
+                            );
+                        }
+                    } else {
+                        res = new ReflectedField(info, nt);
+                    }
+
+                    _fieldCache[info] = res;
                 }
             }
 
@@ -727,13 +768,10 @@ namespace IronPython.Runtime.Operations {
                 if ((getter != null &amp;&amp; getter.IsDefined(typeof(PythonHiddenAttribute), true)) ||
                     setter != null &amp;&amp; setter.IsDefined(typeof(PythonHiddenAttribute), true)) {
                     nt = NameType.Property;
-                }
+                }                
 
                 ExtensionPropertyTracker ept = pt as ExtensionPropertyTracker;
-                if (ept != null) {
-                    rp = new ReflectedExtensionProperty(new ExtensionPropertyInfo(pt.DeclaringType,
-                        getter ?? setter), nt);
-                } else {
+                if (ept == null) {
                     ReflectedPropertyTracker rpt = pt as ReflectedPropertyTracker;
                     Debug.Assert(rpt != null);
 
@@ -742,25 +780,40 @@ namespace IronPython.Runtime.Operations {
                         nt = NameType.Property;
                     }
 
-                    if (pt.GetIndexParameters().Length &gt; 0) {
-                        rp = new ReflectedIndexer(((ReflectedPropertyTracker)pt).Property, NameType.Property, privateBinding);
-                    } else if (allProperties != null &amp;&amp; allProperties.Count &gt; 1) {
+                    if (pt.GetIndexParameters().Length == 0) {
                         List&lt;MethodInfo&gt; getters = new List&lt;MethodInfo&gt;();
                         List&lt;MethodInfo&gt; setters = new List&lt;MethodInfo&gt;();
-                        for (int i = 0; i &lt; allProperties.Count; i++) {
-                            MethodInfo method = ((PropertyTracker)allProperties[i]).GetGetMethod(privateBinding);
+
+                        IList&lt;ExtensionPropertyTracker&gt; overriddenProperties = NewTypeMaker.GetOverriddenProperties((getter ?? setter).DeclaringType, pt.Name);
+                        foreach (ExtensionPropertyTracker tracker in overriddenProperties) {
+                            MethodInfo method = tracker.GetGetMethod(privateBinding);
+                            if (method != null) {
+                                getters.Add(method);
+                            }
+
+                            method = tracker.GetSetMethod(privateBinding);
+                            if (method != null) {
+                                setters.Add(method);
+                            }
+                        }
+
+                        foreach (PropertyTracker propTracker in allProperties) {
+                            MethodInfo method = propTracker.GetGetMethod(privateBinding);
                             if (method != null) {
                                 getters.Add(method);
                             }
-                            method = ((PropertyTracker)allProperties[i]).GetSetMethod(privateBinding);
+
+                            method = propTracker.GetSetMethod(privateBinding);
                             if (method != null) {
                                 setters.Add(method);
                             }
                         }
                         rp = new ReflectedProperty(rpt.Property, getters.ToArray(), setters.ToArray(), nt);
                     } else {
-                        rp = new ReflectedProperty(rpt.Property, getter, setter, nt);
+                        rp = new ReflectedIndexer(((ReflectedPropertyTracker)pt).Property, NameType.Property, privateBinding);
                     }
+                } else {
+                    rp = new ReflectedExtensionProperty(new ExtensionPropertyInfo(pt.DeclaringType, getter ?? setter), nt);
                 }
 
                 _propertyCache[pt] = rp;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Operations/PythonTypeOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -179,7 +179,7 @@ namespace IronPython.Runtime {
         internal readonly object _codeCleanupLock = new object(), _codeUpdateLock = new object();
         internal int _codeCount, _nextCodeCleanup = 200;
         private int _recursionLimit;
-        internal bool _enableTracing;
+        private bool _enableTracing;
 
         /// &lt;summary&gt;
         /// Creates a new PythonContext not bound to Engine.
@@ -221,10 +221,9 @@ namespace IronPython.Runtime {
             }
 
             if (_options.Frames) {
-                _systemState.Dict[SymbolTable.StringToId(&quot;_getframe&quot;)] = BuiltinFunction.MakeMethod(&quot;_getframe&quot;, 
+                _systemState.Dict[SymbolTable.StringToId(&quot;_getframe&quot;)] = BuiltinFunction.MakeFunction(&quot;_getframe&quot;, 
                     ArrayUtils.ConvertAll(typeof(SysModule).GetMember(&quot;_getframeImpl&quot;), (x) =&gt; (MethodBase)x), 
-                    typeof(SysModule), 
-                    FunctionType.Function);
+                    typeof(SysModule));
             }
 
             List path = new List(_options.SearchPaths);
@@ -296,7 +295,7 @@ namespace IronPython.Runtime {
 
         internal bool EnableTracing {
             get {
-                return _enableTracing;
+                return _enableTracing || PythonOptions.Tracing;
             }
             set {
                 lock (_codeUpdateLock) {
@@ -632,16 +631,19 @@ namespace IronPython.Runtime {
 
 
         private Compiler.CompilationMode GetCompilationMode(PythonCompilerOptions options, SourceUnit source) {
+            if ((options.Module &amp; ModuleOptions.ExecOrEvalCode) != 0) {
+                return CompilationMode.Lookup;
+            }
 
             if (ShouldInterpret(options, source)) {
                 // force collectible code for the adaptive compiler.  Technically these should
                 // be orthogonal but 
-                return Compiler.CompilationMode.Collectable;
+                return CompilationMode.Collectable;
             }
 
             return ((_options.Optimize || options.Optimized) &amp;&amp; !_options.LightweightScopes) ?
-                Compiler.CompilationMode.Uncollectable :
-                Compiler.CompilationMode.Collectable;
+                CompilationMode.Uncollectable :
+                CompilationMode.Collectable;
         }
 
         internal bool ShouldInterpret(PythonCompilerOptions options, SourceUnit source) {
@@ -727,7 +729,7 @@ namespace IronPython.Runtime {
 
         protected override ScriptCode/*!*/ LoadCompiledCode(Delegate/*!*/ method, string path, string customData) {
             SourceUnit su = new SourceUnit(this, NullTextContentProvider.Null, path, SourceCodeKind.File);
-            return new OnDiskScriptCode((Func&lt;Scope, LanguageContext, object&gt;)method, su, customData);
+            return new OnDiskScriptCode((Func&lt;CodeContext, FunctionCode, object&gt;)method, su, customData);
         }
 
         public override SourceCodeReader/*!*/ GetSourceReader(Stream/*!*/ stream, Encoding/*!*/ defaultEncoding, string path) {
@@ -3713,23 +3715,23 @@ namespace IronPython.Runtime {
         internal void RegisterTracebackHandler() {
             Debug.Assert(_tracePipeline != null);   // ensure debug context should have been called
 
-            if (_tracePipeline.TraceCallback == null) {
-                _tracePipeline.TraceCallback = _tracebackListeners.Peek();
-                EnableTracing = true;
-            }
+            _tracePipeline.TraceCallback = _tracebackListeners.Peek();
+            EnableTracing = true;
         }
 
         internal void UnregisterTracebackHandler() {
             Debug.Assert(_tracePipeline != null);  // ensure debug context should have been called
 
-            if (_tracePipeline.TraceCallback != null) {
-                _tracePipeline.TraceCallback = null;
-                EnableTracing = false;
-            }
+            _tracePipeline.TraceCallback = null;
+            EnableTracing = false;
         }
 
         internal void PushTracebackHandler(PythonTracebackListener listener) {
             if (_debugContext != null) {
+                while (_tracebackListeners.Count &gt; 0 &amp;&amp; _tracebackListeners.Peek().ExceptionThrown) {
+                    // remove any orphaned traceback listeners that are just doing pops
+                    _tracebackListeners.Pop();
+                }
                 _tracebackListeners.Push(listener);
             }
         }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonContext.cs</filename>
    </modified>
    <modified>
      <diff>@@ -582,6 +582,9 @@ namespace IronPython.Runtime {
             return true;
         }
 
+        public const object __hash__ = null;
+
+
         #endregion
 
         #region IDictionary Members</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonDictionary.cs</filename>
    </modified>
    <modified>
      <diff>@@ -14,25 +14,49 @@
  * ***************************************************************************/
 
 using System;
-using System.Collections.Generic;
-using System.Text;
-using Microsoft.Scripting.Runtime;
 using System.Reflection;
 
+using Microsoft.Scripting.Runtime;
+using Microsoft.Scripting.Utils;
+
 namespace IronPython.Runtime {
+    /// &lt;summary&gt;
+    /// A DynamicStackFrame which has Python specific data.  Currently this
+    /// includes the code context which may provide access to locals and the
+    /// function code object which is needed to build frame objects from.
+    /// &lt;/summary&gt;
     class PythonDynamicStackFrame : DynamicStackFrame {
-        private CodeContext _context;
+        private readonly CodeContext/*!*/ _context;
+        private readonly FunctionCode/*!*/ _code;
 
-        public PythonDynamicStackFrame(CodeContext context, MethodBase method, string funcName, string filename, int line)
+        public PythonDynamicStackFrame(CodeContext/*!*/ context, FunctionCode/*!*/ funcCode, MethodBase method, string funcName, string filename, int line)
             : base(method, funcName, filename, line) {
+            Assert.NotNull(context, funcCode);
+
             _context = context;
+            _code = funcCode;
         }
 
-        public CodeContext CodeContext {
+        /// &lt;summary&gt;
+        /// Gets the code context of the function.
+        /// 
+        /// If the function included a call to locals() or the FullFrames
+        /// option is enabled then the code context includes all local variables.
+        /// &lt;/summary&gt;
+        public CodeContext/*!*/ CodeContext {
             get {
                 return _context;
             }
         }
 
+        /// &lt;summary&gt;
+        /// Gets the code object for this frame.  This is used in creating
+        /// the trace back.
+        /// &lt;/summary&gt;
+        public FunctionCode/*!*/ Code {
+            get {
+                return _code;
+            }
+        }
     }
 }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonDynamicStackFrame.cs</filename>
    </modified>
    <modified>
      <diff>@@ -21,6 +21,7 @@ using System.IO;
 using System.Runtime.InteropServices;
 using System.Text;
 
+using Microsoft.Scripting;
 using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
@@ -964,12 +965,17 @@ namespace IronPython.Runtime {
 
             try {
                 Stream stream;
-                if (Environment.OSVersion.Platform == PlatformID.Win32NT &amp;&amp; name == &quot;nul&quot;) {
-                    stream = Stream.Null;
-                } else if (buffering &lt;= 0) {
-                    stream = PythonContext.GetContext(context).DomainManager.Platform.OpenInputFileStream(name, fmode, faccess, fshare);
-                } else {
-                    stream = PythonContext.GetContext(context).DomainManager.Platform.OpenInputFileStream(name, fmode, faccess, fshare, buffering);
+                try {
+                    if (Environment.OSVersion.Platform == PlatformID.Win32NT &amp;&amp; name == &quot;nul&quot;) {
+                        stream = Stream.Null;
+                    } else if (buffering &lt;= 0) {
+                        stream = PythonContext.GetContext(context).DomainManager.Platform.OpenInputFileStream(name, fmode, faccess, fshare);
+                    } else {
+                        stream = PythonContext.GetContext(context).DomainManager.Platform.OpenInputFileStream(name, fmode, faccess, fshare, buffering);
+                    }
+                } catch (IOException e) {
+                    AddFilename(context, name, e);
+                    throw;
                 }
 
                 // we want to own the lifetime of the stream so we can flush &amp; dispose in our finalizer...
@@ -980,10 +986,21 @@ namespace IronPython.Runtime {
                 __init__(stream, PythonContext.GetContext(context).DefaultEncoding, name, mode);
                 this._isOpen = true;
             } catch (UnauthorizedAccessException e) {
-                throw new IOException(e.Message, e);
+                throw ToIoException(context, name, e);
             }
         }
 
+        internal static Exception ToIoException(CodeContext context, string name, UnauthorizedAccessException e) {
+            Exception excp = new IOException(e.Message, e);
+            AddFilename(context, name, excp);
+            return excp;
+        }
+
+        internal static void AddFilename(CodeContext context, string name, Exception ioe) {
+            var pyExcep = PythonExceptions.ToPython(ioe);
+            PythonOps.SetAttr(context, pyExcep, SymbolTable.StringToId(&quot;filename&quot;), name);
+        }
+
         internal static void ValidateMode(string mode) {
             FileMode fmode;
             FileAccess access;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonFile.cs</filename>
    </modified>
    <modified>
      <diff>@@ -193,7 +193,7 @@ namespace IronPython.Runtime {
         private bool CanOptimizeCall(Binding.PythonInvokeBinder binder, object[] args) {
             return args.Length &gt;= (NormalArgumentCount - _defaults.Length) &amp;&amp;
                 args.Length &lt;= NormalArgumentCount &amp;&amp;
-                Defaults.Length &lt;= 13 &amp;&amp;
+                ArgNames.Length &lt; MaxGeneratedFunctionArgs &amp;&amp;
                 !binder.Signature.HasDictionaryArgument() &amp;&amp;
                 !binder.Signature.HasKeywordArgument() &amp;&amp;
                 !binder.Signature.HasListArgument() &amp;&amp;
@@ -405,6 +405,8 @@ namespace IronPython.Runtime {
         // *** BEGIN GENERATED CODE ***
         // generated by function: function_callers from: generate_calls.py
 
+        internal const int MaxGeneratedFunctionArgs = 14;
+
 
         class FunctionCaller&lt;T0&gt; : FunctionCaller {
             public FunctionCaller(int compat) : base(compat) { }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonFunction.Generated.cs</filename>
    </modified>
    <modified>
      <diff>@@ -45,7 +45,7 @@ namespace IronPython.Runtime {
         public readonly MutableTuple Closure;
 
         private object[]/*!*/ _defaults;                // the default parameters of the method
-        private IAttributesCollection _dict;            // a dictionary to story arbitrary members on the function object
+        internal IAttributesCollection _dict;           // a dictionary to story arbitrary members on the function object
         private object _module;                         // the module name
 
         private int _id, _compat;                       // ID/Compat flags used for testing in rules
@@ -403,43 +403,6 @@ namespace IronPython.Runtime {
        
         #region Custom member lookup operators
 
-        [SpecialName]
-        public void SetMemberAfter(CodeContext context, string name, object value) {
-            EnsureDict();
-
-            _dict[SymbolTable.StringToId(name)] = value;
-        }
-
-        [SpecialName]
-        public object GetBoundMember(CodeContext context, string name) {
-            object value;
-            if (_dict != null &amp;&amp; _dict.TryGetValue(SymbolTable.StringToId(name), out value)) {
-                return value;
-            }
-            return OperationFailed.Value;
-        }
-
-        [SpecialName]
-        public bool DeleteMember(CodeContext context, string name) {
-            switch (name) {
-                case &quot;func_dict&quot;:
-                case &quot;__dict__&quot;:
-                    throw PythonOps.TypeError(&quot;function's dictionary may not be deleted&quot;);
-                case &quot;__doc__&quot;:
-                case &quot;func_doc&quot;:
-                    _doc = null;
-                    return true;
-                case &quot;func_defaults&quot;:
-                    _defaults = ArrayUtils.EmptyObjects;
-                    _compat = CalculatedCachedCompat();
-                    return true;
-            }
-
-            if (_dict == null) return false;
-
-            return _dict.Remove(SymbolTable.StringToId(name));
-        }
-
         IList&lt;string&gt; IMembersList.GetMemberNames() {
             return PythonOps.GetStringMemberList(this);
         }
@@ -485,7 +448,7 @@ namespace IronPython.Runtime {
 
         #region Private APIs
 
-        private IAttributesCollection EnsureDict() {
+        internal IAttributesCollection EnsureDict() {
             if (_dict == null) {
                 Interlocked.CompareExchange(ref _dict, (IAttributesCollection)PythonDictionary.MakeSymbolDictionary(), null);
             }
@@ -598,6 +561,7 @@ namespace IronPython.Runtime {
 
         #endregion
 
+        [Python3Warning(&quot;cell comparisons not supported in 3.x&quot;)]
         public int __cmp__(object other) {
             ClosureCell cc = other as ClosureCell;
             if (cc == null) throw PythonOps.TypeError(&quot;cell.__cmp__(x,y) expected cell, got {0}&quot;, PythonTypeOps.GetName(other));</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonFunction.cs</filename>
    </modified>
    <modified>
      <diff>@@ -48,7 +48,7 @@ namespace IronPython {
         private readonly bool _noSite;
         private readonly bool _ignoreEnvironment;
         private readonly bool _verbose;
-        private readonly bool _frames, _fullFrames;
+        private readonly bool _frames, _fullFrames, _tracing;
         private readonly Version _version;
         private readonly int? _gcStress;
         private bool _enableProfiler;
@@ -177,6 +177,18 @@ namespace IronPython {
             }
         }
 
+        /// &lt;summary&gt;
+        /// Tracing is always available.  Without this option tracing is only enabled when sys.settrace
+        /// is called. This means code that was already running before sys.settrace will not be debuggable.
+        /// 
+        /// With this option pdb.set_trace and pdb.post_mortem will always work properly.
+        /// &lt;/summary&gt;
+        public bool Tracing {
+            get {
+                return _tracing;
+            }
+        }
+
         /// &lt;summary&gt; 
         /// Severity of a warning that indentation is formatted inconsistently.
         /// &lt;/summary&gt;
@@ -250,6 +262,7 @@ namespace IronPython {
             _fullFrames = GetOption(options, &quot;FullFrames&quot;, false);
             _frames = _fullFrames || GetOption(options, &quot;Frames&quot;, false);
             _gcStress = GetOption&lt;int?&gt;(options, &quot;GCStress&quot;, null);
+            _tracing = GetOption(options, &quot;Tracing&quot;, false);
 
             object value;
             if (options != null &amp;&amp; options.TryGetValue(&quot;PythonVersion&quot;, out value)) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonOptions.cs</filename>
    </modified>
    <modified>
      <diff>@@ -28,23 +28,23 @@ using Debugging = Microsoft.Scripting.Debugging;
 
 namespace IronPython.Runtime {
     internal sealed class TraceThread {
-        public Stack&lt;TraceBackFrame&gt; Frames;
+        public List&lt;TraceBackFrame&gt; Frames;
         public bool InTraceback;
     }
 
     internal sealed class PythonTracebackListener : Debugging.ITraceCallback {
+        private readonly PythonContext _pythonContext;
+        [ThreadStatic] private static TraceThread _threads;
+        [ThreadStatic] private TracebackDelegate _globalTraceDispatch;
+        [ThreadStatic] private object _globalTraceObject;
+        private bool _exceptionThrown;
+        
 #if PROFILE_SUPPORT
         private bool _profile;
 #endif
-        private TracebackDelegate _globalTraceDispatch;
-        private object _globalTraceObject;
-        private PythonContext _pythonContext;
-
-        private ThreadLocal&lt;TraceThread&gt; _threads;
 
         internal PythonTracebackListener(PythonContext pythonContext) {
             _pythonContext = pythonContext;
-            _threads = new ThreadLocal&lt;TraceThread&gt;();
         }
 
         internal PythonContext PythonContext {
@@ -53,6 +53,12 @@ namespace IronPython.Runtime {
             }
         }
 
+        internal bool ExceptionThrown {
+            get {
+                return _exceptionThrown;
+            }
+        }
+
         internal void SetTrace(object function, TracebackDelegate traceDispatch) {
             _globalTraceDispatch = traceDispatch;
             _globalTraceObject = function;
@@ -69,22 +75,16 @@ namespace IronPython.Runtime {
         }
 #endif
 
-        internal TraceThread GetCurrentThread() {
-            return _threads.Value;
+        internal static TraceThread GetCurrentThread() {
+            return _threads;
         }
 
-        private TraceThread GetOrCreateThread() {
-            TraceThread thread = _threads.Value;
+        private static TraceThread GetOrCreateThread() {
+            TraceThread thread = _threads;
 
             if (thread == null) {
-                thread = new TraceThread();
-                _threads.Value = thread;
-                thread.Frames = new Stack&lt;TraceBackFrame&gt;();
-
-                // Create the &lt;module&gt; (bottom) frame
-                thread.Frames.Push(
-                    new TraceBackFrame(_pythonContext.SharedContext, new PythonDictionary(), new PythonDictionary(), new FunctionCode(),
-                    new TraceBackFrame(_pythonContext.SharedContext, new PythonDictionary(), new PythonDictionary(), new FunctionCode(), null)));
+                _threads = thread = new TraceThread();
+                thread.Frames = new List&lt;TraceBackFrame&gt;();
             }
 
             return thread;
@@ -102,12 +102,14 @@ namespace IronPython.Runtime {
             }
 
             TracebackDelegate traceDispatch = null;
+            object traceDispatchObject = null;
             TraceThread thread = GetOrCreateThread();
             TraceBackFrame pyFrame;
 
             try {
                 if (kind == Debugging.TraceEventKind.FrameEnter) {
                     traceDispatch = _globalTraceDispatch;
+                    traceDispatchObject = _globalTraceObject;
                     /*
                     if (thread.Frames.Count == 1 &amp;&amp; traceDispatch != null) {
                         // Dispatch &quot;line&quot; trace for &lt;module&gt; frame
@@ -120,19 +122,21 @@ namespace IronPython.Runtime {
                     pyFrame = new TraceBackFrame(
                         this,
                         properties.Code,
-                        thread.Frames.Count == 0 ? null : thread.Frames.Peek(),
+                        thread.Frames.Count == 0 ? null : thread.Frames[thread.Frames.Count - 1],
                         properties,
                         scopeCallback
                     );
-                    thread.Frames.Push(pyFrame);
 
-                    pyFrame.f_trace = traceDispatch;
+                    thread.Frames.Add(pyFrame);
+
+                    pyFrame.Setf_trace(traceDispatchObject);
                 } else {
                     if (thread.Frames.Count == 0) {
                         return;
                     }
-                    pyFrame = thread.Frames.Peek();
-                    traceDispatch = pyFrame.f_trace;
+                    pyFrame = thread.Frames[thread.Frames.Count - 1];
+                    traceDispatch = pyFrame.TraceDelegate;
+                    traceDispatchObject = pyFrame.Getf_trace();
                 }
 
                 // Update the current line
@@ -140,12 +144,12 @@ namespace IronPython.Runtime {
                     pyFrame._lineNo = sourceSpan.Start.Line;
                 }
 
-                if (traceDispatch != null) {
-                    DispatchTrace(thread, kind, payload, traceDispatch, pyFrame);
+                if (traceDispatchObject != null &amp;&amp; !_exceptionThrown) {
+                    DispatchTrace(thread, kind, payload, traceDispatch, traceDispatchObject, pyFrame);
                 }
             } finally {
                 if (kind == Debugging.TraceEventKind.FrameExit &amp;&amp; thread.Frames.Count &gt; 0) {
-                    thread.Frames.Pop();
+                    thread.Frames.RemoveAt(thread.Frames.Count - 1);
                 }
             }
         }
@@ -153,7 +157,7 @@ namespace IronPython.Runtime {
         #endregion
 
         
-        private void DispatchTrace(TraceThread thread, Debugging.TraceEventKind kind, object payload, TracebackDelegate traceDispatch, TraceBackFrame pyFrame) {
+        private void DispatchTrace(TraceThread thread, Debugging.TraceEventKind kind, object payload, TracebackDelegate traceDispatch, object traceDispatchObject, TraceBackFrame pyFrame) {
             object args = null;
 
             // Prepare the event
@@ -165,7 +169,7 @@ namespace IronPython.Runtime {
                     traceEvent = &quot;exception&quot;;
                     object pyException = PythonExceptions.ToPython((Exception)payload);
                     object pyType = ((IPythonObject)pyException).PythonType;
-                    args = new PythonTuple(new object[] { pyType, pyException, null });
+                    args = PythonTuple.MakeTuple(pyType, pyException, null);
                     break;
                 case Debugging.TraceEventKind.FrameExit:
                     traceEvent = &quot;return&quot;;
@@ -173,25 +177,22 @@ namespace IronPython.Runtime {
                     break;
             }
 
-            bool traceDispatchThrew = false;
+            bool traceDispatchThrew = true;
             _pythonContext.TracePipeline.TraceCallback = null;
             thread.InTraceback = true;
             try {
                 traceDispatch = traceDispatch(pyFrame, traceEvent, args);
-            } catch {
-                // We're matching CPython's behavior here.  If the trace dispatch throws any exceptions
-                // we don't re-enable tracebacks
-                traceDispatchThrew = true;
-                _globalTraceObject = _globalTraceDispatch = null;
-
-                throw;
+                traceDispatchThrew = false;
             } finally {
                 thread.InTraceback = false;
-                if (!traceDispatchThrew) {
-                    // renable tracebacks
-                    _pythonContext.TracePipeline.TraceCallback = this;
-
-                    pyFrame.f_trace = traceDispatch;
+                _pythonContext.TracePipeline.TraceCallback = this;
+
+                if (traceDispatchThrew) {
+                    // We're matching CPython's behavior here.  If the trace dispatch throws any exceptions
+                    // we don't re-enable tracebacks.  We need to leave the trace callback in place though
+                    // so that we can pop our frames.
+                    _globalTraceObject = _globalTraceDispatch = null;
+                    _exceptionThrown = true;
                 }
             }
         }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonTracebackListener.cs</filename>
    </modified>
    <modified>
      <diff>@@ -567,14 +567,21 @@ namespace IronPython.Runtime {
         }
 
         bool IValueEquality.ValueEquals(object other) {
-            if (Object.ReferenceEquals(other, this)) return true;
+            if (!Object.ReferenceEquals(other, this)) {
+                PythonTuple l = other as PythonTuple;
+                if (l == null || _data.Length != l._data.Length) {
+                    return false;
+                }
 
-            PythonTuple l = other as PythonTuple;
-            if (l == null) return false;
+                for (int i = 0; i &lt; _data.Length; i++) {
+                    object obj1 = _data[i], obj2 = l._data[i];
 
-            if (_data.Length != l._data.Length) return false;
-            for (int i = 0; i &lt; _data.Length; i++) {
-                if (!PythonOps.EqualRetBool(_data[i], l._data[i])) return false;
+                    if (Object.ReferenceEquals(obj1, obj2)) {
+                        continue;
+                    } else if (!PythonOps.EqualRetBool(obj1, obj2)) {
+                        return false;
+                    }
+                }
             }
             return true;
         }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonTuple.cs</filename>
    </modified>
    <modified>
      <diff>@@ -467,7 +467,9 @@ namespace IronPython.Runtime {
         }
 
         public void remove([NotNull]SetCollection o) {
-            remove(FrozenSetCollection.Make(((IEnumerable)o).GetEnumerator()));
+            if (!_items.RemoveAlwaysHash(FrozenSetCollection.Make(((IEnumerable)o).GetEnumerator()))) {
+                throw PythonOps.KeyError(o);
+            }
         }
 
         public void remove(object o) {
@@ -690,6 +692,9 @@ namespace IronPython.Runtime {
             return !((IValueEquality)this).ValueEquals(other);
         }
 
+        public const object __hash__ = null;
+
+
         #endregion
 
         #region IEnumerable&lt;object&gt; Members</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Set.cs</filename>
    </modified>
    <modified>
      <diff>@@ -56,12 +56,23 @@ namespace IronPython.Runtime.Types {
 
         #region Static factories
 
-        internal static BuiltinFunction/*!*/ MakeMethod(string name, MethodBase info, Type declaringType, FunctionType ft) {
-            Debug.Assert(!info.ContainsGenericParameters);
+        /// &lt;summary&gt;
+        /// Creates a new builtin function for a static .NET function.  This is used for module methods
+        /// and well-known __new__ methods.
+        /// &lt;/summary&gt;
+        internal static BuiltinFunction/*!*/ MakeFunction(string name, MethodBase[] infos, Type declaringType) {
+#if DEBUG
+            foreach (MethodBase mi in infos) {
+                Debug.Assert(!mi.ContainsGenericParameters);
+            }
+#endif
 
-            return new BuiltinFunction(name, new MethodBase[] { info }, declaringType, ft);
+            return new BuiltinFunction(name, infos, declaringType, FunctionType.AlwaysVisible | FunctionType.Function);
         }
 
+        /// &lt;summary&gt;
+        /// Creates a built-in function for a .NET method declared on a type.
+        /// &lt;/summary&gt;
         internal static BuiltinFunction/*!*/ MakeMethod(string name, MethodBase[] infos, Type declaringType, FunctionType ft) {
             foreach (MethodBase mi in infos) {
                 if (mi.ContainsGenericParameters) {
@@ -72,18 +83,6 @@ namespace IronPython.Runtime.Types {
             return new BuiltinFunction(name, infos, declaringType, ft);
         }
 
-        internal static BuiltinFunction/*!*/ MakeOrAdd(BuiltinFunction existing, string name, MethodBase mi, Type declaringType, FunctionType funcType) {
-            Debug.Assert(!mi.ContainsGenericParameters);
-            PythonBinder.AssertNotExtensionType(declaringType);
-
-            if (existing != null) {
-                existing._data.AddMethod(mi);
-                return existing;
-            } else {
-                return MakeMethod(name, mi, declaringType, funcType);
-            }
-        }
-
         internal virtual BuiltinFunction/*!*/ BindToInstance(object instance) {
             return new BuiltinFunction(instance, _data);
         }
@@ -448,7 +447,7 @@ namespace IronPython.Runtime.Types {
             // add any warnings that are applicable for calling this function
             WarningInfo info;
 
-            if (target.Method != null &amp;&amp; BindingWarnings.ShouldWarn(PythonContext.GetPythonContext(call).Binder, target.Method, out info)) {
+            if (target.Method != null &amp;&amp; BindingWarnings.ShouldWarn(PythonContext.GetPythonContext(call), target.Method, out info)) {
                 res = info.AddWarning(codeContext, res);
             }            
 
@@ -476,16 +475,17 @@ namespace IronPython.Runtime.Types {
         }
 
         internal static DynamicMetaObject TranslateArguments(DynamicMetaObjectBinder call, Expression codeContext, DynamicMetaObject function, DynamicMetaObject/*!*/[] args, bool hasSelf, string name) {
+            if (hasSelf) {
+                args = ArrayUtils.RemoveFirst(args);
+            }
+
             CallSignature sig = BindingHelpers.GetCallSignature(call);
             if (sig.HasDictionaryArgument()) {
                 int index = sig.IndexOf(ArgumentType.Dictionary);
-                if (hasSelf) {
-                    args = ArrayUtils.RemoveFirst(args);
-                }
 
                 DynamicMetaObject dict = args[index];
 
-                if (!(dict.Value is IDictionary)) {
+                if (!(dict.Value is IDictionary) &amp;&amp; dict.Value != null) {
                     // The DefaultBinder only handles types that implement IDictionary.  Here we have an
                     // arbitrary user-defined mapping type.  We'll convert it into a PythonDictionary
                     // and then have an embedded dynamic site pass that dictionary through to the default
@@ -523,15 +523,10 @@ namespace IronPython.Runtime.Types {
 
             if (sig.HasListArgument()) {
                 int index = sig.IndexOf(ArgumentType.List);
-                if (hasSelf) {
-                    args = ArrayUtils.RemoveFirst(args);
-                }
-
                 DynamicMetaObject str = args[index];
 
                  // TODO: ANything w/ __iter__ that's not an IList&lt;object&gt;
-                if (str.Value is string || 
-                    str.Value is XRange) {
+                if (!(str.Value is IList&lt;object&gt;) &amp;&amp; str.Value is IEnumerable) {
                     // The DefaultBinder only handles types that implement IList&lt;object&gt;.  Here we have a
                     // string.  We'll convert it into a tuple
                     // and then have an embedded dynamic site pass that tuple through to the default
@@ -541,10 +536,9 @@ namespace IronPython.Runtime.Types {
                     dynamicArgs[index + 1] = new DynamicMetaObject(
                         Expression.Call(
                            typeof(PythonOps).GetMethod(&quot;MakeTupleFromSequence&quot;),
-                           args[index].Expression
+                           Expression.Convert(args[index].Expression, typeof(object))
                         ),
-                        BindingRestrictions.Empty,
-                        PythonOps.MakeTupleFromSequence(str.Value)
+                        BindingRestrictions.Empty
                     );
 
                     if (call is IPythonSite) {
@@ -629,7 +623,7 @@ namespace IronPython.Runtime.Types {
             // add any warnings that are applicable for calling this function
             WarningInfo info;
 
-            if (target.Method != null &amp;&amp; BindingWarnings.ShouldWarn(PythonContext.GetPythonContext(call).Binder, target.Method, out info)) {
+            if (target.Method != null &amp;&amp; BindingWarnings.ShouldWarn(PythonContext.GetPythonContext(call), target.Method, out info)) {
                 res = info.AddWarning(res);
             }
 
@@ -712,6 +706,31 @@ namespace IronPython.Runtime.Types {
             return lres &gt; 0 ? 1 : -1;
         }
 
+        // these are present in CPython but always return NotImplemented.
+        [return: MaybeNotImplemented]
+        [Python3Warning(&quot;builtin_function_or_method order comparisons not supported in 3.x&quot;)]
+        public static NotImplementedType operator &gt;(BuiltinFunction self, BuiltinFunction other) {
+            return PythonOps.NotImplemented;
+        }
+
+        [return: MaybeNotImplemented]
+        [Python3Warning(&quot;builtin_function_or_method order comparisons not supported in 3.x&quot;)]
+        public static NotImplementedType operator &lt;(BuiltinFunction self, BuiltinFunction other) {
+            return PythonOps.NotImplemented;
+        }
+
+        [return: MaybeNotImplemented]
+        [Python3Warning(&quot;builtin_function_or_method order comparisons not supported in 3.x&quot;)]
+        public static NotImplementedType operator &gt;=(BuiltinFunction self, BuiltinFunction other) {
+            return PythonOps.NotImplemented;
+        }
+
+        [return: MaybeNotImplemented]
+        [Python3Warning(&quot;builtin_function_or_method order comparisons not supported in 3.x&quot;)]
+        public static NotImplementedType operator &lt;=(BuiltinFunction self, BuiltinFunction other) {
+            return PythonOps.NotImplemented;
+        }
+
         public int __hash__(CodeContext/*!*/ context) {
             return PythonOps.Hash(context, _instance) ^ PythonOps.Hash(context, _data);
         }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Types/BuiltinFunction.cs</filename>
    </modified>
    <modified>
      <diff>@@ -1614,59 +1614,25 @@ namespace IronPython.Runtime.Types {
                 }
             }
         }
-
-        private static void StoreOverriddenProperty(MethodInfo mi, string newName) {
-            Type baseType = mi.DeclaringType.BaseType;
-
-            string propName = newName.Substring(4); // get_ or set_
-            ExtensionPropertyTracker newProp = null;
-            foreach (PropertyInfo pi in baseType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy)) {
-                if (pi.Name == propName) {
-                    if (newName.StartsWith(&quot;get_&quot;)) {
-                        newProp = AddPropertyInfo(propName, mi, null);
-                    } else if (newName.StartsWith(&quot;set_&quot;)) {
-                        newProp = AddPropertyInfo(propName, null, mi);
-                    }
-                }
-            }
-
-            if (newProp != null) {
-                // back-patch any existing functions so that cached rules will work
-                // when called again...
-                foreach (ReflectedGetterSetter rg in PythonTypeOps._propertyCache.Values) {
-                    if (rg.DeclaringType != baseType ||
-                        rg.__name__ != newProp.Name) {
-                        continue;
-                    }
-
-                    if (newProp.GetGetMethod(true) != null) {
-                        rg.AddGetter(newProp.GetGetMethod(true));
-                    }
-
-                    if (newProp.GetSetMethod(true) != null) {
-                        rg.AddSetter(newProp.GetSetMethod(true));
-                    }
-                }
-            }
-        }
-
+        
         private static void StoreOverriddenField(MethodInfo mi, string newName) {
             Type baseType = mi.DeclaringType.BaseType;
             string fieldName = newName.Substring(FieldGetterPrefix.Length); // get_ or set_
-            foreach (FieldInfo pi in baseType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy)) {
-                if (pi.Name == fieldName) {
-                    if (newName.StartsWith(FieldGetterPrefix)) {
-                        AddPropertyInfo(fieldName, mi, null);
-                    } else if (newName.StartsWith(FieldSetterPrefix)) {
-                        AddPropertyInfo(fieldName, null, mi);
+            lock (PythonTypeOps._propertyCache) {
+                foreach (FieldInfo pi in baseType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy)) {
+                    if (pi.Name == fieldName) {
+                        if (newName.StartsWith(FieldGetterPrefix)) {
+                            AddPropertyInfo(pi.DeclaringType, fieldName, mi, null);
+                        } else if (newName.StartsWith(FieldSetterPrefix)) {
+                            AddPropertyInfo(pi.DeclaringType, fieldName, null, mi);
+                        }
                     }
                 }
             }
         }
 
-        private static ExtensionPropertyTracker AddPropertyInfo(string/*!*/ propName, MethodInfo get, MethodInfo set) {
+        private static ExtensionPropertyTracker AddPropertyInfo(Type baseType, string/*!*/ propName, MethodInfo get, MethodInfo set) {
             MethodInfo mi = get ?? set;
-            Type baseType = mi.DeclaringType.BaseType;
 
             Dictionary&lt;string, List&lt;ExtensionPropertyTracker&gt;&gt; propInfoList;
 
@@ -1729,23 +1695,61 @@ namespace IronPython.Runtime.Types {
                         break;
                     }
                 }
-            }
 
-            lock (_overriddenMethods) {
                 Dictionary&lt;string, List&lt;MethodInfo&gt;&gt; overrideInfo;
                 if (!_overriddenMethods.TryGetValue(declType, out overrideInfo)) {
                     _overriddenMethods[declType] = overrideInfo = new Dictionary&lt;string, List&lt;MethodInfo&gt;&gt;();
                 }
 
                 List&lt;MethodInfo&gt; methods;
-                if (!overrideInfo.TryGetValue(newName, out methods)) {
-                    overrideInfo[newName] = methods = new List&lt;MethodInfo&gt;();
+                if (!overrideInfo.TryGetValue(pythonName, out methods)) {
+                    overrideInfo[pythonName] = methods = new List&lt;MethodInfo&gt;();
                 }
 
                 methods.Add(mi);
             }
         }
 
+        private static void StoreOverriddenProperty(MethodInfo mi, string newName) {
+            Type baseType = mi.DeclaringType.BaseType;
+
+            lock (PythonTypeOps._propertyCache) {
+                string propName = newName.Substring(4); // get_ or set_
+                ExtensionPropertyTracker newProp = null;
+                foreach (PropertyInfo pi in baseType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy)) {                    
+                    if (pi.Name == propName) {
+                        Type declType = pi.DeclaringType;
+                        if (newName.StartsWith(&quot;get_&quot;)) {                            
+                            newProp = AddPropertyInfo(declType, propName, mi, null);
+                        } else if (newName.StartsWith(&quot;set_&quot;)) {
+                            newProp = AddPropertyInfo(declType, propName, null, mi);
+                        }
+                    }
+                }
+
+                if (newProp != null) {
+                    // back-patch any existing properties so that cached rules will work
+                    // when called again...
+
+                    foreach (ReflectedGetterSetter rg in PythonTypeOps._propertyCache.Values) {
+                        if (rg.DeclaringType != baseType ||
+                            rg.__name__ != newProp.Name) {
+                            continue;
+                        }
+
+                        if (newProp.GetGetMethod(true) != null) {
+                            rg.AddGetter(newProp.GetGetMethod(true));
+                        }
+
+                        if (newProp.GetSetMethod(true) != null) {
+                            rg.AddSetter(newProp.GetSetMethod(true));
+                        }
+                    }
+
+                }
+            }
+        }
+
         private static IEnumerable&lt;string&gt; GetBaseName(MethodInfo mi, Dictionary&lt;string, string[]&gt; specialNames) {
             string newName;
             if (mi.Name.StartsWith(BaseMethodPrefix)) {
@@ -1763,31 +1767,33 @@ namespace IronPython.Runtime.Types {
             return specialNames[newName];
         }
 
+        /// &lt;summary&gt;
+        /// Called from PythonTypeOps - the BuiltinFunction._function lock must be held.
+        /// &lt;/summary&gt;
         internal static IList&lt;MethodInfo&gt; GetOverriddenMethods(Type type, string name) {
-            lock (_overriddenMethods) {
-                Dictionary&lt;string, List&lt;MethodInfo&gt;&gt; methods;
-                List&lt;MethodInfo&gt; res = null;
-                Type curType = type;
-                while (curType != null) {
-                    if (_overriddenMethods.TryGetValue(curType, out methods)) {
-                        List&lt;MethodInfo&gt; methodList;
-                        if (methods.TryGetValue(name, out methodList)) {
-                            if (res == null) {
-                                res = new List&lt;MethodInfo&gt;(methodList.Count);
-                            }
-                            foreach (MethodInfo method in methodList) {
-                                if (type.IsAssignableFrom(method.DeclaringType)) {
-                                    res.Add(method);
-                                }
+            Dictionary&lt;string, List&lt;MethodInfo&gt;&gt; methods;
+            List&lt;MethodInfo&gt; res = null;
+            Type curType = type;
+            while (curType != null) {
+                if (_overriddenMethods.TryGetValue(curType, out methods)) {
+                    List&lt;MethodInfo&gt; methodList;
+                    if (methods.TryGetValue(name, out methodList)) {
+                        if (res == null) {
+                            res = new List&lt;MethodInfo&gt;(methodList.Count);
+                        }
+                        foreach (MethodInfo method in methodList) {
+                            if (type.IsAssignableFrom(method.DeclaringType)) {
+                                res.Add(method);
                             }
                         }
                     }
-                    curType = curType.BaseType;
-                }
-                if (res != null) {
-                    return res;
                 }
+                curType = curType.BaseType;
+            }
+            if (res != null) {
+                return res;
             }
+        
             return new MethodInfo[0];
         }
 </diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Types/NewTypeMaker.cs</filename>
    </modified>
    <modified>
      <diff>@@ -44,6 +44,7 @@ namespace IronPython.Runtime.Types {
             if (IsSystemType ||                                         // limited numbers of these, just generate optimal code
                 IsMixedNewStyleOldStyle() ||                            // old-style classes shouldn't be commonly used
                 args.Length &gt; 5 ||                                      // and we only generate optimal code for a small number of calls.
+                HasSystemCtor ||                                        // __clrtype__ overridden and ctor doesn't take PythonType as 1st arg
                 GetType() != typeof(PythonType)) {                      // and we don't handle meta classes yet (they could override __call__)...
                 return new FastBindResult&lt;T&gt;();
             }</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Types/PythonType.Generated.cs</filename>
    </modified>
    <modified>
      <diff>@@ -374,6 +374,26 @@ type(name, bases, dict) -&gt; creates a new type instance with the given name, base
             return 0;
         }
 
+        [Python3Warning(&quot;type inequality comparisons not supported in 3.x&quot;)]
+        public static bool operator &gt;(PythonType self, PythonType other) {
+            return self.__cmp__(other) &gt; 0;
+        }
+
+        [Python3Warning(&quot;type inequality comparisons not supported in 3.x&quot;)]
+        public static bool operator &lt;(PythonType self, PythonType other) {
+            return self.__cmp__(other) &lt; 0;
+        }
+
+        [Python3Warning(&quot;type inequality comparisons not supported in 3.x&quot;)]
+        public static bool operator &gt;=(PythonType self, PythonType other) {
+            return self.__cmp__(other) &gt;= 0;
+        }
+
+        [Python3Warning(&quot;type inequality comparisons not supported in 3.x&quot;)]
+        public static bool operator &lt;=(PythonType self, PythonType other) {
+            return self.__cmp__(other) &lt;= 0;
+        }
+
         public void __delattr__(CodeContext/*!*/ context, string name) {
             DeleteCustomMember(context, SymbolTable.StringToId(name));
         }
@@ -957,7 +977,13 @@ type(name, bases, dict) -&gt; creates a new type instance with the given name, base
                 if (value) _attrs |= PythonTypeAttributes.HasDictionary;
                 else _attrs &amp;= (~PythonTypeAttributes.HasDictionary);
             }
-        }        
+        }
+
+        internal bool HasSystemCtor {
+            get {
+                return (_attrs &amp; PythonTypeAttributes.SystemCtor) != 0;
+            }
+        }
 
         internal void SetConstructor(BuiltinFunction ctor) {
             _ctor = ctor;
@@ -1758,7 +1784,31 @@ type(name, bases, dict) -&gt; creates a new type instance with the given name, base
 
             lock (_userTypeCtors) {
                 if (!_userTypeCtors.TryGetValue(_underlyingSystemType, out _ctor)) {
-                    _userTypeCtors[_underlyingSystemType] = _ctor = BuiltinFunction.MakeMethod(Name, _underlyingSystemType.GetConstructors(), _underlyingSystemType, FunctionType.Function);
+                    ConstructorInfo[] ctors = _underlyingSystemType.GetConstructors();
+
+                    bool isPythonType = false;
+                    foreach (ConstructorInfo ci in ctors) {
+                        ParameterInfo[] pis = ci.GetParameters();
+                        if((pis.Length &gt; 1 &amp;&amp; pis[0].ParameterType == typeof(CodeContext) &amp;&amp; pis[1].ParameterType == typeof(PythonType)) ||
+                            (pis.Length &gt; 0 &amp;&amp; pis[0].ParameterType == typeof(PythonType))) {
+                            isPythonType = true;
+                            break;
+                        }
+                    }
+
+                    _ctor = BuiltinFunction.MakeFunction(Name, ctors, _underlyingSystemType);
+
+                    if (isPythonType) {
+                        _userTypeCtors[_underlyingSystemType] = _ctor;
+                    } else {
+                        // __clrtype__ returned a type w/o any PythonType parameters, force this to
+                        // be created like a normal .NET type.  Presumably the user is planning on storing
+                        // the Python type in a static field or something and passing the Type object to
+                        // some .NET API which wants to Activator.CreateInstance on it w/o providing a 
+                        // PythonType object.
+                        _instanceCtor = new SystemInstanceCreator(this);
+                        _attrs |= PythonTypeAttributes.SystemCtor;
+                    }
                 }
             }
 
@@ -1950,6 +2000,14 @@ type(name, bases, dict) -&gt; creates a new type instance with the given name, base
             return hasSlot;
         }
 
+        /// &lt;summary&gt;
+        /// Gets the .NET type which is used for instances of the Python type.
+        /// 
+        /// When overridden by a metaclass enables a customization of the .NET type which
+        /// is used for instances of the Python type.  Meta-classes can construct custom
+        /// types at runtime which include new .NET methods, fields, custom attributes or
+        /// other features to better interoperate with .NET.
+        /// &lt;/summary&gt;
         [PythonHidden]
         public virtual Type __clrtype__() {
             return _underlyingSystemType;
@@ -2145,11 +2203,10 @@ type(name, bases, dict) -&gt; creates a new type instance with the given name, base
         private void AddSystemConstructors() {
             if (typeof(Delegate).IsAssignableFrom(_underlyingSystemType)) {
                 SetConstructor(
-                    BuiltinFunction.MakeMethod(
+                    BuiltinFunction.MakeFunction(
                         _underlyingSystemType.Name,
-                        typeof(DelegateOps).GetMethod(&quot;__new__&quot;),
-                        _underlyingSystemType,
-                        FunctionType.Function | FunctionType.AlwaysVisible
+                        new[] { typeof(DelegateOps).GetMethod(&quot;__new__&quot;) },
+                        _underlyingSystemType
                     )
                 );
             } else if (!_underlyingSystemType.IsAbstract) {
@@ -2273,6 +2330,12 @@ type(name, bases, dict) -&gt; creates a new type instance with the given name, base
             IsPythonType = 0x04,
             WeakReferencable = 0x08,
             HasDictionary = 0x10,
+
+            /// &lt;summary&gt;
+            /// The type has a ctor which does not accept PythonTypes.  This is used
+            /// for user defined types which implement __clrtype__
+            /// &lt;/summary&gt;
+            SystemCtor    = 0x20
         }
 
         #endregion</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Types/PythonType.cs</filename>
    </modified>
    <modified>
      <diff>@@ -167,8 +167,8 @@ namespace IronPython.Runtime.Types {
 
             [SpecialName]
             public object InPlaceAdd(CodeContext/*!*/ context, object func) {
-                if (func == null) {
-                    throw PythonOps.TypeError(&quot;event addition expected callable object, got None&quot;);
+                if (func == null || !PythonOps.IsCallable(context, func)) {
+                    throw PythonOps.TypeError(&quot;event addition expected callable object, got {0}&quot;, PythonTypeOps.GetName(func));
                 }
 
                 if (_event.Tracker.IsStatic) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Types/ReflectedEvent.cs</filename>
    </modified>
    <modified>
      <diff>@@ -33,6 +33,7 @@ namespace IronPython.Runtime.Types {
     public abstract class ReflectedGetterSetter : PythonTypeSlot {
         private MethodInfo/*!*/[]/*!*/ _getter, _setter;
         private readonly NameType _nameType;
+        private BuiltinFunction _getfunc, _setfunc;
 
         protected ReflectedGetterSetter(MethodInfo[]/*!*/ getter, MethodInfo[]/*!*/ setter, NameType nt) {
             Debug.Assert(getter != null);
@@ -50,11 +51,25 @@ namespace IronPython.Runtime.Types {
         }
 
         internal void AddGetter(MethodInfo mi) {
-            _getter = ArrayUtils.Append(_getter, mi);
+            lock (this) {
+                _getter = ArrayUtils.Append(_getter, mi);
+                MakeGetFunc();
+            }
+        }
+
+        private void MakeGetFunc() {
+            _getfunc = PythonTypeOps.GetBuiltinFunction(DeclaringType, __name__, _getter);
         }
 
         internal void AddSetter(MethodInfo mi) {
-            _setter = ArrayUtils.Append(_setter, mi);
+            lock (this) {
+                _setter = ArrayUtils.Append(_setter, mi);
+                MakeSetFunc();
+            }
+        }
+
+        private void MakeSetFunc() {
+            _setfunc = PythonTypeOps.GetBuiltinFunction(DeclaringType, __name__, _setter);
         }
 
         internal abstract Type DeclaringType {
@@ -98,7 +113,15 @@ namespace IronPython.Runtime.Types {
                 throw new MissingMemberException(&quot;unreadable property&quot;);
             }
 
-            return CallTarget(context, storage, _getter, instance, args);
+            if (_getfunc == null) {
+                lock (this) {
+                    if (_getfunc == null) {
+                        MakeGetFunc();
+                    }
+                }
+            }
+
+            return _getfunc.Call(context, storage, instance, args);
         }
 
         internal object CallTarget(CodeContext context, SiteLocalStorage&lt;CallSite&lt;Func&lt;CallSite, CodeContext, object, object[], object&gt;&gt;&gt; storage, MethodInfo[] targets, object instance, params object[] args) {
@@ -130,10 +153,18 @@ namespace IronPython.Runtime.Types {
                 return false;
             }
 
+            if (_setfunc == null) {
+                lock (this) {
+                    if (_setfunc == null) {
+                        MakeSetFunc();
+                    }
+                }
+            }
+
             if (args.Length != 0) {
-                CallTarget(context, storage, _setter, instance, ArrayUtils.Append(args, value));
+                _setfunc.Call(context, storage, instance, ArrayUtils.Append(args, value));
             } else {
-                CallTarget(context, storage, _setter, instance, value);
+                _setfunc.Call(context, storage, instance, new [] { value });
             }
 
             return true;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Types/ReflectedGetterSetter.cs</filename>
    </modified>
    <modified>
      <diff>@@ -218,7 +218,7 @@ namespace IronPython.Runtime.Types {
                 MemberGroup res;
 
                 foreach (Type curType in binder.GetContributingTypes(type)) {
-                    res = GetBaseHelperOverloads(type, name, FilterSpecialNames(binder.GetMember(curType, name), name, action));
+                    res = FilterSpecialNames(binder.GetMember(curType, name), name, action);
                     if (res.Count &gt; 0) {
                         return res;
                     }
@@ -299,15 +299,13 @@ namespace IronPython.Runtime.Types {
 
                                 Debug.Assert(opInfo.Name != &quot;Equals&quot;);
 
-                                MemberGroup res = GetBaseHelperOverloads(type, opInfo.Name, binder.GetMember(curType, opInfo.Name));
+                                MemberGroup res = binder.GetMember(curType, opInfo.Name);
                                 if (res.Count == 0 &amp;&amp; opInfo.AlternateName != null) {
                                     res = binder.GetMember(curType, opInfo.AlternateName);
                                     if (opInfo.AlternateName == &quot;Equals&quot;) {
                                         // &quot;Equals&quot; is available as an alternate method name.  Because it's also on object and Python
                                         // doesn't define it on object we need to filter it out.  
                                         res = FilterObjectEquality(res);
-                                    } else {
-                                        res = GetBaseHelperOverloads(type, opInfo.AlternateName, res);
                                     }
                                 }
 
@@ -452,9 +450,7 @@ namespace IronPython.Runtime.Types {
                             break;
                         }
                     }
-                    res = FilterSpecialNames(res, name, action);
-
-                    return GetBaseHelperOverloads(PythonTypeOps.GetFinalSystemType(type), name, res);
+                    return FilterSpecialNames(res, name, action);
                 }
 
                 return MemberGroup.EmptyGroup;
@@ -496,6 +492,7 @@ namespace IronPython.Runtime.Types {
                 // IValueEquality takes precedence over Equals which can be provided for
                 // nice .NET interop.
                 new OneOffResolver(&quot;__all__&quot;, AllResolver),
+
                 new OneOffResolver(&quot;__contains__&quot;, ContainsResolver),
                 new OneOffResolver(&quot;__dir__&quot;, DirResolver),
                 new OneOffResolver(&quot;__doc__&quot;, DocResolver),
@@ -686,9 +683,19 @@ namespace IronPython.Runtime.Types {
         /// Provides a resolution for IValueEquality.GetValueHashCode to __hash__.
         /// &lt;/summary&gt;
         private static MemberGroup/*!*/ HashResolver(MemberBinder/*!*/ binder, Type/*!*/ type) {
-            // __repr__ for normal .NET types is special, if we're a Python type then
-            // we'll use one of the built-in reprs (from object or from the type)
             if (typeof(IValueEquality).IsAssignableFrom(type) &amp;&amp; !type.IsInterface) {
+                // check and see if __new__ has been overridden by the base type.
+                foreach (Type t in binder.GetContributingTypes(type)) {
+                    if (t == typeof(ObjectOps) || t == typeof(object)) {
+                        break;
+                    }
+
+                    MemberInfo[] hash = t.GetMember(&quot;__hash__&quot;);
+                    if (hash.Length &gt; 0) {
+                        return MemberGroup.EmptyGroup;
+                    }
+                }
+
                 return new MemberGroup(typeof(IValueEquality).GetMethod(&quot;GetValueHashCode&quot;));
             }
 
@@ -1852,51 +1859,7 @@ namespace IronPython.Runtime.Types {
             }
             return mts;
         }
-
-        /// &lt;summary&gt;
-        /// Gets the base helper methods generated by NewTypeMaker for the specified method name in the given type.
-        /// 
-        /// These base helper methods just do a return base.Whatever(*args) so that we can issue super calls from
-        /// users subclasses.
-        /// &lt;/summary&gt;
-        private static MemberGroup/*!*/ GetBaseHelperOverloads(Type/*!*/ type, string/*!*/ name, MemberGroup/*!*/ res) {
-            // we only get base methods when we're looking for a type from a normal .NET type.  If it's a NewTypeMaker
-            // type then we don't want them as we'll bind to the NewTypeMaker methods which override the base helper
-            // methods.
-            if (res.Count &gt; 0 &amp;&amp; PythonTypeOps.GetFinalSystemType(type) == type) {
-                List&lt;MemberTracker&gt; newMembers = null;
-
-                IList&lt;MethodInfo&gt; overriddenMethods = NewTypeMaker.GetOverriddenMethods(type, name);
-                
-                if (overriddenMethods.Count &gt; 0) {
-                    if (newMembers == null) {
-                        newMembers = new List&lt;MemberTracker&gt;();
-                    }
-
-                    foreach (MethodInfo mi in overriddenMethods) {
-                        newMembers.Add(MemberTracker.FromMemberInfo(mi));
-                    }
-                }
-
-                IList&lt;ExtensionPropertyTracker&gt; overriddenProperties = NewTypeMaker.GetOverriddenProperties(type, name);
-                if (overriddenProperties.Count &gt; 0) {
-                    if (newMembers == null) {
-                        newMembers = new List&lt;MemberTracker&gt;();
-                    }
-
-                    foreach (ExtensionPropertyTracker tracker in overriddenProperties) {
-                        newMembers.Add(tracker);
-                    }
-                }
-
-                if (newMembers != null) {
-                    newMembers.InsertRange(0, res);
-                    res = new MemberGroup(newMembers.ToArray());
-                }
-            }            
-            return res;
-        }
-
+        
         private static MethodInfo[] GetMethodSet(string name, int expected) {
             MethodInfo[] methods = typeof(InstanceOps).GetMethods();
             MethodInfo[] filtered = new MethodInfo[expected];</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPython/Runtime/Types/TypeInfo.cs</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{811AC32C-11F3-4ED8-92A7-A7E39C2BB704}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Exe&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPythonConsole/IronPythonConsole.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{F1D861C5-D9D5-4CDA-968B-8275F5D9F6D2}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Exe&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPythonConsoleAny/IronPythonConsoleAny.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -316,7 +316,7 @@ namespace IronPythonTest.interop.net.type.clrtype {
         }
 
         public PythonType PythonType {
-            get { throw new NotImplementedException(); }
+            get { return TypeCache.Int32; }
         }
 
         public void SetPythonType(PythonType newType) {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPythonTest/ClrType.cs</filename>
    </modified>
    <modified>
      <diff>@@ -330,9 +330,9 @@ namespace IronPythonTest {
             }
 
             public override DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion) {
-                return new DynamicMetaObject(
+                return errorSuggestion ?? new DynamicMetaObject(
                     Expression.Constant(&quot;FallbackInvokeMember&quot;),
-                    target.Restrictions.Merge(BindingRestrictions.Combine(args))
+                    target.Restrictions.Merge(BindingRestrictions.Combine(args)).Merge(target.Restrict(target.LimitType).Restrictions)
                 );
             }
 
@@ -453,6 +453,19 @@ namespace IronPythonTest {
             }
         }
 
+        class MyUnaryBinder : UnaryOperationBinder {
+            public MyUnaryBinder(ExpressionType et)
+                : base(et) {
+            }
+
+            public override DynamicMetaObject FallbackUnaryOperation(DynamicMetaObject target, DynamicMetaObject errorSuggestion) {
+                return new DynamicMetaObject(
+                    Expression.Constant(&quot;UnaryFallback&quot;),
+                    BindingRestrictionsHelpers.GetRuntimeTypeRestriction(target)
+                );
+            }
+        }
+
         public void ScenarioDlrInterop() {
 #if !SILVERLIGHT
             ScriptScope scope = _env.CreateScope();
@@ -656,9 +669,27 @@ class os_getattr:
     def TestFunc(self):
         return 'TestFunc'
 
+class ns_nonzero(object):
+    def __nonzero__(self):
+        return True
+
+ns_nonzero_inst = ns_nonzero()
+
+class ns_len1(object):
+    def __len__(self): return 1
+
+ns_len1_inst = ns_len1()
+
+class ns_len0(object):
+    def __len__(self): return 0
+
+ns_len0_inst = ns_len0()
+
 def TestFunc():
     return 'TestFunc'
 
+TestFunc.SubFunc = TestFunc
+
 def Invokable(*args, **kwargs):
     return args, kwargs
 
@@ -681,6 +712,8 @@ al_getattrinst = MyArrayList_getattr()
 
 ns_getattributeinst = ns_getattribute()
 al_getattributeinst = MyArrayList_getattribute()
+
+xrange = xrange
 &quot;, SourceCodeKind.Statements);
 
             src.Execute(scope);
@@ -933,6 +966,21 @@ al_getattributeinst = MyArrayList_getattribute()
                 }
             }
 
+            site = CallSite&lt;Func&lt;CallSite, object, object&gt;&gt;.Create(new MyUnaryBinder(ExpressionType.Not));
+            AreEqual(site.Target(site, (object)scope.GetVariable(&quot;nsinst&quot;)), true);
+            AreEqual(site.Target(site, (object)scope.GetVariable(&quot;ns_nonzero_inst&quot;)), false);
+            AreEqual(site.Target(site, (object)scope.GetVariable(&quot;ns_len0_inst&quot;)), true);
+            AreEqual(site.Target(site, (object)scope.GetVariable(&quot;ns_len1_inst&quot;)), false);
+
+            site = CallSite&lt;Func&lt;CallSite, object, object&gt;&gt;.Create(new MyInvokeMemberBinder(&quot;ToString&quot;, new CallInfo(0)));
+            AreEqual(site.Target(site, (object)scope.GetVariable(&quot;xrange&quot;)), &quot;FallbackInvokeMember&quot;);
+
+            // invoke a function defined as a member of a function
+            site = CallSite&lt;Func&lt;CallSite, object, object&gt;&gt;.Create(new MyInvokeMemberBinder(&quot;SubFunc&quot;, new CallInfo(0)));
+            AreEqual(site.Target(site, (object)scope.GetVariable(&quot;TestFunc&quot;)), &quot;TestFunc&quot;);
+
+            site = CallSite&lt;Func&lt;CallSite, object, object&gt;&gt;.Create(new MyInvokeMemberBinder(&quot;DoesNotExist&quot;, new CallInfo(0)));
+            AreEqual(site.Target(site, (object)scope.GetVariable(&quot;TestFunc&quot;)), &quot;FallbackInvokeMember&quot;);
 #endif
         }
 
@@ -979,6 +1027,19 @@ al_getattributeinst = MyArrayList_getattribute()
             var scope = _pe.CreateScope();
             scope.SetVariable(&quot;ops&quot;, ops);
             AreEqual(&quot;[1, 2, 3]&quot;, _pe.Execute&lt;string&gt;(&quot;ops.Format([1,2,3])&quot;, scope));
+
+            ScriptSource src = _pe.CreateScriptSourceFromString(&quot;def f(*args): return args&quot;, SourceCodeKind.Statements);
+            src.Execute(scope);
+            object f = (object)scope.GetVariable(&quot;f&quot;);
+
+            for (int i = 0; i &lt; 20; i++) {
+                object[] inp = new object[i];
+                for (int j = 0; j &lt; inp.Length; j++) {
+                    inp[j] = j;
+                }
+
+                AreEqual((object)ops.Invoke(f, inp), PythonTuple.MakeTuple(inp));
+            }
         }
 
         public void ScenarioCP712() {</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPythonTest/EngineTest.cs</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{B6B42537-07F8-4F6C-A99A-B155CAEB124E}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Library&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPythonTest/IronPythonTest.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{81DA19C7-4FEC-47E7-981B-D9310D549F95}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;WinExe&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPythonWindow/IronPythonWindow.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{7F6F9AB3-9943-4316-BD4C-A10F580BC75C}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;WinExe&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Languages/IronPython/IronPythonWindowAny/IronPythonWindowAny.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{166940A1-2C91-4BD0-B72B-A517FBD8BF0B}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Exe&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Languages/Ruby/ClassInitGenerator/ClassInitGenerator.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{D6AB587D-A888-4B98-85AC-F15E36F53838}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Exe&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Languages/Ruby/Console/Ruby.Console.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{6EE7A428-D803-41BC-8248-1297C3ACE369}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Exe&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Languages/Ruby/Console/Ruby.ConsoleAny.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{8103D91B-89D8-4A18-9A40-426992602EA2}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Exe&lt;/OutputType&gt;</diff>
      <filename>Merlin/Main/Languages/Ruby/IronRuby.Tests/IronRuby.Tests.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -764,13 +764,13 @@ namespace IronRuby.Tests {
             var sjisEncoding = RubyEncoding.KCodeSJIS;
 
             // change KCODE at runtime:
-            Context.SetGlobalVariable(null, &quot;KCODE&quot;, MutableString.Create(&quot;S&quot;));
+            Context.SetGlobalVariable(null, &quot;KCODE&quot;, MS(&quot;S&quot;));
             Assert(ReferenceEquals(Context.KCode, sjisEncoding));
 
             // load file encoded in SJIS:
             var tmpPath = Path.GetTempFileName();
             try {
-                Runtime.Globals.SetVariable(&quot;TempFileName&quot;, MutableString.Create(tmpPath));
+                Runtime.Globals.SetVariable(&quot;TempFileName&quot;, MS(tmpPath));
                 File.WriteAllBytes(tmpPath, sjisEncoding.Encoding.GetBytes(&quot;C&#65422; = '&#65422;'&quot;));
                 Engine.Execute(@&quot;load(TempFileName)&quot;);
                 var str = Runtime.Globals.GetVariable&lt;MutableString&gt;(&quot;C&#65422;&quot;);
@@ -878,7 +878,7 @@ __ENCODING__
 
         // Ruby preamble overrides the encoding's preamble (BOM)
         [Options(Compatibility = RubyCompatibility.Ruby19)]
-        private void Encoding_Host2() {
+        public void Encoding_Host2() {
             var src = &quot;# encoding: ASCII-8BIT\r\n$X = '\u0394'&quot;;
             var binsrc = Encoding.UTF8.GetBytes(src);
 
@@ -895,6 +895,54 @@ __ENCODING__
             Assert(actualCode.Length == binsrc.Length);
         }
 
+        [Options(Compatibility = RubyCompatibility.Ruby19)]
+        public void NamesEncoding1() {
+            // TODO:
+            XTestOutput(@&quot;#encoding: SJIS
+class C&#65422;
+  def initialize
+    @&#65422; = 1
+    @@&#65422; = 2
+  end
+  
+  def &#65422;
+  end
+  
+  X&#65422; = 5
+end
+
+$X&#65422; = 3
+&#65422; = 4
+
+puts C&#65422;.name
+puts C&#65422;.name.encoding
+puts C&#65422;.new.inspect
+
+C&#65422;.instance_methods(false).each { |x| puts x,x.encoding }
+C&#65422;.new.instance_variables.each { |x| puts x,x.encoding }
+C&#65422;.class_variables.each { |x| puts x,x.encoding }
+C&#65422;.constants.each { |x| puts x,x.encoding }
+local_variables.each { |x| puts x,x.encoding }
+global_variables.each { |x| puts x,x.encoding if x[0] == 'X' }
+&quot;, @&quot;
+C&#65422;
+#&lt;Encoding: SJIS&gt;
+#&lt;C&#65422; TODO&gt;
+&#65422;
+#&lt;Encoding: SJIS&gt;
+@&#65422;
+#&lt;Encoding: SJIS&gt;
+@@&#65422;
+#&lt;Encoding: SJIS&gt;
+X&#65422;
+#&lt;Encoding: SJIS&gt;
+&#65422;
+#&lt;Encoding: SJIS&gt;
+$&#65422;
+#&lt;Encoding: SJIS&gt;
+&quot;);
+        }
+
         // TODO:
         public void BlockParameterSyntax1() {
             // &quot;yield(&amp;p)&quot; -&gt; block argument should not be given</diff>
      <filename>Merlin/Main/Languages/Ruby/IronRuby.Tests/Parser/ParserTests.cs</filename>
    </modified>
    <modified>
      <diff>@@ -346,6 +346,7 @@ namespace IronRuby.Tests {
                 PythonInterop3,
                 PythonInterop4,
                 PythonInterop5,
+                // TODO (bug in IronPython): PythonInterop6,
 
                 CustomTypeDescriptor1,
                 CustomTypeDescriptor2,
@@ -400,17 +401,20 @@ namespace IronRuby.Tests {
                 ClrOverride2,
                 ClrOverride3,
                 //TODO: Fix ClrOverride4,
+                ClrEventImpl1,
                 ClrDetachedVirtual1,
                 ClrConstructor1,
                 ClrConstructor2,
                 ClrConstructor3,
                 ClrConstructor4,
+                ClrConstructor5,
                 ClrPrimitiveNumericTypes1,
                 ClrArrays1,
                 ClrArrays2,
                 ClrChar1,
                 ClrOperators1,
                 ClrOperators2,
+                ClrOperators3,
                 ClrConversions1,
                 ClrHashEqualsToString1,
                 ClrHashEqualsToString2,
@@ -458,6 +462,9 @@ namespace IronRuby.Tests {
                 RescueSplat1,
                 RescueSplat2,
                 RescueSplat3,
+                ExceptionMapping1,
+                ExceptionMapping2,
+                ExceptionMapping3,
 
                 ClassVariables1,
                 UnqualifiedConstants2,
@@ -602,10 +609,10 @@ namespace IronRuby.Tests {
                 AliasInModuleEval1,
                 MethodAliasInModuleEval1,
                 SuperInModuleEval1,
-                
                 // TODO: SuperParameterlessEval1,
                 // TODO: SuperParameterlessEval2,
                 SuperInDefineMethodEval1,
+                // TODO: NamesEncoding1,
 
                 Backtrace1,
                 Backtrace2,
@@ -616,7 +623,7 @@ namespace IronRuby.Tests {
                 Dlr_ClrSubtype,
                 Dlr_MethodMissing,
                 Dlr_Miscellaneous,
-                Dlr_Convertible,
+                Dlr_Conversions,
                 Dlr_Indexable,
                 Dlr_Number,
                 Dlr_Comparable,</diff>
      <filename>Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs</filename>
    </modified>
    <modified>
      <diff>@@ -1467,6 +1467,53 @@ false
 &quot;);
         }
 
+        public class ClassWithVirtualEvent1 {
+            public virtual event Func&lt;int, int&gt; OnEvent;
+
+            public int Fire(int arg) {
+                return OnEvent(arg);
+            }
+        }
+
+        public void ClrEventImpl1() {
+            // TODO: fix
+            if (_driver.PartialTrust) return;
+
+            var e = new ClassWithVirtualEvent1();
+            Context.ObjectClass.SetConstant(&quot;E&quot;, Context.GetClass(typeof(ClassWithVirtualEvent1)));
+
+            var f = Engine.Execute&lt;ClassWithVirtualEvent1&gt;(@&quot;
+class F &lt; E
+  def add_OnEvent handler
+    puts 'add ' + handler.inspect
+    super
+  end
+
+  def remove_OnEvent handler
+    puts 'remove ' + handler.inspect
+    super
+  end
+end
+
+F.new
+&quot;);
+            var handler = new Func&lt;int, int&gt;((i) =&gt; i + 1);
+
+            AssertOutput(() =&gt; f.OnEvent += handler, @&quot;add System.Func`2[System.Int32,System.Int32]&quot;);
+            var r = f.Fire(10);
+            Assert(r == 11);
+            AssertOutput(() =&gt; f.OnEvent -= handler, @&quot;remove System.Func`2[System.Int32,System.Int32]&quot;);
+
+            TestOutput(@&quot;
+f = F.new
+f.on_event { |x| x * 2 }
+puts f.fire(10)
+&quot;, @&quot;
+add System.Func`2[System.Int32,System.Int32]
+20
+&quot;);
+        }
+
         #endregion
 
         #region Virtual method overrides
@@ -2015,6 +2062,16 @@ init
 &quot;);
         }
 
+        public struct Struct1 {
+            public int Foo;
+        }
+
+        public void ClrConstructor5() {
+            Context.ObjectClass.SetConstant(&quot;S&quot;, Context.GetClass(typeof(Struct1)));
+            var s = Engine.Execute(@&quot;S.new&quot;);
+            Assert(s is Struct1);
+        }
+
         #endregion
 
         #region CLR Primitive Types: Numeric, Arrays, Char, Enums
@@ -2260,8 +2317,7 @@ false
         }
 
         public void ClrOperators2() {
-            AssertOutput(delegate() {
-                CompilerTest(@&quot;
+            TestOutput(@&quot;
 p :b == true                # Symbol hides SymbolId::op_Equality
 p String == Fixnum          # Only instance operator calls are allowed (MutableString::op_Equality shound be ignored)
 
@@ -2272,14 +2328,32 @@ class C &lt; Numeric
 end
 
 p C.new.ceil                 # Numeric#ceil uses self with DefaultProtocol attribute
-&quot;);
-            }, @&quot;
+&quot;, @&quot;
 false
 false
 2
 &quot;);
         }
 
+        /// &lt;summary&gt;
+        /// Operator mapping is not performed for builtin classes. 
+        /// CLR DateTime defines op_LessThan but we want less-than operator to call comparison method &amp;lt;=&amp;gt;.
+        /// &lt;/summary&gt;
+        public void ClrOperators3() {
+            TestOutput(@&quot;
+class Time
+  def &lt;=&gt;(other)
+    puts '&lt;=&gt;'
+    1
+  end
+end
+p Time.mktime(1) &lt; Time.mktime(10)
+&quot;, @&quot;
+&lt;=&gt;
+false
+&quot;);
+        }
+
         public class Conversions1 {
             public int F(int? a, int? b) {
                 return a ?? b ?? 3;
@@ -2289,6 +2363,10 @@ false
                 return new object[] { a, b, c, d, e, f, g, h, i, j, k };
             }
 
+            public object[] Numerics(byte a, sbyte b, short c, ushort d, int e, uint f, long g, ulong h, BigInteger i) {
+                return new object[] { a, b, c, d, e, f, g, h, i };
+            }
+
             public Delegate Delegate(Func&lt;object, object&gt; d) {
                 return d;
             }
@@ -2389,7 +2467,7 @@ p(*Inst.numerics(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11))
 (10+0j)
 Convertible(11)
 &quot;);
-
+                        
             // protocol conversions:
             TestOutput(@&quot;
 class C
@@ -2400,12 +2478,28 @@ class C
   def to_str
     'xxx'
   end
+
+  def to_int
+    1
+  end
 end
-p Inst.ListAndStrings(C.new, C.new)
+c = C.new
+
+p Inst.ListAndStrings(c, c)
 p Inst.Foo(Conv)
+p(*Inst.numerics(c, c, c, c, c, c, c, c, c))
 &quot;, @&quot;
 8
 12
+1 (Byte)
+1 (SByte)
+1 (Int16)
+1 (UInt16)
+1
+1 (UInt32)
+1 (Int64)
+1 (UInt64)
+1
 &quot;);
             
             // protocol conversions:</diff>
      <filename>Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ClrTests.cs</filename>
    </modified>
    <modified>
      <diff>@@ -14,21 +14,15 @@
  * ***************************************************************************/
 
 using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Reflection;
-using System.Runtime.Serialization;
-using Microsoft.Scripting.Runtime;
-using IronRuby.Runtime;
-using IronRuby.Builtins;
-using System.IO;
-using System.Linq.Expressions;
 using System.Dynamic;
-using Microsoft.Scripting.Utils;
-using Microsoft.Scripting.Hosting;
+using System.Linq.Expressions;
 using System.Runtime.CompilerServices;
-using Microsoft.Scripting;
+using IronRuby.Builtins;
+using Microsoft.Scripting.Hosting;
+using Microsoft.Scripting.Math;
+using Microsoft.Scripting.Runtime;
+using Microsoft.Scripting.Utils;
+using System.Collections;
 
 namespace IronRuby.Tests {
     #region Custom binders
@@ -682,7 +676,7 @@ end
             AreEqual(MyInvokeMemberBinder.Invoke(misc_class, &quot;ToString&quot;), &quot;FallbackInvokeMember&quot;);
         }
 
-        public void Dlr_Convertible() {
+        public void Dlr_Conversions() {
             Engine.Execute(@&quot;
 class C
   def to_int
@@ -696,24 +690,23 @@ class C
   def to_str
     'str'
   end
-
-  def each
-    [1,2,3].each {|x| yield x }
-  end
 end
 &quot;);
             var classC = Runtime.Globals.GetVariable(&quot;C&quot;);
             var c = Engine.Operations.CreateInstance(classC);
 
-            // TODO:
-            //AreEqual(MyConvertBinder.Convert&lt;int&gt;(c, 10), 1);
-            //AreEqual(MyConvertBinder.Convert&lt;byte&gt;(c, 10), 1);
-            //AreEqual(MyConvertBinder.Convert&lt;string&gt;(c, &quot;FallbackConvert&quot;), &quot;str&quot;);
-            //AreEqual(MyConvertBinder.Convert&lt;double&gt;(c, -8.0), 2.0);
-            //AreEqual(MyConvertBinder.Convert&lt;float&gt;(c, -8.0f), 2.0f);
-            //IEnumerable e = MyConvertBinder.Convert&lt;IEnumerable&gt;(c, null)
-            //Assert(e != null);
-            //new List&lt;object&gt;(e);
+            AreEqual(MyConvertBinder.Convert&lt;sbyte&gt;(c, 10), (sbyte)1);
+            AreEqual(MyConvertBinder.Convert&lt;byte&gt;(c, 10), (byte)1);
+            AreEqual(MyConvertBinder.Convert&lt;short&gt;(c, 10), (short)1);
+            AreEqual(MyConvertBinder.Convert&lt;ushort&gt;(c, 10), (ushort)1);
+            AreEqual(MyConvertBinder.Convert&lt;int&gt;(c, 10), 1);
+            AreEqual(MyConvertBinder.Convert&lt;uint&gt;(c, 10), (uint)1);
+            AreEqual(MyConvertBinder.Convert&lt;long&gt;(c, 10), (long)1);
+            AreEqual(MyConvertBinder.Convert&lt;ulong&gt;(c, 10), (ulong)1);
+            AreEqual(MyConvertBinder.Convert&lt;BigInteger&gt;(c, 10), (BigInteger)1);
+            AreEqual(MyConvertBinder.Convert&lt;double&gt;(c, -8.0), 2.0);
+            AreEqual(MyConvertBinder.Convert&lt;float&gt;(c, -8.0f), 2.0f);
+            AreEqual(MyConvertBinder.Convert&lt;string&gt;(c, &quot;FallbackConvert&quot;), &quot;str&quot;);
         }
 
         public void Dlr_Indexable() {</diff>
      <filename>Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/DlrInteropTests.cs</filename>
    </modified>
    <modified>
      <diff>@@ -639,5 +639,76 @@ to_ary
 ok
 &quot;);
         }
+
+        public void ExceptionMapping1() {
+            TestOutput(@&quot;
+class LoadError
+  def self.new message
+    ZeroDivisionError.new message
+  end
+end
+
+begin
+  require 'non-existent'
+rescue ZeroDivisionError
+  puts 'Caught ZeroDivisionError'
+end
+&quot;, @&quot;
+Caught ZeroDivisionError
+&quot;);
+        }
+
+        public void ExceptionMapping2() {
+            TestOutput(@&quot;
+class ZeroDivisionError
+  def self.new(message)
+    puts 'new ZeroDivError'
+    'not an exception'
+  end
+end
+
+module Any
+  def self.===(other)
+    puts &quot;&quot;?#{other.inspect}&quot;&quot;
+    true
+  end
+end
+
+begin
+  1/0
+rescue Any
+  puts 'rescue'
+  p $!
+end
+
+puts 'Done'
+&quot;, @&quot;
+new ZeroDivError
+?#&lt;TypeError: exception object expected&gt;
+rescue
+#&lt;TypeError: exception object expected&gt;
+Done
+&quot;);
+        }
+
+        public void ExceptionMapping3() {
+            TestOutput(@&quot;
+class LoadError
+  def initialize *args
+    puts 'init'
+  end
+end
+
+begin
+  require 'non-existent'
+rescue LoadError
+  puts 'Caught LoadError'
+end
+&quot;, @&quot;
+init
+Caught LoadError
+&quot;);
+        }
+
     }
 }</diff>
      <filename>Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ExceptionTests.cs</filename>
    </modified>
    <modified>
      <diff>@@ -198,9 +198,8 @@ bar
 
         public void Scenario_RubyInteractive1() {
             ScriptScope scope = Runtime.CreateScope();
-            AssertOutput(delegate() {
-                Engine.CreateScriptSourceFromString(&quot;1+1&quot;, SourceCodeKind.InteractiveCode).Execute(scope);
-            }, &quot;=&gt; 2&quot;);
+            AssertOutput(() =&gt; Engine.CreateScriptSourceFromString(&quot;&quot;, SourceCodeKind.InteractiveCode).Execute(scope), &quot;&quot;);
+            AssertOutput(() =&gt; Engine.CreateScriptSourceFromString(&quot;x = 1 + 1&quot;, SourceCodeKind.InteractiveCode).Execute(scope), &quot;=&gt; 2&quot;);
         }
 
         public void Scenario_RubyInteractive2() {
@@ -266,7 +265,7 @@ module M; end
 class C; include M; end
 &quot;));
         }
-
+        
         public void ObjectOperations1() {
             var cls = Engine.Execute(@&quot;
 class C
@@ -287,6 +286,18 @@ end
 
             AssertOutput(() =&gt; Engine.Operations.Invoke(foo, 1, 2), &quot;[1, 2]&quot;);
             AssertOutput(() =&gt; Engine.Operations.InvokeMember(obj, &quot;foo&quot;, 1, 2), &quot;[1, 2]&quot;);
+
+            var str = Engine.Operations.ConvertTo&lt;string&gt;(MutableString.CreateAscii(&quot;foo&quot;));
+            Assert(str == &quot;foo&quot;);
+
+            str = Engine.Operations.ConvertTo&lt;string&gt;(Engine.Execute(&quot;class C; def to_str; 'bar'; end; new; end&quot;));
+            Assert(str == &quot;bar&quot;);
+
+            var b = Engine.Operations.ConvertTo&lt;byte&gt;(Engine.Execute(&quot;class C; def to_int; 123; end; new; end&quot;));
+            Assert(b == 123);
+
+            var lambda = Engine.Operations.ConvertTo&lt;Func&lt;int, int&gt;&gt;(Engine.Execute(&quot;lambda { |x| x * 2 }&quot;));
+            Assert(lambda(10) == 20);
         }
 
         public void ObjectOperations2() {
@@ -420,6 +431,18 @@ a.Count
             
         }
 
+        public void PythonInterop6() {
+            if (!_driver.RunPython) return;
+
+            var py = Runtime.GetEngine(&quot;python&quot;);
+
+            var scope = py.CreateScope();
+            py.Execute(@&quot;def foo(): pass&quot;, scope);
+
+            // TODO:
+            var s = Engine.Execute(&quot;foo.inspect&quot;, scope);
+        }
+
         public void CustomTypeDescriptor1() {
             var cls = Engine.Execute(@&quot;
 class C</diff>
      <filename>Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/HostingTests.cs</filename>
    </modified>
    <modified>
      <diff>@@ -56,30 +56,37 @@ namespace IronRuby.Tests {
             ));
             int s_crlf_count = 6;
 
-            var io = new RubyIO(Context, stream, &quot;r&quot;);
-            Assert(io.PeekByte() == (byte)'a');
+            var io = new RubyBufferedStream(stream);
+            Assert(io.PeekByte(0) == (byte)'a');
 
             var buffer = MutableString.CreateBinary(B(&quot;foo:&quot;));
-            Assert(io.AppendBytes(buffer, 4) == 4);
+            Assert(io.AppendBytes(buffer, 4, false) == 4);
             Assert(buffer.ToString() == &quot;foo:ab\r\n&quot;);
 
             buffer = MutableString.CreateBinary();
-            Assert(io.AppendBytes(buffer, 1) == 1);
+            Assert(io.AppendBytes(buffer, 1, false) == 1);
             Assert(buffer.ToString() == &quot;e&quot;);
 
-            buffer = MutableString.CreateMutable(&quot;x:&quot;);
+            buffer = MutableString.CreateMutable(&quot;x:&quot;, RubyEncoding.Binary);
             int c = s.Length - s_crlf_count - 2;
-            Assert(io.AppendBytes(buffer, c) == c);
+            Assert(io.AppendBytes(buffer, c, false) == c);
             Assert(buffer.ToString() == &quot;x:&quot; + s.Replace(crlf, &quot;\n&quot;).Substring(0, c));
 
             buffer = MutableString.CreateBinary();
-            Assert(io.AppendBytes(buffer, 10) == 4);
+            Assert(io.AppendBytes(buffer, 10, false) == 4);
             Assert(buffer.ToString() == &quot;st\n!&quot;);
 
             buffer = MutableString.CreateBinary();
-            Assert(io.AppendBytes(buffer, 10) == 0);
+            Assert(io.AppendBytes(buffer, 10, false) == 0);
             Assert(buffer.ToString() == &quot;&quot;);
 
+            stream = new TestStream(false, B(s = &quot;abcd&quot; + crlf + &quot;xyz&quot; + crlf + &quot;qqq;&quot;));
+            io = new RubyBufferedStream(stream);
+            buffer = MutableString.CreateBinary();
+            Assert(io.AppendBytes(buffer, Int32.MaxValue, true) == s.Length);
+            io.BaseStream.Seek(0, SeekOrigin.Begin);
+            Assert(io.AppendBytes(buffer, Int32.MaxValue, false) == s.Length - 2);
+            Assert(buffer.ToString() == s + s.Replace(crlf, &quot;\n&quot;));
         }
     }
 }</diff>
      <filename>Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/IoTests.cs</filename>
    </modified>
    <modified>
      <diff>@@ -197,7 +197,7 @@ Python
         }
 
         public void LibraryLoader1() {
-            Context.DefineGlobalVariable(&quot;lib_name&quot;, MutableString.Create(typeof(TestLibraryInitializer1).AssemblyQualifiedName));
+            Context.DefineGlobalVariable(&quot;lib_name&quot;, MutableString.CreateAscii(typeof(TestLibraryInitializer1).AssemblyQualifiedName));
 
             AssertOutput(delegate() {
                 CompilerTest(@&quot;</diff>
      <filename>Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/LoaderTests.cs</filename>
    </modified>
    <modified>
      <diff>@@ -44,6 +44,10 @@ namespace IronRuby.Tests {
             Test_Translate();
         }
 
+        private MutableString/*!*/ MS(string/*!*/ data) {
+            return MutableString.CreateMutable(data.Length * 3, RubyEncoding.Binary).Append(data);
+        }
+
         private MutableString/*!*/ MS(string/*!*/ data, RubyEncoding/*!*/ e) {
             return MutableString.CreateMutable(data.Length * 3, e).Append(data);
         }
@@ -57,7 +61,7 @@ namespace IronRuby.Tests {
         }
 
         private void Test_Factories() {
-            var x = MutableString.Create(&quot;&quot;);
+            var x = MutableString.CreateAscii(&quot;&quot;);
             Assert(!x.IsBinary &amp;&amp; x.IsEmpty);
 
             var y = MutableString.Create(x);
@@ -124,7 +128,7 @@ namespace IronRuby.Tests {
             // ASCII characters only:
             a = MutableString.Create(&quot;hello&quot;, RubyEncoding.UTF8);
             b = MutableString.Create(&quot;hello&quot;, RubyEncoding.GetRubyEncoding(&quot;SJIS&quot;));
-            c = MutableString.Create(&quot;hello&quot;, RubyEncoding.Binary);
+            c = MutableString.CreateAscii(&quot;hello&quot;);
             Assert(a.GetHashCode() == b.GetHashCode());
             Assert(a.GetHashCode() == c.GetHashCode());
             Assert(b.GetHashCode() == c.GetHashCode());
@@ -469,7 +473,7 @@ namespace IronRuby.Tests {
                 () =&gt; Test_Reverse(invalid_utf8, RubyEncoding.UTF8, rev_invalid_utf8)
             );
 
-            Assert(MutableStringOps.Reverse(MutableString.Create(&quot;&#945;&#931;&quot;)).ToString() == &quot;&#931;&#945;&quot;);
+            Assert(MutableStringOps.Reverse(MutableString.Create(&quot;&#945;&#931;&quot;, RubyEncoding.UTF8)).ToString() == &quot;&#931;&#945;&quot;);
 
             // TODO: KCODE
         }</diff>
      <filename>Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/MutableStringTests.cs</filename>
    </modified>
    <modified>
      <diff>@@ -139,7 +139,7 @@ namespace IronRuby.Tests {
 
             var c = Engine.Execute(@&quot;class C &lt; X; new; end&quot;);
             var sym = SymbolTable.StringToId(&quot;x&quot;);
-            var ms = MutableString.Create(&quot;x&quot;);
+            var ms = MutableString.CreateAscii(&quot;x&quot;);
 
             var cases = new[] {
                 // F</diff>
      <filename>Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/OverloadResolutionTests.cs</filename>
    </modified>
    <modified>
      <diff>@@ -117,7 +117,7 @@ end
 &quot;;
         
         public void ToIntToStrConversion1() {
-            Context.DefineGlobalVariable(&quot;protocol_tester&quot;, MutableString.Create(typeof(DefaultProtocolTester).AssemblyQualifiedName));
+            Context.DefineGlobalVariable(&quot;protocol_tester&quot;, MutableString.CreateAscii(typeof(DefaultProtocolTester).AssemblyQualifiedName));
 
             Engine.Execute(StrIntDeclarations);
 </diff>
      <filename>Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ProtocolTests.cs</filename>
    </modified>
    <modified>
      <diff>@@ -85,7 +85,6 @@ namespace IronRuby.Tests {
             Assert(RubyUtils.TryMangleName(&quot;Foo123bar&quot;) == &quot;foo123bar&quot;);
             Assert(RubyUtils.TryMangleName(&quot;123Bar&quot;) == &quot;123_bar&quot;);
             Assert(RubyUtils.TryMangleName(&quot;?Bar&quot;) == &quot;?_bar&quot;);
-            Assert(RubyUtils.TryMangleName(&quot;B__&quot;) == &quot;b__&quot;);
 
             // special cases:
             Assert(RubyUtils.TryUnmangleName(&quot;ON&quot;) == null);
@@ -131,6 +130,11 @@ namespace IronRuby.Tests {
             Assert(RubyUtils.TryMangleName(&quot;FooBAR&quot;) == null);
             Assert(RubyUtils.TryMangleName(&quot;foo&quot;) == null);
             Assert(RubyUtils.TryMangleName(&quot;initialize&quot;) == null);
+
+            // name containing underscore(s) cannot be mangled:
+            Assert(RubyUtils.TryMangleName(&quot;a_b&quot;) == null);
+            Assert(RubyUtils.TryMangleName(&quot;add_Foo&quot;) == null);
+            Assert(RubyUtils.TryMangleName(&quot;B__&quot;) == null);
             Assert(RubyUtils.TryMangleName(&quot;foo_bar=&quot;) == null);
             Assert(RubyUtils.TryMangleName(&quot;foo__bar&quot;) == null);
             Assert(RubyUtils.TryMangleName(&quot;_foo&quot;) == null);</diff>
      <filename>Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/RubyUtilsTests.cs</filename>
    </modified>
    <modified>
      <diff>@@ -186,7 +186,7 @@ namespace IronRuby.StandardLibrary.BigDecimal {
 
         [RubyMethod(&quot;ver&quot;, RubyMethodAttributes.PublicSingleton)]
         public static MutableString/*!*/ Version(RubyClass/*!*/ self) {
-            return MutableString.Create(&quot;1.0.1&quot;);
+            return MutableString.CreateAscii(&quot;1.0.1&quot;);
         }
 
         #region induced_from
@@ -236,7 +236,7 @@ namespace IronRuby.StandardLibrary.BigDecimal {
 
         [RubyMethod(&quot;split&quot;)]
         public static RubyArray/*!*/ Split(BigDecimal/*!*/ self) {
-            return RubyOps.MakeArray4(self.Sign, MutableString.Create(self.GetFractionString()), 10, self.Exponent);
+            return RubyOps.MakeArray4(self.Sign, MutableString.CreateAscii(self.GetFractionString()), 10, self.Exponent);
         }
 
         [RubyMethod(&quot;fix&quot;)]
@@ -257,12 +257,12 @@ namespace IronRuby.StandardLibrary.BigDecimal {
 
         [RubyMethod(&quot;to_s&quot;)]
         public static MutableString/*!*/ ToString(BigDecimal/*!*/ self) {
-            return MutableString.Create(self.ToString());
+            return MutableString.CreateAscii(self.ToString());
         }
 
         [RubyMethod(&quot;to_s&quot;)]
         public static MutableString/*!*/ ToString(BigDecimal/*!*/ self, [DefaultProtocol]int separateAt) {
-            return MutableString.Create(self.ToString(separateAt));
+            return MutableString.CreateAscii(self.ToString(separateAt));
         }
 
         [RubyMethod(&quot;to_s&quot;)]
@@ -282,14 +282,14 @@ namespace IronRuby.StandardLibrary.BigDecimal {
                 separateAt = Int32.Parse(m.Groups[&quot;separateAt&quot;].Value);
             }
             bool floatFormat = floatFormatGroup.Success;
-            return MutableString.Create(self.ToString(separateAt, posSign, floatFormat));
+            return MutableString.CreateAscii(self.ToString(separateAt, posSign, floatFormat));
         }
 
         #endregion
 
         [RubyMethod(&quot;inspect&quot;)]
         public static MutableString/*!*/ Inspect(RubyContext/*!*/ context, BigDecimal/*!*/ self) {
-            MutableString str = MutableString.CreateMutable();
+            MutableString str = MutableString.CreateMutable(RubyEncoding.ClassName);
             str.AppendFormat(&quot;#&lt;{0}:&quot;, context.GetClassOf(self).Name);
             RubyUtils.AppendFormatHexObjectId(str, RubyUtils.GetObjectId(context, self));
             str.AppendFormat(&quot;,'{0}',&quot;, self.ToString(10));
@@ -326,10 +326,11 @@ namespace IronRuby.StandardLibrary.BigDecimal {
         [RubyMethod(&quot;_dump&quot;)]
         public static MutableString/*!*/ Dump(BigDecimal/*!*/ self, [Optional]object limit) {
             // We ignore the limit value as BigDecimal does not contain other objects.
-            return MutableString.CreateMutable(
-                string.Format(&quot;{0}:{1}&quot;,
-                    self.MaxPrecisionDigits,
-                    self));
+            return MutableString.CreateMutable(RubyEncoding.Binary).
+                Append(self.MaxPrecisionDigits.ToString()).
+                Append(':').
+                Append(self.ToString()
+            );
         }
 
         #endregion</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/BigDecimal/BigDecimalOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -19,6 +19,7 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.Dynamic;
 using System.IO;
+using System.Runtime.CompilerServices;
 using System.Text;
 using IronRuby.Compiler;
 using IronRuby.Runtime;
@@ -260,6 +261,7 @@ namespace IronRuby.Builtins {
             ConversionStorage&lt;MutableString&gt;/*!*/ stringCast, 
             RubyContext/*!*/ context, RubyArray/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ format) {
 
+            // TODO (encoding):
             using (MutableStringStream stream = new MutableStringStream()) {
                 BinaryWriter writer = new BinaryWriter(stream);
                 int i = 0;
@@ -484,7 +486,7 @@ namespace IronRuby.Builtins {
         }
 
         [RubyMethod(&quot;sort&quot;)]
-        public static RubyArray/*!*/ Sort(
+        public static object Sort(
             BinaryOpStorage/*!*/ comparisonStorage,
             BinaryOpStorage/*!*/ lessThanStorage,
             BinaryOpStorage/*!*/ greaterThanStorage,
@@ -496,12 +498,42 @@ namespace IronRuby.Builtins {
         }
 
         [RubyMethod(&quot;sort!&quot;)]
+        public static object SortInPlace(
+            BinaryOpStorage/*!*/ comparisonStorage,
+            BinaryOpStorage/*!*/ lessThanStorage,
+            BinaryOpStorage/*!*/ greaterThanStorage,
+            BlockParam block, RubyArray/*!*/ self) {
+
+            StrongBox&lt;object&gt; breakResult;
+            RubyArray result = SortInPlace(comparisonStorage, lessThanStorage, greaterThanStorage, block, self, out breakResult);
+            if (breakResult != null) {
+                return breakResult.Value;
+            } else {
+                return result;
+            }
+        }
+
         public static RubyArray/*!*/ SortInPlace(
             BinaryOpStorage/*!*/ comparisonStorage,
             BinaryOpStorage/*!*/ lessThanStorage,
+            BinaryOpStorage/*!*/ greaterThanStorage,
+            RubyArray/*!*/ self) {
+
+            StrongBox&lt;object&gt; breakResult;
+            RubyArray result = SortInPlace(comparisonStorage, lessThanStorage, greaterThanStorage, null, self, out breakResult);
+            Debug.Assert(result != null &amp;&amp; breakResult == null);
+            return result;
+        }
+
+        internal static RubyArray SortInPlace(
+            BinaryOpStorage/*!*/ comparisonStorage,
+            BinaryOpStorage/*!*/ lessThanStorage,
             BinaryOpStorage/*!*/ greaterThanStorage,            
-            BlockParam block, RubyArray/*!*/ self) {
+            BlockParam block,
+            RubyArray/*!*/ self,
+            out StrongBox&lt;object&gt; breakResult) {
 
+            breakResult = null;
             var context = comparisonStorage.Context;
             RubyUtils.RequiresNotFrozen(context, self);
 
@@ -512,11 +544,13 @@ namespace IronRuby.Builtins {
             if (block == null) {
                 self.Sort((x, y) =&gt; Protocols.Compare(comparisonStorage, lessThanStorage, greaterThanStorage, x, y));
             } else {
+                object nonRefBreakResult = null;
                 try {
-                    self.Sort((x, y) =&gt; {
-                        object result;
+                    self.Sort((x, y) =&gt;
+                    {
+                        object result = null;
                         if (block.Yield(x, y, out result)) {
-                            // TODO: this doesn't work
+                            nonRefBreakResult = result;
                             throw new BreakException();
                         }
 
@@ -526,7 +560,17 @@ namespace IronRuby.Builtins {
 
                         return Protocols.ConvertCompareResult(lessThanStorage, greaterThanStorage, result);
                     });
-                } catch (BreakException) {
+                } catch (InvalidOperationException e) {
+                    if (e.InnerException == null) {
+                        throw;
+                    }
+
+                    if (e.InnerException is BreakException) {
+                        breakResult = new StrongBox&lt;object&gt;(nonRefBreakResult);
+                        return null;
+                    } else {
+                        throw e.InnerException;
+                    }
                 }
             }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ArrayOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -48,7 +48,7 @@ namespace IronRuby.Builtins {
             } catch (Exception ex) {
                 throw ToRubyException(ex, strName, DirectoryOperation.Open);
             }
-            _dirName = MutableString.Create(RubyUtils.CanonicalizePath(strName));
+            _dirName = MutableString.Create(RubyUtils.CanonicalizePath(strName), RubyEncoding.Path);
             _closed = false;
             _pos = -2;
         }
@@ -104,7 +104,7 @@ namespace IronRuby.Builtins {
             if (defaultDirectory == null)
                 throw RubyExceptions.CreateArgumentError(&quot;HOME / USERPROFILE not set&quot;);
 
-            return ChangeDirectory(self, MutableString.Create(defaultDirectory));
+            return ChangeDirectory(self, MutableString.Create(defaultDirectory, RubyEncoding.Path));
 #else
             throw new InvalidOperationException();
 #endif
@@ -140,10 +140,10 @@ namespace IronRuby.Builtins {
             }
 
             RubyArray ret = new RubyArray(rawEntries.Length + 2);
-            ret.Add(MutableString.Create(&quot;.&quot;));
-            ret.Add(MutableString.Create(&quot;..&quot;));
+            ret.Add(MutableString.CreateAscii(&quot;.&quot;));
+            ret.Add(MutableString.CreateAscii(&quot;..&quot;));
             foreach (string entry in rawEntries) {
-                ret.Add(MutableString.Create(Path.GetFileName(entry)));
+                ret.Add(MutableString.Create(Path.GetFileName(entry), RubyEncoding.Path));
             }
             return ret;
         }
@@ -169,7 +169,7 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;getwd&quot;, RubyMethodAttributes.PublicSingleton)]
         [RubyMethod(&quot;pwd&quot;, RubyMethodAttributes.PublicSingleton)]
         public static MutableString/*!*/ GetCurrentDirectory(object self) {
-            return MutableString.Create(RubyUtils.CanonicalizePath(Directory.GetCurrentDirectory()));
+            return MutableString.Create(RubyUtils.CanonicalizePath(Directory.GetCurrentDirectory()), RubyEncoding.Path);
         }
 
         #region glob
@@ -178,9 +178,9 @@ namespace IronRuby.Builtins {
         public static object Glob([NotNull]BlockParam/*!*/ block, RubyClass/*!*/ self, 
             [DefaultProtocol, NotNull]MutableString/*!*/ pattern, [DefaultProtocol, Optional]int flags) {
 
-            foreach (string fileName in IronRuby.Builtins.Glob.GlobResults(self.Context, pattern.ConvertToString(), flags)) {
+            foreach (string fileName in IronRuby.Builtins.Glob.GlobResults(self.Context.DomainManager.Platform, pattern.ConvertToString(), flags)) {
                 object result;
-                if (block.Yield(MutableString.Create(fileName).TaintBy(pattern), out result)) {
+                if (block.Yield(MutableString.Create(fileName, pattern.Encoding).TaintBy(pattern), out result)) {
                     return result;
                 }
             }
@@ -193,8 +193,8 @@ namespace IronRuby.Builtins {
             [DefaultProtocol, NotNull]MutableString/*!*/ pattern, [DefaultProtocol, Optional]int flags) {
             
             RubyArray result = new RubyArray();
-            foreach (string fileName in IronRuby.Builtins.Glob.GlobResults(self.Context, pattern.ConvertToString(), flags)) {
-                result.Add(MutableString.Create(fileName).TaintBy(pattern));
+            foreach (string fileName in IronRuby.Builtins.Glob.GlobResults(self.Context.DomainManager.Platform, pattern.ConvertToString(), flags)) {
+                result.Add(MutableString.Create(fileName, pattern.Encoding).TaintBy(pattern));
             }
 
             return result;
@@ -286,11 +286,11 @@ namespace IronRuby.Builtins {
 
             MutableString ret;
             if (self._pos == -2) {
-                ret = MutableString.Create(&quot;.&quot;);
+                ret = MutableString.CreateAscii(&quot;.&quot;);
             } else if (self._pos == -1) {
-                ret = MutableString.Create(&quot;..&quot;);
+                ret = MutableString.CreateAscii(&quot;..&quot;);
             } else {
-                ret = MutableString.Create(Path.GetFileName(self._rawEntries[self._pos]));
+                ret = MutableString.Create(Path.GetFileName(self._rawEntries[self._pos]), RubyEncoding.Path);
             }
             self._pos++;
             return ret;
@@ -343,14 +343,14 @@ namespace IronRuby.Builtins {
 
             switch (op) {
                 case DirectoryOperation.ChangeDir:
-                    return RubyErrno.CreateEINVAL(path);
+                    return RubyExceptions.CreateEINVAL(path);
 
                 case DirectoryOperation.Open:
-                    return RubyErrno.CreateENOENT(path);
+                    return RubyExceptions.CreateENOENT(path);
 
                 case DirectoryOperation.Delete:
                     if (ex is ArgumentException) {
-                        return RubyErrno.CreateEINVAL(path);
+                        return RubyExceptions.CreateEINVAL(path);
                     }
                     if (ex is IOException) {
                         return Errno.CreateEACCES(path);
@@ -359,10 +359,10 @@ namespace IronRuby.Builtins {
 
                 case DirectoryOperation.Create:
                     if (ex is ArgumentException) {
-                        return RubyErrno.CreateEINVAL(path);
+                        return RubyExceptions.CreateEINVAL(path);
                     }
                     if (ex is IOException) {
-                        return RubyErrno.CreateEEXIST(path);
+                        return RubyExceptions.CreateEEXIST(path);
                     }
                     break;
             }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Dir.cs</filename>
    </modified>
    <modified>
      <diff>@@ -47,24 +47,25 @@ namespace IronRuby.Builtins {
         }
 
         private static object TrueForItems(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BlockParam predicate, object self, bool expected) {
-            bool result = expected;
+            object result = ScriptingRuntimeHelpers.BooleanToObject(expected);
             Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
                 if (predicate != null) {
                     if (predicate.Yield(item, out item)) {
-                        return item;
+                        result = item;
+                        return selfBlock.Break(item);
                     }
                 }
 
                 bool isTrue = Protocols.IsTrue(item);
-                if (isTrue != result) {
-                    result = isTrue;
-                    return selfBlock.Break(ScriptingRuntimeHelpers.BooleanToObject(isTrue));
+                if (isTrue != expected) {
+                    result = ScriptingRuntimeHelpers.BooleanToObject(!expected);
+                    return selfBlock.Break(result);
                 }
 
                 return null;
             }));
 
-            return ScriptingRuntimeHelpers.BooleanToObject(result);
+            return result;
         }
 
         #endregion
@@ -73,15 +74,17 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;collect&quot;)]
         [RubyMethod(&quot;map&quot;)]
-        public static RubyArray Map(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BlockParam collector, object self) {
-            RubyArray result = new RubyArray();
+        public static object Map(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BlockParam collector, object self) {
+            RubyArray resultArray = new RubyArray();
+            object result = resultArray;
             Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
                 if (collector != null) {
                     if (collector.Yield(item, out item)) {
-                        return item;
+                        result = item;
+                        return selfBlock.Break(item);
                     }
                 }
-                result.Add(item);
+                resultArray.Add(item);
                 return null;
             }));
             return result;
@@ -139,17 +142,19 @@ namespace IronRuby.Builtins {
             }
 
             int index = 0;
+            object result = self;
 
             Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
                 object blockResult;
                 if (block.Yield(item, index, out blockResult)) {
-                    return blockResult;
+                    result = blockResult;
+                    return selfBlock.Break(blockResult);
                 }
                 index += 1;
                 return null;
             }));
 
-            return self;
+            return result;
         }
 
         #endregion
@@ -175,17 +180,18 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;find_all&quot;)]
         [RubyMethod(&quot;select&quot;)]
-        public static RubyArray/*!*/ Select(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BlockParam predicate, object self) {
+        public static object Select(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BlockParam predicate, object self) {
             return Filter(each, predicate, self, true);
         }
 
         [RubyMethod(&quot;reject&quot;)]
-        public static RubyArray/*!*/ Reject(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BlockParam predicate, object self) {
+        public static object Reject(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BlockParam predicate, object self) {
             return Filter(each, predicate, self, false);
         }
 
-        private static RubyArray/*!*/ Filter(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BlockParam predicate, object self, bool acceptingValue) {
-            RubyArray result = new RubyArray();
+        private static object Filter(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BlockParam predicate, object self, bool acceptingValue) {
+            RubyArray resultArray = new RubyArray();
+            object result = resultArray;
 
             Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
                 if (predicate == null) {
@@ -194,12 +200,13 @@ namespace IronRuby.Builtins {
 
                 object blockResult;
                 if (predicate.Yield(item, out blockResult)) {
-                    return blockResult;
+                    result = blockResult;
+                    return selfBlock.Break(blockResult);
                 }
 
                 // Check if the result is what we expect (use true to select, false to reject)
                 if (Protocols.IsTrue(blockResult) == acceptingValue) {
-                    result.Add(item);
+                    resultArray.Add(item);
                 }
                 return null;
             }));
@@ -212,20 +219,22 @@ namespace IronRuby.Builtins {
         #region grep
 
         [RubyMethod(&quot;grep&quot;)]
-        public static RubyArray Grep(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BinaryOpStorage/*!*/ caseEquals, 
+        public static object Grep(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BinaryOpStorage/*!*/ caseEquals, 
             BlockParam action, object self, object pattern) {
 
-            RubyArray result = new RubyArray();
+            RubyArray resultArray = new RubyArray();
+            object result = resultArray;
             var site = caseEquals.GetCallSite(&quot;===&quot;);
 
             Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
                 if (RubyOps.IsTrue(site.Target(site, pattern, item))) {
                     if (action != null) {
                         if (action.Yield(item, out item)) {
-                            return item;
+                            result = item;
+                            return selfBlock.Break(item);
                         }
                     }
-                    result.Add(item);
+                    resultArray.Add(item);
                 }
                 return null;
             }));
@@ -239,12 +248,12 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;include?&quot;)]
         [RubyMethod(&quot;member?&quot;)]
-        public static bool Contains(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BinaryOpStorage/*!*/ equals, object self, object value) {
-            bool result = false;
+        public static object Contains(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BinaryOpStorage/*!*/ equals, object self, object value) {
+            object result = ScriptingRuntimeHelpers.BooleanToObject(false);
 
             Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
                 if (Protocols.IsEqual(equals, item, value)) {
-                    result = true;
+                    result = ScriptingRuntimeHelpers.BooleanToObject(true);
                     return selfBlock.Break(result);
                 }
                 return null;
@@ -272,7 +281,7 @@ namespace IronRuby.Builtins {
                 }
 
                 if (operation.Yield(result, item, out result)) {
-                    return result;
+                    return selfBlock.Break(result);
                 }
 
                 return null;
@@ -327,7 +336,8 @@ namespace IronRuby.Builtins {
                 if (comparer != null) {
                     object blockResult;
                     if (comparer.Yield(result, item, out blockResult)) {
-                        return blockResult;
+                        result = blockResult;
+                        return selfBlock.Break(blockResult);
                     }
 
                     if (blockResult == null) {
@@ -353,9 +363,13 @@ namespace IronRuby.Builtins {
         #region partition
 
         [RubyMethod(&quot;partition&quot;)]
-        public static RubyArray/*!*/ Partition(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BlockParam predicate, object self) {
+        public static object Partition(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BlockParam predicate, object self) {
             RubyArray trueSet = new RubyArray();
             RubyArray falseSet = new RubyArray();
+            RubyArray pair = new RubyArray(2);
+            pair.Add(trueSet);
+            pair.Add(falseSet);
+            object result = pair;
 
             Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
                 if (predicate == null) {
@@ -364,7 +378,8 @@ namespace IronRuby.Builtins {
 
                 object blockResult;
                 if (predicate.Yield(item, out blockResult)) {
-                    return blockResult;
+                    result = blockResult;
+                    return selfBlock.Break(blockResult);
                 }
 
                 if (Protocols.IsTrue(blockResult)) {
@@ -376,10 +391,7 @@ namespace IronRuby.Builtins {
                 return null;
             }));
 
-            RubyArray pair = new RubyArray(2);
-            pair.Add(trueSet);
-            pair.Add(falseSet);
-            return pair;
+            return result;
         }
 
         #endregion
@@ -398,7 +410,7 @@ namespace IronRuby.Builtins {
         }
 
         [RubyMethod(&quot;sort_by&quot;)]
-        public static RubyArray/*!*/ SortBy(
+        public static object SortBy(
             CallSiteStorage&lt;EachSite&gt;/*!*/ each, 
             BinaryOpStorage/*!*/ comparisonStorage,
             BinaryOpStorage/*!*/ lessThanStorage,
@@ -407,6 +419,7 @@ namespace IronRuby.Builtins {
 
             // collect key, value pairs
             List&lt;KeyValuePair&lt;object, object&gt;&gt; keyValuePairs = new List&lt;KeyValuePair&lt;object, object&gt;&gt;();
+            object result = null;
 
             // Collect the key, value pairs
             Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
@@ -416,35 +429,42 @@ namespace IronRuby.Builtins {
 
                 object key;
                 if (keySelector.Yield(item, out key)) {
-                    return key;
+                    keyValuePairs = null;
+                    result = key;
+                    return selfBlock.Break(key);
                 }
 
                 keyValuePairs.Add(new KeyValuePair&lt;object, object&gt;(key, item));
                 return null;
             }));
 
+            if (keyValuePairs == null) {
+                return result;
+            }
+
             // sort by keys
             keyValuePairs.Sort(delegate(KeyValuePair&lt;object, object&gt; x, KeyValuePair&lt;object, object&gt; y) {
                 return Protocols.Compare(comparisonStorage, lessThanStorage, greaterThanStorage, x.Key, y.Key);
             });
 
             // return values
-            RubyArray result = new RubyArray(keyValuePairs.Count);
+            RubyArray results = new RubyArray(keyValuePairs.Count);
             foreach (KeyValuePair&lt;object, object&gt; pair in keyValuePairs) {
-                result.Add(pair.Value);
+                results.Add(pair.Value);
             }
 
-            return result;
+            return results;
         }
 
         #endregion
 
         #region zip
 
-        internal static RubyArray/*!*/ Zip(CallSiteStorage&lt;EachSite&gt;/*!*/ each, ConversionStorage&lt;IList&gt;/*!*/ tryToA, BlockParam block,
+        internal static object Zip(CallSiteStorage&lt;EachSite&gt;/*!*/ each, ConversionStorage&lt;IList&gt;/*!*/ tryToA, BlockParam block,
             object self, params IList[]/*!*/ args) {
 
             RubyArray results = (block == null) ? new RubyArray() : null;
+            object result = results;
 
             int index = 0;
             Each(each, self, Proc.Create(each.Context, delegate(BlockParam/*!*/ selfBlock, object _, object item) {
@@ -465,7 +485,8 @@ namespace IronRuby.Builtins {
                 if (block != null) {
                     object blockResult;
                     if (block.Yield(array, out blockResult)) {
-                        return blockResult;
+                        result = blockResult;
+                        return selfBlock.Break(blockResult);
                     }
                 }
                 else {
@@ -474,11 +495,11 @@ namespace IronRuby.Builtins {
                 return null;
             }));
 
-            return results;
+            return result;
         }
 
         [RubyMethod(&quot;zip&quot;)]
-        public static RubyArray/*!*/ Zip(CallSiteStorage&lt;EachSite&gt;/*!*/ each, ConversionStorage&lt;IList&gt;/*!*/ tryToA, BlockParam block,
+        public static object Zip(CallSiteStorage&lt;EachSite&gt;/*!*/ each, ConversionStorage&lt;IList&gt;/*!*/ tryToA, BlockParam block,
             object self, [NotNull]params object[] args) {
 
             // Call to_a on each argument</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Enumerable.cs</filename>
    </modified>
    <modified>
      <diff>@@ -28,6 +28,9 @@ namespace IronRuby.Builtins {
     [RubyConstant(&quot;ENV&quot;)]
     [RubySingleton, Includes(typeof(Enumerable))]
     public static class EnvironmentSingletonOps {
+        private static MutableString/*!*/ FrozenString(object/*!*/ value) {
+            return MutableString.Create((string)value, RubyEncoding.UTF8).Freeze();
+        }
 
         #region Public Instance Methods
 
@@ -36,7 +39,7 @@ namespace IronRuby.Builtins {
         public static MutableString GetVariable(RubyContext/*!*/ context, object/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ name) {
             PlatformAdaptationLayer pal = context.DomainManager.Platform;
             string value = pal.GetEnvironmentVariable(name.ConvertToString());
-            return (value != null) ? MutableString.Create(value) : null;
+            return (value != null) ? FrozenString(value) : null;
         }
 
         [RubyMethod(&quot;[]=&quot;, RubyMethodAttributes.PublicInstance)]
@@ -75,8 +78,8 @@ namespace IronRuby.Builtins {
             }
 
             foreach (DictionaryEntry entry in variables) {
-                MutableString key = MutableString.Create(entry.Key.ToString()).Freeze();
-                MutableString value = MutableString.Create(entry.Value.ToString()).Freeze();
+                MutableString key = FrozenString(entry.Key);
+                MutableString value = FrozenString(entry.Value);
                 object result;
                 if (block.Yield(key, value, out result)) {
                     return result;
@@ -100,8 +103,8 @@ namespace IronRuby.Builtins {
 
             foreach (DictionaryEntry entry in variables) {
                 RubyArray array = new RubyArray(2);
-                array.Add(MutableString.Create(entry.Key.ToString()).Freeze());
-                array.Add(MutableString.Create(entry.Value.ToString()).Freeze());
+                array.Add(FrozenString(entry.Key));
+                array.Add(FrozenString(entry.Value));
                 object result;
                 if (block.Yield(array, out result)) {
                     return result;
@@ -119,7 +122,7 @@ namespace IronRuby.Builtins {
             }
 
             foreach (DictionaryEntry entry in variables) {
-                MutableString name = MutableString.Create(entry.Key.ToString()).Freeze();
+                MutableString name = FrozenString(entry.Key);
                 object result;
                 if (block.Yield(name, out result)) {
                     return result;
@@ -137,7 +140,7 @@ namespace IronRuby.Builtins {
             }
 
             foreach (DictionaryEntry entry in variables) {
-                MutableString value = MutableString.Create(entry.Value.ToString()).Freeze();
+                MutableString value = FrozenString(entry.Value);
                 object result;
                 if (block.Yield(value, out result)) {
                     return result;
@@ -185,7 +188,7 @@ namespace IronRuby.Builtins {
             PlatformAdaptationLayer pal = context.DomainManager.Platform;
             foreach (DictionaryEntry entry in pal.GetEnvironmentVariables()) {
                 if (strValue.Equals(entry.Value)) {
-                    return MutableString.Create(entry.Key.ToString()).Freeze();
+                    return FrozenString(entry.Key);
                 }
             }
             return null;
@@ -215,7 +218,7 @@ namespace IronRuby.Builtins {
             PlatformAdaptationLayer pal = context.DomainManager.Platform;
             Hash result = new Hash(context);
             foreach (DictionaryEntry entry in pal.GetEnvironmentVariables()) {
-                result.Add(MutableString.Create(entry.Value.ToString()).Freeze(), MutableString.Create(entry.Key.ToString()).Freeze());
+                result.Add(FrozenString(entry.Value), FrozenString(entry.Key));
             }
             return result;
         }
@@ -226,7 +229,7 @@ namespace IronRuby.Builtins {
             IDictionary variables = pal.GetEnvironmentVariables();
             RubyArray result = new RubyArray(variables.Count);
             foreach (DictionaryEntry entry in variables) {
-                result.Add(MutableString.Create(entry.Key.ToString()).Freeze());
+                result.Add(FrozenString(entry.Key));
             }
             return result;
         }
@@ -275,10 +278,9 @@ namespace IronRuby.Builtins {
             }
             RubyArray result = new RubyArray(2);
             foreach (DictionaryEntry entry in pal.GetEnvironmentVariables()) {
-                string key = entry.Key.ToString();
-                result.Add(MutableString.Create(key).Freeze());
-                result.Add(MutableString.Create(entry.Value.ToString()).Freeze());
-                pal.SetEnvironmentVariable(key, null);
+                result.Add(FrozenString(entry.Key));
+                result.Add(FrozenString(entry.Value));
+                pal.SetEnvironmentVariable((string)entry.Key, null);
                 break;
             }
             return result;
@@ -289,14 +291,14 @@ namespace IronRuby.Builtins {
             PlatformAdaptationLayer pal = context.DomainManager.Platform;
             Hash result = new Hash(context);
             foreach (DictionaryEntry entry in pal.GetEnvironmentVariables()) {
-                result.Add(MutableString.Create(entry.Key.ToString()).Freeze(), MutableString.Create(entry.Value.ToString()).Freeze());
+                result.Add(FrozenString(entry.Key), FrozenString(entry.Value));
             }
             return result;
         }
 
         [RubyMethod(&quot;to_s&quot;)]
         public static MutableString/*!*/ ToString(object/*!*/ self) {
-            return MutableString.Create(&quot;ENV&quot;);
+            return MutableString.CreateAscii(&quot;ENV&quot;);
         }
 
         [RubyMethod(&quot;values&quot;)]
@@ -305,7 +307,7 @@ namespace IronRuby.Builtins {
             IDictionary variables = pal.GetEnvironmentVariables();
             RubyArray result = new RubyArray(variables.Count);
             foreach (DictionaryEntry entry in variables) {
-                result.Add(MutableString.Create(entry.Value.ToString()).Freeze());
+                result.Add(FrozenString(entry.Value));
             }
             return result;
         }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/EnvironmentSingletonOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -42,8 +42,8 @@ namespace IronRuby.Builtins {
 
             public AddressInUseError() : this(null, null) { }
             public AddressInUseError(string message) : this(message, null) { }
-            public AddressInUseError(string message, Exception inner) : base(RubyErrno.MakeMessage(message, M), inner) { }
-            public AddressInUseError(MutableString message) : base(RubyErrno.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
+            public AddressInUseError(string message, Exception inner) : base(RubyExceptions.MakeMessage(message, M), inner) { }
+            public AddressInUseError(MutableString message) : base(RubyExceptions.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
 
 #if !SILVERLIGHT
             protected AddressInUseError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
@@ -57,8 +57,8 @@ namespace IronRuby.Builtins {
 
             public DomainError() : this(null, null) { }
             public DomainError(string message) : this(message, null) { }
-            public DomainError(string message, Exception inner) : base(RubyErrno.MakeMessage(message, M), inner) { }
-            public DomainError(MutableString message) : base(RubyErrno.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
+            public DomainError(string message, Exception inner) : base(RubyExceptions.MakeMessage(message, M), inner) { }
+            public DomainError(MutableString message) : base(RubyExceptions.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
 
 #if !SILVERLIGHT
             protected DomainError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
@@ -70,7 +70,7 @@ namespace IronRuby.Builtins {
         public class InvalidErrorOps {
             [RubyConstructor]
             public static InvalidError/*!*/ Create(RubyClass/*!*/ self, [DefaultProtocol, DefaultParameterValue(null)]MutableString message) {
-                InvalidError result = new InvalidError(RubyErrno.MakeMessage(ref message, &quot;Invalid Argument&quot;));
+                InvalidError result = new InvalidError(RubyExceptions.MakeMessage(ref message, &quot;Invalid Argument&quot;));
                 RubyExceptionData.InitializeException(result, message);
                 return result;
             }
@@ -80,7 +80,7 @@ namespace IronRuby.Builtins {
         public class FileNotFoundExceptionOps {
             [RubyConstructor]
             public static FileNotFoundException/*!*/ Create(RubyClass/*!*/ self, [DefaultProtocol, DefaultParameterValue(null)]MutableString message) {
-                FileNotFoundException result = new FileNotFoundException(RubyErrno.MakeMessage(ref message, &quot;No such file or directory&quot;));
+                FileNotFoundException result = new FileNotFoundException(RubyExceptions.MakeMessage(ref message, &quot;No such file or directory&quot;));
                 RubyExceptionData.InitializeException(result, message);
                 return result;
             }
@@ -90,7 +90,7 @@ namespace IronRuby.Builtins {
         public class DirectoryNotFoundExceptionOps {
             [RubyConstructor]
             public static DirectoryNotFoundException/*!*/ Create(RubyClass/*!*/ self, [DefaultProtocol, DefaultParameterValue(null)]MutableString message) {
-                DirectoryNotFoundException result = new DirectoryNotFoundException(RubyErrno.MakeMessage(ref message, &quot;Not a directory&quot;));
+                DirectoryNotFoundException result = new DirectoryNotFoundException(RubyExceptions.MakeMessage(ref message, &quot;Not a directory&quot;));
                 RubyExceptionData.InitializeException(result, message);
                 return result;
             }
@@ -100,7 +100,7 @@ namespace IronRuby.Builtins {
         public class UnauthorizedAccessExceptionOps {
             [RubyConstructor]
             public static UnauthorizedAccessException/*!*/ Create(RubyClass/*!*/ self, [DefaultProtocol, DefaultParameterValue(null)]MutableString message) {
-                UnauthorizedAccessException result = new UnauthorizedAccessException(RubyErrno.MakeMessage(ref message, &quot;Permission denied&quot;));
+                UnauthorizedAccessException result = new UnauthorizedAccessException(RubyExceptions.MakeMessage(ref message, &quot;Permission denied&quot;));
                 RubyExceptionData.InitializeException(result, message);
                 return result;
             }
@@ -112,8 +112,8 @@ namespace IronRuby.Builtins {
 
             public ChildError() : this(null, null) { }
             public ChildError(string message) : this(message, null) { }
-            public ChildError(string message, Exception inner) : base(RubyErrno.MakeMessage(message, M), inner) { }
-            public ChildError(MutableString message) : base(RubyErrno.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
+            public ChildError(string message, Exception inner) : base(RubyExceptions.MakeMessage(message, M), inner) { }
+            public ChildError(MutableString message) : base(RubyExceptions.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
 
 #if !SILVERLIGHT
             protected ChildError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
@@ -125,25 +125,20 @@ namespace IronRuby.Builtins {
         public class ExistErrorOps {
             [RubyConstructor]
             public static ExistError/*!*/ Create(RubyClass/*!*/ self, [DefaultProtocol, DefaultParameterValue(null)]MutableString message) {
-                ExistError result = new ExistError(RubyErrno.MakeMessage(ref message, &quot;File exists&quot;));
+                var result = new ExistError(RubyExceptions.MakeMessage(ref message, &quot;File exists&quot;));
                 RubyExceptionData.InitializeException(result, message);
                 return result;
             }
         }
 
-        [RubyClass(&quot;EBADF&quot;), Serializable]
-        public class BadFileDescriptorError : ExternalException {
-            private const string/*!*/ M = &quot;Bad file descriptor&quot;;
-
-            public BadFileDescriptorError() : this(null, null) { }
-            public BadFileDescriptorError(string message) : this(message, null) { }
-            public BadFileDescriptorError(string message, Exception inner) : base(RubyErrno.MakeMessage(message, M), inner) { }
-            public BadFileDescriptorError(MutableString message) : base(RubyErrno.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
-
-#if !SILVERLIGHT
-            protected BadFileDescriptorError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
-                : base(info, context) { }
-#endif
+        [RubyClass(&quot;EBADF&quot;, Extends = typeof(BadFileDescriptorError), Inherits = typeof(ExternalException))]
+        public class BadFileDescriptorErrorOps {
+            [RubyConstructor]
+            public static BadFileDescriptorError/*!*/ Create(RubyClass/*!*/ self, [DefaultProtocol, DefaultParameterValue(null)]MutableString message) {
+                var result = new BadFileDescriptorError(RubyExceptions.MakeMessage(ref message, &quot;Bad file descriptor&quot;));
+                RubyExceptionData.InitializeException(result, message);
+                return result;
+            }
         }
 
         [RubyClass(&quot;EPIPE&quot;), Serializable]
@@ -152,8 +147,8 @@ namespace IronRuby.Builtins {
 
             public PipeError() : this(null, null) { }
             public PipeError(string message) : this(message, null) { }
-            public PipeError(string message, Exception inner) : base(RubyErrno.MakeMessage(message, M), inner) { }
-            public PipeError(MutableString message) : base(RubyErrno.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
+            public PipeError(string message, Exception inner) : base(RubyExceptions.MakeMessage(message, M), inner) { }
+            public PipeError(MutableString message) : base(RubyExceptions.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
 
 #if !SILVERLIGHT
             protected PipeError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
@@ -167,8 +162,8 @@ namespace IronRuby.Builtins {
 
             public NotConnectedError() : this(null, null) { }
             public NotConnectedError(string message) : this(message, null) { }
-            public NotConnectedError(string message, Exception inner) : base(RubyErrno.MakeMessage(message, M), inner) { }
-            public NotConnectedError(MutableString message) : base(RubyErrno.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
+            public NotConnectedError(string message, Exception inner) : base(RubyExceptions.MakeMessage(message, M), inner) { }
+            public NotConnectedError(MutableString message) : base(RubyExceptions.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
 
 #if !SILVERLIGHT
             protected NotConnectedError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
@@ -182,8 +177,8 @@ namespace IronRuby.Builtins {
 
             public ConnectionRefusedError() : this(null, null) { }
             public ConnectionRefusedError(string message) : this(message, null) { }
-            public ConnectionRefusedError(string message, Exception inner) : base(RubyErrno.MakeMessage(message, M), inner) { }
-            public ConnectionRefusedError(MutableString message) : base(RubyErrno.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
+            public ConnectionRefusedError(string message, Exception inner) : base(RubyExceptions.MakeMessage(message, M), inner) { }
+            public ConnectionRefusedError(MutableString message) : base(RubyExceptions.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
 
 #if !SILVERLIGHT
             protected ConnectionRefusedError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
@@ -197,8 +192,8 @@ namespace IronRuby.Builtins {
 
             public ConnectionResetError() : this(null, null) { }
             public ConnectionResetError(string message) : this(message, null) { }
-            public ConnectionResetError(string message, Exception inner) : base(RubyErrno.MakeMessage(message, M), inner) { }
-            public ConnectionResetError(MutableString message) : base(RubyErrno.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
+            public ConnectionResetError(string message, Exception inner) : base(RubyExceptions.MakeMessage(message, M), inner) { }
+            public ConnectionResetError(MutableString message) : base(RubyExceptions.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
 
 #if !SILVERLIGHT
             protected ConnectionResetError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
@@ -212,8 +207,8 @@ namespace IronRuby.Builtins {
 
             public ConnectionAbortError() : this(null, null) { }
             public ConnectionAbortError(string message) : this(message, null) { }
-            public ConnectionAbortError(string message, Exception inner) : base(RubyErrno.MakeMessage(message, M), inner) { }
-            public ConnectionAbortError(MutableString message) : base(RubyErrno.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
+            public ConnectionAbortError(string message, Exception inner) : base(RubyExceptions.MakeMessage(message, M), inner) { }
+            public ConnectionAbortError(MutableString message) : base(RubyExceptions.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
 
 #if !SILVERLIGHT
             protected ConnectionAbortError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
@@ -227,8 +222,8 @@ namespace IronRuby.Builtins {
 
             public ImproperLinkError() : this(null, null) { }
             public ImproperLinkError(string message) : this(message, null) { }
-            public ImproperLinkError(string message, Exception inner) : base(RubyErrno.MakeMessage(message, M), inner) { }
-            public ImproperLinkError(MutableString message) : base(RubyErrno.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
+            public ImproperLinkError(string message, Exception inner) : base(RubyExceptions.MakeMessage(message, M), inner) { }
+            public ImproperLinkError(MutableString message) : base(RubyExceptions.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
 
 #if !SILVERLIGHT
             protected ImproperLinkError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
@@ -243,8 +238,8 @@ namespace IronRuby.Builtins {
 
         public InvalidSeekError() : this(null, null) { }
         public InvalidSeekError(string message) : this(message, null) { }
-        public InvalidSeekError(string message, Exception inner) : base(RubyErrno.MakeMessage(message, M), inner) { }
-        public InvalidSeekError(MutableString message) : base(RubyErrno.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
+        public InvalidSeekError(string message, Exception inner) : base(RubyExceptions.MakeMessage(message, M), inner) { }
+        public InvalidSeekError(MutableString message) : base(RubyExceptions.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
 
 #if !SILVERLIGHT
         protected InvalidSeekError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Errno.cs</filename>
    </modified>
    <modified>
      <diff>@@ -81,7 +81,7 @@ namespace IronRuby.Builtins {
         public static Exception/*!*/ ReinitializeException(RubyContext/*!*/ context, Exception/*!*/ self, [DefaultParameterValue(null)]object message) {
             var instance = RubyExceptionData.GetInstance(self);
             instance.Backtrace = null;
-            instance.Message = message ?? MutableString.Create(context.GetClassOf(self).Name);
+            instance.Message = message ?? MutableString.Create(context.GetClassOf(self).Name, RubyEncoding.ClassName);
             return self;
         }
 
@@ -134,7 +134,7 @@ namespace IronRuby.Builtins {
 
                         ParameterExpression messageVariable = null;
 
-                        // new &lt;exception-type&gt;(GetClrMessage(&lt;class&gt;, #message = &lt;message&gt;))
+                        // RubyOps.MarkException(new &lt;exception-type&gt;(GetClrMessage(&lt;class&gt;, #message = &lt;message&gt;)))
                         if (cls.BuildAllocatorCall(metaBuilder, args, () =&gt;
                             Ast.Call(null, new Func&lt;RubyClass, object, string&gt;(GetClrMessage).Method,
                                 classExpression,
@@ -172,7 +172,7 @@ namespace IronRuby.Builtins {
             object message = RubyExceptionData.GetInstance(self).Message;
             string className = inspectStorage.Context.GetClassDisplayName(self);
 
-            MutableString result = MutableString.CreateMutable();
+            MutableString result = MutableString.CreateMutable(RubyEncoding.ClassName);
             result.Append(&quot;#&lt;&quot;);
             result.Append(className);
             result.Append(&quot;: &quot;);</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ExceptionOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -211,7 +211,7 @@ namespace IronRuby.Builtins {
     public static class SystemCallErrorOps {
         [RubyConstructor]
         public static ExternalException/*!*/ Factory(RubyClass/*!*/ self, [DefaultProtocol]MutableString message) {
-            ExternalException result = new ExternalException(RubyErrno.MakeMessage(ref message, &quot;unknown error&quot;));
+            ExternalException result = new ExternalException(RubyExceptions.MakeMessage(ref message, &quot;unknown error&quot;));
             RubyExceptionData.InitializeException(result, message);
             return result;
         }
@@ -219,9 +219,9 @@ namespace IronRuby.Builtins {
         [RubyConstructor]
         public static ExternalException/*!*/ Factory(RubyClass/*!*/ self, int errorCode) {
             // TODO:
-            var message = MutableString.Create(&quot;system error #&quot; + errorCode);
+            var message = MutableString.Create(&quot;system error #&quot; + errorCode, RubyEncoding.UTF8);
 
-            ExternalException result = new ExternalException(RubyErrno.MakeMessage(ref message, &quot;unknown error&quot;));
+            ExternalException result = new ExternalException(RubyExceptions.MakeMessage(ref message, &quot;unknown error&quot;));
             RubyExceptionData.InitializeException(result, message);
             return result;
         }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Exceptions.cs</filename>
    </modified>
    <modified>
      <diff>@@ -26,7 +26,7 @@ namespace IronRuby.Builtins {
         [RubyMethodAttribute(&quot;to_s&quot;)]
         public static MutableString/*!*/ ToString(bool self) {
             Debug.Assert(self == false);
-            return MutableString.Create(&quot;false&quot;); 
+            return MutableString.CreateAscii(&quot;false&quot;); 
         }
 
         [RubyMethodAttribute(&quot;&amp;&quot;)]</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FalseClass.cs</filename>
    </modified>
    <modified>
      <diff>@@ -24,6 +24,7 @@ using IronRuby.Runtime;
 using IronRuby.Runtime.Calls;
 using Microsoft.Scripting;
 using Microsoft.Scripting.Runtime;
+using IronRuby.Compiler;
 
 namespace IronRuby.Builtins {
 
@@ -41,8 +42,9 @@ namespace IronRuby.Builtins {
             [DefaultProtocol, NotNull]Union&lt;int, MutableString&gt; descriptorOrPath, [Optional, DefaultProtocol]MutableString mode, [Optional]int permission) {
 
             if (descriptorOrPath.IsFixnum()) {
-                // TODO: descriptor
-                throw new NotImplementedException();
+                return new RubyFile(
+                    self.Context, RubyIOOps.GetDescriptorStream(self.Context, descriptorOrPath.Fixnum()), descriptorOrPath.Fixnum(), IOModeEnum.Parse(mode)
+                );
             } else {
                 // TODO: permissions
                 return CreateFile(self, descriptorOrPath.Second, mode);
@@ -54,8 +56,9 @@ namespace IronRuby.Builtins {
             [DefaultProtocol, NotNull]Union&lt;int, MutableString&gt; descriptorOrPath, int mode, [Optional]int permission) {
 
             if (descriptorOrPath.IsFixnum()) {
-                // TODO: descriptor
-                throw new NotImplementedException();
+                return new RubyFile(
+                    self.Context, RubyIOOps.GetDescriptorStream(self.Context, descriptorOrPath.Fixnum()), descriptorOrPath.Fixnum(), (IOMode)mode
+                );
             } else {
                 // TODO: permissions
                 return CreateFile(self, descriptorOrPath.Second, mode);
@@ -64,17 +67,17 @@ namespace IronRuby.Builtins {
 
         [RubyConstructor]
         public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, [NotNull]MutableString/*!*/ path) {
-            return new RubyFile(self.Context, path.ConvertToString(), &quot;r&quot;);
+            return new RubyFile(self.Context, path.ConvertToString(), IOMode.Default);
         }
 
         [RubyConstructor]
         public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, [NotNull]MutableString/*!*/ path, MutableString mode) {
-            return new RubyFile(self.Context, path.ConvertToString(), (mode != null) ? mode.ConvertToString() : &quot;r&quot;);
+            return new RubyFile(self.Context, path.ConvertToString(), IOModeEnum.Parse(mode));
         }
 
         [RubyConstructor]
         public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, [NotNull]MutableString/*!*/ path, int mode) {
-            return new RubyFile(self.Context, path.ConvertToString(), (RubyFileMode)mode);
+            return new RubyFile(self.Context, path.ConvertToString(), (IOMode)mode);
         }
 
         #endregion
@@ -82,10 +85,10 @@ namespace IronRuby.Builtins {
         #region Declared Constants
 
         static RubyFileOps() {
-            ALT_SEPARATOR = MutableString.Create(AltDirectorySeparatorChar.ToString()).Freeze();
-            SEPARATOR = MutableString.Create(DirectorySeparatorChar.ToString()).Freeze();
+            ALT_SEPARATOR = MutableString.CreateAscii(AltDirectorySeparatorChar.ToString()).Freeze();
+            SEPARATOR = MutableString.CreateAscii(DirectorySeparatorChar.ToString()).Freeze();
             Separator = SEPARATOR;
-            PATH_SEPARATOR = MutableString.Create(PathSeparatorChar.ToString()).Freeze();
+            PATH_SEPARATOR = MutableString.CreateAscii(PathSeparatorChar.ToString()).Freeze();
         }
 
         private const char AltDirectorySeparatorChar = '\\';
@@ -113,13 +116,13 @@ namespace IronRuby.Builtins {
         [RubyModule(&quot;Constants&quot;)]
         public static class Constants {
             [RubyConstant]
-            public readonly static int APPEND = (int)RubyFileMode.APPEND;
+            public readonly static int APPEND = (int)IOMode.WriteAppends;
             [RubyConstant]
-            public readonly static int BINARY = (int)RubyFileMode.BINARY;
+            public readonly static int BINARY = (int)IOMode.PreserveEndOfLines;
             [RubyConstant]
-            public readonly static int CREAT = (int)RubyFileMode.CREAT;
+            public readonly static int CREAT = (int)IOMode.CreateIfNotExists;
             [RubyConstant]
-            public readonly static int EXCL = (int)RubyFileMode.EXCL;
+            public readonly static int EXCL = (int)IOMode.ErrorIfExists;
             [RubyConstant]
             public readonly static int FNM_CASEFOLD = 0x08;
             [RubyConstant]
@@ -139,15 +142,15 @@ namespace IronRuby.Builtins {
             [RubyConstant]
             public readonly static int LOCK_UN = 0x08;
             [RubyConstant]
-            public readonly static int NONBLOCK = (int)RubyFileMode.NONBLOCK;
+            public readonly static int NONBLOCK = (int)IOMode.WriteOnly;
             [RubyConstant]
-            public readonly static int RDONLY = (int)RubyFileMode.RDONLY;
+            public readonly static int RDONLY = (int)IOMode.ReadOnly;
             [RubyConstant]
-            public readonly static int RDWR = (int)RubyFileMode.RDWR;
+            public readonly static int RDWR = (int)IOMode.ReadWrite;
             [RubyConstant]
-            public readonly static int TRUNC = (int)RubyFileMode.TRUNC;
+            public readonly static int TRUNC = (int)IOMode.Truncate;
             [RubyConstant]
-            public readonly static int WRONLY = (int)RubyFileMode.WRONLY;
+            public readonly static int WRONLY = (int)IOMode.WriteOnly;
         }
 
         #endregion
@@ -184,16 +187,6 @@ namespace IronRuby.Builtins {
             return true;
         }
 
-        private static MutableString/*!*/ TrimTrailingSlashes(MutableString/*!*/ path) {
-            int offset = path.Length - 1;
-            while (offset &gt; 0) {
-                if (path.GetChar(offset) != '/' &amp;&amp; path.GetChar(offset) != '\\')
-                    break;
-                --offset;
-            }
-            return path.GetSlice(0, offset + 1);
-        }
-
         [RubyMethod(&quot;basename&quot;, RubyMethodAttributes.PublicSingleton)]
         public static MutableString/*!*/ Basename(RubyClass/*!*/ self,
             [DefaultProtocol, NotNull]MutableString/*!*/ path, [DefaultProtocol, NotNull, Optional]MutableString extensionFilter) {
@@ -202,34 +195,32 @@ namespace IronRuby.Builtins {
                 return path;
             }
 
-            MutableString trimmedPath = TrimTrailingSlashes(path);
+            string trimmedPath = path.ConvertToString().TrimEnd('\\', '/');
 
-            // Special cases of drive letters C:\\ or C:/
-            if (trimmedPath.Length == 2) {
-                if (Char.IsLetter(trimmedPath.GetChar(0)) &amp;&amp; trimmedPath.GetChar(1) == ':') {
-                    var result = (path.Length &gt; 2 ? MutableString.Create(path.GetChar(2).ToString()) : MutableString.CreateMutable());
-                    return result.TaintBy(path);
+            if (trimmedPath.Length == 0) {
+                return path.GetSlice(0, 1);
+            } else if (trimmedPath.Length == 2 &amp;&amp; Tokenizer.IsLetter(trimmedPath[0]) &amp;&amp; trimmedPath[1] == ':') {
+                // drive letter
+                var result = MutableString.CreateMutable(path.Encoding);
+                if (path.GetCharCount() &gt; 2) {
+                    result.Append(path.GetChar(2));
                 }
+                return result.TaintBy(path);
             }
 
-            string trimmedPathAsString = trimmedPath.ConvertToString();
-            if (trimmedPathAsString == &quot;/&quot;) {
-                return trimmedPath;
-            }
-
-            string filename = Path.GetFileName(trimmedPath.ConvertToString());
+            string filename = Path.GetFileName(trimmedPath);
 
             // Handle UNC host names correctly
-            string root = Path.GetPathRoot(trimmedPath.ConvertToString());
+            string root = Path.GetPathRoot(trimmedPath);
             if (MutableString.IsNullOrEmpty(extensionFilter)) {
-                return MutableString.Create(trimmedPathAsString == root ? root : filename);
+                return MutableString.Create(trimmedPath == root ? root : filename, path.Encoding);
             }
 
             string fileExtension = Path.GetExtension(filename);
             string basename = Path.GetFileNameWithoutExtension(filename);
 
             string strResult = WildcardExtensionMatch(fileExtension, extensionFilter.ConvertToString()) ? basename : filename;
-            return RubyUtils.CanonicalizePath(MutableString.Create(strResult)).TaintBy(path);
+            return RubyUtils.CanonicalizePath(MutableString.Create(strResult, path.Encoding)).TaintBy(path);
         }
 
         internal static void Chmod(string path, int permission) {
@@ -299,7 +290,7 @@ namespace IronRuby.Builtins {
         public static int Delete(RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path) {
             string strPath = path.ConvertToString();
             if (!FileExists(self.Context, strPath)) {
-                throw RubyErrno.CreateENOENT(String.Format(&quot;No such file or directory - {0}&quot;, strPath));
+                throw RubyExceptions.CreateENOENT(String.Format(&quot;No such file or directory - {0}&quot;, strPath));
             }
 #if !SILVERLIGHT
             FileAttributes oldAttributes = File.GetAttributes(strPath);
@@ -340,7 +331,7 @@ namespace IronRuby.Builtins {
                 // handle top-level UNC paths
                 directoryName = Path.GetDirectoryName(strPath);
                 if (directoryName == null) {
-                    return MutableString.Create(strPath);
+                    return MutableString.Create(strPath, RubyEncoding.Path);
                 }
 
                 string fileName = Path.GetFileName(strPath);
@@ -354,7 +345,7 @@ namespace IronRuby.Builtins {
             }
 
             directoryName = String.IsNullOrEmpty(directoryName) ? &quot;.&quot; : directoryName;
-            return MutableString.Create(directoryName);
+            return MutableString.Create(directoryName, RubyEncoding.Path);
         }
 
         private static bool IsValidPath(string path) {
@@ -391,7 +382,7 @@ namespace IronRuby.Builtins {
                 // File.extname(&quot;.foo&quot;) should be &quot;&quot;, but Path.GetExtension(&quot;.foo&quot;) returns &quot;.foo&quot;
                 extension = String.Empty;
             }
-            return MutableString.Create(extension).TaintBy(path);
+            return MutableString.Create(extension, path.Encoding).TaintBy(path);
         }
 
         #region fnmatch
@@ -399,7 +390,7 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;fnmatch&quot;, RubyMethodAttributes.PublicSingleton)]
         [RubyMethod(&quot;fnmatch?&quot;, RubyMethodAttributes.PublicSingleton)]
         public static bool FnMatch(object/*!*/ self, [NotNull]MutableString/*!*/ pattern, [NotNull]MutableString/*!*/ path, [Optional]int flags) {
-            return Glob.FnMatch(pattern, path, flags);
+            return Glob.FnMatch(pattern.ConvertToString(), path.ConvertToString(), flags);
         }
 
         #endregion
@@ -413,7 +404,7 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;join&quot;, RubyMethodAttributes.PublicSingleton)]
         public static MutableString Join(ConversionStorage&lt;MutableString&gt;/*!*/ stringCast, RubyClass/*!*/ self, [NotNull]params object[] parts) {
-            MutableString result = MutableString.CreateMutable();
+            MutableString result = MutableString.CreateMutable(RubyEncoding.Binary);
             Dictionary&lt;object, bool&gt; visitedLists = null;
             var worklist = new Stack&lt;object&gt;();
             int current = 0;
@@ -496,7 +487,8 @@ namespace IronRuby.Builtins {
                 context.DomainManager.Platform, 
                 path.ConvertToString(),
                 basePath == null ? null : basePath.ConvertToString());
-            return MutableString.Create(result);
+
+            return MutableString.Create(result, RubyEncoding.Path);
         }
 #endif
 
@@ -525,12 +517,12 @@ namespace IronRuby.Builtins {
             [DefaultProtocol, NotNull]MutableString/*!*/ oldPath, [DefaultProtocol, NotNull]MutableString/*!*/ newPath) {
 
             if (oldPath.IsEmpty || newPath.IsEmpty) {
-                throw RubyErrno.CreateENOENT();
+                throw RubyExceptions.CreateENOENT();
             }
 
             string strOldPath = oldPath.ConvertToString();
             if (!FileExists(context, strOldPath) &amp;&amp; !DirectoryExists(context, strOldPath)) {
-                throw RubyErrno.CreateENOENT(String.Format(&quot;No such file or directory - {0}&quot;, oldPath));
+                throw RubyExceptions.CreateENOENT(String.Format(&quot;No such file or directory - {0}&quot;, oldPath));
             }
 
             string strNewPath = newPath.ConvertToString();
@@ -561,7 +553,28 @@ namespace IronRuby.Builtins {
             return result;
         }
 
-        //truncate
+#if !SILVERLIGHT
+        [RubyMethod(&quot;truncate&quot;, BuildConfig = &quot;!SILVERLIGHT&quot;)]
+        public static int Truncate(RubyFile/*!*/ self, [DefaultProtocol]int size) {
+            if (size &lt; 0) {
+                throw new InvalidError();
+            }
+
+            self.Length = size;
+            return 0;
+        }
+
+        [RubyMethod(&quot;truncate&quot;, RubyMethodAttributes.PublicSingleton, BuildConfig = &quot;!SILVERLIGHT&quot;)]
+        public static int Truncate(RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path, [DefaultProtocol]int size) {
+            if (size &lt; 0) {
+                throw new InvalidError();
+            }
+            using (RubyFile f = new RubyFile(self.Context, path.ConvertToString(), IOMode.ReadWrite)) {
+                f.Length = size;
+            }
+            return 0;
+        }
+#endif
 
         internal static readonly object UmaskKey = new object();
 
@@ -591,7 +604,7 @@ namespace IronRuby.Builtins {
         public static int UpdateTimes(RubyClass/*!*/ self, DateTime accessTime, DateTime modifiedTime, [NotNull]MutableString/*!*/ path) {
             string strPath = path.ConvertToString();
             if (!FileExists(self.Context, strPath)) {
-                throw RubyErrno.CreateENOENT(String.Format(&quot;No such file or directory - {0}&quot;, strPath));
+                throw RubyExceptions.CreateENOENT(String.Format(&quot;No such file or directory - {0}&quot;, strPath));
             }
 
             FileInfo info = new FileInfo(strPath);
@@ -659,12 +672,15 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;inspect&quot;)]
         public static MutableString/*!*/ Inspect(RubyContext/*!*/ context, RubyFile/*!*/ self) {
-            return MutableString.CreateMutable(&quot;#&lt;File:&quot;).Append(self.Path).Append('&gt;');
+            return MutableString.CreateMutable(RubyEncoding.Binary).
+                Append(&quot;#&lt;File:&quot;).
+                Append(self.Path).
+                Append('&gt;');
         }
 
         [RubyMethod(&quot;path&quot;)]
-        public static MutableString/*!*/ GetPath(RubyFile/*!*/ self) {
-            return MutableString.Create(self.Path);
+        public static MutableString GetPath(RubyFile/*!*/ self) {
+            return self.Path != null ? MutableString.Create(self.Path, RubyEncoding.Path) : null;
         }
 
         //truncate
@@ -688,7 +704,7 @@ namespace IronRuby.Builtins {
                 if (TryCreate(context, path, out fsi)) {
                     return fsi;
                 } else {
-                    throw RubyErrno.CreateENOENT(String.Format(&quot;No such file or directory - {0}&quot;, path));
+                    throw RubyExceptions.CreateENOENT(String.Format(&quot;No such file or directory - {0}&quot;, path));
                 }
             }
 
@@ -700,7 +716,7 @@ namespace IronRuby.Builtins {
                 } else if (pal.DirectoryExists(path)) {
                     result = new DirectoryInfo(path);                    
                 } else if (path.ToUpper().Equals(NUL_VALUE)) {
-                    result = null;
+                    result = new DeviceInfo(NUL_VALUE);
                 } else {
                     return false;
                 }
@@ -787,13 +803,12 @@ namespace IronRuby.Builtins {
 
             [RubyMethod(&quot;file?&quot;)]
             public static bool IsFile(FileSystemInfo/*!*/ self) {
-                return (self is FileInfo);
+                return self is FileInfo;
             }
 
             [RubyMethod(&quot;ftype&quot;)]
             public static MutableString FileType(FileSystemInfo/*!*/ self) {
-                string result = IsFile(self) ? &quot;file&quot; : &quot;directory&quot;;
-                return MutableString.Create(result);
+                return MutableString.CreateAscii(IsFile(self) ? &quot;file&quot; : &quot;directory&quot;);
             }
 
             [RubyMethod(&quot;gid&quot;)]
@@ -813,7 +828,7 @@ namespace IronRuby.Builtins {
 
             [RubyMethod(&quot;inspect&quot;)]
             public static MutableString/*!*/ Inspect(RubyContext/*!*/ context, FileSystemInfo/*!*/ self) {
-               return MutableString.Create(String.Format(
+               return MutableString.CreateAscii(String.Format(
                     &quot;#&lt;File::Stat dev={0}, ino={1}, mode={2}, nlink={3}, uid={4}, gid={5}, rdev={6}, size={7}, blksize={8}, blocks={9}, atime={10}, mtime={11}, ctime={12}&quot;,
                     context.Inspect(DeviceId(self)),
                     context.Inspect(Inode(self)),
@@ -881,17 +896,25 @@ namespace IronRuby.Builtins {
 
             [RubyMethod(&quot;size&quot;)]
             public static int Size(FileSystemInfo/*!*/ self) {
+                if (self is DeviceInfo) {
+                    return 0;
+                }
+
                 FileInfo info = (self as FileInfo);
                 return (info == null) ? 0 : (int)info.Length;
             }
 
             [RubyMethod(&quot;size?&quot;)]
             public static object NullableSize(FileSystemInfo/*!*/ self) {
+                if (self is DeviceInfo) {
+                    return 0;
+                }
+
                 FileInfo info = (self as FileInfo);
                 if (info == null) {
                     return null;
                 }
-                return (int)info.Length;
+                return (info.Length == 0) ? null : (object)(int)info.Length;
             }
 
             [RubyMethod(&quot;socket?&quot;)]
@@ -924,7 +947,33 @@ namespace IronRuby.Builtins {
 
             [RubyMethod(&quot;zero?&quot;)]
             public static bool IsZeroLength(FileSystemInfo/*!*/ self) {
-                return (Size(self) == 0);
+                if (self is DeviceInfo) {
+                    return true;
+                }
+
+                FileInfo info = (self as FileInfo);
+                return (info == null) ? false : info.Length == 0;
+            }
+
+            internal class DeviceInfo : FileSystemInfo {
+                
+                private string/*!*/ _name;
+
+                internal DeviceInfo(string/*!*/ name) {
+                    _name = name;
+                }
+
+                public override void Delete() {
+                    throw new NotImplementedException();
+                }
+
+                public override bool Exists {
+                    get { return true; }
+                }
+
+                public override string Name {
+                    get { return _name; }
+                }
             }
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FileOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -161,10 +161,10 @@ namespace IronRuby.Builtins {
 
             using (IDisposable handle = RubyUtils.InfiniteInspectTracker.TrackObject(self)) {
                 if (handle == null) {
-                    return MutableString.Create(&quot;{...}&quot;);
+                    return MutableString.CreateAscii(&quot;{...}&quot;);
                 }
 
-                MutableString str = MutableString.CreateMutable();
+                MutableString str = MutableString.CreateMutable(RubyEncoding.Binary);
                 str.Append('{');
                 bool first = true;
                 foreach (var entry in self) {</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/HashOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -14,19 +14,17 @@
  * ***************************************************************************/
 
 using System;
-using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
-using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Threading;
 using IronRuby.Compiler.Generation;
 using IronRuby.Runtime;
 using IronRuby.Runtime.Calls;
+using IronRuby.Runtime.Conversions;
 using Microsoft.Scripting.Math;
 using Microsoft.Scripting.Runtime;
 using Ast = System.Linq.Expressions.Expression;
-using System.Collections;
 
 namespace IronRuby.Builtins {
 
@@ -34,7 +32,15 @@ namespace IronRuby.Builtins {
     /// Implementation of IO builtin class. 
     /// &lt;/summary&gt;
     [RubyClass(&quot;IO&quot;, Extends = typeof(RubyIO)), Includes(typeof(RubyFileOps.Constants), typeof(Enumerable))]
+    [Includes(typeof(PrintOps), Copy = true)]
     public class RubyIOOps {
+        internal static Stream/*!*/ GetDescriptorStream(RubyContext/*!*/ context, int descriptor) {
+            Stream stream = context.GetStream(descriptor);
+            if (stream == null) {
+                throw RubyExceptions.CreateEBADF();
+            }
+            return stream;
+        }
 
         #region Constants
 
@@ -52,48 +58,70 @@ namespace IronRuby.Builtins {
         #region Ruby Constructors
 
         [RubyConstructor]
-        public static RubyIO/*!*/ CreateIO(RubyClass/*!*/ self) {
-            // TODO: should create an IO object with an uninitialized stream
-            throw new NotImplementedException();
+        public static RubyIO/*!*/ Create(RubyClass/*!*/ self, [DefaultProtocol]int descriptor, 
+            [DefaultProtocol, Optional, NotNull]MutableString mode) {
+            return Create(self, descriptor, (int)IOModeEnum.Parse(mode));
         }
 
         [RubyConstructor]
-        public static RubyIO/*!*/ CreateIO(RubyClass/*!*/ self, 
-            [DefaultProtocol]int fileDescriptor, [DefaultProtocol, NotNull, Optional]MutableString modeString) {
-
-            // TODO: a new RubyIO should be created here
-            RubyIO result = self.Context.GetDescriptor(fileDescriptor);
-            if (modeString != null) {
-                result.ResetIOMode(modeString.ConvertToString());
-            }
-            return result;
+        public static RubyIO/*!*/ Create(RubyClass/*!*/ self, [DefaultProtocol]int descriptor, int mode) {
+            return new RubyIO(self.Context, GetDescriptorStream(self.Context, descriptor), descriptor, (IOMode)mode);
         }
 
         [RubyMethod(&quot;initialize&quot;, RubyMethodAttributes.PrivateInstance)]
-        public static void CreateIO(RubyIO/*!*/ self) {
-            // TODO:
+        public static RubyIO/*!*/ Reinitialize(RubyIO/*!*/ self, [DefaultProtocol]int descriptor,
+            [DefaultProtocol, Optional, NotNull]MutableString mode) {
+            return Reinitialize(self, descriptor, (int)IOModeEnum.Parse(mode));
         }
 
         [RubyMethod(&quot;initialize&quot;, RubyMethodAttributes.PrivateInstance)]
-        public static void CreateIO(RubyIO/*!*/ self,
-            [DefaultProtocol]int fileDescriptor, [DefaultProtocol, NotNull, Optional]MutableString modeString) {
-
-            // TODO:
-            if (modeString != null) {
-                self.ResetIOMode(modeString.ConvertToString());
-            }
+        public static RubyIO/*!*/ Reinitialize(RubyIO/*!*/ self, [DefaultProtocol]int descriptor, int mode) {
+            self.Mode = (IOMode)mode;
+            self.SetStream(GetDescriptorStream(self.Context, descriptor));
+            self.SetFileDescriptor(descriptor);
+            return self;
         }
 
-        //initialize_copy
+        [RubyMethod(&quot;initialize_copy&quot;, RubyMethodAttributes.PrivateInstance)]
+        public static RubyIO/*!*/ InitializeCopy(RubyIO/*!*/ self, [NotNull]RubyIO/*!*/ source) {
+            Stream stream = source.GetStream();
+            int descriptor = self.Context.DuplicateFileDescriptor(source.GetFileDescriptor());
+
+            self.SetStream(stream);
+            self.SetFileDescriptor(descriptor);
+            self.Mode = source.Mode;
+            return self;
+        }
 
         [RubyMethod(&quot;for_fd&quot;, RubyMethodAttributes.PublicSingleton)]
         public static RuleGenerator/*!*/ ForFileDescriptor() {
             return new RuleGenerator(RuleGenerators.InstanceConstructor);
         }
 
-        #endregion
+        [RubyMethod(&quot;reopen&quot;)]
+        public static RubyIO/*!*/ Reopen(RubyIO/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path,
+            [DefaultProtocol, Optional, NotNull]MutableString mode) {
+            return Reopen(self, path, (int)IOModeEnum.Parse(mode, self.Mode));
+        }
 
-        #region Public singleton methods
+        [RubyMethod(&quot;reopen&quot;)]
+        public static RubyIO/*!*/ Reopen(RubyIO/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path, int mode) {
+            Stream newStream = RubyFile.OpenFileStream(self.Context, path.ConvertToString(), (IOMode)mode);
+            self.Context.SetStream(self.GetFileDescriptor(), newStream);
+            self.SetStream(newStream);
+            self.Mode = (IOMode)mode;
+            return self;
+        }
+
+        [RubyMethod(&quot;reopen&quot;)]
+        public static RubyIO/*!*/ Reopen(RubyIO/*!*/ self, [NotNull]RubyIO/*!*/ source) {
+            self.Context.RedirectFileDescriptor(self.GetFileDescriptor(), source.GetFileDescriptor());
+            self.SetStream(source.GetStream());
+            self.Mode = source.Mode;
+            return self;
+        }
+
+        #endregion
 
         internal static object TryInvokeOpenBlock(RubyContext/*!*/ context, BlockParam/*!*/ block, RubyIO/*!*/ io) {
             if (block == null)
@@ -107,22 +135,6 @@ namespace IronRuby.Builtins {
             }
         }
 
-        #region foreach
-
-        [RubyMethod(&quot;foreach&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static void ForEach(BlockParam block, RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path) {
-            ForEach(block, self, path, self.Context.InputSeparator);
-        }
-
-        [RubyMethod(&quot;foreach&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static void ForEach(BlockParam block, RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path, MutableString separator) {
-            using (RubyIO io = new RubyIO(self.Context, File.OpenRead(path.ConvertToString()), &quot;r&quot;)) {
-                Each(block, io, separator);
-            }
-        }
-
-        #endregion
-
         #region open
 
         [RubyMethod(&quot;open&quot;, RubyMethodAttributes.PublicSingleton)]
@@ -141,8 +153,8 @@ namespace IronRuby.Builtins {
                         metaBuilder.BfcVariable = metaBuilder.GetTemporary(typeof(BlockParam), &quot;#bfc&quot;);
                     }
 
-                    metaBuilder.Result = Ast.Call(typeof(RubyIOOps).GetMethod(&quot;InvokeOpenBlock&quot;), 
-                        args.MetaContext.Expression, 
+                    metaBuilder.Result = Ast.Call(new Func&lt;UnaryOpStorage, BlockParam, object, object&gt;(InvokeOpenBlock).Method, 
+                        Ast.Constant(new UnaryOpStorage(args.RubyContext)),
                         metaBuilder.BfcVariable, 
                         metaBuilder.Result
                     );
@@ -155,25 +167,38 @@ namespace IronRuby.Builtins {
         }
 
         [Emitted]
-        public static object InvokeOpenBlock(RubyContext/*!*/ context, BlockParam/*!*/ block, object obj) {
-            RubyIO io;
-            if (!RubyOps.IsRetrySingleton(obj) &amp;&amp; block != null &amp;&amp; (io = obj as RubyIO) != null) {
+        public static object InvokeOpenBlock(UnaryOpStorage/*!*/ closeStorage, BlockParam/*!*/ block, object obj) {
+            object result = obj;
+            if (!RubyOps.IsRetrySingleton(obj) &amp;&amp; block != null) {
                 try {
-                    block.Yield(io, out obj);
+                    block.Yield(obj, out result);
                 } finally {
-                    io.Close();
+                    try {
+                        var site = closeStorage.GetCallSite(&quot;close&quot;);
+                        site.Target(site, obj);                        
+                    } catch (SystemException) {
+                        // MRI: nop
+                    }
                 }
             }
-            return obj;
+            return result;
         }
 
         #endregion
 
         #region pipe, popen
-#if !SILVERLIGHT
 
-        //pipe
+        [RubyMethod(&quot;pipe&quot;, RubyMethodAttributes.PublicSingleton, BuildConfig = &quot;!SILVERLIGHT&quot;)]
+        public static RubyArray/*!*/ OpenPipe(RubyClass/*!*/ self) {
+            Stream reader, writer;
+            RubyPipe.CreatePipe(out reader, out writer);
+            RubyArray result = new RubyArray(2);
+            result.Add(new RubyIO(self.Context, reader, IOMode.ReadOnly));
+            result.Add(new RubyIO(self.Context, writer, IOMode.WriteOnly));
+            return result;
+        }
 
+#if !SILVERLIGHT
         [RubyMethod(&quot;popen&quot;, RubyMethodAttributes.PublicSingleton, BuildConfig = &quot;!SILVERLIGHT&quot;)]
         public static object OpenPipe(RubyContext/*!*/ context, BlockParam block, RubyClass/*!*/ self,
             [DefaultProtocol, NotNull]MutableString/*!*/ command, [DefaultProtocol, Optional, NotNull]MutableString modeString) {
@@ -185,42 +210,51 @@ namespace IronRuby.Builtins {
         public static RubyIO/*!*/ OpenPipe(RubyContext/*!*/ context, RubyClass/*!*/ self,
             [DefaultProtocol, NotNull]MutableString/*!*/ command, [DefaultProtocol, Optional, NotNull]MutableString modeString) {
 
-            bool preserveEndOfLines;
-            IOMode mode = RubyIO.ParseIOMode(modeString.ConvertToString(), out preserveEndOfLines);
+            IOMode mode = IOModeEnum.Parse(modeString);
 
             ProcessStartInfo startInfo = KernelOps.GetShell(context, command);
             startInfo.UseShellExecute = false;
 
-            if (mode == IOMode.ReadOnlyFromStart) {
-                startInfo.RedirectStandardOutput = true;
-            } else if (mode == IOMode.WriteOnlyAppend || mode == IOMode.WriteOnlyTruncate) {
-                startInfo.RedirectStandardInput = true;
-            } else {
-                startInfo.RedirectStandardOutput = true;
-                startInfo.RedirectStandardInput = true;
-            }
+            bool redirectStandardInput = mode.CanWrite();
+            bool redirectStandardOutput = mode.CanRead();
 
-            Process process;
-            try {
-                process = Process.Start(startInfo);
-            } catch (Exception e) {
-                throw RubyErrno.CreateENOENT(startInfo.FileName, e);
-            }
-
-            context.ChildProcessExitStatus = new RubyProcess.Status(process);
+            Process process = OpenPipe(context, command, redirectStandardInput, redirectStandardOutput, false);
 
             StreamReader reader = null;
             StreamWriter writer = null;
-            if (startInfo.RedirectStandardOutput) {
+            if (redirectStandardOutput) {
                 reader = process.StandardOutput;
             }
 
-            if (startInfo.RedirectStandardInput) {
+            if (redirectStandardInput) {
                 writer = process.StandardInput;
             }
 
-            return new RubyIO(context, reader, writer, modeString.ConvertToString());
+            return new RubyIO(context, reader, writer, mode);
         }
+
+        internal static Process/*!*/ OpenPipe(RubyContext/*!*/ context, MutableString/*!*/ command, 
+            bool redirectStandardInput, bool redirectStandardOutput, bool redirectStandardError) {
+
+            ProcessStartInfo startInfo = KernelOps.GetShell(context, command);
+            startInfo.UseShellExecute = false;
+
+            startInfo.RedirectStandardInput = redirectStandardInput;
+            startInfo.RedirectStandardOutput = redirectStandardOutput;
+            startInfo.RedirectStandardError = redirectStandardError;
+
+            Process process;
+            try {
+                process = Process.Start(startInfo);
+            } catch (Exception e) {
+                throw RubyExceptions.CreateENOENT(startInfo.FileName, e);
+            }
+
+            context.ChildProcessExitStatus = new RubyProcess.Status(process);
+
+            return process;
+        }
+
 #endif
         #endregion
 
@@ -269,7 +303,7 @@ namespace IronRuby.Builtins {
                         return null;
                     }
                 } catch (Exception e) {
-                    throw RubyErrno.CreateEINVAL(e.Message, e);
+                    throw RubyExceptions.CreateEINVAL(e.Message, e);
                 }
 
                 result = new RubyArray();
@@ -348,16 +382,6 @@ namespace IronRuby.Builtins {
 
         //sysopen
 
-        #endregion
-
-        #region Public instance methods
-
-        [RubyMethod(&quot;&lt;&lt;&quot;)]
-        public static RubyIO Output(BinaryOpStorage/*!*/ writeStorage, RubyIO/*!*/ self, object value) {
-            Protocols.Write(writeStorage, self, value);
-            return self;
-        }
-
         [RubyMethod(&quot;binmode&quot;)]
         public static RubyIO/*!*/ Binmode(RubyIO/*!*/ self) {
             if (!self.Closed &amp;&amp; self.Position == 0) {
@@ -373,19 +397,24 @@ namespace IronRuby.Builtins {
             if (self.Closed) {
                 throw RubyExceptions.CreateIOError(&quot;closed stream&quot;);
             }
-
             self.Close();
         }
 
         // TODO:
         [RubyMethod(&quot;close_read&quot;)]
         public static void CloseReader(RubyIO/*!*/ self) {
+            if (self.Closed) {
+                throw RubyExceptions.CreateIOError(&quot;closed stream&quot;);
+            }
             self.CloseReader();
         }
 
         // TODO:
         [RubyMethod(&quot;close_write&quot;)]
         public static void CloseWriter(RubyIO/*!*/ self) {
+            if (self.Closed) {
+                throw RubyExceptions.CreateIOError(&quot;closed stream&quot;);
+            }
             self.CloseWriter();
         }
         
@@ -400,21 +429,22 @@ namespace IronRuby.Builtins {
 
         #endregion
 
-        //reopen
         //stat
 
         [RubyMethod(&quot;eof&quot;)]
         [RubyMethod(&quot;eof?&quot;)]
         public static bool Eof(RubyIO/*!*/ self) {
-            self.AssertOpenedForReading();
+            self.RequireReadable();
             return self.IsEndOfStream();
         }
 
+        [RubyMethod(&quot;ioctl&quot;)]
         [RubyMethod(&quot;fcntl&quot;)]
         public static int FileControl(RubyIO/*!*/ self, [DefaultProtocol]int commandId, [Optional]MutableString arg) {
             return self.FileControl(commandId, (arg != null) ? arg.ConvertToBytes() : null);
         }
 
+        [RubyMethod(&quot;ioctl&quot;)]
         [RubyMethod(&quot;fcntl&quot;)]
         public static int FileControl(RubyIO/*!*/ self, [DefaultProtocol]int commandId, int arg) {
             return self.FileControl(commandId, arg);
@@ -428,18 +458,15 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;fileno&quot;)]
         [RubyMethod(&quot;to_i&quot;)]
         public static int FileNo(RubyIO/*!*/ self) {
-            return self.FileDescriptor;
+            return self.GetFileDescriptor();
         }
 
         [RubyMethod(&quot;fsync&quot;)]
         [RubyMethod(&quot;flush&quot;)]
         public static void Flush(RubyIO/*!*/ self) {
-            self.AssertOpenedForWriting();
             self.Flush();
         }
 
-        //ioctl
-
         [RubyMethod(&quot;isatty&quot;)]
         [RubyMethod(&quot;tty?&quot;)]
         public static bool IsAtty(RubyIO/*!*/ self) {
@@ -448,11 +475,13 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;sync&quot;)]
         public static bool Sync(RubyIO/*!*/ self) {
+            self.RequireOpen();
             return self.AutoFlush;
         }
 
         [RubyMethod(&quot;sync=&quot;)]
         public static bool Sync(RubyIO/*!*/ self, bool sync) {
+            self.RequireOpen();
             self.AutoFlush = sync;
             return sync;
         }
@@ -467,13 +496,13 @@ namespace IronRuby.Builtins {
         // TODO: 1.9 only
         [RubyMethod(&quot;external_encoding&quot;)]
         public static RubyEncoding GetExternalEncoding(RubyIO/*!*/ self) {
-            return (self.ExternalEncoding != null) ? RubyEncoding.GetRubyEncoding(self.ExternalEncoding) : null;
+            return self.ExternalEncoding;
         }
 
         // TODO: 1.9 only
         [RubyMethod(&quot;internal_encoding&quot;)]
         public static RubyEncoding GetInternalEncoding(RubyIO/*!*/ self) {
-            return (self.InternalEncoding != null) ? RubyEncoding.GetRubyEncoding(self.InternalEncoding) : null;
+            return self.InternalEncoding;
         }
 
         // TODO: 1.9 only
@@ -481,74 +510,30 @@ namespace IronRuby.Builtins {
 
         #endregion
 
-        #region rewind, seek, pos, tell, lineno
+        #region rewind, seek, sysseek, pos, tell, lineno
 
         [RubyMethod(&quot;rewind&quot;)]
         public static void Rewind(RubyContext/*!*/ context, RubyIO/*!*/ self) {
-            Seek(self, 0, 0);
-            SetLineNo(context, self, 0);
-        }
-
-        private static void Seek(RubyIO/*!*/ self, long pos, int seekOrigin) {
-            if (seekOrigin &lt; 0 || seekOrigin &gt; 2) {
-                throw RubyExceptions.CreateArgumentError(&quot;Invalid argument&quot;);
-            }
-
-            if (self.IsConsoleDescriptor()) {
-                throw new Errno.BadFileDescriptorError();
-            }
-
-            // TODO: make sure we assert stream is not actually closed
-            if (self.Closed) {
-                throw RubyExceptions.CreateArgumentError(&quot;trying to seek on a non-existent stream?&quot;);
-            }
-
-            SeekOrigin origin = SeekOrigin.Current;
-            if (seekOrigin == SEEK_SET) {
-                origin = SeekOrigin.Begin;
-            } else if (seekOrigin == SEEK_END) {
-                origin = SeekOrigin.End;
-            }
-
-            self.Seek(pos, origin);
+            self.Seek(0, SeekOrigin.Begin);
+            self.LineNumber = 0;
         }
 
         [RubyMethod(&quot;seek&quot;)]
-        public static int Seek(RubyIO/*!*/ self, [DefaultProtocol]int pos, [DefaultProtocol, DefaultParameterValue(SEEK_SET)]int seekOrigin) {
-            Seek(self, (long)pos, seekOrigin);
+        public static int Seek(RubyIO/*!*/ self, [DefaultProtocol]IntegerValue pos, [DefaultProtocol, DefaultParameterValue(SEEK_SET)]int seekOrigin) {
+            self.Seek(pos.ToInt64(), RubyIO.ToSeekOrigin(seekOrigin));
             return 0;
         }
 
-        [RubyMethod(&quot;seek&quot;)]
-        public static int Seek(RubyIO/*!*/ self, [NotNull]BigInteger/*!*/ pos, [DefaultProtocol, DefaultParameterValue(SEEK_SET)]int seekOrigin) {
-            long longPos;
-            if (!pos.AsInt64(out longPos)) {
-                throw RubyExceptions.CreateRangeError(&quot;bignum too big to convert into `long'&quot;);
-            }
-            Seek(self, longPos, seekOrigin);
-            return 0;
-        }
-
-        [RubyMethod(&quot;lineno&quot;)]
-        public static int GetLineNo(RubyContext/*!*/ context, RubyIO/*!*/ self) {
-            return context.InputProvider.LastInputLineNumber;
-        }
-
-        [RubyMethod(&quot;lineno=&quot;)]
-        public static void SetLineNo(RubyContext/*!*/ context, RubyIO/*!*/ self, [DefaultProtocol]int value) {
-            context.InputProvider.LastInputLineNumber = value;
+        [RubyMethod(&quot;sysseek&quot;)]
+        public static object SysSeek(RubyIO/*!*/ self, [DefaultProtocol]IntegerValue pos, [DefaultProtocol, DefaultParameterValue(SEEK_SET)]int seekOrigin) {
+            self.Flush();
+            self.Seek(pos.ToInt64(), RubyIO.ToSeekOrigin(seekOrigin));
+            return pos.ToObject();
         }
 
         [RubyMethod(&quot;pos&quot;)]
         [RubyMethod(&quot;tell&quot;)]
-        public static object Pos(RubyIO/*!*/ self) {
-            if (self.IsConsoleDescriptor()) {
-                throw new Errno.BadFileDescriptorError();
-            }
-            if (self.Closed) {
-                throw RubyExceptions.CreateIOError(&quot;closed stream&quot;);
-            }
-
+        public static object/*!*/ Pos(RubyIO/*!*/ self) {
             if (self.Position &lt;= Int32.MaxValue) {
                 return (int)self.Position;
             }
@@ -557,140 +542,29 @@ namespace IronRuby.Builtins {
         }
 
         [RubyMethod(&quot;pos=&quot;)]
-        public static void Pos(RubyIO/*!*/ self, [DefaultProtocol]int value) {
-            if (self.IsConsoleDescriptor()) {
-                throw new Errno.BadFileDescriptorError();
-            }
-
-            self.Seek(value, SeekOrigin.Begin);
+        public static void Pos(RubyIO/*!*/ self, [DefaultProtocol]IntegerValue pos) {
+            self.Seek(pos.ToInt64(), SeekOrigin.Begin);
         }
 
-        #endregion
-
-        #region print, puts, putc
-
-        // print, puts accept an arbitrary self object (it is called from Kernel#print, puts).
-        
-        [RubyMethod(&quot;print&quot;)]
-        public static void Print(BinaryOpStorage/*!*/ writeStorage, RubyScope/*!*/ scope, object self) {
-            Print(writeStorage, self, scope.GetInnerMostClosureScope().LastInputLine);
-        }
-
-        [RubyMethod(&quot;print&quot;)]
-        public static void Print(BinaryOpStorage/*!*/ writeStorage, object self, object value) {
-            Protocols.Write(writeStorage, self, value);
-        }
-
-        [RubyMethod(&quot;print&quot;)]
-        public static void Print(BinaryOpStorage/*!*/ writeStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion, object self, 
-            [NotNull]params object[]/*!*/ args) {
-            MutableString delimiter = writeStorage.Context.OutputSeparator;
-            for (int i = 0; i &lt; args.Length; i++) {
-                MutableString str = ToPrintedString(tosConversion, args[i]);               
-                Print(writeStorage, self, str);
-            }
-			if (delimiter != null)
-			{
-				Print(writeStorage, self, delimiter);
-			}
-        }
-
-        [RubyMethod(&quot;putc&quot;)]
-        public static MutableString/*!*/ Putc(BinaryOpStorage/*!*/ writeStorage, object self, [NotNull]MutableString/*!*/ val) {
-            if (val.IsEmpty) {
-                throw RubyExceptions.CreateTypeError(&quot;can't convert String into Integer&quot;);
-            }
-
-            // writes a single byte into the output stream:
-            var c = MutableString.CreateBinary(val.GetBinarySlice(0, 1));
-            Protocols.Write(writeStorage, self, c);
-            return val;
-        }
-
-        [RubyMethod(&quot;putc&quot;)]
-        public static int Putc(BinaryOpStorage/*!*/ writeStorage, object self, [DefaultProtocol]int c) {
-            MutableString str = MutableString.CreateBinary(1).Append(unchecked((byte)c));
-            Protocols.Write(writeStorage, self, str);
-            return c;
-        }
-
-        private static readonly MutableString NewLine = MutableString.CreateMutable(&quot;\n&quot;).Freeze();
-
-        public static MutableString/*!*/ ToPrintedString(ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion, object obj) {
-            IDictionary&lt;object, object&gt; hash;
-            IList list;
-            MutableString str;
-
-            if ((list = obj as IList) != null) {
-                return IListOps.Join(tosConversion, list, NewLine);
-            } else if ((hash = obj as IDictionary&lt;object, object&gt;) != null) {
-                return IDictionaryOps.ToMutableString(tosConversion, hash);
-            } else if (obj == null) {
-                return MutableString.Create(&quot;nil&quot;);
-            } else if (obj is bool) {
-                return MutableString.Create((bool)obj ? &quot;true&quot; : &quot;false&quot;);
-            } else if (obj is double) {
-                double value = (double)obj;
-                var result = MutableString.Create(value.ToString(System.Globalization.CultureInfo.InvariantCulture));
-                if ((double)(int)value == value) {
-                    result.Append(&quot;.0&quot;);
-                }
-                return result;
-            } else if ((str = obj as MutableString) != null) {
-                return str;
-            } else {
-                return Protocols.ConvertToString(tosConversion, obj);
-            }
-        }
-
-        [RubyMethod(&quot;puts&quot;)]
-        public static void PutsEmptyLine(BinaryOpStorage/*!*/ writeStorage, object self) {
-            Protocols.Write(writeStorage, self, MutableString.CreateMutable(&quot;\n&quot;));
-        }
-
-        [RubyMethod(&quot;puts&quot;)]
-        public static void Puts(BinaryOpStorage/*!*/ writeStorage, object self, [NotNull]MutableString/*!*/ str) {
-            Protocols.Write(writeStorage, self, str);
-
-            if (!str.EndsWith('\n')) {
-                PutsEmptyLine(writeStorage, self);
-            }
-        }
-
-        [RubyMethod(&quot;puts&quot;)]
-        public static void Puts(BinaryOpStorage/*!*/ writeStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion, 
-            object self, [NotNull]object/*!*/ val) {
-
-            Puts(writeStorage, self, ToPrintedString(tosConversion, val));
-        }
-
-        [RubyMethod(&quot;puts&quot;)]
-        public static void Puts(BinaryOpStorage/*!*/ writeStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion, 
-            object self, [NotNull]params object[]/*!*/ vals) {
-
-            for (int i = 0; i &lt; vals.Length; i++) {
-                Puts(writeStorage, tosConversion, self, vals[i]);
-            }
+        [RubyMethod(&quot;lineno&quot;)]
+        public static int GetLineNumber(RubyIO/*!*/ self) {
+            self.RequireOpen();
+            return self.LineNumber;
         }
 
-        [RubyMethod(&quot;printf&quot;)]
-        public static void PrintFormatted(
-            StringFormatterSiteStorage/*!*/ storage, 
-            ConversionStorage&lt;MutableString&gt;/*!*/ stringCast, 
-            BinaryOpStorage/*!*/ writeStorage,
-            RubyIO/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ format, [NotNull]params object[]/*!*/ args) {
-
-            KernelOps.PrintFormatted(storage, stringCast, writeStorage, null, self, format, args);
+        [RubyMethod(&quot;lineno=&quot;)]
+        public static void SetLineNumber(RubyContext/*!*/ context, RubyIO/*!*/ self, [DefaultProtocol]int value) {
+            self.RequireOpen();
+            self.LineNumber = value;
         }
 
         #endregion
 
-        #region write, write_nonblock
+        #region write, syswrite, write_nonblock
 
         [RubyMethod(&quot;write&quot;)]
         public static int Write(RubyIO/*!*/ self, [NotNull]MutableString/*!*/ val) {
-            self.AssertOpenedForWriting();
-            int bytesWritten = self.Write(val);
+            int bytesWritten = val.IsEmpty ? 0 : self.WriteBytes(val, 0, val.GetByteCount());
             if (self.AutoFlush) {
                 self.Flush();
             }
@@ -702,46 +576,67 @@ namespace IronRuby.Builtins {
             return Write(self, Protocols.ConvertToString(tosConversion, obj));
         }
 
-        //write_nonblock
-        
-        #endregion
+        [RubyMethod(&quot;syswrite&quot;)]
+        public static int SysWrite(BinaryOpStorage/*!*/ writeStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion,
+            RubyContext/*!*/ context, RubyIO/*!*/ self, [NotNull]MutableString/*!*/ val) {
+
+            RubyBufferedStream stream = self.GetWritableStream();
+            if (stream.DataBuffered) {
+                PrintOps.ReportWarning(writeStorage, tosConversion, MutableString.CreateAscii(&quot;syswrite for buffered IO&quot;));
+            }
+            int bytes = Write(self, val);
+            self.Flush();
+            return bytes;
+        }
 
-        #region read, read_nonblock
+        [RubyMethod(&quot;syswrite&quot;)]
+        public static int SysWrite(BinaryOpStorage/*!*/ writeStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion,
+            RubyContext/*!*/ context, RubyIO/*!*/ self, object obj) {
+            return SysWrite(writeStorage, tosConversion, context, self, Protocols.ConvertToString(tosConversion, obj));
+        }
 
-        private static RubyIO/*!*/ OpenFileForRead(RubyContext/*!*/ context, MutableString/*!*/ path) {
-            string strPath = path.ConvertToString();
-            if (!File.Exists(strPath)) {
-                throw RubyErrno.CreateENOENT(String.Format(&quot;No such file or directory - {0}&quot;, strPath));
+        [RubyMethod(&quot;write_nonblock&quot;)]
+        public static int WriteNoBlock(RubyIO/*!*/ self, [NotNull]MutableString/*!*/ val) {
+            var stream = self.GetWritableStream();
+            try {
+                stream.WriteTimeout = 0;
+            } catch (InvalidOperationException) {
+                throw RubyExceptions.CreateEBADF();
             }
-            return new RubyIO(context, File.OpenRead(strPath), &quot;r&quot;);
+            return Write(self, val);
         }
-        
-        private static byte[]/*!*/ ReadAllBytes(RubyIO/*!*/ io) {
-            var fixedBuffer = new byte[io.Length];
-            io.ReadBytes(fixedBuffer, 0, (int)io.Length);
-            return fixedBuffer;
+
+        [RubyMethod(&quot;write_nonblock&quot;)]
+        public static int WriteNoBlock(ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion, RubyIO/*!*/ self, object obj) {
+            return Write(self, Protocols.ConvertToString(tosConversion, obj));
         }
+        
+        #endregion
+
+        #region read, sysread, read_nonblock, readpartial
 
         [RubyMethod(&quot;read&quot;)]
         public static MutableString/*!*/ Read(RubyIO/*!*/ self) {
-            self.AssertOpenedForReading();
+            var buffer = MutableString.CreateBinary();
+            self.AppendBytes(buffer, Int32.MaxValue);
+            return buffer;
+        }
 
-            if (!self.PreserveEndOfLines) {
-                MutableString result = MutableString.CreateBinary();
-                int c;
-                while ((c = self.ReadByteNormalizeEoln()) != -1) {
-                    result.Append((byte)c);
-                }
-                return result;
+        [RubyMethod(&quot;read&quot;)]
+        public static MutableString/*!*/ Read(RubyIO/*!*/ self, DynamicNull bytes, [DefaultProtocol, Optional]MutableString buffer) {
+            if (buffer == null) {
+                buffer = MutableString.CreateBinary();
             } else {
-                // TODO: change this once Binary mutable string uses resizable byte[] instead of List&lt;byte&gt;
-                return MutableString.CreateBinary(ReadAllBytes(self));
-            }
+                buffer.Clear();
+            } 
+            
+            self.AppendBytes(buffer, Int32.MaxValue);
+            return buffer;
         }
 
         [RubyMethod(&quot;read&quot;)]
         public static MutableString Read(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
-            self.AssertOpenedForReading();
+            self.RequireReadable();
             if (bytes &lt; 0) {
                 throw RubyExceptions.CreateArgumentError(&quot;negative length -1 given&quot;);
             }
@@ -756,36 +651,73 @@ namespace IronRuby.Builtins {
             return (bytesRead == 0 &amp;&amp; bytes != 0) ? null : buffer;
         }
 
-        [RubyMethod(&quot;read&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static MutableString/*!*/ ReadFile(RubyClass/*!*/ self,
-            [DefaultProtocol, NotNull]MutableString/*!*/ path) {
+        [RubyMethod(&quot;sysread&quot;)]
+        public static MutableString/*!*/ SystemRead(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
+            var stream = self.GetReadableStream();
+            if (stream.DataBuffered) {
+                throw RubyExceptions.CreateIOError(&quot;sysread for buffered IO&quot;);
+            }
+
+            // We use Flush to simulate non-buffered IO. 
+            // A better approach would be to create a parallel FileStream with 
+            // System.IO.FileOptions.WriteThrough (which corresponds to FILE_FLAG_NO_BUFFERING), and also maybe 
+            // System.IO.FileOptions.SequentialScan (FILE_FLAG_SEQUENTIAL_SCAN).
+            // TODO: sysopen does that?
+            stream.Flush();
 
-            using (RubyIO io = OpenFileForRead(self.Context, path)) {
-                return Read(io);
+            var result = Read(self, bytes, buffer);
+            if (result == null) {
+                throw new EOFError(&quot;end of file reached&quot;);
             }
+            return result;
         }
 
+        [RubyMethod(&quot;read_nonblock&quot;)]
+        public static MutableString/*!*/ ReadNoBlock(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
+            var stream = self.GetReadableStream();
+
+            try {
+                stream.ReadTimeout = 0;
+            } catch (InvalidOperationException) {
+                throw RubyExceptions.CreateEBADF();
+            }
+
+            return Read(self, bytes, buffer);
+        }
+
+        // TODO: use Nullable&lt;int&gt; as parameters:
+
         [RubyMethod(&quot;read&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static MutableString/*!*/ Read(RubyClass/*!*/ self,
-            [DefaultProtocol, NotNull]MutableString/*!*/ path, [DefaultProtocol]int length, [DefaultProtocol, Optional]int offset) {
+        public static MutableString/*!*/ Read(ConversionStorage&lt;int&gt;/*!*/ fixnumCast, RubyClass/*!*/ self,
+            [DefaultProtocol, NotNull]MutableString/*!*/ path, [DefaultParameterValue(null)]object lengthObj, 
+            [DefaultParameterValue(0)]object offsetObj) {
+
+            var site = fixnumCast.GetSite(ConvertToFixnumAction.Make(fixnumCast.Context));
+            int length = (lengthObj != null) ? site.Target(site, lengthObj) : 0;
+            int offset = (offsetObj != null) ? site.Target(site, offsetObj) : 0;
 
             if (offset &lt; 0) {
-                throw RubyErrno.CreateEINVAL();
+                throw RubyExceptions.CreateEINVAL();
             }
 
             if (length &lt; 0) {
                 throw RubyExceptions.CreateArgumentError(String.Format(&quot;negative length {0} given&quot;, length));
             }
 
-            using (RubyIO io = OpenFileForRead(self.Context, path)) {
+            using (RubyIO io = new RubyFile(self.Context, path.ConvertToString(), IOMode.ReadOnly)) {
                 if (offset &gt; 0) {
                     io.Seek(offset, SeekOrigin.Begin);
                 }
-                return Read(io, length, null);
+
+                if (lengthObj == null) {
+                    return Read(io);
+                } else {
+                    return Read(io, length, null);
+                }
             }
         }
 
-        //read_nonblock
+        //readpartial
 
         #endregion
 
@@ -794,7 +726,7 @@ namespace IronRuby.Builtins {
         // returns a string in 1.9
         [RubyMethod(&quot;readchar&quot;)]
         public static int ReadChar(RubyIO/*!*/ self) {
-            self.AssertOpenedForReading();
+            self.RequireReadable();
             int c = self.ReadByteNormalizeEoln();
             
             if (c == -1) {
@@ -837,7 +769,8 @@ namespace IronRuby.Builtins {
                 result.Add(line);
             }
 
-            context.InputProvider.LastInputLineNumber += result.Count;
+            self.LineNumber += result.Count;
+            context.InputProvider.LastInputLineNumber = self.LineNumber;
             return result;
         }
 
@@ -852,20 +785,17 @@ namespace IronRuby.Builtins {
         public static RubyArray/*!*/ ReadLines(RubyClass/*!*/ self,
             [DefaultProtocol, NotNull]MutableString path, [DefaultProtocol]MutableString separator) {
 
-            using (RubyIO io = new RubyIO(self.Context, File.OpenRead(path.ConvertToString()), &quot;r&quot;)) {
+            using (RubyIO io = new RubyIO(self.Context, File.OpenRead(path.ConvertToString()), IOMode.ReadOnly)) {
                 return ReadLines(self.Context, io, separator);
             }
         }
 
-
-
         #endregion
 
         #region getc, gets, ungetc, getbyte (1.9)
 
         [RubyMethod(&quot;getc&quot;)]
         public static object Getc(RubyIO/*!*/ self) {
-            self.AssertOpenedForReading();
             int c = self.ReadByteNormalizeEoln();
             return (c != -1) ? ScriptingRuntimeHelpers.Int32ToObject(c) : null;
         }
@@ -882,30 +812,45 @@ namespace IronRuby.Builtins {
             KernelOps.Taint(scope.RubyContext, result);
 
             scope.GetInnerMostClosureScope().LastInputLine = result;
-            scope.RubyContext.InputProvider.IncrementLastInputLineNumber();
+            scope.RubyContext.InputProvider.LastInputLineNumber = ++self.LineNumber;
 
             return result;
         }
 
+        [RubyMethod(&quot;ungetc&quot;)]
+        public static void SetPreviousByte(RubyIO/*!*/ self, [DefaultProtocol]int b) {
+            self.PushBack(unchecked((byte)b));
+        }
+
         // TODO: 1.9 only
         // getbyte
 
-        //ungetc
-
         #endregion
 
-        #region each, each_byte, each_line
+        #region foreach, each, each_byte, each_line
+
+        [RubyMethod(&quot;foreach&quot;, RubyMethodAttributes.PublicSingleton)]
+        public static void ForEach(BlockParam block, RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path) {
+            ForEach(block, self, path, self.Context.InputSeparator);
+        }
+
+        [RubyMethod(&quot;foreach&quot;, RubyMethodAttributes.PublicSingleton)]
+        public static void ForEach(BlockParam block, RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path, [DefaultProtocol]MutableString separator) {
+            using (RubyIO io = new RubyIO(self.Context, File.OpenRead(path.ConvertToString()), IOMode.ReadOnly)) {
+                Each(self.Context, block, io, separator);
+            }
+        }
 
         [RubyMethod(&quot;each&quot;)]
         [RubyMethod(&quot;each_line&quot;)]
-        public static void Each(RubyContext/*!*/ context, BlockParam block, RubyIO/*!*/ self) {
-            Each(block, self, context.InputSeparator);
+        public static object Each(RubyContext/*!*/ context, BlockParam block, RubyIO/*!*/ self) {
+            return Each(context, block, self, context.InputSeparator);
         }
 
         [RubyMethod(&quot;each&quot;)]
         [RubyMethod(&quot;each_line&quot;)]
-        public static object Each(BlockParam block, RubyIO/*!*/ self, [DefaultProtocol]MutableString separator) {
-            self.AssertOpenedForReading();
+        public static object Each(RubyContext/*!*/ context, BlockParam block, RubyIO/*!*/ self, [DefaultProtocol]MutableString separator) {
+            self.RequireReadable();
 
             MutableString line;
             while ((line = self.ReadLineOrParagraph(separator)) != null) {
@@ -915,6 +860,8 @@ namespace IronRuby.Builtins {
 
                 KernelOps.Taint(block.RubyContext, line);
 
+                context.InputProvider.LastInputLineNumber = ++self.LineNumber;
+
                 object result;
                 if (block.Yield(line, out result)) {
                     return result;
@@ -926,7 +873,7 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;each_byte&quot;)]
         public static object EachByte(BlockParam block, RubyIO/*!*/ self) {
-            self.AssertOpenedForReading();
+            self.RequireReadable();
             object aByte;
             while ((aByte = Getc(self)) != null) {
                 if (block == null) {
@@ -947,26 +894,6 @@ namespace IronRuby.Builtins {
         // bytes -&gt; Enumerable::Enumerator
         // lines -&gt; Enumerable::Enumerator
 
-        //readpartial
-
-        [RubyMethod(&quot;sysread&quot;)]
-        public static MutableString/*!*/ SystemRead(RubyIO/*!*/ self, [DefaultProtocol]int bytes) {
-            var fixedBuffer = new byte[bytes];
-            int len = self.ReadBytes(fixedBuffer, 0, bytes);
-            if (len == 0) {
-                throw new EOFError(&quot;end of file reached&quot;);
-            }
-
-            MutableString result = MutableString.CreateBinary();
-            result.Append(fixedBuffer, 0, len);
-            return result;
-        }
-
-        //sysseek
-        //syswrite
-
-        #endregion
-
         public static IOWrapper/*!*/ CreateIOWrapper(RespondToStorage/*!*/ respondToStorage, object io, FileAccess access) {
             bool canRead, canWrite, canSeek, canFlush, canBeClosed;
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/IoOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -151,12 +151,12 @@ namespace IronRuby.Builtins {
         }
 
         private static MutableString/*!*/ JoinArguments(MutableString/*!*/[]/*!*/ args) {
-            MutableString result = MutableString.CreateMutable();
+            MutableString result = MutableString.CreateMutable(RubyEncoding.Binary);
 
             for (int i = 0; i &lt; args.Length; i++) {
                 result.Append(args[i]);
                 if (args.Length &gt; 1 &amp;&amp; i &lt; args.Length - 1) {
-                    result.Append(&quot; &quot;);
+                    result.Append(' ');
                 }
             }
 
@@ -171,7 +171,7 @@ namespace IronRuby.Builtins {
                 p.WaitForExit();
                 return p;
             } catch (Exception e) {
-                throw RubyErrno.CreateENOENT(psi.FileName, e);
+                throw RubyExceptions.CreateENOENT(psi.FileName, e);
             }
         }
 
@@ -183,7 +183,7 @@ namespace IronRuby.Builtins {
             try {
                 return Process.Start(psi);
             } catch (Exception e) {
-                throw RubyErrno.CreateENOENT(psi.FileName, e);
+                throw RubyExceptions.CreateENOENT(psi.FileName, e);
             }
         }
 
@@ -203,7 +203,11 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;`&quot;, RubyMethodAttributes.PublicSingleton, BuildConfig = &quot;!SILVERLIGHT&quot;)]
         public static MutableString/*!*/ ExecuteCommand(RubyContext/*!*/ context, object self, [DefaultProtocol, NotNull]MutableString/*!*/ command) {
             Process p = ExecuteProcessCapturingStandardOutput(GetShell(context, command));
-            MutableString result = MutableString.Create(p.StandardOutput.ReadToEnd());
+            string output = p.StandardOutput.ReadToEnd();
+            if (Environment.NewLine != &quot;\n&quot;) {
+                output = output.Replace(Environment.NewLine, &quot;\n&quot;);
+            }
+            MutableString result = MutableString.Create(output, RubyEncoding.GetRubyEncoding(p.StandardOutput.CurrentEncoding));
             context.ChildProcessExitStatus = new RubyProcess.Status(p);
             return result;
         }
@@ -379,7 +383,8 @@ namespace IronRuby.Builtins {
                 foreach (KeyValuePair&lt;string, GlobalVariable&gt; global in context.GlobalVariables) {
                     if (global.Value.IsEnumerated) {
                         // TODO: Ruby 1.9 returns symbols:
-                        result.Add(MutableString.Create(global.Key));
+                        // TODO (encoding):
+                        result.Add(MutableString.Create(global.Key, RubyEncoding.UTF8));
                     }
                 }
             }
@@ -436,7 +441,8 @@ namespace IronRuby.Builtins {
 
             RubyArray result = new RubyArray(names.Count);
             for (int i = 0; i &lt; names.Count; i++) {
-                result.Add(MutableString.Create(names[i]));
+                // TODO (encoding):
+                result.Add(MutableString.Create(names[i], RubyEncoding.UTF8));
             }
             return result;
         }
@@ -500,7 +506,7 @@ namespace IronRuby.Builtins {
                 throw new NotImplementedError();
             }
 
-            RubyIO file = new RubyFile(context, fileName, (mode != null) ? mode.ToString() : &quot;r&quot;);
+            RubyIO file = new RubyFile(context, fileName, IOModeEnum.Parse(mode));
 
             SetPermission(context, fileName, permission);
 
@@ -535,7 +541,7 @@ namespace IronRuby.Builtins {
                 throw new NotImplementedError();
             }
 
-            RubyIO file = new RubyFile(context, fileName, (RubyFileMode)mode);
+            RubyIO file = new RubyFile(context, fileName, (IOMode)mode);
 
             SetPermission(context, fileName, permission);
 
@@ -566,36 +572,38 @@ namespace IronRuby.Builtins {
             object self, [NotNull]params object[]/*!*/ args) {
 
             var inspect = inspectStorage.GetCallSite(&quot;inspect&quot;);
-            var inspectedArgs = new object[args.Length];
+            var inspectedArgs = new MutableString[args.Length];
             for (int i = 0; i &lt; args.Length; i++) {
-                inspectedArgs[i] = inspect.Target(inspect, args[i]);
+                inspectedArgs[i] = Protocols.ConvertToString(tosConversion, inspect.Target(inspect, args[i]));
             }
             
             // no dynamic dispatch to &quot;puts&quot;:
-            RubyIOOps.Puts(writeStorage, tosConversion, writeStorage.Context.StandardOutput, inspectedArgs);
+            foreach (var arg in inspectedArgs) {
+                PrintOps.Puts(writeStorage, writeStorage.Context.StandardOutput, arg);
+            }
         }
 
         [RubyMethod(&quot;print&quot;, RubyMethodAttributes.PrivateInstance)]
         [RubyMethod(&quot;print&quot;, RubyMethodAttributes.PublicSingleton)]
         public static void Print(BinaryOpStorage/*!*/ writeStorage, RubyScope/*!*/ scope, object self) {
             // no dynamic dispatch to &quot;print&quot;:
-            RubyIOOps.Print(writeStorage, scope, scope.RubyContext.StandardOutput);
+            PrintOps.Print(writeStorage, scope, scope.RubyContext.StandardOutput);
         }
 
         [RubyMethod(&quot;print&quot;, RubyMethodAttributes.PrivateInstance)]
         [RubyMethod(&quot;print&quot;, RubyMethodAttributes.PublicSingleton)]
         public static void Print(BinaryOpStorage/*!*/ writeStorage, object self, object val) {
             // no dynamic dispatch to &quot;print&quot;:
-            RubyIOOps.Print(writeStorage, writeStorage.Context.StandardOutput, val);
+            PrintOps.Print(writeStorage, writeStorage.Context.StandardOutput, val);
         }
 
         [RubyMethod(&quot;print&quot;, RubyMethodAttributes.PrivateInstance)]
         [RubyMethod(&quot;print&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static void Print(BinaryOpStorage/*!*/ writeStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion, 
+        public static void Print(BinaryOpStorage/*!*/ writeStorage,  
             object self, [NotNull]params object[]/*!*/ args) {
 
             // no dynamic dispatch to &quot;print&quot;:
-            RubyIOOps.Print(writeStorage, tosConversion, tosConversion.Context.StandardOutput, args);
+            PrintOps.Print(writeStorage, writeStorage.Context.StandardOutput, args);
         }
 
         // this overload is called only if the first parameter is string:
@@ -631,46 +639,46 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;putc&quot;, RubyMethodAttributes.PublicSingleton)]
         public static MutableString/*!*/ Putc(BinaryOpStorage/*!*/ writeStorage, object self, [NotNull]MutableString/*!*/ arg) {
             // no dynamic dispatch:
-            return RubyIOOps.Putc(writeStorage, writeStorage.Context.StandardOutput, arg);
+            return PrintOps.Putc(writeStorage, writeStorage.Context.StandardOutput, arg);
         }
 
         [RubyMethod(&quot;putc&quot;, RubyMethodAttributes.PrivateInstance)]
         [RubyMethod(&quot;putc&quot;, RubyMethodAttributes.PublicSingleton)]
         public static int Putc(BinaryOpStorage/*!*/ writeStorage, object self, [DefaultProtocol]int arg) {
             // no dynamic dispatch:
-            return RubyIOOps.Putc(writeStorage, writeStorage.Context.StandardOutput, arg);
+            return PrintOps.Putc(writeStorage, writeStorage.Context.StandardOutput, arg);
         }
 
         [RubyMethod(&quot;puts&quot;, RubyMethodAttributes.PrivateInstance)]
         [RubyMethod(&quot;puts&quot;, RubyMethodAttributes.PublicSingleton)]
         public static void PutsEmptyLine(BinaryOpStorage/*!*/ writeStorage, object self) {
             // call directly, no dynamic dispatch to &quot;self&quot;:
-            RubyIOOps.PutsEmptyLine(writeStorage, writeStorage.Context.StandardOutput);
+            PrintOps.PutsEmptyLine(writeStorage, writeStorage.Context.StandardOutput);
         }
 
         [RubyMethod(&quot;puts&quot;, RubyMethodAttributes.PrivateInstance)]
         [RubyMethod(&quot;puts&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static void PutString(BinaryOpStorage/*!*/ writeStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion, 
-            object self, object arg) {
+        public static void PutString(BinaryOpStorage/*!*/ writeStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion,
+            ConversionStorage&lt;IList&gt;/*!*/ tryToAry, object self, object arg) {
 
             // call directly, no dynamic dispatch to &quot;self&quot;:
-            RubyIOOps.Puts(writeStorage, tosConversion, writeStorage.Context.StandardOutput, arg);
+            PrintOps.Puts(writeStorage, tosConversion, tryToAry, writeStorage.Context.StandardOutput, arg);
         }
 
         [RubyMethod(&quot;puts&quot;, RubyMethodAttributes.PrivateInstance)]
         [RubyMethod(&quot;puts&quot;, RubyMethodAttributes.PublicSingleton)]
         public static void PutString(BinaryOpStorage/*!*/ writeStorage, object self, [NotNull]MutableString/*!*/ arg) {
             // call directly, no dynamic dispatch to &quot;self&quot;:
-            RubyIOOps.Puts(writeStorage, writeStorage.Context.StandardOutput, arg);
+            PrintOps.Puts(writeStorage, writeStorage.Context.StandardOutput, arg);
         }
 
         [RubyMethod(&quot;puts&quot;, RubyMethodAttributes.PrivateInstance)]
         [RubyMethod(&quot;puts&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static void PutString(BinaryOpStorage/*!*/ writeStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion, 
-            object self, [NotNull]params object[]/*!*/ args) {
+        public static void PutString(BinaryOpStorage/*!*/ writeStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion,
+            ConversionStorage&lt;IList&gt;/*!*/ tryToAry, object self, [NotNull]params object[]/*!*/ args) {
 
             // call directly, no dynamic dispatch to &quot;self&quot;:
-            RubyIOOps.Puts(writeStorage, tosConversion, writeStorage.Context.StandardOutput, args);
+            PrintOps.Puts(writeStorage, tosConversion, tryToAry, writeStorage.Context.StandardOutput, args);
         }
 
         [RubyMethod(&quot;warn&quot;, RubyMethodAttributes.PrivateInstance)]
@@ -678,13 +686,7 @@ namespace IronRuby.Builtins {
         public static void ReportWarning(BinaryOpStorage/*!*/ writeStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion, 
             object self, object message) {
 
-            if (writeStorage.Context.Verbose != null) {
-                var output = writeStorage.Context.StandardErrorOutput;
-                // MRI: unlike Kernel#puts this outputs \n even if the message ends with \n:
-                var site = writeStorage.GetCallSite(&quot;write&quot;, 1);
-                site.Target(site, output, RubyIOOps.ToPrintedString(tosConversion, message));
-                RubyIOOps.PutsEmptyLine(writeStorage, output);
-            }
+            PrintOps.ReportWarning(writeStorage, tosConversion, message);
         }
 
         // TODO: not supported in Ruby 1.9
@@ -911,14 +913,14 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;sleep&quot;, RubyMethodAttributes.PrivateInstance)]
         [RubyMethod(&quot;sleep&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static double Sleep(object self, double seconds) {
+        public static int Sleep(object self, double seconds) {
             if (seconds &lt; 0) {
                 throw RubyExceptions.CreateArgumentError(&quot;time interval must be positive&quot;);
             }
 
             double ms = seconds * 1000;
             Thread.Sleep(ms &gt; Int32.MaxValue ? Timeout.Infinite : (int)ms);
-            return seconds;
+            return (int)seconds;
         }
         
         //split
@@ -930,7 +932,7 @@ namespace IronRuby.Builtins {
         public static MutableString/*!*/ Sprintf(StringFormatterSiteStorage/*!*/ storage, 
             object self, [DefaultProtocol, NotNull]MutableString/*!*/ format, [NotNull]params object[] args) {
 
-            return new StringFormatter(storage, format.ConvertToString(), args).Format();
+            return new StringFormatter(storage, format.ConvertToString(), format.Encoding, args).Format();
         }
 
         //sub
@@ -1137,7 +1139,7 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;to_s&quot;)]
         public static MutableString/*!*/ ToS(object self) {
-            return self == null ? MutableString.CreateEmpty() : MutableString.Create(self.ToString());
+            return self == null ? MutableString.CreateEmpty() : MutableString.Create(self.ToString(), RubyEncoding.UTF8);
         }
 
         /// &lt;summary&gt;
@@ -1146,24 +1148,19 @@ namespace IronRuby.Builtins {
         /// &lt;/summary&gt;
         [RubyMethod(&quot;inspect&quot;)]
         public static MutableString/*!*/ Inspect(UnaryOpStorage/*!*/ inspectStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion,
-            object self)
-        {
+            object self) {
 
             var context = tosConversion.Context;
-            if (context.HasInstanceVariables(self))
-            {
+            if (context.HasInstanceVariables(self)) {
                 return RubyUtils.InspectObject(inspectStorage, tosConversion, self);
-            }
-            else
-            {
+            } else {
                 var site = tosConversion.GetSite(ConvertToSAction.Make(context));
                 return site.Target(site, self);
             }
         }
 
         [RubyMethod(&quot;to_a&quot;)]
-        public static RubyArray/*!*/ ToA(RubyContext/*!*/ context, object self)
-        {
+        public static RubyArray/*!*/ ToA(RubyContext/*!*/ context, object self) {
             RubyArray result = new RubyArray();
             result.Add(self);
             return context.TaintObjectBy(result, self);
@@ -1363,7 +1360,8 @@ namespace IronRuby.Builtins {
 
             RubyArray result = new RubyArray(names.Length);
             foreach (string name in names) {
-                result.Add(MutableString.Create(name));
+                // TODO (encoding):
+                result.Add(MutableString.Create(name, RubyEncoding.UTF8));
             }
             return result;
         }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -70,9 +70,9 @@ namespace IronRuby.Builtins {
             
         #region Constants
 
-        private static readonly MutableString _positiveInfinityString = MutableString.Create(&quot;inf&quot;).Freeze();
-        private static readonly MutableString _negativeInfinityString = MutableString.Create(&quot;-inf&quot;).Freeze();
-        private static readonly MutableString _nanString = MutableString.Create(&quot;nan&quot;).Freeze();
+        private static readonly MutableString _positiveInfinityString = MutableString.CreateAscii(&quot;inf&quot;).Freeze();
+        private static readonly MutableString _negativeInfinityString = MutableString.CreateAscii(&quot;-inf&quot;).Freeze();
+        private static readonly MutableString _nanString = MutableString.CreateAscii(&quot;nan&quot;).Freeze();
 
         #endregion
 
@@ -190,7 +190,7 @@ namespace IronRuby.Builtins {
                 } else if (Double.IsNaN(value)) {
                     WriteStringValue(_nanString);
                 } else {
-                    StringFormatter sf = new StringFormatter(_context, &quot;%.15g&quot;, new object[] { value });
+                    StringFormatter sf = new StringFormatter(_context, &quot;%.15g&quot;, RubyEncoding.Binary, new object[] { value });
                     sf.TrailingZeroAfterWholeFloat = false;
                     WriteStringValue(sf.Format());
                 }
@@ -203,7 +203,7 @@ namespace IronRuby.Builtins {
 
                     if (libClass != theClass &amp;&amp; !(obj is RubyStruct)) {
                         marshaller._writer.Write((byte)'C');
-                        marshaller.WriteSymbol(theClass.Name);
+                        marshaller.WriteModuleName(theClass);
                     }
                 }
             }
@@ -215,8 +215,12 @@ namespace IronRuby.Builtins {
                 _writer.Write(data);
             }
 
-            private void WriteStringValue(string/*!*/ value) {
-                byte[] data = MutableString.Create(value).ConvertToBytes();
+            private void WriteModuleName(RubyModule/*!*/ module) {
+                WriteSymbol(module.Name, RubyEncoding.ClassName);
+            }
+
+            private void WriteStringValue(string/*!*/ value, RubyEncoding/*!*/ encoding) {
+                byte[] data = encoding.StrictEncoding.GetBytes(value);
                 WriteInt32(data.Length);
                 _writer.Write(data);
             }
@@ -261,7 +265,7 @@ namespace IronRuby.Builtins {
                 }
             }
 
-            private void WriteSymbol(string/*!*/ value) {
+            private void WriteSymbol(string/*!*/ value, RubyEncoding/*!*/ encoding) {
                 int position;
                 if (_symbols.TryGetValue(value, out position)) {
                     _writer.Write((byte)';');
@@ -270,7 +274,7 @@ namespace IronRuby.Builtins {
                     position = _symbols.Count;
                     _symbols[value] = position;
                     _writer.Write((byte)':');
-                    WriteStringValue(value);
+                    WriteStringValue(value, encoding);
                 }
             }
 
@@ -288,11 +292,11 @@ namespace IronRuby.Builtins {
                 WriteInt32(3);
                 // Write the attributes that are implemented in C#. Any user-defined attributes (for subtypes of Range)
                 // will be handled by the default handling of IRubyObject
-                WriteSymbol(&quot;begin&quot;);
+                WriteSymbol(&quot;begin&quot;, RubyEncoding.Binary);
                 WriteAnObject(range.Begin);
-                WriteSymbol(&quot;end&quot;);
+                WriteSymbol(&quot;end&quot;, RubyEncoding.Binary);
                 WriteAnObject(range.End);
-                WriteSymbol(&quot;excl&quot;);
+                WriteSymbol(&quot;excl&quot;, RubyEncoding.Binary);
                 WriteAnObject(range.ExcludeEnd);
             }
 
@@ -300,14 +304,14 @@ namespace IronRuby.Builtins {
                 _writer.Write((byte)'o');
                 RubyClass theClass = _context.GetClassOf(obj);
                 TestForAnonymous(theClass);
-                WriteSymbol(theClass.Name);
+                WriteModuleName(theClass);
             }
 
             private void WriteUsingDump(object/*!*/ obj) {
                 _writer.Write((byte)'u');
                 RubyClass theClass = _context.GetClassOf(obj);
                 TestForAnonymous(theClass);
-                WriteSymbol(theClass.Name);
+                WriteModuleName(theClass);
                 MutableString dumpResult = _sites.Dump.Target(_sites.Dump, obj, _recursionLimit) as MutableString;
                 if (dumpResult == null) {
                     throw RubyExceptions.CreateTypeError(&quot;_dump() must return string&quot;);
@@ -319,20 +323,20 @@ namespace IronRuby.Builtins {
                 _writer.Write((byte)'U');
                 RubyClass theClass = _context.GetClassOf(obj);
                 TestForAnonymous(theClass);
-                WriteSymbol(theClass.Name);
+                WriteModuleName(theClass);
                 WriteAnObject(_sites.MarshalDump.Target(_sites.MarshalDump, obj));
             }
 
             private void WriteClass(RubyClass/*!*/ obj) {
                 _writer.Write((byte)'c');
                 TestForAnonymous(obj);
-                WriteStringValue(obj.Name);
+                WriteStringValue(obj.Name, RubyEncoding.ClassName);
             }
 
             private void WriteModule(RubyModule/*!*/ obj) {
                 _writer.Write((byte)'m');
                 TestForAnonymous(obj);
-                WriteStringValue(obj.Name);
+                WriteStringValue(obj.Name, RubyEncoding.ClassName);
             }
 
             private void WriteStruct(RubyStruct/*!*/ obj) {
@@ -340,12 +344,13 @@ namespace IronRuby.Builtins {
                 _writer.Write((byte)'S');
                 RubyClass theClass = _context.GetClassOf(obj);
                 TestForAnonymous(theClass);
-                WriteSymbol(theClass.Name);
+                WriteModuleName(theClass);
                 var names = obj.GetNames();
                 WriteInt32(names.Count);
                 foreach (string name in names) {
                     int index = obj.GetIndex(name);
-                    WriteSymbol(name);
+                    // TODO (encoding):
+                    WriteSymbol(name, RubyEncoding.UTF8);
                     WriteAnObject(obj[index]);
                 }
             }
@@ -373,7 +378,8 @@ namespace IronRuby.Builtins {
                 } else if (obj is int) {
                     WriteFixnum((int)obj);
                 } else if (obj is SymbolId) {
-                    WriteSymbol(SymbolTable.IdToString((SymbolId)obj));
+                    // TODO (encoding):
+                    WriteSymbol(SymbolTable.IdToString((SymbolId)obj), RubyEncoding.UTF8);
                 } else {
                     int objectRef;
                     if (_objects.TryGetValue(obj, out objectRef)) {
@@ -406,7 +412,7 @@ namespace IronRuby.Builtins {
                             if (theClass.IsSingletonClass) {
                                 foreach (var mixin in theClass.GetMixins()) {
                                     _writer.Write((byte)'e');
-                                    WriteSymbol(mixin.Name);
+                                    WriteModuleName(mixin);
                                 }
                             }
                         }
@@ -454,7 +460,8 @@ namespace IronRuby.Builtins {
                                 if (!_context.TryGetInstanceVariable(obj, name, out value)) {
                                     value = null;
                                 }
-                                WriteSymbol(name);
+                                // TODO (encoding):
+                                WriteSymbol(name, RubyEncoding.UTF8);
                                 WriteAnObject(value);
                             }
                         }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Marshal.cs</filename>
    </modified>
    <modified>
      <diff>@@ -171,7 +171,7 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;to_s&quot;)]
         public static MutableString/*!*/ ToS(RubyContext/*!*/ context, MatchData/*!*/ self) {
-            return MutableString.Create(self.Value).TaintBy(self, context);
+            return MutableString.Create(self.Value, self.Encoding).TaintBy(self, context);
         }
 
         #endregion</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MatchDataOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -725,7 +725,8 @@ namespace IronRuby.Builtins {
             using (self.Context.ClassHierarchyLocker()) {
                 self.ForEachClassVariable(true, delegate(RubyModule/*!*/ module, string name, object value) {
                     if (name != null &amp;&amp; !visited.ContainsKey(name)) {
-                        result.Add(MutableString.Create(name));
+                        // TODO (encoding):
+                        result.Add(MutableString.Create(name, RubyEncoding.UTF8));
                         visited.Add(name, true);
                     }
                     return false;
@@ -787,7 +788,8 @@ namespace IronRuby.Builtins {
 
                     if (!visited.ContainsKey(name)) {
                         visited.Add(name, true);
-                        result.Add(MutableString.Create(name));
+                        // TODO (encoding):
+                        result.Add(MutableString.Create(name, RubyEncoding.UTF8));
                     }
                     return false;
                 });
@@ -879,7 +881,8 @@ namespace IronRuby.Builtins {
             if (symbolicNames) {
                 return SymbolTable.StringToId(name);
             } else {
-                return MutableString.Create(name);
+                // TODO (encoding):
+                return MutableString.Create(name, RubyEncoding.UTF8);
             }
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ModuleOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -39,7 +39,7 @@ namespace IronRuby.Builtins {
 
         [RubyConstructor]
         public static MutableString/*!*/ Create(RubyClass/*!*/ self) {
-            return MutableString.CreateMutable();
+            return MutableString.CreateEmpty();
         }
         
         [RubyConstructor]
@@ -331,7 +331,7 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;%&quot;)]
         public static MutableString/*!*/ Format(StringFormatterSiteStorage/*!*/ storage, MutableString/*!*/ self, object arg) {
             IList args = arg as IList ?? new object[] { arg };
-            StringFormatter formatter = new StringFormatter(storage, self.ConvertToString(), args);
+            StringFormatter formatter = new StringFormatter(storage, self.ConvertToString(), self.Encoding, args);
             return formatter.Format().TaintBy(self);
         }
 
@@ -657,7 +657,7 @@ namespace IronRuby.Builtins {
 
             if (value.IsEmpty) {
                 self.Remove(index, 1).TaintBy(value);
-                return MutableString.CreateMutable();
+                return MutableString.CreateEmpty();
             }
 
             self.Replace(index, 1, value).TaintBy(value);
@@ -898,7 +898,7 @@ namespace IronRuby.Builtins {
 
         #region center
 
-        private static readonly MutableString _DefaultPadding = MutableString.Create(&quot; &quot;).Freeze();
+        private static readonly MutableString _DefaultPadding = MutableString.CreateAscii(&quot; &quot;).Freeze();
 
         [RubyMethod(&quot;center&quot;)]
         public static MutableString/*!*/ Center(MutableString/*!*/ self, 
@@ -1121,25 +1121,28 @@ namespace IronRuby.Builtins {
             return EachLine(block, self, context.InputSeparator);
         }
 
-        private static readonly MutableString _DefaultLineSeparator = MutableString.Create(&quot;\n&quot;).Freeze();
-        private static readonly MutableString _DefaultDoubleLineSeparator = MutableString.Create(&quot;\n\n&quot;).Freeze();
+        internal static readonly MutableString DefaultLineSeparator = MutableString.CreateAscii(&quot;\n&quot;).Freeze();
+        internal static readonly MutableString DefaultParagraphSeparator = MutableString.CreateAscii(&quot;\n\n&quot;).Freeze();
 
         [RubyMethod(&quot;each&quot;)]
         [RubyMethod(&quot;each_line&quot;)]
         public static object EachLine(BlockParam block, MutableString/*!*/ self, [DefaultProtocol]MutableString separator) {
+            return EachLine(block, self, separator, 0);
+        }
+
+        public static object EachLine(BlockParam block, MutableString/*!*/ self, [DefaultProtocol]MutableString separator, int start) {
             self.TrackChanges();
 
             MutableString paragraphSeparator;
             if (separator == null || separator.IsEmpty) {
-                separator = _DefaultLineSeparator;
-                paragraphSeparator = _DefaultDoubleLineSeparator;
+                separator = DefaultLineSeparator;
+                paragraphSeparator = DefaultParagraphSeparator;
             } else {
                 paragraphSeparator = null;
             }
 
             // TODO: this is slow, refactor when we redo MutableString
             MutableString str = self;
-            int start = 0;
 
             // In &quot;normal&quot; mode just split the string at the end of each seperator occurrance.
             // In &quot;paragraph&quot; mode, split the string at the end of each occurrance of two or more
@@ -1233,7 +1236,7 @@ namespace IronRuby.Builtins {
             result = input.Clone();
             matchScope.CurrentMatch = match;
 
-            if (block.Yield(MutableString.Create(match.Value), out blockResult)) {
+            if (block.Yield(MutableString.Create(match.Value, input.Encoding), out blockResult)) {
                 return true;
             }
 
@@ -1275,7 +1278,7 @@ namespace IronRuby.Builtins {
                 matchScope.CurrentMatch = currentMatch;
 
                 input.TrackChanges();
-                if (block.Yield(MutableString.Create(match.Value), out blockResult)) {
+                if (block.Yield(MutableString.Create(match.Value, input.Encoding), out blockResult)) {
                     return true;
                 }
                 if (input.HasChanged) {
@@ -1815,7 +1818,7 @@ namespace IronRuby.Builtins {
         #endregion
 
 
-        #region match
+        #region =~, match
 
         [RubyMethod(&quot;=~&quot;)]
         public static object Match(RubyScope/*!*/ scope, MutableString/*!*/ self, [NotNull]RubyRegex/*!*/ regex) {
@@ -1901,12 +1904,12 @@ namespace IronRuby.Builtins {
 
         private static object MatchToScanResult(RubyScope/*!*/ scope, MutableString/*!*/ self, RubyRegex/*!*/ regex, Match/*!*/ match) {
             if (match.Groups.Count == 1) {
-                return MutableString.Create(match.Value).TaintBy(self).TaintBy(regex, scope);
+                return MutableString.Create(match.Value, self.Encoding).TaintBy(self).TaintBy(regex, scope);
             } else {
                 var result = new RubyArray(match.Groups.Count - 1);
                 for (int i = 1; i &lt; match.Groups.Count; i++) {
                     if (match.Groups[i].Success) {
-                        result.Add(MutableString.Create(match.Groups[i].Value).TaintBy(self).TaintBy(regex, scope));
+                        result.Add(MutableString.Create(match.Groups[i].Value, self.Encoding).TaintBy(self).TaintBy(regex, scope));
                     } else {
                         result.Add(null);
                     }
@@ -2673,8 +2676,7 @@ namespace IronRuby.Builtins {
                                     }
                                     str.Append(((buffer[i] &amp; (1 &lt;&lt; b)) != 0 ? '1' : '0'));
                                 }
-                            }
-                            else {
+                            } else {
                                 str = MutableString.CreateEmpty();
                             }
                             result.Add(str);</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MutableStringOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -81,13 +81,13 @@ namespace IronRuby.Builtins {
 
         [RubyMethodAttribute(&quot;inspect&quot;)]
         public static MutableString Inspect(object self) {
-            return MutableString.Create(&quot;nil&quot;);
+            return MutableString.CreateAscii(&quot;nil&quot;);
         }
 
         [RubyMethodAttribute(&quot;to_s&quot;)]
         public static MutableString/*!*/ ToString(object self) {
             Debug.Assert(self == null);
-            return MutableString.Create(String.Empty);
+            return MutableString.CreateEmpty();
         }
 
         [SpecialName]</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/NilClassOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -57,18 +57,18 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;name&quot;)]
         [RubyMethod(&quot;to_s&quot;)]
         public static MutableString/*!*/ ToS(RubyEncoding/*!*/ self) {
-            return MutableString.Create(self.Name);
+            return MutableString.CreateAscii(self.Name);
         }
 
         [RubyMethod(&quot;inspect&quot;)]
         public static MutableString/*!*/ Inspect(RubyContext/*!*/ context, RubyEncoding/*!*/ self) {
             // TODO: to_s overridden
-            MutableString result = MutableString.CreateMutable();
+            MutableString result = MutableString.CreateMutable(RubyEncoding.ClassName);
             result.Append(&quot;#&lt;&quot;);
             result.Append(context.GetClassDisplayName(self));
             result.Append(':');
             result.Append(self.Name);
-            result.Append(&quot;&gt;&quot;);
+            result.Append('&gt;');
             return result;
         }
 
@@ -124,7 +124,7 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;locale_charmap&quot;, RubyMethodAttributes.PublicSingleton)]
         public static MutableString/*!*/ GetDefaultCharmap(RubyClass/*!*/ self) {
-            return MutableString.Create(&quot;CP&quot; + StringUtils.DefaultEncoding.CodePage.ToString());
+            return MutableString.CreateAscii(&quot;CP&quot; + StringUtils.DefaultEncoding.CodePage.ToString());
         }
 
         #endregion</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/RubyEncodingOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -178,10 +178,10 @@ namespace IronRuby.Builtins {
         public static MutableString GetEncoding(RubyRegex/*!*/ self) {
             switch (self.Options &amp; RubyRegexOptions.EncodingMask) {
                 case RubyRegexOptions.NONE: return null;
-                case RubyRegexOptions.EUC: return MutableString.Create(&quot;euc&quot;);
-                case RubyRegexOptions.FIXED: return MutableString.Create(&quot;none&quot;);
-                case RubyRegexOptions.UTF8: return MutableString.Create(&quot;utf8&quot;);
-                case RubyRegexOptions.SJIS: return MutableString.Create(&quot;sjis&quot;);
+                case RubyRegexOptions.EUC: return MutableString.CreateAscii(&quot;euc&quot;);
+                case RubyRegexOptions.FIXED: return MutableString.CreateAscii(&quot;none&quot;);
+                case RubyRegexOptions.UTF8: return MutableString.CreateAscii(&quot;utf8&quot;);
+                case RubyRegexOptions.SJIS: return MutableString.CreateAscii(&quot;sjis&quot;);
                 default: throw Assert.Unreachable;
             }
         }
@@ -261,7 +261,7 @@ namespace IronRuby.Builtins {
                 return new RubyRegex(&quot;(?!)&quot;, RubyRegexOptions.NONE);
             }
 
-            MutableString result = MutableString.CreateMutable();
+            MutableString result = MutableString.CreateMutable(RubyEncoding.Binary);
             for (int i = 0; i &lt; strings.Length; i++) {
                 if (i &gt; 0) {
                     result.Append('|');</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/RubyRegexOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -26,14 +26,14 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;list&quot;, RubyMethodAttributes.PublicSingleton)]
         public static Hash/*!*/ List(RubyContext/*!*/ context, RubyModule/*!*/ self) {
             Hash result = new Hash(context);
-            result.Add(MutableString.Create(&quot;TERM&quot;), ScriptingRuntimeHelpers.Int32ToObject(15));
-            result.Add(MutableString.Create(&quot;SEGV&quot;), ScriptingRuntimeHelpers.Int32ToObject(11));
-            result.Add(MutableString.Create(&quot;KILL&quot;), ScriptingRuntimeHelpers.Int32ToObject(9));
-            result.Add(MutableString.Create(&quot;EXIT&quot;), ScriptingRuntimeHelpers.Int32ToObject(0));
-            result.Add(MutableString.Create(&quot;INT&quot;), ScriptingRuntimeHelpers.Int32ToObject(2));
-            result.Add(MutableString.Create(&quot;FPE&quot;), ScriptingRuntimeHelpers.Int32ToObject(8));
-            result.Add(MutableString.Create(&quot;ABRT&quot;), ScriptingRuntimeHelpers.Int32ToObject(22));
-            result.Add(MutableString.Create(&quot;ILL&quot;), ScriptingRuntimeHelpers.Int32ToObject(4));
+            result.Add(MutableString.CreateAscii(&quot;TERM&quot;), ScriptingRuntimeHelpers.Int32ToObject(15));
+            result.Add(MutableString.CreateAscii(&quot;SEGV&quot;), ScriptingRuntimeHelpers.Int32ToObject(11));
+            result.Add(MutableString.CreateAscii(&quot;KILL&quot;), ScriptingRuntimeHelpers.Int32ToObject(9));
+            result.Add(MutableString.CreateAscii(&quot;EXIT&quot;), ScriptingRuntimeHelpers.Int32ToObject(0));
+            result.Add(MutableString.CreateAscii(&quot;INT&quot;), ScriptingRuntimeHelpers.Int32ToObject(2));
+            result.Add(MutableString.CreateAscii(&quot;FPE&quot;), ScriptingRuntimeHelpers.Int32ToObject(8));
+            result.Add(MutableString.CreateAscii(&quot;ABRT&quot;), ScriptingRuntimeHelpers.Int32ToObject(22));
+            result.Add(MutableString.CreateAscii(&quot;ILL&quot;), ScriptingRuntimeHelpers.Int32ToObject(4));
             return result;
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Signal.cs</filename>
    </modified>
    <modified>
      <diff>@@ -41,7 +41,7 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;to_s&quot;, RubyMethodAttributes.PublicInstance)]
         public static MutableString/*!*/ ToS(object/*!*/ self) {
-            return MutableString.Create(&quot;main&quot;);
+            return MutableString.CreateAscii(&quot;main&quot;);
         }
 
         // thread-safe:</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/SingletonOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -68,7 +68,6 @@ namespace IronRuby.Builtins {
     /// TODO: Many dynamic languages have similar printf style functionality.
     ///       Combine this with IronPython's StringFormatter and move the common code into the DLR
     /// 
-    /// TODO: Use MutableString instead of StringBuilder for building the string
     /// TODO: Support negative numbers for %u and %o and %x
     /// &lt;/summary&gt;
     internal sealed class StringFormatter {      
@@ -117,23 +116,30 @@ namespace IronRuby.Builtins {
         // Should ddd.0 be displayed as &quot;ddd&quot; or &quot;ddd.0&quot;. &quot;'%g' % ddd.0&quot; needs &quot;ddd&quot;, but str(ddd.0) needs &quot;ddd.0&quot;
         private bool _TrailingZeroAfterWholeFloat;
 
+        /// TODO: Use MutableString instead of StringBuilder for building the string + encodings
         private StringBuilder _buf;
 
+        // TODO (encoding):
+        private readonly RubyEncoding/*!*/ _encoding;
+
         private readonly StringFormatterSiteStorage/*!*/ _siteStorage;
 
         #region Constructors
 
         // TODO: remove
-        internal StringFormatter(RubyContext/*!*/ context, string/*!*/ format, IList/*!*/ data) {
-            Assert.NotNull(context, format, data);
+        internal StringFormatter(RubyContext/*!*/ context, string/*!*/ format, RubyEncoding/*!*/ encoding, IList/*!*/ data) {
+            Assert.NotNull(context, format, data, encoding);
 
             _context = context;
             _format = format;
             _data = data;
+
+            // TODO (encoding):
+            _encoding = encoding;
         }
 
-        internal StringFormatter(StringFormatterSiteStorage/*!*/ siteStorage, string/*!*/ format, IList/*!*/ data)
-            : this(siteStorage.Context, format, data) {
+        internal StringFormatter(StringFormatterSiteStorage/*!*/ siteStorage, string/*!*/ format, RubyEncoding/*!*/ encoding, IList/*!*/ data)
+            : this(siteStorage.Context, format, encoding, data) {
             Assert.NotNull(siteStorage);
             _siteStorage = siteStorage;
         }
@@ -162,7 +168,7 @@ namespace IronRuby.Builtins {
 
             _buf.Append(_format, _index, _format.Length - _index);
 
-            MutableString result = MutableString.Create(_buf.ToString());
+            MutableString result = MutableString.Create(_buf.ToString(), _encoding);
 
             if (_tainted) {
                 KernelOps.Taint(_context, result);</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/StringFormatter.cs</filename>
    </modified>
    <modified>
      <diff>@@ -230,7 +230,7 @@ namespace IronRuby.Builtins {
 
             using (IDisposable handle = RubyUtils.InfiniteInspectTracker.TrackObject(self)) {
                 // #&lt;struct Struct::Foo name=nil, val=nil&gt;
-                var result = MutableString.CreateMutable();
+                var result = MutableString.CreateMutable(RubyEncoding.Binary);
                 result.Append(&quot;#&lt;struct &quot;);
                 result.Append(context.Inspect(context.GetClassOf(self)));
 
@@ -245,8 +245,9 @@ namespace IronRuby.Builtins {
                     if (i != 0) {
                         result.Append(&quot;, &quot;);
                     }
+                    // TODO (encoding):
                     result.Append(members[i]);
-                    result.Append(&quot;=&quot;);
+                    result.Append('=');
                     result.Append(context.Inspect(data[i]));
                 }
                 result.Append('&gt;');
@@ -257,7 +258,7 @@ namespace IronRuby.Builtins {
         // For some unknown reason Struct defines the method even though it is mixed in from Enumerable
         // Until we discover the difference, delegate to Enumerable#select
         [RubyMethod(&quot;select&quot;)]
-        public static RubyArray/*!*/ Select(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BlockParam predicate, RubyStruct/*!*/ self) {
+        public static object Select(CallSiteStorage&lt;EachSite&gt;/*!*/ each, BlockParam predicate, RubyStruct/*!*/ self) {
             return Enumerable.Select(each, predicate, self);
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/StructOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -30,7 +30,7 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;id2name&quot;)]
         [RubyMethod(&quot;to_s&quot;)]
         public static MutableString/*!*/ ToString(SymbolId self) {
-            return MutableString.Create(SymbolTable.IdToString(self));
+            return MutableString.Create(SymbolTable.IdToString(self), RubyEncoding.Symbol);
         }
 
         [RubyMethod(&quot;inspect&quot;)]
@@ -54,7 +54,7 @@ namespace IronRuby.Builtins {
             switch (str) {
                 case null:
                     // Ruby doesn't allow empty symbols, we can get one from outside though:
-                    return MutableString.Create(&quot;:\&quot;\&quot;&quot;);
+                    return MutableString.CreateAscii(&quot;:\&quot;\&quot;&quot;);
 
                 case &quot;|&quot;:
                 case &quot;^&quot;:</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/SymbolOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -15,17 +15,13 @@
 
 using System;
 using System.Collections.Generic;
-using System.Linq.Expressions;
-using Microsoft.Scripting;
-using System.Dynamic;
-using Microsoft.Scripting.Actions;
-using Microsoft.Scripting.Runtime;
-using Microsoft.Scripting.Utils;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Text;
 using System.Threading;
 using IronRuby.Runtime;
-using System.Text;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
+using Microsoft.Scripting;
+using Microsoft.Scripting.Runtime;
 
 namespace IronRuby.Builtins {
     /// &lt;summary&gt;
@@ -76,6 +72,7 @@ namespace IronRuby.Builtins {
             private readonly int _id;
             private ThreadGroup _group;
             private readonly Thread _thread;
+            private bool _blocked;
             private bool _abortOnException;
             private AutoResetEvent _runSignal = new AutoResetEvent(false);
             private bool _isSleeping;
@@ -159,6 +156,16 @@ namespace IronRuby.Builtins {
             internal object Result { get; set; }
             internal bool CreatedFromRuby { get; set; }
             internal bool ExitRequested { get; set; }
+            
+            internal bool Blocked {
+                get {
+                    return _blocked;
+                }
+                set {
+                    System.Diagnostics.Debug.Assert(Thread.CurrentThread == _thread);
+                    _blocked = value;
+                }
+            }
 
             internal bool AbortOnException {
                 get {
@@ -279,7 +286,7 @@ namespace IronRuby.Builtins {
         public static MutableString/*!*/ Inspect(RubyContext/*!*/ context, Thread/*!*/ self) {
             RubyThreadInfo.RegisterThread(Thread.CurrentThread);
 
-            MutableString result = MutableString.CreateMutable();
+            MutableString result = MutableString.CreateMutable(RubyEncoding.ClassName);
             result.Append(&quot;#&lt;&quot;);
             result.Append(context.GetClassDisplayName(self));
             result.Append(':');
@@ -516,7 +523,11 @@ namespace IronRuby.Builtins {
             }
 
             if ((state &amp; ThreadState.Running) == ThreadState.Running) {
-                return RubyThreadStatus.Running;
+                if (info.Blocked) {
+                    return RubyThreadStatus.Sleeping;
+                } else {
+                    return RubyThreadStatus.Running;
+                }
             }
 
             throw new ArgumentException(&quot;unknown thread status: &quot; + state);
@@ -527,13 +538,13 @@ namespace IronRuby.Builtins {
             RubyThreadInfo.RegisterThread(Thread.CurrentThread);
             switch (GetStatus(self)) {
                 case RubyThreadStatus.Unstarted:
-                    return MutableString.Create(&quot;unstarted&quot;);
+                    return MutableString.CreateAscii(&quot;unstarted&quot;);
                 case RubyThreadStatus.Running:
-                    return MutableString.Create(&quot;run&quot;);
+                    return MutableString.CreateAscii(&quot;run&quot;);
                 case RubyThreadStatus.Sleeping:
-                    return MutableString.Create(&quot;sleep&quot;);
+                    return MutableString.CreateAscii(&quot;sleep&quot;);
                 case RubyThreadStatus.Aborting:
-                    return MutableString.Create(&quot;aborting&quot;);
+                    return MutableString.CreateAscii(&quot;aborting&quot;);
                 case RubyThreadStatus.Completed:
                     return false;
                 case RubyThreadStatus.Aborted:</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ThreadOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -21,6 +21,7 @@ using Microsoft.Scripting.Math;
 using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 using IronRuby.Runtime;
+using System.Globalization;
 
 namespace IronRuby.Builtins {
 
@@ -383,6 +384,8 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;strftime&quot;)]
         public static MutableString/*!*/ FormatTime(DateTime self, [DefaultProtocol, NotNull]MutableString/*!*/ format) {
+            // TODO (encoding):
+
             bool inEscape = false;
             StringBuilder builder = new StringBuilder();
             foreach (char c in format.ToString()) {
@@ -469,7 +472,7 @@ namespace IronRuby.Builtins {
                             break;
                     }
                     if (thisFormat != null) {
-                        builder.Append(self.ToString(thisFormat));
+                        builder.Append(self.ToString(thisFormat, CultureInfo.InvariantCulture));
                     }
                     inEscape = false;
                 } else {
@@ -477,7 +480,7 @@ namespace IronRuby.Builtins {
                 }
             }
 
-            return MutableString.Create(builder.ToString());
+            return MutableString.Create(builder.ToString(), format.Encoding);
         }
 
         [RubyMethod(&quot;succ&quot;)]
@@ -512,7 +515,7 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;inspect&quot;)]
         [RubyMethod(&quot;to_s&quot;)]
         public static MutableString/*!*/ ToString(DateTime self) {
-            return MutableString.Create(self.ToString(&quot;ddd MMM dd HH:mm:ss K yyyy&quot;));
+            return MutableString.CreateAscii(self.ToString(&quot;ddd MMM dd HH:mm:ss K yyyy&quot;, CultureInfo.InvariantCulture));
         }
 
         [RubyMethod(&quot;gmtoff&quot;)]
@@ -578,7 +581,7 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;zone&quot;)]
         public static MutableString/*!*/ GetZone(DateTime/*!*/ self) {
             // TODO: 
-            return MutableString.Create(&quot;UTC&quot;);
+            return MutableString.CreateAscii(&quot;UTC&quot;);
         }
     }
 }
\ No newline at end of file</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/TimeOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -26,7 +26,7 @@ namespace IronRuby.Builtins {
         [RubyMethodAttribute(&quot;to_s&quot;)]
         public static MutableString/*!*/ ToString(bool self) {
             Debug.Assert(self == true);
-            return MutableString.Create(&quot;true&quot;); 
+            return MutableString.CreateAscii(&quot;true&quot;); 
         }
 
         [RubyMethodAttribute(&quot;&amp;&quot;)]</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/TrueClass.cs</filename>
    </modified>
    <modified>
      <diff>@@ -91,7 +91,7 @@ namespace IronRuby.Builtins {
         internal static MutableString/*!*/ ToS(RubyContext/*!*/ context, string/*!*/ methodName, RubyModule/*!*/ declaringModule, RubyModule/*!*/ targetModule, 
             string/*!*/ classDisplayName) {
 
-            MutableString result = MutableString.CreateMutable();
+            MutableString result = MutableString.CreateMutable(RubyEncoding.ClassName);
 
             result.Append(&quot;#&lt;&quot;);
             result.Append(classDisplayName);</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/UnboundMethod.cs</filename>
    </modified>
    <modified>
      <diff>@@ -155,7 +155,8 @@ namespace IronRuby.StandardLibrary.Digest {
             #region Helpers
 
             internal static MutableString/*!*/ Bytes2Hex(byte[]/*!*/ bytes) {
-                return MutableString.Create(System.BitConverter.ToString(bytes).Replace(&quot;-&quot;, &quot;&quot;).ToLower());
+                // TODO (opt): see also OpenSSL
+                return MutableString.CreateAscii(System.BitConverter.ToString(bytes).Replace(&quot;-&quot;, &quot;&quot;).ToLower());
             }
 
             internal static MutableString/*!*/ HexEncode(MutableString/*!*/ str) {</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Digest/Digest.cs</filename>
    </modified>
    <modified>
      <diff>@@ -33,7 +33,7 @@ namespace IronRuby.StandardLibrary.Enumerator {
     public static class EnumerableKernelOps {
         [RubyMethod(&quot;to_enum&quot;)]
         [RubyMethod(&quot;enum_for&quot;)]
-        public static Enumerable.Enumerator/*!*/ Create(object self, [DefaultProtocol, Optional]string enumeratorName, 
+        public static Enumerable.Enumerator/*!*/ Create(object self, [DefaultProtocol, NotNull]string/*!*/ enumeratorName, 
             [NotNull]params object[] targetParameters) {
             return new Enumerable.Enumerator(self, enumeratorName, targetParameters);
         }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Enumerator/Enumerator.cs</filename>
    </modified>
    <modified>
      <diff>@@ -18,6 +18,7 @@ using IronRuby.Runtime;
 using Microsoft.Scripting.Generation;
 using Microsoft.Scripting.Math;
 using Microsoft.Scripting.Runtime;
+using System.Globalization;
 
 namespace IronRuby.Builtins {
 
@@ -810,7 +811,7 @@ namespace IronRuby.Builtins {
         /// &lt;/summary&gt;
         [RubyMethod(&quot;to_s&quot;)]
         public static MutableString/*!*/ ToString(BigInteger/*!*/ self) {
-            return MutableString.Create(self.ToString());
+            return MutableString.CreateAscii(self.ToString());
         }
 
         /// &lt;summary&gt;
@@ -824,7 +825,7 @@ namespace IronRuby.Builtins {
             }
 
             // TODO: Can we do the ToLower in BigInteger?
-            return MutableString.Create(self.ToString((uint)radix).ToLower());
+            return MutableString.CreateAscii(self.ToString((uint)radix).ToLower());
         }
 
         #endregion</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrBigInteger.cs</filename>
    </modified>
    <modified>
      <diff>@@ -534,7 +534,7 @@ namespace IronRuby.Builtins {
         /// &lt;/remarks&gt;
         [RubyMethod(&quot;to_s&quot;)]
         public static MutableString ToS(RubyContext/*!*/ context, double self) {
-            StringFormatter sf = new StringFormatter(context, &quot;%.15g&quot;, new object[] { self });
+            StringFormatter sf = new StringFormatter(context, &quot;%.15g&quot;, RubyEncoding.Binary, new object[] { self });
             sf.TrailingZeroAfterWholeFloat = true;
             return sf.Format();
         }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrFloat.cs</filename>
    </modified>
    <modified>
      <diff>@@ -87,7 +87,7 @@ namespace IronRuby.Builtins {
         
         [RubyMethod(&quot;inspect&quot;)]
         public static MutableString/*!*/ Inspect(object/*!*/ self) {
-            return MutableString.CreateMutable().Append(self.ToString()).Append(&quot; (Byte)&quot;);
+            return MutableString.CreateMutable(RubyEncoding.Binary).Append(self.ToString()).Append(&quot; (Byte)&quot;);
         }
     }
     
@@ -126,7 +126,7 @@ namespace IronRuby.Builtins {
         
         [RubyMethod(&quot;inspect&quot;)]
         public static MutableString/*!*/ Inspect(object/*!*/ self) {
-            return MutableString.CreateMutable().Append(self.ToString()).Append(&quot; (SByte)&quot;);
+            return MutableString.CreateMutable(RubyEncoding.Binary).Append(self.ToString()).Append(&quot; (SByte)&quot;);
         }
     }
     
@@ -165,7 +165,7 @@ namespace IronRuby.Builtins {
         
         [RubyMethod(&quot;inspect&quot;)]
         public static MutableString/*!*/ Inspect(object/*!*/ self) {
-            return MutableString.CreateMutable().Append(self.ToString()).Append(&quot; (Int16)&quot;);
+            return MutableString.CreateMutable(RubyEncoding.Binary).Append(self.ToString()).Append(&quot; (Int16)&quot;);
         }
     }
     
@@ -204,7 +204,7 @@ namespace IronRuby.Builtins {
         
         [RubyMethod(&quot;inspect&quot;)]
         public static MutableString/*!*/ Inspect(object/*!*/ self) {
-            return MutableString.CreateMutable().Append(self.ToString()).Append(&quot; (UInt16)&quot;);
+            return MutableString.CreateMutable(RubyEncoding.Binary).Append(self.ToString()).Append(&quot; (UInt16)&quot;);
         }
     }
     
@@ -243,7 +243,7 @@ namespace IronRuby.Builtins {
         
         [RubyMethod(&quot;inspect&quot;)]
         public static MutableString/*!*/ Inspect(object/*!*/ self) {
-            return MutableString.CreateMutable().Append(self.ToString()).Append(&quot; (UInt32)&quot;);
+            return MutableString.CreateMutable(RubyEncoding.Binary).Append(self.ToString()).Append(&quot; (UInt32)&quot;);
         }
     }
     
@@ -282,7 +282,7 @@ namespace IronRuby.Builtins {
         
         [RubyMethod(&quot;inspect&quot;)]
         public static MutableString/*!*/ Inspect(object/*!*/ self) {
-            return MutableString.CreateMutable().Append(self.ToString()).Append(&quot; (Int64)&quot;);
+            return MutableString.CreateMutable(RubyEncoding.Binary).Append(self.ToString()).Append(&quot; (Int64)&quot;);
         }
     }
     
@@ -321,7 +321,7 @@ namespace IronRuby.Builtins {
         
         [RubyMethod(&quot;inspect&quot;)]
         public static MutableString/*!*/ Inspect(object/*!*/ self) {
-            return MutableString.CreateMutable().Append(self.ToString()).Append(&quot; (UInt64)&quot;);
+            return MutableString.CreateMutable(RubyEncoding.Binary).Append(self.ToString()).Append(&quot; (UInt64)&quot;);
         }
     }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrInteger.Generated.cs</filename>
    </modified>
    <modified>
      <diff>@@ -66,6 +66,6 @@ public static partial class $SelfOps {
     
     [RubyMethod(&quot;inspect&quot;)]
     public static MutableString/*!*/ Inspect(object/*!*/ self) {
-        return MutableString.CreateMutable().Append(self.ToString()).Append(&quot; ($Self)&quot;);
+        return MutableString.CreateMutable(RubyEncoding.Binary).Append(self.ToString()).Append(&quot; ($Self)&quot;);
     }
 }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrInteger.Generator.rb</filename>
    </modified>
    <modified>
      <diff>@@ -855,7 +855,7 @@ namespace IronRuby.Builtins {
         /// &lt;example&gt;12345.to_s =&gt; &quot;12345&quot;&lt;/example&gt;
         [RubyMethod(&quot;to_s&quot;)]
         public static object ToString(object/*!*/ self) {
-            return MutableString.Create(self.ToString());
+            return MutableString.CreateAscii(self.ToString());
         }
 
         /// &lt;summary&gt;
@@ -876,7 +876,7 @@ namespace IronRuby.Builtins {
             }
             // TODO: Should we try to use a Fixnum specific ToString?
             // TODO: Can we do the ToLower in BigInteger?
-            return MutableString.Create(self.ToString((uint)radix).ToLower());
+            return MutableString.CreateAscii(self.ToString((uint)radix).ToLower());
         }
 
         #endregion</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrInteger.cs</filename>
    </modified>
    <modified>
      <diff>@@ -38,14 +38,14 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;clr_name&quot;)]
         public static MutableString/*!*/ GetClrName(ClrName/*!*/ self) {
-            return MutableString.Create(self.ActualName);
+            return MutableString.Create(self.ActualName, RubyEncoding.UTF8);
         }
 
         [RubyMethod(&quot;to_s&quot;)]
         [RubyMethod(&quot;to_str&quot;)]
         [RubyMethod(&quot;ruby_name&quot;)]
         public static MutableString/*!*/ GetRubyName(ClrName/*!*/ self) {
-            return MutableString.Create(self.MangledName);
+            return MutableString.Create(self.MangledName, RubyEncoding.UTF8);
         }
 
         [RubyMethod(&quot;to_sym&quot;)]
@@ -98,7 +98,7 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;unmangle&quot;, RubyMethodAttributes.PublicSingleton)]
         public static MutableString Unmangle(RubyClass/*!*/ self, [DefaultProtocol]string/*!*/ rubyName) {
             var clr = RubyUtils.TryUnmangleName(rubyName);
-            return clr != null ? MutableString.Create(clr) : null;
+            return clr != null ? MutableString.Create(clr, RubyEncoding.UTF8) : null;
         }
 
         /// &lt;summary&gt;
@@ -110,7 +110,7 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;mangle&quot;, RubyMethodAttributes.PublicSingleton)]
         public static MutableString Mangle(RubyClass/*!*/ self, [DefaultProtocol]string/*!*/ clrName) {
             var ruby = RubyUtils.TryMangleName(clrName);
-            return ruby != null ? MutableString.Create(ruby) : null;
+            return ruby != null ? MutableString.Create(ruby, RubyEncoding.UTF8) : null;
         }
     }
 }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrNameOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -21,6 +21,8 @@ using System;
 using IronRuby.Compiler;
 using System.Runtime.InteropServices;
 using Microsoft.Scripting;
+using System.Runtime.CompilerServices;
+using IronRuby.Runtime.Calls;
 
 namespace IronRuby.Builtins {
 
@@ -58,7 +60,7 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;%&quot;)]
         public static string/*!*/ Format(StringFormatterSiteStorage/*!*/ storage, string/*!*/ self, object arg) {
             IList args = arg as IList ?? new object[] { arg };
-            StringFormatter formatter = new StringFormatter(storage, self, args);
+            StringFormatter formatter = new StringFormatter(storage, self, RubyEncoding.UTF8, args);
             return formatter.Format().ToString();
         }
 
@@ -141,15 +143,17 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;inspect&quot;, RubyMethodAttributes.PublicInstance)]
         public static MutableString/*!*/ Inspect(string/*!*/ self) {
-            return MutableString.Create(MutableString.AppendUnicodeRepresentation(
-                new StringBuilder().Append('\''), self, false, false, '\'', -1).Append('\'').ToString()
+            return MutableString.Create(
+                MutableString.AppendUnicodeRepresentation(new StringBuilder().Append('\''), self, false, false, '\'', -1).Append('\'').ToString(),
+                RubyEncoding.UTF8
             );
         }
 
         [RubyMethod(&quot;dump&quot;, RubyMethodAttributes.PublicInstance)]
         public static MutableString/*!*/ Dump(string/*!*/ self) {
-            return MutableString.Create(MutableString.AppendUnicodeRepresentation(
-                new StringBuilder().Append('\''), self, false, true, '\'', -1).Append('\'').ToString()
+            return MutableString.Create(
+                MutableString.AppendUnicodeRepresentation(new StringBuilder().Append('\''), self, false, true, '\'', -1).Append('\'').ToString(), 
+                RubyEncoding.UTF8
             );
         }
 
@@ -198,7 +202,25 @@ namespace IronRuby.Builtins {
 
         #endregion
 
-        #region TODO: match
+        #region =~, TODO: match
+
+        [RubyMethod(&quot;=~&quot;)]
+        public static object Match(RubyScope/*!*/ scope, string/*!*/ self, [NotNull]RubyRegex/*!*/ regex) {
+            return RegexpOps.MatchIndex(scope, regex, MutableString.Create(self, RubyEncoding.UTF8));
+        }
+
+        [RubyMethod(&quot;=~&quot;)]
+        public static object Match(string/*!*/ self, [NotNull]string/*!*/ str) {
+            throw RubyExceptions.CreateTypeError(&quot;type mismatch: String given&quot;);
+        }
+
+        [RubyMethod(&quot;=~&quot;)]
+        public static object Match(CallSiteStorage&lt;Func&lt;CallSite, RubyScope, object, string, object&gt;&gt;/*!*/ storage,
+            RubyScope/*!*/ scope, string/*!*/ self, object obj) {
+            var site = storage.GetCallSite(&quot;=~&quot;, new RubyCallSignature(1, RubyCallFlags.HasScope | RubyCallFlags.HasImplicitSelf));
+            return site.Target(site, scope, obj, self);
+        }
+
         #endregion
 
         #region TODO: scan</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrStringOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -328,9 +328,9 @@ namespace IronRuby.Builtins {
 
             using (IDisposable handle = RubyUtils.InfiniteInspectTracker.TrackObject(self)) {
                 if (handle == null) {
-                    return MutableString.Create(&quot;{...}&quot;);
+                    return MutableString.CreateAscii(&quot;{...}&quot;);
                 }
-                MutableString str = MutableString.CreateMutable();
+                MutableString str = MutableString.CreateMutable(RubyEncoding.Binary);
                 str.Append('{');
                 foreach (KeyValuePair&lt;object, object&gt; pair in self) {
                     if (str.Length != 1) {
@@ -522,7 +522,7 @@ namespace IronRuby.Builtins {
 
             using (IDisposable handle = RubyUtils.InfiniteToSTracker.TrackObject(self)) {
                 if (handle == null) {
-                    return MutableString.Create(&quot;{...}&quot;);
+                    return MutableString.CreateAscii(&quot;{...}&quot;);
                 } else {
                     return IListOps.Join(tosConversion, ToArray(self));
                 }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/IDictionaryOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -1009,65 +1009,147 @@ namespace IronRuby.Builtins {
 
         #region flatten, flatten!
 
-        [MultiRuntimeAware]
-        private static RubyUtils.RecursionTracker _infiniteFlattenTracker = new RubyUtils.RecursionTracker();
+        private static int IndexOfList(ConversionStorage&lt;IList&gt;/*!*/ tryToAry, IList/*!*/ list, int start, out IList listItem) {
+            for (int i = start; i &lt; list.Count; i++) {
+                listItem = Protocols.TryCastToArray(tryToAry, list[i]);
+                if (listItem != null) {
+                    return i;
+                }
+            }
+            listItem = null;
+            return -1;
+        }
 
-        public static bool TryFlattenArray(
-            CallSiteStorage&lt;Func&lt;CallSite, RubyClass, object&gt;&gt;/*!*/ allocateStorage, 
-            ConversionStorage&lt;IList&gt;/*!*/ tryToAry, 
-            IList list, out IList/*!*/ result) {
+        /// &lt;summary&gt;
+        /// Enumerates all items of the list recursively - if there are any items convertible to IList the items of that lists are enumerated as well.
+        /// Returns null if there are no nested lists and so the list can be enumerated using a standard enumerator.
+        /// &lt;/summary&gt;
+        public static IEnumerable&lt;object&gt; EnumerateRecursively(ConversionStorage&lt;IList&gt;/*!*/ tryToAry, IList/*!*/ list, Func&lt;IList, object&gt;/*!*/ loopDetected) {
+            IList nested;
+            int nestedIndex = IndexOfList(tryToAry, list, 0, out nested);
 
-            result = CreateResultArray(allocateStorage, list);
+            if (nestedIndex == -1) {
+                return null;
+            }
 
-            using (IDisposable handle = _infiniteFlattenTracker.TrackObject(list)) {
-                if (handle == null) {
-                    throw RubyExceptions.CreateArgumentError(&quot;tried to flatten recursive array&quot;);
+            return EnumerateRecursively(tryToAry, list, list, nested, nestedIndex, loopDetected);
+        }
+
+        private static IEnumerable&lt;object&gt;/*!*/ EnumerateRecursively(ConversionStorage&lt;IList&gt;/*!*/ tryToAry, IList/*!*/ root, 
+            IList/*!*/ list, IList nested, int nestedIndex, Func&lt;IList, object&gt;/*!*/ loopDetected) {
+
+            var worklist = new Stack&lt;KeyValuePair&lt;IList, int&gt;&gt;();
+            var recursionPath = new Dictionary&lt;object, bool&gt;(ReferenceEqualityComparer.Instance);
+            int start = 0;
+
+            while (true) {
+                if (nestedIndex &gt;= 0) {
+                    // push a workitem for the items following the nested list:
+                    if (nestedIndex &lt; list.Count - 1) {
+                        worklist.Push(new KeyValuePair&lt;IList, int&gt;(list, nestedIndex + 1));
+                    }
+
+                    // yield items preceding the nested list:
+                    for (int i = start; i &lt; nestedIndex; i++) {
+                        yield return list[i];
+                    }
+
+                    // push a workitem for the nested list:
+                    if (nestedIndex != -1) {
+                        worklist.Push(new KeyValuePair&lt;IList, int&gt;(nested, 0));                        
+                    }
+                } else {
+                    // there is no nested list =&gt; yield all remaining items:
+                    for (int i = start; i &lt; list.Count; i++) {
+                        yield return list[i];
+                    }
                 }
-                bool flattened = false;
-                for (int i = 0; i &lt; list.Count; i++) {
-                    IList item = Protocols.TryCastToArray(tryToAry, list[i]);
-                    if (item != null) {
-                        flattened = true;
-                        IList flattenedList;
-
-                        TryFlattenArray(allocateStorage, tryToAry, item, out flattenedList);
-                        if (flattenedList != null) {
-                            AddRange(result, flattenedList);
-                        } else {
-                            result.Add(item);
-                        }
+
+                // finished nested list workitem:
+                if (start == 0) {
+                    recursionPath.Remove(list);
+                }
+
+            next:
+                if (worklist.Count == 0) {
+                    break;
+                }
+
+                var workitem = worklist.Pop();
+                list = workitem.Key;
+                start = workitem.Value;
+
+                // starting nested workitem:
+                if (start == 0) {
+                    if (ReferenceEquals(nested, root) || recursionPath.ContainsKey(nested)) {
+                        yield return loopDetected(nested);
+                        goto next;
                     } else {
-                        result.Add(list[i]);
+                        recursionPath.Add(nested, true);
                     }
                 }
-                return flattened;
+                
+                nestedIndex = IndexOfList(tryToAry, list, start, out nested);
             }
         }
 
         [RubyMethod(&quot;flatten&quot;)]
-        public static IList/*!*/ Flatten(
-            CallSiteStorage&lt;Func&lt;CallSite, RubyClass, object&gt;&gt;/*!*/ allocateStorage, 
-            ConversionStorage&lt;IList&gt;/*!*/ tryToAry, 
+        public static IList/*!*/ Flatten(CallSiteStorage&lt;Func&lt;CallSite, RubyClass, object&gt;&gt;/*!*/ allocateStorage, ConversionStorage&lt;IList&gt;/*!*/ tryToAry, 
             IList/*!*/ self) {
 
-            IList result;
-            TryFlattenArray(allocateStorage, tryToAry, self, out result);
+            IList result = CreateResultArray(allocateStorage, self);
+            var recEnum = EnumerateRecursively(tryToAry, self, (_) =&gt; { throw RubyExceptions.CreateArgumentError(&quot;tried to flatten recursive array&quot;); });
+
+            if (recEnum != null) {
+                foreach (var item in recEnum) {
+                    result.Add(item);
+                }
+            } else {
+                AddRange(result, self);
+            }
+
             return result;
         }
 
         [RubyMethod(&quot;flatten!&quot;)]
-        public static IList FlattenInPlace(
-            CallSiteStorage&lt;Func&lt;CallSite, RubyClass, object&gt;&gt;/*!*/ allocateStorage, 
-            ConversionStorage&lt;IList&gt;/*!*/ tryToAry, 
-            IList/*!*/ self) {
+        public static IList FlattenInPlace(ConversionStorage&lt;IList&gt;/*!*/ tryToAry, IList/*!*/ self) {
+            IList nested;
+            int nestedIndex = IndexOfList(tryToAry, self, 0, out nested);
 
-            IList result;
-            if (!TryFlattenArray(allocateStorage, tryToAry, self, out result)) {
+            if (nestedIndex == -1) {
                 return null;
             }
 
-            self.Clear();
-            AddRange(self, result);
+            var remaining = new object[self.Count - nestedIndex];
+            for (int i = 0, j = nestedIndex; i &lt; remaining.Length; i++) {
+                remaining[i] = self[j++];
+            }
+
+            bool isRecursive = false;
+            var recEnum = EnumerateRecursively(tryToAry, self, remaining, nested, 0, (rec) =&gt; {
+                isRecursive = true;
+                return rec;
+            });
+
+            // rewrite items following the first nested list (including the list):
+            int itemCount = nestedIndex;
+            foreach (var item in recEnum) {
+                if (itemCount &lt; self.Count) {
+                    self[itemCount] = item;
+                } else {
+                    self.Add(item);
+                }
+                itemCount++;
+            }
+
+            // empty arrays can make the list shrink:
+            while (self.Count &gt; itemCount) {
+                self.RemoveAt(self.Count - 1);
+            }
+
+            if (isRecursive) {
+                throw RubyExceptions.CreateArgumentError(&quot;tried to flatten recursive array&quot;);
+            }
             return self;
         }
 
@@ -1265,9 +1347,9 @@ namespace IronRuby.Builtins {
 
             using (IDisposable handle = RubyUtils.InfiniteInspectTracker.TrackObject(self)) {
                 if (handle == null) {
-                    return MutableString.Create(&quot;[...]&quot;);
+                    return MutableString.CreateAscii(&quot;[...]&quot;);
                 }
-                MutableString str = MutableString.CreateMutable();
+                MutableString str = MutableString.CreateMutable(RubyEncoding.Binary);
                 str.Append('[');
                 bool first = true;
                 foreach (object obj in self) {
@@ -1431,7 +1513,7 @@ namespace IronRuby.Builtins {
         #region sort, sort!
 
         [RubyMethod(&quot;sort&quot;)]
-        public static IList/*!*/ Sort(
+        public static object Sort(
             CallSiteStorage&lt;Func&lt;CallSite, RubyClass, object&gt;&gt;/*!*/ allocateStorage,
             BinaryOpStorage/*!*/ comparisonStorage,
             BinaryOpStorage/*!*/ lessThanStorage,
@@ -1440,13 +1522,19 @@ namespace IronRuby.Builtins {
 
             // TODO: this is not optimal because it makes an extra array copy
             // (only affects sorting of .NET types, do we need our own quicksort?)
-            IList result = CreateResultArray(allocateStorage, self);
-            Replace(result, ArrayOps.SortInPlace(comparisonStorage, lessThanStorage, greaterThanStorage, block, ToArray(self)));
-            return result;
+            IList resultList = CreateResultArray(allocateStorage, self);
+            StrongBox&lt;object&gt; breakResult;
+            RubyArray result = ArrayOps.SortInPlace(comparisonStorage, lessThanStorage, greaterThanStorage, block, ToArray(self), out breakResult);
+            if (breakResult == null) {
+                Replace(resultList, result);
+                return resultList;
+            } else {
+                return breakResult.Value;
+            }
         }
 
         [RubyMethod(&quot;sort!&quot;)]
-        public static IList/*!*/ SortInPlace(
+        public static object SortInPlace(
             BinaryOpStorage/*!*/ comparisonStorage,
             BinaryOpStorage/*!*/ lessThanStorage,
             BinaryOpStorage/*!*/ greaterThanStorage,
@@ -1457,8 +1545,14 @@ namespace IronRuby.Builtins {
 
             // TODO: this is not optimal because it makes an extra array copy
             // (only affects sorting of .NET types, do we need our own quicksort?)
-            Replace(self, ArrayOps.SortInPlace(comparisonStorage, lessThanStorage, greaterThanStorage, block, ToArray(self)));
-            return self;
+            StrongBox&lt;object&gt; breakResult;
+            RubyArray result = ArrayOps.SortInPlace(comparisonStorage, lessThanStorage, greaterThanStorage, block, ToArray(self), out breakResult);
+            if (breakResult == null) {
+                Replace(self, result);
+                return self;
+            } else {
+                return breakResult.Value;
+            }
         }
 
         #endregion
@@ -1557,7 +1651,7 @@ namespace IronRuby.Builtins {
         #region zip 
 
         [RubyMethod(&quot;zip&quot;)]
-        public static IList/*!*/ Zip(CallSiteStorage&lt;EachSite&gt;/*!*/ each, ConversionStorage&lt;IList&gt;/*!*/ tryToAry, BlockParam block,
+        public static object Zip(CallSiteStorage&lt;EachSite&gt;/*!*/ each, ConversionStorage&lt;IList&gt;/*!*/ tryToAry, BlockParam block,
             object self, [DefaultProtocol, NotNull, NotNullItems]params IList[]/*!*/ args) {
 
             return Enumerable.Zip(each, tryToAry, block, self, args);</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/IListOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -81,20 +81,20 @@ namespace IronRuby.Builtins {
         public static class ClrOps {
             [RubyMethod(&quot;profile&quot;, RubyMethodAttributes.PublicSingleton)]
             public static Hash/*!*/ GetProfile(RubyContext/*!*/ context, object self) {
-                if (!((RubyOptions)context.Options).Profile) {
+                if (!context.RubyOptions.Profile) {
                     throw RubyExceptions.CreateSystemCallError(&quot;You must enable profiling to use Clr.profile&quot;);
                 }
 
                 Hash result = new Hash(context);
                 foreach (var entry in Profiler.Instance.GetProfile()) {
-                    result[entry.Key] = Protocols.Normalize(Utils.DateTimeTicksFromStopwatch(entry.Value));
+                    result[entry.Id] = Utils.DateTimeTicksFromStopwatch(entry.Ticks);
                 }
                 return result;
             }
 
             [RubyMethod(&quot;profile&quot;, RubyMethodAttributes.PublicSingleton)]
             public static object GetProfile(RubyContext/*!*/ context, BlockParam/*!*/ block, object self) {
-                if (!((RubyOptions)context.Options).Profile) {
+                if (!context.RubyOptions.Profile) {
                     throw RubyExceptions.CreateSystemCallError(&quot;You must enable profiling to use Clr.profile&quot;);
                 }
 
@@ -104,15 +104,20 @@ namespace IronRuby.Builtins {
                     return blockResult;
                 }
 
+                var startDict = new Dictionary&lt;string, long&gt;();
+                foreach (var counter in start) {
+                    startDict[counter.Id] = counter.Ticks;
+                }
+
                 Hash result = new Hash(context);
                 foreach (var entry in Profiler.Instance.GetProfile()) {
                     long startTime;
-                    if (!start.TryGetValue(entry.Key, out startTime)) {
+                    if (!startDict.TryGetValue(entry.Id, out startTime)) {
                         startTime = 0;
                     }
-                    long elapsed = entry.Value - startTime;
+                    long elapsed = entry.Ticks - startTime;
                     if (elapsed &gt; 0) {
-                        result[entry.Key] = Protocols.Normalize(Utils.DateTimeTicksFromStopwatch(elapsed));
+                        result[entry.Id] = Utils.DateTimeTicksFromStopwatch(elapsed);
                     }
                 }
                 return result;</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/IronRubyOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -32,7 +32,7 @@ namespace IronRuby.Builtins {
 
         [RubyMethod(&quot;inspect&quot;)]
         public static MutableString/*!*/ Inspect(object/*!*/ self) {
-            return MutableString.CreateMutable().Append(self.ToString()).Append(&quot; (Single)&quot;);
+            return MutableString.CreateMutable(RubyEncoding.Binary).Append(self.ToString()).Append(&quot; (Single)&quot;);
         }
     }
 }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/SingleOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -81,12 +81,12 @@ namespace IronRuby.Builtins {
         [RubyMethod(&quot;name&quot;)]
         [RubyMethod(&quot;to_s&quot;)]
         public static MutableString/*!*/ GetName(TypeGroup/*!*/ self) {
-            return MutableString.Create(self.Name);
+            return MutableString.Create(self.Name, RubyEncoding.UTF8);
         }
 
         [RubyMethod(&quot;inspect&quot;)]
         public static MutableString/*!*/ Inspect(RubyContext/*!*/ context, TypeGroup/*!*/ self) {
-            var result = MutableString.CreateMutable();
+            var result = MutableString.CreateMutable(RubyEncoding.ClassName);
             result.Append(&quot;#&lt;TypeGroup: &quot;);
 
             bool isFirst = true;
@@ -101,7 +101,7 @@ namespace IronRuby.Builtins {
 
                 result.Append(context.GetTypeName(type, true));
             }
-            result.Append(&quot;&gt;&quot;);
+            result.Append('&gt;');
 
             return result;
         }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/TypeGroupOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -1 +1 @@
-&quot;%MERLIN_ROOT%\Bin\Debug\ClassInitGenerator&quot; &quot;%MERLIN_ROOT%\Bin\Debug\IronRuby.Libraries.dll&quot; /libraries:IronRuby.Builtins;IronRuby.StandardLibrary.Threading;IronRuby.StandardLibrary.Sockets;IronRuby.StandardLibrary.OpenSsl;IronRuby.StandardLibrary.Digest;IronRuby.StandardLibrary.Zlib;IronRuby.StandardLibrary.StringIO;IronRuby.StandardLibrary.StringScanner;IronRuby.StandardLibrary.Enumerator;IronRuby.StandardLibrary.FunctionControl;IronRuby.StandardLibrary.FileControl;IronRuby.StandardLibrary.BigDecimal;IronRuby.StandardLibrary.Iconv;IronRuby.StandardLibrary.ParseTree /out:%~dp0\Initializers.Generated.cs
+&quot;%MERLIN_ROOT%\Bin\Debug\ClassInitGenerator&quot; &quot;%MERLIN_ROOT%\Bin\Debug\IronRuby.Libraries.dll&quot; /libraries:IronRuby.Builtins;IronRuby.StandardLibrary.Threading;IronRuby.StandardLibrary.Sockets;IronRuby.StandardLibrary.OpenSsl;IronRuby.StandardLibrary.Digest;IronRuby.StandardLibrary.Zlib;IronRuby.StandardLibrary.StringIO;IronRuby.StandardLibrary.StringScanner;IronRuby.StandardLibrary.Enumerator;IronRuby.StandardLibrary.FunctionControl;IronRuby.StandardLibrary.FileControl;IronRuby.StandardLibrary.BigDecimal;IronRuby.StandardLibrary.Iconv;IronRuby.StandardLibrary.ParseTree;IronRuby.StandardLibrary.Open3 /out:%~dp0\Initializers.Generated.cs</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/GenerateInitializers.cmd</filename>
    </modified>
    <modified>
      <diff>@@ -27,6 +27,7 @@
 [assembly: IronRuby.Runtime.RubyLibraryAttribute(typeof(IronRuby.StandardLibrary.BigDecimal.BigDecimalLibraryInitializer))]
 [assembly: IronRuby.Runtime.RubyLibraryAttribute(typeof(IronRuby.StandardLibrary.Iconv.IconvLibraryInitializer))]
 [assembly: IronRuby.Runtime.RubyLibraryAttribute(typeof(IronRuby.StandardLibrary.ParseTree.ParseTreeLibraryInitializer))]
+[assembly: IronRuby.Runtime.RubyLibraryAttribute(typeof(IronRuby.StandardLibrary.Open3.Open3LibraryInitializer))]
 
 namespace IronRuby.Builtins {
     public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitializer {
@@ -44,28 +45,29 @@ namespace IronRuby.Builtins {
             
             // Skipped primitive: __ClassSingleton
             // Skipped primitive: __MainSingleton
-            IronRuby.Builtins.RubyModule def43 = DefineGlobalModule(&quot;Comparable&quot;, typeof(IronRuby.Builtins.Comparable), 0x00000103, LoadComparable_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyModule def34 = DefineGlobalModule(&quot;Enumerable&quot;, typeof(IronRuby.Builtins.Enumerable), 0x00000103, LoadEnumerable_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyModule def8 = DefineGlobalModule(&quot;Errno&quot;, typeof(IronRuby.Builtins.Errno), 0x00000103, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyModule def25 = DefineModule(&quot;File::Constants&quot;, typeof(IronRuby.Builtins.RubyFileOps.Constants), 0x00000103, null, null, LoadFile__Constants_Constants, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def44 = DefineGlobalModule(&quot;Comparable&quot;, typeof(IronRuby.Builtins.Comparable), 0x00000103, LoadComparable_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def35 = DefineGlobalModule(&quot;Enumerable&quot;, typeof(IronRuby.Builtins.Enumerable), 0x00000103, LoadEnumerable_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def2 = DefineGlobalModule(&quot;Errno&quot;, typeof(IronRuby.Builtins.Errno), 0x00000103, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def26 = DefineModule(&quot;File::Constants&quot;, typeof(IronRuby.Builtins.RubyFileOps.Constants), 0x00000103, null, null, LoadFile__Constants_Constants, IronRuby.Builtins.RubyModule.EmptyArray);
             DefineGlobalModule(&quot;FileTest&quot;, typeof(IronRuby.Builtins.FileTest), 0x00000103, null, LoadFileTest_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
             DefineGlobalModule(&quot;GC&quot;, typeof(IronRuby.Builtins.RubyGC), 0x00000103, LoadGC_Instance, LoadGC_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
             IronRuby.Builtins.RubyModule def22 = DefineGlobalModule(&quot;IronRuby&quot;, typeof(IronRuby.Ruby), 0x00000000, null, LoadIronRuby_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyModule def2 = DefineModule(&quot;IronRuby::Clr&quot;, typeof(IronRuby.Builtins.IronRubyOps.ClrOps), 0x00000100, null, LoadIronRuby__Clr_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyModule def3 = DefineModule(&quot;IronRuby::Clr::BigInteger&quot;, typeof(IronRuby.Builtins.ClrBigInteger), 0x00000103, LoadIronRuby__Clr__BigInteger_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def4 = DefineModule(&quot;IronRuby::Clr&quot;, typeof(IronRuby.Builtins.IronRubyOps.ClrOps), 0x00000100, null, LoadIronRuby__Clr_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def5 = DefineModule(&quot;IronRuby::Clr::BigInteger&quot;, typeof(IronRuby.Builtins.ClrBigInteger), 0x00000103, LoadIronRuby__Clr__BigInteger_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
             IronRuby.Builtins.RubyModule def20 = DefineModule(&quot;IronRuby::Clr::FlagEnumeration&quot;, typeof(IronRuby.Builtins.FlagEnumeration), 0x00000000, LoadIronRuby__Clr__FlagEnumeration_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyModule def4 = DefineModule(&quot;IronRuby::Clr::Float&quot;, typeof(IronRuby.Builtins.ClrFloat), 0x00000103, LoadIronRuby__Clr__Float_Instance, LoadIronRuby__Clr__Float_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyModule def5 = DefineModule(&quot;IronRuby::Clr::Integer&quot;, typeof(IronRuby.Builtins.ClrInteger), 0x00000103, LoadIronRuby__Clr__Integer_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def6 = DefineModule(&quot;IronRuby::Clr::Float&quot;, typeof(IronRuby.Builtins.ClrFloat), 0x00000103, LoadIronRuby__Clr__Float_Instance, LoadIronRuby__Clr__Float_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def7 = DefineModule(&quot;IronRuby::Clr::Integer&quot;, typeof(IronRuby.Builtins.ClrInteger), 0x00000103, LoadIronRuby__Clr__Integer_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
             IronRuby.Builtins.RubyModule def23 = DefineModule(&quot;IronRuby::Clr::MultiDimensionalArray&quot;, typeof(IronRuby.Builtins.MultiDimensionalArray), 0x00000000, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyModule def6 = DefineModule(&quot;IronRuby::Clr::String&quot;, typeof(IronRuby.Builtins.ClrString), 0x00000103, LoadIronRuby__Clr__String_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def8 = DefineModule(&quot;IronRuby::Clr::String&quot;, typeof(IronRuby.Builtins.ClrString), 0x00000103, LoadIronRuby__Clr__String_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def24 = DefineModule(&quot;IronRuby::Print&quot;, typeof(IronRuby.Builtins.PrintOps), 0x00000103, LoadIronRuby__Print_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
             // Skipped primitive: Kernel
             DefineGlobalModule(&quot;Marshal&quot;, typeof(IronRuby.Builtins.RubyMarshal), 0x00000103, null, LoadMarshal_Class, LoadMarshal_Constants, IronRuby.Builtins.RubyModule.EmptyArray);
             DefineGlobalModule(&quot;Math&quot;, typeof(IronRuby.Builtins.RubyMath), 0x00000103, LoadMath_Instance, LoadMath_Class, LoadMath_Constants, IronRuby.Builtins.RubyModule.EmptyArray);
             ExtendClass(typeof(Microsoft.Scripting.Actions.TypeTracker), null, LoadMicrosoft__Scripting__Actions__TypeTracker_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
             DefineGlobalModule(&quot;ObjectSpace&quot;, typeof(IronRuby.Builtins.ObjectSpace), 0x00000103, null, LoadObjectSpace_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyModule def40 = DefineGlobalModule(&quot;Precision&quot;, typeof(IronRuby.Builtins.Precision), 0x00000103, LoadPrecision_Instance, LoadPrecision_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def41 = DefineGlobalModule(&quot;Precision&quot;, typeof(IronRuby.Builtins.Precision), 0x00000103, LoadPrecision_Instance, LoadPrecision_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
             #if !SILVERLIGHT
-            IronRuby.Builtins.RubyModule def26 = DefineGlobalModule(&quot;Process&quot;, typeof(IronRuby.Builtins.RubyProcess), 0x00000103, LoadProcess_Instance, LoadProcess_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def27 = DefineGlobalModule(&quot;Process&quot;, typeof(IronRuby.Builtins.RubyProcess), 0x00000103, LoadProcess_Instance, LoadProcess_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
             #endif
             #if !SILVERLIGHT
             DefineGlobalModule(&quot;Signal&quot;, typeof(IronRuby.Builtins.Signal), 0x00000103, null, LoadSignal_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
@@ -73,264 +75,267 @@ namespace IronRuby.Builtins {
             ExtendClass(typeof(System.Type), null, LoadSystem__Type_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
             // Skipped primitive: __ClassSingletonSingleton
             #if !SILVERLIGHT
-            object def1 = DefineSingleton(Load__Singleton_ArgFilesSingletonOps_Instance, null, null, def34);
+            object def1 = DefineSingleton(Load__Singleton_ArgFilesSingletonOps_Instance, null, null, def35);
             #endif
-            object def7 = DefineSingleton(Load__Singleton_EnvironmentSingletonOps_Instance, null, null, def34);
-            ExtendClass(typeof(Microsoft.Scripting.Actions.TypeGroup), null, LoadMicrosoft__Scripting__Actions__TypeGroup_Instance, null, null, new IronRuby.Builtins.RubyModule[] {def34});
+            object def9 = DefineSingleton(Load__Singleton_EnvironmentSingletonOps_Instance, null, null, def35);
+            ExtendClass(typeof(Microsoft.Scripting.Actions.TypeGroup), null, LoadMicrosoft__Scripting__Actions__TypeGroup_Instance, null, null, new IronRuby.Builtins.RubyModule[] {def35});
             // Skipped primitive: Object
-            ExtendClass(typeof(System.Char), null, null, null, null, new IronRuby.Builtins.RubyModule[] {def6, def34, def43}, 
+            ExtendClass(typeof(System.Char), null, null, null, null, new IronRuby.Builtins.RubyModule[] {def8, def35, def44}, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Char, System.Char&gt;(IronRuby.Builtins.CharOps.Create), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Char[], System.Char&gt;(IronRuby.Builtins.CharOps.Create), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.String, System.Char&gt;(IronRuby.Builtins.CharOps.Create), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.Char&gt;(IronRuby.Builtins.CharOps.Create)
             );
-            ExtendModule(typeof(System.Collections.Generic.IDictionary&lt;System.Object, System.Object&gt;), LoadSystem__Collections__Generic__IDictionary_Instance, null, null, def34);
-            ExtendModule(typeof(System.Collections.IEnumerable), LoadSystem__Collections__IEnumerable_Instance, null, null, def34);
-            ExtendModule(typeof(System.Collections.IList), LoadSystem__Collections__IList_Instance, null, null, def34);
-            ExtendModule(typeof(System.IComparable), LoadSystem__IComparable_Instance, null, null, def43);
-            ExtendClass(typeof(System.String), null, null, null, null, new IronRuby.Builtins.RubyModule[] {def6, def34, def43}, 
+            ExtendModule(typeof(System.Collections.Generic.IDictionary&lt;System.Object, System.Object&gt;), LoadSystem__Collections__Generic__IDictionary_Instance, null, null, def35);
+            ExtendModule(typeof(System.Collections.IEnumerable), LoadSystem__Collections__IEnumerable_Instance, null, null, def35);
+            ExtendModule(typeof(System.Collections.IList), LoadSystem__Collections__IList_Instance, null, null, def35);
+            ExtendModule(typeof(System.IComparable), LoadSystem__IComparable_Instance, null, null, def44);
+            ExtendClass(typeof(System.String), null, null, null, null, new IronRuby.Builtins.RubyModule[] {def8, def35, def44}, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.String&gt;(IronRuby.Builtins.ClrStringOps.Create), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Char, System.Int32, System.String&gt;(IronRuby.Builtins.ClrStringOps.Create), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Char[], System.String&gt;(IronRuby.Builtins.ClrStringOps.Create), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Char[], System.Int32, System.Int32, System.String&gt;(IronRuby.Builtins.ClrStringOps.Create)
             );
-            DefineGlobalClass(&quot;Array&quot;, typeof(IronRuby.Builtins.RubyArray), 0x00000003, Context.ObjectClass, LoadArray_Instance, LoadArray_Class, null, new IronRuby.Builtins.RubyModule[] {def34}, 
+            DefineGlobalClass(&quot;Array&quot;, typeof(IronRuby.Builtins.RubyArray), 0x00000003, Context.ObjectClass, LoadArray_Instance, LoadArray_Class, null, new IronRuby.Builtins.RubyModule[] {def35}, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.ArrayOps.CreateArray), 
                 new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Runtime.Union&lt;System.Collections.IList, System.Int32&gt;&gt;, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyClass, System.Object, System.Object&gt;(IronRuby.Builtins.ArrayOps.CreateArray), 
                 new System.Func&lt;IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyClass, System.Int32, System.Object, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.ArrayOps.CreateArray), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, System.Object, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.ArrayOps.CreateArray)
             );
             DefineGlobalClass(&quot;Binding&quot;, typeof(IronRuby.Builtins.Binding), 0x00000003, Context.ObjectClass, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            DefineGlobalClass(&quot;Dir&quot;, typeof(IronRuby.Builtins.RubyDir), 0x00000103, Context.ObjectClass, LoadDir_Instance, LoadDir_Class, null, new IronRuby.Builtins.RubyModule[] {def34});
+            DefineGlobalClass(&quot;Dir&quot;, typeof(IronRuby.Builtins.RubyDir), 0x00000103, Context.ObjectClass, LoadDir_Instance, LoadDir_Class, null, new IronRuby.Builtins.RubyModule[] {def35});
             #if !SILVERLIGHT
             if (Context.RubyOptions.Compatibility &gt;= RubyCompatibility.Ruby19) {
             DefineGlobalClass(&quot;Encoding&quot;, typeof(IronRuby.Builtins.RubyEncoding), 0x00000003, Context.ObjectClass, LoadEncoding_Instance, LoadEncoding_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
             }
             #endif
-            IronRuby.Builtins.RubyClass def44 = Context.ExceptionClass = DefineGlobalClass(&quot;Exception&quot;, typeof(System.Exception), 0x00000003, Context.ObjectClass, LoadException_Instance, LoadException_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def45 = Context.ExceptionClass = DefineGlobalClass(&quot;Exception&quot;, typeof(System.Exception), 0x00000003, Context.ObjectClass, LoadException_Instance, LoadException_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__Exception));
             Context.FalseClass = DefineGlobalClass(&quot;FalseClass&quot;, typeof(IronRuby.Builtins.FalseClass), 0x00000103, Context.ObjectClass, LoadFalseClass_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
             #if !SILVERLIGHT
-            IronRuby.Builtins.RubyClass def32 = DefineClass(&quot;File::Stat&quot;, typeof(System.IO.FileSystemInfo), 0x00000003, Context.ObjectClass, LoadFile__Stat_Instance, null, null, new IronRuby.Builtins.RubyModule[] {def43}, 
+            IronRuby.Builtins.RubyClass def33 = DefineClass(&quot;File::Stat&quot;, typeof(System.IO.FileSystemInfo), 0x00000003, Context.ObjectClass, LoadFile__Stat_Instance, null, null, new IronRuby.Builtins.RubyModule[] {def44}, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.IO.FileSystemInfo&gt;(IronRuby.Builtins.RubyFileOps.RubyStatOps.Create)
             );
             #endif
-            DefineGlobalClass(&quot;Hash&quot;, typeof(IronRuby.Builtins.Hash), 0x00000003, Context.ObjectClass, LoadHash_Instance, LoadHash_Class, null, new IronRuby.Builtins.RubyModule[] {def34}, 
+            DefineGlobalClass(&quot;Hash&quot;, typeof(IronRuby.Builtins.Hash), 0x00000003, Context.ObjectClass, LoadHash_Instance, LoadHash_Class, null, new IronRuby.Builtins.RubyModule[] {def35}, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.Hash&gt;(IronRuby.Builtins.HashOps.CreateHash), 
                 new System.Func&lt;IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyClass, System.Object, IronRuby.Builtins.Hash&gt;(IronRuby.Builtins.HashOps.CreateHash), 
                 new System.Func&lt;IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyClass, IronRuby.Builtins.Hash&gt;(IronRuby.Builtins.HashOps.CreateHash)
             );
-            IronRuby.Builtins.RubyClass def45 = DefineGlobalClass(&quot;IO&quot;, typeof(IronRuby.Builtins.RubyIO), 0x00000003, Context.ObjectClass, LoadIO_Instance, LoadIO_Class, LoadIO_Constants, new IronRuby.Builtins.RubyModule[] {def25, def34}, 
-                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.CreateIO), 
-                new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.CreateIO)
+            IronRuby.Builtins.RubyClass def46 = DefineGlobalClass(&quot;IO&quot;, typeof(IronRuby.Builtins.RubyIO), 0x00000003, Context.ObjectClass, LoadIO_Instance, LoadIO_Class, LoadIO_Constants, new IronRuby.Builtins.RubyModule[] {def26, def35}, 
+                new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.Create), 
+                new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, System.Int32, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.Create)
             );
-            IronRuby.Builtins.RubyClass def28 = DefineClass(&quot;IronRuby::Clr::Name&quot;, typeof(IronRuby.Runtime.ClrName), 0x00000003, Context.ObjectClass, LoadIronRuby__Clr__Name_Instance, LoadIronRuby__Clr__Name_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyClass def29 = DefineClass(&quot;IronRuby::Clr::Scope&quot;, typeof(Microsoft.Scripting.Runtime.Scope), 0x00000003, Context.ObjectClass, LoadIronRuby__Clr__Scope_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyClass def29 = DefineClass(&quot;IronRuby::Clr::Name&quot;, typeof(IronRuby.Runtime.ClrName), 0x00000003, Context.ObjectClass, LoadIronRuby__Clr__Name_Instance, LoadIronRuby__Clr__Name_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyClass def30 = DefineClass(&quot;IronRuby::Clr::Scope&quot;, typeof(Microsoft.Scripting.Runtime.Scope), 0x00000003, Context.ObjectClass, LoadIronRuby__Clr__Scope_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
             DefineGlobalClass(&quot;MatchData&quot;, typeof(IronRuby.Builtins.MatchData), 0x00000003, Context.ObjectClass, LoadMatchData_Instance, LoadMatchData_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
             DefineGlobalClass(&quot;Method&quot;, typeof(IronRuby.Builtins.RubyMethod), 0x00000003, Context.ObjectClass, LoadMethod_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
             // Skipped primitive: Module
             Context.NilClass = DefineGlobalClass(&quot;NilClass&quot;, typeof(Microsoft.Scripting.Runtime.DynamicNull), 0x00000003, Context.ObjectClass, LoadNilClass_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyClass def39 = DefineGlobalClass(&quot;Numeric&quot;, typeof(IronRuby.Builtins.Numeric), 0x00000103, Context.ObjectClass, LoadNumeric_Instance, null, null, new IronRuby.Builtins.RubyModule[] {def43});
+            IronRuby.Builtins.RubyClass def40 = DefineGlobalClass(&quot;Numeric&quot;, typeof(IronRuby.Builtins.Numeric), 0x00000103, Context.ObjectClass, LoadNumeric_Instance, null, null, new IronRuby.Builtins.RubyModule[] {def44});
             DefineGlobalClass(&quot;Proc&quot;, typeof(IronRuby.Builtins.Proc), 0x00000003, Context.ObjectClass, LoadProc_Instance, LoadProc_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Action&lt;IronRuby.Builtins.RubyClass, System.Object[]&gt;(IronRuby.Builtins.ProcOps.Error)
             );
             #if !SILVERLIGHT &amp;&amp; !SILVERLIGHT
-            IronRuby.Builtins.RubyClass def27 = DefineClass(&quot;Process::Status&quot;, typeof(IronRuby.Builtins.RubyProcess.Status), 0x00000103, Context.ObjectClass, LoadProcess__Status_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyClass def28 = DefineClass(&quot;Process::Status&quot;, typeof(IronRuby.Builtins.RubyProcess.Status), 0x00000103, Context.ObjectClass, LoadProcess__Status_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
             #endif
-            DefineGlobalClass(&quot;Range&quot;, typeof(IronRuby.Builtins.Range), 0x00000003, Context.ObjectClass, LoadRange_Instance, null, null, new IronRuby.Builtins.RubyModule[] {def34}, 
+            DefineGlobalClass(&quot;Range&quot;, typeof(IronRuby.Builtins.Range), 0x00000003, Context.ObjectClass, LoadRange_Instance, null, null, new IronRuby.Builtins.RubyModule[] {def35}, 
                 new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Builtins.RubyClass, System.Object, System.Object, System.Boolean, IronRuby.Builtins.Range&gt;(IronRuby.Builtins.RangeOps.CreateRange)
             );
-            DefineGlobalClass(&quot;Regexp&quot;, typeof(IronRuby.Builtins.RubyRegex), 0x00000003, Context.ObjectClass, LoadRegexp_Instance, LoadRegexp_Class, LoadRegexp_Constants, new IronRuby.Builtins.RubyModule[] {def34}, 
+            DefineGlobalClass(&quot;Regexp&quot;, typeof(IronRuby.Builtins.RubyRegex), 0x00000003, Context.ObjectClass, LoadRegexp_Instance, LoadRegexp_Class, LoadRegexp_Constants, new IronRuby.Builtins.RubyModule[] {def35}, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.RubyRegex, IronRuby.Builtins.RubyRegex&gt;(IronRuby.Builtins.RegexpOps.Create), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.RubyRegex, System.Int32, System.Object, IronRuby.Builtins.RubyRegex&gt;(IronRuby.Builtins.RegexpOps.Create), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.RubyRegex, System.Object, System.Object, IronRuby.Builtins.RubyRegex&gt;(IronRuby.Builtins.RegexpOps.Create), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.Int32, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyRegex&gt;(IronRuby.Builtins.RegexpOps.Create), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.Boolean, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyRegex&gt;(IronRuby.Builtins.RegexpOps.Create)
             );
-            DefineGlobalClass(&quot;String&quot;, typeof(IronRuby.Builtins.MutableString), 0x00000003, Context.ObjectClass, LoadString_Instance, null, null, new IronRuby.Builtins.RubyModule[] {def34, def43}, 
+            DefineGlobalClass(&quot;String&quot;, typeof(IronRuby.Builtins.MutableString), 0x00000003, Context.ObjectClass, LoadString_Instance, null, null, new IronRuby.Builtins.RubyModule[] {def35, def44}, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.MutableStringOps.Create), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.MutableStringOps.Create)
             );
-            DefineGlobalClass(&quot;Struct&quot;, typeof(IronRuby.Builtins.RubyStruct), 0x00000003, Context.ObjectClass, LoadStruct_Instance, LoadStruct_Class, LoadStruct_Constants, new IronRuby.Builtins.RubyModule[] {def34}, 
+            DefineGlobalClass(&quot;Struct&quot;, typeof(IronRuby.Builtins.RubyStruct), 0x00000003, Context.ObjectClass, LoadStruct_Instance, LoadStruct_Class, LoadStruct_Constants, new IronRuby.Builtins.RubyModule[] {def35}, 
                 new System.Action&lt;IronRuby.Builtins.RubyClass, System.Object[]&gt;(IronRuby.Builtins.RubyStructOps.AllocatorUndefined)
             );
             DefineGlobalClass(&quot;Symbol&quot;, typeof(Microsoft.Scripting.SymbolId), 0x00000003, Context.ObjectClass, LoadSymbol_Instance, LoadSymbol_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
             DefineGlobalClass(&quot;Thread&quot;, typeof(System.Threading.Thread), 0x00000003, Context.ObjectClass, LoadThread_Instance, LoadThread_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
             DefineGlobalClass(&quot;ThreadGroup&quot;, typeof(IronRuby.Builtins.ThreadGroup), 0x00000103, Context.ObjectClass, LoadThreadGroup_Instance, null, LoadThreadGroup_Constants, IronRuby.Builtins.RubyModule.EmptyArray);
-            DefineGlobalClass(&quot;Time&quot;, typeof(System.DateTime), 0x00000003, Context.ObjectClass, LoadTime_Instance, LoadTime_Class, null, new IronRuby.Builtins.RubyModule[] {def43}, 
+            DefineGlobalClass(&quot;Time&quot;, typeof(System.DateTime), 0x00000003, Context.ObjectClass, LoadTime_Instance, LoadTime_Class, null, new IronRuby.Builtins.RubyModule[] {def44}, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.DateTime&gt;(IronRuby.Builtins.TimeOps.Create)
             );
             Context.TrueClass = DefineGlobalClass(&quot;TrueClass&quot;, typeof(IronRuby.Builtins.TrueClass), 0x00000103, Context.ObjectClass, LoadTrueClass_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
             DefineGlobalClass(&quot;UnboundMethod&quot;, typeof(IronRuby.Builtins.UnboundMethod), 0x00000103, Context.ObjectClass, LoadUnboundMethod_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
             // Skipped primitive: Class
-            IronRuby.Builtins.RubyClass def24 = DefineGlobalClass(&quot;File&quot;, typeof(IronRuby.Builtins.RubyFile), 0x00000003, def45, LoadFile_Instance, LoadFile_Class, LoadFile_Constants, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def25 = DefineGlobalClass(&quot;File&quot;, typeof(IronRuby.Builtins.RubyFile), 0x00000003, def46, LoadFile_Instance, LoadFile_Class, LoadFile_Constants, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Runtime.Union&lt;System.Int32, IronRuby.Builtins.MutableString&gt;, IronRuby.Builtins.MutableString, System.Int32, IronRuby.Builtins.RubyFile&gt;(IronRuby.Builtins.RubyFileOps.CreateFile), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Runtime.Union&lt;System.Int32, IronRuby.Builtins.MutableString&gt;, System.Int32, System.Int32, IronRuby.Builtins.RubyFile&gt;(IronRuby.Builtins.RubyFileOps.CreateFile), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyFile&gt;(IronRuby.Builtins.RubyFileOps.CreateFile), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyFile&gt;(IronRuby.Builtins.RubyFileOps.CreateFile), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.Int32, IronRuby.Builtins.RubyFile&gt;(IronRuby.Builtins.RubyFileOps.CreateFile)
             );
-            DefineGlobalClass(&quot;Float&quot;, typeof(System.Double), 0x00000003, def39, LoadFloat_Instance, LoadFloat_Class, LoadFloat_Constants, new IronRuby.Builtins.RubyModule[] {def40});
-            IronRuby.Builtins.RubyClass def46 = DefineGlobalClass(&quot;Integer&quot;, typeof(IronRuby.Builtins.Integer), 0x00000103, def39, LoadInteger_Instance, LoadInteger_Class, null, new IronRuby.Builtins.RubyModule[] {def40});
-            DefineGlobalClass(&quot;NoMemoryError&quot;, typeof(IronRuby.Builtins.NoMemoryError), 0x00000103, def44, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;Float&quot;, typeof(System.Double), 0x00000003, def40, LoadFloat_Instance, LoadFloat_Class, LoadFloat_Constants, new IronRuby.Builtins.RubyModule[] {def41});
+            IronRuby.Builtins.RubyClass def47 = DefineGlobalClass(&quot;Integer&quot;, typeof(IronRuby.Builtins.Integer), 0x00000103, def40, LoadInteger_Instance, LoadInteger_Class, null, new IronRuby.Builtins.RubyModule[] {def41});
+            DefineGlobalClass(&quot;NoMemoryError&quot;, typeof(IronRuby.Builtins.NoMemoryError), 0x00000103, def45, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__NoMemoryError));
-            IronRuby.Builtins.RubyClass def42 = DefineGlobalClass(&quot;ScriptError&quot;, typeof(IronRuby.Builtins.ScriptError), 0x00000003, def44, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def43 = DefineGlobalClass(&quot;ScriptError&quot;, typeof(IronRuby.Builtins.ScriptError), 0x00000003, def45, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__ScriptError));
-            IronRuby.Builtins.RubyClass def41 = DefineGlobalClass(&quot;SignalException&quot;, typeof(IronRuby.Builtins.SignalException), 0x00000103, def44, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def42 = DefineGlobalClass(&quot;SignalException&quot;, typeof(IronRuby.Builtins.SignalException), 0x00000103, def45, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__SignalException));
-            IronRuby.Builtins.RubyClass def35 = Context.StandardErrorClass = DefineGlobalClass(&quot;StandardError&quot;, typeof(System.SystemException), 0x00000003, def44, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def37 = Context.StandardErrorClass = DefineGlobalClass(&quot;StandardError&quot;, typeof(System.SystemException), 0x00000003, def45, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__StandardError));
-            ExtendClass(typeof(System.Single), def39, LoadSystem__Single_Instance, LoadSystem__Single_Class, null, new IronRuby.Builtins.RubyModule[] {def40}, 
+            ExtendClass(typeof(System.Single), def40, LoadSystem__Single_Instance, LoadSystem__Single_Class, null, new IronRuby.Builtins.RubyModule[] {def41}, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Double, System.Single&gt;(IronRuby.Builtins.SingleOps.Create)
             );
-            DefineGlobalClass(&quot;SystemExit&quot;, typeof(IronRuby.Builtins.SystemExit), 0x00000003, def44, LoadSystemExit_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;SystemExit&quot;, typeof(IronRuby.Builtins.SystemExit), 0x00000003, def45, LoadSystemExit_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, IronRuby.Builtins.SystemExit&gt;(IronRuby.Builtins.SystemExitOps.Factory), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, System.Object, IronRuby.Builtins.SystemExit&gt;(IronRuby.Builtins.SystemExitOps.Factory)
             );
-            DefineGlobalClass(&quot;ArgumentError&quot;, typeof(System.ArgumentException), 0x00000003, def35, LoadArgumentError_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;ArgumentError&quot;, typeof(System.ArgumentException), 0x00000003, def37, LoadArgumentError_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__ArgumentError));
-            DefineGlobalClass(&quot;Bignum&quot;, typeof(Microsoft.Scripting.Math.BigInteger), 0x00000003, def46, LoadBignum_Instance, LoadBignum_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            DefineGlobalClass(&quot;EncodingError&quot;, typeof(IronRuby.Builtins.EncodingError), 0x00000003, def35, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;Bignum&quot;, typeof(Microsoft.Scripting.Math.BigInteger), 0x00000003, def47, LoadBignum_Instance, LoadBignum_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            DefineGlobalClass(&quot;EncodingError&quot;, typeof(IronRuby.Builtins.EncodingError), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__EncodingError));
-            DefineGlobalClass(&quot;Fixnum&quot;, typeof(System.Int32), 0x00000003, def46, LoadFixnum_Instance, LoadFixnum_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            DefineGlobalClass(&quot;IndexError&quot;, typeof(System.IndexOutOfRangeException), 0x00000003, def35, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;Fixnum&quot;, typeof(System.Int32), 0x00000003, def47, LoadFixnum_Instance, LoadFixnum_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            DefineGlobalClass(&quot;IndexError&quot;, typeof(System.IndexOutOfRangeException), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__IndexError));
-            DefineGlobalClass(&quot;Interrupt&quot;, typeof(IronRuby.Builtins.Interrupt), 0x00000103, def41, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;Interrupt&quot;, typeof(IronRuby.Builtins.Interrupt), 0x00000103, def42, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__Interrupt));
-            IronRuby.Builtins.RubyClass def36 = DefineGlobalClass(&quot;IOError&quot;, typeof(System.IO.IOException), 0x00000003, def35, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def38 = DefineGlobalClass(&quot;IOError&quot;, typeof(System.IO.IOException), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__IOError));
-            DefineGlobalClass(&quot;LoadError&quot;, typeof(IronRuby.Builtins.LoadError), 0x00000003, def42, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;LoadError&quot;, typeof(IronRuby.Builtins.LoadError), 0x00000003, def43, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__LoadError));
-            DefineGlobalClass(&quot;LocalJumpError&quot;, typeof(IronRuby.Builtins.LocalJumpError), 0x00000003, def35, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;LocalJumpError&quot;, typeof(IronRuby.Builtins.LocalJumpError), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__LocalJumpError));
-            IronRuby.Builtins.RubyClass def47 = DefineGlobalClass(&quot;NameError&quot;, typeof(System.MemberAccessException), 0x00000003, def35, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def48 = DefineGlobalClass(&quot;NameError&quot;, typeof(System.MemberAccessException), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__NameError));
-            DefineGlobalClass(&quot;NotImplementedError&quot;, typeof(IronRuby.Builtins.NotImplementedError), 0x00000003, def42, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;NotImplementedError&quot;, typeof(IronRuby.Builtins.NotImplementedError), 0x00000003, def43, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__NotImplementedError));
-            IronRuby.Builtins.RubyClass def38 = DefineGlobalClass(&quot;RangeError&quot;, typeof(System.ArgumentOutOfRangeException), 0x00000003, def35, LoadRangeError_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def39 = DefineGlobalClass(&quot;RangeError&quot;, typeof(System.ArgumentOutOfRangeException), 0x00000003, def37, LoadRangeError_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__RangeError));
-            DefineGlobalClass(&quot;RegexpError&quot;, typeof(IronRuby.Builtins.RegexpError), 0x00000003, def35, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;RegexpError&quot;, typeof(IronRuby.Builtins.RegexpError), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__RegexpError));
-            DefineGlobalClass(&quot;RuntimeError&quot;, typeof(IronRuby.Builtins.RuntimeError), 0x00000103, def35, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;RuntimeError&quot;, typeof(IronRuby.Builtins.RuntimeError), 0x00000103, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__RuntimeError));
-            DefineGlobalClass(&quot;SecurityError&quot;, typeof(System.Security.SecurityException), 0x00000003, def35, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;SecurityError&quot;, typeof(System.Security.SecurityException), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__SecurityError));
-            DefineGlobalClass(&quot;SyntaxError&quot;, typeof(IronRuby.Builtins.SyntaxError), 0x00000003, def42, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;SyntaxError&quot;, typeof(IronRuby.Builtins.SyntaxError), 0x00000003, def43, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__SyntaxError));
-            ExtendClass(typeof(System.Byte), def46, LoadSystem__Byte_Instance, LoadSystem__Byte_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            ExtendClass(typeof(System.Byte), def47, LoadSystem__Byte_Instance, LoadSystem__Byte_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, System.Byte&gt;(IronRuby.Builtins.ByteOps.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, Microsoft.Scripting.Math.BigInteger, System.Byte&gt;(IronRuby.Builtins.ByteOps.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Double, System.Byte&gt;(IronRuby.Builtins.ByteOps.InducedFrom)
             );
-            ExtendClass(typeof(System.Int16), def46, LoadSystem__Int16_Instance, LoadSystem__Int16_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            ExtendClass(typeof(System.Int16), def47, LoadSystem__Int16_Instance, LoadSystem__Int16_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, System.Int16&gt;(IronRuby.Builtins.Int16Ops.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, Microsoft.Scripting.Math.BigInteger, System.Int16&gt;(IronRuby.Builtins.Int16Ops.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Double, System.Int16&gt;(IronRuby.Builtins.Int16Ops.InducedFrom)
             );
-            ExtendClass(typeof(System.Int64), def46, LoadSystem__Int64_Instance, LoadSystem__Int64_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            ExtendClass(typeof(System.Int64), def47, LoadSystem__Int64_Instance, LoadSystem__Int64_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, System.Int64&gt;(IronRuby.Builtins.Int64Ops.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, Microsoft.Scripting.Math.BigInteger, System.Int64&gt;(IronRuby.Builtins.Int64Ops.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Double, System.Int64&gt;(IronRuby.Builtins.Int64Ops.InducedFrom)
             );
-            ExtendClass(typeof(System.SByte), def46, LoadSystem__SByte_Instance, LoadSystem__SByte_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            ExtendClass(typeof(System.SByte), def47, LoadSystem__SByte_Instance, LoadSystem__SByte_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, System.SByte&gt;(IronRuby.Builtins.SByteOps.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, Microsoft.Scripting.Math.BigInteger, System.SByte&gt;(IronRuby.Builtins.SByteOps.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Double, System.SByte&gt;(IronRuby.Builtins.SByteOps.InducedFrom)
             );
-            ExtendClass(typeof(System.UInt16), def46, LoadSystem__UInt16_Instance, LoadSystem__UInt16_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            ExtendClass(typeof(System.UInt16), def47, LoadSystem__UInt16_Instance, LoadSystem__UInt16_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, System.UInt16&gt;(IronRuby.Builtins.UInt16Ops.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, Microsoft.Scripting.Math.BigInteger, System.UInt16&gt;(IronRuby.Builtins.UInt16Ops.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Double, System.UInt16&gt;(IronRuby.Builtins.UInt16Ops.InducedFrom)
             );
-            ExtendClass(typeof(System.UInt32), def46, LoadSystem__UInt32_Instance, LoadSystem__UInt32_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            ExtendClass(typeof(System.UInt32), def47, LoadSystem__UInt32_Instance, LoadSystem__UInt32_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, System.UInt32&gt;(IronRuby.Builtins.UInt32Ops.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, Microsoft.Scripting.Math.BigInteger, System.UInt32&gt;(IronRuby.Builtins.UInt32Ops.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Double, System.UInt32&gt;(IronRuby.Builtins.UInt32Ops.InducedFrom)
             );
-            ExtendClass(typeof(System.UInt64), def46, LoadSystem__UInt64_Instance, LoadSystem__UInt64_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            ExtendClass(typeof(System.UInt64), def47, LoadSystem__UInt64_Instance, LoadSystem__UInt64_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, System.UInt64&gt;(IronRuby.Builtins.UInt64Ops.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, Microsoft.Scripting.Math.BigInteger, System.UInt64&gt;(IronRuby.Builtins.UInt64Ops.InducedFrom), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Double, System.UInt64&gt;(IronRuby.Builtins.UInt64Ops.InducedFrom)
             );
-            IronRuby.Builtins.RubyClass def37 = DefineGlobalClass(&quot;SystemCallError&quot;, typeof(System.Runtime.InteropServices.ExternalException), 0x00000003, def35, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def36 = DefineGlobalClass(&quot;SystemCallError&quot;, typeof(System.Runtime.InteropServices.ExternalException), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.Runtime.InteropServices.ExternalException&gt;(IronRuby.Builtins.SystemCallErrorOps.Factory), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, System.Runtime.InteropServices.ExternalException&gt;(IronRuby.Builtins.SystemCallErrorOps.Factory)
             );
-            DefineGlobalClass(&quot;SystemStackError&quot;, typeof(IronRuby.Builtins.SystemStackError), 0x00000003, def35, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;SystemStackError&quot;, typeof(IronRuby.Builtins.SystemStackError), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__SystemStackError));
-            DefineGlobalClass(&quot;ThreadError&quot;, typeof(IronRuby.Builtins.ThreadError), 0x00000103, def35, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;ThreadError&quot;, typeof(IronRuby.Builtins.ThreadError), 0x00000103, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__ThreadError));
-            DefineGlobalClass(&quot;TypeError&quot;, typeof(System.InvalidOperationException), 0x00000003, def35, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;TypeError&quot;, typeof(System.InvalidOperationException), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__TypeError));
-            DefineGlobalClass(&quot;ZeroDivisionError&quot;, typeof(System.DivideByZeroException), 0x00000003, def35, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;ZeroDivisionError&quot;, typeof(System.DivideByZeroException), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__ZeroDivisionError));
-            DefineGlobalClass(&quot;EOFError&quot;, typeof(IronRuby.Builtins.EOFError), 0x00000103, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;EOFError&quot;, typeof(IronRuby.Builtins.EOFError), 0x00000103, def38, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__EOFError));
-            IronRuby.Builtins.RubyClass def33 = DefineClass(&quot;Errno::EACCES&quot;, typeof(System.UnauthorizedAccessException), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def34 = DefineClass(&quot;Errno::EACCES&quot;, typeof(System.UnauthorizedAccessException), 0x00000003, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.UnauthorizedAccessException&gt;(IronRuby.Builtins.Errno.UnauthorizedAccessExceptionOps.Create)
             );
-            IronRuby.Builtins.RubyClass def9 = DefineClass(&quot;Errno::EADDRINUSE&quot;, typeof(IronRuby.Builtins.Errno.AddressInUseError), 0x00000103, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyClass def10 = DefineClass(&quot;Errno::EBADF&quot;, typeof(IronRuby.Builtins.Errno.BadFileDescriptorError), 0x00000103, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyClass def11 = DefineClass(&quot;Errno::ECHILD&quot;, typeof(IronRuby.Builtins.Errno.ChildError), 0x00000103, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyClass def12 = DefineClass(&quot;Errno::ECONNABORTED&quot;, typeof(IronRuby.Builtins.Errno.ConnectionAbortError), 0x00000103, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyClass def13 = DefineClass(&quot;Errno::ECONNREFUSED&quot;, typeof(IronRuby.Builtins.Errno.ConnectionRefusedError), 0x00000103, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyClass def14 = DefineClass(&quot;Errno::ECONNRESET&quot;, typeof(IronRuby.Builtins.Errno.ConnectionResetError), 0x00000103, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyClass def15 = DefineClass(&quot;Errno::EDOM&quot;, typeof(IronRuby.Builtins.Errno.DomainError), 0x00000103, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyClass def19 = DefineClass(&quot;Errno::EEXIST&quot;, typeof(IronRuby.Builtins.ExistError), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def10 = DefineClass(&quot;Errno::EADDRINUSE&quot;, typeof(IronRuby.Builtins.Errno.AddressInUseError), 0x00000103, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyClass def3 = DefineClass(&quot;Errno::EBADF&quot;, typeof(IronRuby.Builtins.BadFileDescriptorError), 0x00000003, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.BadFileDescriptorError&gt;(IronRuby.Builtins.Errno.BadFileDescriptorErrorOps.Create)
+            );
+            IronRuby.Builtins.RubyClass def11 = DefineClass(&quot;Errno::ECHILD&quot;, typeof(IronRuby.Builtins.Errno.ChildError), 0x00000103, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyClass def12 = DefineClass(&quot;Errno::ECONNABORTED&quot;, typeof(IronRuby.Builtins.Errno.ConnectionAbortError), 0x00000103, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyClass def13 = DefineClass(&quot;Errno::ECONNREFUSED&quot;, typeof(IronRuby.Builtins.Errno.ConnectionRefusedError), 0x00000103, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyClass def14 = DefineClass(&quot;Errno::ECONNRESET&quot;, typeof(IronRuby.Builtins.Errno.ConnectionResetError), 0x00000103, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyClass def15 = DefineClass(&quot;Errno::EDOM&quot;, typeof(IronRuby.Builtins.Errno.DomainError), 0x00000103, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyClass def19 = DefineClass(&quot;Errno::EEXIST&quot;, typeof(IronRuby.Builtins.ExistError), 0x00000003, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.ExistError&gt;(IronRuby.Builtins.Errno.ExistErrorOps.Create)
             );
-            IronRuby.Builtins.RubyClass def21 = DefineClass(&quot;Errno::EINVAL&quot;, typeof(IronRuby.Builtins.InvalidError), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def21 = DefineClass(&quot;Errno::EINVAL&quot;, typeof(IronRuby.Builtins.InvalidError), 0x00000003, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.InvalidError&gt;(IronRuby.Builtins.Errno.InvalidErrorOps.Create)
             );
-            IronRuby.Builtins.RubyClass def31 = DefineClass(&quot;Errno::ENOENT&quot;, typeof(System.IO.FileNotFoundException), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def32 = DefineClass(&quot;Errno::ENOENT&quot;, typeof(System.IO.FileNotFoundException), 0x00000003, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.IO.FileNotFoundException&gt;(IronRuby.Builtins.Errno.FileNotFoundExceptionOps.Create)
             );
-            IronRuby.Builtins.RubyClass def17 = DefineClass(&quot;Errno::ENOTCONN&quot;, typeof(IronRuby.Builtins.Errno.NotConnectedError), 0x00000103, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyClass def30 = DefineClass(&quot;Errno::ENOTDIR&quot;, typeof(System.IO.DirectoryNotFoundException), 0x00000003, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def17 = DefineClass(&quot;Errno::ENOTCONN&quot;, typeof(IronRuby.Builtins.Errno.NotConnectedError), 0x00000103, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyClass def31 = DefineClass(&quot;Errno::ENOTDIR&quot;, typeof(System.IO.DirectoryNotFoundException), 0x00000003, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.IO.DirectoryNotFoundException&gt;(IronRuby.Builtins.Errno.DirectoryNotFoundExceptionOps.Create)
             );
-            IronRuby.Builtins.RubyClass def18 = DefineClass(&quot;Errno::EPIPE&quot;, typeof(IronRuby.Builtins.Errno.PipeError), 0x00000103, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyClass def16 = DefineClass(&quot;Errno::EXDEV&quot;, typeof(IronRuby.Builtins.Errno.ImproperLinkError), 0x00000103, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            DefineGlobalClass(&quot;ESPIPE&quot;, typeof(IronRuby.Builtins.InvalidSeekError), 0x00000103, def37, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            DefineGlobalClass(&quot;FloatDomainError&quot;, typeof(IronRuby.Builtins.FloatDomainError), 0x00000103, def38, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            IronRuby.Builtins.RubyClass def18 = DefineClass(&quot;Errno::EPIPE&quot;, typeof(IronRuby.Builtins.Errno.PipeError), 0x00000103, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyClass def16 = DefineClass(&quot;Errno::EXDEV&quot;, typeof(IronRuby.Builtins.Errno.ImproperLinkError), 0x00000103, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            DefineGlobalClass(&quot;ESPIPE&quot;, typeof(IronRuby.Builtins.InvalidSeekError), 0x00000103, def36, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            DefineGlobalClass(&quot;FloatDomainError&quot;, typeof(IronRuby.Builtins.FloatDomainError), 0x00000103, def39, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__FloatDomainError));
-            DefineGlobalClass(&quot;NoMethodError&quot;, typeof(System.MissingMethodException), 0x00000003, def47, LoadNoMethodError_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+            DefineGlobalClass(&quot;NoMethodError&quot;, typeof(System.MissingMethodException), 0x00000003, def48, LoadNoMethodError_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
             new System.Func&lt;IronRuby.Builtins.RubyClass, System.Object, System.Exception&gt;(BuiltinsLibraryInitializer.ExceptionFactory__NoMethodError));
-            def24.SetBuiltinConstant(&quot;Constants&quot;, def25);
-            def22.SetBuiltinConstant(&quot;Clr&quot;, def2);
-            def2.SetBuiltinConstant(&quot;BigInteger&quot;, def3);
-            def2.SetBuiltinConstant(&quot;FlagEnumeration&quot;, def20);
-            def2.SetBuiltinConstant(&quot;Float&quot;, def4);
-            def2.SetBuiltinConstant(&quot;Integer&quot;, def5);
-            def2.SetBuiltinConstant(&quot;MultiDimensionalArray&quot;, def23);
-            def2.SetBuiltinConstant(&quot;String&quot;, def6);
+            def25.SetBuiltinConstant(&quot;Constants&quot;, def26);
+            def22.SetBuiltinConstant(&quot;Clr&quot;, def4);
+            def4.SetBuiltinConstant(&quot;BigInteger&quot;, def5);
+            def4.SetBuiltinConstant(&quot;FlagEnumeration&quot;, def20);
+            def4.SetBuiltinConstant(&quot;Float&quot;, def6);
+            def4.SetBuiltinConstant(&quot;Integer&quot;, def7);
+            def4.SetBuiltinConstant(&quot;MultiDimensionalArray&quot;, def23);
+            def4.SetBuiltinConstant(&quot;String&quot;, def8);
+            def22.SetBuiltinConstant(&quot;Print&quot;, def24);
             #if !SILVERLIGHT
             Context.ObjectClass.SetBuiltinConstant(&quot;ARGF&quot;, def1);
             #endif
-            Context.ObjectClass.SetBuiltinConstant(&quot;ENV&quot;, def7);
+            Context.ObjectClass.SetBuiltinConstant(&quot;ENV&quot;, def9);
             #if !SILVERLIGHT
-            def24.SetBuiltinConstant(&quot;Stat&quot;, def32);
+            def25.SetBuiltinConstant(&quot;Stat&quot;, def33);
             #endif
-            def2.SetBuiltinConstant(&quot;Name&quot;, def28);
-            def2.SetBuiltinConstant(&quot;Scope&quot;, def29);
+            def4.SetBuiltinConstant(&quot;Name&quot;, def29);
+            def4.SetBuiltinConstant(&quot;Scope&quot;, def30);
             #if !SILVERLIGHT &amp;&amp; !SILVERLIGHT
-            def26.SetBuiltinConstant(&quot;Status&quot;, def27);
+            def27.SetBuiltinConstant(&quot;Status&quot;, def28);
             #endif
-            def8.SetBuiltinConstant(&quot;EACCES&quot;, def33);
-            def8.SetBuiltinConstant(&quot;EADDRINUSE&quot;, def9);
-            def8.SetBuiltinConstant(&quot;EBADF&quot;, def10);
-            def8.SetBuiltinConstant(&quot;ECHILD&quot;, def11);
-            def8.SetBuiltinConstant(&quot;ECONNABORTED&quot;, def12);
-            def8.SetBuiltinConstant(&quot;ECONNREFUSED&quot;, def13);
-            def8.SetBuiltinConstant(&quot;ECONNRESET&quot;, def14);
-            def8.SetBuiltinConstant(&quot;EDOM&quot;, def15);
-            def8.SetBuiltinConstant(&quot;EEXIST&quot;, def19);
-            def8.SetBuiltinConstant(&quot;EINVAL&quot;, def21);
-            def8.SetBuiltinConstant(&quot;ENOENT&quot;, def31);
-            def8.SetBuiltinConstant(&quot;ENOTCONN&quot;, def17);
-            def8.SetBuiltinConstant(&quot;ENOTDIR&quot;, def30);
-            def8.SetBuiltinConstant(&quot;EPIPE&quot;, def18);
-            def8.SetBuiltinConstant(&quot;EXDEV&quot;, def16);
+            def2.SetBuiltinConstant(&quot;EACCES&quot;, def34);
+            def2.SetBuiltinConstant(&quot;EADDRINUSE&quot;, def10);
+            def2.SetBuiltinConstant(&quot;EBADF&quot;, def3);
+            def2.SetBuiltinConstant(&quot;ECHILD&quot;, def11);
+            def2.SetBuiltinConstant(&quot;ECONNABORTED&quot;, def12);
+            def2.SetBuiltinConstant(&quot;ECONNREFUSED&quot;, def13);
+            def2.SetBuiltinConstant(&quot;ECONNRESET&quot;, def14);
+            def2.SetBuiltinConstant(&quot;EDOM&quot;, def15);
+            def2.SetBuiltinConstant(&quot;EEXIST&quot;, def19);
+            def2.SetBuiltinConstant(&quot;EINVAL&quot;, def21);
+            def2.SetBuiltinConstant(&quot;ENOENT&quot;, def32);
+            def2.SetBuiltinConstant(&quot;ENOTCONN&quot;, def17);
+            def2.SetBuiltinConstant(&quot;ENOTDIR&quot;, def31);
+            def2.SetBuiltinConstant(&quot;EPIPE&quot;, def18);
+            def2.SetBuiltinConstant(&quot;EXDEV&quot;, def16);
         }
         
         private static void Load__ClassSingleton_Instance(IronRuby.Builtins.RubyModule/*!*/ module) {
@@ -440,11 +445,11 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;sort&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyArray, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.ArrayOps.Sort)
+                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyArray, System.Object&gt;(IronRuby.Builtins.ArrayOps.Sort)
             );
             
             module.DefineLibraryMethod(&quot;sort!&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyArray, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.ArrayOps.SortInPlace)
+                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyArray, System.Object&gt;(IronRuby.Builtins.ArrayOps.SortInPlace)
             );
             
             module.DefineLibraryMethod(&quot;to_a&quot;, 0x51, 
@@ -712,7 +717,7 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;collect&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, System.Object, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.Enumerable.Map)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, System.Object, System.Object&gt;(IronRuby.Builtins.Enumerable.Map)
             );
             
             module.DefineLibraryMethod(&quot;detect&quot;, 0x51, 
@@ -732,15 +737,15 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;find_all&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, System.Object, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.Enumerable.Select)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, System.Object, System.Object&gt;(IronRuby.Builtins.Enumerable.Select)
             );
             
             module.DefineLibraryMethod(&quot;grep&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BlockParam, System.Object, System.Object, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.Enumerable.Grep)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BlockParam, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.Enumerable.Grep)
             );
             
             module.DefineLibraryMethod(&quot;include?&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object, System.Boolean&gt;(IronRuby.Builtins.Enumerable.Contains)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.Enumerable.Contains)
             );
             
             module.DefineLibraryMethod(&quot;inject&quot;, 0x51, 
@@ -748,7 +753,7 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;map&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, System.Object, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.Enumerable.Map)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, System.Object, System.Object&gt;(IronRuby.Builtins.Enumerable.Map)
             );
             
             module.DefineLibraryMethod(&quot;max&quot;, 0x51, 
@@ -756,7 +761,7 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;member?&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object, System.Boolean&gt;(IronRuby.Builtins.Enumerable.Contains)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.Enumerable.Contains)
             );
             
             module.DefineLibraryMethod(&quot;min&quot;, 0x51, 
@@ -764,15 +769,15 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;partition&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, System.Object, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.Enumerable.Partition)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, System.Object, System.Object&gt;(IronRuby.Builtins.Enumerable.Partition)
             );
             
             module.DefineLibraryMethod(&quot;reject&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, System.Object, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.Enumerable.Reject)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, System.Object, System.Object&gt;(IronRuby.Builtins.Enumerable.Reject)
             );
             
             module.DefineLibraryMethod(&quot;select&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, System.Object, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.Enumerable.Select)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, System.Object, System.Object&gt;(IronRuby.Builtins.Enumerable.Select)
             );
             
             module.DefineLibraryMethod(&quot;sort&quot;, 0x51, 
@@ -780,7 +785,7 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;sort_by&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BlockParam, System.Object, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.Enumerable.SortBy)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BlockParam, System.Object, System.Object&gt;(IronRuby.Builtins.Enumerable.SortBy)
             );
             
             module.DefineLibraryMethod(&quot;to_a&quot;, 0x51, 
@@ -788,7 +793,7 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;zip&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, IronRuby.Runtime.BlockParam, System.Object, System.Object[], IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.Enumerable.Zip)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, IronRuby.Runtime.BlockParam, System.Object, System.Object[], System.Object&gt;(IronRuby.Builtins.Enumerable.Zip)
             );
             
         }
@@ -1034,6 +1039,12 @@ namespace IronRuby.Builtins {
                 new System.Func&lt;IronRuby.Builtins.RubyFile, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.RubyFileOps.GetPath)
             );
             
+            #if !SILVERLIGHT
+            module.DefineLibraryMethod(&quot;truncate&quot;, 0x51, 
+                new System.Func&lt;IronRuby.Builtins.RubyFile, System.Int32, System.Int32&gt;(IronRuby.Builtins.RubyFileOps.Truncate)
+            );
+            
+            #endif
         }
         
         private static void LoadFile_Class(IronRuby.Builtins.RubyModule/*!*/ module) {
@@ -1126,6 +1137,12 @@ namespace IronRuby.Builtins {
             );
             
             #endif
+            #if !SILVERLIGHT
+            module.DefineLibraryMethod(&quot;truncate&quot;, 0x61, 
+                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.Int32, System.Int32&gt;(IronRuby.Builtins.RubyFileOps.Truncate)
+            );
+            
+            #endif
             module.DefineLibraryMethod(&quot;umask&quot;, 0x61, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, System.Int32&gt;(IronRuby.Builtins.RubyFileOps.GetUmask), 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32&gt;(IronRuby.Builtins.RubyFileOps.GetUmask)
@@ -1631,10 +1648,7 @@ namespace IronRuby.Builtins {
         }
         
         private static void LoadIO_Instance(IronRuby.Builtins.RubyModule/*!*/ module) {
-            module.DefineLibraryMethod(&quot;&lt;&lt;&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Builtins.RubyIO, System.Object, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.Output)
-            );
-            
+            LoadIronRuby__Print_Instance(module);
             module.DefineLibraryMethod(&quot;binmode&quot;, 0x51, 
                 new System.Func&lt;IronRuby.Builtins.RubyIO, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.Binmode)
             );
@@ -1656,8 +1670,8 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;each&quot;, 0x51, 
-                new System.Action&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.Each), 
-                new System.Func&lt;IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString, System.Object&gt;(IronRuby.Builtins.RubyIOOps.Each)
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyIO, System.Object&gt;(IronRuby.Builtins.RubyIOOps.Each), 
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString, System.Object&gt;(IronRuby.Builtins.RubyIOOps.Each)
             );
             
             module.DefineLibraryMethod(&quot;each_byte&quot;, 0x51, 
@@ -1665,8 +1679,8 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;each_line&quot;, 0x51, 
-                new System.Action&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.Each), 
-                new System.Func&lt;IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString, System.Object&gt;(IronRuby.Builtins.RubyIOOps.Each)
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyIO, System.Object&gt;(IronRuby.Builtins.RubyIOOps.Each), 
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString, System.Object&gt;(IronRuby.Builtins.RubyIOOps.Each)
             );
             
             module.DefineLibraryMethod(&quot;eof&quot;, 0x51, 
@@ -1708,24 +1722,33 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;initialize&quot;, 0x52, 
-                new System.Action&lt;IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.CreateIO), 
-                new System.Action&lt;IronRuby.Builtins.RubyIO, System.Int32, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.RubyIOOps.CreateIO)
+                new System.Func&lt;IronRuby.Builtins.RubyIO, System.Int32, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.Reinitialize), 
+                new System.Func&lt;IronRuby.Builtins.RubyIO, System.Int32, System.Int32, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.Reinitialize)
+            );
+            
+            module.DefineLibraryMethod(&quot;initialize_copy&quot;, 0x52, 
+                new System.Func&lt;IronRuby.Builtins.RubyIO, IronRuby.Builtins.RubyIO, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.InitializeCopy)
             );
             
             module.DefineLibraryMethod(&quot;internal_encoding&quot;, 0x51, 
                 new System.Func&lt;IronRuby.Builtins.RubyIO, IronRuby.Builtins.RubyEncoding&gt;(IronRuby.Builtins.RubyIOOps.GetInternalEncoding)
             );
             
+            module.DefineLibraryMethod(&quot;ioctl&quot;, 0x51, 
+                new System.Func&lt;IronRuby.Builtins.RubyIO, System.Int32, IronRuby.Builtins.MutableString, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.FileControl), 
+                new System.Func&lt;IronRuby.Builtins.RubyIO, System.Int32, System.Int32, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.FileControl)
+            );
+            
             module.DefineLibraryMethod(&quot;isatty&quot;, 0x51, 
                 new System.Func&lt;IronRuby.Builtins.RubyIO, System.Boolean&gt;(IronRuby.Builtins.RubyIOOps.IsAtty)
             );
             
             module.DefineLibraryMethod(&quot;lineno&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyIO, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.GetLineNo)
+                new System.Func&lt;IronRuby.Builtins.RubyIO, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.GetLineNumber)
             );
             
             module.DefineLibraryMethod(&quot;lineno=&quot;, 0x51, 
-                new System.Action&lt;IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyIO, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.SetLineNo)
+                new System.Action&lt;IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyIO, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.SetLineNumber)
             );
             
             module.DefineLibraryMethod(&quot;pid&quot;, 0x51, 
@@ -1737,36 +1760,19 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;pos=&quot;, 0x51, 
-                new System.Action&lt;IronRuby.Builtins.RubyIO, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.Pos)
-            );
-            
-            module.DefineLibraryMethod(&quot;print&quot;, 0x51, 
-                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyScope, System.Object&gt;(IronRuby.Builtins.RubyIOOps.Print), 
-                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object&gt;(IronRuby.Builtins.RubyIOOps.Print), 
-                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, System.Object, System.Object[]&gt;(IronRuby.Builtins.RubyIOOps.Print)
-            );
-            
-            module.DefineLibraryMethod(&quot;printf&quot;, 0x51, 
-                new System.Action&lt;IronRuby.Builtins.StringFormatterSiteStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.BinaryOpStorage, IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString, System.Object[]&gt;(IronRuby.Builtins.RubyIOOps.PrintFormatted)
-            );
-            
-            module.DefineLibraryMethod(&quot;putc&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.RubyIOOps.Putc), 
-                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Int32, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.Putc)
-            );
-            
-            module.DefineLibraryMethod(&quot;puts&quot;, 0x51, 
-                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object&gt;(IronRuby.Builtins.RubyIOOps.PutsEmptyLine), 
-                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.RubyIOOps.Puts), 
-                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, System.Object, System.Object&gt;(IronRuby.Builtins.RubyIOOps.Puts), 
-                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, System.Object, System.Object[]&gt;(IronRuby.Builtins.RubyIOOps.Puts)
+                new System.Action&lt;IronRuby.Builtins.RubyIO, IronRuby.Runtime.IntegerValue&gt;(IronRuby.Builtins.RubyIOOps.Pos)
             );
             
             module.DefineLibraryMethod(&quot;read&quot;, 0x51, 
                 new System.Func&lt;IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.RubyIOOps.Read), 
+                new System.Func&lt;IronRuby.Builtins.RubyIO, Microsoft.Scripting.Runtime.DynamicNull, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.RubyIOOps.Read), 
                 new System.Func&lt;IronRuby.Builtins.RubyIO, System.Int32, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.RubyIOOps.Read)
             );
             
+            module.DefineLibraryMethod(&quot;read_nonblock&quot;, 0x51, 
+                new System.Func&lt;IronRuby.Builtins.RubyIO, System.Int32, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.RubyIOOps.ReadNoBlock)
+            );
+            
             module.DefineLibraryMethod(&quot;readchar&quot;, 0x51, 
                 new System.Func&lt;IronRuby.Builtins.RubyIO, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.ReadChar)
             );
@@ -1781,13 +1787,18 @@ namespace IronRuby.Builtins {
                 new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.RubyIOOps.ReadLines)
             );
             
+            module.DefineLibraryMethod(&quot;reopen&quot;, 0x51, 
+                new System.Func&lt;IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.Reopen), 
+                new System.Func&lt;IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString, System.Int32, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.Reopen), 
+                new System.Func&lt;IronRuby.Builtins.RubyIO, IronRuby.Builtins.RubyIO, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.Reopen)
+            );
+            
             module.DefineLibraryMethod(&quot;rewind&quot;, 0x51, 
                 new System.Action&lt;IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.Rewind)
             );
             
             module.DefineLibraryMethod(&quot;seek&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Builtins.RubyIO, System.Int32, System.Int32, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.Seek), 
-                new System.Func&lt;IronRuby.Builtins.RubyIO, Microsoft.Scripting.Math.BigInteger, System.Int32, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.Seek)
+                new System.Func&lt;IronRuby.Builtins.RubyIO, IronRuby.Runtime.IntegerValue, System.Int32, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.Seek)
             );
             
             module.DefineLibraryMethod(&quot;sync&quot;, 0x51, 
@@ -1799,7 +1810,16 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;sysread&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Builtins.RubyIO, System.Int32, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.RubyIOOps.SystemRead)
+                new System.Func&lt;IronRuby.Builtins.RubyIO, System.Int32, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.RubyIOOps.SystemRead)
+            );
+            
+            module.DefineLibraryMethod(&quot;sysseek&quot;, 0x51, 
+                new System.Func&lt;IronRuby.Builtins.RubyIO, IronRuby.Runtime.IntegerValue, System.Int32, System.Object&gt;(IronRuby.Builtins.RubyIOOps.SysSeek)
+            );
+            
+            module.DefineLibraryMethod(&quot;syswrite&quot;, 0x51, 
+                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.SysWrite), 
+                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyIO, System.Object, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.SysWrite)
             );
             
             module.DefineLibraryMethod(&quot;tell&quot;, 0x51, 
@@ -1818,11 +1838,20 @@ namespace IronRuby.Builtins {
                 new System.Func&lt;IronRuby.Builtins.RubyIO, System.Boolean&gt;(IronRuby.Builtins.RubyIOOps.IsAtty)
             );
             
+            module.DefineLibraryMethod(&quot;ungetc&quot;, 0x51, 
+                new System.Action&lt;IronRuby.Builtins.RubyIO, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.SetPreviousByte)
+            );
+            
             module.DefineLibraryMethod(&quot;write&quot;, 0x51, 
                 new System.Func&lt;IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.Write), 
                 new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Builtins.RubyIO, System.Object, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.Write)
             );
             
+            module.DefineLibraryMethod(&quot;write_nonblock&quot;, 0x51, 
+                new System.Func&lt;IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.WriteNoBlock), 
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Builtins.RubyIO, System.Object, System.Int32&gt;(IronRuby.Builtins.RubyIOOps.WriteNoBlock)
+            );
+            
         }
         
         private static void LoadIO_Class(IronRuby.Builtins.RubyModule/*!*/ module) {
@@ -1836,6 +1865,12 @@ namespace IronRuby.Builtins {
             module.DefineRuleGenerator(&quot;open&quot;, 0x61, IronRuby.Builtins.RubyIOOps.Open());
             
             #if !SILVERLIGHT
+            module.DefineLibraryMethod(&quot;pipe&quot;, 0x61, 
+                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.RubyIOOps.OpenPipe)
+            );
+            
+            #endif
+            #if !SILVERLIGHT
             module.DefineLibraryMethod(&quot;popen&quot;, 0x61, 
                 new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, System.Object&gt;(IronRuby.Builtins.RubyIOOps.OpenPipe), 
                 new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyIO&gt;(IronRuby.Builtins.RubyIOOps.OpenPipe)
@@ -1843,8 +1878,7 @@ namespace IronRuby.Builtins {
             
             #endif
             module.DefineLibraryMethod(&quot;read&quot;, 0x61, 
-                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.RubyIOOps.ReadFile), 
-                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.Int32, System.Int32, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.RubyIOOps.Read)
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;System.Int32&gt;, IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.Object, System.Object, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.RubyIOOps.Read)
             );
             
             module.DefineLibraryMethod(&quot;readlines&quot;, 0x61, 
@@ -2473,6 +2507,12 @@ namespace IronRuby.Builtins {
                 new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RespondToStorage, System.String, System.Object, System.Object&gt;(IronRuby.Builtins.ClrString.Compare)
             );
             
+            module.DefineLibraryMethod(&quot;=~&quot;, 0x51, 
+                new System.Func&lt;IronRuby.Runtime.RubyScope, System.String, IronRuby.Builtins.RubyRegex, System.Object&gt;(IronRuby.Builtins.ClrString.Match), 
+                new System.Func&lt;System.String, System.String, System.Object&gt;(IronRuby.Builtins.ClrString.Match), 
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, IronRuby.Runtime.RubyScope, System.Object, System.String, System.Object&gt;&gt;, IronRuby.Runtime.RubyScope, System.String, System.Object, System.Object&gt;(IronRuby.Builtins.ClrString.Match)
+            );
+            
             module.DefineLibraryMethod(&quot;==&quot;, 0x51, 
                 new System.Func&lt;System.String, System.String, System.Boolean&gt;(IronRuby.Builtins.ClrString.StringEquals), 
                 new System.Func&lt;System.String, IronRuby.Builtins.MutableString, System.Boolean&gt;(IronRuby.Builtins.ClrString.StringEquals), 
@@ -2547,15 +2587,41 @@ namespace IronRuby.Builtins {
             
         }
         
+        private static void LoadIronRuby__Print_Instance(IronRuby.Builtins.RubyModule/*!*/ module) {
+            module.DefineLibraryMethod(&quot;&lt;&lt;&quot;, 0x51, 
+                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.PrintOps.Output)
+            );
+            
+            module.DefineLibraryMethod(&quot;print&quot;, 0x51, 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyScope, System.Object&gt;(IronRuby.Builtins.PrintOps.Print), 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object[]&gt;(IronRuby.Builtins.PrintOps.Print), 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object&gt;(IronRuby.Builtins.PrintOps.Print)
+            );
+            
+            module.DefineLibraryMethod(&quot;printf&quot;, 0x51, 
+                new System.Action&lt;IronRuby.Builtins.StringFormatterSiteStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.BinaryOpStorage, System.Object, IronRuby.Builtins.MutableString, System.Object[]&gt;(IronRuby.Builtins.PrintOps.PrintFormatted)
+            );
+            
+            module.DefineLibraryMethod(&quot;putc&quot;, 0x51, 
+                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.PrintOps.Putc), 
+                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Int32, System.Int32&gt;(IronRuby.Builtins.PrintOps.Putc)
+            );
+            
+            module.DefineLibraryMethod(&quot;puts&quot;, 0x51, 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object&gt;(IronRuby.Builtins.PrintOps.PutsEmptyLine), 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.PrintOps.Puts), 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, System.Object, System.Object&gt;(IronRuby.Builtins.PrintOps.Puts), 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, System.Object, System.Object[]&gt;(IronRuby.Builtins.PrintOps.Puts)
+            );
+            
+        }
+        
         private static void LoadKernel_Instance(IronRuby.Builtins.RubyModule/*!*/ module) {
             module.DefineLibraryMethod(&quot;__id__&quot;, 0x51, 
                 new System.Func&lt;IronRuby.Runtime.RubyContext, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.GetObjectId)
             );
             
             module.DefineLibraryMethod(&quot;__send__&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
-                new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.String, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
-                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, System.Object, System.String, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
                 new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.String, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
                 new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, System.Object, System.String, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
                 new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.String, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
@@ -2563,7 +2629,10 @@ namespace IronRuby.Builtins {
                 new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.String, System.Object, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
                 new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, System.Object, System.String, System.Object, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
                 new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.String, System.Object[], System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
-                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, System.Object, System.String, System.Object[], System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage)
+                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, System.Object, System.String, System.Object[], System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
+                new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
+                new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.String, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
+                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, System.Object, System.String, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage)
             );
             
             #if !SILVERLIGHT
@@ -2828,7 +2897,7 @@ namespace IronRuby.Builtins {
             module.DefineLibraryMethod(&quot;print&quot;, 0x52, 
                 new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyScope, System.Object&gt;(IronRuby.Builtins.KernelOps.Print), 
                 new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.Print), 
-                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, System.Object, System.Object[]&gt;(IronRuby.Builtins.KernelOps.Print)
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object[]&gt;(IronRuby.Builtins.KernelOps.Print)
             );
             
             module.DefineLibraryMethod(&quot;printf&quot;, 0x52, 
@@ -2859,9 +2928,9 @@ namespace IronRuby.Builtins {
             
             module.DefineLibraryMethod(&quot;puts&quot;, 0x52, 
                 new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object&gt;(IronRuby.Builtins.KernelOps.PutsEmptyLine), 
-                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.PutString), 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.PutString), 
                 new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.KernelOps.PutString), 
-                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, System.Object, System.Object[]&gt;(IronRuby.Builtins.KernelOps.PutString)
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, System.Object, System.Object[]&gt;(IronRuby.Builtins.KernelOps.PutString)
             );
             
             module.DefineLibraryMethod(&quot;raise&quot;, 0x52, 
@@ -2895,9 +2964,6 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;send&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
-                new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.String, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
-                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, System.Object, System.String, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
                 new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.String, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
                 new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, System.Object, System.String, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
                 new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.String, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
@@ -2905,7 +2971,10 @@ namespace IronRuby.Builtins {
                 new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.String, System.Object, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
                 new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, System.Object, System.String, System.Object, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
                 new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.String, System.Object[], System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
-                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, System.Object, System.String, System.Object[], System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage)
+                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, System.Object, System.String, System.Object[], System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
+                new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
+                new System.Func&lt;IronRuby.Runtime.RubyScope, System.Object, System.String, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage), 
+                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, System.Object, System.String, System.Object&gt;(IronRuby.Builtins.KernelOps.SendMessage)
             );
             
             module.DefineLibraryMethod(&quot;set_trace_func&quot;, 0x52, 
@@ -2931,7 +3000,7 @@ namespace IronRuby.Builtins {
             module.DefineLibraryMethod(&quot;sleep&quot;, 0x52, 
                 new System.Action&lt;System.Object&gt;(IronRuby.Builtins.KernelOps.Sleep), 
                 new System.Func&lt;System.Object, System.Int32, System.Int32&gt;(IronRuby.Builtins.KernelOps.Sleep), 
-                new System.Func&lt;System.Object, System.Double, System.Double&gt;(IronRuby.Builtins.KernelOps.Sleep)
+                new System.Func&lt;System.Object, System.Double, System.Int32&gt;(IronRuby.Builtins.KernelOps.Sleep)
             );
             
             module.DefineLibraryMethod(&quot;sprintf&quot;, 0x52, 
@@ -2981,8 +3050,8 @@ namespace IronRuby.Builtins {
             
             #if !SILVERLIGHT
             module.DefineLibraryMethod(&quot;trap&quot;, 0x52, 
-                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.Trap), 
-                new System.Func&lt;IronRuby.Runtime.RubyContext, System.Object, System.Object, IronRuby.Builtins.Proc, System.Object&gt;(IronRuby.Builtins.KernelOps.Trap)
+                new System.Func&lt;IronRuby.Runtime.RubyContext, System.Object, System.Object, IronRuby.Builtins.Proc, System.Object&gt;(IronRuby.Builtins.KernelOps.Trap), 
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.Trap)
             );
             
             #endif
@@ -3130,7 +3199,7 @@ namespace IronRuby.Builtins {
             module.DefineLibraryMethod(&quot;print&quot;, 0x61, 
                 new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyScope, System.Object&gt;(IronRuby.Builtins.KernelOps.Print), 
                 new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.Print), 
-                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, System.Object, System.Object[]&gt;(IronRuby.Builtins.KernelOps.Print)
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object[]&gt;(IronRuby.Builtins.KernelOps.Print)
             );
             
             module.DefineLibraryMethod(&quot;printf&quot;, 0x61, 
@@ -3149,9 +3218,9 @@ namespace IronRuby.Builtins {
             
             module.DefineLibraryMethod(&quot;puts&quot;, 0x61, 
                 new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object&gt;(IronRuby.Builtins.KernelOps.PutsEmptyLine), 
-                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.PutString), 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.PutString), 
                 new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.KernelOps.PutString), 
-                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, System.Object, System.Object[]&gt;(IronRuby.Builtins.KernelOps.PutString)
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, System.Object, System.Object[]&gt;(IronRuby.Builtins.KernelOps.PutString)
             );
             
             module.DefineLibraryMethod(&quot;raise&quot;, 0x61, 
@@ -3183,7 +3252,7 @@ namespace IronRuby.Builtins {
             module.DefineLibraryMethod(&quot;sleep&quot;, 0x61, 
                 new System.Action&lt;System.Object&gt;(IronRuby.Builtins.KernelOps.Sleep), 
                 new System.Func&lt;System.Object, System.Int32, System.Int32&gt;(IronRuby.Builtins.KernelOps.Sleep), 
-                new System.Func&lt;System.Object, System.Double, System.Double&gt;(IronRuby.Builtins.KernelOps.Sleep)
+                new System.Func&lt;System.Object, System.Double, System.Int32&gt;(IronRuby.Builtins.KernelOps.Sleep)
             );
             
             module.DefineLibraryMethod(&quot;sprintf&quot;, 0x61, 
@@ -3216,8 +3285,8 @@ namespace IronRuby.Builtins {
             
             #if !SILVERLIGHT
             module.DefineLibraryMethod(&quot;trap&quot;, 0x61, 
-                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.Trap), 
-                new System.Func&lt;IronRuby.Runtime.RubyContext, System.Object, System.Object, IronRuby.Builtins.Proc, System.Object&gt;(IronRuby.Builtins.KernelOps.Trap)
+                new System.Func&lt;IronRuby.Runtime.RubyContext, System.Object, System.Object, IronRuby.Builtins.Proc, System.Object&gt;(IronRuby.Builtins.KernelOps.Trap), 
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, System.Object, System.Object, System.Object&gt;(IronRuby.Builtins.KernelOps.Trap)
             );
             
             #endif
@@ -4589,9 +4658,9 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;gsub&quot;, 0x51, 
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyRegex, System.Object&gt;(IronRuby.Builtins.MutableStringOps.BlockReplaceAll), 
                 new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, System.Object&gt;(IronRuby.Builtins.MutableStringOps.BlockReplaceAll), 
-                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyRegex, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.MutableStringOps.ReplaceAll), 
-                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyRegex, System.Object&gt;(IronRuby.Builtins.MutableStringOps.BlockReplaceAll)
+                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyRegex, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.MutableStringOps.ReplaceAll)
             );
             
             module.DefineLibraryMethod(&quot;gsub!&quot;, 0x51, 
@@ -4752,9 +4821,9 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;sub&quot;, 0x51, 
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyRegex, System.Object&gt;(IronRuby.Builtins.MutableStringOps.BlockReplaceFirst), 
                 new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, System.Object&gt;(IronRuby.Builtins.MutableStringOps.BlockReplaceFirst), 
-                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyRegex, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.MutableStringOps.ReplaceFirst), 
-                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyRegex, System.Object&gt;(IronRuby.Builtins.MutableStringOps.BlockReplaceFirst)
+                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyRegex, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.Builtins.MutableStringOps.ReplaceFirst)
             );
             
             module.DefineLibraryMethod(&quot;sub!&quot;, 0x51, 
@@ -4903,7 +4972,7 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;select&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyStruct, IronRuby.Builtins.RubyArray&gt;(IronRuby.Builtins.RubyStructOps.Select)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyStruct, System.Object&gt;(IronRuby.Builtins.RubyStructOps.Select)
             );
             
             module.DefineLibraryMethod(&quot;size&quot;, 0x51, 
@@ -5314,7 +5383,7 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;flatten!&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, IronRuby.Builtins.RubyClass, System.Object&gt;&gt;, IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, System.Collections.IList, System.Collections.IList&gt;(IronRuby.Builtins.IListOps.FlattenInPlace)
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, System.Collections.IList, System.Collections.IList&gt;(IronRuby.Builtins.IListOps.FlattenInPlace)
             );
             
             module.DefineLibraryMethod(&quot;hash&quot;, 0x51, 
@@ -5424,11 +5493,11 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;sort&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, IronRuby.Builtins.RubyClass, System.Object&gt;&gt;, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BlockParam, System.Collections.IList, System.Collections.IList&gt;(IronRuby.Builtins.IListOps.Sort)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, IronRuby.Builtins.RubyClass, System.Object&gt;&gt;, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BlockParam, System.Collections.IList, System.Object&gt;(IronRuby.Builtins.IListOps.Sort)
             );
             
             module.DefineLibraryMethod(&quot;sort!&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BlockParam, System.Collections.IList, System.Collections.IList&gt;(IronRuby.Builtins.IListOps.SortInPlace)
+                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BlockParam, System.Collections.IList, System.Object&gt;(IronRuby.Builtins.IListOps.SortInPlace)
             );
             
             module.DefineLibraryMethod(&quot;to_a&quot;, 0x51, 
@@ -5465,7 +5534,7 @@ namespace IronRuby.Builtins {
             );
             
             module.DefineLibraryMethod(&quot;zip&quot;, 0x51, 
-                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, IronRuby.Runtime.BlockParam, System.Object, System.Collections.IList[], System.Collections.IList&gt;(IronRuby.Builtins.IListOps.Zip)
+                new System.Func&lt;IronRuby.Runtime.CallSiteStorage&lt;System.Func&lt;System.Runtime.CompilerServices.CallSite, System.Object, IronRuby.Builtins.Proc, System.Object&gt;&gt;, IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, IronRuby.Runtime.BlockParam, System.Object, System.Collections.IList[], System.Object&gt;(IronRuby.Builtins.IListOps.Zip)
             );
             
         }
@@ -6467,9 +6536,7 @@ namespace IronRuby.StandardLibrary.Sockets {
                 new System.Action&lt;IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyClass, System.Boolean&gt;(IronRuby.StandardLibrary.Sockets.RubyBasicSocket.SetDoNotReverseLookup)
             );
             
-            module.DefineLibraryMethod(&quot;for_fd&quot;, 0x21, 
-                new System.Func&lt;IronRuby.Builtins.RubyClass, System.Int32, IronRuby.StandardLibrary.Sockets.RubyBasicSocket&gt;(IronRuby.StandardLibrary.Sockets.RubyBasicSocket.ForFileDescriptor)
-            );
+            module.DefineRuleGenerator(&quot;for_fd&quot;, 0x21, IronRuby.StandardLibrary.Sockets.RubyBasicSocket.ForFileDescriptor());
             
         }
         #endif
@@ -6913,6 +6980,7 @@ namespace IronRuby.StandardLibrary.OpenSsl {
     public sealed class OpenSslLibraryInitializer : IronRuby.Builtins.LibraryInitializer {
         protected override void LoadModules() {
             IronRuby.Builtins.RubyClass classRef0 = GetClass(typeof(System.Object));
+            IronRuby.Builtins.RubyClass classRef1 = GetClass(typeof(System.Runtime.InteropServices.ExternalException));
             
             
             IronRuby.Builtins.RubyModule def1 = DefineGlobalModule(&quot;OpenSSL&quot;, typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl), 0x00000103, null, null, LoadOpenSSL_Constants, IronRuby.Builtins.RubyModule.EmptyArray);
@@ -6922,12 +6990,29 @@ namespace IronRuby.StandardLibrary.OpenSsl {
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest.CreateDigest)
             );
             IronRuby.Builtins.RubyClass def5 = DefineClass(&quot;OpenSSL::HMAC&quot;, typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.HMAC), 0x00000103, classRef0, null, LoadOpenSSL__HMAC_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
-            IronRuby.Builtins.RubyModule def6 = DefineModule(&quot;OpenSSL::Random&quot;, typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.RandomModule), 0x00000103, null, LoadOpenSSL__Random_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def6 = DefineModule(&quot;OpenSSL::PKey&quot;, typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.PKey), 0x00000103, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyClass def7 = DefineClass(&quot;OpenSSL::PKey::RSA&quot;, typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.PKey.RSA), 0x00000103, classRef0, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def8 = DefineModule(&quot;OpenSSL::Random&quot;, typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.RandomModule), 0x00000103, null, LoadOpenSSL__Random_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyModule def9 = DefineModule(&quot;OpenSSL::X509&quot;, typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509), 0x00000103, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
+            IronRuby.Builtins.RubyClass def10 = DefineClass(&quot;OpenSSL::X509::Certificate&quot;, typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate), 0x00000103, classRef0, LoadOpenSSL__X509__Certificate_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate.CreateCertificate), 
+                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate.CreateCertificate)
+            );
+            IronRuby.Builtins.RubyClass def12 = DefineClass(&quot;OpenSSL::X509::CertificateError&quot;, typeof(System.Security.Cryptography.CryptographicException), 0x00000003, classRef1, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray, 
+                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.Security.Cryptography.CryptographicException&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.CryptographicExceptionOps.Create)
+            );
+            IronRuby.Builtins.RubyClass def11 = DefineClass(&quot;OpenSSL::X509::Name&quot;, typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Name), 0x00000103, classRef0, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
             def1.SetConstant(&quot;BN&quot;, def2);
             def1.SetConstant(&quot;Digest&quot;, def3);
             def3.SetConstant(&quot;Digest&quot;, def4);
             def1.SetConstant(&quot;HMAC&quot;, def5);
-            def1.SetConstant(&quot;Random&quot;, def6);
+            def1.SetConstant(&quot;PKey&quot;, def6);
+            def6.SetConstant(&quot;RSA&quot;, def7);
+            def1.SetConstant(&quot;Random&quot;, def8);
+            def1.SetConstant(&quot;X509&quot;, def9);
+            def9.SetConstant(&quot;Certificate&quot;, def10);
+            def9.SetConstant(&quot;CertificateError&quot;, def12);
+            def9.SetConstant(&quot;Name&quot;, def11);
         }
         
         private static void LoadOpenSSL_Constants(IronRuby.Builtins.RubyModule/*!*/ module) {
@@ -6945,13 +7030,37 @@ namespace IronRuby.StandardLibrary.OpenSsl {
         }
         
         private static void LoadOpenSSL__Digest__Digest_Instance(IronRuby.Builtins.RubyModule/*!*/ module) {
+            module.DefineLibraryMethod(&quot;digest&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest.BlankDigest)
+            );
+            
+            module.DefineLibraryMethod(&quot;digest_size&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest, System.Int32&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest.Seed)
+            );
+            
+            module.DefineLibraryMethod(&quot;hexdigest&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest.BlankHexDigest)
+            );
+            
             module.DefineLibraryMethod(&quot;initialize&quot;, 0x12, 
                 new System.Func&lt;IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest, IronRuby.Builtins.MutableString, IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest.Initialize)
             );
             
+            module.DefineLibraryMethod(&quot;name&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest.Name)
+            );
+            
+            module.DefineLibraryMethod(&quot;reset&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest, IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest.Reset)
+            );
+            
         }
         
         private static void LoadOpenSSL__HMAC_Class(IronRuby.Builtins.RubyModule/*!*/ module) {
+            module.DefineLibraryMethod(&quot;digest&quot;, 0x21, 
+                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.HMAC.Digest)
+            );
+            
             module.DefineLibraryMethod(&quot;hexdigest&quot;, 0x21, 
                 new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.HMAC.HexDigest)
             );
@@ -6973,6 +7082,41 @@ namespace IronRuby.StandardLibrary.OpenSsl {
             
         }
         
+        private static void LoadOpenSSL__X509__Certificate_Instance(IronRuby.Builtins.RubyModule/*!*/ module) {
+            module.DefineLibraryMethod(&quot;initialize&quot;, 0x12, 
+                new System.Func&lt;IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate, IronRuby.Builtins.MutableString, IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate.Initialize)
+            );
+            
+            module.DefineLibraryMethod(&quot;inspect&quot;, 0x11, 
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate.ToString)
+            );
+            
+            module.DefineLibraryMethod(&quot;issuer&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate.Issuer)
+            );
+            
+            module.DefineLibraryMethod(&quot;public_key&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate.PublicKey)
+            );
+            
+            module.DefineLibraryMethod(&quot;serial&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate, System.Int32&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate.Serial)
+            );
+            
+            module.DefineLibraryMethod(&quot;subject&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate.Subject)
+            );
+            
+            module.DefineLibraryMethod(&quot;to_s&quot;, 0x11, 
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate.ToString)
+            );
+            
+            module.DefineLibraryMethod(&quot;version&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate, System.Int32&gt;(IronRuby.StandardLibrary.OpenSsl.OpenSsl.X509.Certificate.Version)
+            );
+            
+        }
+        
     }
 }
 
@@ -7391,21 +7535,197 @@ namespace IronRuby.StandardLibrary.Zlib {
 namespace IronRuby.StandardLibrary.StringIO {
     public sealed class StringIOLibraryInitializer : IronRuby.Builtins.LibraryInitializer {
         protected override void LoadModules() {
-            IronRuby.Builtins.RubyClass classRef0 = GetClass(typeof(IronRuby.Builtins.RubyIO));
+            IronRuby.Builtins.RubyModule moduleRef0 = GetModule(typeof(IronRuby.Builtins.Enumerable));
+            IronRuby.Builtins.RubyClass classRef0 = GetClass(typeof(System.Object));
             
             
-            DefineGlobalClass(&quot;StringIO&quot;, typeof(IronRuby.StandardLibrary.StringIO.StringIO), 0x00000103, classRef0, LoadStringIO_Instance, LoadStringIO_Class, null, IronRuby.Builtins.RubyModule.EmptyArray, 
-                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.CreateIO)
+            DefineGlobalClass(&quot;StringIO&quot;, typeof(IronRuby.StandardLibrary.StringIO.StringIO), 0x00000103, classRef0, LoadStringIO_Instance, LoadStringIO_Class, null, new IronRuby.Builtins.RubyModule[] {moduleRef0}, 
+                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Create), 
+                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Create), 
+                new System.Func&lt;IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, System.Int32, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Create)
             );
         }
         
         private static void LoadStringIO_Instance(IronRuby.Builtins.RubyModule/*!*/ module) {
+            module.DefineLibraryMethod(&quot;&lt;&lt;&quot;, 0x11, 
+                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Output)
+            );
+            
+            module.DefineLibraryMethod(&quot;binmode&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.SetBinaryMode)
+            );
+            
+            module.DefineLibraryMethod(&quot;close&quot;, 0x11, 
+                new System.Action&lt;IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Close)
+            );
+            
+            module.DefineLibraryMethod(&quot;close_read&quot;, 0x11, 
+                new System.Action&lt;IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.CloseRead)
+            );
+            
+            module.DefineLibraryMethod(&quot;close_write&quot;, 0x11, 
+                new System.Action&lt;IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.CloseWrite)
+            );
+            
+            module.DefineLibraryMethod(&quot;closed?&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Boolean&gt;(IronRuby.StandardLibrary.StringIO.StringIO.IsClosed)
+            );
+            
+            module.DefineLibraryMethod(&quot;closed_read?&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Boolean&gt;(IronRuby.StandardLibrary.StringIO.StringIO.IsClosedRead)
+            );
+            
+            module.DefineLibraryMethod(&quot;closed_write?&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Boolean&gt;(IronRuby.StandardLibrary.StringIO.StringIO.IsClosedWrite)
+            );
+            
+            module.DefineLibraryMethod(&quot;each&quot;, 0x11, 
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, IronRuby.StandardLibrary.StringIO.StringIO, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.EachLine), 
+                new System.Func&lt;IronRuby.Runtime.BlockParam, IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.EachLine)
+            );
+            
+            module.DefineLibraryMethod(&quot;each_byte&quot;, 0x11, 
+                new System.Func&lt;IronRuby.Runtime.BlockParam, IronRuby.StandardLibrary.StringIO.StringIO, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.EachByte)
+            );
+            
+            module.DefineLibraryMethod(&quot;each_line&quot;, 0x11, 
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, IronRuby.StandardLibrary.StringIO.StringIO, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.EachLine), 
+                new System.Func&lt;IronRuby.Runtime.BlockParam, IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.EachLine)
+            );
+            
+            module.DefineLibraryMethod(&quot;eof&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Boolean&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Eof)
+            );
+            
+            module.DefineLibraryMethod(&quot;eof?&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Boolean&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Eof)
+            );
+            
+            module.DefineLibraryMethod(&quot;fcntl&quot;, 0x11, 
+                new System.Action&lt;IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.FileControl)
+            );
+            
+            module.DefineLibraryMethod(&quot;fileno&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.GetDescriptor)
+            );
+            
+            module.DefineLibraryMethod(&quot;flush&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Flush)
+            );
+            
+            module.DefineLibraryMethod(&quot;fsync&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.FSync)
+            );
+            
+            module.DefineLibraryMethod(&quot;getc&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.GetByte)
+            );
+            
+            module.DefineLibraryMethod(&quot;gets&quot;, 0x11, 
+                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Gets), 
+                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Gets)
+            );
+            
+            module.DefineLibraryMethod(&quot;initialize&quot;, 0x12, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Reinitialize), 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Reinitialize), 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, System.Int32, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Reinitialize)
+            );
+            
+            module.DefineLibraryMethod(&quot;initialize_copy&quot;, 0x12, 
+                new System.Func&lt;IronRuby.Runtime.RespondToStorage, IronRuby.Runtime.UnaryOpStorage, IronRuby.StandardLibrary.StringIO.StringIO, System.Object, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Reopen), 
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Reopen)
+            );
+            
+            module.DefineLibraryMethod(&quot;isatty&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Boolean&gt;(IronRuby.StandardLibrary.StringIO.StringIO.IsConsole)
+            );
+            
             module.DefineLibraryMethod(&quot;length&quot;, 0x11, 
                 new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.GetLength)
             );
             
+            module.DefineLibraryMethod(&quot;lineno&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.GetLineNo)
+            );
+            
+            module.DefineLibraryMethod(&quot;lineno=&quot;, 0x11, 
+                new System.Action&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.SetLineNo)
+            );
+            
             module.DefineLibraryMethod(&quot;path&quot;, 0x11, 
-                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.GetPath)
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.GetDescriptor)
+            );
+            
+            module.DefineLibraryMethod(&quot;pid&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.GetDescriptor)
+            );
+            
+            module.DefineLibraryMethod(&quot;pos&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.GetPosition)
+            );
+            
+            module.DefineLibraryMethod(&quot;pos=&quot;, 0x11, 
+                new System.Action&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Pos)
+            );
+            
+            module.DefineLibraryMethod(&quot;print&quot;, 0x11, 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyScope, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Print), 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object[]&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Print), 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Print)
+            );
+            
+            module.DefineLibraryMethod(&quot;printf&quot;, 0x11, 
+                new System.Action&lt;IronRuby.Builtins.StringFormatterSiteStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.BinaryOpStorage, IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, System.Object[]&gt;(IronRuby.StandardLibrary.StringIO.StringIO.PrintFormatted)
+            );
+            
+            module.DefineLibraryMethod(&quot;putc&quot;, 0x11, 
+                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Putc), 
+                new System.Func&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, System.Int32, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Putc)
+            );
+            
+            module.DefineLibraryMethod(&quot;puts&quot;, 0x11, 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.PutsEmptyLine), 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, System.Object, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Puts), 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, System.Object, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Puts), 
+                new System.Action&lt;IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.Runtime.ConversionStorage&lt;System.Collections.IList&gt;, System.Object, System.Object[]&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Puts)
+            );
+            
+            module.DefineLibraryMethod(&quot;read&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, Microsoft.Scripting.Runtime.DynamicNull, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Read), 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, Microsoft.Scripting.Runtime.DynamicNull, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Read), 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Read)
+            );
+            
+            module.DefineLibraryMethod(&quot;readchar&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.ReadChar)
+            );
+            
+            module.DefineLibraryMethod(&quot;readline&quot;, 0x11, 
+                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.StringIO.StringIO.ReadLine), 
+                new System.Func&lt;IronRuby.Runtime.RubyScope, IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.StringIO.StringIO.ReadLine)
+            );
+            
+            module.DefineLibraryMethod(&quot;readlines&quot;, 0x11, 
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.RubyArray&gt;(IronRuby.StandardLibrary.StringIO.StringIO.ReadLines), 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyArray&gt;(IronRuby.StandardLibrary.StringIO.StringIO.ReadLines)
+            );
+            
+            module.DefineLibraryMethod(&quot;reopen&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Reopen), 
+                new System.Func&lt;IronRuby.Runtime.RespondToStorage, IronRuby.Runtime.UnaryOpStorage, IronRuby.StandardLibrary.StringIO.StringIO, System.Object, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Reopen), 
+                new System.Func&lt;IronRuby.Runtime.RubyContext, IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Reopen), 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Reopen), 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Reopen), 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, System.Int32, IronRuby.StandardLibrary.StringIO.StringIO&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Reopen)
+            );
+            
+            module.DefineLibraryMethod(&quot;rewind&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Rewind)
+            );
+            
+            module.DefineLibraryMethod(&quot;seek&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32, System.Int32, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Seek)
             );
             
             module.DefineLibraryMethod(&quot;size&quot;, 0x11, 
@@ -7420,20 +7740,50 @@ namespace IronRuby.StandardLibrary.StringIO {
                 new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.StringIO.StringIO.SetString)
             );
             
+            module.DefineLibraryMethod(&quot;sync&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Boolean&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Sync)
+            );
+            
+            module.DefineLibraryMethod(&quot;sync=&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Boolean, System.Boolean&gt;(IronRuby.StandardLibrary.StringIO.StringIO.SetSync)
+            );
+            
+            module.DefineLibraryMethod(&quot;sysread&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, Microsoft.Scripting.Runtime.DynamicNull, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.StringIO.StringIO.SystemRead), 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, Microsoft.Scripting.Runtime.DynamicNull, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.StringIO.StringIO.SystemRead), 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString&gt;(IronRuby.StandardLibrary.StringIO.StringIO.SystemRead)
+            );
+            
+            module.DefineLibraryMethod(&quot;syswrite&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Write), 
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.StandardLibrary.StringIO.StringIO, System.Object, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Write)
+            );
+            
+            module.DefineLibraryMethod(&quot;tell&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.GetPosition)
+            );
+            
             module.DefineLibraryMethod(&quot;truncate&quot;, 0x11, 
-                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.SetLength)
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;System.Int32&gt;, IronRuby.StandardLibrary.StringIO.StringIO, System.Object, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.SetLength)
+            );
+            
+            module.DefineLibraryMethod(&quot;tty?&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Boolean&gt;(IronRuby.StandardLibrary.StringIO.StringIO.IsConsole)
             );
             
             module.DefineLibraryMethod(&quot;ungetc&quot;, 0x11, 
-                new System.Action&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.UnGetCharacter)
+                new System.Action&lt;IronRuby.StandardLibrary.StringIO.StringIO, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.SetPreviousByte)
+            );
+            
+            module.DefineLibraryMethod(&quot;write&quot;, 0x11, 
+                new System.Func&lt;IronRuby.StandardLibrary.StringIO.StringIO, IronRuby.Builtins.MutableString, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Write), 
+                new System.Func&lt;IronRuby.Runtime.ConversionStorage&lt;IronRuby.Builtins.MutableString&gt;, IronRuby.StandardLibrary.StringIO.StringIO, System.Object, System.Int32&gt;(IronRuby.StandardLibrary.StringIO.StringIO.Write)
             );
             
         }
         
         private static void LoadStringIO_Class(IronRuby.Builtins.RubyModule/*!*/ module) {
-            module.DefineLibraryMethod(&quot;open&quot;, 0x21, 
-                new System.Func&lt;IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, System.Object&gt;(IronRuby.StandardLibrary.StringIO.StringIO.OpenIO)
-            );
+            module.DefineRuleGenerator(&quot;open&quot;, 0x21, IronRuby.StandardLibrary.StringIO.StringIO.Open());
             
         }
         
@@ -8190,3 +8540,23 @@ namespace IronRuby.StandardLibrary.ParseTree {
     }
 }
 
+namespace IronRuby.StandardLibrary.Open3 {
+    public sealed class Open3LibraryInitializer : IronRuby.Builtins.LibraryInitializer {
+        protected override void LoadModules() {
+            
+            
+            DefineGlobalModule(&quot;Open3&quot;, typeof(IronRuby.StandardLibrary.Open3.Open3), 0x00000103, null, LoadOpen3_Class, null, IronRuby.Builtins.RubyModule.EmptyArray);
+        }
+        
+        private static void LoadOpen3_Class(IronRuby.Builtins.RubyModule/*!*/ module) {
+            #if !SILVERLIGHT
+            module.DefineLibraryMethod(&quot;popen3&quot;, 0x21, 
+                new System.Func&lt;IronRuby.Runtime.RubyContext, System.Object, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyArray&gt;(IronRuby.StandardLibrary.Open3.Open3.OpenPipe)
+            );
+            
+            #endif
+        }
+        
+    }
+}
+</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs</filename>
    </modified>
    <modified>
      <diff></diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby.Libraries.Build.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{77323B06-15A2-4CF4-8A7A-86EAA2B66498}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Library&lt;/OutputType&gt;
@@ -86,6 +85,7 @@
     &lt;Compile Include=&quot;Builtins\FileTest.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\FixnumOps.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\FloatOps.cs&quot; /&gt;
+    &lt;Compile Include=&quot;Builtins\PrintOps.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\RubyGC.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\HashOps.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\Integer.cs&quot; /&gt;
@@ -103,6 +103,7 @@
     &lt;Compile Include=&quot;Builtins\Numeric.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\ObjectOps.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\Precision.cs&quot; /&gt;
+    &lt;Compile Include=&quot;Builtins\RubyPipe.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\RubyProcess.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\ProcOps.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\RangeOps.cs&quot; /&gt;
@@ -142,6 +143,7 @@
     &lt;Compile Include=&quot;FileControl\Fcntl.cs&quot; /&gt;
     &lt;Compile Include=&quot;Iconv\Iconv.cs&quot; /&gt;
     &lt;Compile Include=&quot;Initializers.Generated.cs&quot; /&gt;
+    &lt;Compile Include=&quot;Open3\Open3.cs&quot; /&gt;
     &lt;Compile Include=&quot;OpenSSL\OpenSSL.cs&quot; /&gt;
     &lt;Compile Include=&quot;ParseTree\IronRubyParseTreeOps.cs&quot; /&gt;
     &lt;Compile Include=&quot;Properties\AssemblyInfo.cs&quot; /&gt;
@@ -197,4 +199,4 @@
   &lt;/Target&gt;
   &lt;Target Name=&quot;AfterBuild&quot;&gt;
   &lt;/Target&gt;
-&lt;/Project&gt;
+&lt;/Project&gt;
\ No newline at end of file</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby.Libraries.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -21,50 +21,52 @@ using Microsoft.Scripting.Math;
 using Microsoft.Scripting.Runtime;
 using Crypto = System.Security.Cryptography;
 using System.Text;
+using System.Security.Cryptography.X509Certificates;
+using System.Security.Cryptography;
 
 namespace IronRuby.StandardLibrary.OpenSsl {
 
-    [RubyModule(&quot;OpenSSL&quot;)]
-    public static class OpenSsl {
-        // TODO: constants
-        // Config,HMACError,PKCS12,Random,OPENSSL_VERSION,PKCS7,BN,ConfigError,PKey,Engine,BNError,Netscape,OCSP
-        // OpenSSLError,CipherError,SSL,VERSION,X509,ASN1,OPENSSL_VERSION_NUMBER,Cipher
+  [RubyModule(&quot;OpenSSL&quot;)]
+  public static class OpenSsl {
+    // TODO: constants
+    // Config,HMACError,PKCS12,Random,OPENSSL_VERSION,PKCS7,BN,ConfigError,PKey,Engine,BNError,Netscape,OCSP
+    // OpenSSLError,CipherError,SSL,VERSION,X509,ASN1,OPENSSL_VERSION_NUMBER,Cipher
 
-        [RubyConstant]
-        public const string OPENSSL_VERSION = &quot;OpenSSL 0.9.8d 28 Sep 2006&quot;;
+    [RubyConstant]
+    public const string OPENSSL_VERSION = &quot;OpenSSL 0.9.8d 28 Sep 2006&quot;;
 
-        [RubyConstant]
-        public const double OPENSSL_VERSION_NUMBER = 9470031;
+    [RubyConstant]
+    public const double OPENSSL_VERSION_NUMBER = 9470031;
 
-        [RubyConstant]
-        public const string VERSION = &quot;1.0.0&quot;;
+    [RubyConstant]
+    public const string VERSION = &quot;1.0.0&quot;;
 
-        [RubyModule(&quot;Digest&quot;)]
-        public static class DigestFactory {
+    [RubyModule(&quot;Digest&quot;)]
+    public static class DigestFactory {
 
-            // TODO: constants:
-            // SHA224,MDC2,DSS1,SHA512,SHA1,MD5,DSS,SHA384,SHA,MD4,SHA256,DigestError,RIPEMD160,MD2
+      // TODO: constants:
+      // SHA224,MDC2,DSS1,SHA512,SHA1,MD5,DSS,SHA384,SHA,MD4,SHA256,DigestError,RIPEMD160,MD2
 
-            [RubyClass(&quot;Digest&quot;)]
-            public class Digest {
-                private Crypto.HMAC _algorithm;
+      [RubyClass(&quot;Digest&quot;)]
+      public class Digest {
+        private Crypto.HMAC _algorithm;
 
-                public Crypto.HMAC Algorithm {
-                    get { return _algorithm; }
-                }
+        public Crypto.HMAC Algorithm {
+          get { return _algorithm; }
+        }
 
-                protected Digest() {
-                }
+        protected Digest() {
+        }
 
-                [RubyConstructor]
-                public static Digest/*!*/ CreateDigest(RubyClass/*!*/ self, [NotNull]MutableString/*!*/ algorithmName) {
-                    return Initialize(new Digest(), algorithmName);
-                }
-                
-                // Reinitialization. Not called when a factory/non-default ctor is called.
-                [RubyMethod(&quot;initialize&quot;, RubyMethodAttributes.PrivateInstance)]
-                public static Digest/*!*/ Initialize(Digest/*!*/ self, [NotNull]MutableString/*!*/ algorithmName) {
-                    Crypto.HMAC algorithm;
+        [RubyConstructor]
+        public static Digest/*!*/ CreateDigest(RubyClass/*!*/ self, [NotNull]MutableString/*!*/ algorithmName) {
+          return Initialize(new Digest(), algorithmName);
+        }
+
+        // Reinitialization. Not called when a factory/non-default ctor is called.
+        [RubyMethod(&quot;initialize&quot;, RubyMethodAttributes.PrivateInstance)]
+        public static Digest/*!*/ Initialize(Digest/*!*/ self, [NotNull]MutableString/*!*/ algorithmName) {
+          Crypto.HMAC algorithm;
 
 #if SILVERLIGHT
                     switch (algorithmName.ToString()) {
@@ -73,89 +75,363 @@ namespace IronRuby.StandardLibrary.OpenSsl {
                         default: algorithm = null; break;
                     }
 #else
-                    algorithm = Crypto.HMAC.Create(&quot;HMAC&quot; + algorithmName.ConvertToString());
+          algorithm = Crypto.HMAC.Create(&quot;HMAC&quot; + algorithmName.ConvertToString());
 #endif
 
-                    if (algorithm == null) {
-                        throw new RuntimeError(String.Format(&quot;Unsupported digest algorithm ({0}).&quot;, algorithmName));
-                    }
+          if (algorithm == null) {
+            throw new RuntimeError(String.Format(&quot;Unsupported digest algorithm ({0}).&quot;, algorithmName));
+          }
 
-                    self._algorithm = algorithm;
-                    return self;
-                }
-            }
+          self._algorithm = algorithm;
+          return self;
         }
 
-        [RubyClass(&quot;HMAC&quot;)]
-        public class HMAC {
-            [RubyMethod(&quot;hexdigest&quot;, RubyMethodAttributes.PublicSingleton)]
-            public static MutableString/*!*/ HexDigest(RubyClass/*!*/ self, [NotNull]DigestFactory.Digest/*!*/ digest,
-                [NotNull]MutableString/*!*/ key, [NotNull]MutableString/*!*/ data) {
-                
-                // TODO: does MRI really modify the digest object?
-                digest.Algorithm.Key = key.ConvertToBytes();
-                byte[] hash = digest.Algorithm.ComputeHash(data.ConvertToBytes());
+        // new(string) -&gt; digest
 
-                return MutableString.Create(BitConverter.ToString(hash).Replace(&quot;-&quot;, &quot;&quot;).ToLower());
-            }
+        [RubyMethod(&quot;reset&quot;)]
+        public static Digest/*!*/ Reset(Digest/*!*/ self) {
+          self._algorithm.Clear();
+          return self;
         }
 
-        [RubyModule(&quot;Random&quot;)]
-        public static class RandomModule {
+        // update(string) -&gt; aString
+        // finish -&gt; aString
 
-            // This is a no-op method since our random number generator uses the .NET crypto random number generator
-            // that gets its seed values from the OS
+        [RubyMethod(&quot;name&quot;)]
+        public static MutableString/*!*/ Name(Digest/*!*/ self) {
+          return MutableString.CreateAscii(self._algorithm.HashName);
+        }
 
-            [RubyMethod(&quot;seed&quot;, RubyMethodAttributes.PublicSingleton)]
-            public static MutableString/*!*/ Seed(RubyModule/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ seed) {
-                return seed;
-            }
+        [RubyMethod(&quot;digest_size&quot;)]
+        public static int Seed(Digest/*!*/ self) {
+          return self._algorithm.OutputBlockSize;
+        }
+
+        //TODO: Properly disable this with BuildConfig
+        [RubyMethod(&quot;digest&quot;)]
+        public static MutableString/*!*/ BlankDigest(Digest/*!*/ self) {
+#if !SILVERLIGHT
+          // TODO: This support only SHA1, It should use self._algorithm but It is not
+          byte[] blank_data = Encoding.UTF8.GetBytes(&quot;&quot;);
+          byte[] hash = new SHA1CryptoServiceProvider().ComputeHash(blank_data);
+          return MutableString.CreateBinary(hash);
+#else
+            throw new NotSupportedException();
+#endif
+        }
+
+        //TODO: Properly disable with BuildConfig
+        [RubyMethod(&quot;hexdigest&quot;)]
+        public static MutableString/*!*/ BlankHexDigest(Digest/*!*/ self) {
+#if !SILVERLIGHT
+          byte[] blank_data = Encoding.UTF8.GetBytes(&quot;&quot;);
+          byte[] hash = new SHA1CryptoServiceProvider().ComputeHash(blank_data);
+		  return MutableString.CreateAscii(BitConverter.ToString(hash).Replace(&quot;-&quot;, &quot;&quot;).ToLower());
+#else
+            throw new NotSupportedException();
+#endif
+        }
+      }
+    }
+
+    [RubyClass(&quot;HMAC&quot;)]
+    public class HMAC {
+
+      internal static byte[] Digest(DigestFactory.Digest digest, MutableString key, MutableString data) {
+        // TODO: does MRI really modify the digest object?
+        digest.Algorithm.Key = key.ConvertToBytes();
+        byte[] hash = digest.Algorithm.ComputeHash(data.ConvertToBytes());
+        return hash;
+      }
+
+      [RubyMethod(&quot;hexdigest&quot;, RubyMethodAttributes.PublicSingleton)]
+      public static MutableString/*!*/ HexDigest(RubyClass/*!*/ self,
+          [NotNull]DigestFactory.Digest/*!*/ digest,
+          [NotNull]MutableString/*!*/ key,
+          [NotNull]MutableString/*!*/ data) {
+
+        byte[] hash = Digest(digest, key, data);
+
+                // TODO (opt):
+                return MutableString.CreateAscii(BitConverter.ToString(hash).Replace(&quot;-&quot;, &quot;&quot;).ToLower());
+      }
+
+      [RubyMethod(&quot;digest&quot;, RubyMethodAttributes.PublicSingleton)]
+      public static MutableString/*!*/ Digest(RubyClass/*!*/ self,
+          [NotNull]DigestFactory.Digest/*!*/ digest,
+          [NotNull]MutableString/*!*/ key,
+          [NotNull]MutableString/*!*/ data) {
+
+        byte[] hash = Digest(digest, key, data);
+
+        return MutableString.CreateBinary(hash);
+      }
+
+      // HMAC.new(key, digest) -&gt; hmac
+      // update(string) -&gt; self
+      // digest -&gt; aString
+      // hexdigest -&gt; aString
+      // reset -&gt; self
+    }
+
+    [RubyModule(&quot;Random&quot;)]
+    public static class RandomModule {
+
+      // This is a no-op method since our random number generator uses the .NET crypto random number generator
+      // that gets its seed values from the OS
+
+      [RubyMethod(&quot;seed&quot;, RubyMethodAttributes.PublicSingleton)]
+      public static MutableString/*!*/ Seed(RubyModule/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ seed) {
+        return seed;
+      }
+
+      [RubyMethod(&quot;pseudo_bytes&quot;, RubyMethodAttributes.PublicSingleton)]
+      [RubyMethod(&quot;random_bytes&quot;, RubyMethodAttributes.PublicSingleton)]
+      public static MutableString/*!*/ RandomBytes(RubyModule/*!*/ self, [DefaultProtocol]int length) {
+        if (length &lt; 0) {
+          throw RubyExceptions.CreateArgumentError(&quot;negative string size&quot;);
+        }
+
+        if (length == 0) {
+                    return MutableString.CreateEmpty();
+        }
+
+        byte[] data = new byte[length];
+        var generator = new Crypto.RNGCryptoServiceProvider();
+        generator.GetBytes(data);
+
+        return MutableString.CreateBinary(data);
+      }
+
+      // add(str, entropy) -&gt; self
+      // load_random_file(filename) -&gt; true
+    }
+
+    [RubyClass(&quot;BN&quot;)]
+    public class BN {
+
+      // new =&gt; aBN
+      // new(bn) =&gt; aBN
+      // new(string) =&gt; aBN
+      // new(string, 0 | 2 | 10 | 16) =&gt; aBN
+
+      [RubyMethod(&quot;rand&quot;, RubyMethodAttributes.PublicSingleton)]
+      public static BigInteger/*!*/ Rand(RubyClass/*!*/ self, [DefaultProtocol]int bits, [DefaultProtocol, Optional]int someFlag, [Optional]bool otherFlag) { // TODO: figure out someFlag and otherFlag
+        byte[] data = new byte[bits &gt;&gt; 3];
+        var generator = new Crypto.RNGCryptoServiceProvider();
+        generator.GetBytes(data);
+
+        uint[] transformed = new uint[data.Length &gt;&gt; 2];
+        int j = 0;
+        for (int i = 0; i &lt; transformed.Length; ++i) {
+          transformed[i] = data[j] + (uint)(data[j + 1] &lt;&lt; 8) + (uint)(data[j + 2] &lt;&lt; 16) + (uint)(data[j + 3] &lt;&lt; 24);
+          j += 4;
+        }
+
+        return new BigInteger(1, transformed);
+      }
+    }
+
+    [RubyModule(&quot;X509&quot;)]
+    public static class X509 {
+
+      [RubyClass(&quot;CertificateError&quot;, Extends = typeof(CryptographicException), Inherits = typeof(ExternalException))]
+      public class CryptographicExceptionOps {
+        [RubyConstructor]
+        public static CryptographicException/*!*/ Create(RubyClass/*!*/ self, [DefaultProtocol, DefaultParameterValue(null)]MutableString message) {
+			  CryptographicException result = new CryptographicException(RubyExceptions.MakeMessage(ref message, &quot;Not enought data.&quot;));
+          RubyExceptionData.InitializeException(result, message);
+          return result;
+        }
+      }
+
+      // TODO: Constants
+
+      [RubyClass(&quot;Certificate&quot;)]
+      public class Certificate {
+        private X509Certificate/*!*/ _certificate;
+
+        [RubyConstructor]
+        public static Certificate/*!*/ CreateCertificate(RubyClass/*!*/ self) {
+          return Initialize(new Certificate(), null);
+        }
+
+        [RubyConstructor]
+        public static Certificate/*!*/ CreateCertificate(RubyClass/*!*/ self, MutableString/*!*/ data) {
+          return Initialize(new Certificate(), data);
+        }
+
+        [RubyMethod(&quot;initialize&quot;, RubyMethodAttributes.PrivateInstance)]
+        public static Certificate/*!*/ Initialize(Certificate/*!*/ self, MutableString/*!*/ data) {
+          if (data == null) {
+            self._certificate = new X509Certificate();
+          } else {
+            self._certificate = new X509Certificate(data.ToByteArray());
+          }
+
+          return self;
+        }
 
-            [RubyMethod(&quot;pseudo_bytes&quot;, RubyMethodAttributes.PublicSingleton)]
-            [RubyMethod(&quot;random_bytes&quot;, RubyMethodAttributes.PublicSingleton)]
-            public static MutableString/*!*/ RandomBytes(RubyModule/*!*/ self, [DefaultProtocol, NotNull]int/*!*/ length) {
-                if (length &lt; 0) {
-                    throw RubyExceptions.CreateArgumentError(&quot;negative string size&quot;);
-                }
+        // add_extension
+        // check_private_key
+        // extensions
+        // extensions=
 
-                if (length == 0) {
-                    return MutableString.Create(&quot;&quot;);
-                }
+        private static string OpenSSLFormat(string x509String) {
+          string[] pairs = x509String.Split(',');
+          Array.Sort&lt;string&gt;(pairs);
 
-                byte[] data = new byte[length];
-                var generator = new Crypto.RNGCryptoServiceProvider();
-                generator.GetBytes(data);
+          StringBuilder sb = new StringBuilder();
+          foreach (var val in pairs) {
+            sb.AppendFormat(&quot;/{0}&quot;, val.Trim());
+          }
 
-                return MutableString.CreateBinary(data);
+          return sb.ToString();
+        }
+
+        // issuer=
+
+        [RubyMethod(&quot;issuer&quot;)]
+        public static MutableString Issuer(Certificate/*!*/ self) {
+          if (self._certificate.Handle == IntPtr.Zero) {
+            return null;
+          } else {
+			  return MutableString.CreateAscii(OpenSSLFormat(self._certificate.Issuer));
+          }
+        }
+
+        // not_after =&gt; time
+        // not_after=
+        // not_before =&gt; time
+        // not_before=
+
+        [RubyMethod(&quot;public_key&quot;)]
+        public static MutableString PublicKey(Certificate/*!*/ self) {
+          if (self._certificate.Handle == IntPtr.Zero) {
+            // TODO: Raise OpenSSL::X509::CertificateError
+            return MutableString.CreateEmpty();
+          } else {
+			  return MutableString.CreateAscii(self._certificate.GetPublicKeyString());
+          }
+        }
+        // public_key=
+
+        private int SerailNumber {
+          get {
+            if (_certificate.Handle == IntPtr.Zero) {
+              return 0;
+            } else {
+              return int.Parse(_certificate.GetSerialNumberString());
             }
+          }
+        }
 
-            // add(str, entropy) -&gt; self
-            // load_random_file(filename) -&gt; true
+        [RubyMethod(&quot;serial&quot;)]
+        public static int Serial(Certificate/*!*/ self) {
+          return self.SerailNumber;
         }
 
-        [RubyClass(&quot;BN&quot;)]
-        public class BN {
+        // serial=
+        // sign(key, digest) =&gt; self
+        // signature_algorithm
 
-            // new =&gt; aBN
-            // new(bn) =&gt; aBN
-            // new(string) =&gt; aBN
-            // new(string, 0 | 2 | 10 | 16) =&gt; aBN
+        [RubyMethod(&quot;subject&quot;)]
+        public static MutableString Subject(Certificate/*!*/ self) {
+          if (self._certificate.Handle == IntPtr.Zero) {
+            return null;
+          } else {
+			  return MutableString.CreateAscii(OpenSSLFormat(self._certificate.Subject));
+          }
+        }
 
-            [RubyMethod(&quot;rand&quot;, RubyMethodAttributes.PublicSingleton)]
-            public static BigInteger/*!*/ Rand(RubyClass/*!*/ self, [DefaultProtocol]int bits, [DefaultProtocol, Optional]int someFlag, [Optional]bool otherFlag) { // TODO: figure out someFlag and otherFlag
-                byte[] data = new byte[bits &gt;&gt; 3];
-                var generator = new Crypto.RNGCryptoServiceProvider();
-                generator.GetBytes(data);
+        // subject=
+        // to_der
+        // to_pem
 
-                uint[] transformed = new uint[data.Length &gt;&gt; 2];
-                int j = 0;
-                for (int i = 0; i &lt; transformed.Length; ++i) {
-                    transformed[i] = data[j] + (uint)(data[j + 1] &lt;&lt; 8) + (uint)(data[j + 2] &lt;&lt; 16) + (uint)(data[j + 3] &lt;&lt; 24);
-                    j += 4;
-                }
+        [RubyMethod(&quot;inspect&quot;)]
+        [RubyMethod(&quot;to_s&quot;)]
+        public static MutableString ToString(RubyContext/*!*/ context, Certificate/*!*/ self) {
+          using (IDisposable handle = RubyUtils.InfiniteInspectTracker.TrackObject(self)) {
+            // #&lt;OpenSSL::X509::Certificate subject=, issuer=, serial=0, not_before=nil, not_after=nil&gt;
+            var result = MutableString.CreateEmpty();
+            result.Append(&quot;#&lt;&quot;);
+            result.Append(context.Inspect(context.GetClassOf(self)));
 
-                return new BigInteger(1, transformed);
+            if (handle == null) {
+              return result.Append(&quot;:...&gt;&quot;);
             }
+            result.Append(' ');
+            if (self._certificate.Handle == IntPtr.Zero) {
+              result.Append(&quot;subject=, issuer=, serial=0, not_before=nil, not_after=nil&quot;);
+            } else {
+              result.Append(string.Format(&quot;subject={0}&quot;, OpenSSLFormat(self._certificate.Subject)));
+              result.Append(string.Format(&quot;, issuer={0}&quot;, OpenSSLFormat(self._certificate.Issuer)));
+              result.Append(string.Format(&quot;, serial={0}&quot;, self.SerailNumber));
+              result.Append(string.Concat(&quot;, not_before=&quot;, &quot;nil&quot;));
+              result.Append(string.Concat(&quot;, not_after=&quot;, &quot;nil&quot;));
+            }
+            result.Append('&gt;');
+            return result;
+          }
         }
+
+        // to_text
+        // verify
+
+        [RubyMethod(&quot;version&quot;)]
+        public static int Version(Certificate/*!*/ self) {
+          if (self._certificate.Handle == IntPtr.Zero) {
+            return 0;
+          } else {
+            return 2;
+          }
+        }
+
+        // version=
+      }
+
+      [RubyClass(&quot;Name&quot;)]
+      public class Name {
+        // new =&gt; name
+        // new(string) =&gt; name
+        // new(dn) =&gt; name
+        // new(dn, template) =&gt; name
+        // add_entry(oid, value [, type]) =&gt; self
+        // to_s =&gt; string
+        // to_s(integer) =&gt; string
+        // to_a =&gt; [[name, data, type], ...]
+        // hash =&gt; integer
+        // to_der =&gt; string
+        // parse(string) =&gt; name
+      }
+    }
+
+    [RubyModule(&quot;PKey&quot;)]
+    public static class PKey {
+
+      [RubyClass(&quot;RSA&quot;)]
+      public class RSA {
+        // RSA.new([size | encoded_key] [, pass]) -&gt; rsa
+        // new(2048) -&gt; rsa 
+        // new(File.read(&quot;rsa.pem&quot;)) -&gt; rsa
+        // new(File.read(&quot;rsa.pem&quot;), &quot;mypassword&quot;) -&gt; rsa
+        // initialize
+        // generate(size [, exponent]) -&gt; rsa
+        // public? -&gt; true (The return value is always true since every private key is also a public key)
+        // private? -&gt; true | false
+        // to_pem -&gt; aString
+        // to_pem(cipher, pass) -&gt; aString
+        // to_der -&gt; aString
+        // public_encrypt(string [, padding]) -&gt; aString
+        // public_decrypt(string [, padding]) -&gt; aString
+        // private_encrypt(string [, padding]) -&gt; aString
+        // private_decrypt(string [, padding]) -&gt; aString
+        // params -&gt; hash
+        // to_text -&gt; aString
+        // public_key -&gt; aRSA
+        // inspect
+        // to_s
+      }
     }
-}
\ No newline at end of file
+  }
+}</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/OpenSSL/OpenSSL.cs</filename>
    </modified>
    <modified>
      <diff>@@ -139,6 +139,7 @@ namespace IronRuby.StandardLibrary.ParseTree {
                 private static readonly Rhs BlockRhs = new Rhs { InBlockParameters = true };
                 private static readonly object Skip = new object();
                 private object _result;
+                private RubyEncoding _encoding;
                 
                 // null -&gt; no rhs
                 private Rhs _rhs;
@@ -241,6 +242,8 @@ namespace IronRuby.StandardLibrary.ParseTree {
                 #region SourceUnitTree
 
                 public override bool Enter(SourceUnitTree/*!*/ node) {
+                    _encoding = node.Encoding;
+
                     if (node.Statements == null || node.Statements.Count == 0) {
                         _result = new RubyArray();
                     } else if (node.Statements.Count == 1) {
@@ -299,12 +302,12 @@ namespace IronRuby.StandardLibrary.ParseTree {
                 }
 
                 public override bool Enter(StringLiteral/*!*/ node) {
-                    _result = MakeNode(NodeKind.str, node.GetMutableString());
+                    _result = MakeNode(NodeKind.str, node.GetMutableString(_encoding));
                     return false;
                 }
 
                 public override bool Enter(SymbolLiteral/*!*/ node) {
-                    _result = MakeNode(NodeKind.lit, SymbolTable.StringToId(node.GetMutableString().ToString()));
+                    _result = MakeNode(NodeKind.lit, SymbolTable.StringToId(node.GetMutableString(_encoding).ToString()));
                     return false;
                 }
 
@@ -314,9 +317,9 @@ namespace IronRuby.StandardLibrary.ParseTree {
                         NodeKind kind;
                         object value;
                         switch (node.Kind) {
-                            case StringKind.Immutable: kind = NodeKind.lit; value = SymbolTable.StringToId(lit.GetMutableString().ToString()); break;
-                            case StringKind.Command: kind = NodeKind.xstr; value = lit.GetMutableString(); break;
-                            case StringKind.Mutable: kind = NodeKind.str; value = lit.GetMutableString(); break;
+                            case StringKind.Immutable: kind = NodeKind.lit; value = SymbolTable.StringToId(lit.GetMutableString(_encoding).ToString()); break;
+                            case StringKind.Command: kind = NodeKind.xstr; value = lit.GetMutableString(_encoding); break;
+                            case StringKind.Mutable: kind = NodeKind.str; value = lit.GetMutableString(_encoding); break;
                             default: throw Assert.Unreachable;
                         }
 
@@ -348,7 +351,7 @@ namespace IronRuby.StandardLibrary.ParseTree {
                         var part = parts[i];
                         lit = part as StringLiteral;
                         if (lit != null) {
-                            object value = lit.GetMutableString();
+                            object value = lit.GetMutableString(_encoding);
                             if (i &gt; 0) {
                                 value = MakeNode(NodeKind.str, value);
                             }
@@ -367,7 +370,7 @@ namespace IronRuby.StandardLibrary.ParseTree {
                     if (node.Pattern.Count == 0) {
                         _result = MakeNode(NodeKind.lit, new RubyRegex(String.Empty, node.Options));
                     } else if (node.Pattern.Count == 1 &amp;&amp; (lit = node.Pattern[0] as StringLiteral) != null) {
-                        _result = MakeNode(NodeKind.lit, lit.GetMutableString().ToRegularExpression(node.Options));
+                        _result = MakeNode(NodeKind.lit, lit.GetMutableString(_encoding).ToRegularExpression(node.Options));
                     } else {
                         var regex = VisitStringConstructor(node.Pattern, NodeKind.dregx);
                         if (node.Options != RubyRegexOptions.NONE) {</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/ParseTree/IronRubyParseTreeOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -38,3 +38,7 @@ using System.Security;
 [assembly: AllowPartiallyTrustedCallers]
 [assembly: SecurityTransparent]
 #endif
+
+#if CLR4
+[assembly: SecurityRules(SecurityRuleSet.Level1)]
+#endif
\ No newline at end of file</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Properties/AssemblyInfo.cs</filename>
    </modified>
    <modified>
      <diff>@@ -18,97 +18,758 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Actions;
 using IronRuby.Builtins;
 using IronRuby.Runtime;
+using IronRuby.Runtime.Calls;
+using Microsoft.Scripting.Utils;
+using System;
+using System.IO;
+using Microsoft.Scripting.Math;
+using System.Diagnostics;
+using System.Collections;
 
 namespace IronRuby.StandardLibrary.StringIO {
+    [RubyClass(&quot;StringIO&quot;, Inherits = typeof(object)), Includes(typeof(Enumerable))]
+    public class StringIO {
+        private MutableString/*!*/ _content;
+        private int _position;
+        private IOMode _mode;
+        private int _lineNumber;
 
-    [RubyClass(&quot;StringIO&quot;)]
-    public class StringIO : RubyIO {
-        public StringIO(RubyContext/*!*/ context)
-            : base(context) {
+        public StringIO()
+            : this(MutableString.CreateBinary(), IOMode.ReadWrite) {
         }
 
-        public StringIO(RubyContext/*!*/ context, MutableStringStream/*!*/ stream, string/*!*/ mode)
-            : base(context, stream, mode) {
+        public StringIO(MutableString/*!*/ content, IOMode mode) {
+            ContractUtils.RequiresNotNull(content, &quot;content&quot;);
+            _content = content;
+            _mode = mode;
         }
 
-        protected MutableStringStream Data {
-            get {
-                MutableStringStream stream = (this.Stream as MutableStringStream);
-                if (stream == null) {
-                    throw RubyExceptions.CreateArgumentError(&quot;stream is not a StringIO&quot;);
-                }
-                return stream;
+        private void SetPosition(long value) {
+            if (value &lt; 0 || value &gt; Int32.MaxValue) {
+                throw RubyExceptions.CreateEINVAL();
+            }
+            _position = (int)value; 
+        }
+
+        private void SetContent(MutableString/*!*/ content) {
+            _content = content;
+            _position = 0;
+            _lineNumber = 0;
+        }
+
+        private MutableString/*!*/ GetContent() {
+            if (_mode.IsClosed()) {
+                throw RubyExceptions.CreateIOError(&quot;closed stream&quot;);
+            }
+            return _content;
+        }
+
+        private MutableString/*!*/ GetReadableContent() {
+            if (!_mode.CanRead()) {
+                throw RubyExceptions.CreateIOError(&quot;not opened for reading&quot;);
+            }
+            return _content;
+        }
+
+        private MutableString/*!*/ GetWritableContent() {
+            if (!_mode.CanWrite()) {
+                throw RubyExceptions.CreateIOError(&quot;not opened for writing&quot;);
+            }
+            return _content;
+        }
+
+        private void Close() {
+            _mode = _mode.Close();
+        }
+
+        private static MutableString/*!*/ CheckContent(MutableString/*!*/ content, IOMode mode) {
+            if (content.IsFrozen &amp;&amp; mode.CanWrite()) {
+                throw Errno.CreateEACCES(&quot;Permission denied&quot;);
+            }
+
+            if ((mode &amp; IOMode.Truncate) != 0) {
+                content.Clear();
             }
+            return content;
+        }
+
+        #region Construction
+
+        [RubyConstructor]
+        public static StringIO/*!*/ Create(RubyClass/*!*/ self) {
+            return new StringIO();
         }
 
-        #region Public Singleton Methods
+        [RubyConstructor]
+        public static StringIO/*!*/ Create(RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ initialString,
+            [DefaultProtocol, Optional, NotNull]MutableString mode) {
+
+            IOMode ioMode = IOModeEnum.Parse(mode, initialString.IsFrozen ? IOMode.ReadOnly : IOMode.ReadWrite) | IOMode.PreserveEndOfLines;
+            return new StringIO(CheckContent(initialString, ioMode), ioMode);
+        }
 
         [RubyConstructor]
-        public static RubyIO CreateIO(RubyClass/*!*/ self, [Optional]MutableString initialString, [Optional]MutableString mode) {
-            MutableStringStream stream = new MutableStringStream(initialString ?? MutableString.CreateBinary());
-            string ioMode = (mode != null) ? mode.ConvertToString() : &quot;rb+&quot;;
-            return new StringIO(self.Context, stream, ioMode);
+        public static StringIO/*!*/ Create(RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString initialString, int mode) {
+            IOMode ioMode = (IOMode)mode | IOMode.PreserveEndOfLines;
+            return new StringIO(CheckContent(initialString, ioMode), ioMode);
+        }
+
+        [RubyMethod(&quot;initialize&quot;, RubyMethodAttributes.PrivateInstance)]
+        public static StringIO/*!*/ Reinitialize(StringIO/*!*/ self) {
+            self.SetContent(MutableString.CreateBinary());
+            self._mode = IOMode.ReadWrite;
+            return self;
+        }
+
+        [RubyMethod(&quot;initialize&quot;, RubyMethodAttributes.PrivateInstance)]
+        public static StringIO/*!*/ Reinitialize(StringIO/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ content,
+            [DefaultProtocol, Optional, NotNull]MutableString mode) {
+            IOMode ioMode = IOModeEnum.Parse(mode, content.IsFrozen ? IOMode.ReadOnly : IOMode.ReadWrite) | IOMode.PreserveEndOfLines;
+            self.SetContent(CheckContent(content, ioMode));
+            self._mode = ioMode;
+            return self;
+        }
+
+        [RubyMethod(&quot;initialize&quot;, RubyMethodAttributes.PrivateInstance)]
+        public static StringIO/*!*/ Reinitialize(StringIO/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ content, int mode) {
+            IOMode ioMode = (IOMode)mode | IOMode.PreserveEndOfLines;
+            self.SetContent(CheckContent(content, ioMode));
+            self._mode = ioMode;
+            return self;
         }
 
         [RubyMethod(&quot;open&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static object OpenIO([NotNull]BlockParam/*!*/ block, RubyClass/*!*/ self, [Optional]MutableString initialString, [Optional]MutableString mode) {
-            MutableStringStream stream = new MutableStringStream(initialString ?? MutableString.CreateBinary());
-            string ioMode = (mode != null) ? mode.ConvertToString() : &quot;rb+&quot;;
-            RubyIO io = new StringIO(self.Context, stream, ioMode);
+        public static RuleGenerator/*!*/ Open() {
+            return RubyIOOps.Open();
+        }
+
+        #endregion
+
+        #region reopen
+
+        [RubyMethod(&quot;reopen&quot;)]
+        public static StringIO/*!*/ Reopen(StringIO/*!*/ self) {
+            self.SetContent(MutableString.CreateBinary());
+            self._mode = IOMode.ReadWrite;
+            return self;
+        }
+
+        [RubyMethod(&quot;reopen&quot;)]
+        [RubyMethod(&quot;initialize_copy&quot;, RubyMethodAttributes.PrivateInstance)]
+        public static StringIO/*!*/ Reopen(RespondToStorage/*!*/ respondToStorage, UnaryOpStorage/*!*/ toStringIoStorage,
+            StringIO/*!*/ self, [NotNull]object/*!*/ other) {
 
-            object result;
-            block.Yield(io, out result);
-            if (!io.Closed) {
-                io.Close();
+            if (!Protocols.RespondTo(respondToStorage, other, &quot;to_strio&quot;)) {
+                throw RubyExceptions.CreateTypeConversionError(respondToStorage.Context.GetClassName(other), &quot;StringIO&quot;);
             }
-            return result;
+
+            var site = toStringIoStorage.GetCallSite(&quot;to_strio&quot;, 0);
+            var strio = site.Target(site, other) as StringIO;
+            if (strio == null) {
+                throw RubyExceptions.CreateTypeError(&quot;C#to_strio should return StringIO&quot;);
+            }
+
+            return Reopen(respondToStorage.Context, self, strio);
+        }
+
+        [RubyMethod(&quot;reopen&quot;)]
+        [RubyMethod(&quot;initialize_copy&quot;, RubyMethodAttributes.PrivateInstance)]
+        public static StringIO/*!*/ Reopen(RubyContext/*!*/ context, [NotNull]StringIO/*!*/ self, [NotNull]StringIO/*!*/ other) {
+            self.SetContent(other._content);
+            self._mode = other._mode;
+            self._lineNumber = other._lineNumber;
+            self._position = other._position;
+
+            // TODO: this seems to be MRI bug
+            // Shouldn't StringIO's taint be always same as the underlying string's taint?
+            context.TaintObjectBy(self, other);
+            return self;
+        }
+
+        [RubyMethod(&quot;reopen&quot;)]
+        public static StringIO/*!*/ Reopen(StringIO/*!*/ self, [NotNull]MutableString/*!*/ content) {
+            return Reopen(self, content, null);
+        }
+
+        [RubyMethod(&quot;reopen&quot;)]
+        public static StringIO/*!*/ Reopen(StringIO/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ content,
+            [DefaultProtocol, NotNull]MutableString mode) {
+            IOMode ioMode = IOModeEnum.Parse(mode, content.IsFrozen ? IOMode.ReadOnly : IOMode.ReadWrite) | IOMode.PreserveEndOfLines;
+            self.SetContent(CheckContent(content, ioMode));
+            self._mode = ioMode;
+            return self;
+        }
+
+        [RubyMethod(&quot;reopen&quot;)]
+        public static StringIO/*!*/ Reopen(StringIO/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ content, int mode) {
+            IOMode ioMode = (IOMode)mode | IOMode.PreserveEndOfLines;
+            self.SetContent(CheckContent(content, ioMode));
+            self._mode = ioMode;
+            return self;
+        }
+
+        #endregion
+
+        #region close(_read|_write), closed(_read|_write)?
+
+        [RubyMethod(&quot;close&quot;)]
+        public static void Close(StringIO/*!*/ self) {
+            self.GetContent();
+            self.Close();
+        }
+
+        [RubyMethod(&quot;close_read&quot;)]
+        public static void CloseRead(StringIO/*!*/ self) {
+            self.GetReadableContent();
+            self._mode = self._mode.CloseRead();
+        }
+
+        [RubyMethod(&quot;close_write&quot;)]
+        public static void CloseWrite(StringIO/*!*/ self) {
+            self.GetWritableContent();
+            self._mode = self._mode.CloseWrite();
+        }
+
+        [RubyMethod(&quot;closed?&quot;)]
+        public static bool IsClosed(StringIO/*!*/ self) {
+            return self._mode.IsClosed();
+        }
+
+        [RubyMethod(&quot;closed_read?&quot;)]
+        public static bool IsClosedRead(StringIO/*!*/ self) {
+            return !self._mode.CanRead();
+        }
+
+        [RubyMethod(&quot;closed_write?&quot;)]
+        public static bool IsClosedWrite(StringIO/*!*/ self) {
+            return !self._mode.CanWrite();
         }
 
         #endregion
 
-        #region Public Instance Methods
+        #region length, size, pos, tell, truncate, eof, eof?, rewind, seek
 
         [RubyMethod(&quot;length&quot;)]
         [RubyMethod(&quot;size&quot;)]
         public static int GetLength(StringIO/*!*/ self) {
-            return (int)self.Data.Length;
+            return self.GetContent().GetByteCount();
         }
 
-        [RubyMethod(&quot;path&quot;)]
-        public static object GetPath(StringIO/*!*/ self) {
-            return null;
+        [RubyMethod(&quot;pos&quot;)]
+        [RubyMethod(&quot;tell&quot;)]
+        public static int GetPosition(StringIO/*!*/ self) {
+            return self._position;
+        }
+
+        [RubyMethod(&quot;pos=&quot;)]
+        public static void Pos(StringIO/*!*/ self, [DefaultProtocol]int pos) {
+            self.SetPosition(pos);
+        }
+
+        [RubyMethod(&quot;truncate&quot;)]
+        public static object SetLength(ConversionStorage&lt;int&gt;/*!*/ fixnumCast, StringIO/*!*/ self, object lengthObj) {
+            int length = Protocols.CastToFixnum(fixnumCast, lengthObj);
+            if (length &lt; 0) {
+                throw RubyExceptions.CreateEINVAL(&quot;negative length&quot;);
+            }
+            self.GetWritableContent().SetByteCount(length);
+            return lengthObj;
+        }
+
+        [RubyMethod(&quot;rewind&quot;)]
+        public static int Rewind(StringIO/*!*/ self) {
+            self.GetContent();
+            self._position = 0;
+            self._lineNumber = 0;
+            return 0;
+        }
+
+        [RubyMethod(&quot;seek&quot;)]
+        public static int Seek(StringIO/*!*/ self, [DefaultProtocol]int pos, [DefaultProtocol, DefaultParameterValue(RubyIO.SEEK_SET)]int seekOrigin) {
+            self.SetPosition(RubyIO.GetSeekPosition(
+                self._content.GetByteCount(), self._position, pos, RubyIO.ToSeekOrigin(seekOrigin)
+            ));
+            return 0;
         }
 
+        [RubyMethod(&quot;eof&quot;)]
+        [RubyMethod(&quot;eof?&quot;)]
+        public static bool Eof(StringIO/*!*/ self) {
+            var context = self.GetReadableContent();
+            return self._position &gt;= context.GetByteCount();
+        }
+
+        #endregion
+
+        #region string, string=
+
         [RubyMethod(&quot;string&quot;)]
         public static MutableString/*!*/ GetString(StringIO/*!*/ self) {
-            return self.Data.String;
+            return self._content;
         }
 
         [RubyMethod(&quot;string=&quot;)]
-        public static MutableString/*!*/ SetString(StringIO/*!*/ self, [NotNull]MutableString/*!*/ str) {
-            self.Data.String = str;
+        public static MutableString/*!*/ SetString(StringIO/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ str) {
+            self.SetContent(str);
             return str;
         }
 
-        [RubyMethod(&quot;truncate&quot;)]
-        public static int SetLength(StringIO/*!*/ self, int length) {
-            self.Data.SetLength(length);
-            return length;
+        #endregion
+
+        #region &lt;&lt;, print, putc, puts
+
+        [RubyMethod(&quot;&lt;&lt;&quot;)]
+        public static object/*!*/ Output(BinaryOpStorage/*!*/ writeStorage, object/*!*/ self, object value) {
+            return PrintOps.Output(writeStorage, self, value);
+        }
+
+        [RubyMethod(&quot;print&quot;)]
+        public static void Print(BinaryOpStorage/*!*/ writeStorage, RubyScope/*!*/ scope, object self) {
+            Print(writeStorage, self, scope.GetInnerMostClosureScope().LastInputLine);
+        }
+
+        [RubyMethod(&quot;print&quot;)]
+        public static void Print(BinaryOpStorage/*!*/ writeStorage, object self, [NotNull]params object[]/*!*/ args) {
+            // MRI: StringIO#print is different from PrintOps.Print - it doesn't output delimiter after each arg.
+            MutableString delimiter = writeStorage.Context.OutputSeparator;
+
+            foreach (object arg in args) {
+                Protocols.Write(writeStorage, self, arg ?? MutableString.CreateAscii(&quot;nil&quot;));
+            }
+
+            if (delimiter != null) {
+                Protocols.Write(writeStorage, self, delimiter);
+            }
+        }
+
+        [RubyMethod(&quot;print&quot;)]
+        public static void Print(BinaryOpStorage/*!*/ writeStorage, object/*!*/ self, object value) {
+            Protocols.Write(writeStorage, self, value ?? MutableString.CreateAscii(&quot;nil&quot;));
+
+            MutableString delimiter = writeStorage.Context.OutputSeparator;
+            if (delimiter != null) {
+                Protocols.Write(writeStorage, self, delimiter);
+            }
+        }
+
+        [RubyMethod(&quot;putc&quot;)]
+        public static MutableString/*!*/ Putc(BinaryOpStorage/*!*/ writeStorage, object self, [NotNull]MutableString/*!*/ val) {
+            return PrintOps.Putc(writeStorage, self, val);
+        }
+
+        [RubyMethod(&quot;putc&quot;)]
+        public static int Putc(BinaryOpStorage/*!*/ writeStorage, object self, [DefaultProtocol]int c) {
+            return PrintOps.Putc(writeStorage, self, c);
+        }
+
+        [RubyMethod(&quot;puts&quot;)]
+        public static void PutsEmptyLine(BinaryOpStorage/*!*/ writeStorage, object self) {
+            PrintOps.PutsEmptyLine(writeStorage, self);
+        }
+
+        [RubyMethod(&quot;puts&quot;)]
+        public static void Puts(BinaryOpStorage/*!*/ writeStorage, object self, [NotNull]MutableString/*!*/ str) {
+            PrintOps.Puts(writeStorage, self, str);
+        }
+
+        [RubyMethod(&quot;puts&quot;)]
+        public static void Puts(BinaryOpStorage/*!*/ writeStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion, 
+            ConversionStorage&lt;IList&gt;/*!*/ tryToAry, object self, [NotNull]object/*!*/ val) {
+
+            PrintOps.Puts(writeStorage, tosConversion, tryToAry, self, val);
+        }
+
+        [RubyMethod(&quot;puts&quot;)]
+        public static void Puts(BinaryOpStorage/*!*/ writeStorage, ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion,
+            ConversionStorage&lt;IList&gt;/*!*/ tryToAry, object self, [NotNull]params object[]/*!*/ vals) {
+
+            PrintOps.Puts(writeStorage, tosConversion, tryToAry, self, vals);
+        }
+
+        [RubyMethod(&quot;printf&quot;)]
+        public static void PrintFormatted(
+            StringFormatterSiteStorage/*!*/ storage,
+            ConversionStorage&lt;MutableString&gt;/*!*/ stringCast,
+            BinaryOpStorage/*!*/ writeStorage,
+            StringIO/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ format, [NotNull]params object[]/*!*/ args) {
+
+            PrintOps.PrintFormatted(storage, stringCast, writeStorage, self, format, args);
+        }
+
+        #endregion
+
+        #region write, syswrite
+
+        [RubyMethod(&quot;write&quot;)]
+        [RubyMethod(&quot;syswrite&quot;)]
+        public static int Write(StringIO/*!*/ self, [NotNull]MutableString/*!*/ value) {
+            var content = self.GetWritableContent();
+            int length = content.GetByteCount();
+            var bytesWritten = value.GetByteCount();
+            int pos;
+
+            if ((self._mode &amp; IOMode.WriteAppends) != 0) {
+                pos = length;
+            } else {
+                pos = self._position;
+            }
+
+            try {
+                if (pos &gt;= length) {
+                    content.Append(0, pos - length);
+                    content.Append(value);
+                } else {
+                    content.Replace(pos, Math.Min(bytesWritten, length -  pos), value);
+                }
+            } catch (InvalidOperationException) {
+                throw RubyExceptions.CreateIOError(&quot;not modifiable string&quot;);
+            }
+
+            content.TaintBy(value);
+            self._position = pos + bytesWritten;
+            return bytesWritten;
+        }
+
+        [RubyMethod(&quot;write&quot;)]
+        [RubyMethod(&quot;syswrite&quot;)]
+        public static int Write(ConversionStorage&lt;MutableString&gt;/*!*/ tosConversion, StringIO/*!*/ self, object obj) {
+            return Write(self, Protocols.ConvertToString(tosConversion, obj));
+        }
+
+        #endregion
+
+        #region read, sysread
+
+        [RubyMethod(&quot;read&quot;)]
+        public static MutableString/*!*/ Read(StringIO/*!*/ self, [Optional]DynamicNull bytes) {
+            return Read(self, null, false);
+        }
+
+        [RubyMethod(&quot;read&quot;)]
+        public static MutableString/*!*/ Read(StringIO/*!*/ self, DynamicNull bytes, [DefaultProtocol, NotNull]MutableString buffer) {
+            return Read(self, buffer, false);
+        }
+
+        public static MutableString/*!*/ Read(StringIO/*!*/ self, MutableString buffer, bool eofError) {
+            var content = self.GetReadableContent();
+            int start = self._position;
+            int length = content.GetByteCount();
+
+            if (buffer != null) {
+                buffer.Clear();
+            } else {
+                buffer = MutableString.CreateBinary();
+            }
+
+            if (start &lt; length) {
+                self._position = length;
+                buffer.Append(content, start, length - start).TaintBy(content);
+            } else if (eofError) {
+                throw new EOFError(&quot;end of file reached&quot;);
+            }
+
+            return buffer;
+        }
+
+        [RubyMethod(&quot;read&quot;)]
+        public static MutableString Read(StringIO/*!*/ self, [DefaultProtocol]int count, [DefaultProtocol, Optional, NotNull]MutableString buffer) {
+            var content = self.GetReadableContent();
+            if (count &lt; 0) {
+                throw RubyExceptions.CreateArgumentError(&quot;negative length -1 given&quot;);
+            }
+
+            if (buffer != null) {
+                buffer.Clear();
+            }
+
+            int length = content.GetByteCount();
+            if (self._position &gt;= length) {
+                return null;
+            }
+
+            if (buffer == null) {
+                buffer = MutableString.CreateBinary();
+            }
+
+            int bytesRead = Math.Min(count, length - self._position);
+            buffer.Append(content, self._position, bytesRead).TaintBy(content);
+            self._position += bytesRead;
+            return buffer;
+        }
+
+        [RubyMethod(&quot;sysread&quot;)]
+        public static MutableString/*!*/ SystemRead(StringIO/*!*/ self, [Optional]DynamicNull bytes) {
+            return Read(self, null, true);
+        }
+
+        [RubyMethod(&quot;sysread&quot;)]
+        public static MutableString/*!*/ SystemRead(StringIO/*!*/ self, DynamicNull bytes, [DefaultProtocol, NotNull]MutableString buffer) {
+            return Read(self, buffer, true);
+        }
+
+        [RubyMethod(&quot;sysread&quot;)]
+        public static MutableString/*!*/ SystemRead(StringIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional, NotNull]MutableString buffer) {
+            var result = Read(self, bytes, buffer);
+            if (result == null) {
+                throw new EOFError(&quot;end of file reached&quot;);
+            }
+            return result;
+        }
+
+        #endregion
+
+        #region getc, getbyte (1.9), ungetc, ungetbyte (1.9), readchar, readbyte (1.9)
+
+        [RubyMethod(&quot;getc&quot;)]
+        public static object GetByte(StringIO/*!*/ self) {
+            var content = self.GetReadableContent();
+
+            if (self._position &gt;= content.GetByteCount()) {
+                return null;
+            }
+
+            return ScriptingRuntimeHelpers.Int32ToObject(content.GetByte(self._position++));
         }
 
         [RubyMethod(&quot;ungetc&quot;)]
-        public static void UnGetCharacter(StringIO/*!*/ self, [DefaultProtocol]int ch) {
-            if (!RubyIO.IsReadable(self.Mode) || self.Closed) {
-                throw RubyExceptions.CreateIOError(&quot;not opened for reading&quot;);
+        public static void SetPreviousByte(StringIO/*!*/ self, [DefaultProtocol]int b) {
+            // MRI: this checks if the IO is readable although it actually modifies the string:
+            MutableString content = self.GetReadableContent();
+
+            int pos = self._position - 1;
+            if (pos &gt;= 0) {
+                int length = content.GetByteCount();
+                try {
+                    if (pos &gt;= length) {
+                        content.Append(0, pos - length);
+                        content.Append(unchecked((byte)b));
+                    } else {
+                        content.SetByte(pos, unchecked((byte)b));
+                    }
+                    self._position = pos;
+                } catch (InvalidOperationException) {
+                    throw RubyExceptions.CreateIOError(&quot;not modifiable string&quot;);
+                }
+            }
+        }
+
+        // returns a string in 1.9
+        [RubyMethod(&quot;readchar&quot;)]
+        public static int ReadChar(StringIO/*!*/ self) {
+            var content = self.GetReadableContent();
+            int length = content.GetByteCount();
+
+            if (self._position &gt;= length) {
+                throw new EOFError(&quot;end of file reached&quot;);
+            }
+
+            return content.GetByte(self._position++);
+        }
+
+        #endregion
+
+        #region gets, readline, readlines
+
+        //
+        // Note
+        //
+        // MRI: the behavior of IO#readline and StringIO#readline is different.
+        // StringIO doesn't normalize EOLNs.
+        // Also, gets/readlines increment _lineNumber field instead of global $. variable.
+        // 
+
+        [RubyMethod(&quot;lineno&quot;)]
+        public static int GetLineNo(StringIO/*!*/ self) {
+            return self._lineNumber;
+        }
+
+        [RubyMethod(&quot;lineno=&quot;)]
+        public static void SetLineNo(StringIO/*!*/ self, [DefaultProtocol]int value) {
+            self._lineNumber = value;
+        }
+
+        [RubyMethod(&quot;gets&quot;)]
+        public static MutableString Gets(RubyScope/*!*/ scope, StringIO/*!*/ self) {
+            return Gets(scope, self, scope.RubyContext.InputSeparator);
+        }
+
+        [RubyMethod(&quot;gets&quot;)]
+        public static MutableString Gets(RubyScope/*!*/ scope, StringIO/*!*/ self, [DefaultProtocol]MutableString separator) {
+            var content = self.GetReadableContent();
+
+            int position = self._position;
+            MutableString result = ReadLine(content, separator, ref position);
+            self._position = position;
+
+            scope.GetInnerMostClosureScope().LastInputLine = result;
+            self._lineNumber++;
+
+            return result;
+        }
+
+        [RubyMethod(&quot;readline&quot;)]
+        public static MutableString/*!*/ ReadLine(RubyScope/*!*/ scope, StringIO/*!*/ self) {
+            return ReadLine(scope, self, scope.RubyContext.InputSeparator);
+        }
+
+        [RubyMethod(&quot;readline&quot;)]
+        public static MutableString/*!*/ ReadLine(RubyScope/*!*/ scope, StringIO/*!*/ self, [DefaultProtocol]MutableString separator) {
+            // no dynamic call, modifies $_ scope variable:
+            MutableString result = Gets(scope, self, separator);
+            if (result == null) {
+                throw new EOFError(&quot;end of file reached&quot;);
+            }
+
+            return result;
+        }
+
+        [RubyMethod(&quot;readlines&quot;)]
+        public static RubyArray/*!*/ ReadLines(RubyContext/*!*/ context, StringIO/*!*/ self) {
+            return ReadLines(self, context.InputSeparator);
+        }
+
+        [RubyMethod(&quot;readlines&quot;)]
+        public static RubyArray/*!*/ ReadLines(StringIO/*!*/ self, [DefaultProtocol]MutableString separator) {
+            var content = self.GetReadableContent();
+            RubyArray result = new RubyArray();
+
+            // no dynamic call, doesn't modify $_ scope variable:
+            MutableString line;
+            int position = self._position;
+            while ((line = ReadLine(content, separator, ref position)) != null) {
+                result.Add(line);
+                self._lineNumber++;
             }
+            self._position = position;
+            return result;
+        }
+
+        private static readonly byte[] ParagraphSeparator = new byte[] { (byte)'\n', (byte)'\n' };
+
+        private static MutableString ReadLine(MutableString/*!*/ content, MutableString separator, ref int position) {
+            int length = content.GetByteCount();
+            if (position &gt;= length) {
+                return null;
+            }
+
+            int oldPosition = position;
+
+            if (separator == null) {
+                position = length;
+            } else if (separator.IsEmpty) {
+                // skip initial ends of line:
+                while (oldPosition &lt; length &amp;&amp; content.GetByte(oldPosition) == '\n') {
+                    oldPosition++;
+                }
+
+                position = content.IndexOf(ParagraphSeparator, oldPosition);
+                position = (position != -1) ? position + 1 : length;
+            } else {
+                position = content.IndexOf(separator, oldPosition);
+                position = (position != -1) ? position + separator.Length : length;
+            }
+
+            return content.GetSlice(oldPosition, position - oldPosition);
+        }
+
+        #endregion
+
+        #region each, each_line, each_byte, each_char (1.9)
+        
+        [RubyMethod(&quot;each&quot;)]
+        [RubyMethod(&quot;each_line&quot;)]
+        public static object EachLine(RubyContext/*!*/ context, BlockParam block, StringIO/*!*/ self) {
+            return EachLine(block, self, context.InputSeparator);
+        }
 
-            long offset = self.Data.Position;
-            if (offset == 0) {
-                return;
+        [RubyMethod(&quot;each&quot;)]
+        [RubyMethod(&quot;each_line&quot;)]
+        public static object EachLine(BlockParam block, StringIO/*!*/ self, [DefaultProtocol]MutableString separator) {
+            // TODO: improve MSOps.EachLine
+            var content = self.GetReadableContent();
+            var result = MutableStringOps.EachLine(block, content, separator, self._position);
+            return ReferenceEquals(result, content) ? self : result;
+        }
+
+        [RubyMethod(&quot;each_byte&quot;)]
+        public static object EachByte(BlockParam block, StringIO/*!*/ self) {
+            MutableString content;
+            int pos;
+            while ((pos = self._position) &lt; (content = self.GetReadableContent()).GetByteCount()) {
+                if (block == null) {
+                    throw RubyExceptions.NoBlockGiven();
+                }
+
+                self._position++;
+
+                object result;
+                if (block.Yield(ScriptingRuntimeHelpers.Int32ToObject(content.GetByte(pos)), out result)) {
+                    return result;
+                }
             }
+            return null;
+        }
+
+        #endregion
+        
+        #region TODO: chars, bytes, lines (1.9)
+
+        #endregion
+
+        #region TODO: external_encoding, internal_encoding, set_encoding (1.9)
+
+        #endregion
+
+        #region Stubs: binmode, fcntl, fileno, pid, path, fsync, sync, sync=, isatty, tty?, flush
+
+        [RubyMethod(&quot;binmode&quot;)]
+        public static StringIO/*!*/ SetBinaryMode(StringIO/*!*/ self) {
+            // nop
+            return self;
+        }
+
+        [RubyMethod(&quot;fcntl&quot;)]
+        public static void FileControl(StringIO/*!*/ self) {
+            throw new NotImplementedError();
+        }
+
+        [RubyMethod(&quot;fileno&quot;)]
+        [RubyMethod(&quot;pid&quot;)]
+        [RubyMethod(&quot;path&quot;)]
+        public static object GetDescriptor(StringIO/*!*/ self) {
+            // nop
+            return null;
+        }
+
+        [RubyMethod(&quot;fsync&quot;)]
+        public static int FSync(StringIO/*!*/ self) {
+            // nop
+            return 0;
+        }
+
+        [RubyMethod(&quot;sync&quot;)]
+        public static bool Sync(StringIO/*!*/ self) {
+            // nop
+            return true;
+        }
+
+        [RubyMethod(&quot;sync=&quot;)]
+        public static bool SetSync(StringIO/*!*/ self, bool value) {
+            // nop
+            return value;
+        }
+
+        [RubyMethod(&quot;isatty&quot;)]
+        [RubyMethod(&quot;tty?&quot;)]
+        public static bool IsConsole(StringIO/*!*/ self) {
+            // nop
+            return false;
+        }
 
-            self.Data.String.SetByte((int)(offset - 1), unchecked((byte)ch));
-            self.Data.Seek(-1, System.IO.SeekOrigin.Current);
+        [RubyMethod(&quot;flush&quot;)]
+        public static StringIO/*!*/ Flush(StringIO/*!*/ self) {
+            // nop
+            return self;
         }
 
         #endregion</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/StringIO/StringIO.cs</filename>
    </modified>
    <modified>
      <diff>@@ -123,7 +123,7 @@ namespace IronRuby.StandardLibrary.StringScanner {
             if (subgroup &gt;= self.LastMatchingGroups.Count) {
                 return null;
             }
-            return MutableString.Create(self.LastMatchingGroups[subgroup].ToString());
+            return MutableString.Create(self.LastMatchingGroups[subgroup].ToString(), self._scanString.Encoding);
         }
 
         [RubyMethod(&quot;beginning_of_line?&quot;)]
@@ -182,7 +182,7 @@ namespace IronRuby.StandardLibrary.StringScanner {
         [RubyMethod(&quot;inspect&quot;)]
         [RubyMethod(&quot;to_s&quot;)]
         public static MutableString ToString(StringScanner/*!*/ self) {
-            return MutableString.Create(self.ToString());
+            return MutableString.Create(self.ToString(), self._scanString.Encoding);
         }
 
         [RubyMethod(&quot;match?&quot;)]
@@ -226,7 +226,7 @@ namespace IronRuby.StandardLibrary.StringScanner {
                 len = maxlen;
             }
             if (self.CurrentPosition &gt;= self.Length || len == 0) {
-                return MutableString.CreateMutable();
+                return MutableString.CreateEmpty();
             }
             return self.ScanString.GetSlice(self.CurrentPosition, len);
         }
@@ -259,7 +259,7 @@ namespace IronRuby.StandardLibrary.StringScanner {
             int position = self.FoundPosition + self.LastMatch.Length;
             int len = self.Length - position;
             if (len &lt;= 0) {
-                return MutableString.CreateMutable();
+                return MutableString.CreateEmpty();
             }
             return self.ScanString.GetSlice(position, len);
         }
@@ -282,7 +282,7 @@ namespace IronRuby.StandardLibrary.StringScanner {
         public static MutableString Rest(StringScanner/*!*/ self) {
             int len = self.Length - self.CurrentPosition;
             if (len &lt;= 0) {
-                return MutableString.CreateMutable();
+                return MutableString.CreateEmpty();
             }
             return self.ScanString.GetSlice(self.CurrentPosition, len);
         }
@@ -429,7 +429,7 @@ namespace IronRuby.StandardLibrary.StringScanner {
             get { return _scanString.Length; }
         }
 
-        private MutableString ScanString {
+        private MutableString/*!*/ ScanString {
             get { return _scanString; }
             set { _scanString = value; }
         }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/StringScanner/StringScanner.cs</filename>
    </modified>
    <modified>
      <diff>@@ -510,6 +510,12 @@ namespace IronRuby.StandardLibrary.Zlib {
                 if (zstring.IsEmpty) {
                     throw new BufError(&quot;buffer error&quot;);
                 }
+                
+                // TODO: hack
+                if (zstring.GetByteCount() == 6 &amp;&amp; zstring.GetByte(0) == (byte)'X' &amp;&amp; zstring.GetByte(1) == 0x85 &amp;&amp; 
+                    zstring.GetByte(2) == 0 &amp;&amp; zstring.GetByte(3) == 0 &amp;&amp; zstring.GetByte(4) == 0 &amp;&amp; zstring.GetByte(5) == 0) {
+                    return MutableString.CreateEmpty();
+                }
 
                 self._inputBuffer.AddRange(zstring.ConvertToBytes());
 
@@ -836,7 +842,7 @@ namespace IronRuby.StandardLibrary.Zlib {
 
             [RubyMethod(&quot;open&quot;, RubyMethodAttributes.PublicSingleton)]
             public static GZipReader/*!*/ Open(RespondToStorage/*!*/ respondToStorage, RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path) {
-                return Create(respondToStorage, self, new RubyFile(self.Context, path.ConvertToString(), RubyFileMode.RDONLY));
+                return Create(respondToStorage, self, new RubyFile(self.Context, path.ConvertToString(), IOMode.ReadOnly));
             }
 
             [RubyMethod(&quot;open&quot;, RubyMethodAttributes.PublicSingleton)]
@@ -1036,10 +1042,6 @@ namespace IronRuby.StandardLibrary.Zlib {
 
             [RubyMethod(&quot;deflate&quot;)]
             public static MutableString/*!*/ DeflateString(Deflate/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ str, int flush) {
-                if (str.IsEmpty) {
-                    throw new BufError(&quot;buffer error&quot;);
-                }
-
                 if (flush != FINISH) {
                     throw new NotImplementedError(&quot;flush can only be FINISH&quot;);
                 }
@@ -1172,7 +1174,7 @@ namespace IronRuby.StandardLibrary.Zlib {
                 [DefaultParameterValue(0)]int level, 
                 [DefaultParameterValue(DEFAULT_STRATEGY)]int strategy) {
 
-                RubyFile file = new RubyFile(self.Context, filename.ConvertToString(), RubyFileMode.CREAT | RubyFileMode.TRUNC | RubyFileMode.WRONLY | RubyFileMode.BINARY);
+                RubyFile file = new RubyFile(self.Context, filename.ConvertToString(), IOMode.CreateIfNotExists | IOMode.Truncate | IOMode.WriteOnly | IOMode.PreserveEndOfLines);
                 GzipWriter gzipFile = Create(respondToStorage, self, file, level, strategy);
 
                 if (block == null) {</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Zlib/zlib.cs</filename>
    </modified>
    <modified>
      <diff>@@ -28,14 +28,15 @@ using IronRuby.Builtins;
 using IronRuby.Runtime;
 using IronRuby.StandardLibrary.FileControl;
 using Microsoft.Scripting.Math;
+using IronRuby.Runtime.Calls;
 
 namespace IronRuby.StandardLibrary.Sockets {
     [RubyClass(&quot;BasicSocket&quot;, BuildConfig = &quot;!SILVERLIGHT&quot;)]
     public abstract class RubyBasicSocket : RubyIO {
         // TODO: do these escape out of the library?
-        private static readonly MutableString BROADCAST_STRING = MutableString.Create(&quot;&lt;broadcast&gt;&quot;).Freeze();
-        private static readonly MutableString BROADCAST_IP_STRING = MutableString.Create(&quot;255.255.255.255&quot;).Freeze();
-        private static readonly MutableString ANY_IP_STRING = MutableString.Create(&quot;0.0.0.0&quot;).Freeze();
+        private static readonly MutableString BROADCAST_STRING = MutableString.CreateAscii(&quot;&lt;broadcast&gt;&quot;).Freeze();
+        private static readonly MutableString BROADCAST_IP_STRING = MutableString.CreateAscii(&quot;255.255.255.255&quot;).Freeze();
+        private static readonly MutableString ANY_IP_STRING = MutableString.CreateAscii(&quot;0.0.0.0&quot;).Freeze();
 
         private readonly Socket/*!*/ _socket;
 
@@ -52,7 +53,7 @@ namespace IronRuby.StandardLibrary.Sockets {
         /// Create a new RubyBasicSocket from a specified stream and mode
         /// &lt;/summary&gt;
         protected RubyBasicSocket(RubyContext/*!*/ context, Socket/*!*/ socket)
-            : base(context, new SocketStream(socket), &quot;rb+&quot;) {
+            : base(context, new SocketStream(socket), IOMode.ReadWrite | IOMode.PreserveEndOfLines) {
             _socket = socket;
         }
 
@@ -120,8 +121,8 @@ namespace IronRuby.StandardLibrary.Sockets {
         /// &lt;/summary&gt;
         /// &lt;returns&gt;The corresponding socket&lt;/returns&gt;
         [RubyMethod(&quot;for_fd&quot;, RubyMethodAttributes.PublicSingleton)]
-        public static RubyBasicSocket/*!*/ ForFileDescriptor(RubyClass/*!*/ self, [DefaultProtocol]int fileDescriptor) {
-            return (RubyBasicSocket)self.Context.GetDescriptor(fileDescriptor);
+        public static RuleGenerator/*!*/ ForFileDescriptor() {
+            return new RuleGenerator(RuleGenerators.InstanceConstructor);
         }
 
         #endregion
@@ -388,15 +389,16 @@ namespace IronRuby.StandardLibrary.Sockets {
 
             IPEndPoint ep = (IPEndPoint)endPoint;
 
-            result.Add(MutableString.Create(AddressFamilyToString(ep.AddressFamily)));
+            result.Add(MutableString.CreateAscii(AddressFamilyToString(ep.AddressFamily)));
             result.Add(ep.Port);
             if (DoNotReverseLookup(context).Value) {
-                result.Add(MutableString.Create(ep.Address.ToString()));
+                result.Add(MutableString.CreateAscii(ep.Address.ToString()));
             } else {
                 // TODO: MRI returns localhost rather than the local machine name here
-                result.Add(MutableString.Create(Dns.GetHostEntry(ep.Address).HostName));
+                // TODO (encoding):
+                result.Add(MutableString.Create(Dns.GetHostEntry(ep.Address).HostName, RubyEncoding.UTF8));
             }
-            result.Add(MutableString.Create(ep.Address.ToString()));
+            result.Add(MutableString.CreateAscii(ep.Address.ToString()));
             return result;
         }
 
@@ -592,12 +594,14 @@ namespace IronRuby.StandardLibrary.Sockets {
         internal static RubyArray/*!*/ CreateHostEntryArray(IPHostEntry/*!*/ hostEntry, bool packIpAddresses) {
             RubyArray result = new RubyArray(4);
             // Canonical Hostname
-            result.Add(MutableString.Create(hostEntry.HostName));
+            // TODO (encoding):
+            result.Add(MutableString.Create(hostEntry.HostName, RubyEncoding.UTF8));
 
             // Aliases
             RubyArray aliases = new RubyArray(hostEntry.Aliases.Length);
             foreach (string alias in hostEntry.Aliases) {
-                aliases.Add(MutableString.Create(alias));
+                // TODO (encoding):
+                aliases.Add(MutableString.Create(alias, RubyEncoding.UTF8));
             }
             result.Add(aliases);
 
@@ -612,25 +616,24 @@ namespace IronRuby.StandardLibrary.Sockets {
                     str.Append(bytes, 0, bytes.Length);
                     result.Add(str);
                 } else {
-                    result.Add(MutableString.Create(address.ToString()));
+                    result.Add(MutableString.CreateAscii(address.ToString()));
                 }
             }
             return result;
         }
 
 
-        class AddressFamilyName {
-            MutableString _name;
-            AddressFamily _family;
-            public MutableString Name { get { return _name; } }
-            public AddressFamily Family { get { return _family; } }
-            public AddressFamilyName(string name, AddressFamily family) {
-                _name = MutableString.Create(name);
-                _family = family;
+        private struct AddressFamilyName {
+            public readonly MutableString/*!*/ Name;
+            public readonly AddressFamily Family;
+
+            public AddressFamilyName(string/*!*/ name, AddressFamily family) {
+                Name = MutableString.CreateAscii(name);
+                Family = family;
             }
         }
 
-        static List&lt;AddressFamilyName&gt; FamilyNames = new List&lt;AddressFamilyName&gt;(new AddressFamilyName[] {
+        private static AddressFamilyName[] FamilyNames = new[] {
             new AddressFamilyName(&quot;AF_INET&quot;, AddressFamily.InterNetwork),
             new AddressFamilyName(&quot;AF_UNIX&quot;, AddressFamily.Unix),
             //new AddressFamilyName(&quot;AF_AX25&quot;, AddressFamily.Ax),
@@ -668,25 +671,21 @@ namespace IronRuby.StandardLibrary.Sockets {
             //new AddressFamilyName(&quot;AF_NETGRAPH&quot;, AddressFamily.Netgraph),
             new AddressFamilyName(&quot;AF_MAX&quot;, AddressFamily.Max),
             //new AddressFamilyName(&quot;AF_E164&quot;, AddressFamily.E164),
-        });
-
-        internal class ServiceName {
-            int _port;
-            MutableString _protocol;
-            MutableString _name;
+        };
 
-            public int Port { get { return _port; } }
-            public MutableString Protocol { get { return _protocol; } }
-            public MutableString Name { get { return _name; } }
+        internal sealed class ServiceName {
+            public readonly int Port;
+            public readonly MutableString Protocol;
+            public readonly MutableString Name;
 
-            public ServiceName(int port, string protocol, string name) {
-                _port = port;
-                _protocol = MutableString.Create(protocol);
-                _name = MutableString.Create(name);
+            public ServiceName(int port, string/*!*/ protocol, string/*!*/ name) {
+                Port = port;
+                Protocol = MutableString.CreateAscii(protocol);
+                Name = MutableString.CreateAscii(name);
             }
         }
 
-        static List&lt;ServiceName&gt; ServiceNames = new List&lt;ServiceName&gt;(new ServiceName[] {
+        private static ServiceName[] ServiceNames = new[] {
             new ServiceName(7, &quot;tcp&quot;, &quot;echo&quot;),
             new ServiceName(7, &quot;udp&quot;, &quot;echo&quot;),
             new ServiceName(9, &quot;tcp&quot;, &quot;discard&quot;),
@@ -830,7 +829,7 @@ namespace IronRuby.StandardLibrary.Sockets {
             new ServiceName(10011, &quot;udp&quot;, &quot;rscsb&quot;),
             new ServiceName(10012, &quot;tcp&quot;, &quot;qmaster&quot;),
             new ServiceName(10012, &quot;udp&quot;, &quot;qmaster&quot;)
-        });
+        };
 
         #endregion
     }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/BasicSocket.cs</filename>
    </modified>
    <modified>
      <diff>@@ -33,7 +33,7 @@ namespace IronRuby.StandardLibrary.Sockets {
         
         [RubyMethod(&quot;getaddress&quot;, RubyMethodAttributes.PublicSingleton)]
         public static MutableString/*!*/ GetAddress(ConversionStorage&lt;MutableString&gt;/*!*/ stringCast, RubyClass/*!*/ self, object hostNameOrAddress) {
-            return MutableString.Create(GetHostAddress(ConvertToHostString(stringCast, hostNameOrAddress)).ToString());
+            return MutableString.CreateAscii(GetHostAddress(ConvertToHostString(stringCast, hostNameOrAddress)).ToString());
         }
 
         #region Public Instance Methods</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/IPSocket.cs</filename>
    </modified>
    <modified>
      <diff>@@ -78,12 +78,13 @@ namespace IronRuby.StandardLibrary.Sockets {
                 result.Add(ToAddressFamilyString(address.AddressFamily));
                 result.Add(iPort);
                 if (DoNotReverseLookup(self.Context).Value) {
-                    result.Add(MutableString.Create(address.ToString()));
+                    result.Add(MutableString.CreateAscii(address.ToString()));
                 } else {
                     IPHostEntry alias = GetHostEntry(address);
-                    result.Add(MutableString.Create(alias.HostName));
+                    // TODO (encoding):
+                    result.Add(MutableString.Create(alias.HostName, RubyEncoding.UTF8));
                 }
-                result.Add(MutableString.Create(address.ToString()));
+                result.Add(MutableString.CreateAscii(address.ToString()));
                 result.Add((int)address.AddressFamily);
                 result.Add(socketType);
 
@@ -122,10 +123,11 @@ namespace IronRuby.StandardLibrary.Sockets {
 
         [RubyMethod(&quot;gethostname&quot;, RubyMethodAttributes.PublicSingleton)]
         public static MutableString GetHostname(RubyClass/*!*/ self) {
-            return MutableString.Create(Dns.GetHostName());
+            // TODO (encoding):
+            return MutableString.Create(Dns.GetHostName(), RubyEncoding.UTF8);
         }
 
-        private static readonly MutableString/*!*/ _DefaultProtocol = MutableString.Create(&quot;tcp&quot;).Freeze();
+        private static readonly MutableString/*!*/ _DefaultProtocol = MutableString.CreateAscii(&quot;tcp&quot;).Freeze();
 
         [RubyMethod(&quot;getservbyname&quot;, RubyMethodAttributes.PublicSingleton)]
         public static int GetServiceByName(RubyClass/*!*/ self, 
@@ -146,9 +148,7 @@ namespace IronRuby.StandardLibrary.Sockets {
             try {
                 return ParseInteger(self.Context, name.ConvertToString());
             } catch (InvalidOperationException) {
-                throw SocketErrorOps.Create(
-                    String.Format(&quot;no such service {0} {1}&quot;, name.ConvertToString(), protocol.ConvertToString())
-                );
+                throw SocketErrorOps.Create(MutableString.FormatMessage(&quot;no such service {0} {1}&quot;, name, protocol));
             }
         }
 
@@ -186,7 +186,8 @@ namespace IronRuby.StandardLibrary.Sockets {
             IPHostEntry entry = GetHostEntry(ConvertToHostString(stringCast, hostName));
 
             RubyArray result = new RubyArray(2);
-            result.Add(MutableString.Create(entry.HostName));
+            // TODO (encoding):
+            result.Add(MutableString.Create(entry.HostName, RubyEncoding.UTF8));
             if (service != null) {
                 result.Add(MutableString.Create(service.Name));
             } else {
@@ -204,7 +205,8 @@ namespace IronRuby.StandardLibrary.Sockets {
             ServiceName service = SearchForService(ep.Port);
 
             RubyArray result = new RubyArray(2);
-            result.Add(MutableString.Create(entry.HostName));
+            // TODO (encoding):
+            result.Add(MutableString.Create(entry.HostName, RubyEncoding.UTF8));
             if (service != null) {
                 result.Add(MutableString.Create(service.Name));
             } else {
@@ -243,7 +245,7 @@ namespace IronRuby.StandardLibrary.Sockets {
             IPEndPoint ep = UnpackSockAddr(address);
             RubyArray result = new RubyArray(2);
             result.Add(ep.Port);
-            result.Add(MutableString.Create(ep.Address.ToString()));
+            result.Add(MutableString.CreateAscii(ep.Address.ToString()));
             return result;
         }
 
@@ -267,7 +269,7 @@ namespace IronRuby.StandardLibrary.Sockets {
             RubySocket s = new RubySocket(context, self.Socket.Accept());
             result.Add(s);
             SocketAddress addr = s.Socket.RemoteEndPoint.Serialize();
-            result.Add(MutableString.Create(addr.ToString()));
+            result.Add(MutableString.CreateAscii(addr.ToString()));
             return result;
         }
 
@@ -340,9 +342,9 @@ namespace IronRuby.StandardLibrary.Sockets {
             // TODO: Do we need some kind of strong reference to the socket
             // here to stop the RubySocket from being garbage collected?
             RubySocket s = new RubySocket(context, self.Socket.Accept());
-            result.Add(s.FileDescriptor);
+            result.Add(s.GetFileDescriptor());
             SocketAddress addr = s.Socket.RemoteEndPoint.Serialize();
-            result.Add(MutableString.Create(addr.ToString()));
+            result.Add(MutableString.CreateAscii(addr.ToString()));
             return result;
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/Socket.cs</filename>
    </modified>
    <modified>
      <diff>@@ -27,12 +27,12 @@ namespace IronRuby.StandardLibrary.Sockets {
     public static class SocketErrorOps {
         [RubyConstructor]
         public static Exception/*!*/ Create(RubyClass/*!*/ self, [DefaultParameterValue(null)]object message) {
-            return RubyExceptionData.InitializeException(new SocketException(0), message ?? MutableString.Create(&quot;SocketError&quot;));
+            return RubyExceptionData.InitializeException(new SocketException(0), message ?? MutableString.CreateAscii(&quot;SocketError&quot;));
 
         }
 
-        public static Exception/*!*/ Create(string/*!*/ message) {
-            return RubyExceptionData.InitializeException(new SocketException(0), MutableString.Create(message));
+        public static Exception/*!*/ Create(MutableString/*!*/ message) {
+            return RubyExceptionData.InitializeException(new SocketException(0), message);
         }
     }
 }</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/SocketError.cs</filename>
    </modified>
    <modified>
      <diff>@@ -56,7 +56,13 @@ namespace IronRuby.StandardLibrary.Sockets {
             IAsyncResult result = Interlocked.Exchange(ref _acceptResult, null);
 
             if (result == null) {
-                return Socket.Accept();
+                ThreadOps.RubyThreadInfo info = ThreadOps.RubyThreadInfo.FromThread(Thread.CurrentThread);
+                info.Blocked = true;
+                try {
+                    return Socket.Accept();
+                } finally {
+                    info.Blocked = false;
+                }
             }
 
             // wait until accept finishes:
@@ -121,7 +127,7 @@ namespace IronRuby.StandardLibrary.Sockets {
 
         [RubyMethod(&quot;sysaccept&quot;)]
         public static int SysAccept(RubyContext/*!*/ context, TCPServer/*!*/ self) {
-            return Accept(context, self).FileDescriptor;
+            return Accept(context, self).GetFileDescriptor();
         }
 
         [RubyMethod(&quot;listen&quot;)]</diff>
      <filename>Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/TCPServer.cs</filename>
    </modified>
    <modified>
      <diff>@@ -188,9 +188,7 @@ Global
 		{6EE7A428-D803-41BC-8248-1297C3ACE369}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{6EE7A428-D803-41BC-8248-1297C3ACE369}.Release|Any CPU.Build.0 = Release|Any CPU
 		{6EE7A428-D803-41BC-8248-1297C3ACE369}.Silverlight Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{6EE7A428-D803-41BC-8248-1297C3ACE369}.Silverlight Debug|Any CPU.Build.0 = Debug|Any CPU
 		{6EE7A428-D803-41BC-8248-1297C3ACE369}.Silverlight Release|Any CPU.ActiveCfg = Release|Any CPU
-		{6EE7A428-D803-41BC-8248-1297C3ACE369}.Silverlight Release|Any CPU.Build.0 = Release|Any CPU
 		{ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}.FxCop|Any CPU.ActiveCfg = Silverlight Release|Any CPU</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby.sln</filename>
    </modified>
    <modified>
      <diff>@@ -35,8 +35,12 @@ namespace IronRuby.Builtins {
         }
 
         public override void Close() {
-            _reader.Close();
-            _writer.Close();
+            if (_reader != null) {
+                _reader.Close();
+            }
+            if (_writer != null) {
+                _writer.Close();
+            }
         }
 
         public StreamReader Reader {
@@ -60,8 +64,12 @@ namespace IronRuby.Builtins {
         }
 
         public override void Flush() {
-            _reader.BaseStream.Flush();
-            _writer.Flush();
+            if (_reader != null) {
+                _reader.BaseStream.Flush();
+            }
+            if (_writer != null) {
+                _writer.Flush();
+            }
         }
 
         public override long Length {
@@ -74,10 +82,17 @@ namespace IronRuby.Builtins {
         }
 
         public override int ReadByte() {
+            if (_reader == null) {
+                throw new InvalidOperationException();
+            }
             return _reader.Read();
         }
 
         public override int Read(byte[]/*!*/ buffer, int offset, int count) {
+            if (_reader == null) {
+                throw new InvalidOperationException();
+            }
+
             // TODO:
             return _reader.BaseStream.Read(buffer, offset, count);
         }
@@ -91,6 +106,10 @@ namespace IronRuby.Builtins {
         }
 
         public override void Write(byte[] buffer, int offset, int count) {
+            if (_writer == null) {
+                throw new InvalidOperationException();
+            }
+
             // TODO:
             Debug.Assert(_writer != null);
             _writer.Write(_writer.Encoding.GetString(buffer, offset, count));</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/DuplexStream.cs</filename>
    </modified>
    <modified>
      <diff>@@ -213,8 +213,8 @@ namespace IronRuby.Builtins {
 
         public ExistError() : this(null, null) { }
         public ExistError(string message) : this(message, null) { }
-        public ExistError(string message, Exception inner) : base(RubyErrno.MakeMessage(message, M), inner) { }
-        public ExistError(MutableString message) : base(RubyErrno.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
+        public ExistError(string message, Exception inner) : base(RubyExceptions.MakeMessage(message, M), inner) { }
+        public ExistError(MutableString message) : base(RubyExceptions.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
 
 #if !SILVERLIGHT
         protected ExistError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
@@ -223,13 +223,28 @@ namespace IronRuby.Builtins {
     }
 
     [Serializable]
+    public class BadFileDescriptorError : ExternalException {
+        private const string/*!*/ M = &quot;Bad file descriptor&quot;;
+
+        public BadFileDescriptorError() : this(null, null) { }
+        public BadFileDescriptorError(string message) : this(message, null) { }
+        public BadFileDescriptorError(string message, Exception inner) : base(RubyExceptions.MakeMessage(message, M), inner) { }
+        public BadFileDescriptorError(MutableString message) : base(RubyExceptions.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
+
+#if !SILVERLIGHT
+        protected BadFileDescriptorError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
+            : base(info, context) { }
+#endif
+    }
+
+    [Serializable]
     public class InvalidError : ExternalException {
         private const string/*!*/ M = &quot;Invalid argument&quot;;
 
         public InvalidError() : this(null, null) { }
         public InvalidError(string message) : this(message, null) { }
-        public InvalidError(string message, Exception inner) : base(RubyErrno.MakeMessage(message, M), inner) { }
-        public InvalidError(MutableString message) : base(RubyErrno.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
+        public InvalidError(string message, Exception inner) : base(RubyExceptions.MakeMessage(message, M), inner) { }
+        public InvalidError(MutableString message) : base(RubyExceptions.MakeMessage(ref message, M)) { RubyExceptionData.InitializeException(this, message); }
 
 #if !SILVERLIGHT
         protected InvalidError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/Exceptions.cs</filename>
    </modified>
    <modified>
      <diff>@@ -157,7 +157,8 @@ namespace IronRuby.Builtins {
         }
 
         public override MutableString/*!*/ GetPattern() {
-            return MutableString.Create(_pattern);
+            // TODO (encoding):
+            return MutableString.Create(_pattern, RubyEncoding.UTF8);
         }
 
 #if DEBUG
@@ -166,7 +167,7 @@ namespace IronRuby.Builtins {
         }
 #endif
         public override MutableString[]/*!*/ Split(MutableString/*!*/ input, int count, int start) {
-            return MutableString.MakeArray(_regex.Split(input.ConvertToString(), count, start));
+            return MutableString.MakeArray(_regex.Split(input.ConvertToString(), count, start), input.Encoding);
         }
 
         private static int SkipNonSpecial(string/*!*/ pattern, int i, out char escaped) {</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/GenericRegex.cs</filename>
    </modified>
    <modified>
      <diff>@@ -15,16 +15,14 @@
 
 using System;
 using System.Collections.Generic;
-using System.IO;
-using Microsoft.Scripting;
-using Microsoft.Scripting.Runtime;
-using Microsoft.Scripting.Utils;
 using System.Text;
 using System.Text.RegularExpressions;
 using IronRuby.Runtime;
+using Microsoft.Scripting;
+using Microsoft.Scripting.Utils;
 
 namespace IronRuby.Builtins {
-    public class Glob {
+    public static class Glob {
         // Duplicated constants from File.Constants
         private static class Constants {
             public readonly static int FNM_CASEFOLD = 0x08;
@@ -125,20 +123,19 @@ namespace IronRuby.Builtins {
             return (charClass == null) ? result.ToString() : String.Empty;
         }
 
-        public static bool FnMatch(MutableString/*!*/ pattern, MutableString/*!*/ path, int flags) {
-            if (pattern.IsEmpty) {
-                return path.IsEmpty;
+        public static bool FnMatch(string/*!*/ pattern, string/*!*/ path, int flags) {
+            if (pattern.Length == 0) {
+                return path.Length == 0;
             }
 
             bool pathName = ((flags &amp; Constants.FNM_PATHNAME) != 0);
             bool noEscape = ((flags &amp; Constants.FNM_NOESCAPE) != 0);
-            string sPath = path.ConvertToString();
-            string regexPattern = PatternToRegex(pattern.ConvertToString(), pathName, noEscape);
+            string regexPattern = PatternToRegex(pattern, pathName, noEscape);
             if (regexPattern.Length == 0) {
                 return false;
             }
 
-            if (((flags &amp; Constants.FNM_DOTMATCH) == 0) &amp;&amp; sPath.Length &gt; 0 &amp;&amp; sPath[0] == '.') {
+            if (((flags &amp; Constants.FNM_DOTMATCH) == 0) &amp;&amp; path.Length &gt; 0 &amp;&amp; path[0] == '.') {
                 // Starting dot requires an explicit dot in the pattern
                 if (regexPattern.Length &lt; 4 || regexPattern[2] != '[' || regexPattern[3] != '.') {
                     return false;
@@ -149,7 +146,7 @@ namespace IronRuby.Builtins {
             if ((flags &amp; Constants.FNM_CASEFOLD) != 0) {
                 options |= RegexOptions.IgnoreCase;
             }
-            Match match = Regex.Match(sPath, regexPattern, options);
+            Match match = Regex.Match(path, regexPattern, options);
             return match != null &amp;&amp; match.Success &amp;&amp; (match.Length == path.Length);
         }
 
@@ -482,31 +479,29 @@ namespace IronRuby.Builtins {
                     return;
                 }
 
-                MutableString mPattern = MutableString.Create(dirSegment);
                 bool doubleStar = dirSegment.Equals(&quot;**&quot;);
                 if (doubleStar &amp;&amp; !isPreviousDoubleStar) {
                     DoGlob(baseDirectory, patternEnd, true);
                 }
 
-                string[] files = Directory.GetFileSystemEntries(baseDirectory);
-                foreach (string file in files) {
-                    string objectName = Path.GetFileName(file);
-                    if (FnMatch(mPattern, MutableString.Create(objectName), _flags)) {
+                foreach (string file in _pal.GetDirectories(baseDirectory, &quot;*&quot;).Concat(_pal.GetFiles(baseDirectory, &quot;*&quot;))) {
+                    string objectName = _pal.GetFileName(file);
+                    if (FnMatch(dirSegment, objectName, _flags)) {
                         TestPath(file, patternEnd, isLastPathSegment);
                         if (doubleStar) {
                             DoGlob(file, position, true);
                         }
                     }
                 }
-                if (isLastPathSegment &amp;&amp; (_flags &amp; Constants.FNM_DOTMATCH) != 0 || mPattern.GetChar(0) == '.') {
-                    if (FnMatch(mPattern, MutableString.Create(&quot;.&quot;), _flags)) {
+                if (isLastPathSegment &amp;&amp; (_flags &amp; Constants.FNM_DOTMATCH) != 0 || dirSegment[0] == '.') {
+                    if (FnMatch(dirSegment, &quot;.&quot;, _flags)) {
                         string directory = baseDirectory + &quot;/.&quot;;
                         if (_dirOnly) {
                             directory += '/';
                         }
                         TestPath(directory, patternEnd, true);
                     }
-                    if (FnMatch(mPattern, MutableString.Create(&quot;..&quot;), _flags)) {
+                    if (FnMatch(dirSegment, &quot;..&quot;, _flags)) {
                         string directory = baseDirectory + &quot;/..&quot;;
                         if (_dirOnly) {
                             directory += '/';
@@ -517,24 +512,19 @@ namespace IronRuby.Builtins {
             }
         }
 
-        private static IList&lt;string&gt;/*!*/ DoGlob(PlatformAdaptationLayer/*!*/ pal, string/*!*/ pattern, int flags) {
-            GlobMatcher matcher = new GlobMatcher(pal, pattern, flags);
-            return matcher.DoGlob();
-        }
-
-        public static IEnumerable&lt;string&gt;/*!*/ GlobResults(RubyContext/*!*/ context, string/*!*/ pattern, int flags) {
+        public static IEnumerable&lt;string&gt;/*!*/ GlobResults(PlatformAdaptationLayer/*!*/ pal, string/*!*/ pattern, int flags) {
             if (pattern.Length == 0) {
                 yield break;
             }
             bool noEscape = ((flags &amp; Constants.FNM_NOESCAPE) != 0);
-            string sPattern = pattern;
-            string[] groups = UngroupGlobs(sPattern, noEscape);
+            string[] groups = UngroupGlobs(pattern, noEscape);
             if (groups.Length == 0) {
                 yield break;
             }
 
             foreach (string group in groups) {
-                foreach (string filename in DoGlob(context.DomainManager.Platform, group, flags)) {                 
+                GlobMatcher matcher = new GlobMatcher(pal, group, flags);
+                foreach (string filename in matcher.DoGlob()) {                 
                     yield return filename;
                 }
             }</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/Glob.cs</filename>
    </modified>
    <modified>
      <diff>@@ -26,6 +26,7 @@ namespace IronRuby.Builtins {
 
         public Match/*!*/ Match { get { return _match; } }
         public MutableString/*!*/ OriginalString { get { return _originalString; } }
+        public RubyEncoding/*!*/ Encoding { get { return _originalString.Encoding; } }
         public bool Success { get { return _match.Success; } }
         public GroupCollection Groups { get { return _match.Groups; } }
         public int Index { get { return _match.Index; } }
@@ -69,7 +70,7 @@ namespace IronRuby.Builtins {
 
         public MutableString GetGroupValue(RubyContext/*!*/ context, int index) {
             var group = Groups[index];
-            return group.Success ? MutableString.Create(group.Value).TaintBy(this, context) : null;
+            return group.Success ? MutableString.Create(group.Value, Encoding).TaintBy(this, context) : null;
         }
 
         public Group/*!*/ GetExistingGroup(int index) {</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/MatchData.cs</filename>
    </modified>
    <modified>
      <diff>@@ -174,6 +174,10 @@ namespace IronRuby.Builtins {
                 return new BinaryContent(BinaryRegex.Escape(ToByteArray()), _owner);
             }
 
+            public override void CheckEncoding() {
+                _owner._encoding.StrictEncoding.GetCharCount(_data, 0, _count);
+            }
+
             #endregion
 
             #region CompareTo (read-only)
@@ -342,7 +346,9 @@ namespace IronRuby.Builtins {
             }
 
             public override void SetByte(int index, byte b) {
-                Debug.Assert(index &lt; _count);
+                if (index &gt;= _count) {
+                    throw new ArgumentOutOfRangeException(&quot;index&quot;);
+                }
                 _data[index] = b;
             }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/MutableString.BinaryContent.cs</filename>
    </modified>
    <modified>
      <diff>@@ -179,6 +179,10 @@ namespace IronRuby.Builtins {
                 return (sb != null) ? new CharArrayContent(sb.ToString().ToCharArray(), _owner) : this;
             }
 
+            public override void CheckEncoding() {
+                _owner._encoding.StrictEncoding.GetByteCount(_data, 0, _count);
+            }
+
             #endregion
 
             #region CompareTo (read-only)</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/MutableString.CharArrayContent.cs</filename>
    </modified>
    <modified>
      <diff>@@ -58,6 +58,7 @@ namespace IronRuby.Builtins {
             public abstract void SwitchToBinaryContent();
             public abstract void SwitchToStringContent();
             public abstract void SwitchToMutableContent();
+            public abstract void CheckEncoding();
 
             public abstract byte[]/*!*/ ToByteArray();
             internal abstract byte[]/*!*/ GetByteArray();</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/MutableString.Content.cs</filename>
    </modified>
    <modified>
      <diff>@@ -154,6 +154,10 @@ namespace IronRuby.Builtins {
                 return (sb != null) ? new StringContent(sb.ToString(), _owner) : this;
             }
 
+            public override void CheckEncoding() {
+                _owner._encoding.StrictEncoding.GetByteCount(_data);
+            }
+
             #endregion
 
             #region CompareTo (read-only)</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/MutableString.StringContent.cs</filename>
    </modified>
    <modified>
      <diff>@@ -131,29 +131,6 @@ namespace IronRuby.Builtins {
 
         #endregion
 
-        #region Obsolete
-
-        /// &lt;summary&gt;
-        /// Creates an empty textual MutableString.
-        /// &lt;/summary&gt;
-        public static MutableString/*!*/ CreateMutable() {
-            // TODO: encoding
-            return new MutableString(RubyEncoding.Obsolete);
-        }
-
-
-        // TODO: encoding
-        public static MutableString/*!*/ CreateMutable(string/*!*/ str) {
-            return new MutableString(str.ToCharArray(), RubyEncoding.Obsolete);
-        }
-
-        // TODO: encoding
-        public static MutableString/*!*/ Create(string/*!*/ str) {
-            return Create(str, RubyEncoding.Obsolete);
-        }
-
-        #endregion
-
         #region Factories
 
         public static MutableString/*!*/ CreateMutable(RubyEncoding/*!*/ encoding) {
@@ -171,6 +148,12 @@ namespace IronRuby.Builtins {
             return new MutableString(str, encoding);
         }
 
+        public static MutableString CreateAscii(string/*!*/ str) {
+            ContractUtils.RequiresNotNull(str, &quot;str&quot;);
+            Debug.Assert(str.IsAscii());
+            return Create(str, RubyEncoding.Binary);
+        }
+
         public static MutableString/*!*/ Create(string/*!*/ str, RubyEncoding/*!*/ encoding) {
             ContractUtils.RequiresNotNull(str, &quot;str&quot;);
             ContractUtils.RequiresNotNull(encoding, &quot;encoding&quot;);
@@ -181,6 +164,10 @@ namespace IronRuby.Builtins {
             return new MutableString(Utils.EmptyBytes, 0, RubyEncoding.Binary);
         }
 
+        public static MutableString/*!*/ CreateBinary(RubyEncoding/*!*/ encoding) {
+            return new MutableString(Utils.EmptyBytes, 0, encoding);
+        }
+
         public static MutableString/*!*/ CreateBinary(int capacity) {
             return CreateBinary(capacity, RubyEncoding.Binary);
         }
@@ -235,7 +222,7 @@ namespace IronRuby.Builtins {
         }
 
         public static MutableString/*!*/ CreateEmpty() {
-            return MutableString.Create(String.Empty);
+            return MutableString.Create(String.Empty, RubyEncoding.Binary);
         }
 
         /// &lt;summary&gt;
@@ -259,12 +246,14 @@ namespace IronRuby.Builtins {
             return Duplicate(context, copySingletonMembers, CreateInstance());
         }
 
-        public static MutableString[]/*!*/ MakeArray(ICollection&lt;string&gt;/*!*/ stringCollection) {
+        public static MutableString[]/*!*/ MakeArray(ICollection&lt;string&gt;/*!*/ stringCollection, RubyEncoding/*!*/ encoding) {
             ContractUtils.RequiresNotNull(stringCollection, &quot;stringCollection&quot;);
+            ContractUtils.RequiresNotNull(encoding, &quot;encoding&quot;);
+
             MutableString[] result = new MutableString[stringCollection.Count];
             int i = 0;
             foreach (var str in stringCollection) {
-                result[i++] = MutableString.Create(str);
+                result[i++] = MutableString.Create(str, encoding);
             }
             return result;
         }
@@ -464,6 +453,22 @@ namespace IronRuby.Builtins {
             //}
         }
 
+        /// &lt;summary&gt;
+        /// Checks if the string content is correctly encoded.
+        /// &lt;/summary&gt;
+        public MutableString/*!*/ CheckEncoding() {
+            try {
+                _content.CheckEncoding();
+            } catch (EncoderFallbackException) {
+                // TODO: better exception
+                throw;
+            } catch (DecoderFallbackException) {
+                // TODO: better exception
+                throw;
+            }
+            return this;
+        }
+
         public bool IsTainted {
             get {
                 return (_flags &amp; IsTaintedFlag) != 0; 
@@ -696,19 +701,31 @@ namespace IronRuby.Builtins {
             return _content.Count;
         }
 
-        public int SetLength(int value) {
-            ContractUtils.Requires(value &gt;= _content.Count);
-            return _content.Count = value;
+        public void SetLength(int value) {
+            ContractUtils.Requires(value &gt;= 0, &quot;value&quot;);
+            if (value &lt; _content.Count) {
+                _content.Remove(value, _content.Count - value);
+            } else {
+                _content.Count = value;
+            }
         }
 
         public int GetCharCount() {
             return _content.GetCharCount();
         }
 
+        public void SetCharCount(int value) {
+            SwitchToCharacters().SetLength(value);
+        }
+
         public int GetByteCount() {
             return _content.GetByteCount();
         }
 
+        public void SetByteCount(int value) {
+            SwitchToBytes().SetLength(value);
+        }
+
         public MutableString/*!*/ TrimExcess() {
             _content.TrimExcess();
             return this;
@@ -802,7 +819,8 @@ namespace IronRuby.Builtins {
         // TODO: binary ops, ...
         public MutableString[]/*!*/ Split(char[]/*!*/ separators, int maxComponents, StringSplitOptions options) {
             // TODO:
-            return MakeArray(StringUtils.Split(_content.ConvertToString(), separators, maxComponents, options));
+            // TODO (encoding):
+            return MakeArray(StringUtils.Split(_content.ConvertToString(), separators, maxComponents, options), _encoding);
         }
         
         #endregion
@@ -1024,6 +1042,15 @@ namespace IronRuby.Builtins {
             return this;
         }
 
+        public MutableString/*!*/ Append(char[]/*!*/ value, int start, int count) {
+            ContractUtils.RequiresNotNull(value, &quot;value&quot;);
+            ContractUtils.RequiresArrayRange(value, start, count, &quot;startIndex&quot;, &quot;count&quot;);
+
+            Mutate();
+            _content.Append(value, start, count);
+            return this;
+        }
+
         public MutableString/*!*/ Append(string value) {
             if (value != null) {
                 Mutate();
@@ -1059,7 +1086,8 @@ namespace IronRuby.Builtins {
         }
 
         /// &lt;summary&gt;
-        /// Reads &quot;count&quot; bytes from &quot;source&quot; stream and appends them to this string.
+        /// Reads at most &quot;count&quot; bytes from &quot;source&quot; stream and appends them to this string.
+        /// Allocates space for &quot;count&quot; bytes, so the string might need to be trimmed after the operation.
         /// &lt;/summary&gt;
         public MutableString/*!*/ Append(Stream/*!*/ stream, int count) {
             ContractUtils.RequiresNotNull(stream, &quot;stream&quot;);
@@ -1389,7 +1417,7 @@ namespace IronRuby.Builtins {
 
         #endregion
 
-        #region Quoted Representation
+        #region Quoted Representation (read-only)
 
 #if !SILVERLIGHT
         private sealed class DumpDecoderFallback : DecoderFallback {
@@ -1594,6 +1622,15 @@ namespace IronRuby.Builtins {
             }
         }
 
+        /// &lt;summary&gt;
+        /// Returns a string with all non-ASCII characters replaced by escaped Unicode or hexadecimal numeric sequences.
+        /// &lt;/summary&gt;
+        public string/*!*/ ToAsciiString() {
+            var result = AppendRepresentation(new StringBuilder(), false, true, -1).ToString();
+            Debug.Assert(result.IsAscii());
+            return result;
+        }
+
         public StringBuilder/*!*/ AppendRepresentation(StringBuilder/*!*/ result, bool octalEscapes, bool forceEscapes, int quote) {
             ContractUtils.RequiresNotNull(result, &quot;result&quot;);
 
@@ -1662,6 +1699,17 @@ namespace IronRuby.Builtins {
 
         #endregion
 
+        #region FormatMessage (read-only)
+
+        /// &lt;summary&gt;
+        /// Formats an error message that can be loaded from resources and thus localized.
+        /// &lt;/summary&gt;
+        public static MutableString/*!*/ FormatMessage(string/*!*/ message, params MutableString[]/*!*/ args) {
+            return MutableString.Create(String.Format(message, args), RubyEncoding.UTF8);
+        }
+
+        #endregion
+
         #region Internal Helpers
 
         internal byte[]/*!*/ GetByteArray() {</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/MutableString.cs</filename>
    </modified>
    <modified>
      <diff>@@ -137,9 +137,9 @@ namespace IronRuby.Builtins {
             object value = ToValue();
             string str = value as string;
             if (str != null) {
-                return MutableString.Create(str);
+                return MutableString.Create(str, _encoding);
             } else {
-                return MutableString.CreateBinary((byte[])value);
+                return MutableString.CreateBinary((byte[])value, _encoding);
             }
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/MutableStringBuilder.cs</filename>
    </modified>
    <modified>
      <diff>@@ -24,7 +24,7 @@ namespace IronRuby.Builtins {
         private int _position;
 
         public MutableStringStream() 
-            : this(MutableString.CreateMutable()) {
+            : this(MutableString.CreateBinary()) {
         }
 
         public MutableStringStream(MutableString/*!*/ basis) {
@@ -57,7 +57,7 @@ namespace IronRuby.Builtins {
         }
 
         public override long Length {
-            get { return _string.ConvertToBytes().Length; }
+            get { return _string.GetByteCount(); }
         }
 
         public override long Position {
@@ -91,31 +91,11 @@ namespace IronRuby.Builtins {
         }
 
         public override long Seek(long offset, SeekOrigin origin) {
-            int byteCount = _string.GetByteCount();
-
-            int position = _position;
-            switch (origin) {
-                case SeekOrigin.Begin:
-                    position = (int)offset;
-                    break;
-                case SeekOrigin.End:
-                    position = byteCount + (int)offset;
-                    break;
-                case SeekOrigin.Current:
-                    position += (int)offset;
-                    break;
-            }
-            Position = position;
-            return Position;
+            return Position = RubyIO.GetSeekPosition(_string.GetByteCount(), _position, offset, origin);
         }
 
         public override void SetLength(long value) {
-            int byteCount = _string.GetByteCount();
-            if (byteCount &lt; value) {
-                _string.Append(0, (int)(value - byteCount));
-            } else if (byteCount &gt; value) {
-                _string.Remove((int)value, byteCount - (int)value);
-            }
+            _string.SetByteCount((int)value);
         }
 
         public override void Write(byte[]/*!*/ buffer, int offset, int count) {</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/MutableStringStream.cs</filename>
    </modified>
    <modified>
      <diff>@@ -136,7 +136,7 @@ namespace IronRuby.Builtins {
         }
 
         public MutableString/*!*/ Inspect(RubyContext/*!*/ context) {
-            var result = MutableString.CreateMutable();
+            var result = MutableString.CreateMutable(RubyEncoding.Binary);
             result.Append(context.Inspect(_begin));
             result.Append(Separator);
             result.Append(context.Inspect(_end));</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/Range.cs</filename>
    </modified>
    <modified>
      <diff>@@ -99,17 +99,22 @@ namespace IronRuby.Builtins {
         #region Dynamic Sites
 
         private CallSite&lt;Func&lt;CallSite, object, object&gt;&gt; _inspectSite;
-        private CallSite&lt;Func&lt;CallSite, object, MutableString&gt;&gt; _stringConversionSite;
+        private CallSite&lt;Func&lt;CallSite, object, MutableString&gt;&gt; _inspectResultConversionSite;
         private CallSite&lt;Func&lt;CallSite, object, object, object&gt;&gt; _eqlSite;
         private CallSite&lt;Func&lt;CallSite, object, object&gt;&gt; _hashSite;
         private CallSite&lt;Func&lt;CallSite, object, object&gt;&gt; _toStringSite;
+        private CallSite&lt;Func&lt;CallSite, object, object, object&gt;&gt; _newSite;
 
         public CallSite&lt;Func&lt;CallSite, object, object&gt;&gt;/*!*/ InspectSite { 
             get { return RubyUtils.GetCallSite(ref _inspectSite, Context, &quot;inspect&quot;, 0); } 
         }
+
+        public CallSite&lt;Func&lt;CallSite, object, object, object&gt;&gt;/*!*/ NewSite {
+            get { return RubyUtils.GetCallSite(ref _newSite, Context, &quot;new&quot;, 1); }
+        }
         
-        public CallSite&lt;Func&lt;CallSite, object, MutableString&gt;&gt;/*!*/ StringConversionSite {
-            get { return RubyUtils.GetCallSite(ref _stringConversionSite, ConvertToSAction.Make(Context)); } 
+        public CallSite&lt;Func&lt;CallSite, object, MutableString&gt;&gt;/*!*/ InspectResultConversionSite {
+            get { return RubyUtils.GetCallSite(ref _inspectResultConversionSite, ConvertToSAction.Make(Context)); } 
         }
 
         public CallSite&lt;Func&lt;CallSite, object, object, object&gt;&gt;/*!*/ EqualsSite {
@@ -742,12 +747,12 @@ namespace IronRuby.Builtins {
             }
 
             string operatorName;
-            if (!_isSingletonClass &amp;&amp; (operatorName = RubyUtils.MapOperator(name)) != null) {
+            if (tryUnmangle &amp;&amp; !_isSingletonClass &amp;&amp; (operatorName = RubyUtils.MapOperator(name)) != null) {
                 // instance invocation of an operator:
                 if (TryGetClrMethod(type, basicBindingFlags | BindingFlags.Static, true, name, null, operatorName, null, out method)) {
                     return true;
                 }
-            } else if (name == &quot;[]&quot; || name == &quot;[]=&quot;) {
+            } else if (tryUnmangle &amp;&amp; (name == &quot;[]&quot; || name == &quot;[]=&quot;)) {
                 if (type.IsArray &amp;&amp; !_isSingletonClass) {
                     bool isSetter = name.Length == 3;
                     TryGetClrMethod(type, bindingFlags, false, name, null, isSetter ? &quot;Set&quot; : &quot;Get&quot;, null, out method);
@@ -1281,13 +1286,20 @@ namespace IronRuby.Builtins {
 
                 RubyMethodGroupInfo.BuildCallNoFlow(metaBuilder, args, methodName, constructionOverloads, callConvention, implicitProtocolConversions);
 
-                // we need to handle break, which unwinds to a proc-converter that could be this method's frame:
                 if (!metaBuilder.Error) {
+                    metaBuilder.Result = MarkNewException(metaBuilder.Result);
+
+                    // we need to handle break, which unwinds to a proc-converter that could be this method's frame:
                     metaBuilder.ControlFlowBuilder = RubyMethodGroupInfo.RuleControlFlowBuilder;
                 }
             }
         }
 
+        private Expression/*!*/ MarkNewException(Expression/*!*/ expression) {
+            // mark the exception as &quot;Ruby created&quot; so that &quot;new&quot; is not called again on its class when handled in rescue clause:
+            return IsException() ? Methods.MarkException.OpCall(AstUtils.Convert(expression, typeof(Exception))) : expression;
+        }
+
         private static void BuildOverriddenInitializerCall(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, RubyMemberInfo/*!*/ initializer) {
             var instanceExpr = metaBuilder.Result;
             metaBuilder.Result = null;
@@ -1330,6 +1342,16 @@ namespace IronRuby.Builtins {
         }
 
         public bool BuildAllocatorCall(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, Func&lt;Expression&gt;/*!*/ defaultExceptionMessage) {
+            var newExpression = GetAllocatorNewExpression(args, defaultExceptionMessage);
+            if (newExpression != null) {
+                metaBuilder.Result = MarkNewException(newExpression);
+                return true;
+            } else {
+                return false;
+            }
+        }
+
+        private Expression GetAllocatorNewExpression(CallArguments/*!*/ args, Func&lt;Expression&gt;/*!*/ defaultExceptionMessage) {
             Type type = GetUnderlyingSystemType();
 
             if (type == typeof(object)) {
@@ -1337,42 +1359,35 @@ namespace IronRuby.Builtins {
             }
 
             if (_structInfo != null) {
-                metaBuilder.Result = Methods.AllocateStructInstance.OpCall(AstUtils.Convert(args.TargetExpression, typeof(RubyClass)));
-                return true;
+                return Methods.AllocateStructInstance.OpCall(AstUtils.Convert(args.TargetExpression, typeof(RubyClass)));
             }
 
             ConstructorInfo ctor;
             if (IsException()) {
                 if ((ctor = type.GetConstructor(new[] { typeof(string) })) != null) {
-                    metaBuilder.Result = Ast.New(ctor, defaultExceptionMessage());
-                    return true;
+                    return Ast.New(ctor, defaultExceptionMessage());
                 } else if ((ctor = type.GetConstructor(new[] { typeof(string), typeof(Exception) })) != null) {
-                    metaBuilder.Result = Ast.New(ctor, defaultExceptionMessage(), AstUtils.Constant(null));
-                    return true;
+                    return Ast.New(ctor, defaultExceptionMessage(), AstUtils.Constant(null));
                 }
             }
 
             if ((ctor = type.GetConstructor(new[] { typeof(RubyClass) })) != null) {
-                metaBuilder.Result = Ast.New(ctor, AstUtils.Convert(args.TargetExpression, typeof(RubyClass)));
-                return true;
+                return Ast.New(ctor, AstUtils.Convert(args.TargetExpression, typeof(RubyClass)));
             }
 
             if ((ctor = type.GetConstructor(new[] { typeof(RubyContext) })) != null) {
-                metaBuilder.Result = Ast.New(ctor, AstUtils.Convert(args.MetaContext.Expression, typeof(RubyContext)));
-                return true;
+                return Ast.New(ctor, AstUtils.Convert(args.MetaContext.Expression, typeof(RubyContext)));
             }
 
             if ((ctor = type.GetConstructor(Type.EmptyTypes)) != null) {
-                metaBuilder.Result = Ast.New(ctor);
-                return true;
+                return Ast.New(ctor);
             }
 
             if (type.IsValueType &amp;&amp; type != typeof(int) &amp;&amp; type != typeof(double)) {
-                metaBuilder.Result = Ast.New(type);
-                return true;
+                return Ast.New(type);
             }
 
-            return false;
+            return null;
         }
 
         private void BuildDelegateConstructorCall(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, Type/*!*/ type) {</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyClass.cs</filename>
    </modified>
    <modified>
      <diff>@@ -42,6 +42,9 @@ namespace IronRuby.Builtins {
 
         public static readonly RubyEncoding/*!*/ Binary = new RubyEncoding(BinaryEncoding.Instance, BinaryEncoding.Instance, null);
         public static readonly RubyEncoding/*!*/ UTF8 = new RubyEncoding(new UTF8Encoding(false, false), new UTF8Encoding(false, true), null);
+        public static readonly RubyEncoding/*!*/ ClassName = UTF8; // TODO: remove
+        public static readonly RubyEncoding/*!*/ Symbol = UTF8; // TODO: remove
+        public static readonly RubyEncoding/*!*/ Path = UTF8; // TODO: remove
         public static readonly RubyEncoding/*!*/ Obsolete = Binary;
         
         private static RubyEncoding _default;
@@ -132,7 +135,7 @@ namespace IronRuby.Builtins {
             get { return _encoding; }
         }
 
-        internal Encoding/*!*/ StrictEncoding {
+        public Encoding/*!*/ StrictEncoding {
             get { return _strictEncoding; }
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyEncoding.cs</filename>
    </modified>
    <modified>
      <diff>@@ -31,7 +31,7 @@ namespace IronRuby.Builtins {
         public static string/*!*/ MakeMessage(ref MutableString message, string/*!*/ baseMessage) {
             Assert.NotNull(baseMessage);
             string result = MakeMessage(message != null ? message.ConvertToString() : null, baseMessage);
-            message = MutableString.Create(result);
+            message = MutableString.Create(result, message != null ? message.Encoding : RubyEncoding.UTF8);
             return result;
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyErrno.cs</filename>
    </modified>
    <modified>
      <diff>@@ -16,134 +16,121 @@
 using System;
 using System.IO;
 using System.Threading;
-using Microsoft.Scripting.Runtime;
-using Microsoft.Scripting.Utils;
 using IronRuby.Runtime;
-using System.Text;
-using System.Diagnostics;
+using Microsoft.Scripting.Utils;
 
 namespace IronRuby.Builtins {
-    public enum IOMode {
-        ReadOnlyFromStart,
-        ReadWriteFromStart,
-        WriteOnlyTruncate,
-        ReadWriteTruncate,
-        WriteOnlyAppend,
-        ReadWriteAppend,
-        Closed,
-    }
-
     /// &lt;summary&gt;
     /// IO builtin class. Wraps a BCL Stream object. Implementation of Ruby methods is in IoOps.cs in IronRuby.Libraries assembly.
     /// &lt;/summary&gt;
     public class RubyIO : IDisposable {
         private RubyContext/*!*/ _context;
-        private Encoding/*!*/ _externalEncoding;
-        private Encoding _internalEncoding;
+        private RubyEncoding/*!*/ _externalEncoding;
+        private RubyEncoding _internalEncoding;
 
-        private Stream _stream;
-        private bool _preserveEndOfLines;
-
-        private IOMode _mode;
+        // -1 if uninitialized or closed:
         private int _fileDescriptor;
-        private bool _disposed;
-        private bool _closed;
+
+        // null if uninitialized or closed:
+        private RubyBufferedStream _stream;
+
         private bool _autoFlush;
-        private int _peekAhead;
+        private IOMode _mode;
+        public int LineNumber { get; set; }
+
+        #region Constants
 
         public const int SEEK_SET = 0;
         public const int SEEK_CUR = 1;
         public const int SEEK_END = 2;
 
-        private const byte CR = (byte)'\r';
-        private const byte LF = (byte)'\n';
+        public static SeekOrigin ToSeekOrigin(int rubySeekOrigin) {
+            switch (rubySeekOrigin) {
+                case SEEK_SET: return SeekOrigin.Begin;
+                case SEEK_END: return SeekOrigin.End;
+                case SEEK_CUR: return SeekOrigin.Current;
+                default: throw RubyExceptions.CreateArgumentError(&quot;Invalid argument&quot;);
+            }
+        }
+
+        public static long GetSeekPosition(long length, long position, long seekOffset, SeekOrigin origin) {
+            switch (origin) {
+                case SeekOrigin.Begin: return seekOffset;
+                case SeekOrigin.End: return length + seekOffset;
+                case SeekOrigin.Current: return position + seekOffset;
+            }
+            throw Assert.Unreachable;
+        }
+
+        #endregion
 
         #region Construction
 
         public RubyIO(RubyContext/*!*/ context) {
+            ContractUtils.RequiresNotNull(context, &quot;context&quot;);
+
             _context = context;
-            _fileDescriptor = context.AddDescriptor(this);
-            _disposed = false;
-            _closed = false;
-            _peekAhead = -1;
-            _stream = Stream.Null;
-
-            // TODO: enable setting
-            _externalEncoding = BinaryEncoding.Instance;
+            _fileDescriptor = -1;
+            _stream = null;
+
+            // TODO (encoding): enable setting
+            _externalEncoding = RubyEncoding.Binary;
             _internalEncoding = null;
         }
 
-        public RubyIO(RubyContext/*!*/ context, Stream/*!*/ stream, string/*!*/ modeString)
-            : this(context) {
-            ContractUtils.RequiresNotNull(stream, &quot;stream&quot;);
-            ContractUtils.RequiresNotNull(modeString, &quot;modeString&quot;);
-
-            _mode = ParseIOMode(modeString, out _preserveEndOfLines);
-            _stream = stream;
-
-            ResetLineNumbersForReadOnlyFiles(context);
+        public RubyIO(RubyContext/*!*/ context, Stream/*!*/ stream, IOMode mode) 
+            : this(context, stream, context.AllocateFileDescriptor(stream), mode) {
         }
 
-        // TODO: hack
-        public RubyIO(RubyContext/*!*/ context, StreamReader reader, StreamWriter writer, string/*!*/ modeString)
-            : this(context) {
-            _mode = ParseIOMode(modeString, out _preserveEndOfLines);
-            _stream = new DuplexStream(reader, writer);
-
-            ResetLineNumbersForReadOnlyFiles(context);
+        public RubyIO(RubyContext/*!*/ context, StreamReader reader, StreamWriter writer, IOMode mode)
+            : this(context, new DuplexStream(reader, writer), mode) {
         }
 
-
-        public RubyIO(RubyContext/*!*/ context, Stream/*!*/ stream, RubyFileMode mode)
+        public RubyIO(RubyContext/*!*/ context, Stream/*!*/ stream, int descriptor, IOMode mode) 
             : this(context) {
+            ContractUtils.RequiresNotNull(context, &quot;context&quot;);
             ContractUtils.RequiresNotNull(stream, &quot;stream&quot;);
+            _stream = new RubyBufferedStream(stream);
+            _mode = mode;
+            _fileDescriptor = descriptor;
+        }
 
-            _mode = ParseIOMode(mode, out _preserveEndOfLines);
-            _stream = stream;
+        #endregion
 
-            ResetLineNumbersForReadOnlyFiles(context);
-        }
+        #region Descriptor, Encoding, Flags
 
-        private void ResetLineNumbersForReadOnlyFiles(RubyContext/*!*/ context) {
-            if (RubyIO.IsReadable(_mode)) {
-                context.InputProvider.LastInputLineNumber = 0;
-            }
+        public RubyContext/*!*/ Context {
+            get { return _context; }
         }
 
-        #endregion
-
-        public Encoding ExternalEncoding {
+        public RubyEncoding ExternalEncoding {
             get { return _externalEncoding; }
         }
 
-        public Encoding InternalEncoding {
+        public RubyEncoding InternalEncoding {
             get { return _internalEncoding; }
         }
 
-        public int FileDescriptor {
-            get { return _fileDescriptor; }
+        public int GetFileDescriptor() {
+            RequireOpen();
+            return _fileDescriptor;
         }
 
-        public IOMode Mode {
-            get { return _mode; }
-        }
-
-        protected Stream/*!*/ Stream {
-            get {
-                if (_stream == null) {
-                    throw RubyExceptions.CreateIOError(&quot;uninitialized stream&quot;);
-                }
-
-                return _stream; 
-            }
+        public void SetFileDescriptor(int value) {
+            ContractUtils.Requires(value &gt;= 0);
+            RequireOpen();
+            _fileDescriptor = value; 
         }
 
         public bool IsConsole {
-            get { return _stream is ConsoleStream; } 
+            get {
+                var stream = GetStream();
+                return stream.BaseStream is ConsoleStream || stream.BaseStream == Stream.Null; 
+            } 
         }
 
         internal static bool IsConsoleDescriptor(int fileDescriptor) {
-            return (fileDescriptor &lt; 3);
+            return fileDescriptor &gt;= 0 &amp;&amp; fileDescriptor &lt; 3;
         }
 
         public bool IsConsoleDescriptor() {
@@ -151,461 +138,319 @@ namespace IronRuby.Builtins {
         }
 
         public bool Closed {
-            get { return _closed; }
-            set { _closed = value; }
+            get { return _mode.IsClosed(); }
         }
 
         public bool PreserveEndOfLines {
-            get { return _preserveEndOfLines; }
-            set { _preserveEndOfLines = value; }
-        }
-
-        #region Mode
-
-        public static IOMode ParseIOMode(RubyFileMode mode, out bool preserveEndOfLines) {
-            preserveEndOfLines = ((mode &amp; RubyFileMode.BINARY) != 0);
-
-            IOMode io;
-            RubyFileMode readWriteMode = mode &amp; RubyFileMode.ReadWriteMask;
-
-            if (readWriteMode == RubyFileMode.WRONLY) {
-                io = ((mode &amp; RubyFileMode.APPEND) != 0) ? IOMode.WriteOnlyAppend : IOMode.WriteOnlyTruncate;
-            } else if (readWriteMode == RubyFileMode.RDONLY) {
-                io = ((mode &amp; RubyFileMode.APPEND) != 0) ? IOMode.ReadWriteFromStart : IOMode.ReadOnlyFromStart;
-            } else if (readWriteMode == RubyFileMode.RDWR) {
-                io = ((mode &amp; RubyFileMode.APPEND) != 0) ? IOMode.ReadWriteAppend : IOMode.ReadWriteFromStart;
-            } else {
-                throw new ArgumentException(&quot;file mode must be one of WRONLY, RDONLY, RDWR&quot;);
+            get { 
+                return (_mode &amp; IOMode.PreserveEndOfLines) != 0; 
             }
-
-            return io;
-        }
-
-        public static IOMode ParseIOMode(string/*!*/ mode, out bool preserveEndOfLines) {
-            int i = mode.Length - 1;
-            if (i &lt; 0) {
-                // empty:
-                preserveEndOfLines = false;
-                return IOMode.ReadOnlyFromStart;
-            }
-
-            bool plus = (mode[i] == '+');
-            if (plus) {
-                i--;
-            }
-
-            if (i &lt; 0) {
-                throw IllegalMode(mode);
-            }
-
-            preserveEndOfLines = (mode[i] == 'b');
-            if (preserveEndOfLines) {
-                i--;
-            }
-
-            if (i != 0) {
-                throw IllegalMode(mode);
+            set {
+                if (value) {
+                    _mode |= IOMode.PreserveEndOfLines;
+                } else {
+                    _mode &amp;= ~IOMode.PreserveEndOfLines;
+                }
             }
+        }
 
-            switch (mode[0]) {
-                case 'r':
-                    return plus ? IOMode.ReadWriteFromStart : IOMode.ReadOnlyFromStart;
+        public bool AutoFlush {
+            get { return _autoFlush; }
+            set { _autoFlush = value; }
+        }
 
-                case 'w':
-                    return plus ? IOMode.ReadWriteTruncate : IOMode.WriteOnlyTruncate;
+        #endregion
 
-                case 'a':
-                    return plus ? IOMode.ReadWriteAppend : IOMode.WriteOnlyAppend;
+        #region Basic Stream Operations
 
-                default:
-                    throw IllegalMode(mode);
+        public RubyBufferedStream/*!*/ GetStream() {
+            if (Closed) {
+                throw RubyExceptions.CreateIOError(&quot;closed stream&quot;);
             }
-        }
 
-        internal static ArgumentException/*!*/ IllegalMode(string modeString) {
-            return new ArgumentException(String.Format(&quot;illegal access mode {0}&quot;, modeString));
-        }
-
-        public static bool IsReadable(IOMode mode) {
-            return (mode == IOMode.ReadOnlyFromStart || 
-                mode == IOMode.ReadWriteAppend || 
-                mode == IOMode.ReadWriteFromStart || 
-                mode == IOMode.ReadWriteTruncate);
-        }
-
-        #endregion
-        
-        #region IDisposable Members
-
-        protected virtual void Dispose(bool disposing) {
-            if (!_disposed) {
-                if (disposing) {
-                    if (_stream != null) {
-                        _stream.Dispose();
-                        _stream = null;
-                    }
-                }
-                _disposed = true;
+            if (_stream == null) {
+                throw RubyExceptions.CreateIOError(&quot;uninitialized stream&quot;);
             }
-        }
 
-        public void Dispose() {
-            Dispose(true);
-            GC.SuppressFinalize(this);
+            return _stream;
         }
 
-        ~RubyIO() {
-            Dispose(false);
+        public void SetStream(Stream/*!*/ stream) {
+            ContractUtils.RequiresNotNull(stream, &quot;stream&quot;);
+            _stream = new RubyBufferedStream(stream);
         }
 
-        #endregion
-
-        #region Instance methods
-
-        public virtual WaitHandle/*!*/ CreateReadWaitHandle() {
-            // TODO:
-            throw new NotSupportedException();
+        public void RequireOpen() {
+            GetStream();
         }
 
-        public virtual WaitHandle/*!*/ CreateWriteWaitHandle() {
-            // TODO:
-            throw new NotSupportedException();
+        public void RequireWritable() {
+            GetWritableStream();
         }
 
-        public virtual WaitHandle/*!*/ CreateErrorWaitHandle() {
-            // TODO:
-            throw new NotSupportedException();
+        public void RequireReadable() {
+            GetReadableStream();
         }
 
-        public virtual int FileControl(int commandId, int arg) {
-            // TODO:
-            throw new NotSupportedException();
+        public RubyBufferedStream/*!*/ GetWritableStream() {
+            var result = GetStream();
+            if (!_mode.CanWrite()) {
+                throw RubyExceptions.CreateIOError(&quot;not opened for writing&quot;);
+            }
+            if (!result.CanWrite) {
+                throw RubyExceptions.CreateEBADF();
+            }
+            return result;
         }
 
-        public virtual int FileControl(int commandId, byte[] arg) {
-            // TODO:
-            throw new NotSupportedException();
-        }
-        
-        public void ResetIOMode(string/*!*/ modeString) {
-            _mode = ParseIOMode(modeString, out _preserveEndOfLines);
+        public RubyBufferedStream/*!*/ GetReadableStream() {
+            var result = GetStream();
+            if (!_mode.CanRead()) {
+                throw RubyExceptions.CreateIOError(&quot;not opened for reading&quot;);
+            }
+            if (!result.CanRead) {
+                throw RubyExceptions.CreateEBADF();
+            }
+            return result;
         }
 
         public long Position {
             get {
-                Assert.NotNull(_stream);
-                return _stream.Position;
+                var stream = GetStream();
+                try {
+                    return stream.Position;
+                } catch (ObjectDisposedException) {
+                    throw RubyExceptions.CreateEBADF();
+                }
+            }
+            set {
+                var stream = GetStream();
+                try {
+                    stream.Position = value;
+                } catch (ObjectDisposedException) {
+                    throw RubyExceptions.CreateEBADF();
+                }
             }
         }
 
-        public bool AutoFlush {
-            get { return _autoFlush; }
-            set { _autoFlush = value; }
+        public void Seek(long offset, SeekOrigin origin) {
+            var stream = GetStream();
+            try {
+                stream.Seek(offset, origin);
+            } catch (IOException) {
+                throw RubyExceptions.CreateEINVAL();
+            } catch (ObjectDisposedException) {
+                throw RubyExceptions.CreateEBADF();
+            }
         }
 
-        public void AssertNotClosed() {
-            if (_closed) {
-                throw RubyExceptions.CreateIOError(&quot;closed stream&quot;);
+        public void Flush() {
+            var stream = GetStream();
+            try {
+                stream.Flush();
+            } catch (ObjectDisposedException) {
+                throw RubyExceptions.CreateEBADF();
             }
         }
 
-        public void AssertOpenedForWriting() {
-            AssertNotClosed();
-            if (_mode == IOMode.ReadOnlyFromStart) {
-                throw RubyExceptions.CreateIOError(&quot;not opened for writing&quot;);
+        public long Length {
+            get {
+                var stream = GetStream();
+                try {
+                    return stream.Length;
+                } catch (ObjectDisposedException) {
+                    throw RubyExceptions.CreateEBADF();
+                }
             }
-        }
 
-        public void AssertOpenedForReading() {
-            AssertNotClosed();
-            if (_mode == IOMode.WriteOnlyAppend || _mode == IOMode.WriteOnlyTruncate) {
-                throw RubyExceptions.CreateIOError(&quot;not opened for reading&quot;);
+            set {
+                var stream = GetStream();
+                try {
+                    stream.SetLength(value);
+                } catch (ObjectDisposedException) {
+                    throw RubyExceptions.CreateIOError(&quot;closed stream&quot;);
+                } catch (NotSupportedException) {
+                    throw RubyExceptions.CreateIOError(&quot;not opened for writing&quot;);
+                }
             }
         }
 
-        public BinaryReader/*!*/ GetBinaryReader() {
-            AssertOpenedForReading();
-            return new BinaryReader(_stream);
+        public int WriteBytes(byte[]/*!*/ buffer, int index, int count) {
+            ContractUtils.RequiresNotNull(buffer, &quot;buffer&quot;);
+            return WriteBytes(buffer, null, index, count);
         }
 
-        public BinaryWriter/*!*/ GetBinaryWriter() {
-            AssertOpenedForWriting();
-            return new BinaryWriter(_stream);
+        public int WriteBytes(MutableString/*!*/ buffer, int index, int count) {
+            ContractUtils.RequiresNotNull(buffer, &quot;buffer&quot;);
+            return WriteBytes(null, buffer, index, count);
         }
 
-        public bool IsEndOfStream() {
-            return PeekByte() == -1;
+        // TODO: transcoding
+        private int WriteBytes(byte[] bytes, MutableString str, int index, int count) {
+            var stream = GetWritableStream();
+
+            if ((_mode &amp; IOMode.WriteAppends) != 0 &amp;&amp; stream.CanSeek) {
+                stream.Seek(0, SeekOrigin.End);
+            }
+
+            try {
+                if (bytes != null) {
+                    return stream.WriteBytes(bytes, index, count, PreserveEndOfLines);
+                } else {
+                    return stream.WriteBytes(str, index, count, PreserveEndOfLines);
+                }
+            } catch (ObjectDisposedException) {
+                throw RubyExceptions.CreateEBADF();
+            }
+        }
+
+        public void Dispose() {
+            Close();
         }
 
         public void Close() {
+            int fd = _fileDescriptor;
+            _mode = _mode.Close();
+            _fileDescriptor = -1;
+
             if (_stream != null) {
-                _stream.Close();
+                _stream = null;
+                _context.CloseStream(fd);
             }
-            _closed = true;
         }
 
-        // TODO:
         public void CloseWriter() {
-            var duplex = _stream as DuplexStream;
-            if (duplex == null) {
+            var duplex = GetStream().BaseStream as DuplexStream;
+            if (duplex == null &amp;&amp; _mode.CanRead() || duplex != null &amp;&amp; !_mode.CanWrite()) {
                 throw RubyExceptions.CreateIOError(&quot;closing non-duplex IO for writing&quot;);
             }
-            duplex.Writer.Close();
+            
+            if (duplex != null) {
+                duplex.Writer.Close();
+            }
+
+            _mode = _mode.CloseWrite();
+            if (_mode.IsClosed()) {
+                Close();
+            }
         }
 
-        // TODO:
         public void CloseReader() {
-            var duplex = _stream as DuplexStream;
-            if (duplex == null) {
+            var duplex = GetStream().BaseStream as DuplexStream;
+            if (duplex == null &amp;&amp; _mode.CanWrite() || duplex != null &amp;&amp; !_mode.CanRead()) {
                 throw RubyExceptions.CreateIOError(&quot;closing non-duplex IO for reading&quot;);
+            } 
+            
+            if (duplex != null) {
+                duplex.Reader.Close();
             }
-            duplex.Reader.Close();
-        }
 
-        public long Seek(long offset, SeekOrigin origin) {
-            return _stream.Seek(offset, origin);
+            _mode = _mode.CloseRead();
+            if (_mode.IsClosed()) {
+                Close();
+            }
         }
 
-        public void Flush() {
-            _stream.Flush();
+        public IOMode Mode {
+            get { return _mode; }
+            set { _mode = value; }
         }
 
-        public long Length {
-            get { return _stream.Length; }
-        }
+        #endregion
 
-        // returns the number of bytes written to the stream:
-        public int Write(char[]/*!*/ buffer, int index, int count) {
-            byte[] bytes = _externalEncoding.GetBytes(buffer, index, count);
-            Write(bytes, 0, bytes.Length);
-            return bytes.Length;
-        }
+        #region Operations
 
-        // returns the number of bytes written to the stream:
-        public int Write(string/*!*/ value) {
-            byte[] bytes = _externalEncoding.GetBytes(value);
-            Write(bytes, 0, bytes.Length);
-            return bytes.Length;
+        public virtual WaitHandle/*!*/ CreateReadWaitHandle() {
+            // TODO:
+            throw new NotSupportedException();
         }
 
-        // returns the number of bytes written to the stream:
-        public int Write(MutableString/*!*/ value) {
-            byte[] bytes = value.ToByteArray();
-            return Write(bytes, 0, bytes.Length);
-        }
-
-        public int Write(byte[]/*!*/ buffer, int index, int count) {
-            if (_preserveEndOfLines) {
-                _stream.Write(buffer, index, count);
-                return buffer.Length;
-            } else {
-                int bytesWritten = 0;
-                int i = index;
-                while (i &lt; count) {
-                    int j = i;
-                    while (j &lt; buffer.Length &amp;&amp; buffer[j] != LF) {
-                        j++;
-                    }
-                    _stream.Write(buffer, i, j - i);
-                    bytesWritten += j - i;
-
-                    if (j &lt; buffer.Length) {
-                        _stream.WriteByte(CR);
-                        _stream.WriteByte(LF);
-                        bytesWritten += 2;
-                    }
-
-                    i = j + 1;
-                }
-
-                return bytesWritten;
-            }
+        public virtual WaitHandle/*!*/ CreateWriteWaitHandle() {
+            // TODO:
+            throw new NotSupportedException();
         }
 
-        public int PeekByte() {
-            int result;
-            if (_peekAhead != -1) {
-                result = _peekAhead;
-            } else if (!_stream.CanSeek) {
-                result = _stream.ReadByte();
-                _peekAhead = result;
-            } else {
-                long pos = _stream.Position;
-                result = _stream.ReadByte();
-                _stream.Position = pos;
-            }
-            return result;
+        public virtual WaitHandle/*!*/ CreateErrorWaitHandle() {
+            // TODO:
+            throw new NotSupportedException();
         }
 
-        public int ReadByte() {
-            if (_peekAhead != -1) {
-                int result = _peekAhead;
-                _peekAhead = -1;
-                return result;
-            }
-            return _stream.ReadByte();
-        }
+        public virtual int FileControl(int commandId, int arg) {
+            GetStream();
 
-        public int ReadBytes(byte[]/*!*/ buffer, int offset, int count) {
-            return _stream.Read(buffer, offset, count);
+            // TODO:
+            throw new NotSupportedException();
         }
 
-        public int AppendBytes(MutableString/*!*/ buffer, int count) {
-            ContractUtils.RequiresNotNull(buffer, &quot;buffer&quot;);
-            ContractUtils.Requires(count &gt;= 0, &quot;count&quot;);
-
-            if (count == 0) {
-                return 0;
-            }
-
-            buffer.SwitchToBytes();
-            int initialBufferSize = buffer.GetByteCount();
-            if (_preserveEndOfLines) {
-                AppendRawBytes(buffer, count);
-            } else {
-                // allocate 3 more bytes at the end for a backstop and possible LF:
-                buffer.EnsureCapacity(initialBufferSize + count + 3);
-                byte[] bytes = buffer.GetByteArray();
-
-                int done = initialBufferSize;
-                bool eof;
-                do {
-                    AppendRawBytes(buffer, count);
-                    int end = buffer.GetByteCount();
-                    int bytesRead = end - done;
-                    if (bytesRead == 0) {
-                        break;
-                    }
-                    eof = bytesRead &lt; count;
-
-                    if (bytes[end - 1] == CR &amp;&amp; PeekByte() == LF) {
-                        ReadByte();
-                        bytes[end++] = LF;
-                    }
-
-                    // insert backstop:
-                    bytes[end] = CR;
-                    bytes[end + 1] = LF;
-
-                    int last = IndexOfCrLf(bytes, done);
-                    count -= last - done;
-                    done = last;
-                    while (last &lt; end) {
-                        int next = IndexOfCrLf(bytes, last + 2);
-                        int chunk = next - last - 1;
-                        Buffer.BlockCopy(bytes, last + 1, bytes, done, chunk);
-                        done += chunk;
-                        count -= chunk;
-                        last = next;
-                    }
-                    buffer.Remove(done);
-                } while (count &gt; 0 &amp;&amp; !eof);
-            }
+        public virtual int FileControl(int commandId, byte[] arg) {
+            GetStream();
 
-            return buffer.GetByteCount() - initialBufferSize;
+            // TODO:
+            throw new NotSupportedException();
         }
 
-        private void AppendRawBytes(MutableString/*!*/ buffer, int count) {
-            Debug.Assert(count &gt; 0);
-
-            if (_peekAhead != -1) {
-                buffer.Append((byte)_peekAhead);
-                _peekAhead = -1;
-                count--;
-            }
-            buffer.Append(_stream, count);
+        public BinaryReader/*!*/ GetBinaryReader() {
+            return new BinaryReader(GetReadableStream());
         }
 
-        private static int IndexOfCrLf(byte[]/*!*/ array, int i) {
-            while (true) {
-                if (array[i++] == CR &amp;&amp; array[i] == LF) {
-                    return i - 1;
-                }
-            }
+        public BinaryWriter/*!*/ GetBinaryWriter() {
+            return new BinaryWriter(GetWritableStream());
         }
 
-        public int ReadByteNormalizeEoln() {
-            // TODO: encoding
-            int first = ReadByte();
-            if (first == '\r' &amp;&amp; !_preserveEndOfLines) {
-                int second = PeekByte();
-                if (second == '\n') {
-                    return ReadByte();
-                }
-            }
-
-            return first;
+        public bool IsEndOfStream() {
+            return GetReadableStream().PeekByte(0) == -1;
         }
 
-        public int PeekByteNormalizeEoln() {
-            // TODO: encoding
-            long position = _stream.Position;
-
-            int first = PeekByte();
-            if (first == -1) {
-                return -1;
-            }
+        // returns the number of bytes written to the stream:
+        public int WriteBytes(char[]/*!*/ buffer, int index, int count) {
+            byte[] bytes = _externalEncoding.StrictEncoding.GetBytes(buffer, index, count);
+            return WriteBytes(bytes, 0, bytes.Length);
+        }
 
-            if (first == '\r' &amp;&amp; !_preserveEndOfLines) {
-                first = ReadByte();
-                int second = PeekByte();
-                if (second == '\n') {
-                    return second;
-                }
+        // returns the number of bytes written to the stream:
+        public int WriteBytes(string/*!*/ value) {
+            byte[] bytes = _externalEncoding.StrictEncoding.GetBytes(value);
+            return WriteBytes(bytes, 0, bytes.Length);
+        }
 
-                _stream.Position = position;
+        public int AppendBytes(MutableString/*!*/ buffer, int count) {
+            var stream = GetReadableStream();
+            try {
+                return stream.AppendBytes(buffer, count, PreserveEndOfLines);
+            } catch (ObjectDisposedException) {
+                throw RubyExceptions.CreateEBADF();
             }
-
-            return first;
         }
 
         public MutableString ReadLineOrParagraph(MutableString separator) {
-            if (separator != null &amp;&amp; separator.Length == 0) {
-                return ReadParagraph();
-            } else {
-                return ReadLine(separator);
+            var stream = GetReadableStream();
+            try {
+                return stream.ReadLineOrParagraph(separator, _externalEncoding, PreserveEndOfLines);
+            } catch (ObjectDisposedException) {
+                throw RubyExceptions.CreateEBADF();
             }
         }
 
-        public MutableString ReadLine(MutableString separator) {
-            AssertOpenedForReading();
-
-            int c = ReadByteNormalizeEoln();
-            if (c == -1) {
-                return null;
+        public int ReadByteNormalizeEoln() {
+            var stream = GetReadableStream();
+            try {
+                return stream.ReadByteNormalizeEoln(PreserveEndOfLines);
+            } catch (ObjectDisposedException) {
+                throw RubyExceptions.CreateEBADF();
             }
-
-            int separatorOffset = 0;
-            MutableString result = MutableString.CreateMutable();
-
-            do {
-                result.Append((char)c);
-
-                if (separator != null &amp;&amp; c == separator.GetChar(separatorOffset)) {
-                    if (separatorOffset == separator.Length - 1) {
-                        break;
-                    }
-                    separatorOffset++;
-                } else if (separatorOffset &gt; 0) {
-                    separatorOffset = 0;
-                }
-
-                c = ReadByteNormalizeEoln();
-            } while (c != -1);
-
-            return result;
         }
 
-        public MutableString ReadParagraph() {
-            var result = ReadLine(MutableString.Create(&quot;\n\n&quot;));
-
-            int c;
-            while ((c = PeekByteNormalizeEoln()) != -1) {
-                if (c != '\n') break;
-                ReadByteNormalizeEoln();
+        public int PeekByteNormalizeEoln() {
+            var stream = GetReadableStream();
+            try {
+                return stream.PeekByteNormalizeEoln(PreserveEndOfLines);
+            } catch (ObjectDisposedException) {
+                throw RubyExceptions.CreateEBADF();
             }
+        }
 
-            return result;
+        public void PushBack(byte b) {
+            GetStream().PushBack(b);            
         }
 
         #endregion</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyIO.cs</filename>
    </modified>
    <modified>
      <diff>@@ -31,14 +31,14 @@ namespace IronRuby.Builtins {
         // $.
         private int _lastInputLineNumber;
 
-        internal RubyInputProvider(RubyContext/*!*/ context, ICollection&lt;string&gt;/*!*/ arguments) {
-            Assert.NotNull(context);
+        internal RubyInputProvider(RubyContext/*!*/ context, ICollection&lt;string&gt;/*!*/ arguments, RubyEncoding/*!*/ encoding) {
+            Assert.NotNull(context, encoding);
             Assert.NotNullItems(arguments);
             _context = context;
 
             var args = new RubyArray();
             foreach (var arg in arguments) {
-                ExpandArgument(args, arg);
+                ExpandArgument(args, arg, encoding);
             }
 
             _commandLineArguments = args;
@@ -71,7 +71,7 @@ namespace IronRuby.Builtins {
         public MutableString/*!*/ CurrentFileName {
             get {
                 // TODO:
-                return MutableString.Create(&quot;-&quot;);
+                return MutableString.CreateAscii(&quot;-&quot;);
             }
         }
 
@@ -79,19 +79,19 @@ namespace IronRuby.Builtins {
             Interlocked.Increment(ref _lastInputLineNumber);
         }
 
-        private void ExpandArgument(RubyArray/*!*/ args, string/*!*/ arg) {
+        private void ExpandArgument(RubyArray/*!*/ args, string/*!*/ arg, RubyEncoding/*!*/ encoding) {
             if (arg.IndexOf('*') != -1 || arg.IndexOf('?') != -1) {
                 bool added = false;
-                foreach (string path in Glob.GlobResults(_context, arg, 0)) {
-                    args.Add(MutableString.Create(path));
+                foreach (string path in Glob.GlobResults(_context.DomainManager.Platform, arg, 0)) {
+                    args.Add(MutableString.Create(path, encoding));
                     added = true;
                 }
 
                 if (!added) {
-                    args.Add(MutableString.Create(arg));
+                    args.Add(MutableString.Create(arg, encoding));
                 }
             } else {
-                args.Add(MutableString.Create(arg));
+                args.Add(MutableString.Create(arg, encoding));
             }
         }
     }</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyInputProvider.cs</filename>
    </modified>
    <modified>
      <diff>@@ -2066,7 +2066,7 @@ namespace IronRuby.Builtins {
             if (IsSingletonClass) {
                 RubyClass c = (RubyClass)this;
                 object singletonOf;
-                MutableString result = MutableString.CreateMutable();
+                MutableString result = MutableString.CreateMutable(RubyEncoding.ClassName);
 
                 int nestings = 0;
                 while (true) {
@@ -2098,7 +2098,7 @@ namespace IronRuby.Builtins {
                 if (showEmptyName) {
                     return MutableString.FrozenEmpty;
                 } else {
-                    MutableString result = MutableString.CreateMutable();
+                    MutableString result = MutableString.CreateMutable(RubyEncoding.ClassName);
                     result.Append(&quot;#&lt;&quot;);
                     result.Append(_context.GetClassOf(this).GetName(context));
                     result.Append(':');
@@ -2107,7 +2107,7 @@ namespace IronRuby.Builtins {
                     return result;
                 }
             } else {
-                return MutableString.CreateMutable(GetName(context));
+                return MutableString.CreateMutable(GetName(context), RubyEncoding.ClassName);
             }
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyModule.cs</filename>
    </modified>
    <modified>
      <diff>@@ -45,7 +45,7 @@ namespace IronRuby.Builtins {
         }
 
         public override string/*!*/ ToString() {
-#if DEBUG &amp;&amp; !SILVERLIGHT &amp;&amp; !SYSTEM_CORE
+#if DEBUG &amp;&amp; !SILVERLIGHT &amp;&amp; !CLR4
             if (RubyBinder._DumpingExpression) {
                 return BaseToMutableString(this).ToString();
             }
@@ -77,7 +77,7 @@ namespace IronRuby.Builtins {
             if (self is RubyObject) {
                 return ToMutableString(self);
             } else {
-                return MutableString.CreateMutable(self.BaseToString());
+                return MutableString.CreateMutable(self.BaseToString(), RubyEncoding.UTF8);
             }
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyObject.cs</filename>
    </modified>
    <modified>
      <diff>@@ -83,6 +83,11 @@ namespace IronRuby.Builtins {
             get { return _regex.Options; }
         }
 
+        public RubyEncoding/*!*/ Encoding {
+            // TODO:
+            get { return _regex.GetPattern().Encoding; }
+        }
+
         public MutableString/*!*/ GetPattern() {
             return _regex.GetPattern();
         }
@@ -112,7 +117,7 @@ namespace IronRuby.Builtins {
 
         public Match/*!*/ Match(MutableString/*!*/ input, int start) {
             ContractUtils.RequiresNotNull(input, &quot;input&quot;);
-            return Match(input, start, input.Length - start);
+            return Match(input, start, input.GetCharCount() - start);
         }
 
         public Match/*!*/ Match(MutableString/*!*/ input, int start, int count) {
@@ -220,11 +225,11 @@ namespace IronRuby.Builtins {
         }
 
         public MutableString/*!*/ ToMutableString() {
-            return AppendTo(MutableString.CreateMutable());
+            return AppendTo(MutableString.CreateMutable(RubyEncoding.Binary));
         }
 
         public MutableString/*!*/ Inspect() {
-            MutableString result = MutableString.CreateMutable();
+            MutableString result = MutableString.CreateMutable(RubyEncoding.Binary);
             result.Append('/');
             AppendEscapeForwardSlash(result, GetPattern());
             result.Append('/');</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyRegex.cs</filename>
    </modified>
    <modified>
      <diff>@@ -66,7 +66,8 @@ namespace IronRuby.Builtins {
             internal RubyArray/*!*/ GetMembers() {
                 RubyArray list = new RubyArray(_names.Length);
                 foreach (string id in _names) {
-                    list.Add(MutableString.Create(id));
+                    // TODO: we need to add encoding to symbols and preserve it here:
+                    list.Add(MutableString.Create(id, RubyEncoding.UTF8));
                 }
                 return list;
             }</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyStruct.cs</filename>
    </modified>
    <modified>
      <diff>@@ -154,7 +154,6 @@ namespace IronRuby.Compiler.Ast {
                 Methods.FilterBlockException.OpCall(scopeVariable, filterVariable)
             ).Finally(
                 traceReturn,
-                Methods.LeaveBlockFrame.OpCall(scopeVariable),
                 LeaveInterpretedFrameExpression.Instance
             );
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/BlockDefinition.cs</filename>
    </modified>
    <modified>
      <diff>@@ -53,12 +53,12 @@ namespace IronRuby.Compiler.Ast {
             get { return _value; }
         }
 
-        public MutableString/*!*/ GetMutableString() {
+        public MutableString/*!*/ GetMutableString(RubyEncoding/*!*/ encoding) {
             string str = _value as string;
             if (str != null) {
-                return MutableString.Create(str);
+                return MutableString.Create(str, encoding);
             } else {
-                return MutableString.CreateBinary((byte[])_value);
+                return MutableString.CreateBinary((byte[])_value, encoding);
             }
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/Expressions/StringLiteral.cs</filename>
    </modified>
    <modified>
      <diff>@@ -97,10 +97,6 @@ namespace IronRuby.Compiler.Ast {
                 blockParameter = null;
             }
 
-            if (_statements.Count == 0) {
-                return Ast.Lambda&lt;T&gt;(AstUtils.Constant(null), parameters);
-            }
-
             gen.EnterSourceUnit(
                 scope,
                 selfVariable,
@@ -112,32 +108,37 @@ namespace IronRuby.Compiler.Ast {
 
             MSA.Expression body;
 
-            if (gen.PrintInteractiveResult) {
-                var resultVariable = scope.DefineHiddenVariable(&quot;#result&quot;, typeof(object));
 
-                var epilogue = Methods.PrintInteractiveResult.OpCall(runtimeScopeVariable,
-                    Ast.Dynamic(ConvertToSAction.Make(gen.Context), typeof(MutableString),
-                        CallBuilder.InvokeMethod(gen.Context, &quot;inspect&quot;, RubyCallSignature.WithScope(0),
-                            gen.CurrentScopeVariable, resultVariable
+            if (_statements.Count &gt; 0) {
+                if (gen.PrintInteractiveResult) {
+                    var resultVariable = scope.DefineHiddenVariable(&quot;#result&quot;, typeof(object));
+
+                    var epilogue = Methods.PrintInteractiveResult.OpCall(runtimeScopeVariable,
+                        Ast.Dynamic(ConvertToSAction.Make(gen.Context), typeof(MutableString),
+                            CallBuilder.InvokeMethod(gen.Context, &quot;inspect&quot;, RubyCallSignature.WithScope(0),
+                                gen.CurrentScopeVariable, resultVariable
+                            )
                         )
-                    )
-                );
+                    );
 
-                body = gen.TransformStatements(null, _statements, epilogue, ResultOperation.Store(resultVariable));
+                    body = gen.TransformStatements(null, _statements, epilogue, ResultOperation.Store(resultVariable));
+                } else {
+                    body = gen.TransformStatements(_statements, ResultOperation.Return);
+                }
+
+                // TODO:
+                var exceptionVariable = Ast.Parameter(typeof(Exception), &quot;#exception&quot;);
+                body = AstUtils.Try(
+                    body
+                ).Filter(exceptionVariable, Methods.TraceTopLevelCodeFrame.OpCall(runtimeScopeVariable, exceptionVariable),
+                    Ast.Empty()
+                ).Finally(
+                    LeaveInterpretedFrameExpression.Instance
+                );
             } else {
-                body = gen.TransformStatements(_statements, ResultOperation.Return);
+                body = AstUtils.Constant(null);
             }
 
-            // TODO:
-            var exceptionVariable = Ast.Parameter(typeof(Exception), &quot;#exception&quot;);
-            body = AstUtils.Try(
-                body
-            ).Filter(exceptionVariable, Methods.TraceTopLevelCodeFrame.OpCall(runtimeScopeVariable, exceptionVariable),
-                Ast.Empty()
-            ).Finally(
-                LeaveInterpretedFrameExpression.Instance
-            );
-
             // scope initialization:
             MSA.Expression prologue;
             switch (gen.CompilerOptions.FactoryKind) {</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/SourceUnitTree.cs</filename>
    </modified>
    <modified>
      <diff>@@ -301,16 +301,13 @@ namespace IronRuby.Compiler.Generation {
                     }
                 }
             } else if (!TryOverrideProperty(mi, overridden)) {
-                string name;
                 EventInfo[] eis = mi.DeclaringType.GetEvents(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                 foreach (EventInfo ei in eis) {
                     if (ei.GetAddMethod() == mi) {
-                        if (!TryGetName(mi.DeclaringType, ei, mi, out name)) return;
-                        CreateVTableEventOverride(mi, mi.Name);
+                        CreateVTableMethodOverride(mi, mi.Name);
                         return;
                     } else if (ei.GetRemoveMethod() == mi) {
-                        if (!TryGetName(mi.DeclaringType, ei, mi, out name)) return;
-                        CreateVTableEventOverride(mi, mi.Name);
+                        CreateVTableMethodOverride(mi, mi.Name);
                         return;
                     }
                 }
@@ -511,27 +508,6 @@ namespace IronRuby.Compiler.Generation {
             return impl;
         }
 
-        private void CreateVTableEventOverride(MethodInfo mi, string name) {
-#if TODO
-            // override the add/remove method  
-            MethodBuilder impl;
-            ILGen il = DefineMethodOverride(mi, out impl);
-
-            LocalBuilder callTarget = EmitBaseClassCallCheckForProperties(il, mi, name);
-
-            il.Emit(OpCodes.Ldloc, callTarget);
-            il.EmitLoadArg(0);
-            il.EmitLoadArg(0);
-            EmitClassObjectFromInstance(il);
-            il.EmitLoadArg(1);
-            il.EmitBoxing(mi.GetParameters()[0].ParameterType);
-            il.Emit(OpCodes.Ldstr, name);
-            il.EmitCall(EventHelper());
-            il.Emit(OpCodes.Ret);
-            _tb.DefineMethodOverride(impl, mi);
-#endif
-        }
-
         private MethodBuilder CreateVTableMethodOverride(MethodInfo mi, string name) {
             ParameterInfo[] parameters = mi.GetParameters();
             MethodBuilder impl;</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/ClsTypeEmitter.cs</filename>
    </modified>
    <modified>
      <diff>@@ -24,8 +24,27 @@ using IronRuby.Compiler.Generation;
 using IronRuby.Runtime;
 
 namespace IronRuby.Compiler.Generation {
-
     public sealed class Profiler {
+        public struct MethodCounter {
+            public readonly string/*!*/ Name;
+            public readonly string/*!*/ File;
+            public readonly int Line;
+            public readonly long Ticks;
+
+            public MethodCounter(string/*!*/ name, string/*!*/ file, int line, long ticks) {
+                Name = name;
+                File = file;
+                Line = line;
+                Ticks = ticks;
+	        }
+
+            public string/*!*/ Id {
+                get {
+                    return String.Format(&quot;{0};{1};{2}&quot;, Name, File, Line);
+                }
+            }
+        }
+
         public static readonly Profiler/*!*/ Instance = new Profiler();
         internal static long[] _ProfileTicks = new long[100];
         
@@ -53,8 +72,8 @@ namespace IronRuby.Compiler.Generation {
             return index;
         }
 
-        public Dictionary&lt;string/*!*/, long&gt;/*!*/ GetProfile() {
-            var result = new Dictionary&lt;string, long&gt;();
+        public List&lt;MethodCounter/*!*/&gt;/*!*/ GetProfile() {
+            var result = new List&lt;MethodCounter&gt;();
             lock (_counters) {
                 // capture the current profile:
                 long[] newProfile = new long[_ProfileTicks.Length];
@@ -69,7 +88,12 @@ namespace IronRuby.Compiler.Generation {
                 }
 
                 foreach (var counter in _counters) {
-                    result.Add(counter.Key, total[counter.Value]);
+                    string methodName = counter.Key;
+                    string fileName = null;
+                    int line = 0;
+                    if (RubyExceptionData.TryParseRubyMethodName(ref methodName, ref fileName, ref line)) {
+                        result.Add(new MethodCounter(methodName, fileName, line, total[counter.Value]));
+                    }
                 }
             }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/Profiler.cs</filename>
    </modified>
    <modified>
      <diff>@@ -48,7 +48,7 @@ namespace IronRuby.Compiler.Generation {
         }
 
         [Emitted]
-        public static Exception InvokeMethodMissing(object o, string/*!*/ name) {
+        public static Exception/*!*/ InvokeMethodMissing(object o, string/*!*/ name) {
             return RubyExceptions.CreateMethodMissing(RubyContext._Default, o, name);
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/RubyTypeEmitter.cs</filename>
    </modified>
    <modified>
      <diff>@@ -323,8 +323,6 @@ namespace IronRuby.Compiler {
         private static MethodInfo _IsSuperCallTarget;
         public static MethodInfo/*!*/ IsTrue { get { return _IsTrue ?? (_IsTrue = GetMethod(typeof(RubyOps), &quot;IsTrue&quot;)); } }
         private static MethodInfo _IsTrue;
-        public static MethodInfo/*!*/ LeaveBlockFrame { get { return _LeaveBlockFrame ?? (_LeaveBlockFrame = GetMethod(typeof(RubyOps), &quot;LeaveBlockFrame&quot;)); } }
-        private static MethodInfo _LeaveBlockFrame;
         public static MethodInfo/*!*/ LeaveLoop { get { return _LeaveLoop ?? (_LeaveLoop = GetMethod(typeof(RubyOps), &quot;LeaveLoop&quot;)); } }
         private static MethodInfo _LeaveLoop;
         public static MethodInfo/*!*/ LeaveMethodFrame { get { return _LeaveMethodFrame ?? (_LeaveMethodFrame = GetMethod(typeof(RubyOps), &quot;LeaveMethodFrame&quot;)); } }
@@ -379,6 +377,8 @@ namespace IronRuby.Compiler {
         private static MethodInfo _MakeTypeConversionError;
         public static MethodInfo/*!*/ MakeWrongNumberOfArgumentsError { get { return _MakeWrongNumberOfArgumentsError ?? (_MakeWrongNumberOfArgumentsError = GetMethod(typeof(RubyOps), &quot;MakeWrongNumberOfArgumentsError&quot;)); } }
         private static MethodInfo _MakeWrongNumberOfArgumentsError;
+        public static MethodInfo/*!*/ MarkException { get { return _MarkException ?? (_MarkException = GetMethod(typeof(RubyOps), &quot;MarkException&quot;)); } }
+        private static MethodInfo _MarkException;
         public static MethodInfo/*!*/ MatchLastInputLine { get { return _MatchLastInputLine ?? (_MatchLastInputLine = GetMethod(typeof(RubyOps), &quot;MatchLastInputLine&quot;)); } }
         private static MethodInfo _MatchLastInputLine;
         public static MethodInfo/*!*/ MatchString { get { return _MatchString ?? (_MatchString = GetMethod(typeof(RubyOps), &quot;MatchString&quot;)); } }
@@ -441,24 +441,42 @@ namespace IronRuby.Compiler {
         private static MethodInfo _StringToMutableString;
         public static MethodInfo/*!*/ ToArrayValidator { get { return _ToArrayValidator ?? (_ToArrayValidator = GetMethod(typeof(RubyOps), &quot;ToArrayValidator&quot;)); } }
         private static MethodInfo _ToArrayValidator;
+        public static MethodInfo/*!*/ ToBignumValidator { get { return _ToBignumValidator ?? (_ToBignumValidator = GetMethod(typeof(RubyOps), &quot;ToBignumValidator&quot;)); } }
+        private static MethodInfo _ToBignumValidator;
+        public static MethodInfo/*!*/ ToByteValidator { get { return _ToByteValidator ?? (_ToByteValidator = GetMethod(typeof(RubyOps), &quot;ToByteValidator&quot;)); } }
+        private static MethodInfo _ToByteValidator;
+        public static MethodInfo/*!*/ ToDoubleValidator { get { return _ToDoubleValidator ?? (_ToDoubleValidator = GetMethod(typeof(RubyOps), &quot;ToDoubleValidator&quot;)); } }
+        private static MethodInfo _ToDoubleValidator;
         public static MethodInfo/*!*/ ToFixnumValidator { get { return _ToFixnumValidator ?? (_ToFixnumValidator = GetMethod(typeof(RubyOps), &quot;ToFixnumValidator&quot;)); } }
         private static MethodInfo _ToFixnumValidator;
-        public static MethodInfo/*!*/ ToFloatValidator { get { return _ToFloatValidator ?? (_ToFloatValidator = GetMethod(typeof(RubyOps), &quot;ToFloatValidator&quot;)); } }
-        private static MethodInfo _ToFloatValidator;
         public static MethodInfo/*!*/ ToHashValidator { get { return _ToHashValidator ?? (_ToHashValidator = GetMethod(typeof(RubyOps), &quot;ToHashValidator&quot;)); } }
         private static MethodInfo _ToHashValidator;
+        public static MethodInfo/*!*/ ToInt16Validator { get { return _ToInt16Validator ?? (_ToInt16Validator = GetMethod(typeof(RubyOps), &quot;ToInt16Validator&quot;)); } }
+        private static MethodInfo _ToInt16Validator;
+        public static MethodInfo/*!*/ ToInt64Validator { get { return _ToInt64Validator ?? (_ToInt64Validator = GetMethod(typeof(RubyOps), &quot;ToInt64Validator&quot;)); } }
+        private static MethodInfo _ToInt64Validator;
         public static MethodInfo/*!*/ ToIntegerValidator { get { return _ToIntegerValidator ?? (_ToIntegerValidator = GetMethod(typeof(RubyOps), &quot;ToIntegerValidator&quot;)); } }
         private static MethodInfo _ToIntegerValidator;
         public static MethodInfo/*!*/ ToProcValidator { get { return _ToProcValidator ?? (_ToProcValidator = GetMethod(typeof(RubyOps), &quot;ToProcValidator&quot;)); } }
         private static MethodInfo _ToProcValidator;
         public static MethodInfo/*!*/ ToRegexValidator { get { return _ToRegexValidator ?? (_ToRegexValidator = GetMethod(typeof(RubyOps), &quot;ToRegexValidator&quot;)); } }
         private static MethodInfo _ToRegexValidator;
+        public static MethodInfo/*!*/ ToSByteValidator { get { return _ToSByteValidator ?? (_ToSByteValidator = GetMethod(typeof(RubyOps), &quot;ToSByteValidator&quot;)); } }
+        private static MethodInfo _ToSByteValidator;
         public static MethodInfo/*!*/ ToSDefaultConversion { get { return _ToSDefaultConversion ?? (_ToSDefaultConversion = GetMethod(typeof(RubyOps), &quot;ToSDefaultConversion&quot;)); } }
         private static MethodInfo _ToSDefaultConversion;
+        public static MethodInfo/*!*/ ToSingleValidator { get { return _ToSingleValidator ?? (_ToSingleValidator = GetMethod(typeof(RubyOps), &quot;ToSingleValidator&quot;)); } }
+        private static MethodInfo _ToSingleValidator;
         public static MethodInfo/*!*/ ToStringValidator { get { return _ToStringValidator ?? (_ToStringValidator = GetMethod(typeof(RubyOps), &quot;ToStringValidator&quot;)); } }
         private static MethodInfo _ToStringValidator;
         public static MethodInfo/*!*/ ToSymbolValidator { get { return _ToSymbolValidator ?? (_ToSymbolValidator = GetMethod(typeof(RubyOps), &quot;ToSymbolValidator&quot;)); } }
         private static MethodInfo _ToSymbolValidator;
+        public static MethodInfo/*!*/ ToUInt16Validator { get { return _ToUInt16Validator ?? (_ToUInt16Validator = GetMethod(typeof(RubyOps), &quot;ToUInt16Validator&quot;)); } }
+        private static MethodInfo _ToUInt16Validator;
+        public static MethodInfo/*!*/ ToUInt32Validator { get { return _ToUInt32Validator ?? (_ToUInt32Validator = GetMethod(typeof(RubyOps), &quot;ToUInt32Validator&quot;)); } }
+        private static MethodInfo _ToUInt32Validator;
+        public static MethodInfo/*!*/ ToUInt64Validator { get { return _ToUInt64Validator ?? (_ToUInt64Validator = GetMethod(typeof(RubyOps), &quot;ToUInt64Validator&quot;)); } }
+        private static MethodInfo _ToUInt64Validator;
         public static MethodInfo/*!*/ TraceBlockCall { get { return _TraceBlockCall ?? (_TraceBlockCall = GetMethod(typeof(RubyOps), &quot;TraceBlockCall&quot;)); } }
         private static MethodInfo _TraceBlockCall;
         public static MethodInfo/*!*/ TraceBlockReturn { get { return _TraceBlockReturn ?? (_TraceBlockReturn = GetMethod(typeof(RubyOps), &quot;TraceBlockReturn&quot;)); } }</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Compiler/ReflectionCache.Generated.cs</filename>
    </modified>
    <modified>
      <diff>@@ -65,6 +65,16 @@ namespace IronRuby.Hosting {
             return RunFile(Engine.CreateScriptSourceFromFile(RubyUtils.CanonicalizePath(fileName), (((RubyContext)Language).RubyOptions.KCode ?? RubyEncoding.Binary).Encoding));
         }
 
+        protected override void ExecuteCommand(string command) {
+#if SILVERLIGHT
+            base.ExecuteCommand(command);
+#else
+            var kcode = ((RubyContext)Language).RubyOptions.KCode;
+            var encoding = kcode != null ? kcode.Encoding : System.Console.InputEncoding;
+            ExecuteCommand(Engine.CreateScriptSource(new BinaryContentProvider(encoding.GetBytes(command)), null, encoding, SourceCodeKind.InteractiveCode));
+#endif
+        }
+        
         protected override Scope/*!*/ CreateScope() {
             Scope scope = base.CreateScope();
             scope.SetVariable(SymbolTable.StringToId(&quot;iron_ruby&quot;), Engine);</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Hosting/RubyCommandLine.cs</filename>
    </modified>
    <modified>
      <diff>@@ -71,6 +71,16 @@ namespace IronRuby.Hosting {
         }
 #endif
 
+        private static string[] GetPaths(string input) {
+            string[] paths = StringUtils.Split(input, new char[] { Path.PathSeparator }, Int32.MaxValue, StringSplitOptions.RemoveEmptyEntries);
+            for (int i = 0; i &lt; paths.Length; i++) {
+                // Trim any occurrances of &quot;
+                string[] parts = StringUtils.Split(paths[i], new char[] { '&quot;' }, Int32.MaxValue, StringSplitOptions.RemoveEmptyEntries);
+                paths[i] = String.Concat(parts);
+            }
+            return paths;
+        }
+
         /// &lt;exception cref=&quot;Exception&quot;&gt;On error.&lt;/exception&gt;
         protected override void ParseArgument(string arg) {
             ContractUtils.RequiresNotNull(arg, &quot;arg&quot;);
@@ -110,21 +120,6 @@ namespace IronRuby.Hosting {
                     RuntimeSetup.DebugMode = true;          // $DEBUG = true
                     break;
                 
-                case &quot;-r&quot;:
-                    string libPath = PopNextArg();
-                    LanguageSetup.Options[&quot;RequiredLibraries&quot;] = libPath;
-                    break;
-
-                case &quot;-e&quot;:
-                    LanguageSetup.Options[&quot;MainFile&quot;] = &quot;-e&quot;;
-                    if (CommonConsoleOptions.Command == null) {
-                        CommonConsoleOptions.Command = String.Empty;
-                    } else {
-                        CommonConsoleOptions.Command += &quot;\n&quot;;
-                    }
-                    CommonConsoleOptions.Command += PopNextArg();
-                    break;
-
                 #endregion
 
 #if DEBUG &amp;&amp; !SILVERLIGHT
@@ -185,12 +180,45 @@ namespace IronRuby.Hosting {
                     break;
 
                 default:
+                    if (arg.StartsWith(&quot;-e&quot;)) {
+                        string command;
+                        if (arg == &quot;-e&quot;) {
+                            command = PopNextArg();
+                        } else {
+                            command = arg.Substring(2);
+                        }
+
+                        LanguageSetup.Options[&quot;MainFile&quot;] = &quot;-e&quot;;
+                        if (CommonConsoleOptions.Command == null) {
+                            CommonConsoleOptions.Command = String.Empty;
+                        } else {
+                              CommonConsoleOptions.Command += &quot;\n&quot;;
+                        }
+                        CommonConsoleOptions.Command += command;
+                        break;
+                    }
+
                     if (arg.StartsWith(&quot;-I&quot;)) {
+                        string includePaths;
                         if (arg == &quot;-I&quot;) {
-                            _loadPaths.Add(PopNextArg());
+                            includePaths = PopNextArg();
+                        } else {
+                            includePaths = arg.Substring(2);
+                        }
+
+                        _loadPaths.AddRange(GetPaths(includePaths));
+                        break;
+                    }
+
+                    if (arg.StartsWith(&quot;-r&quot;)) {
+                        string libPath;
+                        if (arg == &quot;-r&quot;) {
+                            libPath = PopNextArg();
                         } else {
-                            _loadPaths.Add(arg.Substring(2));
+                            libPath = arg.Substring(2);
                         }
+
+                        LanguageSetup.Options[&quot;RequiredLibraries&quot;] = libPath;
                         break;
                     }
 
@@ -209,6 +237,12 @@ namespace IronRuby.Hosting {
                     if (ConsoleOptions.FileName != null) {
                         LanguageSetup.Options[&quot;MainFile&quot;] = RubyUtils.CanonicalizePath(ConsoleOptions.FileName);
                         LanguageSetup.Options[&quot;Arguments&quot;] = PopRemainingArgs();
+                        LanguageSetup.Options[&quot;ArgumentEncoding&quot;] = 
+#if SILVERLIGHT
+                            RubyEncoding.UTF8;
+#else
+                            RubyEncoding.GetRubyEncoding(Console.InputEncoding);
+#endif
                         CommonConsoleOptions.Exit = false;
                     } 
                     break;
@@ -228,13 +262,12 @@ namespace IronRuby.Hosting {
             try {
                 string rubylib = Environment.GetEnvironmentVariable(&quot;RUBYLIB&quot;);
                 if (rubylib != null) {
-                    _loadPaths.AddRange(rubylib.Split(Path.PathSeparator));
+                    _loadPaths.AddRange(GetPaths(rubylib));
                 }
             } catch (SecurityException) {
                 // nop
             }
 #endif
-
             LanguageSetup.Options[&quot;SearchPaths&quot;] = _loadPaths;
         }
 
@@ -278,7 +311,7 @@ namespace IronRuby.Hosting {
                 { &quot;-compileRegexps&quot;, &quot;Faster throughput, slower startup&quot; },
 #endif
                 { &quot;-trace&quot;,         &quot;Enable support for set_trace_func&quot; },
-                { &quot;-profile&quot;,       &quot;Enable support Clr.profile&quot; },
+                { &quot;-profile&quot;,       &quot;Enable support for 'pi = IronRuby::Clr.profile { block_to_profile }'&quot; },
                 { &quot;-18&quot;,            &quot;Ruby 1.8 mode&quot; },
                 { &quot;-19&quot;,            &quot;Ruby 1.9 mode&quot; },
                 { &quot;-20&quot;,            &quot;Ruby 2.0 mode&quot; },</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Hosting/RubyOptionsParser.cs</filename>
    </modified>
    <modified>
      <diff>@@ -53,3 +53,6 @@ using IronRuby.Runtime;
 #endif
 
 
+#if CLR4
+[assembly: SecurityRules(SecurityRuleSet.Level1)]
+#endif
\ No newline at end of file</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Properties/AssemblyInfo.cs</filename>
    </modified>
    <modified>
      <diff></diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Ruby.Build.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -117,7 +117,7 @@ namespace IronRuby {
 
         internal static bool RequireFile(LanguageContext/*!*/ context, KeyValuePair&lt;string, Scope&gt; pathAndScope) {
             var rc = (RubyContext)context;
-            return rc.Loader.LoadFile(pathAndScope.Value, null, MutableString.Create(pathAndScope.Key),
+            return rc.Loader.LoadFile(pathAndScope.Value, null, MutableString.Create(pathAndScope.Key, RubyEncoding.UTF8),
                 LoadFlags.LoadOnce | LoadFlags.AppendExtensions);
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Ruby.cs</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,6 @@
   &lt;PropertyGroup&gt;
     &lt;Configuration Condition=&quot; '$(Configuration)' == '' &quot;&gt;Debug&lt;/Configuration&gt;
     &lt;Platform Condition=&quot; '$(Platform)' == '' &quot;&gt;AnyCPU&lt;/Platform&gt;
-    &lt;ProductVersion&gt;10.0.20624&lt;/ProductVersion&gt;
     &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
     &lt;ProjectGuid&gt;{7F6984B4-EE6D-4E6F-ABB1-E210D7DC4FDD}&lt;/ProjectGuid&gt;
     &lt;OutputType&gt;Library&lt;/OutputType&gt;
@@ -124,8 +123,9 @@
     &lt;Compile Include=&quot;Builtins\CharacterMap.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\ConsoleStream.cs&quot; /&gt;
     &lt;None Include=&quot;Builtins\Subclasses.Generator.rb&quot; /&gt;
-    &lt;Compile Include=&quot;Builtins\RubyErrno.cs&quot; /&gt;
+    &lt;Compile Include=&quot;Builtins\IOMode.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\MutableStringBuilder.cs&quot; /&gt;
+    &lt;Compile Include=&quot;Builtins\RubyBufferedStream.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\RubyEvent.Meta.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\DuplexStream.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\GenericRegex.cs&quot; /&gt;
@@ -147,7 +147,7 @@
     &lt;Compile Include=&quot;Builtins\MutableString.CharArrayContent.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\MutableString.StringContent.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\RubyMethod.Meta.cs&quot; /&gt;
-    &lt;Compile Include=&quot;Builtins\File.cs&quot; /&gt;
+    &lt;Compile Include=&quot;Builtins\RubyFile.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\Glob.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\MatchData.cs&quot; /&gt;
     &lt;Compile Include=&quot;Builtins\MutableStringStream.cs&quot; /&gt;
@@ -256,7 +256,7 @@
     &lt;Compile Include=&quot;Compiler\Ast\Expressions\RangeExpression.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\Conversions\Converter.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\Conversions\Converter.Generated.cs&quot; /&gt;
-    &lt;Compile Include=&quot;Builtins\Initializer.cs&quot; /&gt;
+    &lt;Compile Include=&quot;Builtins\LibraryInitializer.cs&quot; /&gt;
     &lt;Compile Include=&quot;Compiler\AstGenerator.cs&quot; /&gt;
     &lt;Compile Include=&quot;Compiler\Ast\Arguments.cs&quot; /&gt;
     &lt;Compile Include=&quot;Compiler\Ast\AstFactory.cs&quot; /&gt;
@@ -379,7 +379,6 @@
     &lt;Compile Include=&quot;RubyCompatibility.cs&quot; /&gt;
     &lt;Compile Include=&quot;Runtime\IOWrapper.cs&quot; /&gt;
     &lt;None Include=&quot;Compiler\Parser\Parser.y&quot; /&gt;
-    &lt;None Include=&quot;Migrated rules for Ruby.ruleset&quot; /&gt;
     &lt;None Include=&quot;Runtime\Calls\MethodDispatcher.Generator.rb&quot; /&gt;
     &lt;None Include=&quot;Runtime\Conversions\Converter.Generator.rb&quot; /&gt;
   &lt;/ItemGroup&gt;</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Ruby.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -41,6 +41,12 @@ namespace IronRuby.Runtime {
         }
 
         public override int GetByteCount(char[]/*!*/ chars, int index, int count) {
+            for (int i = 0; i &lt; count; i++) {
+                if (chars[index + i] &gt; 0xff) {
+                    // TODO: we don't support fallbacks (we should add the result of the fallback to the count):
+                    throw new EncoderFallbackException();
+                }
+            }
             return count;
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/BinaryEncoding.cs</filename>
    </modified>
    <modified>
      <diff>@@ -24,6 +24,7 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 using Ast = System.Linq.Expressions.Expression;
 using AstUtils = Microsoft.Scripting.Ast.Utils;
+using IronRuby.Runtime.Conversions;
 
 namespace IronRuby.Runtime.Calls {
     internal interface IInteropBinder {
@@ -586,24 +587,15 @@ namespace IronRuby.Runtime.Calls {
                     return result;
                 }
 #endif
+                var metaBuilder = new MetaObjectBuilder(this, target, DynamicMetaObject.EmptyMetaObjects);
 
-                // TODO:
-                return errorSuggestion ?? new DynamicMetaObject(
-                    Expression.Throw(Methods.MakeTypeConversionError.OpCall(
-                        AstUtils.Constant(_context), AstUtils.Convert(target.Expression, typeof(object)), Ast.Constant(ReturnType)
-                    ), ReturnType),
-                    target.Restrictions
-                );
-            }
-
-            public static DynamicMetaObject/*!*/ Bind(DynamicMetaObject/*!*/ context, ConvertBinder/*!*/ binder,
-                DynamicMetaObject/*!*/ target, Func&lt;DynamicMetaObject, DynamicMetaObject, DynamicMetaObject&gt;/*!*/ fallback) {
+                if (!GenericConversionAction.BuildConversion(metaBuilder, target, Ast.Constant(_context), Type, errorSuggestion == null)) {
+                    Debug.Assert(errorSuggestion != null);
+                    // no conversion applicable so we didn't do any operation with arguments that would require restrictions converted to conditions:
+                    metaBuilder.SetMetaResult(errorSuggestion, false);
+                }
 
-                // TODO:
-                return null;
-                //return InvokeMember.Bind(context, RubyUtils.MapOperator(binder.Operation), _CallInfo, binder, target, new[] { arg },
-                //    (trgt, args) =&gt; fallback(trgt, args[0])
-                //);
+                return metaBuilder.CreateMetaObject(this);
             }
 
             public override string/*!*/ ToString() {</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/InteropBinder.cs</filename>
    </modified>
    <modified>
      <diff>@@ -76,7 +76,7 @@ namespace IronRuby.Runtime.Calls {
             return result;
         }
 
-#if DEBUG &amp;&amp; !SILVERLIGHT &amp;&amp; !SYSTEM_CORE
+#if DEBUG &amp;&amp; !SILVERLIGHT &amp;&amp; !CLR4
         // ExpressionWriter might call ToString on a live object that might dynamically invoke a method.
         // We need to prevent recursion in such case.
         [ThreadStatic]
@@ -88,7 +88,7 @@ namespace IronRuby.Runtime.Calls {
 
         [Conditional(&quot;DEBUG&quot;)]
         internal static void DumpPrecompiledRule(DynamicMetaObjectBinder/*!*/ action, MethodDispatcher/*!*/ dispatcher) {
-#if DEBUG &amp;&amp; !SILVERLIGHT &amp;&amp; !SYSTEM_CORE
+#if DEBUG &amp;&amp; !SILVERLIGHT &amp;&amp; !CLR4
             if (RubyOptions.ShowRules) {
                 var oldColor = Console.ForegroundColor;
                 Console.ForegroundColor = ConsoleColor.Cyan;
@@ -102,7 +102,7 @@ namespace IronRuby.Runtime.Calls {
 
         [Conditional(&quot;DEBUG&quot;)]
         internal static void DumpRule(DynamicMetaObjectBinder/*!*/ action, BindingRestrictions/*!*/ restrictions, Expression/*!*/ expr) {
-#if DEBUG &amp;&amp; !SILVERLIGHT &amp;&amp; !SYSTEM_CORE
+#if DEBUG &amp;&amp; !SILVERLIGHT &amp;&amp; !CLR4
             if (RubyOptions.ShowRules) {
                 var oldColor = Console.ForegroundColor;
                 try {</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyBinder.cs</filename>
    </modified>
    <modified>
      <diff>@@ -23,11 +23,12 @@ using Microsoft.Scripting.Utils;
 using Microsoft.Scripting.Runtime;
 using IronRuby.Runtime;
 using IronRuby.Runtime.Calls;
+using IronRuby.Runtime.Conversions;
 using IronRuby.Compiler;
 using AstUtils = Microsoft.Scripting.Ast.Utils;
 
 namespace IronRuby.Runtime.Calls {
-    using Ast = System.Linq.Expressions.Expression;
+    using Ast = System.Linq.Expressions.Expression;    
 
     public interface IRubyDynamicMetaObjectProvider : IDynamicMetaObjectProvider {
     }
@@ -73,10 +74,14 @@ namespace IronRuby.Runtime.Calls {
             return InteropBinder.BinaryOperation.Bind(CreateMetaContext(), binder, this, arg, binder.FallbackBinaryOperation);
         }
 
-        // TODO:
-        //public override DynamicMetaObject/*!*/ BindConvert(ConvertBinder/*!*/ binder) {
-        //    return InteropBinder.Convert.Bind(CreateMetaContext(), binder, this, binder.FallbackConvert);
-        //}
+        public override DynamicMetaObject/*!*/ BindConvert(ConvertBinder/*!*/ binder) {
+            var protocolConversion = ProtocolConversionAction.TryGetDefaultConversionAction(Context, binder.Type);
+            if (protocolConversion != null) {
+                return protocolConversion.Bind(this, DynamicMetaObject.EmptyMetaObjects);
+            } else {
+                return binder.FallbackConvert(this);
+            }
+        }
     }
     
     public abstract class RubyMetaObject&lt;T&gt; : RubyMetaObject {</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyMetaObject.cs</filename>
    </modified>
    <modified>
      <diff>@@ -14,19 +14,17 @@
  * ***************************************************************************/
 
 using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Dynamic;
+using System.Linq.Expressions;
+using System.Reflection;
 using IronRuby.Builtins;
 using IronRuby.Compiler;
 using IronRuby.Compiler.Generation;
-using Microsoft.Scripting.Runtime;
-using System.Linq.Expressions;
-using Ast = System.Linq.Expressions.Expression;
+using IronRuby.Runtime.Calls;
 using AstFactory = IronRuby.Compiler.Ast.AstFactory;
 using AstUtils = Microsoft.Scripting.Ast.Utils;
-using System.Dynamic;
-using System.Reflection;
-using System.Diagnostics;
-using System.Collections.Generic;
-using IronRuby.Runtime.Calls;
 
 namespace IronRuby.Runtime.Conversions {
 
@@ -81,7 +79,7 @@ namespace IronRuby.Runtime.Conversions {
 
                 conversionMethod = targetClass.ResolveMethodForSiteNoLock(ToS, VisibilityContext.AllVisible).Info;
 
-                // find method_missing - we need to add &quot;to_xxx&quot; methods to the missing methods table:
+                // find method_missing - we need to add &quot;to_s&quot; method to the missing methods table:
                 if (conversionMethod == null) {
                     methodMissing = targetClass.ResolveMethodMissingForSite(ToS, RubyMethodVisibility.None);
                 }</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/ConvertToSAction.cs</filename>
    </modified>
    <modified>
      <diff>@@ -270,5 +270,75 @@ namespace IronRuby.Runtime.Conversions {
             }
             return Candidate.Equivalent;
         }
+
+        #region Runtime Conversions
+
+        internal static Byte ToByte(int value) {
+            if (value &gt;= Byte.MinValue &amp;&amp; value &lt;= Byte.MaxValue) {
+                return (Byte)value;
+            }
+            throw RubyExceptions.CreateRangeError(&quot;number too big to convert into System::Byte&quot;);
+        }
+
+        internal static SByte ToSByte(int value) {
+            if (value &gt;= SByte.MinValue &amp;&amp; value &lt;= SByte.MaxValue) {
+                return (SByte)value;
+            }
+            throw RubyExceptions.CreateRangeError(&quot;number too big to convert into System::SByte&quot;);
+        }
+
+        internal static Int16 ToInt16(int value) {
+            if (value &gt;= Int16.MinValue &amp;&amp; value &lt;= Int16.MaxValue) {
+                return (Int16)value;
+            }
+            throw RubyExceptions.CreateRangeError(&quot;number too big to convert into System::Int16&quot;);
+        }
+
+        internal static UInt16 ToUInt16(int value) {
+            if (value &gt;= UInt16.MinValue &amp;&amp; value &lt;= UInt16.MaxValue) {
+                return (UInt16)value;
+            }
+            throw RubyExceptions.CreateRangeError(&quot;number too big to convert into System::UInt16&quot;);
+        }
+
+        internal static UInt32 ToUInt32(int value) {
+            if (value &gt;= UInt32.MinValue) {
+                return (UInt32)value;
+            }
+            throw RubyExceptions.CreateRangeError(&quot;number too big to convert into System::UInt32&quot;);
+        }
+
+        internal static UInt32 ToUInt32(BigInteger value) {
+            UInt32 result;
+            if (value.AsUInt32(out result)) {
+                return result;
+            }
+            throw RubyExceptions.CreateRangeError(&quot;number too big to convert into System::UInt32&quot;);
+        }
+
+        internal static Int64 ToInt64(BigInteger value) {
+            Int64 result;
+            if (value.AsInt64(out result)) {
+                return result;
+            }
+            throw RubyExceptions.CreateRangeError(&quot;number too big to convert into System::Int64&quot;);
+        }
+
+        internal static UInt64 ToUInt64(int value) {
+            if (value &gt;= 0) {
+                return (UInt64)value;
+            }
+            throw RubyExceptions.CreateRangeError(&quot;number too big to convert into System::UInt64&quot;);
+        }
+
+        internal static UInt64 ToUInt64(BigInteger value) {
+            UInt64 result;
+            if (value.AsUInt64(out result)) {
+                return result;
+            }
+            throw RubyExceptions.CreateRangeError(&quot;number too big to convert into System::UInt64&quot;);
+        }
+
+        #endregion
     }
 }</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/Converter.cs</filename>
    </modified>
    <modified>
      <diff>@@ -61,24 +61,32 @@ namespace IronRuby.Runtime.Conversions {
         }
 
         protected override bool Build(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, bool defaultFallback) {
-            if (TryImplicitConversion(metaBuilder, args)) {
-                metaBuilder.AddObjectTypeRestriction(args.Target, args.TargetExpression);
-                return true;
-            }
-
             // TODO: this is our meta object, should we add IRubyMetaConvertible interface instead of using interop-binder?
             if (args.Target is IDynamicMetaObjectProvider) {
                 metaBuilder.SetMetaResult(args.MetaTarget.BindConvert(new InteropBinder.Convert(args.RubyContext, _type, true)), false);
                 return true;
             }
 
+            return BuildConversion(metaBuilder, args.MetaTarget, args.MetaContext.Expression, _type, defaultFallback);
+        }
+
+        internal static bool BuildConversion(MetaObjectBuilder/*!*/ metaBuilder, DynamicMetaObject/*!*/ target, Expression/*!*/ contextExpression, 
+            Type/*!*/ toType, bool defaultFallback) {
+
+            Expression expr = TryImplicitConversion(target, toType);
+            if (expr != null) {
+                metaBuilder.Result = expr;
+                metaBuilder.AddObjectTypeRestriction(target.Value, target.Expression);
+                return true;
+            }
+
             if (defaultFallback) {
-                metaBuilder.AddObjectTypeRestriction(args.Target, args.TargetExpression);
+                metaBuilder.AddObjectTypeRestriction(target.Value, target.Expression);
 
                 metaBuilder.SetError(Methods.MakeTypeConversionError.OpCall(
-                    args.MetaContext.Expression,
-                    AstUtils.Convert(args.TargetExpression, typeof(object)),
-                    Ast.Constant(_type)
+                    contextExpression,
+                    AstUtils.Convert(target.Expression, typeof(object)),
+                    Ast.Constant(toType)
                 ));
                 return true;
             }
@@ -86,22 +94,20 @@ namespace IronRuby.Runtime.Conversions {
             return false;
         }
 
-        internal bool TryImplicitConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
+        private static Expression TryImplicitConversion(DynamicMetaObject/*!*/ target, Type/*!*/ toType) {
             // TODO: include this into ImplicitConvert?
-            if (args.Target == null) {
-                if (!_type.IsValueType || _type.IsGenericType &amp;&amp; _type.GetGenericTypeDefinition() == typeof(Nullable&lt;&gt;)) {
-                    metaBuilder.Result = AstUtils.Constant(null, _type);
-                    return true;
+            if (target.Value == null) {
+                if (!toType.IsValueType || toType.IsGenericType &amp;&amp; toType.GetGenericTypeDefinition() == typeof(Nullable&lt;&gt;)) {
+                    return AstUtils.Constant(null, toType);
                 } else {
-                    return false;
+                    return null;
                 }
             }
 
-            Type fromType = args.Target.GetType();
-            return null != (metaBuilder.Result = 
-                Converter.ImplicitConvert(args.TargetExpression, fromType, _type) ??
-                Converter.ExplicitConvert(args.TargetExpression, fromType, _type)
-            );
+            Type fromType = target.Value.GetType();
+            return 
+                Converter.ImplicitConvert(target.Expression, fromType, toType) ??
+                Converter.ExplicitConvert(target.Expression, fromType, toType);
         }
     }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/GenericConversionAction.cs</filename>
    </modified>
    <modified>
      <diff>@@ -23,15 +23,14 @@ using System.Reflection;
 using IronRuby.Builtins;
 using IronRuby.Compiler;
 using IronRuby.Compiler.Generation;
+using IronRuby.Runtime.Calls;
 using Microsoft.Scripting;
+using Microsoft.Scripting.Generation;
 using Microsoft.Scripting.Math;
-using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 using Ast = System.Linq.Expressions.Expression;
 using AstFactory = IronRuby.Compiler.Ast.AstFactory;
 using AstUtils = Microsoft.Scripting.Ast.Utils;
-using Microsoft.Scripting.Generation;
-using IronRuby.Runtime.Calls;
 
 namespace IronRuby.Runtime.Conversions {
     public abstract class RubyConversionAction : RubyMetaBinder {
@@ -80,27 +79,35 @@ namespace IronRuby.Runtime.Conversions {
         }
 
         private static Func&lt;RubyMetaBinderFactory, RubyConversionAction&gt; TryGetDefaultConversionAction(Type/*!*/ parameterType) {
-            if (parameterType == typeof(MutableString)) {
-                return (factory) =&gt; factory.Conversion&lt;ConvertToStrAction&gt;();
+            // TODO: 
+            // nullable int (see Array#fill, Sockets:ConvertToSocketFlag, Kernel#open(perm=nil), File.chown, IO#read)
+
+            switch (Type.GetTypeCode(parameterType)) {
+                case TypeCode.SByte: return (factory) =&gt; factory.Conversion&lt;ConvertToSByteAction&gt;();
+                case TypeCode.Byte: return (factory) =&gt; factory.Conversion&lt;ConvertToByteAction&gt;();
+                case TypeCode.Int16: return (factory) =&gt; factory.Conversion&lt;ConvertToInt16Action&gt;();
+                case TypeCode.UInt16: return (factory) =&gt; factory.Conversion&lt;ConvertToUInt16Action&gt;();
+                case TypeCode.Int32: return (factory) =&gt; factory.Conversion&lt;ConvertToFixnumAction&gt;();
+                case TypeCode.UInt32: return (factory) =&gt; factory.Conversion&lt;ConvertToUInt32Action&gt;();
+                case TypeCode.Int64: return (factory) =&gt; factory.Conversion&lt;ConvertToInt64Action&gt;();
+                case TypeCode.UInt64: return (factory) =&gt; factory.Conversion&lt;ConvertToUInt64Action&gt;();
+                case TypeCode.Single: return (factory) =&gt; factory.Conversion&lt;ConvertToSingleAction&gt;();
+                case TypeCode.Double: return (factory) =&gt; factory.Conversion&lt;ConvertToFAction&gt;();
+                case TypeCode.String: return (factory) =&gt; factory.Conversion&lt;ConvertToSymbolAction&gt;();
             }
 
-            // TODO: nullable int (see Array#fill, Sockets:ConvertToSocketFlag, Kernel#open(perm=nil), File.chown)
-            if (parameterType == typeof(int)) {
-                return (factory) =&gt; factory.Conversion&lt;ConvertToFixnumAction&gt;();
+            if (parameterType == typeof(MutableString)) {
+                return (factory) =&gt; factory.Conversion&lt;ConvertToStrAction&gt;();
             }
 
-            if (parameterType == typeof(string)) {
-                return (factory) =&gt; factory.Conversion&lt;ConvertToSymbolAction&gt;();
+            if (parameterType == typeof(BigInteger)) {
+                return (factory) =&gt; factory.Conversion&lt;ConvertToBignumAction&gt;();
             }
 
             if (parameterType == typeof(IntegerValue)) {
                 return (factory) =&gt; factory.Conversion&lt;ConvertToIntAction&gt;();
             }
 
-            if (parameterType == typeof(double)) {
-                return (factory) =&gt; factory.Conversion&lt;ConvertToFAction&gt;();
-            }
-
             if (parameterType == typeof(Union&lt;int, MutableString&gt;)) {
                 return (factory) =&gt; factory.CompositeConversion(CompositeConversion.ToFixnumToStr);
             }
@@ -124,18 +131,18 @@ namespace IronRuby.Runtime.Conversions {
             return null;
         }
 
-        internal static Expression ImplicitConvert(Type/*!*/ type, CallArguments/*!*/ args) {
-            return Converter.ImplicitConvert(args.TargetExpression, CompilerHelpers.GetType(args.Target), type);
+        internal static Expression ImplicitConvert(Type/*!*/ toType, CallArguments/*!*/ args) {
+            return Converter.ImplicitConvert(args.TargetExpression, CompilerHelpers.GetType(args.Target), toType);
         }
 
-        internal static Expression ExplicitConvert(Type/*!*/ type, CallArguments/*!*/ args) {
-            return Converter.ExplicitConvert(args.TargetExpression, CompilerHelpers.GetType(args.Target), type);
+        internal static Expression ExplicitConvert(Type/*!*/ toType, CallArguments/*!*/ args) {
+            return Converter.ExplicitConvert(args.TargetExpression, CompilerHelpers.GetType(args.Target), toType);
         }
 
-        internal static Expression Convert(Type/*!*/ type, CallArguments/*!*/ args) {
+        internal static Expression Convert(Type/*!*/ toType, CallArguments/*!*/ args) {
             var fromType = CompilerHelpers.GetType(args.Target);
-            return Converter.ImplicitConvert(args.TargetExpression, fromType, type)
-                ?? Converter.ExplicitConvert(args.TargetExpression, fromType, type);
+            return Converter.ImplicitConvert(args.TargetExpression, fromType, toType)
+                ?? Converter.ExplicitConvert(args.TargetExpression, fromType, toType);
         }
     }
 
@@ -216,13 +223,6 @@ namespace IronRuby.Runtime.Conversions {
             }
 
             if (!respondToMethod.Found) {
-                // TODO: Is MRI consistent on respond_to? visibility?
-                //if (respondToMethod.IncompatibleVisibility != RubyMethodVisibility.None) {
-                //    // respond_to? is not visible:
-                //    conversions[conversions.Length - 1].SetError(metaBuilder, args, targetClassNameConstant, resultType);
-                //    return;
-                //} else 
-                    
                 if (conversionMethod == null) {
                     // error:
                     selectedConversion.SetError(metaBuilder, args, targetClassNameConstant, resultType);
@@ -380,6 +380,8 @@ namespace IronRuby.Runtime.Conversions {
         protected override MethodInfo ConversionResultValidator { get { return Methods.ToProcValidator; } }
     }
 
+    #region String, Symbol, Regex
+
     public sealed class ConvertToStrAction : ConvertToReferenceTypeAction&lt;ConvertToStrAction, MutableString&gt; {
         protected override string/*!*/ ToMethodName { get { return Symbols.ToStr; } }
         protected override string/*!*/ TargetTypeName { get { return &quot;String&quot;; } }
@@ -406,6 +408,46 @@ namespace IronRuby.Runtime.Conversions {
         protected override MethodInfo ConversionResultValidator { get { return Methods.ToRegexValidator; } }
     }
 
+    public sealed class ConvertToSymbolAction : ConvertToReferenceTypeAction&lt;ConvertToSymbolAction, string&gt; {
+        protected override string/*!*/ ToMethodName { get { return Symbols.ToStr; } }
+        protected override string/*!*/ TargetTypeName { get { return &quot;Symbol&quot;; } }
+        protected override MethodInfo ConversionResultValidator { get { return Methods.ToSymbolValidator; } }
+
+        internal protected override bool TryImplicitConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
+            if (base.TryImplicitConversion(metaBuilder, args)) {
+                return true;
+            }
+
+            object target = args.Target;
+            var targetExpression = args.TargetExpression;
+
+            var str = target as MutableString;
+            if (str != null) {
+                metaBuilder.Result = Methods.ConvertMutableStringToSymbol.OpCall(AstUtils.Convert(targetExpression, typeof(MutableString)));
+                return true;
+            }
+
+            if (target is SymbolId) {
+                metaBuilder.Result = Methods.ConvertSymbolIdToSymbol.OpCall(AstUtils.Convert(targetExpression, typeof(SymbolId)));
+                return true;
+            }
+
+            if (target is int) {
+                metaBuilder.Result = Methods.ConvertFixnumToSymbol.OpCall(
+                    AstUtils.Convert(args.MetaContext.Expression, typeof(RubyContext)),
+                    AstUtils.Convert(targetExpression, typeof(int))
+                );
+                return true;
+            }
+
+            return false;
+        }
+    }
+
+    #endregion
+
+    #region Array, Hash, Enumerable
+
     public sealed class ConvertToArrayAction : ConvertToReferenceTypeAction&lt;ConvertToArrayAction, IList&gt; {
         protected override string/*!*/ ToMethodName { get { return Symbols.ToAry; } }
         protected override string/*!*/ TargetTypeName { get { return &quot;Array&quot;; } }
@@ -449,10 +491,13 @@ namespace IronRuby.Runtime.Conversions {
         }
     }
 
-    public sealed class ConvertToFixnumAction : ProtocolConversionAction&lt;ConvertToFixnumAction&gt; {
+    #endregion
+
+    #region Integers
+
+    public abstract class ConvertToIntegerAction&lt;TSelf&gt; : ProtocolConversionAction&lt;TSelf&gt;
+        where TSelf : ConvertToIntegerAction&lt;TSelf&gt;, new() {
         protected override string/*!*/ ToMethodName { get { return Symbols.ToInt; } }
-        protected override string/*!*/ TargetTypeName { get { return &quot;Fixnum&quot;; } }
-        protected override MethodInfo ConversionResultValidator { get { return Methods.ToFixnumValidator; } }
 
         internal protected override bool TryImplicitConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
             object target = args.Target;
@@ -462,12 +507,61 @@ namespace IronRuby.Runtime.Conversions {
                 return true;
             }
 
-            return (metaBuilder.Result = Convert(typeof(int), args)) != null;
+            return (metaBuilder.Result = Convert(ReturnType, args)) != null;
         }
     }
 
-    public abstract class ConvertToIntegerActionBase&lt;TSelf&gt; : ProtocolConversionAction&lt;TSelf&gt;
-        where TSelf : ConvertToIntegerActionBase&lt;TSelf&gt;, new() {
+    public sealed class ConvertToFixnumAction : ConvertToIntegerAction&lt;ConvertToFixnumAction&gt; {
+        protected override string/*!*/ TargetTypeName { get { return &quot;Fixnum&quot;; } }
+        protected override MethodInfo ConversionResultValidator { get { return Methods.ToFixnumValidator; } }
+    }
+
+    public sealed class ConvertToByteAction : ConvertToIntegerAction&lt;ConvertToByteAction&gt; {
+        protected override string/*!*/ TargetTypeName { get { return &quot;System::Byte&quot;; } }
+        protected override MethodInfo ConversionResultValidator { get { return Methods.ToByteValidator; } }
+    }
+
+    public sealed class ConvertToSByteAction : ConvertToIntegerAction&lt;ConvertToSByteAction&gt; {
+        protected override string/*!*/ TargetTypeName { get { return &quot;System::SByte&quot;; } }
+        protected override MethodInfo ConversionResultValidator { get { return Methods.ToSByteValidator; } }
+    }
+
+    public sealed class ConvertToInt16Action : ConvertToIntegerAction&lt;ConvertToInt16Action&gt; {
+        protected override string/*!*/ TargetTypeName { get { return &quot;System::Int16&quot;; } }
+        protected override MethodInfo ConversionResultValidator { get { return Methods.ToInt16Validator; } }
+    }
+
+    public sealed class ConvertToUInt16Action : ConvertToIntegerAction&lt;ConvertToUInt16Action&gt; {
+        protected override string/*!*/ TargetTypeName { get { return &quot;System::UInt16&quot;; } }
+        protected override MethodInfo ConversionResultValidator { get { return Methods.ToUInt16Validator; } }
+    }
+
+    public sealed class ConvertToUInt32Action : ConvertToIntegerAction&lt;ConvertToUInt32Action&gt; {
+        protected override string/*!*/ TargetTypeName { get { return &quot;System::UInt32&quot;; } }
+        protected override MethodInfo ConversionResultValidator { get { return Methods.ToUInt32Validator; } }
+    }
+
+    public sealed class ConvertToUInt64Action : ConvertToIntegerAction&lt;ConvertToUInt64Action&gt; {
+        protected override string/*!*/ TargetTypeName { get { return &quot;System::UInt64&quot;; } }
+        protected override MethodInfo ConversionResultValidator { get { return Methods.ToUInt64Validator; } }
+    }
+
+    public sealed class ConvertToInt64Action : ConvertToIntegerAction&lt;ConvertToInt64Action&gt; {
+        protected override string/*!*/ TargetTypeName { get { return &quot;System::Int64&quot;; } }
+        protected override MethodInfo ConversionResultValidator { get { return Methods.ToInt64Validator; } }
+    }
+
+    public sealed class ConvertToBignumAction : ConvertToIntegerAction&lt;ConvertToBignumAction&gt; {
+        protected override string/*!*/ TargetTypeName { get { return &quot;Bignum&quot;; } }
+        protected override MethodInfo ConversionResultValidator { get { return Methods.ToBignumValidator; } }
+    }
+
+    #endregion
+
+    #region IntegerValue
+
+    public abstract class ConvertToIntegerValueAction&lt;TSelf&gt; : ProtocolConversionAction&lt;TSelf&gt;
+        where TSelf : ConvertToIntegerValueAction&lt;TSelf&gt;, new() {
 
         protected override string/*!*/ TargetTypeName { get { return &quot;Integer&quot;; } }
 
@@ -490,7 +584,7 @@ namespace IronRuby.Runtime.Conversions {
     /// &lt;summary&gt;
     /// Calls to_int and wraps the result (Fixnum or Bignum) into IntegerValue.
     /// &lt;/summary&gt;
-    public sealed class ConvertToIntAction : ConvertToIntegerActionBase&lt;ConvertToIntAction&gt; {
+    public sealed class ConvertToIntAction : ConvertToIntegerValueAction&lt;ConvertToIntAction&gt; {
         protected override string/*!*/ ToMethodName { get { return Symbols.ToInt; } }
         protected override MethodInfo ConversionResultValidator { get { return Methods.ToIntegerValidator; } }
     }
@@ -498,18 +592,21 @@ namespace IronRuby.Runtime.Conversions {
     /// &lt;summary&gt;
     /// Calls to_i and wraps the result (Fixnum or Bignum) into IntegerValue.
     /// &lt;/summary&gt;
-    public sealed class ConvertToIAction : ConvertToIntegerActionBase&lt;ConvertToIAction&gt; {
+    public sealed class ConvertToIAction : ConvertToIntegerValueAction&lt;ConvertToIAction&gt; {
         protected override string/*!*/ ToMethodName { get { return Symbols.ToI; } }
         protected override MethodInfo ConversionResultValidator { get { return Methods.ToIntegerValidator; } }
     }
 
+    #endregion
+
+    #region Floating Point
+
     /// &lt;summary&gt;
     /// Calls to_f (in most cases) and wraps the result into double. It directly calls Kernel.Float for String, Fixnum and Bignum.
     /// &lt;/summary&gt;
-    public sealed class ConvertToFAction : ProtocolConversionAction&lt;ConvertToFAction&gt; {
-        protected override string/*!*/ TargetTypeName { get { return &quot;Float&quot;; } }
+    public abstract class ConvertToFloatingPointAction&lt;TSelf&gt; : ProtocolConversionAction&lt;TSelf&gt;
+        where TSelf : ConvertToFloatingPointAction&lt;TSelf&gt;, new() {
         protected override string/*!*/ ToMethodName { get { return Symbols.ToF; } }
-        protected override MethodInfo ConversionResultValidator { get { return Methods.ToFloatValidator; } }
 
         internal protected override bool TryImplicitConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
             object target = args.Target;
@@ -519,7 +616,7 @@ namespace IronRuby.Runtime.Conversions {
                 return true;
             }
 
-            metaBuilder.Result = Convert(typeof(double), args) ?? FromString(args);
+            metaBuilder.Result = Convert(ReturnType, args) ?? FromString(args);
 
             return metaBuilder.Result != null;
         }
@@ -539,39 +636,15 @@ namespace IronRuby.Runtime.Conversions {
         }
     }
 
-    public sealed class ConvertToSymbolAction : ConvertToReferenceTypeAction&lt;ConvertToSymbolAction, string&gt; {
-        protected override string/*!*/ ToMethodName { get { return Symbols.ToStr; } }
-        protected override string/*!*/ TargetTypeName { get { return &quot;Symbol&quot;; } }
-        protected override MethodInfo ConversionResultValidator { get { return Methods.ToSymbolValidator; } }
-
-        internal protected override bool TryImplicitConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
-            if (base.TryImplicitConversion(metaBuilder, args)) {
-                return true;
-            }
-
-            object target = args.Target;
-            var targetExpression = args.TargetExpression;
-            
-            var str = target as MutableString;
-            if (str != null) {
-                metaBuilder.Result = Methods.ConvertMutableStringToSymbol.OpCall(AstUtils.Convert(targetExpression, typeof(MutableString)));
-                return true;
-            }
-
-            if (target is SymbolId) {
-                metaBuilder.Result = Methods.ConvertSymbolIdToSymbol.OpCall(AstUtils.Convert(targetExpression, typeof(SymbolId)));
-                return true;
-            }
-
-            if (target is int) {
-                metaBuilder.Result = Methods.ConvertFixnumToSymbol.OpCall(
-                    AstUtils.Convert(args.MetaContext.Expression, typeof(RubyContext)), 
-                    AstUtils.Convert(targetExpression, typeof(int))
-                );
-                return true;
-            }
+    public sealed class ConvertToFAction : ConvertToFloatingPointAction&lt;ConvertToFAction&gt; {
+        protected override string/*!*/ TargetTypeName { get { return &quot;Float&quot;; } }
+        protected override MethodInfo ConversionResultValidator { get { return Methods.ToDoubleValidator; } }
+    }
 
-            return false;
-        }
+    public sealed class ConvertToSingleAction : ConvertToFloatingPointAction&lt;ConvertToSingleAction&gt; {
+        protected override string/*!*/ TargetTypeName { get { return &quot;System::Single&quot;; } }
+        protected override MethodInfo ConversionResultValidator { get { return Methods.ToSingleValidator; } }
     }
+
+    #endregion
 }</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/ProtocolConversionAction.cs</filename>
    </modified>
    <modified>
      <diff>@@ -120,7 +120,7 @@ namespace IronRuby.Runtime {
                     if (context.RubyOptions.Compatibility == RubyCompatibility.Ruby18) {
                         var kcode = KCoding.GetKCodeName(context.KCode);
                         Utils.Log(&quot;KCODE set to &quot; + kcode, &quot;KCODE&quot;);
-                        return MutableString.Create(kcode);
+                        return MutableString.CreateAscii(kcode);
                     }
 #endif
                     context.ReportWarning(&quot;variable $KCODE is no longer effective&quot;);</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/Globals/SpecialGlobalVariableInfo.cs</filename>
    </modified>
    <modified>
      <diff>@@ -91,6 +91,16 @@ namespace IronRuby.Runtime {
             return (object)_bignum ?? ScriptingRuntimeHelpers.Int32ToObject(_fixnum);
         }
 
+        public long ToInt64() {
+            long result;
+            if (IsFixnum) {
+                result = _fixnum;
+            } else if (!_bignum.AsInt64(out result)) {
+                throw RubyExceptions.CreateRangeError(&quot;Bignum too big to convert into 64-bit signed integer&quot;);
+            }
+            return result;
+        }
+
         public bool Equals(IntegerValue other) {
             if (_fixnum != other.Fixnum) return false;
             if (ReferenceEquals(_bignum, null)) return ReferenceEquals(other._bignum, null);</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/IntegerValue.cs</filename>
    </modified>
    <modified>
      <diff>@@ -146,7 +146,7 @@ namespace IronRuby.Runtime {
             
             if (options.HasSearchPaths) {
                 foreach (string path in options.SearchPaths) {
-                    loadPaths.Add(MutableString.Create(path.Replace('\\', '/')));
+                    loadPaths.Add(MutableString.Create(path, RubyEncoding.Path));
                 }
             }
             
@@ -160,7 +160,7 @@ namespace IronRuby.Runtime {
             
             AddAbsoluteLibraryPaths(loadPaths, applicationBaseDir, options.LibraryPaths);
 #endif
-            loadPaths.Add(MutableString.Create(&quot;.&quot;));
+            loadPaths.Add(MutableString.CreateAscii(&quot;.&quot;));
             return loadPaths;
         }
 
@@ -177,7 +177,7 @@ namespace IronRuby.Runtime {
                 } else {
                     fullPath = path;
                 }
-                result.Add(MutableString.Create(fullPath.Replace('\\', '/')));
+                result.Add(MutableString.Create(fullPath.Replace('\\', '/'), RubyEncoding.Path));
             }
         }
 
@@ -304,7 +304,7 @@ namespace IronRuby.Runtime {
             } catch (Exception e) {
                 if (!tryPartialName || !(e is FileNotFoundException)) {
                     if (throwOnError) {
-                        throw new LoadError(e.Message, e);
+                        throw RubyExceptions.CreateLoadError(e);
                     } else {
                         return null;
                     }
@@ -320,13 +320,13 @@ namespace IronRuby.Runtime {
                 assembly = Assembly.LoadWithPartialName(assemblyName);
             } catch (Exception e) {
                 if (throwOnError) {
-                    throw new LoadError(e.Message, e);
+                    throw RubyExceptions.CreateLoadError(e);
                 } else {
                     return null;
                 }
             }
             if (assembly == null &amp;&amp; throwOnError) {
-                throw new LoadError(String.Format(&quot;Assembly '{0}' not found&quot;, assemblyName));
+                throw RubyExceptions.CreateLoadError(String.Format(&quot;Assembly '{0}' not found&quot;, assemblyName));
             }
 #pragma warning restore 618,612
             return assembly;
@@ -341,7 +341,9 @@ namespace IronRuby.Runtime {
                 try {
                     initializerType = assembly.GetType(typeName, true);
                 } catch (Exception e) {
-                    if (throwOnError) throw new LoadError(e.Message, e);
+                    if (throwOnError) {
+                        throw new LoadError(e.Message, e);
+                    }
                     return false;
                 }
 
@@ -351,7 +353,9 @@ namespace IronRuby.Runtime {
                 try {
                     DomainManager.LoadAssembly(assembly);
                 } catch (Exception e) {
-                    if (throwOnError) throw new LoadError(e.Message, e);
+                    if (throwOnError) {
+                        throw RubyExceptions.CreateLoadError(e);
+                    }
                     return false;
                 }
             }
@@ -436,7 +440,7 @@ namespace IronRuby.Runtime {
                     return assembly;
                 }
             } catch (Exception e) {
-                throw new LoadError(e.Message, e);
+                throw RubyExceptions.CreateLoadError(e);
             }
 
             return null;
@@ -469,10 +473,10 @@ namespace IronRuby.Runtime {
             string[] sourceFileExtensions = DomainManager.Configuration.GetFileExtensions();
             ResolvedFile file = FindFile(path, (flags &amp; LoadFlags.AppendExtensions) != 0, sourceFileExtensions);
             if (file == null) {
-                throw new LoadError(String.Format(&quot;no such file to load -- {0}&quot;, path));
+                throw RubyExceptions.CreateLoadError(String.Format(&quot;no such file to load -- {0}&quot;, path));
             }
 
-            MutableString pathWithExtension = MutableString.Create(path);
+            MutableString pathWithExtension = MutableString.Create(path, RubyEncoding.Path);
             if (file.AppendedExtension != null) {
                 pathWithExtension.Append(file.AppendedExtension);
             }
@@ -483,7 +487,7 @@ namespace IronRuby.Runtime {
                     if (file.SourceUnit != null) {
                         Scope loadedScope;
                         if (!LoadedScripts.TryGetValue(fullPath, out loadedScope)) {
-                            throw new LoadError(String.Format(&quot;no such file to load -- {0}&quot;, file.Path));
+                            throw RubyExceptions.CreateLoadError(String.Format(&quot;no such file to load -- {0}&quot;, file.Path));
                         }
                         loaded = loadedScope;
                     } else {
@@ -514,7 +518,7 @@ namespace IronRuby.Runtime {
                         DomainManager.LoadAssembly(assembly);
                         loaded = assembly;
                     } catch (Exception e) {
-                        throw new LoadError(e.Message, e);
+                        throw RubyExceptions.CreateLoadError(e);
                     }
                 }
 
@@ -596,7 +600,7 @@ namespace IronRuby.Runtime {
                 isAbsolutePath = Platform.IsAbsolutePath(path);
                 extension = Path.GetExtension(path);
             } catch (ArgumentException e) {
-                throw new LoadError(e.Message, e);
+                throw RubyExceptions.CreateLoadError(e);
             }
 
             // Absolute path -&gt; load paths not consulted.
@@ -666,7 +670,7 @@ namespace IronRuby.Runtime {
                     return GetSourceUnit(path + matchingExtensions[0], matchingExtensions[0], true);
                 } else if (matchingExtensions.Count &gt; 1) {
                     Exception e = new AmbiguousFileNameException(path + matchingExtensions[0], path + matchingExtensions[1]);
-                    throw new LoadError(e.Message, e);
+                    throw RubyExceptions.CreateLoadError(e);
                 }
 
                 foreach (string libExtension in _LibraryExtensions) {
@@ -731,7 +735,7 @@ namespace IronRuby.Runtime {
             lock (_loadPaths) {
                 _loadPaths.Clear();
                 foreach (string path in paths) {
-                    _loadPaths.Add(MutableString.Create(path));
+                    _loadPaths.Add(MutableString.Create(path, RubyEncoding.Path));
                 }
             }
         }
@@ -741,7 +745,7 @@ namespace IronRuby.Runtime {
 
             lock (_loadPaths) {
                 foreach (string path in paths) {
-                    _loadPaths.Add(MutableString.Create(path));
+                    _loadPaths.Add(MutableString.Create(path, RubyEncoding.Path));
                 }
             }
         }
@@ -751,7 +755,7 @@ namespace IronRuby.Runtime {
 
             lock (_loadPaths) {
                 foreach (string path in paths) {
-                    _loadPaths.Insert(0, MutableString.Create(path));
+                    _loadPaths.Insert(0, MutableString.Create(path, RubyEncoding.Path));
                 }
             }
         }
@@ -810,7 +814,7 @@ namespace IronRuby.Runtime {
                 Assembly assembly = _context.DomainManager.Platform.LoadAssembly(GetIronRubyAssemblyLongName(&quot;IronRuby.Libraries&quot;));
                 initializerType = assembly.GetType(LibraryInitializer.GetBuiltinsFullTypeName());
             } catch (Exception e) {
-                throw new LoadError(e.Message, e);
+                throw RubyExceptions.CreateLoadError(e);
             }
 
             LoadLibrary(initializerType, true);
@@ -829,13 +833,13 @@ namespace IronRuby.Runtime {
             try {
                 initializer = Activator.CreateInstance(initializerType) as LibraryInitializer;
             } catch (TargetInvocationException e) {
-                throw new LoadError(e.Message, e);
+                throw RubyExceptions.CreateLoadError(e.InnerException);
             } catch (Exception e) {
-                throw new LoadError(e.Message, e);
+                throw RubyExceptions.CreateLoadError(e);
             }
 
             if (initializer == null) {
-                throw new LoadError(String.Format(&quot;Specified type {0} is not a subclass of {1}&quot;, 
+                throw RubyExceptions.CreateLoadError(String.Format(&quot;Specified type {0} is not a subclass of {1}&quot;, 
                     initializerType.FullName,
                     typeof(LibraryInitializer).FullName)
                 );</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs</filename>
    </modified>
    <modified>
      <diff>@@ -40,6 +40,7 @@ namespace IronRuby.Runtime {
     /// &lt;/summary&gt;
     public sealed class RubyContext : LanguageContext {
         internal static readonly Guid RubyLanguageGuid = new Guid(&quot;F03C4640-DABA-473f-96F1-391400714DAB&quot;);
+        private static readonly Guid LanguageVendor_Microsoft = new Guid(-1723120188, -6423, 0x11d2, 0x90, 0x3f, 0, 0xc0, 0x4f, 0xa3, 2, 0xa1);
         private static int _RuntimeIdGenerator = 0;
 
         // MRI compliance:
@@ -208,9 +209,7 @@ namespace IronRuby.Runtime {
 
         [Conditional(&quot;DEBUG&quot;)]
         internal void RequiresClassHierarchyLock() {
-            if (!_classHierarchyLock.IsLocked) {
-                throw new InvalidOperationException(&quot;Code can only be executed while holding class hierarchy lock.&quot;);
-            }
+            ContractUtils.Requires(_classHierarchyLock.IsLocked, &quot;Code can only be executed while holding class hierarchy lock.&quot;);
         }
 
         // classes used by runtime (we need to update initialization generator if any of these are added):
@@ -362,6 +361,10 @@ namespace IronRuby.Runtime {
             get { return RubyLanguageGuid; }
         }
 
+        public override Guid VendorGuid {
+            get { return LanguageVendor_Microsoft; }
+        }
+
         public int RuntimeId {
             get { return _runtimeId; }
         }
@@ -378,7 +381,7 @@ namespace IronRuby.Runtime {
             _runtimeId = Interlocked.Increment(ref _RuntimeIdGenerator);
             _upTime = new Stopwatch();
             _upTime.Start();
-
+            
             Binder = new RubyBinder(this);
 
             _metaBinderFactory = new RubyMetaBinderFactory(this);
@@ -389,17 +392,17 @@ namespace IronRuby.Runtime {
             _namespaceCache = new Dictionary&lt;NamespaceTracker, RubyModule&gt;();
             _referenceTypeInstanceData = new WeakTable&lt;object, RubyInstanceData&gt;();
             _valueTypeInstanceData = new Dictionary&lt;object, RubyInstanceData&gt;();
-            _inputProvider = new RubyInputProvider(this, _options.Arguments);
+            _inputProvider = new RubyInputProvider(this, _options.Arguments, _options.ArgumentEncoding);
             _globalScope = DomainManager.Globals;
             _loader = new Loader(this);
             _emptyScope = new RubyTopLevelScope(this);
             if (_options.MainFile != null) {
-                _commandLineProgramPath = MutableString.Create(_options.MainFile);
+                _commandLineProgramPath = MutableString.Create(_options.MainFile, RubyEncoding.Path);
             }
             _currentException = null;
             _currentSafeLevel = 0;
             _childProcessExitStatus = null;
-            _inputSeparator = MutableString.Create(&quot;\n&quot;);
+            _inputSeparator = MutableString.CreateAscii(&quot;\n&quot;);
             _outputSeparator = null;
             _stringSeparator = null;
             _itemSeparator = null;
@@ -502,10 +505,10 @@ namespace IronRuby.Runtime {
         private void InitializeGlobalConstants() {
             Debug.Assert(_objectClass != null);
 
-            MutableString version = MutableString.Create(RubyContext.MriVersion);
-            MutableString platform = MutableString.Create(&quot;i386-mswin32&quot;);   // TODO: make this the correct string for MAC OS X in Silverlight
-            MutableString releaseDate = MutableString.Create(RubyContext.MriReleaseDate);
-            MutableString rubyEngine = MutableString.Create(&quot;ironruby&quot;);
+            MutableString version = MutableString.CreateAscii(RubyContext.MriVersion);
+            MutableString platform = MutableString.CreateAscii(&quot;i386-mswin32&quot;);   // TODO: make this the correct string for MAC OS X in Silverlight
+            MutableString releaseDate = MutableString.CreateAscii(RubyContext.MriReleaseDate);
+            MutableString rubyEngine = MutableString.CreateAscii(&quot;ironruby&quot;);
 
             SetGlobalConstant(&quot;RUBY_ENGINE&quot;, rubyEngine);
             SetGlobalConstant(&quot;RUBY_VERSION&quot;, version);
@@ -517,7 +520,7 @@ namespace IronRuby.Runtime {
             SetGlobalConstant(&quot;PLATFORM&quot;, platform);
             SetGlobalConstant(&quot;RELEASE_DATE&quot;, releaseDate);
 
-            SetGlobalConstant(&quot;IRONRUBY_VERSION&quot;, MutableString.Create(RubyContext.IronRubyVersionString));
+            SetGlobalConstant(&quot;IRONRUBY_VERSION&quot;, MutableString.CreateAscii(RubyContext.IronRubyVersionString));
 
             SetGlobalConstant(&quot;STDIN&quot;, StandardInput);
             SetGlobalConstant(&quot;STDOUT&quot;, StandardOutput);
@@ -544,9 +547,12 @@ namespace IronRuby.Runtime {
 
         private void InitializeFileDescriptors(SharedIO/*!*/ io) {
             Debug.Assert(_fileDescriptors.Count == 0);
-            StandardInput = new RubyIO(this, new ConsoleStream(io, ConsoleStreamType.Input), &quot;r&quot;);
-            StandardOutput = new RubyIO(this, new ConsoleStream(io, ConsoleStreamType.Output), &quot;a&quot;);
-            StandardErrorOutput = new RubyIO(this, new ConsoleStream(io, ConsoleStreamType.ErrorOutput), &quot;a&quot;);
+            Stream stream = new ConsoleStream(io, ConsoleStreamType.Input);                
+            StandardInput = new RubyIO(this, stream, AllocateFileDescriptor(stream), IOMode.ReadOnly);
+            stream = new ConsoleStream(io, ConsoleStreamType.Output);
+            StandardOutput = new RubyIO(this, stream, AllocateFileDescriptor(stream), IOMode.WriteOnly | IOMode.WriteAppends);
+            stream = new ConsoleStream(io, ConsoleStreamType.ErrorOutput);
+            StandardErrorOutput = new RubyIO(this, stream, AllocateFileDescriptor(stream), IOMode.WriteOnly | IOMode.WriteAppends);
         }
 
         // TODO: internal
@@ -618,6 +624,7 @@ namespace IronRuby.Runtime {
 
             AddModuleToCacheNoLock(typeof(Kernel), _kernelModule);
             AddModuleToCacheNoLock(objectTracker.Type, _objectClass);
+            AddModuleToCacheNoLock(typeof(RubyObject), _objectClass);
             AddModuleToCacheNoLock(_moduleClass.GetUnderlyingSystemType(), _moduleClass);
             AddModuleToCacheNoLock(_classClass.GetUnderlyingSystemType(), _classClass);
 
@@ -1500,25 +1507,12 @@ namespace IronRuby.Runtime {
         public MutableString/*!*/ Inspect(object obj) {
             RubyClass cls = GetClassOf(obj);
             var inspect = cls.InspectSite;
-            var toS = cls.StringConversionSite;
+            var toS = cls.InspectResultConversionSite;
             return toS.Target(toS, inspect.Target(inspect, obj));
         }
 
         #endregion
 
-        internal string InspectEnsuringClassName(object self) {
-            if (self == null) {
-                return &quot;nil:NilClass&quot;;
-            } else {
-                string strObject = Inspect(self).ConvertToString();
-                if (!strObject.StartsWith(&quot;#&quot;)) {
-                    strObject += &quot;:&quot; + GetClassName(self);
-                }
-                return strObject;
-            }
-        }
-
-
         #region Global Variables: General access (thread-safe)
 
         public object GetGlobalVariable(string/*!*/ name) {
@@ -1679,7 +1673,25 @@ namespace IronRuby.Runtime {
 
         #region IO (thread-safe)
 
-        private readonly List&lt;RubyIO&gt;/*!*/ _fileDescriptors = new List&lt;RubyIO&gt;(10);
+        private sealed class FileDescriptor {
+            public int DuplicateCount;
+            public readonly Stream/*!*/ Stream;
+
+            public FileDescriptor(Stream/*!*/ stream) {
+                Assert.NotNull(stream);
+                Stream = stream;
+                DuplicateCount = 1;
+            }
+
+            public void Close() {
+                DuplicateCount--;
+                if (DuplicateCount == 0) {
+                    Stream.Close();
+                }
+            }
+        }
+
+        private readonly List&lt;FileDescriptor&gt;/*!*/ _fileDescriptors = new List&lt;FileDescriptor&gt;(10);
 
         public const int StandardInputDescriptor = 0;
         public const int StandardOutputDescriptor = 1;
@@ -1689,37 +1701,98 @@ namespace IronRuby.Runtime {
         public object StandardOutput { get; set; }
         public object StandardErrorOutput { get; set; }
 
-        public RubyIO GetDescriptor(int fileDescriptor) {
+        private FileDescriptor TryGetFileDescriptorNoLock(int descriptor) {
+            return (descriptor &lt; 0 || descriptor &gt;= _fileDescriptors.Count) ? null : _fileDescriptors[descriptor];
+        }
+
+        private int AddFileDescriptorNoLock(FileDescriptor/*!*/ fd) {
+            for (int i = 0; i &lt; _fileDescriptors.Count; i++) {
+                if (_fileDescriptors[i] == null) {
+                    _fileDescriptors[i] = fd;
+                    return i;
+                }
+            }
+            _fileDescriptors.Add(fd);
+            return _fileDescriptors.Count - 1;
+        }
+
+        public Stream GetStream(int descriptor) {
             lock (_fileDescriptors) {
-                if (fileDescriptor &lt; 0 || fileDescriptor &gt;= _fileDescriptors.Count) {
-                    return null;
-                } else {
-                    return _fileDescriptors[fileDescriptor];
+                var fd = TryGetFileDescriptorNoLock(descriptor);
+                return (fd != null) ? fd.Stream : null;
+            }
+        }
+
+        public void SetStream(int descriptor, Stream/*!*/ stream) {
+            ContractUtils.RequiresNotNull(stream, &quot;stream&quot;);
+
+            lock (_fileDescriptors) {
+                var fd = TryGetFileDescriptorNoLock(descriptor);
+                if (fd == null) {
+                    throw RubyExceptions.CreateEBADF();
+                }
+                if (fd.Stream != stream) {
+                    fd.Close();
+                    _fileDescriptors[descriptor] = new FileDescriptor(stream);
                 }
             }
         }
 
-        public int AddDescriptor(RubyIO/*!*/ descriptor) {
-            ContractUtils.RequiresNotNull(descriptor, &quot;descriptor&quot;);
+        public void RedirectFileDescriptor(int descriptor, int toDescriptor) {
+            lock (_fileDescriptors) {
+                var fd = TryGetFileDescriptorNoLock(descriptor);
+                if (fd == null) {
+                    throw RubyExceptions.CreateEBADF();
+                }
+
+                var toFd = TryGetFileDescriptorNoLock(toDescriptor);
+                if (toFd == null) {
+                    throw RubyExceptions.CreateEBADF();
+                }
+
+                if (fd == toFd) {
+                    return;
+                }
+
+                fd.Close();
+                toFd.DuplicateCount++;
+                _fileDescriptors[descriptor] = toFd;
+            }
+        }
 
+        public int AllocateFileDescriptor(Stream/*!*/ stream) {
+            ContractUtils.RequiresNotNull(stream, &quot;stream&quot;);
             lock (_fileDescriptors) {
-                for (int i = 0; i &lt; _fileDescriptors.Count; ++i) {
-                    if (_fileDescriptors[i] == null) {
-                        _fileDescriptors[i] = descriptor;
-                        return i;
-                    }
+                return AddFileDescriptorNoLock(new FileDescriptor(stream));
+            }
+        }
+
+        public int DuplicateFileDescriptor(int descriptor) {
+            lock (_fileDescriptors) {
+                var fd = TryGetFileDescriptorNoLock(descriptor);
+                if (fd == null) {
+                    throw RubyExceptions.CreateEBADF();
                 }
-                _fileDescriptors.Add(descriptor);
-                return _fileDescriptors.Count - 1;
+                fd.DuplicateCount++;
+                return AddFileDescriptorNoLock(fd);
             }
         }
 
-        public void RemoveDescriptor(int descriptor) {
-            ContractUtils.Requires(!RubyIO.IsConsoleDescriptor(descriptor));
+        public void CloseStream(int descriptor) {
+            lock (_fileDescriptors) {
+                var fd = TryGetFileDescriptorNoLock(descriptor);
+                if (fd == null) {
+                    throw RubyExceptions.CreateEBADF();
+                }
+                fd.Close();
+                _fileDescriptors[descriptor] = null;
+            }
+        }
 
+        public void RemoveFileDescriptor(int descriptor) {
             lock (_fileDescriptors) {
-                if (descriptor &lt; _fileDescriptors.Count) {
-                    throw new ArgumentException(&quot;Invalid file descriptor&quot;, &quot;descriptor&quot;);
+                if (TryGetFileDescriptorNoLock(descriptor) == null) {
+                    throw RubyExceptions.CreateEBADF();
                 }
 
                 _fileDescriptors[descriptor] = null;
@@ -2047,14 +2120,15 @@ namespace IronRuby.Runtime {
 
                     int i = 0;
                     foreach (var counter in profile) {
-                        if (counter.Key.Length &gt; maxLength) {
-                            maxLength = counter.Key.Length;
+                        string methodInfo = counter.Id;
+                        if (methodInfo.Length &gt; maxLength) {
+                            maxLength = methodInfo.Length;
                         }
 
-                        totalTicks += counter.Value;
+                        totalTicks += counter.Ticks;
 
-                        keys[i] = counter.Key;
-                        values[i] = counter.Value;
+                        keys[i] = methodInfo;
+                        values[i] = counter.Ticks;
                         i++;
                     }
 
@@ -2312,6 +2386,10 @@ namespace IronRuby.Runtime {
             return new InteropBinder.CreateInstance(this, callInfo);
         }
 
+        public override ConvertBinder/*!*/ CreateConvertBinder(Type toType, bool explicitCast) {
+            return new InteropBinder.Convert(this, toType, explicitCast);
+        }
+
         // TODO: override GetMemberNames?
         public IList&lt;string&gt;/*!*/ GetForeignDynamicMemberNames(object obj) {
             if (obj is IRubyDynamicMetaObjectProvider) {
@@ -2386,12 +2464,12 @@ namespace IronRuby.Runtime {
                     _traceListenerSuspended = true;
 
                     _traceListener.Call(new[] {
-                        MutableString.Create(operation),                                          // event
-                        fileName != null ? MutableString.Create(fileName) : null,                 // file
-                        ScriptingRuntimeHelpers.Int32ToObject(lineNumber),                        // line
-                        SymbolTable.StringToId(name),                                             // TODO: alias
-                        new Binding(scope),                                                       // binding
-                        module.IsSingletonClass ? ((RubyClass)module).SingletonClassOf : module   // module
+                        MutableString.CreateAscii(operation),                                         // event
+                        fileName != null ? MutableString.Create(fileName, RubyEncoding.Path) : null,  // file
+                        ScriptingRuntimeHelpers.Int32ToObject(lineNumber),                            // line
+                        SymbolTable.StringToId(name),                                                 // TODO: alias
+                        new Binding(scope),                                                           // binding
+                        module.IsSingletonClass ? ((RubyClass)module).SingletonClassOf : module       // module
                     });
                 } finally {
                     _traceListenerSuspended = false;</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs</filename>
    </modified>
    <modified>
      <diff>@@ -45,11 +45,23 @@ namespace IronRuby.Runtime {
         private static readonly bool DebugInfoAvailable = true;
 #endif
 
-        // owner exception, needed for lazy initialization of message, backtrace
+        // An exception class can implement singleton method &quot;new&quot; that returns an arbitrary instance of an exception.
+        // This mapping needs to be applied on exceptions created in libraries as well (they should be created &quot;dynamically&quot;).
+        // That would however need to pass RubyContext to every method that might throw an exception. Instead, we call
+        // &quot;new&quot; on the exception's class as soon as it gets to the first Ruby EH handler (rescue/ensure/else).
+        //
+        // True if the exception has already been handled by Ruby EH clause or if it was constructed &quot;dynamically&quot; via Class#new.
+        internal bool Handled { get; set; }
+
+        // Real exception begin propagated by the CLR. Needed for lazy initialization of message, backtrace
         private Exception/*!*/ _exception;
-        // For asynchronous exceptions (Thread#raise), the user exception is wrapped in a TheadAbortException
+        // For asynchronous exceptions (Thread#raise), the user-visible exception (accessible via _visibleException)
+        // is wrapped in a TheadAbortException (accessible via _exception)
         private Exception/*!*/ _visibleException;
+#if DEBUG
+        // For asynchronous exceptions, this is useful to figure out which thread raised the exception
         private Thread/*!*/ _throwingThread;
+#endif
 
         // if this is set to null we need to initialize it
         private object _message; 
@@ -62,7 +74,9 @@ namespace IronRuby.Runtime {
         private RubyExceptionData(Exception/*!*/ exception) {
             _exception = exception;
             _visibleException = exception;
+#if DEBUG
             _throwingThread = Thread.CurrentThread;
+#endif
         }
 
         private RubyArray CreateBacktrace(RubyContext/*!*/ context, InterpretedFrame handlerFrame, StackTrace catchSiteTrace) {
@@ -175,7 +189,7 @@ namespace IronRuby.Runtime {
                     }
 
                     if (skipFrames == 0) {
-                        result.Add(MutableString.Create(FormatFrame(file, line, methodName)));
+                        result.Add(MutableString.Create(FormatFrame(file, line, methodName), RubyEncoding.UTF8));
                     } else {
                         skipFrames--;
                     }
@@ -274,7 +288,7 @@ namespace IronRuby.Runtime {
         }
 
         // \u2111\u211c;{method-name};{file-name};{line-number};{dlr-suffix}
-        private static bool TryParseRubyMethodName(ref string methodName, ref string fileName, ref int line) {
+        internal static bool TryParseRubyMethodName(ref string methodName, ref string fileName, ref int line) {
             if (methodName.StartsWith(RubyMethodPrefix)) {
                 string[] parts = methodName.Split(';');
                 if (parts.Length &gt; 4) {
@@ -327,9 +341,6 @@ namespace IronRuby.Runtime {
                 Debug.Assert(e is ThreadAbortException);
                 result = GetInstance(visibleException);
 
-                // Since visibleException was instantiated by the thread calling Thread#raise, we need to reset it here
-                result._throwingThread = Thread.CurrentThread;
-
                 if (result._exception == visibleException) {
                     // A different instance of ThreadAbortException is thrown at the end of every catch block (as long as
                     // Thread.ResetAbort is not called). However, we only want to remember the first one 
@@ -349,7 +360,7 @@ namespace IronRuby.Runtime {
         public object Message {
             get {
                 if (_message == null) {
-                    _message = MutableString.Create(_visibleException.Message);
+                    _message = MutableString.Create(_visibleException.Message, RubyEncoding.UTF8);
                 }
                 return _message;
             }
@@ -388,22 +399,65 @@ namespace IronRuby.Runtime {
             return exception;
         }
 
+        internal static Exception/*!*/ HandleException(RubyContext/*!*/ context, Exception/*!*/ exception) {
+            // already handled:
+            var instanceData = GetInstance(exception);
+            if (instanceData.Handled) {
+                return exception;
+            }
+
+            RubyClass exceptionClass = context.GetClass(exception.GetType());
+
+            // new resolves to Class#new built-in method:
+            var newMethod = exceptionClass.SingletonClass.ResolveMethod(&quot;new&quot;, VisibilityContext.AllVisible);
+            if (newMethod.Found &amp;&amp; newMethod.Info.DeclaringModule == context.ClassClass &amp;&amp; newMethod.Info is RubyCustomMethodInfo) {
+                // initialize resolves to a built-in method:
+                var initializeMethod = exceptionClass.ResolveMethod(&quot;initialize&quot;, VisibilityContext.AllVisible);
+                if (initializeMethod.Found &amp;&amp; initializeMethod.Info is RubyLibraryMethodInfo) {
+                    instanceData.Handled = true;
+                    return exception;
+                }
+            }
+
+            var site = exceptionClass.NewSite;
+            Exception newException;
+            try {
+                newException = site.Target(site, exceptionClass, instanceData.Message) as Exception;
+            } catch (Exception e) {
+                // MRI: this can lead to stack overflow:
+                return HandleException(context, e);
+            }
+
+            // MRI doesn't handle this correctly, see http://redmine.ruby-lang.org/issues/show/1886:
+            if (newException == null) {
+                newException = RubyExceptions.CreateTypeError(&quot;exception object expected&quot;);
+            }
+
+            var newInstanceData = GetInstance(newException);
+            
+            newInstanceData.Handled = true;
+            newInstanceData._backtrace = instanceData._backtrace;
+            return newException;
+        }
+
 #if SILVERLIGHT // Thread.ExceptionState
         public static void ActiveExceptionHandled(Exception visibleException) {}
 #else
-        /// &lt;summary&gt;
-        /// This function calls Thread.ResetAbort. However, note that ResetAbort causes ThreadAbortException.ExceptionState 
-        /// to be cleared, and we use that to squirrel away the Ruby exception that the user is expecting. Hence, ResetAbort
-        /// should only be called when ThreadAbortException.ExceptionState no longer needs to be accessed.
-        /// &lt;/summary&gt;
-        /// &lt;param name=&quot;visibleException&quot;&gt;&lt;/param&gt;
         public static void ActiveExceptionHandled(Exception visibleException) {
             Debug.Assert(RubyUtils.GetVisibleException(visibleException) == visibleException);
 
             RubyExceptionData data = RubyExceptionData.GetInstance(visibleException);
-            if (data._exception != visibleException &amp;&amp; data._throwingThread == Thread.CurrentThread) {
-                Debug.Assert((Thread.CurrentThread.ThreadState &amp; System.Threading.ThreadState.AbortRequested) != 0);
-                Thread.ResetAbort();
+            if (data._exception != visibleException) {
+                // The exception was raised asynchronously with Thread.Abort. We can not just catch and ignore 
+                // the ThreadAbortException as the CLR keeps trying to re-raise it unless ResetAbort is called.
+                //
+                // Note that ResetAbort can cause ThreadAbortException.ExceptionState to be cleared (though it may 
+                // not be cleared under some circustances), and we use that to squirrel away the Ruby exception 
+                // that the user is expecting. Hence, ResetAbort should only be called when 
+                // ThreadAbortException.ExceptionState no longer needs to be accessed. 
+                if ((Thread.CurrentThread.ThreadState &amp; System.Threading.ThreadState.AbortRequested) != 0) {
+                    Thread.ResetAbort();
+                }
             }
         }
 #endif</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyExceptionData.cs</filename>
    </modified>
    <modified>
      <diff>@@ -14,24 +14,21 @@
  * ***************************************************************************/
 
 using System;
+using System.Diagnostics;
 using System.IO;
-using Microsoft.Scripting;
-using Microsoft.Scripting.Runtime;
-using Microsoft.Scripting.Utils;
+using System.Runtime.InteropServices;
 using System.Security;
 using IronRuby.Builtins;
-using IronRuby.Compiler;
-using System.Runtime.InteropServices;
-using System.Net.Sockets;
-using System.Runtime.CompilerServices;
+using Microsoft.Scripting.Utils;
 using IronRuby.Runtime.Calls;
-using System.Diagnostics;
 
 namespace IronRuby.Runtime {
     /// &lt;summary&gt;
     /// Helper class for creating the corresponding .NET exceptions from the Ruby error names
     /// &lt;/summary&gt;
     public static class RubyExceptions {
+        #region TypeError (InvalidOperationException)
+
         public static Exception/*!*/ CreateTypeError(string/*!*/ message) {
             return new InvalidOperationException(message);
         }
@@ -58,13 +55,6 @@ namespace IronRuby.Runtime {
             return CreateTypeConversionError(context.GetClassName(param), toType);
         }
 
-        public static Exception/*!*/ MethodShouldReturnType(RubyContext/*!*/ context, object param, string/*!*/ method, string/*!*/ targetType) {
-            Assert.NotNull(context, method, targetType);
-            return new InvalidOperationException(String.Format(&quot;{0}#{1} should return {2}&quot;,
-                context.GetClassName(param), method, targetType
-            ));
-        }
-
         public static Exception/*!*/ CreateAllocatorUndefinedError(RubyClass/*!*/ rubyClass) {
             return CreateTypeError(String.Format(&quot;allocator undefined for {0}&quot;, rubyClass.Name));
         }
@@ -85,6 +75,33 @@ namespace IronRuby.Runtime {
             ));
         }
 
+        public static Exception/*!*/ MakeCoercionError(RubyContext/*!*/ context, object self, object other) {
+            string selfClass = context.GetClassOf(self).Name;
+            string otherClass = context.GetClassOf(other).Name;
+            return CreateTypeError(String.Format(&quot;{0} can't be coerced into {1}&quot;, selfClass, otherClass));
+        }
+
+        public static Exception/*!*/ CreateReturnTypeError(string/*!*/ className, string/*!*/ methodName, string/*!*/ returnTypeName) {
+            return CreateTypeError(String.Format(&quot;{0}#{1} should return {2}&quot;, className, methodName, returnTypeName));
+        }
+
+        #endregion
+
+        #region NameError (MemberAccessException)
+
+        public static Exception/*!*/ CreateNameError(string/*!*/ message) {
+            return new MemberAccessException(message);
+        }
+
+        public static Exception/*!*/ CreateUndefinedMethodError(RubyModule/*!*/ module, string/*!*/ methodName) {
+            return CreateNameError(String.Format(&quot;undefined method `{0}' for {2} `{1}'&quot;,
+                methodName, module.Name, module.IsClass ? &quot;class&quot; : &quot;module&quot;));
+        }
+
+        #endregion
+
+        #region ArgumentError (ArgumentException)
+
         public static Exception/*!*/ CreateArgumentError(string/*!*/ message) {
             return new ArgumentException(message);
         }
@@ -93,6 +110,83 @@ namespace IronRuby.Runtime {
             return new ArgumentException(message, innerException);
         }
 
+        public static Exception/*!*/ InvalidValueForType(RubyContext/*!*/ context, object obj, string type) {
+            return CreateArgumentError(String.Format(&quot;invalid value for {0}: {1}&quot;, type, context.Inspect(obj)));
+        }
+
+        public static Exception/*!*/ MakeComparisonError(RubyContext/*!*/ context, object self, object other) {
+            string selfClass = context.GetClassOf(self).Name;
+            string otherClass = context.GetClassOf(other).Name;
+            return CreateArgumentError(String.Format(&quot;comparison of {0} with {1} failed&quot;, selfClass, otherClass));
+        }
+
+        #endregion
+
+        #region MissingMethodException
+
+        private static Exception/*!*/ CreateMethodMissing(string/*!*/ message) {
+            return new MissingMethodException(message);
+        }
+
+        public static Exception/*!*/ CreateMethodMissing(RubyContext/*!*/ context, object self, string/*!*/ name) {
+            return CreateMethodMissing(FormatMethodMissingMessage(context, self, name));
+        }
+
+        public static Exception/*!*/ CreatePrivateMethodCalled(RubyContext/*!*/ context, object self, string/*!*/ name) {
+            return CreateMethodMissing(FormatMethodMissingMessage(context, self, name, &quot;private method `{0}' called for {1}&quot;));
+        }
+
+        public static Exception/*!*/ CreateProtectedMethodCalled(RubyContext/*!*/ context, object self, string/*!*/ name) {
+            return CreateMethodMissing(FormatMethodMissingMessage(context, self, name, &quot;protected method `{0}' called for {1}&quot;));
+        }
+
+        public static string/*!*/ FormatMethodMissingMessage(RubyContext/*!*/ context, object self, string/*!*/ name) {
+            return FormatMethodMissingMessage(context, self, name, &quot;undefined method `{0}' for {1}&quot;);
+        }
+
+        [ThreadStatic]
+        private static bool _disableMethodMissingMessageFormatting;
+
+        internal static string/*!*/ FormatMethodMissingMessage(RubyContext/*!*/ context, object obj, string/*!*/ name, string/*!*/ message) {
+            Assert.NotNull(name);
+
+            string str;
+            if (obj == null) {
+                str = &quot;nil:NilClass&quot;;
+            } else if (_disableMethodMissingMessageFormatting) {
+                str = RubyUtils.ObjectToMutableString(context, obj).ToString();
+            } else {
+                _disableMethodMissingMessageFormatting = true;
+                try {
+                    str = context.Inspect(obj).ConvertToString();
+                    if (!str.StartsWith(&quot;#&quot;)) {
+                        str += &quot;:&quot; + context.GetClassName(obj);
+                    }
+                } catch (Exception) {
+                    // MRI: swallows all exceptions
+                    str = RubyUtils.ObjectToMutableString(context, obj).ToString();
+                } finally {
+                    _disableMethodMissingMessageFormatting = false;
+                }
+            }
+            
+            return String.Format(message, name, str);
+        }
+
+        #endregion
+
+        #region LoadError
+
+        public static Exception/*!*/ CreateLoadError(Exception/*!*/ innerException) {
+            return new LoadError(innerException.Message, innerException);
+        }
+
+        public static Exception/*!*/ CreateLoadError(string/*!*/ message) {
+            return new LoadError(message);
+        }
+
+        #endregion
+
         public static Exception/*!*/ CreateNotImplementedError(string/*!*/ message) {
             return new NotImplementedError(message);
         }
@@ -113,10 +207,6 @@ namespace IronRuby.Runtime {
             return new ArgumentOutOfRangeException(String.Empty, message);
         }
 
-        public static Exception/*!*/ CreateNameError(string/*!*/ message) {
-            return new MemberAccessException(message);
-        }
-
         public static Exception/*!*/ CreateLocalJumpError(string/*!*/ message) {
             return new LocalJumpError(message);
         }
@@ -124,7 +214,7 @@ namespace IronRuby.Runtime {
         public static Exception/*!*/ NoBlockGiven() {
             return new LocalJumpError(&quot;no block given&quot;);
         }
-        
+
         public static Exception/*!*/ CreateIOError(string/*!*/ message) {
             return new IOException(message);
         }
@@ -133,56 +223,72 @@ namespace IronRuby.Runtime {
             return new ExternalException(message);
         }
 
-        public static Exception/*!*/ InvalidValueForType(RubyContext/*!*/ context, object obj, string type) {
-            return CreateArgumentError(String.Format(&quot;invalid value for {0}: {1}&quot;, type, context.Inspect(obj)));
+        public static Exception/*!*/ CreateSecurityError(string/*!*/ message) {
+            throw new SecurityException(message);
         }
 
-        public static Exception/*!*/ CreateUndefinedMethodError(RubyModule/*!*/ module, string/*!*/ methodName) {
-            return RubyExceptions.CreateNameError(String.Format(&quot;undefined method `{0}' for {2} `{1}'&quot;,
-                methodName, module.Name, module.IsClass ? &quot;class&quot; : &quot;module&quot;));
+        public static Exception/*!*/ CreateEncodingCompatibilityError(RubyEncoding/*!*/ encoding1, RubyEncoding/*!*/ encoding2) {
+            return new EncodingCompatibilityError(
+                String.Format(&quot;incompatible character encodings: {0}{1} and {2}{3}&quot;,
+                    encoding1.Name, encoding1.IsKCoding ? &quot; (KCODE)&quot; : null, encoding2.Name, encoding2.IsKCoding ? &quot; (KCODE)&quot; : null
+                )
+            );
         }
 
-        public static Exception/*!*/ MakeCoercionError(RubyContext/*!*/ context, object self, object other) {
-            string selfClass = context.GetClassOf(self).Name;
-            string otherClass = context.GetClassOf(other).Name;
-            return RubyExceptions.CreateTypeError(String.Format(&quot;{0} can't be coerced into {1}&quot;, selfClass, otherClass));
+        #region Errno
+
+        public static string/*!*/ MakeMessage(string message, string/*!*/ baseMessage) {
+            Assert.NotNull(baseMessage);
+            return (message != null) ? String.Concat(baseMessage, &quot; - &quot;, message) : baseMessage;
         }
 
-        public static Exception/*!*/ MakeComparisonError(RubyContext/*!*/ context, object self, object other) {
-            string selfClass = context.GetClassOf(self).Name;
-            string otherClass = context.GetClassOf(other).Name;
-            return RubyExceptions.CreateArgumentError(String.Format(&quot;comparison of {0} with {1} failed&quot;, selfClass, otherClass));
+        public static string/*!*/ MakeMessage(ref MutableString message, string/*!*/ baseMessage) {
+            Assert.NotNull(baseMessage);
+            string result = MakeMessage(message != null ? message.ConvertToString() : null, baseMessage);
+            message = MutableString.Create(result, message != null ? message.Encoding : RubyEncoding.UTF8);
+            return result;
         }
 
-        public static Exception/*!*/ CreateSecurityError(string/*!*/ message) {
-            throw new SecurityException(message);
+        public static Exception/*!*/ CreateEEXIST() {
+            return new ExistError();
         }
 
-        public static string/*!*/ FormatMethodMissingMessage(RubyContext/*!*/ context, object self, string/*!*/ name) {
-            return FormatMethodMissingMessage(context, self, name, &quot;undefined method `{0}' for {1}&quot;);
+        public static Exception/*!*/ CreateEEXIST(string message) {
+            return new ExistError(message);
         }
 
-        internal static string/*!*/ FormatMethodMissingMessage(RubyContext/*!*/ context, object self, string/*!*/ name, string/*!*/ message) {
-            Assert.NotNull(name);
-            string strObject = context.InspectEnsuringClassName(self);
-            return String.Format(message, name, strObject);
+        public static Exception/*!*/ CreateEEXIST(string message, Exception inner) {
+            return new ExistError(message, inner);
         }
 
-        public static Exception/*!*/ CreateMethodMissing(RubyContext/*!*/ context, object self, string/*!*/ name) {
-            return new MissingMethodException(FormatMethodMissingMessage(context, self, name));
+        public static Exception/*!*/ CreateEINVAL() {
+            return new InvalidError();
         }
 
-        public static Exception/*!*/ CreatePrivateMethodCalled(RubyContext/*!*/ context, object self, string/*!*/ name) {
-            return new MissingMethodException(FormatMethodMissingMessage(context, self, name, &quot;private method `{0}' called for {1}&quot;));
+        public static Exception/*!*/ CreateEINVAL(string message) {
+            return new InvalidError(message);
         }
 
-        public static Exception/*!*/ CreateProtectedMethodCalled(RubyContext/*!*/ context, object self, string/*!*/ name) {
-            return new MissingMethodException(FormatMethodMissingMessage(context, self, name, &quot;protected method `{0}' called for {1}&quot;));
+        public static Exception/*!*/ CreateEINVAL(string message, Exception inner) {
+            return new InvalidError(message, inner);
         }
 
-        public static Exception/*!*/ CreateEncodingCompatibilityError(RubyEncoding/*!*/ encoding1, RubyEncoding/*!*/ encoding2) {
-            return new EncodingCompatibilityError(String.Format(&quot;incompatible character encodings: {0}{1} and {2}{3}&quot;,
-                encoding1.Name, encoding1.IsKCoding ? &quot; (KCODE)&quot; : null, encoding2.Name, encoding2.IsKCoding ? &quot; (KCODE)&quot; : null));
+        public static Exception/*!*/ CreateENOENT() {
+            return new FileNotFoundException();
+        }
+
+        public static Exception/*!*/ CreateENOENT(string message, Exception inner) {
+            return new FileNotFoundException(message, inner);
+        }
+
+        public static Exception/*!*/ CreateENOENT(string message) {
+            return new FileNotFoundException(message);
         }
+
+        public static Exception/*!*/ CreateEBADF() {
+            return new BadFileDescriptorError();
+        }
+
+        #endregion
     }
 }</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyExceptions.cs</filename>
    </modified>
    <modified>
      <diff>@@ -26,7 +26,7 @@ namespace IronRuby.Runtime {
     public static partial class RubyOps {
         private static readonly object/*!*/ RetrySingleton = new object();
         
-        #region Unwinders, RFC Flags
+        #region RFC Flags
 
         [Emitted]
         public static RuntimeFlowControl/*!*/ CreateRfcForMethod(Proc proc) {
@@ -36,33 +36,6 @@ namespace IronRuby.Runtime {
             return result;
         }
 
-        // Ruby method exit filter:
-        [Emitted]
-        public static bool IsMethodUnwinderTargetFrame(RubyScope/*!*/ scope, Exception/*!*/ exception) {
-            var unwinder = exception as MethodUnwinder;
-            if (unwinder == null) {
-                RubyExceptionData.GetInstance(exception).CaptureExceptionTrace(scope);
-                return false;
-            } else {
-                return unwinder.TargetFrame == scope.FlowControlScope;
-            }
-        }
-
-        [Emitted]
-        public static object GetMethodUnwinderReturnValue(Exception/*!*/ exception) {
-            return ((MethodUnwinder)exception).ReturnValue;
-        }
-
-        [Emitted]
-        public static void LeaveMethodFrame(RuntimeFlowControl/*!*/ rfc) {
-            rfc.LeaveMethod();
-        }
-        
-        [Emitted]
-        public static void LeaveBlockFrame(RubyBlockScope/*!*/ scope) {
-            
-        }
-
         [Emitted]
         public static void EnterLoop(RubyScope/*!*/ scope) {
             scope.InLoop = true;</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.FlowControl.cs</filename>
    </modified>
    <modified>
      <diff>@@ -103,7 +103,7 @@ namespace IronRuby.Runtime {
             RubyFile dataFile;
             RubyContext context = scope.RubyContext;
             if (context.DomainManager.Platform.FileExists(dataPath)) {
-                dataFile = new RubyFile(context, dataPath, RubyFileMode.RDONLY);
+                dataFile = new RubyFile(context, dataPath, IOMode.ReadOnly);
                 dataFile.Seek(dataOffset, SeekOrigin.Begin);
             } else {
                 dataFile = null;
@@ -1201,12 +1201,51 @@ namespace IronRuby.Runtime {
         // Exception Ops go directly to the current exception object. MRI ignores potential aliases.
         //
 
+        /// &lt;summary&gt;
+        /// Called in try-filter that wraps the entire body of a block. 
+        /// We just need to capture stack trace, should not filter out any exception.
+        /// &lt;/summary&gt;
         [Emitted]
         public static bool FilterBlockException(RubyScope/*!*/ scope, Exception/*!*/ exception) {
             RubyExceptionData.GetInstance(exception).CaptureExceptionTrace(scope);
             return false;
         }
 
+        /// &lt;summary&gt;
+        /// Called in try-filter that wraps the entire top-level code. 
+        /// We just need to capture stack trace, should not filter out any exception.
+        /// &lt;/summary&gt;
+        [Emitted]
+        public static bool TraceTopLevelCodeFrame(RubyScope/*!*/ scope, Exception/*!*/ exception) {
+            RubyExceptionData.GetInstance(exception).CaptureExceptionTrace(scope);
+            return false;
+        }
+
+        // Ruby method exit filter:
+        [Emitted]
+        public static bool IsMethodUnwinderTargetFrame(RubyScope/*!*/ scope, Exception/*!*/ exception) {
+            var unwinder = exception as MethodUnwinder;
+            if (unwinder == null) {
+                RubyExceptionData.GetInstance(exception).CaptureExceptionTrace(scope);
+                return false;
+            } else {
+                return unwinder.TargetFrame == scope.FlowControlScope;
+            }
+        }
+
+        [Emitted]
+        public static object GetMethodUnwinderReturnValue(Exception/*!*/ exception) {
+            return ((MethodUnwinder)exception).ReturnValue;
+        }
+
+        [Emitted]
+        public static void LeaveMethodFrame(RuntimeFlowControl/*!*/ rfc) {
+            rfc.LeaveMethod();
+        }
+        
+        /// &lt;summary&gt;
+        /// Filters exceptions raised from EH-body, EH-rescue and EH-else clauses.
+        /// &lt;/summary&gt;
         [Emitted]
         public static bool CanRescue(RubyScope/*!*/ scope, Exception/*!*/ exception) {
             if (exception is StackUnwinder) {
@@ -1218,23 +1257,29 @@ namespace IronRuby.Runtime {
                 return false;
             }
 
-            RubyExceptionData.GetInstance(exception).CaptureExceptionTrace(scope);
+            // calls &quot;new&quot; on the exception class if it hasn't been called yet:
+            exception = RubyExceptionData.HandleException(scope.RubyContext, exception);
+
             scope.RubyContext.CurrentException = exception;
+            RubyExceptionData.GetInstance(exception).CaptureExceptionTrace(scope);
             return true;
         }
 
         [Emitted]
-        public static bool TraceTopLevelCodeFrame(RubyScope/*!*/ scope, Exception/*!*/ exception) {
-            RubyExceptionData.GetInstance(exception).CaptureExceptionTrace(scope);
-            return false;
+        public static Exception/*!*/ MarkException(Exception/*!*/ exception) {
+            RubyExceptionData.GetInstance(exception).Handled = true;
+            return exception;
         }
 
-        [Emitted] //Body, RescueClause:
+        [Emitted]
         public static Exception GetCurrentException(RubyScope/*!*/ scope) {
             return scope.RubyContext.CurrentException;
         }
 
-        [Emitted] //Body:
+        /// &lt;summary&gt;
+        /// Sets $!. Used in EH finally clauses to restore exception stored in oldExceptionVariable local.
+        /// &lt;/summary&gt;
+        [Emitted] 
         public static void SetCurrentException(RubyScope/*!*/ scope, Exception exception) {
             scope.RubyContext.CurrentException = exception;
         }
@@ -1289,7 +1334,7 @@ namespace IronRuby.Runtime {
         }
 
         [Emitted]
-        public static ArgumentException/*!*/ CreateArgumentsErrorForMissingBlock(string message) {
+        public static ArgumentException/*!*/ CreateArgumentsErrorForMissingBlock() {
             return (ArgumentException)RubyExceptions.CreateArgumentError(&quot;block not supplied&quot;);
         }
 
@@ -1470,7 +1515,7 @@ namespace IronRuby.Runtime {
         public static Proc/*!*/ ToProcValidator(string/*!*/ className, object obj) {
             Proc result = obj as Proc;
             if (result == null) {
-                throw new InvalidOperationException(String.Format(&quot;{0}#to_proc should return Proc&quot;, className));
+                throw RubyExceptions.CreateReturnTypeError(className, &quot;to_proc&quot;, &quot;Proc&quot;);
             }
             return result;
         }
@@ -1491,7 +1536,7 @@ namespace IronRuby.Runtime {
         public static MutableString/*!*/ ToStringValidator(string/*!*/ className, object obj) {
             MutableString result = obj as MutableString;
             if (result == null) {
-                throw new InvalidOperationException(String.Format(&quot;{0}#to_str should return String&quot;, className));
+                throw RubyExceptions.CreateReturnTypeError(className, &quot;to_str&quot;, &quot;String&quot;);
             }
             return result;
         }
@@ -1500,7 +1545,7 @@ namespace IronRuby.Runtime {
         public static string/*!*/ ToSymbolValidator(string/*!*/ className, object obj) {
             var str = obj as MutableString;
             if (str == null) {
-                throw new InvalidOperationException(String.Format(&quot;{0}#to_str should return String&quot;, className));
+                throw RubyExceptions.CreateReturnTypeError(className, &quot;to_str&quot;, &quot;String&quot;); 
             }
             return str.ConvertToString();
         }
@@ -1541,7 +1586,7 @@ namespace IronRuby.Runtime {
         public static IList/*!*/ ToArrayValidator(string/*!*/ className, object obj) {
             var result = obj as IList;
             if (result == null) {
-                throw new InvalidOperationException(String.Format(&quot;{0}#to_ary should return Array&quot;, className));
+                throw RubyExceptions.CreateReturnTypeError(className, &quot;to_ary&quot;, &quot;Array&quot;);
             }
             return result;
         }
@@ -1550,13 +1595,12 @@ namespace IronRuby.Runtime {
         public static IDictionary&lt;object, object&gt;/*!*/ ToHashValidator(string/*!*/ className, object obj) {
             var result = obj as IDictionary&lt;object, object&gt;;
             if (result == null) {
-                throw new InvalidOperationException(String.Format(&quot;{0}#to_hash should return Hash&quot;, className));
+                throw RubyExceptions.CreateReturnTypeError(className, &quot;to_hash&quot;, &quot;Hash&quot;);
             }
             return result;
         }
 
-        [Emitted] // ProtocolConversionAction
-        public static int ToFixnumValidator(string/*!*/ className, object obj) {
+        private static int ToIntValidator(string/*!*/ className, string/*!*/ targetType, object obj) {
             if (obj is int) {
                 return (int)obj;
             }
@@ -1567,10 +1611,91 @@ namespace IronRuby.Runtime {
                 if (bignum.AsInt32(out fixnum)) {
                     return fixnum;
                 }
-                throw RubyExceptions.CreateRangeError(&quot;bignum too big to convert into `long'&quot;);
+                throw RubyExceptions.CreateRangeError(String.Format(&quot;bignum too big to convert into {0}&quot;, targetType));
             }
 
-            throw new InvalidOperationException(String.Format(&quot;{0}#to_int should return Integer&quot;, className));
+            throw RubyExceptions.CreateReturnTypeError(className, &quot;to_int&quot;, &quot;Integer&quot;);
+        }
+
+        [Emitted] // ProtocolConversionAction
+        public static int ToFixnumValidator(string/*!*/ className, object obj) {
+            return ToIntValidator(className, &quot;Fixnum&quot;, obj);
+        }
+
+        [Emitted] // ProtocolConversionAction
+        public static Byte ToByteValidator(string/*!*/ className, object obj) {
+            return Converter.ToByte(ToIntValidator(className, &quot;System::Byte&quot;, obj));
+        }
+
+        [Emitted] // ProtocolConversionAction
+        public static SByte ToSByteValidator(string/*!*/ className, object obj) {
+            return Converter.ToSByte(ToIntValidator(className, &quot;System::SByte&quot;, obj));
+        }
+
+        [Emitted] // ProtocolConversionAction
+        public static Int16 ToInt16Validator(string/*!*/ className, object obj) {
+            return Converter.ToInt16(ToIntValidator(className, &quot;System::Int16&quot;, obj));
+        }
+
+        [Emitted] // ProtocolConversionAction
+        public static UInt16 ToUInt16Validator(string/*!*/ className, object obj) {
+            return Converter.ToUInt16(ToIntValidator(className, &quot;System::UInt16&quot;, obj));
+        }
+
+        [Emitted] // ProtocolConversionAction
+        public static UInt32 ToUInt32Validator(string/*!*/ className, object obj) {
+            if (obj is int) {
+                return Converter.ToUInt32((int)obj);
+            }
+
+            var bignum = obj as BigInteger;
+            if ((object)bignum != null) {
+                return Converter.ToUInt32(bignum);
+            }
+
+            throw RubyExceptions.CreateReturnTypeError(className, &quot;to_int/to_i&quot;, &quot;Integer&quot;);
+        }
+
+        [Emitted] // ProtocolConversionAction
+        public static Int64 ToInt64Validator(string/*!*/ className, object obj) {
+            if (obj is int) {
+                return (int)obj;
+            }
+
+            var bignum = obj as BigInteger;
+            if ((object)bignum != null) {
+                return Converter.ToInt64(bignum);
+            }
+
+            throw RubyExceptions.CreateReturnTypeError(className, &quot;to_int/to_i&quot;, &quot;Integer&quot;);
+        }
+
+        [Emitted] // ProtocolConversionAction
+        public static UInt64 ToUInt64Validator(string/*!*/ className, object obj) {
+            if (obj is int) {
+                return Converter.ToUInt64((int)obj);
+            }
+
+            var bignum = obj as BigInteger;
+            if ((object)bignum != null) {
+                return Converter.ToUInt64(bignum);
+            }
+
+            throw RubyExceptions.CreateReturnTypeError(className, &quot;to_int/to_i&quot;, &quot;Integer&quot;);
+        }
+
+        [Emitted] // ProtocolConversionAction
+        public static BigInteger ToBignumValidator(string/*!*/ className, object obj) {
+            if (obj is int) {
+                return (int)obj;
+            }
+
+            var bignum = obj as BigInteger;
+            if ((object)bignum != null) {
+                return bignum;
+            }
+
+            throw RubyExceptions.CreateReturnTypeError(className, &quot;to_int/to_i&quot;, &quot;Integer&quot;);
         }
 
         [Emitted] // ProtocolConversionAction
@@ -1584,21 +1709,33 @@ namespace IronRuby.Runtime {
                 return new IntegerValue(bignum);
             }
 
-            throw new InvalidOperationException(String.Format(&quot;{0}#to_int/to_i should return Integer&quot;, className));
+            throw RubyExceptions.CreateReturnTypeError(className, &quot;to_int/to_i&quot;, &quot;Integer&quot;);
         }
 
         [Emitted] // ProtocolConversionAction
-        public static double ToFloatValidator(string/*!*/ className, object obj) {
+        public static double ToDoubleValidator(string/*!*/ className, object obj) {
             if (obj is double) {
                 return (double)obj;
             }
 
-            // to_f should not return System.Single in pure Ruby code. However, we allow it in IronRuby code
             if (obj is float) {
                 return (double)(float)obj;
             }
 
-            throw new InvalidOperationException(String.Format(&quot;{0}#to_f should return Float&quot;, className));
+            throw RubyExceptions.CreateReturnTypeError(className, &quot;to_f&quot;, &quot;Float&quot;);
+        }
+
+        [Emitted] // ProtocolConversionAction
+        public static float ToSingleValidator(string/*!*/ className, object obj) {
+            if (obj is double) {
+                return (float)(double)obj;
+            }
+
+            if (obj is float) {
+                return (float)obj;
+            }
+
+            throw RubyExceptions.CreateReturnTypeError(className, &quot;to_f&quot;, &quot;System::Single&quot;);
         }
 
         [Emitted]
@@ -1634,7 +1771,7 @@ namespace IronRuby.Runtime {
             if (bignum.AsInt32(out fixnum)) {
                 return fixnum;
             }
-            throw RubyExceptions.CreateRangeError(&quot;bignum too big to convert into `long'&quot;);
+            throw RubyExceptions.CreateRangeError(&quot;bignum too big to convert into Fixnum&quot;);
         }
 
         [Emitted] // ConvertDoubleToFixnum</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs</filename>
    </modified>
    <modified>
      <diff>@@ -19,12 +19,14 @@ using System.Collections.ObjectModel;
 using System.Threading;
 using IronRuby.Builtins;
 using Microsoft.Scripting;
+using Microsoft.Scripting.Utils;
 
 namespace IronRuby.Runtime {
 
     [Serializable]
     public sealed class RubyOptions : LanguageOptions {
         private readonly ReadOnlyCollection&lt;string&gt;/*!*/ _arguments;
+        private readonly RubyEncoding/*!*/ _argumentEncoding;
         private readonly ReadOnlyCollection&lt;string&gt;/*!*/ _libraryPaths;
         private readonly string _mainFile;
         private readonly bool _enableTracing;
@@ -47,6 +49,10 @@ namespace IronRuby.Runtime {
             get { return _arguments; }
         }
 
+        public RubyEncoding/*!*/ ArgumentEncoding {
+            get { return _argumentEncoding; }
+        }
+
         public string MainFile {
             get { return _mainFile; }
         }
@@ -94,6 +100,7 @@ namespace IronRuby.Runtime {
         public RubyOptions(IDictionary&lt;string, object&gt;/*!*/ options)
             : base(options) {
             _arguments = GetStringCollectionOption(options, &quot;Arguments&quot;) ?? EmptyStringCollection;
+            _argumentEncoding = GetOption(options, &quot;ArgumentEncoding&quot;, RubyEncoding.Default);
 
             _mainFile = GetOption(options, &quot;MainFile&quot;, (string)null);
             _verbosity = GetOption(options, &quot;Verbosity&quot;, 1);</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOptions.cs</filename>
    </modified>
    <modified>
      <diff>@@ -633,21 +633,23 @@ namespace IronRuby.Runtime {
             Debug.Assert(index &gt;= 0);
 
             // we don't need to check index range, Groups indexer returns an unsuccessful group if out of range:
+            var match = _currentMatch;
             Group group;
-            if (_currentMatch != null &amp;&amp; (group = _currentMatch.Groups[index]).Success) {
-                return MutableString.Create(group.Value).TaintBy(_currentMatch.OriginalString);
+            if (match != null &amp;&amp; (group = match.Groups[index]).Success) {
+                return MutableString.Create(group.Value, match.Encoding).TaintBy(match.OriginalString);
             }
 
             return null;
         }
 
         internal MutableString GetCurrentMatchLastGroup() {
-            if (_currentMatch != null) {
+            var match = _currentMatch;
+            if (match != null) {
                 // TODO: cache the last successful group index?
-                for (int i = _currentMatch.Groups.Count - 1; i &gt;= 0; i--) {
-                    Group group = _currentMatch.Groups[i];
+                for (int i = match.Groups.Count - 1; i &gt;= 0; i--) {
+                    Group group = match.Groups[i];
                     if (group.Success) {
-                        return MutableString.Create(group.Value).TaintBy(_currentMatch.OriginalString);
+                        return MutableString.Create(group.Value, match.Encoding).TaintBy(match.OriginalString);
                     }
                 }
             }</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyScope.cs</filename>
    </modified>
    <modified>
      <diff>@@ -71,10 +71,10 @@ namespace IronRuby.Runtime {
             var context = tosConversion.Context;
             using (IDisposable handle = RubyUtils.InfiniteInspectTracker.TrackObject(obj)) {
                 if (handle == null) {
-                    return MutableString.Create(&quot;...&quot;);
+                    return MutableString.CreateAscii(&quot;...&quot;);
                 }
 
-                MutableString str = MutableString.CreateMutable();
+                MutableString str = MutableString.CreateMutable(RubyEncoding.ClassName);
                 str.Append(&quot;#&lt;&quot;);
                 str.Append(context.GetClassDisplayName(obj));
 
@@ -88,13 +88,14 @@ namespace IronRuby.Runtime {
                     bool first = true;
                     foreach (KeyValuePair&lt;string, object&gt; var in vars) {
                         if (first) {
-                            str.Append(&quot; &quot;);
+                            str.Append(' ');
                             first = false;
                         } else {
                             str.Append(&quot;, &quot;);
                         }
+                        // TODO (encoding):
                         str.Append(var.Key);
-                        str.Append(&quot;=&quot;);
+                        str.Append('=');
 
                         var inspectSite = inspectStorage.GetCallSite(&quot;inspect&quot;);
                         object inspectedValue = inspectSite.Target(inspectSite, var.Value);
@@ -113,7 +114,7 @@ namespace IronRuby.Runtime {
         }
 
         public static MutableString/*!*/ FormatObjectPrefix(string/*!*/ className, long objectId, bool isTainted) {
-            MutableString str = MutableString.CreateMutable();
+            MutableString str = MutableString.CreateMutable(RubyEncoding.ClassName);
             str.Append(&quot;#&lt;&quot;);
             str.Append(className);
 
@@ -308,6 +309,8 @@ namespace IronRuby.Runtime {
                             return null;
                         }
                     }
+                } else if (c == '_') {
+                    return null;
                 } else {
                     if (mangled != null) {
                         mangled.Append(c);
@@ -594,7 +597,7 @@ namespace IronRuby.Runtime {
 
         #region Tracking operations that have the potential for infinite recursion
 
-        public static readonly MutableString InfiniteRecursionMarker = MutableString.Create(&quot;[...]&quot;).Freeze();
+        public static readonly MutableString InfiniteRecursionMarker = MutableString.CreateAscii(&quot;[...]&quot;).Freeze();
 
         public class RecursionTracker {
             [ThreadStatic]</diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyUtils.cs</filename>
    </modified>
    <modified>
      <diff>@@ -46,13 +46,23 @@ namespace IronRuby.Runtime {
 
             string path;
             string codeLine;
+            RubyEncoding encoding;
             int line = span.Start.Line;
             if (sourceUnit != null) {
                 path = sourceUnit.Path;
-                codeLine = (line &gt; 0) ? sourceUnit.GetCodeLine(line) : null;
+                using (SourceCodeReader reader = sourceUnit.GetReader()) {
+                    if (line &gt; 0) {
+                        reader.SeekLine(line);
+                        codeLine = reader.ReadLine();
+                    } else {
+                        codeLine = null;
+                    }
+                    encoding = RubyEncoding.GetRubyEncoding(reader.Encoding);
+                }
             } else {
                 path = null;
                 codeLine = null;
+                encoding = RubyEncoding.UTF8;
             }
 
             if (severity == Severity.Error || severity == Severity.FatalError) {
@@ -69,7 +79,7 @@ namespace IronRuby.Runtime {
 
                 message = RubyContext.FormatErrorMessage(message, &quot;warning&quot;, path, line, span.Start.Column, null);
 
-                _WriteSite.Target(_WriteSite, _context.StandardErrorOutput, MutableString.CreateMutable(message));
+                _WriteSite.Target(_WriteSite, _context.StandardErrorOutput, MutableString.Create(message, encoding));
             }
         }
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Ruby/Runtime/RuntimeErrorSink.cs</filename>
    </modified>
    <modified>
      <diff>@@ -14,9 +14,9 @@ Topics covered
   - Using Blend for UI design
   - Creating WPF FlowDocument from RDoc SimpleMarkup text
 - Creating domain-specific-languages (DSLs) in Ruby
-- Using the test-spec gem for testing
 - Creating an application that can be developed incrementally from an
   interactive session with ability to reload modified source files.
+- Using a splash screen at application startup
 
 Running the app
 ---------------</diff>
      <filename>Merlin/Main/Languages/Ruby/Samples/Tutorial/README.markdown</filename>
    </modified>
    <modified>
      <diff>@@ -29,6 +29,11 @@ module HostingTutorial
   end
   
   class RedirectingOutputStream &lt; System::IO::Stream
+    def initialize
+      @encoding = System::Text::UTF8Encoding.new
+      super
+    end
+    
     def can_seek
      false
     end
@@ -43,11 +48,9 @@ module HostingTutorial
     
     # TODO - This does not deal with any encoding issues
     def write(buffer, offset, count)
-      char_array = System::Array[System::Char].new(buffer.length)
-      buffer.each_index { |idx| char_array[idx] = buffer[idx] }
       # Do the actual write. Note that this will automatically honor $stdout redirection 
       # of the ScriptEngine of the tutorial application.
-      print System::String.clr_new(char_array, offset, count)
+      print @encoding.get_string(buffer, offset, count)
     end
   end
 end
@@ -60,8 +63,8 @@ module Microsoft
       class ScriptEngine
         def redirect_output
           stream = HostingTutorial::RedirectingOutputStream.new
-          # TODO - This does not deal with any encoding issues
-          self.runtime.i_o.set_output(stream, System::Text::UTF8Encoding.new)
+          @encoding ||= System::Text::UTF8Encoding.new
+          self.runtime.io.set_output(stream, @encoding)
         end
       end
     end</diff>
      <filename>Merlin/Main/Languages/Ruby/Samples/Tutorial/Tutorials/hosting_tutorial.rb</filename>
    </modified>
    <modified>
      <diff>@@ -605,7 +605,8 @@ tutorial &quot;IronRuby tutorial&quot; do
                 :setup =&gt; lambda {
                     # TODO - Position the form so that it is not hidden behind the current window
                 },
-                :code =&gt; &quot;f.text = 'Hello'&quot;
+                :code =&gt; &quot;f.text = 'Hello'&quot;,
+                :test_hook =&gt; lambda { |type, bind| bind.f.close if type == :cleanup }
                 ) { |iar| /hello/i =~ iar.bind.f.text }
         end
         
@@ -754,7 +755,8 @@ tutorial &quot;IronRuby tutorial&quot; do
                     However, we will just clear out the content so that we can use the same window in the
                     next chapter.
                 },
-                :code =&gt; 'w.content = nil'
+                :code =&gt; 'w.content = nil',
+                :test_hook =&gt; lambda { |type, bind| bind.w.close if type == :cleanup }
                 ) { |iar| not iar.bind.w.content }
         end
 </diff>
      <filename>Merlin/Main/Languages/Ruby/Samples/Tutorial/Tutorials/ironruby_tutorial.rb</filename>
    </modified>
    <modified>
      <diff>@@ -74,10 +74,6 @@ class ToStyledHtml &lt; SM::ToHtml
     def self.convert text, paragraph_tag = '&lt;p class=&quot;Body&quot;&gt;'
         if not text then return &quot;&quot; end
         
-        if text =~ /\A(\s+)/
-            text = &quot;#{$1}dummy\n\n&quot; + text # TODO - This is a workaround for http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1301
-        end
-        
         if not @markupParser
             @markupParser = SM::SimpleMarkup.new
             # external hyperlinks</diff>
      <filename>Merlin/Main/Languages/Ruby/Samples/Tutorial/html_tutorial.rb</filename>
    </modified>
    <modified>
      <diff>@@ -132,6 +132,7 @@ module TutorialTests
         result = context.interact task.code_string
         assert_task_success task, task.code_string, result
       end
+      task.test_hook.call(:cleanup, context.bind) if task.test_hook
     end
   end
 end</diff>
      <filename>Merlin/Main/Languages/Ruby/Samples/Tutorial/test/test_console.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,7 +15,7 @@
 
 require &quot;stringio&quot;
 
-SILVERLIGHT = false unless defined? SILVERLIGHT
+SILVERLIGHT = false unless defined?(SILVERLIGHT)
 
 module Tutorial
 
@@ -44,14 +44,16 @@ module Tutorial
     attr :code
     attr :title
     attr :source_files # Files used by the task. The user might want to browse these files
+    attr :test_hook
 
-    def initialize title, description, run_unless, setup, code, source_files, &amp;success_evaluator	                
+    def initialize title, description, run_unless, setup, code, source_files, test_hook, &amp;success_evaluator	                
       @title = title
       @description = description
       @run_unless = run_unless
       @setup = setup
       @code = code
       @source_files = source_files
+      @test_hook = test_hook
     