mirror of
https://github.com/opensim/opensim.git
synced 2026-08-06 01:06:30 +08:00
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.
This commit is contained in:
@@ -31,6 +31,7 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.CSharp;
|
||||
//using Microsoft.JScript;
|
||||
@@ -72,6 +73,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
private bool CompileWithDebugInformation;
|
||||
private Dictionary<string, bool> AllowedCompilers = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
|
||||
private Dictionary<string, enumCompileType> LanguageMapping = new Dictionary<string, enumCompileType>(StringComparer.CurrentCultureIgnoreCase);
|
||||
private bool m_insertCoopTerminationCalls;
|
||||
|
||||
private string FilePrefix;
|
||||
private string ScriptEnginesPath = null;
|
||||
@@ -95,20 +97,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
private Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>> m_lineMaps =
|
||||
new Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>>();
|
||||
|
||||
public bool in_startup = true;
|
||||
|
||||
public Compiler(IScriptEngine scriptEngine)
|
||||
{
|
||||
m_scriptEngine = scriptEngine;;
|
||||
m_scriptEngine = scriptEngine;
|
||||
ScriptEnginesPath = scriptEngine.ScriptEnginePath;
|
||||
ReadConfig();
|
||||
}
|
||||
|
||||
public bool in_startup = true;
|
||||
public void ReadConfig()
|
||||
{
|
||||
// Get some config
|
||||
WriteScriptSourceToDebugFile = m_scriptEngine.Config.GetBoolean("WriteScriptSourceToDebugFile", false);
|
||||
CompileWithDebugInformation = m_scriptEngine.Config.GetBoolean("CompileWithDebugInformation", true);
|
||||
bool DeleteScriptsOnStartup = m_scriptEngine.Config.GetBoolean("DeleteScriptsOnStartup", true);
|
||||
m_insertCoopTerminationCalls = m_scriptEngine.Config.GetString("ScriptStopStrategy", "abort") == "co-op";
|
||||
|
||||
// Get file prefix from scriptengine name and make it file system safe:
|
||||
FilePrefix = "CommonCompiler";
|
||||
@@ -386,7 +390,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
if (language == enumCompileType.lsl)
|
||||
{
|
||||
// Its LSL, convert it to C#
|
||||
LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms);
|
||||
LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms, m_insertCoopTerminationCalls);
|
||||
compileScript = LSL_Converter.Convert(Script);
|
||||
|
||||
// copy converter warnings into our warnings.
|
||||
@@ -411,16 +415,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
{
|
||||
case enumCompileType.cs:
|
||||
case enumCompileType.lsl:
|
||||
compileScript = CreateCSCompilerScript(compileScript);
|
||||
compileScript = CreateCSCompilerScript(
|
||||
compileScript, m_scriptEngine.ScriptBaseClassName, m_scriptEngine.ScriptBaseClassParameters);
|
||||
break;
|
||||
case enumCompileType.vb:
|
||||
compileScript = CreateVBCompilerScript(compileScript);
|
||||
compileScript = CreateVBCompilerScript(compileScript, m_scriptEngine.ScriptBaseClassName);
|
||||
break;
|
||||
// case enumCompileType.js:
|
||||
// compileScript = CreateJSCompilerScript(compileScript);
|
||||
// compileScript = CreateJSCompilerScript(compileScript, m_scriptEngine.ScriptBaseClassName);
|
||||
// break;
|
||||
case enumCompileType.yp:
|
||||
compileScript = CreateYPCompilerScript(compileScript);
|
||||
compileScript = CreateYPCompilerScript(compileScript, m_scriptEngine.ScriptBaseClassName);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -451,43 +456,59 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
// return compileScript;
|
||||
// }
|
||||
|
||||
private static string CreateCSCompilerScript(string compileScript)
|
||||
private static string CreateCSCompilerScript(
|
||||
string compileScript, string baseClassName, ParameterInfo[] constructorParameters)
|
||||
{
|
||||
compileScript = String.Empty +
|
||||
"using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" +
|
||||
String.Empty + "namespace SecondLife { " +
|
||||
String.Empty + "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" +
|
||||
@"public Script() { } " +
|
||||
compileScript +
|
||||
"} }\r\n";
|
||||
compileScript = string.Format(
|
||||
@"using OpenSim.Region.ScriptEngine.Shared;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SecondLife
|
||||
{{
|
||||
public class Script : {0}
|
||||
{{
|
||||
public Script({1}) : base({2}) {{}}
|
||||
{3}
|
||||
}}
|
||||
}}",
|
||||
baseClassName,
|
||||
constructorParameters != null
|
||||
? string.Join(", ", Array.ConvertAll<ParameterInfo, string>(constructorParameters, pi => pi.ToString()))
|
||||
: "",
|
||||
constructorParameters != null
|
||||
? string.Join(", ", Array.ConvertAll<ParameterInfo, string>(constructorParameters, pi => pi.Name))
|
||||
: "",
|
||||
compileScript);
|
||||
|
||||
return compileScript;
|
||||
}
|
||||
|
||||
private static string CreateYPCompilerScript(string compileScript)
|
||||
private static string CreateYPCompilerScript(string compileScript, string baseClassName)
|
||||
{
|
||||
compileScript = String.Empty +
|
||||
"using OpenSim.Region.ScriptEngine.Shared.YieldProlog; " +
|
||||
"using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" +
|
||||
String.Empty + "namespace SecondLife { " +
|
||||
String.Empty + "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" +
|
||||
String.Empty + "public class Script : " + baseClassName + " { \r\n" +
|
||||
//@"public Script() { } " +
|
||||
@"static OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP YP=null; " +
|
||||
@"public Script() { YP= new OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP(); } " +
|
||||
|
||||
compileScript +
|
||||
"} }\r\n";
|
||||
|
||||
return compileScript;
|
||||
}
|
||||
|
||||
private static string CreateVBCompilerScript(string compileScript)
|
||||
private static string CreateVBCompilerScript(string compileScript, string baseClassName)
|
||||
{
|
||||
compileScript = String.Empty +
|
||||
"Imports OpenSim.Region.ScriptEngine.Shared: Imports System.Collections.Generic: " +
|
||||
String.Empty + "NameSpace SecondLife:" +
|
||||
String.Empty + "Public Class Script: Inherits OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass: " +
|
||||
String.Empty + "Public Class Script: Inherits " + baseClassName +
|
||||
"\r\nPublic Sub New()\r\nEnd Sub: " +
|
||||
compileScript +
|
||||
":End Class :End Namespace\r\n";
|
||||
|
||||
return compileScript;
|
||||
}
|
||||
|
||||
@@ -549,6 +570,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
|
||||
"OpenMetaverseTypes.dll"));
|
||||
|
||||
if (m_scriptEngine.ScriptReferencedAssemblies != null)
|
||||
Array.ForEach<string>(
|
||||
m_scriptEngine.ScriptReferencedAssemblies,
|
||||
a => parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, a)));
|
||||
|
||||
if (lang == enumCompileType.yp)
|
||||
{
|
||||
parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
|
||||
|
||||
Reference in New Issue
Block a user