aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs14
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs12
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs37
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSConverter.cs2
4 files changed, 53 insertions, 12 deletions
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;
32 32
33namespace OpenSim.Region.ScriptEngine.Shared.CodeTools 33namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
34{ 34{
35 public class CSCodeGenerator 35 public class CSCodeGenerator : ICodeConverter
36 { 36 {
37 private SYMBOL m_astRoot = null; 37 private SYMBOL m_astRoot = null;
38 private int m_braceCount; // for indentation 38 private int m_braceCount; // for indentation
@@ -41,12 +41,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
41 /// Pass the new CodeGenerator a string containing the LSL source. 41 /// Pass the new CodeGenerator a string containing the LSL source.
42 /// </summary> 42 /// </summary>
43 /// <param name="script">String containing LSL source.</param> 43 /// <param name="script">String containing LSL source.</param>
44 public CSCodeGenerator(string script) 44 public CSCodeGenerator()
45 { 45 {
46 Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true));
47 // Obviously this needs to be in a try/except block.
48 LSL2CSCodeTransformer codeTransformer = new LSL2CSCodeTransformer(p.Parse(script));
49 m_astRoot = codeTransformer.Transform();
50 } 46 }
51 47
52 /// <summary> 48 /// <summary>
@@ -63,8 +59,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
63 /// Generate the code from the AST we have. 59 /// Generate the code from the AST we have.
64 /// </summary> 60 /// </summary>
65 /// <returns>String containing the generated C# code.</returns> 61 /// <returns>String containing the generated C# code.</returns>
66 public string Generate() 62 public string Convert(string script)
67 { 63 {
64 Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true));
65 // Obviously this needs to be in a try/except block.
66 LSL2CSCodeTransformer codeTransformer = new LSL2CSCodeTransformer(p.Parse(script));
67 m_astRoot = codeTransformer.Transform();
68 string retstr = String.Empty; 68 string retstr = String.Empty;
69 69
70 // standard preamble 70 // 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
72 private string FilePrefix; 72 private string FilePrefix;
73 private string ScriptEnginesPath = "ScriptEngines"; 73 private string ScriptEnginesPath = "ScriptEngines";
74 74
75 private static LSL2CSConverter LSL_Converter = new LSL2CSConverter(); 75 private static ICodeConverter LSL_Converter;
76 //private static CSCodeGenerator LSL_Converter;
77 private static CSharpCodeProvider CScodeProvider = new CSharpCodeProvider(); 76 private static CSharpCodeProvider CScodeProvider = new CSharpCodeProvider();
78 private static VBCodeProvider VBcodeProvider = new VBCodeProvider(); 77 private static VBCodeProvider VBcodeProvider = new VBCodeProvider();
79 private static JScriptCodeProvider JScodeProvider = new JScriptCodeProvider(); 78 private static JScriptCodeProvider JScodeProvider = new JScriptCodeProvider();
@@ -82,6 +81,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
82 81
83 // private static int instanceID = new Random().Next(0, int.MaxValue); // Unique number to use on our compiled files 82 // private static int instanceID = new Random().Next(0, int.MaxValue); // Unique number to use on our compiled files
84 private static UInt64 scriptCompileCounter = 0; // And a counter 83 private static UInt64 scriptCompileCounter = 0; // And a counter
84 private bool m_UseCompiler = false;
85 85
86 public IScriptEngine m_scriptEngine; 86 public IScriptEngine m_scriptEngine;
87 public Compiler(IScriptEngine scriptEngine) 87 public Compiler(IScriptEngine scriptEngine)
@@ -94,6 +94,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
94 { 94 {
95 95
96 // Get some config 96 // Get some config
97 m_UseCompiler = m_scriptEngine.Config.GetBoolean("UseNewCompiler", true);
97 WriteScriptSourceToDebugFile = m_scriptEngine.Config.GetBoolean("WriteScriptSourceToDebugFile", true); 98 WriteScriptSourceToDebugFile = m_scriptEngine.Config.GetBoolean("WriteScriptSourceToDebugFile", true);
98 CompileWithDebugInformation = m_scriptEngine.Config.GetBoolean("CompileWithDebugInformation", true); 99 CompileWithDebugInformation = m_scriptEngine.Config.GetBoolean("CompileWithDebugInformation", true);
99 100
@@ -324,9 +325,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
324 if (l == enumCompileType.lsl) 325 if (l == enumCompileType.lsl)
325 { 326 {
326 // Its LSL, convert it to C# 327 // Its LSL, convert it to C#
328 //compileScript = LSL_Converter.Convert(Script);
329 if(m_UseCompiler)
330 LSL_Converter = (ICodeConverter)new CSCodeGenerator();
331 else
332 LSL_Converter = (ICodeConverter)new LSL2CSConverter();
327 compileScript = LSL_Converter.Convert(Script); 333 compileScript = LSL_Converter.Convert(Script);
328 //LSL_Converter = new CSCodeGenerator(Script);
329 //compileScript = LSL_Converter.Generate();
330 l = enumCompileType.cs; 334 l = enumCompileType.cs;
331 } 335 }
332 336
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 @@
1/*
2* Copyright (c) Contributors, http://opensimulator.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28
29using System;
30
31namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
32{
33 public interface ICodeConverter
34 {
35 string Convert(string script);
36 }
37}
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;
32 32
33namespace OpenSim.Region.ScriptEngine.Shared.CodeTools 33namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
34{ 34{
35 public class LSL2CSConverter 35 public class LSL2CSConverter : ICodeConverter
36 { 36 {
37 // Uses regex to convert LSL code to C# code. 37 // Uses regex to convert LSL code to C# code.
38 38