public
Description: Dynamic languages in Silverlight
Homepage: http://sdlsdk.codeplex.com
Clone URL: git://github.com/jschementi/agdlr.git
Repl and Python demo
jschementi (author)
Sun Nov 16 11:06:55 -0800 2008
commit  f7e4b6a22974209600b6b95a8126bf63db0cdcf6
tree    ef941a4e2701dd920972f3ff642a54dd152495e8
parent  08b3919d03b2c53c892c18ba4c38bb19e30aaa38
...
18
19
20
21
 
22
23
24
...
18
19
20
 
21
22
23
24
0
@@ -18,7 +18,7 @@
0
 #silverlightDlrConsole {
0
   padding: 15px;
0
   background-color: black;
0
-  height: 250px;
0
+  height: 300px;
0
   overflow: auto;
0
 }
0
 
...
34
35
36
 
37
38
39
...
54
55
56
 
57
58
59
...
135
136
137
138
 
139
140
141
...
160
161
162
163
 
164
165
166
...
171
172
173
174
 
175
176
177
...
195
196
197
198
 
199
200
201
...
239
240
241
242
 
 
 
 
 
243
244
245
...
34
35
36
37
38
39
40
...
55
56
57
58
59
60
61
...
137
138
139
 
140
141
142
143
...
162
163
164
 
165
166
167
168
...
173
174
175
 
176
177
178
179
...
197
198
199
 
200
201
202
203
...
241
242
243
 
244
245
246
247
248
249
250
251
0
@@ -34,6 +34,7 @@ namespace Microsoft.Scripting.Silverlight {
0
         private HtmlElement      _silverlightDlrConsoleCode;
0
         private HtmlElement      _silverlightDlrConsoleResult;
0
         private HtmlElement      _silverlightDlrConsolePrompt;
0
+        private ScriptEngine     _engine;
0
         #endregion
0
 
0
         #region Console management
0
@@ -54,6 +55,7 @@ namespace Microsoft.Scripting.Silverlight {
0
             _silverlightDlrConsoleCode   = HtmlPage.Document.GetElementById(_sdlrCode);
0
             _silverlightDlrConsoleResult = HtmlPage.Document.GetElementById(_sdlrResult);
0
             _silverlightDlrConsolePrompt = HtmlPage.Document.GetElementById(_sdlrPrompt);
0
+            _engine = DynamicApplication.Current.Engine;
0
         }
0
 
0
         void Start() {
0
@@ -135,7 +137,7 @@ namespace Microsoft.Scripting.Silverlight {
0
 
0
         #region Running Code
0
         string TryExpression(string text) {
0
-            var props = DynamicApplication.Current.Engine.CreateScriptSourceFromString(
0
+            var props = _engine.CreateScriptSourceFromString(
0
                 text, SourceCodeKind.Expression
0
             ).GetCodeProperties();
0
             string result;
0
@@ -160,7 +162,7 @@ namespace Microsoft.Scripting.Silverlight {
0
         object DoSingleLine(bool forceExecute) {
0
             var valid = TryExpression(_code);
0
             if (valid != null) {
0
-                var source = DynamicApplication.Current.Engine.CreateScriptSourceFromString(_code, SourceCodeKind.Expression);
0
+                var source = _engine.CreateScriptSourceFromString(_code, SourceCodeKind.Expression);
0
                 return ExecuteCode(source);
0
             } else {
0
                 DoMultiLine(forceExecute);
0
@@ -171,7 +173,7 @@ namespace Microsoft.Scripting.Silverlight {
0
         object DoMultiLine(bool forceExecute) {
0
             if (forceExecute || IsComplete(_code, false)) {
0
                 _multiLineComplete = true;
0
-                var source = DynamicApplication.Current.Engine.CreateScriptSourceFromString(_code, SourceCodeKind.InteractiveCode);
0
+                var source = _engine.CreateScriptSourceFromString(_code, SourceCodeKind.InteractiveCode);
0
                 return ExecuteCode(source);
0
             } else {
0
                 _multiLine = true;
0
@@ -195,7 +197,7 @@ namespace Microsoft.Scripting.Silverlight {
0
         }
0
 
0
         bool IsComplete(string text, bool allowIncomplete) {
0
-            var props = DynamicApplication.Current.Engine.CreateScriptSourceFromString(
0
+            var props = _engine.CreateScriptSourceFromString(
0
                 text, SourceCodeKind.InteractiveCode
0
             ).GetCodeProperties();
0
             var result = (props != ScriptCodeParseResult.Invalid) &&
0
@@ -239,7 +241,11 @@ namespace Microsoft.Scripting.Silverlight {
0
 
0
         void ShowValueInResultDiv(object result) {
0
             var resultDiv = HtmlPage.Document.CreateElement("div");
0
-            resultDiv.SetProperty("innerHTML", result != null ? result.ToString() : "nil");
0
+            ScriptScope scope = _engine.CreateScope();
0
+            scope.SetVariable("sdlr_result", result);
0
+            result = _engine.CreateScriptSourceFromString("sdlr_result.inspect").Execute(scope);
0
+            var resultStr = result.ToString();
0
+            resultDiv.SetProperty("innerHTML", result != null ? resultStr : "nil");
0
             _silverlightDlrConsoleResult.AppendChild(resultDiv);
0
         }
0
   
...
194
195
196
 
 
 
 
 
 
 
 
 
197
198
199
...
219
220
221
222
223
224
225
226
227
 
228
229
230
231
232
233
 
 
234
235
236
237
238
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
...
228
229
230
 
 
 
 
 
 
231
232
233
234
235
 
 
236
237
238
 
239
240
241
0
@@ -194,6 +194,15 @@ namespace Microsoft.Scripting.Silverlight {
0
             return new Uri(baseUri + relativeUri, UriKind.Relative);
0
         }
0
 
0
+        public static ScriptRuntimeSetup CreateRuntimeSetup() {
0
+            ScriptRuntimeSetup setup = Configuration.TryParseFile();
0
+            if (setup == null) {
0
+                setup = Configuration.LoadFromAssemblies(Package.GetManifestAssemblies());
0
+            }
0
+            setup.HostType = typeof(BrowserScriptHost);
0
+            return setup;
0
+        }
0
+
0
         #endregion
0
 
0
         #region implementation
0
@@ -219,20 +228,14 @@ namespace Microsoft.Scripting.Silverlight {
0
 
0
             ParseArguments(e.InitParams);
0
             
0
-            ScriptRuntimeSetup setup = Configuration.TryParseFile();
0
-            if (setup == null) {
0
-                setup = Configuration.LoadFromAssemblies(Package.GetManifestAssemblies());
0
-            }
0
-
0
-            InitializeDLR(setup);
0
+            InitializeDLR();
0
 
0
             StartMainProgram();
0
         }
0
 
0
-        private void InitializeDLR(ScriptRuntimeSetup setup) {
0
-            setup.HostType = typeof(BrowserScriptHost);
0
+        private void InitializeDLR() {
0
+            var setup = CreateRuntimeSetup();
0
             setup.DebugMode = _debug;
0
-
0
             setup.Options["SearchPaths"] = new string[] { String.Empty };
0
             
0
             _runtimeSetup = setup;

Comments