From ed1208d04378b2ef9928ed270c99f4f99f3a30d5 Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Sun, 12 Aug 2007 19:04:07 +0000 Subject: ScriptEngine successfully compiles script, we are now even further than LSO was. Also added C# script support. --- .../DotNetEngine/Compiler/LSL/Compiler.cs | 19 ++++++++++++++++++- .../DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | 4 ++-- .../ScriptEngine/DotNetEngine/ScriptManager.cs | 22 +++++++++++++++------- 3 files changed, 35 insertions(+), 10 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs index 906b2d3..2c514fc 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs @@ -20,8 +20,25 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL // Output assembly name string OutFile = Path.GetFileNameWithoutExtension(LSOFileName) + ".dll"; + Common.SendToDebug("Reading source code into memory"); // TODO: Add error handling - string CS_Code = LSL_Converter.Convert(File.ReadAllText(LSOFileName)); + string CS_Code; + switch (System.IO.Path.GetExtension(LSOFileName).ToLower()) + { + case ".txt": + case ".lsl": + Common.SendToDebug("Source code is LSL, converting to CS"); + CS_Code = LSL_Converter.Convert(File.ReadAllText(LSOFileName)); + break; + case ".cs": + Common.SendToDebug("Source code is CS"); + CS_Code = File.ReadAllText(LSOFileName); + break; + default: + throw new Exception("Unknown script type."); + } + + Common.SendToDebug("Compiling"); // Do actual compile System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters(); diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs index 99fdb0d..6b0afa9 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs @@ -162,7 +162,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL // void dataserver(key query_id, string data) { //cache = Regex.Replace(cache, @"([^a-zA-Z_]\s*)((?!if|switch|for)[a-zA-Z_]+\s*\([^\)]*\)[^{]*{)", "$1" + "" + "$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); //Console.WriteLine("Replacing using statename: " + current_statename); - cache = Regex.Replace(cache, @"^(\s*)((?!if|switch|for)[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1" + current_statename + "_$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); + cache = Regex.Replace(cache, @"^(\s*)((?!(if|switch|for)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1" + current_statename + "_$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); } ret += cache; @@ -195,7 +195,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL } // Add "void" in front of functions that needs it - Script = Regex.Replace(Script, @"^(\s*)((?!if|switch|for)[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1void $2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); + Script = Regex.Replace(Script, @"^(\s*)((?!(if|switch|for)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1void $2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); // Replace and Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*,[^,>]*)>", @"new Axiom.Math.Quaternion($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs index 832807d..c34889a 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs @@ -114,15 +114,23 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine FileName = ScriptID; // * Does script need compile? Send it to LSL compiler first. (TODO: Use (and clean) compiler cache) - if (FileName.ToLower().EndsWith(".lsl")) + Common.SendToDebug("ScriptManager Script extension: " + System.IO.Path.GetExtension(FileName).ToLower()); + switch (System.IO.Path.GetExtension(FileName).ToLower()) { - Common.SendToDebug("ScriptManager Script is LSL, compiling to .Net Assembly"); - // Create a new instance of the compiler (currently we don't want reuse) - OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler LSLCompiler = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler(); - // Compile - FileName = LSLCompiler.Compile(FileName); + case ".txt": + case ".lsl": + case ".cs": + Common.SendToDebug("ScriptManager Script is CS/LSL, compiling to .Net Assembly"); + // Create a new instance of the compiler (currently we don't want reuse) + OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler LSLCompiler = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler(); + // Compile + FileName = LSLCompiler.Compile(FileName); + break; + default: + throw new Exception("Unknown script type."); } + Common.SendToDebug("Compilation done"); // * Insert yield into code FileName = ProcessYield(FileName); @@ -197,7 +205,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine Type t; //try //{ - t = a.GetType("LSL_ScriptObject", true); + t = a.GetType("SecondLife.Script", true); //} //catch (Exception e) //{ -- cgit v1.1