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.
0.6.0-stable
Melanie Thielker 2008-07-12 01:34:36 +00:00
parent f6c7f167b9
commit d85774c101
6 changed files with 128 additions and 82 deletions

View File

@ -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.
/// </summary>
/// <param name="script">String containing LSL source.</param>
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();
}
/// <summary>
@ -63,8 +59,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
/// Generate the code from the AST we have.
/// </summary>
/// <returns>String containing the generated C# code.</returns>
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

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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.

View File

@ -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)
{

View File

@ -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