<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -45,8 +45,10 @@ namespace Microsoft.Scripting.Silverlight {
     /// Base class for all browser-based PlatformAdaptationLayers. 
     /// Delegates compatible operations to a BrowserVirtualFileSystem.
     /// &lt;/summary&gt;
-    internal abstract class BrowserPAL : PlatformAdaptationLayer {
-        internal BrowserVirtualFilesystem VirtualFilesystem { get; set; }
+    // BUG: should be internal, but Ruby is refusing to call members if so
+    public abstract class BrowserPAL : PlatformAdaptationLayer {
+
+        public BrowserVirtualFilesystem VirtualFilesystem { get; internal set; }
 
         protected static BrowserPAL _PAL;
         internal static BrowserPAL PAL {</diff>
      <filename>Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/BrowserScriptHost.cs</filename>
    </modified>
    <modified>
      <diff>@@ -157,11 +157,18 @@ namespace Microsoft.Scripting.Silverlight {
         /// &lt;/summary&gt;
         /// &lt;param name=&quot;path&quot;&gt;a string representing a path&lt;/param&gt;
         /// &lt;returns&gt;a normalized version of &quot;path&quot;&lt;/returns&gt;
-        public virtual string NormalizePath(string path) {
+        public static string Normalize(string path) {
             return path.Replace('\\', '/');
         }
 
         /// &lt;summary&gt;
+        /// See (static) BrowserVirtualFilesystem.Normalize
+        /// &lt;/summary&gt;
+        public virtual string NormalizePath(string path) {
+            return BrowserVirtualFilesystem.Normalize(path);
+        }
+
+        /// &lt;summary&gt;
         /// Gets a file's stream
         /// &lt;/summary&gt;
         /// &lt;param name=&quot;storageUnit&quot;&gt;Looks for the file in this&lt;/param&gt;
@@ -220,7 +227,9 @@ namespace Microsoft.Scripting.Silverlight {
             } else {
                 sri = Application.GetResourceStream((StreamResourceInfo) xap, relativeUri);
             }
-            return (sri != null) ? sri.Stream : null;
+            return sri == null ? 
+                DynamicApplication.GetManifestResourceStream(relativeUri.ToString()) :
+                sri.Stream;
         }
 
         #region Depricated Methods
@@ -252,7 +261,7 @@ namespace Microsoft.Scripting.Silverlight {
         /// &lt;summary&gt;
         /// The cache of files already downloaded
         /// &lt;/summary&gt;
-        private Cache _cache = new Cache();
+        private DownloadCache _cache = new DownloadCache();
 
         /// &lt;summary&gt;
         /// Gets a file out of the download cache. This does not download the
@@ -274,13 +283,7 @@ namespace Microsoft.Scripting.Silverlight {
                 if (stream != null) return stream;
             }
 
-            Uri fullUri;
-            if (relativeUri.IsAbsoluteUri) {
-                fullUri = relativeUri;
-            } else {
-                baseUri = baseUri ?? DefaultBaseUri();
-                fullUri = new Uri(NormalizePath(((Uri)baseUri).AbsoluteUri) + relativeUri.ToString(), UriKind.Absolute);
-            }
+            var fullUri = DynamicApplication.MakeUri((Uri)baseUri, relativeUri);
 
             if (_cache.Has(fullUri)) {
                 return new MemoryStream(System.Text.Encoding.UTF8.GetBytes(_cache[fullUri]));
@@ -290,18 +293,6 @@ namespace Microsoft.Scripting.Silverlight {
         }
 
         /// &lt;summary&gt;
-        /// The default base URI is the HTML page's URI.
-        /// &lt;/summary&gt;
-        /// &lt;returns&gt;&lt;/returns&gt;
-        private Uri DefaultBaseUri() {
-            var uri = DynamicApplication.Current.BaseUri;
-            var server = uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
-            var path = NormalizePath(Path.GetDirectoryName(uri.LocalPath));
-            var defaultBaseUri = new Uri(new Uri(server), path);
-            return defaultBaseUri;
-        }
-
-        /// &lt;summary&gt;
         /// Download and cache a list of URIs, and execute a delegate when it's
         /// complete.
         /// &lt;/summary&gt;
@@ -317,7 +308,7 @@ namespace Microsoft.Scripting.Silverlight {
     /// &lt;summary&gt;
     /// A cache of Uris mapping to strings.
     /// &lt;/summary&gt;
-    public class Cache {
+    public class DownloadCache {
 
         private Dictionary&lt;Uri, string&gt; _cache = new Dictionary&lt;Uri, string&gt;();
 
@@ -328,7 +319,7 @@ namespace Microsoft.Scripting.Silverlight {
         /// &lt;param name=&quot;uri&quot;&gt;&lt;/param&gt;
         /// &lt;param name=&quot;code&quot;&gt;&lt;/param&gt;
         public void Add(Uri uri, string code) {
-            if (!_cache.ContainsKey(uri)) {
+            if (!Has(uri)) {
                 _cache.Add(uri, code);
             }
         }
@@ -389,7 +380,7 @@ namespace Microsoft.Scripting.Silverlight {
                             content = s.ReadToEnd();
                         }
                         var key = (Uri)e.UserState;
-                        _cache.Add(key, content);
+                        Add(key, content);
                         downloadQueue.Remove(key);
                         if (downloadQueue.Count == 0) {
                             onComplete.Invoke();</diff>
      <filename>Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/BrowserVirtualFilesystem.cs</filename>
    </modified>
    <modified>
      <diff>@@ -22,6 +22,7 @@ using System.Windows;
 using System.Windows.Resources;
 using System.Xml;
 using Microsoft.Scripting.Hosting;
+using Microsoft.Scripting.Utils;
 using System.Net;
 using System.Text.RegularExpressions;
 using System.Windows.Markup;
@@ -77,11 +78,27 @@ namespace Microsoft.Scripting.Silverlight {
         internal DynamicLanguageConfig LanguagesConfig { get; private set; }
 
         /// &lt;summary&gt;
+        /// Figure out the best baseUri to use; the entryPoint's path if it's
+        /// currently running, and the HTML page's path otherwise. 
+        /// &lt;/summary&gt;
+        public static Uri BaseUri {
+            get {
+                if (_Current.Engine != null &amp;&amp; _Current.Engine.RunningEntryPoint) {
+                    return new Uri(
+                        NormalizePath(Path.GetDirectoryName(Settings.EntryPoint)),
+                        UriKind.RelativeOrAbsolute
+                    );
+                }
+                return _HtmlPageUri;
+            }
+        }
+
+        /// &lt;summary&gt;
         /// Hold onto the base uri since it cannot be accessed from a
         /// background thread
-        internal Uri BaseUri { get; private set; }
+        /// &lt;/summary&gt;
+        internal static Uri _HtmlPageUri;
         #endregion
-
         #region Depricated Properties
         [Obsolete(&quot;Use DynamicApplication.Current.Engine.Runtime instead&quot;)]
         public ScriptRuntime Runtime { get { return Engine.Runtime; } }
@@ -110,7 +127,7 @@ namespace Microsoft.Scripting.Silverlight {
         private static int _UIThreadId;
         #endregion
 
-        #region Public API
+        #region LoadComponent, LoadRootVisual
         // these are instance methods so you can do Application.Current.TheMethod(...)
 
         /// &lt;summary&gt;
@@ -121,7 +138,7 @@ namespace Microsoft.Scripting.Silverlight {
         /// &lt;param name=&quot;uri&quot;&gt;Uri to a XAML file&lt;/param&gt;
         /// &lt;returns&gt;the RootVisual&lt;/returns&gt;
         public DependencyObject LoadRootVisual(UIElement root, Uri uri) {
-            root = (UIElement) LoadComponent(root, uri);
+            LoadComponent(root, uri);
             RootVisual = root;
             return root;
         }
@@ -134,25 +151,20 @@ namespace Microsoft.Scripting.Silverlight {
         /// &lt;param name=&quot;uri&quot;&gt;string representing the relative Uri of the XAML file&lt;/param&gt;
         /// &lt;returns&gt;the RootVisual&lt;/returns&gt;
         public DependencyObject LoadRootVisual(UIElement root, string xamlUri) {
-            return LoadRootVisual(root, xamlUri, true);
+            return LoadRootVisual(root, MakeUri(xamlUri));
         }
 
         /// &lt;summary&gt;
-        /// Either loads a XAML file URI, or the XAML itself, represented by a string,
+        /// Loads the XAML itself, represented by a string,
         /// and sets the RootVisual of the application.
         /// &lt;/summary&gt;
-        /// &lt;param name=&quot;root&quot;&gt;element to load XAML into&lt;/param&gt;
-        /// &lt;param name=&quot;xamlOrUri&quot;&gt;string representing a URI of a XAML file, or the XAML content itself&lt;/param&gt;
-        /// &lt;param name=&quot;uri&quot;&gt;set this to &quot;true&quot; if &quot;xamlOrUri&quot; is a URI, and &quot;false&quot; if it is XAML content&lt;/param&gt;
+        /// &lt;param name=&quot;root&quot;&gt;UIElement to load XAML into&lt;/param&gt;
+        /// &lt;param name=&quot;xamlString&quot;&gt;the XAML content itself&lt;/param&gt;
         /// &lt;returns&gt;the RootVisual&lt;/returns&gt;
-        public DependencyObject LoadRootVisual(UIElement root, string xamlOrUri, bool uri) {
-            if (uri) {
-                return LoadRootVisual(root, MakeUri(xamlOrUri));
-            } else {
-                root = (UIElement)LoadComponent(root, xamlOrUri, false);
-                RootVisual = root;
-                return root;
-            }
+        public DependencyObject LoadRootVisualFromString(string xamlString) {
+            var root = LoadComponentFromString(xamlString) as UIElement;
+            RootVisual = root;
+            return root;
         }
 
         /// &lt;summary&gt;
@@ -160,24 +172,8 @@ namespace Microsoft.Scripting.Silverlight {
         /// &lt;/summary&gt;
         /// &lt;param name=&quot;component&quot;&gt;The object to load the XAML into&lt;/param&gt;
         /// &lt;param name=&quot;uri&quot;&gt;string representing the relative Uri of the XAML file&lt;/param&gt;
-        public object LoadComponent(object component, string xamlUri) {
-            return LoadComponent(component, xamlUri, true);
-        }
-
-        /// &lt;summary&gt;
-        /// Loads a XAML file or XAML content into an object.
-        /// &lt;/summary&gt;
-        /// &lt;param name=&quot;component&quot;&gt;The object to load XAML into&lt;/param&gt;
-        /// &lt;param name=&quot;xamlOrUri&quot;&gt;either the URI of a XAML file, or the actual XAML content&lt;/param&gt;
-        /// &lt;param name=&quot;uri&quot;&gt;set this to &quot;true&quot; if &quot;xamlOrUri&quot; is a URI, and &quot;false&quot; if it is XAML content&lt;/param&gt;
-        /// &lt;returns&gt;The loaded XAML&lt;/returns&gt;
-        public object LoadComponent(object component, string xamlOrUri, bool uri) {
-            if (uri) {
-                return LoadComponent(component, MakeUri(xamlOrUri));
-            } else {
-                component = XamlReader.Load(Regex.Replace(xamlOrUri, &quot;x:Class=\&quot;.*?\&quot;&quot;, &quot;&quot;));
-                return component;
-            }
+        public static object LoadComponent(object component, string xamlUri) {
+            return LoadComponent(component, MakeUri(xamlUri));
         }
 
         /// &lt;summary&gt;
@@ -185,35 +181,95 @@ namespace Microsoft.Scripting.Silverlight {
         /// &lt;/summary&gt;
         /// &lt;param name=&quot;component&quot;&gt;The object to load the XAML into&lt;/param&gt;
         /// &lt;param name=&quot;uri&quot;&gt;relative Uri of the XAML file&lt;/param&gt;
-        public new object LoadComponent(object component, Uri relativeUri) {
-            if (Application.GetResourceStream(relativeUri) == null) {
-                var xamlStream = HttpPAL.PAL.VirtualFilesystem.GetFile(relativeUri);
-                if (xamlStream != null) {
-                    string xaml;
-                    using (StreamReader sr = new StreamReader(xamlStream)) {
-                        xaml = sr.ReadToEnd();
-                    }
-                    return LoadComponent(component, xaml, false);
-                }
+        public static new object LoadComponent(object component, Uri relativeUri) {
+            if (relativeUri.IsAbsoluteUri || Application.GetResourceStream(relativeUri) == null) {
+                // XAML file is not in the XAP, so fall back to XamlReader.Load
+                var xaml = HttpPAL.PAL.VirtualFilesystem.GetFileContents(relativeUri);
+                if (xaml != null) return LoadComponentFromString(xaml);
             } else {
                 Application.LoadComponent(component, relativeUri);
                 return component;
             }
             return null;
+        }
+
+        /// &lt;summary&gt;
+        /// Returns an object with the xaml string loaded
+        /// &lt;/summary&gt;
+        /// &lt;param name=&quot;xaml&quot;&gt;XAML string to load&lt;/param&gt;
+        /// &lt;returns&gt;Loaded XAML object&lt;/returns&gt;
+        public static object LoadComponentFromString(string xaml) {
+            return XamlReader.Load(Regex.Replace(xaml, &quot;x:Class=\&quot;.*?\&quot;&quot;, &quot;&quot;));
+        }
+        #endregion
+        #region MakeUri
+        /// &lt;summary&gt;
+        /// See MakeUri(Uri, Uri)
+        /// &lt;/summary&gt;
+        public static Uri MakeUri(string relativeUri) {
+            return MakeUri(null, relativeUri);
+        }
 
+        /// &lt;summary&gt;
+        /// See MakeUri(Uri, Uri)
+        /// &lt;/summary&gt;
+        public static Uri MakeUri(Uri baseUri, string relativeUri) {
+            return MakeUri(null, new Uri(NormalizePath(relativeUri), UriKind.Relative));
         }
 
         /// &lt;summary&gt;
-        /// Makes a Uri object that is relative to the location of the &quot;start&quot; source file.
+        /// See MakeUri(Uri, Uri)
         /// &lt;/summary&gt;
-        /// &lt;param name=&quot;relativeUri&quot;&gt;Any relative uri&lt;/param&gt;
-        /// &lt;returns&gt;A Uri relative to the &quot;start&quot; source file&lt;/returns&gt;
-        public Uri MakeUri(string relativeUri) {
-            string baseUri = ScriptTags.HasScriptTags &amp;&amp; Settings.EntryPoint != null ?
-                Path.GetDirectoryName(Settings.EntryPoint) :
-                &quot;&quot;;
-            if (baseUri != &quot;&quot;) baseUri += &quot;/&quot;;
-            return new Uri(baseUri + relativeUri, UriKind.Relative);
+        public static Uri MakeUri(Uri relativeUri) {
+            return MakeUri(null, relativeUri);
+        }
+
+        /// &lt;summary&gt;
+        /// Makes a Uri out of a baseUri and a relativeUri.
+        /// 
+        /// If the relativeUri is actually absolute, just return it.
+        /// Otherwise, take the baseUri and relativeUri and try to combine
+        /// them. When the baseUri is null, make the baseUri the entry-point's
+        /// directory and try checking if the combined Uri exists in the XAP
+        /// file; if so return it. Otherwise, make the baseUri
+        /// DynamicApplication.BaseUri and return the combined Uri. The Uris
+        /// are &quot;combined&quot;, by taking everything but the filename of the
+        /// baseUri and tacking the relativeUri onto the end.
+        /// &lt;/summary&gt;
+        public static Uri MakeUri(Uri baseUri, Uri relativeUri) {
+            if (!relativeUri.IsAbsoluteUri) {
+                if (baseUri == null) {
+                    baseUri = new Uri(
+                        Settings.EntryPoint == null ?
+                            string.Empty :
+                            NormalizePath(Path.GetDirectoryName(Settings.EntryPoint)),
+                        UriKind.Relative
+                    );
+                }
+                var testUri = MakeUriHelper(baseUri, relativeUri);
+                if (!baseUri.IsAbsoluteUri &amp;&amp; !XapPAL.PAL.FileExists(testUri.ToString())) {
+                    return MakeUriHelper(DynamicApplication.BaseUri, relativeUri);
+                }
+                return testUri;
+            }
+            return relativeUri;
+        }
+
+        private static Uri MakeUriHelper(Uri baseUri, Uri relativeUri) {
+            if (baseUri.IsAbsoluteUri) {
+                return new Uri(baseUri, relativeUri);
+            } else if (baseUri.ToString().Trim().Length == 0) {
+                return relativeUri;
+            } else {
+                return new Uri(NormalizePath(Path.Combine(
+                    Path.GetDirectoryName(baseUri.ToString()),
+                    relativeUri.ToString()
+                )), UriKind.Relative);
+            }
+        }
+
+        private static string NormalizePath(string path) {
+            return BrowserVirtualFilesystem.Normalize(path);
         }
         #endregion
 
@@ -229,7 +285,7 @@ namespace Microsoft.Scripting.Silverlight {
 
             _Current = this;
             _UIThreadId = Thread.CurrentThread.ManagedThreadId;
-            BaseUri = HtmlPage.Document.DocumentUri;
+            _HtmlPageUri = HtmlPage.Document.DocumentUri;
 
             Settings.ReportUnhandledErrors = true;
 
@@ -251,6 +307,7 @@ namespace Microsoft.Scripting.Silverlight {
                     Engine = new DynamicEngine();
                     if (Settings.ConsoleEnabled)
                         Repl.Show();
+                    LanguageTypeExtensions.Load(Engine.LangConfig);
                     ScriptTags.Run(Engine);
                     Engine.Run(Settings.EntryPoint);
                 });
@@ -279,6 +336,25 @@ namespace Microsoft.Scripting.Silverlight {
             args.Handled = true;
             ErrorFormatter.DisplayError(Settings.ErrorTargetID, args.ExceptionObject);
         }
+
+        /// &lt;summary&gt;
+        /// Get a resource out of the current assembly
+        /// &lt;/summary&gt;
+        /// &lt;param name=&quot;filename&quot;&gt;name of the resource&lt;/param&gt;
+        /// &lt;returns&gt;The string contents of the resource&lt;/returns&gt;
+        internal static string GetResource(string filename) {
+            var stream = GetManifestResourceStream(filename);
+            if (stream == null) return null;
+            var textStreamReader = new StreamReader(stream);
+            var result = textStreamReader.ReadToEnd();
+            textStreamReader.Close();
+            return result;
+        }
+
+        internal static Stream GetManifestResourceStream(string filename) {
+            return Assembly.GetExecutingAssembly().GetManifestResourceStream(&quot;Microsoft.Scripting.Silverlight.&quot; + filename);
+        }
+
         #endregion
     }
 }</diff>
      <filename>Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/DynamicApplication.cs</filename>
    </modified>
    <modified>
      <diff>@@ -59,6 +59,10 @@ namespace Microsoft.Scripting.Silverlight {
         /// &lt;/summary&gt;
         public ScriptScope EntryPointScope { get; private set; }
 
+        /// &lt;summary&gt;
+        /// true while the entry-point is running, false otherwise
+        /// &lt;/summary&gt;
+        internal bool RunningEntryPoint { get; set; }
 
         /// &lt;summary&gt;
         /// Finds the avaliable languages, initializes the ScriptRuntime, 
@@ -70,6 +74,7 @@ namespace Microsoft.Scripting.Silverlight {
         /// Initializes the languages, ScriptRuntime, and entry-point ScriptScope.
         /// &lt;/summary&gt;
         public DynamicEngine(DynamicLanguageConfig langConfig) {
+            RunningEntryPoint = false;
             if (langConfig == null) {
                 InitializeLangConfig();
             } else {
@@ -95,10 +100,19 @@ namespace Microsoft.Scripting.Silverlight {
         /// globals and modules.
         /// &lt;/summary&gt;
         private void InitializeScope() {
-            EntryPointScope = Runtime.CreateScope();
-            EntryPointScope.SetVariable(&quot;document&quot;, new DynamicHtmlDocument());
-            EntryPointScope.SetVariable(&quot;window&quot;, new DynamicHtmlObject(HtmlPage.Window));
-            EntryPointScope.SetVariable(&quot;me&quot;, DynamicApplication.Current.RootVisual);
+            EntryPointScope = CreateScope();
+        }
+
+        /// &lt;summary&gt;
+        /// Creates a new scope, adding any convenience globals and modules.
+        /// &lt;/summary&gt;
+        public ScriptScope CreateScope() {
+            var scope = Runtime.CreateScope();
+            scope.SetVariable(&quot;document&quot;, HtmlPage.Document);
+            scope.SetVariable(&quot;window&quot;, HtmlPage.Window);
+            scope.SetVariable(&quot;me&quot;, DynamicApplication.Current.RootVisual);
+            scope.SetVariable(&quot;xaml&quot;, DynamicApplication.Current.RootVisual);
+            return scope;
         }
 
         /// &lt;summary&gt;
@@ -170,13 +184,14 @@ namespace Microsoft.Scripting.Silverlight {
         /// &lt;/summary&gt;
         /// &lt;param name=&quot;entryPoint&quot;&gt;path to the script&lt;/param&gt;
         public void Run(string entryPoint) {
-            if (Settings.EntryPoint != null) {
+            if (entryPoint != null) {
                 var vfs = ((BrowserPAL) Runtime.Host.PlatformAdaptationLayer).VirtualFilesystem;
                 string code = vfs.GetFileContents(entryPoint);
-                Engine = Runtime.GetEngineByFileExtension(Path.GetExtension(Settings.EntryPoint));
-
+                Engine = Runtime.GetEngineByFileExtension(Path.GetExtension(entryPoint));
                 ScriptSource sourceCode = Engine.CreateScriptSourceFromString(code, entryPoint, SourceCodeKind.File);
+                RunningEntryPoint = true;
                 sourceCode.Compile(new ErrorFormatter.Sink()).Execute(EntryPointScope);
+                RunningEntryPoint = false;
             }
         }
     }</diff>
      <filename>Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/DynamicEngine.cs</filename>
    </modified>
    <modified>
      <diff>@@ -57,7 +57,7 @@ namespace Microsoft.Scripting.Silverlight {
         /// &lt;/summary&gt;
         /// &lt;param name=&quot;name&quot;&gt;name of the language&lt;/param&gt;
         /// &lt;returns&gt;configuration information for the language&lt;/returns&gt;
-        private DynamicLanguageInfo GetLanguageByName(string name) {
+        public DynamicLanguageInfo GetLanguageByName(string name) {
             foreach (var lang in Languages)
                 foreach (var n in lang.Names)
                     if (n.ToLower() == name.ToLower())</diff>
      <filename>Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/DynamicLanguageConfig.cs</filename>
    </modified>
    <modified>
      <diff>@@ -29,26 +29,25 @@ namespace Microsoft.Scripting.Silverlight {
     public class DynamicScriptTags {
 
         /// &lt;summary&gt;
-        /// Inline strings and external URIs for a unique language/defer-status combination.
+        /// Inline strings and external URIs for script-tag registered 
+        /// to this control.
         /// &lt;/summary&gt;
         public class ScriptCode {
             public string Language { get; private set; }
             public bool Defer { get; private set; }
-            public List&lt;string&gt; Inline { get; private set; }
-            public List&lt;Uri&gt; External { get; private set; }
+            public string Inline { get; set; }
+            public Uri External { get; set; }
 
             public ScriptCode(string lang, bool defer) {
                 Language = lang;
                 Defer = defer;
-                Inline = new List&lt;string&gt;();
-                External = new List&lt;Uri&gt;();
             }
         }
 
         /// &lt;summary&gt;
-        /// Dictionary of language-name(string) =&gt; (Dictionary of defer-status(bool) =&gt; ScriptCode)
+        /// Script code registered for this Silverlight control
         /// &lt;/summary&gt;
-        public Dictionary&lt;string, Dictionary&lt;bool, ScriptCode&gt;&gt; Code { get; private set; }
+        public List&lt;ScriptCode&gt; Code { get; private set; }
 
         /// &lt;summary&gt;
         /// Holds onto the language config
@@ -56,12 +55,18 @@ namespace Microsoft.Scripting.Silverlight {
         private DynamicLanguageConfig _LangConfig;
 
         /// &lt;summary&gt;
+        /// true while the script-tag is running, false otherwise
+        /// &lt;/summary&gt;
+        internal bool RunningScriptTags;
+
+        /// &lt;summary&gt;
         /// Given a language config it processes the script-tags on the HTML
         /// page (see &quot;GetScriptTags&quot;).
         /// &lt;/summary&gt;
         public DynamicScriptTags(DynamicLanguageConfig langConfig) {
+            RunningScriptTags = false;
             _LangConfig = langConfig;
-            Code = new Dictionary&lt;string, Dictionary&lt;bool, ScriptCode&gt;&gt;();
+            Code = new List&lt;ScriptCode&gt;();
             GetScriptTags();
         }
 
@@ -92,21 +97,15 @@ namespace Microsoft.Scripting.Silverlight {
 
                 _LangConfig.LanguagesUsed[language] = true;
 
-                if (!Code.ContainsKey(type) || Code[type] == null) {
-                    Code[type] = new Dictionary&lt;bool, ScriptCode&gt;();
-                }
-                if (!Code[type].ContainsKey(defer) || Code[type][defer] == null) {
-                    var sc = new ScriptCode(language, defer);
-                    Code[type][defer] = sc;
-                }
-
+                var sc = new ScriptCode(language, defer);
                 if (src != null) {
-                    Code[type][defer].External.Add(MakeUriAbsolute(new Uri(src, UriKind.RelativeOrAbsolute)));
+                    sc.External = DynamicApplication.MakeUri(src);
                 } else {
                     var innerHtml = (string)e.GetProperty(&quot;innerHTML&quot;);
                     if (innerHtml != null)
-                        Code[type][defer].Inline.Add(RemoveMargin(innerHtml));
+                        sc.Inline = RemoveMargin(innerHtml);
                 }
+                Code.Add(sc);
             }
         }
 
@@ -117,9 +116,9 @@ namespace Microsoft.Scripting.Silverlight {
         /// &lt;/summary&gt;
         public void DownloadExternalCode(Action onComplete) {
             var externalUris = new List&lt;Uri&gt;();
-            foreach (var pair1 in Code)
-                foreach(var pair2 in pair1.Value)
-                    externalUris.AddRange(pair2.Value.External);
+            foreach (var sc in Code)
+                if(sc.External != null)
+                    externalUris.Add(sc.External);
             ((HttpVirtualFilesystem)HttpPAL.PAL.VirtualFilesystem).
                 DownloadAndCache(externalUris, onComplete);
         }
@@ -129,13 +128,9 @@ namespace Microsoft.Scripting.Silverlight {
         /// &lt;/summary&gt;
         public bool HasScriptTags {
             get {
-                foreach (var i in Code) {
-                    foreach (var j in i.Value) {
-                        if (j.Value.Inline.Count &gt; 0) {
-                            return true;
-                        }
-                    }
-                }
+                foreach (var i in Code)
+                    if (i.External != null &amp;&amp; i.Inline != null)
+                        return true;
                 return false;
             }
         }
@@ -144,35 +139,35 @@ namespace Microsoft.Scripting.Silverlight {
         /// Runs the registered script tags against the DynamicEngine.
         /// &lt;/summary&gt;
         public void Run(DynamicEngine engine) {
-            foreach (var pair in Code) {
-                var lang = pair.Key;
-                engine.Engine = _LangConfig.GetEngine(GetLanguageNameFrom(pair.Key));
-                if (engine.Engine != null) {
-                    foreach (var pair2 in pair.Value) {
-                        var defer = pair2.Key;
-                        var scripts = pair2.Value;
-                        if (!defer) {
-                            foreach (var uri in scripts.External) {
-                                var code = BrowserPAL.PAL.VirtualFilesystem.GetFileContents(uri);
-                                if (code == null) continue;
-                                ScriptSource externalSourceCode =
-                                    engine.Engine.CreateScriptSourceFromString(
-                                        code,
-                                        uri.AbsoluteUri,
-                                        SourceCodeKind.File
-                                    );
-                                externalSourceCode.Compile(new ErrorFormatter.Sink()).Execute(engine.EntryPointScope);
-                            }
-                            foreach (var code in scripts.Inline) {
-                                ScriptSource inlineSourceCode =
-                                    engine.Engine.CreateScriptSourceFromString(
-                                        code,
-                                        HtmlPage.Document.DocumentUri.LocalPath.Remove(0, 1),
-                                        SourceCodeKind.File
-                                    );
-                                inlineSourceCode.Compile(new ErrorFormatter.Sink()).Execute(engine.EntryPointScope);
-                            }
-                        }
+            var inlineScope = engine.CreateScope();
+            foreach (var sc in Code) {
+                engine.Engine = _LangConfig.GetEngine(sc.Language);
+                if (engine.Engine != null &amp;&amp; !sc.Defer) {
+                    ScriptSource sourceCode = null;
+                    ScriptScope scope = null;
+                    if(sc.External != null) {
+                        var code = BrowserPAL.PAL.VirtualFilesystem.GetFileContents(sc.External);
+                        if (code == null) continue;
+                        sourceCode =
+                            engine.Engine.CreateScriptSourceFromString(
+                                code,
+                                sc.External.AbsoluteUri,
+                                SourceCodeKind.File
+                            );
+                        scope = engine.CreateScope();
+                    } else if (sc.Inline != null) {
+                        sourceCode =
+                            engine.Engine.CreateScriptSourceFromString(
+                                sc.Inline,
+                                DynamicApplication.BaseUri.LocalPath.Remove(0, 1),
+                                SourceCodeKind.File
+                            );
+                        scope = inlineScope;
+                    }
+                    if (sourceCode != null &amp;&amp; scope != null) {
+                        RunningScriptTags = true;
+                        sourceCode.Compile(new ErrorFormatter.Sink()).Execute(scope);
+                        RunningScriptTags = false;
                     }
                 }
             }
@@ -278,30 +273,6 @@ namespace Microsoft.Scripting.Silverlight {
         }
 
         /// &lt;summary&gt;
-        /// Makes the URI absolute (if it isn't already) against the HTML page.
-        /// &lt;/summary&gt;
-        private Uri MakeUriAbsolute(Uri uri) {
-            Uri referenceUri = HtmlPage.Document.DocumentUri;
-            if (!uri.IsAbsoluteUri) {
-
-                // Is this a direcory name?
-                Uri baseUri = null;
-                if (Path.GetExtension(referenceUri.AbsoluteUri) == &quot;&quot;) {
-                    // yes, so just use the directory
-                    baseUri = referenceUri;
-                } else {
-                    // no, so strip off the filename
-                    var slashIndex = referenceUri.AbsoluteUri.LastIndexOf('/');
-                    baseUri = new Uri(referenceUri.AbsoluteUri.Substring(0, slashIndex + 1), UriKind.Absolute);
-                }
-
-                return new Uri(baseUri, uri);
-            } else {
-                return uri;
-            }
-        }
-
-        /// &lt;summary&gt;
         /// Is the given &quot;languageName&quot; represented by a avaliable language?
         /// &lt;/summary&gt;
         public bool LanguageFound(string languageName) {</diff>
      <filename>Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/DynamicScriptTags.cs</filename>
    </modified>
    <modified>
      <diff>@@ -27,6 +27,29 @@ using System.Dynamic;
 
 namespace Microsoft.Scripting.Silverlight {
 
+    #region Run code to load language-specific type extensions
+    public static class LanguageTypeExtensions {
+        public static void Load(DynamicLanguageConfig langConfig) {
+            foreach (var pair in langConfig.LanguagesUsed) {
+                if (pair.Value) {
+                    var lang = langConfig.GetLanguageByName(pair.Key);
+                    LanguageTypeExtensions.LoadByExtension(lang.Extensions[0]);
+                }
+            }
+        }
+
+        public static void LoadByExtension(string fileExtension) {
+            var path = string.Format(&quot;init{0}&quot;, fileExtension);
+            var code = DynamicApplication.GetResource(path);
+            if (code == null) return;
+            var dyneng = DynamicApplication.Current.Engine;
+            dyneng.Engine = dyneng.Runtime.GetEngineByFileExtension(fileExtension);
+            dyneng.Engine.CreateScriptSourceFromString(code, path).Execute(dyneng.CreateScope());
+        }
+    }
+    #endregion
+
+    #region Extension classes that support Microsoft.Scripting.Runtime.ExtensionTypeAttribute
     /// &lt;summary&gt;
     /// Injects properties into the HtmlDocument object for each element ID
     /// &lt;/summary&gt;
@@ -70,97 +93,5 @@ namespace Microsoft.Scripting.Silverlight {
             return result;
         }
     }
-
-    /// &lt;summary&gt;
-    /// Dynamic HtmlDocument
-    /// &lt;/summary&gt;
-    public class DynamicHtmlDocument : DynamicHtmlObject {
-        public DynamicHtmlDocument() {
-            StaticObject = HtmlPage.Document;
-        }
-
-        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) {
-            HtmlElement element = ((HtmlDocument)StaticObject).GetElementById(binder.Name);
-            if (element == null) {
-                return base.TryInvokeMember(binder, args, out result);
-            }
-            result = new DynamicHtmlObject(element);
-            return true;
-        }
-
-        public override bool TryGetMember(GetMemberBinder binder, out object result) {
-            HtmlElement element = ((HtmlDocument)StaticObject).GetElementById(binder.Name);
-            if (element == null) {
-                return base.TryGetMember(binder, out result);
-            }
-            result = new DynamicHtmlObject(element);
-            return true;
-        }
-    }
-
-    /// &lt;summary&gt;
-    /// Dynamic HtmlObject
-    /// &lt;/summary&gt;
-    public class DynamicHtmlObject : DynamicScriptObject {
-        public DynamicHtmlObject() { }
-        public DynamicHtmlObject(HtmlObject obj) {
-            StaticObject = obj;
-        }
-
-        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) {
-            try {
-                var obj = StaticObject.Invoke(binder.Name, args);
-                result = new DynamicScriptObject((ScriptObject)obj);
-                return true;
-            } catch (InvalidOperationException) {
-                return base.TryInvokeMember(binder, args, out result);
-            }
-        }
-
-        public override bool TryGetMember(GetMemberBinder binder, out object result) {
-            try {
-                var obj = StaticObject.Invoke(binder.Name);
-                result = new DynamicScriptObject((ScriptObject)obj);
-                return true;
-            } catch (InvalidOperationException) {
-                return base.TryGetMember(binder, out result);
-            }
-        }
-
-        public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) {
-            return base.TryInvoke(binder, args, out result);
-        }
-    }
-
-    /// &lt;summary&gt;
-    /// Dynamic ScriptObject
-    /// &lt;/summary&gt;
-    public class DynamicScriptObject : DynamicObject {
-        public ScriptObject StaticObject { get; protected set; }
-
-        public DynamicScriptObject() { }
-        public DynamicScriptObject(ScriptObject so) {
-            StaticObject = so;
-        }
-
-        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) {
-            try {
-                var opts = DynamicApplication.Current.Engine.Engine.Operations;
-                result = opts.InvokeMember(StaticObject, binder.Name, args);
-                return true;
-            } catch {
-                return base.TryInvokeMember(binder, args, out result);
-            }
-        }
-
-        public override bool TryGetMember(GetMemberBinder binder, out object result) {
-            try {
-                var opts = DynamicApplication.Current.Engine.Engine.Operations;
-                result = opts.GetMember(StaticObject, binder.Name);
-                return true;
-            } catch {
-                return base.TryGetMember(binder, out result);
-            }
-        }
-    }
-}
+    #endregion
+}
\ No newline at end of file</diff>
      <filename>Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/ExtensionTypes.cs</filename>
    </modified>
    <modified>
      <diff>@@ -16,11 +16,10 @@
     &lt;AssemblyOriginatorKeyFile&gt;..\..\..\Support\MSSharedLibKey.snk&lt;/AssemblyOriginatorKeyFile&gt;
     &lt;SignAssembly Condition=&quot;'$(SignAssembly)' == '' And Exists('$(AssemblyOriginatorKeyFile)')&quot;&gt;true&lt;/SignAssembly&gt;
     &lt;SignedSym Condition=&quot;'$(SignAssembly)' == 'true'&quot;&gt;SIGNED&lt;/SignedSym&gt;
-    &lt;DelaySign&gt;true&lt;/DelaySign&gt;    
+    &lt;DelaySign&gt;true&lt;/DelaySign&gt;
     &lt;SilverlightBuild&gt;true&lt;/SilverlightBuild&gt;
     &lt;Silverlight3Path&gt;..\..\..\Utilities\Silverlight\x86ret&lt;/Silverlight3Path&gt;
     &lt;Silverlight4Path&gt;..\..\..\Utilities\Silverlight\v4-x86fre&lt;/Silverlight4Path&gt;
-
     &lt;!-- The following two lines prevent csc.rsp and Microsoft.NETFramework.props from adding additional assembly references --&gt;
     &lt;NoConfig&gt;true&lt;/NoConfig&gt;
     &lt;AddAdditionalExplicitAssemblyReferences&gt;false&lt;/AddAdditionalExplicitAssemblyReferences&gt;
@@ -161,6 +160,9 @@
     &lt;EmbeddedResource Include=&quot;agdlr.css&quot; /&gt;
     &lt;EmbeddedResource Include=&quot;agdlr.js&quot; /&gt;
   &lt;/ItemGroup&gt;
+  &lt;ItemGroup&gt;
+    &lt;EmbeddedResource Include=&quot;init.rb&quot; /&gt;
+  &lt;/ItemGroup&gt;
   &lt;Import Project=&quot;$(MSBuildBinPath)\Microsoft.CSharp.targets&quot; Condition=&quot; '$(SilverlightTreeBuild)' != 'true' &quot; /&gt;
   &lt;!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
@@ -173,4 +175,4 @@
     &lt;PostBuildEvent&gt;
     &lt;/PostBuildEvent&gt;
   &lt;/PropertyGroup&gt;
-&lt;/Project&gt;
+&lt;/Project&gt;
\ No newline at end of file</diff>
      <filename>Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/Microsoft.Scripting.Silverlight.csproj</filename>
    </modified>
    <modified>
      <diff>@@ -114,7 +114,7 @@ namespace Microsoft.Scripting.Silverlight {
 
             ScriptScope scope = DynamicApplication.Current.Engine.EntryPointScope;
             if (scope == null) {
-                scope = engine.CreateScope();
+                scope = DynamicApplication.Current.Engine.CreateScope();
             }
 
             return Show(engine, scope);</diff>
      <filename>Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/Repl.cs</filename>
    </modified>
    <modified>
      <diff>@@ -164,7 +164,7 @@ namespace Microsoft.Scripting.Silverlight {
             var block = HtmlPage.Document.CreateElement(tagName);
             block.SetAttribute(&quot;type&quot;, mimeType);
             
-            string scriptOrStyle = GetResource(filename);
+            string scriptOrStyle = DynamicApplication.GetResource(filename);
             
             var ieScriptOrStyleSet = false;
 
@@ -189,14 +189,6 @@ namespace Microsoft.Scripting.Silverlight {
             return HtmlPage.Document.GetElementsByTagName(&quot;head&quot;)[0] as HtmlElement;
         }
 
-        private string GetResource(string filename) {
-            var assembly = Assembly.GetExecutingAssembly();
-            var textStreamReader = new StreamReader(assembly.GetManifestResourceStream(&quot;Microsoft.Scripting.Silverlight.&quot; + filename));
-            var result = textStreamReader.ReadToEnd();
-            textStreamReader.Close();
-            return result;
-        }
-
         private string WindowHtml() {
             return string.Format(_htmlTemplate, _windowId, _windowMenuId, _windowLinkId);
         }</diff>
      <filename>Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/Window.cs</filename>
    </modified>
    <modified>
      <diff>@@ -57,20 +57,8 @@ namespace Microsoft.Scripting.Silverlight {
                 }
                 xaml = w.ToString();
 
-                // Find the root XAML node, create the corresponding Control 
-                // object, and set the RootVisual with the XAML string.
-                XmlReader reader = XmlReader.Create(new StringReader(xaml));
-                reader.MoveToContent();
-                if (reader.NodeType == XmlNodeType.Element) {
-                    var aqn = typeof(System.Windows.Controls.UserControl).AssemblyQualifiedName;
-                    var type = Type.GetType(
-                        string.Format(&quot;System.Windows.Controls.{0}, {1}&quot;, reader.Name, aqn.Substring(aqn.IndexOf(',') + 1))
-                    );
-                    if(type != null) {
-                        var root = (UIElement) type.GetConstructor(new Type[] { }).Invoke(new object[] { });
-                        DynamicApplication.Current.LoadRootVisual(root, xaml, false);
-                    }
-                }
+                // set the RootVisual
+                DynamicApplication.Current.LoadRootVisualFromString(xaml);
             };
 
             // If src is set, download the src and invoke onComplete when the</diff>
      <filename>Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/XamlScriptTags.cs</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>01bd6c601e3f5066860231bc5b13a1b3284392ae</id>
    </parent>
  </parents>
  <author>
    <name>Jim Deville</name>
    <email>jdeville@microsoft.com</email>
  </author>
  <url>http://github.com/shri/ironruby/commit/abdb2564bd050a5c37bd7976ccb52e71052265a1</url>
  <id>abdb2564bd050a5c37bd7976ccb52e71052265a1</id>
  <committed-date>2009-10-28T08:43:12-07:00</committed-date>
  <authored-date>2009-10-28T08:43:12-07:00</authored-date>
  <message>reverting accidental undoing of Jimmy's SL changes</message>
  <tree>811cb616796ffe79e185013b3e6eff54e7a17062</tree>
  <committer>
    <name>Jim Deville</name>
    <email>jdeville@microsoft.com</email>
  </committer>
</commit>
