From d85774c101f5509672fc8d791fa3c923fc2071c9 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sat, 12 Jul 2008 01:34:36 +0000 Subject: [PATCH] Patch #9142 (No mantis) Add a config option to OpenSim.ini to select between script compilers in the XEngine without recompile. Set UseNewCompiler=true in OpenSim.ini and try it out. Creates the ICodeConverter interface and adapts the new compiler to it. --- .../Shared/CodeTools/CSCodeGenerator.cs | 14 +- .../ScriptEngine/Shared/CodeTools/Compiler.cs | 12 +- .../Shared/CodeTools/ICodeConverter.cs | 37 +++++ .../Shared/CodeTools/LSL2CSConverter.cs | 2 +- .../Shared/CodeTools/LSLCompilerTest.cs | 136 +++++++++--------- bin/OpenSim.ini.example | 9 +- 6 files changed, 128 insertions(+), 82 deletions(-) create mode 100644 OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs index 82c7edaaf5..7d7384e9e3 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs @@ -32,7 +32,7 @@ using Tools; namespace OpenSim.Region.ScriptEngine.Shared.CodeTools { - public class CSCodeGenerator + public class CSCodeGenerator : ICodeConverter { private SYMBOL m_astRoot = null; private int m_braceCount; // for indentation @@ -41,12 +41,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools /// Pass the new CodeGenerator a string containing the LSL source. /// /// String containing LSL source. - public CSCodeGenerator(string script) + public CSCodeGenerator() { - Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true)); - // Obviously this needs to be in a try/except block. - LSL2CSCodeTransformer codeTransformer = new LSL2CSCodeTransformer(p.Parse(script)); - m_astRoot = codeTransformer.Transform(); } /// @@ -63,8 +59,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools /// Generate the code from the AST we have. /// /// String containing the generated C# code. - public string Generate() + public string Convert(string script) { + Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true)); + // Obviously this needs to be in a try/except block. + LSL2CSCodeTransformer codeTransformer = new LSL2CSCodeTransformer(p.Parse(script)); + m_astRoot = codeTransformer.Transform(); string retstr = String.Empty; // standard preamble diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs index 124f1e69d7..09d816f169 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs @@ -72,8 +72,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools private string FilePrefix; private string ScriptEnginesPath = "ScriptEngines"; - private static LSL2CSConverter LSL_Converter = new LSL2CSConverter(); - //private static CSCodeGenerator LSL_Converter; + private static ICodeConverter LSL_Converter; private static CSharpCodeProvider CScodeProvider = new CSharpCodeProvider(); private static VBCodeProvider VBcodeProvider = new VBCodeProvider(); private static JScriptCodeProvider JScodeProvider = new JScriptCodeProvider(); @@ -82,6 +81,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools // private static int instanceID = new Random().Next(0, int.MaxValue); // Unique number to use on our compiled files private static UInt64 scriptCompileCounter = 0; // And a counter + private bool m_UseCompiler = false; public IScriptEngine m_scriptEngine; public Compiler(IScriptEngine scriptEngine) @@ -94,6 +94,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools { // Get some config + m_UseCompiler = m_scriptEngine.Config.GetBoolean("UseNewCompiler", true); WriteScriptSourceToDebugFile = m_scriptEngine.Config.GetBoolean("WriteScriptSourceToDebugFile", true); CompileWithDebugInformation = m_scriptEngine.Config.GetBoolean("CompileWithDebugInformation", true); @@ -324,9 +325,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools if (l == enumCompileType.lsl) { // Its LSL, convert it to C# + //compileScript = LSL_Converter.Convert(Script); + if(m_UseCompiler) + LSL_Converter = (ICodeConverter)new CSCodeGenerator(); + else + LSL_Converter = (ICodeConverter)new LSL2CSConverter(); compileScript = LSL_Converter.Convert(Script); - //LSL_Converter = new CSCodeGenerator(Script); - //compileScript = LSL_Converter.Generate(); l = enumCompileType.cs; } diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs new file mode 100644 index 0000000000..a57530c803 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs @@ -0,0 +1,37 @@ +/* +* Copyright (c) Contributors, http://opensimulator.org/ +* See CONTRIBUTORS.TXT for a full list of copyright holders. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the OpenSim Project nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +using System; + +namespace OpenSim.Region.ScriptEngine.Shared.CodeTools +{ + public interface ICodeConverter + { + string Convert(string script); + } +} diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSConverter.cs index 380686e305..7e9789fadd 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSConverter.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSConverter.cs @@ -32,7 +32,7 @@ using System.Text.RegularExpressions; namespace OpenSim.Region.ScriptEngine.Shared.CodeTools { - public class LSL2CSConverter + public class LSL2CSConverter : ICodeConverter { // Uses regex to convert LSL code to C# code. diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSLCompilerTest.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSLCompilerTest.cs index 3413d0d4bb..890a6343b5 100644 --- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSLCompilerTest.cs +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSLCompilerTest.cs @@ -56,8 +56,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -87,8 +87,8 @@ state another_state } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -108,8 +108,8 @@ state another_state } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -131,8 +131,8 @@ state another_state } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -158,8 +158,8 @@ state another_state } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -187,8 +187,8 @@ state another_state } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -214,8 +214,8 @@ state another_state } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -253,8 +253,8 @@ state another_state } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -306,8 +306,8 @@ state another_state } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -329,8 +329,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -368,8 +368,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -413,8 +413,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -469,8 +469,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -524,8 +524,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -552,8 +552,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -579,8 +579,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -608,8 +608,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -639,8 +639,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -668,8 +668,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -773,8 +773,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -880,8 +880,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -921,8 +921,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -966,8 +966,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -1011,8 +1011,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -1064,8 +1064,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -1101,8 +1101,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -1147,8 +1147,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -1188,8 +1188,8 @@ state statetwo } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -1221,8 +1221,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -1252,8 +1252,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -1296,8 +1296,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -1329,8 +1329,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -1354,8 +1354,8 @@ default } "; - CSCodeGenerator cg = new CSCodeGenerator(input); - string output = cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); Assert.AreEqual(expected, output); } @@ -1373,8 +1373,8 @@ default "; try { - CSCodeGenerator cg = new CSCodeGenerator(input); - cg.Generate(); + CSCodeGenerator cg = new CSCodeGenerator(); + cg.Convert(input); } catch (Tools.CSToolsException e) { diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index c24d030137..491e7dd030 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -111,10 +111,13 @@ physical_prim = true ;script_engine = OpenSim.Region.ScriptEngine.DotNetEngine.dll,OpenSim.Region.ScriptEngine.RemoteServer.dll ; ; This is the current and most stable ScriptEngine: -script_engine = OpenSim.Region.ScriptEngine.DotNetEngine.dll +script_engine = "OpenSim.Region.ScriptEngine.DotNetEngine.dll" + +; This is the new XEngine (experimental) +;script_engine = "OpenSim.Region.ScriptEngine.XEngine.dll" ;Experimental remote ScriptServer plugin (does not currently work): -;script_engine = OpenSim.Region.ScriptEngine.RemoteServer.dll +;script_engine = "OpenSim.Region.ScriptEngine.RemoteServer.dll" [StandAlone] @@ -596,6 +599,8 @@ AutoSavePeriod = 15 ; Number of minutes between autosave backups [XEngine] +; Use the newer LSL to CS compiler (experimental) +UseNewCompiler = false ; How many threads to keep alive even if nothing is happening MinThreads = 2 ; How many threads to start at maximum load