aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2013-01-17 23:39:09 +0000
committerJustin Clark-Casey (justincc)2013-01-17 23:39:09 +0000
commitc8afc8523b9caf931afb3d5b3f9874b26b866a77 (patch)
treeb1a84d82591f462ae61b3aeed4f4b6dd3c5c06e8 /OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
parentMerge branch 'master' of melanie@opensimulator.org:/var/git/opensim (diff)
downloadopensim-SC_OLD-c8afc8523b9caf931afb3d5b3f9874b26b866a77.zip
opensim-SC_OLD-c8afc8523b9caf931afb3d5b3f9874b26b866a77.tar.gz
opensim-SC_OLD-c8afc8523b9caf931afb3d5b3f9874b26b866a77.tar.bz2
opensim-SC_OLD-c8afc8523b9caf931afb3d5b3f9874b26b866a77.tar.xz
Implement non-wait co-operative termination of scripts for XEngine in addition to termination on wait.
This involves inserting opensim_reserved_CheckForCoopTermination() calls in lsl -> c# translation at any place where the script could be in a loop with no wait calls. These places are for, while, do-while, label, user function call and manual event function call. Call goes through to an XEngineScriptBase which extends ScriptBase. IEngine is extended to supply necessary engine-specific parent class references and constructor parameters to Compiler. Unfortunately, since XEngineScriptBase has to be passed WaitHandle in its constructor, older compiled scripts will fail to load with an error on the OpenSim console. Such scripts will need to be recompiled, either by removing all *.dll files from the bin/ScriptEngines/<region-id> or by setting DeleteScriptsOnStartup = true in [XEngine] for one run. Automatic recompilation may be implemented in a later commit. This feature should not yet be used, default remains termination with Thread.Abort() which will work as normal once scripts are recompiled.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs66
1 files changed, 46 insertions, 20 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
index 03be2ab..7432202 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
@@ -31,6 +31,7 @@ using System.Collections.Generic;
31using System.Globalization; 31using System.Globalization;
32using System.Reflection; 32using System.Reflection;
33using System.IO; 33using System.IO;
34using System.Linq;
34using System.Text; 35using System.Text;
35using Microsoft.CSharp; 36using Microsoft.CSharp;
36//using Microsoft.JScript; 37//using Microsoft.JScript;
@@ -72,6 +73,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
72 private bool CompileWithDebugInformation; 73 private bool CompileWithDebugInformation;
73 private Dictionary<string, bool> AllowedCompilers = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase); 74 private Dictionary<string, bool> AllowedCompilers = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
74 private Dictionary<string, enumCompileType> LanguageMapping = new Dictionary<string, enumCompileType>(StringComparer.CurrentCultureIgnoreCase); 75 private Dictionary<string, enumCompileType> LanguageMapping = new Dictionary<string, enumCompileType>(StringComparer.CurrentCultureIgnoreCase);
76 private bool m_insertCoopTerminationCalls;
75 77
76 private string FilePrefix; 78 private string FilePrefix;
77 private string ScriptEnginesPath = null; 79 private string ScriptEnginesPath = null;
@@ -95,20 +97,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
95 private Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>> m_lineMaps = 97 private Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>> m_lineMaps =
96 new Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>>(); 98 new Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>>();
97 99
100 public bool in_startup = true;
101
98 public Compiler(IScriptEngine scriptEngine) 102 public Compiler(IScriptEngine scriptEngine)
99 { 103 {
100 m_scriptEngine = scriptEngine;; 104 m_scriptEngine = scriptEngine;
101 ScriptEnginesPath = scriptEngine.ScriptEnginePath; 105 ScriptEnginesPath = scriptEngine.ScriptEnginePath;
102 ReadConfig(); 106 ReadConfig();
103 } 107 }
104 108
105 public bool in_startup = true;
106 public void ReadConfig() 109 public void ReadConfig()
107 { 110 {
108 // Get some config 111 // Get some config
109 WriteScriptSourceToDebugFile = m_scriptEngine.Config.GetBoolean("WriteScriptSourceToDebugFile", false); 112 WriteScriptSourceToDebugFile = m_scriptEngine.Config.GetBoolean("WriteScriptSourceToDebugFile", false);
110 CompileWithDebugInformation = m_scriptEngine.Config.GetBoolean("CompileWithDebugInformation", true); 113 CompileWithDebugInformation = m_scriptEngine.Config.GetBoolean("CompileWithDebugInformation", true);
111 bool DeleteScriptsOnStartup = m_scriptEngine.Config.GetBoolean("DeleteScriptsOnStartup", true); 114 bool DeleteScriptsOnStartup = m_scriptEngine.Config.GetBoolean("DeleteScriptsOnStartup", true);
115 m_insertCoopTerminationCalls = m_scriptEngine.Config.GetString("ScriptStopStrategy", "abort") == "co-op";
112 116
113 // Get file prefix from scriptengine name and make it file system safe: 117 // Get file prefix from scriptengine name and make it file system safe:
114 FilePrefix = "CommonCompiler"; 118 FilePrefix = "CommonCompiler";
@@ -386,7 +390,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
386 if (language == enumCompileType.lsl) 390 if (language == enumCompileType.lsl)
387 { 391 {
388 // Its LSL, convert it to C# 392 // Its LSL, convert it to C#
389 LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms); 393 LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms, m_insertCoopTerminationCalls);
390 compileScript = LSL_Converter.Convert(Script); 394 compileScript = LSL_Converter.Convert(Script);
391 395
392 // copy converter warnings into our warnings. 396 // copy converter warnings into our warnings.
@@ -411,16 +415,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
411 { 415 {
412 case enumCompileType.cs: 416 case enumCompileType.cs:
413 case enumCompileType.lsl: 417 case enumCompileType.lsl:
414 compileScript = CreateCSCompilerScript(compileScript); 418 compileScript = CreateCSCompilerScript(
419 compileScript, m_scriptEngine.ScriptBaseClassName, m_scriptEngine.ScriptBaseClassParameters);
415 break; 420 break;
416 case enumCompileType.vb: 421 case enumCompileType.vb:
417 compileScript = CreateVBCompilerScript(compileScript); 422 compileScript = CreateVBCompilerScript(compileScript, m_scriptEngine.ScriptBaseClassName);
418 break; 423 break;
419// case enumCompileType.js: 424// case enumCompileType.js:
420// compileScript = CreateJSCompilerScript(compileScript); 425// compileScript = CreateJSCompilerScript(compileScript, m_scriptEngine.ScriptBaseClassName);
421// break; 426// break;
422 case enumCompileType.yp: 427 case enumCompileType.yp:
423 compileScript = CreateYPCompilerScript(compileScript); 428 compileScript = CreateYPCompilerScript(compileScript, m_scriptEngine.ScriptBaseClassName);
424 break; 429 break;
425 } 430 }
426 431
@@ -451,43 +456,59 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
451// return compileScript; 456// return compileScript;
452// } 457// }
453 458
454 private static string CreateCSCompilerScript(string compileScript) 459 private static string CreateCSCompilerScript(
460 string compileScript, string baseClassName, ParameterInfo[] constructorParameters)
455 { 461 {
456 compileScript = String.Empty + 462 compileScript = string.Format(
457 "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" + 463@"using OpenSim.Region.ScriptEngine.Shared;
458 String.Empty + "namespace SecondLife { " + 464using System.Collections.Generic;
459 String.Empty + "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" + 465
460 @"public Script() { } " + 466namespace SecondLife
461 compileScript + 467{{
462 "} }\r\n"; 468 public class Script : {0}
469 {{
470 public Script({1}) : base({2}) {{}}
471{3}
472 }}
473}}",
474 baseClassName,
475 constructorParameters != null
476 ? string.Join(", ", Array.ConvertAll<ParameterInfo, string>(constructorParameters, pi => pi.ToString()))
477 : "",
478 constructorParameters != null
479 ? string.Join(", ", Array.ConvertAll<ParameterInfo, string>(constructorParameters, pi => pi.Name))
480 : "",
481 compileScript);
482
463 return compileScript; 483 return compileScript;
464 } 484 }
465 485
466 private static string CreateYPCompilerScript(string compileScript) 486 private static string CreateYPCompilerScript(string compileScript, string baseClassName)
467 { 487 {
468 compileScript = String.Empty + 488 compileScript = String.Empty +
469 "using OpenSim.Region.ScriptEngine.Shared.YieldProlog; " + 489 "using OpenSim.Region.ScriptEngine.Shared.YieldProlog; " +
470 "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" + 490 "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" +
471 String.Empty + "namespace SecondLife { " + 491 String.Empty + "namespace SecondLife { " +
472 String.Empty + "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" + 492 String.Empty + "public class Script : " + baseClassName + " { \r\n" +
473 //@"public Script() { } " + 493 //@"public Script() { } " +
474 @"static OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP YP=null; " + 494 @"static OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP YP=null; " +
475 @"public Script() { YP= new OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP(); } " + 495 @"public Script() { YP= new OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP(); } " +
476
477 compileScript + 496 compileScript +
478 "} }\r\n"; 497 "} }\r\n";
498
479 return compileScript; 499 return compileScript;
480 } 500 }
481 501
482 private static string CreateVBCompilerScript(string compileScript) 502 private static string CreateVBCompilerScript(string compileScript, string baseClassName)
483 { 503 {
484 compileScript = String.Empty + 504 compileScript = String.Empty +
485 "Imports OpenSim.Region.ScriptEngine.Shared: Imports System.Collections.Generic: " + 505 "Imports OpenSim.Region.ScriptEngine.Shared: Imports System.Collections.Generic: " +
486 String.Empty + "NameSpace SecondLife:" + 506 String.Empty + "NameSpace SecondLife:" +
487 String.Empty + "Public Class Script: Inherits OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass: " + 507 String.Empty + "Public Class Script: Inherits " + baseClassName +
488 "\r\nPublic Sub New()\r\nEnd Sub: " + 508 "\r\nPublic Sub New()\r\nEnd Sub: " +
489 compileScript + 509 compileScript +
490 ":End Class :End Namespace\r\n"; 510 ":End Class :End Namespace\r\n";
511
491 return compileScript; 512 return compileScript;
492 } 513 }
493 514
@@ -549,6 +570,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
549 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, 570 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
550 "OpenMetaverseTypes.dll")); 571 "OpenMetaverseTypes.dll"));
551 572
573 if (m_scriptEngine.ScriptReferencedAssemblies != null)
574 Array.ForEach<string>(
575 m_scriptEngine.ScriptReferencedAssemblies,
576 a => parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, a)));
577
552 if (lang == enumCompileType.yp) 578 if (lang == enumCompileType.yp)
553 { 579 {
554 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, 580 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,