From d85774c101f5509672fc8d791fa3c923fc2071c9 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sat, 12 Jul 2008 01:34:36 +0000 Subject: 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 +- 4 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs (limited to 'OpenSim/Region/ScriptEngine/Shared') diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs index 82c7eda..7d7384e 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 124f1e6..09d816f 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 0000000..a57530c --- /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 380686e..7e9789f 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. -- cgit v1.1