| CODENOTIFIER | HelpYou are not signed inSign in |
Project: IronRuby
Revision: 139
Author: jlam
Date: 04 Sep 2008 14:06:56
Changes:Updating IronRuby to use new DLR configuration files -- see app.config
Files:| ... | ...@@ -0,0 +1,129 @@ | |
| 1 | /* **************************************************************************** | |
| 2 | * | |
| 3 | * Copyright (c) Microsoft Corporation. | |
| 4 | * | |
| 5 | * This source code is subject to terms and conditions of the Microsoft Public License. A | |
| 6 | * copy of the license can be found in the License.html file at the root of this distribution. If | |
| 7 | * you cannot locate the Microsoft Public License, please send an email to | |
| 8 | * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound | |
| 9 | * by the terms of the Microsoft Public License. | |
| 10 | * | |
| 11 | * You must not remove this notice, or any other, from this software. | |
| 12 | * | |
| 13 | * | |
| 14 | * ***************************************************************************/ | |
| 15 | ||
| 16 | using System; | |
| 17 | using System.Collections.Generic; | |
| 18 | using System.Collections.ObjectModel; | |
| 19 | using Microsoft.Scripting.Utils; | |
| 20 | using System.IO; | |
| 21 | using System.Threading; | |
| 22 | ||
| 23 | namespace Microsoft.Scripting { | |
| 24 | ||
| 25 | [Serializable] | |
| 26 | public class LanguageOptions { | |
| 27 | private bool _exceptionDetail; | |
| 28 | private bool _showClrExceptions; | |
| 29 | private bool _interpretedMode; | |
| 30 | private readonly bool _perfStats; | |
| 31 | private readonly ReadOnlyCollection<string> _searchPaths; | |
| 32 | ||
| 33 | /// <summary> | |
| 34 | /// Interpret code instead of emitting it. | |
| 35 | /// </summary> | |
| 36 | public bool InterpretedMode { | |
| 37 | get { return _interpretedMode; } | |
| 38 | set { _interpretedMode = value; } | |
| 39 | } | |
| 40 | ||
| 41 | /// <summary> | |
| 42 | /// Display exception detail (callstack) when exception gets caught | |
| 43 | /// </summary> | |
| 44 | public bool ExceptionDetail { | |
| 45 | get { return _exceptionDetail; } | |
| 46 | set { _exceptionDetail = value; } | |
| 47 | } | |
| 48 | ||
| 49 | public bool ShowClrExceptions { | |
| 50 | get { return _showClrExceptions; } | |
| 51 | set { _showClrExceptions = value; } | |
| 52 | } | |
| 53 | ||
| 54 | /// <summary> | |
| 55 | /// Whether to gather performance statistics. | |
| 56 | /// </summary> | |
| 57 | public bool PerfStats { | |
| 58 | get { return _perfStats; } | |
| 59 | } | |
| 60 | ||
| 61 | /// <summary> | |
| 62 | /// Initial file search paths provided by the host. | |
| 63 | /// </summary> | |
| 64 | public ReadOnlyCollection<string> SearchPaths { | |
| 65 | get { return _searchPaths; } | |
| 66 | } | |
| 67 | ||
| 68 | public LanguageOptions() | |
| 69 | : this(null) { | |
| 70 | } | |
| 71 | ||
| 72 | public LanguageOptions(IDictionary<string, object> options) { | |
| 73 | _interpretedMode = GetOption(options, "InterpretedMode", false); | |
| 74 | _exceptionDetail = GetOption(options, "ExceptionDetail", false); | |
| 75 | _showClrExceptions = GetOption(options, "ShowClrExceptions", false); | |
| 76 | _perfStats = GetOption(options, "PerfStats", false); | |
| 77 | _searchPaths = GetSearchPathsOption(options) ?? new ReadOnlyCollection<string>(new[] { "." }); | |
| 78 | } | |
| 79 | ||
| 80 | public static T GetOption<T>(IDictionary<string, object> options, string name, T defaultValue) { | |
| 81 | object value; | |
| 82 | if (options != null && options.TryGetValue(name, out value)) { | |
| 83 | if (value is T) { | |
| 84 | return (T)value; | |
| 85 | } | |
| 86 | return (T)Convert.ChangeType(value, typeof(T), Thread.CurrentThread.CurrentCulture); | |
| 87 | } | |
| 88 | return defaultValue; | |
| 89 | } | |
| 90 | ||
| 91 | /// <summary> | |
| 92 | /// Reads an option whose value is expected to be a collection of non-null strings. | |
| 93 | /// Reaturns a read-only copy of the option's value. | |
| 94 | /// </summary> | |
| 95 | public static ReadOnlyCollection<string> GetStringCollectionOption(IDictionary<string, object> options, string name, params char[] separators) { | |
| 96 | object value; | |
| 97 | if (options == null || !options.TryGetValue(name, out value)) { | |
| 98 | return null; | |
| 99 | } | |
| 100 | ||
| 101 | // a collection: | |
| 102 | var collection = value as ICollection<string>; | |
| 103 | if (collection != null) { | |
| 104 | foreach (var item in collection) { | |
| 105 | if (item == null) { | |
| 106 | throw new ArgumentException(String.Format("Invalid value for option {0}: collection shouldn't containt null items", name)); | |
| 107 | } | |
| 108 | } | |
| 109 | ||
| 110 | return new ReadOnlyCollection<string>(ArrayUtils.MakeArray(collection)); | |
| 111 | } | |
| 112 | ||
| 113 | // a string: | |
| 114 | var strValue = value as string; | |
| 115 | if (strValue != null && separators != null && separators.Length > 0) { | |
| 116 | return new ReadOnlyCollection<string>(StringUtils.Split(strValue, separators, Int32.MaxValue, StringSplitOptions.RemoveEmptyEntries)); | |
| 117 | } | |
| 118 | ||
| 119 | throw new ArgumentException(String.Format("Invalid value for option {0}", name)); | |
| 120 | } | |
| 121 | ||
| 122 | public static ReadOnlyCollection<string> GetSearchPathsOption(IDictionary<string, object> options) { | |
| 123 | return GetStringCollectionOption(options, "SearchPaths", Path.PathSeparator); | |
| 124 | } | |
| 125 | ||
| 126 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] | |
| 127 | protected static readonly ReadOnlyCollection<string> EmptyStringCollection = new ReadOnlyCollection<string>(ArrayUtils.EmptyStrings); | |
| 128 | } | |
| 129 | } |
| ... | ...@@ -45,21 +45,21 @@ | |
| 45 | 45 | /// Directory where snippet assembly will be saved if SaveSnippets is set. |
| 46 | 46 | /// </summary> |
| 47 | 47 | public string SnippetsDirectory { |
| 48 | get { return _snippetsDirectory; } | |
| 48 | get { return _optionsFrozen ? _snippetsDirectory : DebugOptions.SnippetsDirectory; } | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /// <summary> |
| 52 | 52 | /// Name of the snippet assembly (w/o extension). |
| 53 | 53 | /// </summary> |
| 54 | 54 | public string SnippetsFileName { |
| 55 | get { return _snippetsFileName; } | |
| 55 | get { return _optionsFrozen ? _snippetsFileName : DebugOptions.SnippetsFileName; } | |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /// <summary> |
| 59 | 59 | /// Save snippets to an assembly (see also SnippetsDirectory, SnippetsFileName). |
| 60 | 60 | /// </summary> |
| 61 | 61 | public bool SaveSnippets { |
| 62 | get { return _saveSnippets; } | |
| 62 | get { return _optionsFrozen ? _saveSnippets : DebugOptions.SaveSnippets; } | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | private AssemblyGen GetAssembly(bool emitSymbols) { |
| ... | ...@@ -15,6 +15,7 @@ | |
| 15 | 15 | |
| 16 | 16 | namespace System.Linq.Expressions { |
| 17 | 17 | public sealed class EmptyStatement : Expression { |
| 18 | internal static readonly EmptyStatement Instance = new EmptyStatement(Annotations.Empty); | |
| 18 | 19 | |
| 19 | 20 | internal EmptyStatement(Annotations annotations) |
| 20 | 21 | : base(ExpressionType.EmptyStatement, typeof(void), annotations) { |
| ... | ...@@ -23,7 +24,7 @@ | |
| 23 | 24 | |
| 24 | 25 | public partial class Expression { |
| 25 | 26 | public static EmptyStatement Empty() { |
| 26 | return Empty(Annotations.Empty); | |
| 27 | return EmptyStatement.Instance; | |
| 27 | 28 | } |
| 28 | 29 | |
| 29 | 30 | public static EmptyStatement Empty(Annotations annotations) { |
| ... | ...@@ -370,6 +370,11 @@ | |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | // emitted: |
| 373 | public static object PropagateRetrySingleton(object possibleRetrySingleton, object other) { | |
| 374 | return IsRetrySingleton(possibleRetrySingleton) ? possibleRetrySingleton : other; | |
| 375 | } | |
| 376 | ||
| 377 | // emitted: | |
| 373 | 378 | public static object GetRetrySingleton() { |
| 374 | 379 | return RetrySingleton; |
| 375 | 380 | } |
| ... | ...@@ -0,0 +1,196 @@ | |
| 1 | /* **************************************************************************** | |
| 2 | * | |
| 3 | * Copyright (c) Microsoft Corporation. | |
| 4 | * | |
| 5 | * This source code is subject to terms and conditions of the Microsoft Public License. A | |
| 6 | * copy of the license can be found in the License.html file at the root of this distribution. If | |
| 7 | * you cannot locate the Microsoft Public License, please send an email to | |
| 8 | * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound | |
| 9 | * by the terms of the Microsoft Public License. | |
| 10 | * | |
| 11 | * You must not remove this notice, or any other, from this software. | |
| 12 | * | |
| 13 | * | |
| 14 | * ***************************************************************************/ | |
| 15 | ||
| 16 | using System; | |
| 17 | using System.Collections.Generic; | |
| 18 | ||
| 19 | namespace Microsoft.Scripting.Utils { | |
| 20 | ||
| 21 | // Like ReadOnlyCollection<T>: wraps an IDictionary<K, V> in a read-only wrapper | |
| 22 | [Serializable] | |
| 23 | internal sealed class ReadOnlyDictionary<K, V> : IDictionary<K, V> { | |
| 24 | ||
| 25 | // For wrapping non-readonly Keys, Values collections | |
| 26 | // Not used for standard dictionaries, which return read-only Keys and Values | |
| 27 | private sealed class ReadOnlyWrapper<T> : ICollection<T> { | |
| 28 | // no idea why this warning is here | |
| 29 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] | |
| 30 | private readonly ICollection<T> _collection; | |
| 31 | ||
| 32 | internal ReadOnlyWrapper(ICollection<T> collection) { | |
| 33 | _collection = collection; | |
| 34 | } | |
| 35 | ||
| 36 | #region ICollection<T> Members | |
| 37 | ||
| 38 | public void Add(T item) { | |
| 39 | throw new NotSupportedException("Collection is read-only."); | |
| 40 | } | |
| 41 | ||
| 42 | public void Clear() { | |
| 43 | throw new NotSupportedException("Collection is read-only."); | |
| 44 | } | |
| 45 | ||
| 46 | public bool Contains(T item) { | |
| 47 | return _collection.Contains(item); | |
| 48 | } | |
| 49 | ||
| 50 | public void CopyTo(T[] array, int arrayIndex) { | |
| 51 | _collection.CopyTo(array, arrayIndex); | |
| 52 | } | |
| 53 | ||
| 54 | public int Count { | |
| 55 | get { return _collection.Count; } | |
| 56 | } | |
| 57 | ||
| 58 | public bool IsReadOnly { | |
| 59 | get { return true; } | |
| 60 | } | |
| 61 | ||
| 62 | public bool Remove(T item) { | |
| 63 | throw new NotSupportedException("Collection is read-only."); | |
| 64 | } | |
| 65 | ||
| 66 | #endregion | |
| 67 | ||
| 68 | #region IEnumerable<T> Members | |
| 69 | ||
| 70 | public IEnumerator<T> GetEnumerator() { | |
| 71 | return _collection.GetEnumerator(); | |
| 72 | } | |
| 73 | ||
| 74 | #endregion | |
| 75 | ||
| 76 | #region IEnumerable Members | |
| 77 | ||
| 78 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { | |
| 79 | return _collection.GetEnumerator(); | |
| 80 | } | |
| 81 | ||
| 82 | #endregion | |
| 83 | } | |
| 84 | ||
| 85 | private readonly IDictionary<K, V> _dict; | |
| 86 | ||
| 87 | internal ReadOnlyDictionary(IDictionary<K, V> dict) { | |
| 88 | ReadOnlyDictionary<K, V> rodict = dict as ReadOnlyDictionary<K, V>; | |
| 89 | _dict = (rodict != null) ? rodict._dict : dict; | |
| 90 | } | |
| 91 | ||
| 92 | #region IDictionary<K,V> Members | |
| 93 | ||
| 94 | public bool ContainsKey(K key) { | |
| 95 | return _dict.ContainsKey(key); | |
| 96 | } | |
| 97 | ||
| 98 | public ICollection<K> Keys { | |
| 99 | get { | |
| 100 | ICollection<K> keys = _dict.Keys; | |
| 101 | if (!keys.IsReadOnly) { | |
| 102 | return new ReadOnlyWrapper<K>(keys); | |
| 103 | } | |
| 104 | return keys; | |
| 105 | } | |
| 106 | } | |
| 107 | ||
| 108 | public bool TryGetValue(K key, out V value) { | |
| 109 | return _dict.TryGetValue(key, out value); | |
| 110 | } | |
| 111 | ||
| 112 | public ICollection<V> Values { | |
| 113 | get { | |
| 114 | ICollection<V> values = _dict.Values; | |
| 115 | if (!values.IsReadOnly) { | |
| 116 | return new ReadOnlyWrapper<V>(values); | |
| 117 | } | |
| 118 | return values; | |
| 119 | } | |
| 120 | } | |
| 121 | ||
| 122 | public V this[K key] { | |
| 123 | get { | |
| 124 | return _dict[key]; | |
| 125 | } | |
| 126 | } | |
| 127 | ||
| 128 | ||
| 129 | void IDictionary<K, V>.Add(K key, V value) { | |
| 130 | throw new NotSupportedException("Collection is read-only."); | |
| 131 | } | |
| 132 | ||
| 133 | bool IDictionary<K, V>.Remove(K key) { | |
| 134 | throw new NotSupportedException("Collection is read-only."); | |
| 135 | } | |
| 136 | ||
| 137 | V IDictionary<K, V>.this[K key] { | |
| 138 | get { | |
| 139 | return _dict[key]; | |
| 140 | } | |
| 141 | set { | |
| 142 | throw new NotSupportedException("Collection is read-only."); | |
| 143 | } | |
| 144 | } | |
| 145 | ||
| 146 | #endregion | |
| 147 | ||
| 148 | #region ICollection<KeyValuePair<K,V>> Members | |
| 149 | ||
| 150 | public bool Contains(KeyValuePair<K, V> item) { | |
| 151 | return _dict.Contains(item); | |
| 152 | } | |
| 153 | ||
| 154 | public void CopyTo(KeyValuePair<K, V>[] array, int arrayIndex) { | |
| 155 | _dict.CopyTo(array, arrayIndex); | |
| 156 | } | |
| 157 | ||
| 158 | public int Count { | |
| 159 | get { return _dict.Count; } | |
| 160 | } | |
| 161 | ||
| 162 | public bool IsReadOnly { | |
| 163 | get { return true; } | |
| 164 | } | |
| 165 | ||
| 166 | void ICollection<KeyValuePair<K, V>>.Add(KeyValuePair<K, V> item) { | |
| 167 | throw new NotSupportedException("Collection is read-only."); | |
| 168 | } | |
| 169 | ||
| 170 | void ICollection<KeyValuePair<K, V>>.Clear() { | |
| 171 | throw new NotSupportedException("Collection is read-only."); | |
| 172 | } | |
| 173 | ||
| 174 | bool ICollection<KeyValuePair<K,V>>.Remove(KeyValuePair<K, V> item) { | |
| 175 | throw new NotSupportedException("Collection is read-only."); | |
| 176 | } | |
| 177 | ||
| 178 | #endregion | |
| 179 | ||
| 180 | #region IEnumerable<KeyValuePair<K,V>> Members | |
| 181 | ||
| 182 | public IEnumerator<KeyValuePair<K, V>> GetEnumerator() { | |
| 183 | return _dict.GetEnumerator(); | |
| 184 | } | |
| 185 | ||
| 186 | #endregion | |
| 187 | ||
| 188 | #region IEnumerable Members | |
| 189 | ||
| 190 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { | |
| 191 | return _dict.GetEnumerator(); | |
| 192 | } | |
| 193 | ||
| 194 | #endregion | |
| 195 | } | |
| 196 | } |
| ... | ...@@ -1,5 +0,0 @@ | |
| 1 | <configuration> | |
| 2 | <appSettings> | |
| 3 | <add key="LibPaths" value="..\..\Languages\Ruby\libs;..\..\..\External\Languages\Ruby\Ruby-1.8.6\lib\ruby\site_ruby\1.8;..\..\..\External\Languages\Ruby\Ruby-1.8.6\lib\ruby\site_ruby;..\..\..\External\Languages\Ruby\Ruby-1.8.6\lib\ruby\1.8" /> | |
| 4 | </appSettings> | |
| 5 | </configuration> |
| ... | ...@@ -0,0 +1,91 @@ | |
| 1 | /* **************************************************************************** | |
| 2 | * | |
| 3 | * Copyright (c) Microsoft Corporation. | |
| 4 | * | |
| 5 | * This source code is subject to terms and conditions of the Microsoft Public License. A | |
| 6 | * copy of the license can be found in the License.html file at the root of this distribution. If | |
| 7 | * you cannot locate the Microsoft Public License, please send an email to | |
| 8 | * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound | |
| 9 | * by the terms of the Microsoft Public License. | |
| 10 | * | |
| 11 | * You must not remove this notice, or any other, from this software. | |
| 12 | * | |
| 13 | * | |
| 14 | * ***************************************************************************/ | |
| 15 | ||
| 16 | #if !SILVERLIGHT | |
| 17 | ||
| 18 | using System.Configuration; | |
| 19 | using System; | |
| 20 | using System.Collections.Generic; | |
| 21 | using Microsoft.Scripting.Runtime; | |
| 22 | ||
| 23 | namespace Microsoft.Scripting.Hosting.Configuration { | |
| 24 | ||
| 25 | public class OptionElement : ConfigurationElement { | |
| 26 | private const string _Option = "option"; | |
| 27 | private const string _Value = "value"; | |
| 28 | private const string _Language = "language"; | |
| 29 | ||
| 30 | private static ConfigurationPropertyCollection _Properties = new ConfigurationPropertyCollection() { | |
| 31 | new ConfigurationProperty(_Option, typeof(string), String.Empty, ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey), | |
| 32 | new ConfigurationProperty(_Value, typeof(string), String.Empty, ConfigurationPropertyOptions.IsRequired), | |
| 33 | new ConfigurationProperty(_Language, typeof(string), String.Empty, ConfigurationPropertyOptions.IsKey), | |
| 34 | }; | |
| 35 | ||
| 36 | protected override ConfigurationPropertyCollection Properties { | |
| 37 | get { return _Properties; } | |
| 38 | } | |
| 39 | ||
| 40 | public string Name { | |
| 41 | get { return (string)this[_Option]; } | |
| 42 | set { this[_Option] = value; } | |
| 43 | } | |
| 44 | ||
| 45 | public string Value { | |
| 46 | get { return (string)this[_Value]; } | |
| 47 | set { this[_Value] = value; } | |
| 48 | } | |
| 49 | ||
| 50 | public string Language { | |
| 51 | get { return (string)this[_Language]; } | |
| 52 | set { this[_Language] = value; } | |
| 53 | } | |
| 54 | ||
| 55 | internal object GetKey() { | |
| 56 | return new Key(Name, Language); | |
| 57 | } | |
| 58 | ||
| 59 | internal sealed class Key : IEquatable<Key> { | |
| 60 | private readonly string _option; | |
| 61 | private readonly string _language; | |
| 62 | ||
| 63 | public string Option { get { return _option; } } | |
| 64 | public string Language { get { return _language; } } | |
| 65 | ||
| 66 | public Key(string option, string language) { | |
| 67 | _option = option; | |
| 68 | _language = language; | |
| 69 | } | |
| 70 | ||
| 71 | public override bool Equals(object obj) { | |
| 72 | return Equals(obj as Key); | |
| 73 | } | |
| 74 | ||
| 75 | public bool Equals(Key other) { | |
| 76 | return other != null && | |
| 77 | DlrConfiguration.OptionNameComparer.Equals(_option, other._option) && | |
| 78 | DlrConfiguration.LanguageNameComparer.Equals(_language, other._language); | |
| 79 | } | |
| 80 | ||
| 81 | public override int GetHashCode() { | |
| 82 | return _option.GetHashCode() ^ (_language ?? String.Empty).GetHashCode(); | |
| 83 | } | |
| 84 | ||
| 85 | public override string ToString() { | |
| 86 | return (String.IsNullOrEmpty(_language) ? String.Empty : _language + ":") + _option; | |
| 87 | } | |
| 88 | } | |
| 89 | } | |
| 90 | } | |
| 91 | #endif | |
| 0 | 92 | \ No newline at end of file |
| ... | ...@@ -17,8 +17,13 @@ | |
| 17 | 17 | using System.Collections.Generic; |
| 18 | 18 | using Microsoft.Scripting.Runtime; |
| 19 | 19 | using Microsoft.Scripting.Utils; |
| 20 | using System.Reflection; | |
| 21 | using System.IO; | |
| 20 | 22 | |
| 21 | 23 | namespace Microsoft.Scripting.Hosting { |
| 24 | /// <summary> | |
| 25 | /// Stores information needed to setup a ScriptRuntime | |
| 26 | /// </summary> | |
| 22 | 27 | [Serializable] |
| 23 | 28 | public sealed class ScriptRuntimeSetup { |
| 24 | 29 | // host specification: |
| ... | ...@@ -26,109 +31,75 @@ | |
| 26 | 31 | private object[] _hostArguments; |
| 27 | 32 | |
| 28 | 33 | // languages available in the runtime: |
| 29 | private readonly Dictionary<AssemblyQualifiedTypeName, LanguageSetup> _languageSetups; | |
| 34 | private readonly List<LanguageSetup> _languageSetups; | |
| 30 | 35 | |
| 31 | 36 | // DLR options: |
| 32 | 37 | private bool _debugMode; |
| 33 | 38 | private bool _privateBinding; |
| 34 | 39 | |
| 35 | 40 | // common language options: |
| 36 | private IDictionary<string, object> _options; | |
| 37 | ||
| 38 | public ScriptRuntimeSetup() | |
| 39 | : this(false) { | |
| 40 | } | |
| 41 | ||
| 42 | #if SIGNED || SILVERLIGHT | |
| 43 | private const string IronPythonAssembly = "IronPython, Version=2.0.0.5000, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; | |
| 44 | private const string JScriptAssembly = "Microsoft.JScript.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; | |
| 45 | private const string IronRubyAssembly = "IronRuby, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; | |
| 46 | private const string VisualBasicAssembly = "Microsoft.VisualBasic.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; | |
| 47 | private const string ToyScriptAssembly = "ToyScript, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; | |
| 48 | #else | |
| 49 | private const string IronPythonAssembly = "IronPython, Version=2.0.0.3000, Culture=neutral, PublicKeyToken=null"; | |
| 50 | private const string JScriptAssembly = "Microsoft.JScript.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; | |
| 51 | private const string IronRubyAssembly = "IronRuby, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; | |
| 52 | private const string VisualBasicAssembly = "Microsoft.VisualBasic.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; | |
| 53 | private const string ToyScriptAssembly = "ToyScript, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; | |
| 54 | #endif | |
| 55 | ||
| 56 | public ScriptRuntimeSetup(bool addWellKnownLanguages) { | |
| 57 | _languageSetups = new Dictionary<AssemblyQualifiedTypeName, LanguageSetup>(); | |
| 58 | ||
| 59 | if (addWellKnownLanguages) { | |
| 60 | AddLanguage("IronPython.Runtime.PythonContext", IronPythonAssembly, | |
| 61 | "IronPython", | |
| 62 | new[] { "py", "python", "ironpython" }, | |
| 63 | new[] { ".py" } | |
| 64 | ); | |
| 65 | ||
| 66 | AddLanguage("Microsoft.JScript.Runtime.JSContext", JScriptAssembly, | |
| 67 | "Managed JScript", | |
| 68 | new[] { "managedjscript", "js", "jscript" }, | |
| 69 | new[] { ".jsx", ".js" } | |
| 70 | ); | |
| 71 | ||
| 72 | AddLanguage("IronRuby.Runtime.RubyContext", IronRubyAssembly, | |
| 73 | "IronRuby", | |
| 74 | new[] { "rb", "ruby", "ironruby" }, | |
| 75 | new[] { ".rb" } | |
| 76 | ); | |
| 77 | ||
| 78 | AddLanguage("Microsoft.VisualBasic.Scripting.Runtime.VisualBasicLanguageContext", VisualBasicAssembly, | |
| 79 | "Visual Basic", | |
| 80 | new[] { "vbx" }, | |
| 81 | new[] { ".vbx" } | |
| 82 | ); | |
| 83 | ||
| 84 | AddLanguage("ToyScript.ToyLanguageContext", ToyScriptAssembly, | |
| 85 | "ToyScript", | |
| 86 | new[] { "ts", "toyscript" }, | |
| 87 | new[] { ".ts" } | |
| 88 | ); | |
| 89 | } | |
| 41 | private Dictionary<string, object> _options; | |
| 90 | 42 | |
| 43 | public ScriptRuntimeSetup() { | |
| 44 | _languageSetups = new List<LanguageSetup>(); | |
| 45 | _options = new Dictionary<string, object>(); | |
| 91 | 46 | _hostType = typeof(ScriptHost); |
| 92 | 47 | _hostArguments = ArrayUtils.EmptyObjects; |
| 93 | 48 | } |
| 94 | 49 | |
| 95 | public Dictionary<AssemblyQualifiedTypeName, LanguageSetup> LanguageSetups { | |
| 50 | /// <summary> | |
| 51 | /// The list of language setup information for languages to load into | |
| 52 | /// the runtime | |
| 53 | /// </summary> | |
| 54 | public IList<LanguageSetup> LanguageSetups { | |
| 96 | 55 | get { return _languageSetups; } |
| 97 | 56 | } |
| 98 | 57 | |
| 58 | /// <summary> | |
| 59 | /// Indicates that the script runtime is in debug mode. | |
| 60 | /// This means: | |
| 61 | /// | |
| 62 | /// 1) Symbols are emitted for debuggable methods (methods associated with SourceUnit). | |
| 63 | /// 2) Debuggable methods are emitted to non-collectable types (this is due to CLR limitations on dynamic method debugging). | |
| 64 | /// 3) JIT optimization is disabled for all methods | |
| 65 | /// 4) Languages may disable optimizations based on this value. | |
| 66 | /// </summary> | |
| 99 | 67 | public bool DebugMode { |
| 100 | 68 | get { return _debugMode; } |
| 101 | 69 | set { _debugMode = value; } |
| 102 | 70 | } |
| 103 | 71 | |
| 72 | /// <summary> | |
| 73 | /// Ignore CLR visibility checks | |
| 74 | /// </summary> | |
| 104 | 75 | public bool PrivateBinding { |
| 105 | 76 | get { return _privateBinding; } |
| 106 | 77 | set { _privateBinding = value; } |
| 107 | 78 | } |
| 108 | 79 | |
| 80 | /// <summary> | |
| 81 | /// Can be any derived class of ScriptHost. When set, it allows the | |
| 82 | /// host to override certain methods to control behavior of the runtime | |
| 83 | /// </summary> | |
| 109 | 84 | public Type HostType { |
| 110 | 85 | get { return _hostType; } |
| 111 | set { _hostType = value; } | |
| 112 | } | |
| 113 | ||
| 114 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] | |
| 115 | public IDictionary<string, object> Options { | |
| 116 | get { | |
| 117 | if (_options == null) { | |
| 118 | _options = new Dictionary<string, object>(); | |
| 119 | } | |
| 120 | return _options; | |
| 121 | } | |
| 122 | 86 | set { |
| 123 | 87 | ContractUtils.RequiresNotNull(value, "value"); |
| 124 | _options = value; | |
| 88 | ContractUtils.Requires(typeof(ScriptHost).IsAssignableFrom(value), "value", "Must be ScriptHost or a derived type of ScriptHost"); | |
| 89 | _hostType = value; | |
| 125 | 90 | } |
| 126 | 91 | } |
| 127 | 92 | |
| 128 | public bool HasOptions { | |
| 129 | get { return _options != null; } | |
| 93 | /// <remarks> | |
| 94 | /// Option names are case-sensitive. | |
| 95 | /// </remarks> | |
| 96 | public Dictionary<string, object> Options { | |
| 97 | get { return _options; } | |
| 130 | 98 | } |
| 131 | 99 | |
| 100 | /// <summary> | |
| 101 | /// Arguments passed to the host type when it is constructed | |
| 102 | /// </summary> | |
| 132 | 103 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] |
| 133 | 104 | public object[] HostArguments { |
| 134 | 105 | get { |
| ... | ...@@ -139,107 +110,60 @@ | |
| 139 | 110 | _hostArguments = value; |
| 140 | 111 | } |
| 141 | 112 | } |
| 142 | ||
| 143 | private void AddLanguage(string typeName, string assemblyName, string displayName, string[] ids, string[] extensions) { | |
| 144 | _languageSetups.Add(new AssemblyQualifiedTypeName(typeName, assemblyName), new LanguageSetup(displayName, ids, extensions)); | |
| 145 | } | |
| 146 | ||
| 147 | public LanguageSetup GetLanguageSetup<TLanguage>() { | |
| 148 | LanguageSetup setup; | |
| 149 | if (!_languageSetups.TryGetValue(new AssemblyQualifiedTypeName(typeof(TLanguage)), out setup)) { | |
| 150 | throw new ArgumentException("Language not registered"); | |
| 151 | } | |
| 152 | return setup; | |
| 153 | } | |
| 154 | 113 | |
| 155 | public bool TryGetLanguageProviderByExtension(string extension, out AssemblyQualifiedTypeName provider) { | |
| 156 | if (!extension.StartsWith(".")) { | |
| 157 | extension = "." + extension; | |
| 158 | } | |
| 159 | ||
| 160 | foreach (var entry in _languageSetups) { | |
| 161 | if (IndexOf(entry.Value.FileExtensions, extension, StringComparer.OrdinalIgnoreCase) != -1) { | |
| 162 | provider = entry.Key; | |
| 163 | return true; | |
| 164 | } | |
| 165 | } | |
| 114 | internal DlrConfiguration ToConfiguration(string paramName) { | |
| 115 | ContractUtils.Requires(_languageSetups.Count > 0, paramName, "ScriptRuntimeSetup must have at least one LanguageSetup"); | |
| 166 | 116 | |
| 167 | provider = default(AssemblyQualifiedTypeName); | |
| 168 | return false; | |
| 169 | } | |
| 117 | var config = new DlrConfiguration(_debugMode, _privateBinding, _options); | |
| 170 | 118 | |
| 171 | public bool TryGetLanguageProviderById(string id, out AssemblyQualifiedTypeName provider) { | |
| 172 | foreach (var entry in _languageSetups) { | |
| 173 | if (IndexOf(entry.Value.Ids, id, StringComparer.OrdinalIgnoreCase) != -1) { | |
| 174 | provider = entry.Key; | |
| 175 | return true; | |
| 176 | } | |
| 119 | foreach (var language in _languageSetups) { | |
| 120 | config.AddLanguage( | |
| 121 | language.TypeName, | |
| 122 | language.DisplayName, | |
| 123 | language.Names, | |
| 124 | language.FileExtensions, | |
| 125 | language.Options | |
| 126 | ); | |
| 177 | 127 | } |
| 178 | provider = default(AssemblyQualifiedTypeName); | |
| 179 | return false; | |
| 180 | } | |
| 181 | 128 | |
| 182 | public AssemblyQualifiedTypeName GetLanguageProviderById(string id) { | |
| 183 | AssemblyQualifiedTypeName provider; | |