mirror of
https://github.com/opensim/opensim.git
synced 2026-08-01 22:26:09 +08:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user