From fd63c0cd32739f99af0c93ee3115212bb695f063 Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Sun, 12 Aug 2007 17:37:37 +0000 Subject: Code comments and cleanup, correct datatypes for key, vector, rotation, (hopefully) reference to Axiom during compile, passing of BuiltIns during script load, BuiltIn interface added, etc etc --- .../DotNetEngine/Compiler/LSL/Compiler.cs | 9 ++- .../DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | 76 +++++++--------------- .../DotNetEngine/Compiler/LSL/LSL_BaseClass.cs | 11 ++++ 3 files changed, 40 insertions(+), 56 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL') diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs index 33be6ec..6eadb0e 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs @@ -16,16 +16,21 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL { - string OutFile = Path.GetFileNameWithoutExtension(LSOFileName); + // Output assembly name + string OutFile = Path.GetFileNameWithoutExtension(LSOFileName) + ".dll"; // TODO: Add error handling string CS_Code = LSL_Converter.Convert(File.ReadAllText(LSOFileName)); + // Do actual compile System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters(); - parameters.GenerateExecutable = true; + parameters.IncludeDebugInformation = true; + parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment"); + parameters.GenerateExecutable = false; parameters.OutputAssembly = OutFile; CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, CS_Code); + // Go through errors // TODO: Return errors to user somehow if (results.Errors.Count > 0) { diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs index f058566..d9042b5 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs @@ -18,11 +18,12 @@ namespace LSL2CS.Converter DataTypes.Add("float", "float"); DataTypes.Add("string", "string"); DataTypes.Add("key", "string"); - DataTypes.Add("vector", "vector"); - DataTypes.Add("rotation", "rotation"); + DataTypes.Add("vector", "Axiom.Math.Vector3"); + DataTypes.Add("rotation", "Axiom.Math.Quaternion"); DataTypes.Add("list", "list"); DataTypes.Add("null", "null"); } + @@ -34,37 +35,14 @@ namespace LSL2CS.Converter // Prepare script for processing // - // Here we will remove those linebreaks that are allowed in so many languages. - // One hard-ass regex should do the job. - - // Then we will add some linebreaks. + // Clean up linebreaks Script = Regex.Replace(Script, @"\r\n", "\n"); Script = Regex.Replace(Script, @"\n", "\r\n"); - //Script = Regex.Replace(Script, @"\n\s*{", @"{"); - //Script = Regex.Replace(Script, @"[\r\n]", @""); - - // Then we remove unwanted linebreaks - - - //// - //// Split up script to process line by line - //// - //int count = 0; - //string line; - //Regex r = new Regex("\r?\n", RegexOptions.Multiline | RegexOptions.Compiled); - //string[] lines = r.Split(Script); - - //for (int i = 0; i < lines.Length; i++) - //{ - // // Remove space in front and back - // line = lines[i].Trim(); - // count++; - // Return += count + ". " + translate(line) + "\r\n"; - //} // QUOTE REPLACEMENT - //char[] SA = Script.ToCharArray(); + // temporarily replace quotes so we can work our magic on the script without + // always considering if we are inside our outside ""'s string _Script = ""; string C; bool in_quote = false; @@ -129,8 +107,10 @@ namespace LSL2CS.Converter - + // // PROCESS STATES + // Remove state definitions and add state names to start of each event within state + // int ilevel = 0; int lastlevel = 0; string ret = ""; @@ -190,13 +170,6 @@ namespace LSL2CS.Converter current_statename = ""; } - // if we moved from level 0 to level 1 don't add last word + { - // if we moved from level 1 to level 0 don't add last } - // if level > 0 cache all data so we can run regex on it when going to level 0 - - - - break; } lastlevel = ilevel; @@ -209,17 +182,23 @@ namespace LSL2CS.Converter - // Replace CAST - (integer) with (int) - Script = Regex.Replace(Script, @"\(integer\)", @"(int)", RegexOptions.Compiled | RegexOptions.Multiline); - // Replace return types and function variables - integer a() and f(integer a, integer a) - Script = Regex.Replace(Script, @"(^|;|}|[\(,])(\s*int)eger(\s*)", @"$1$2$3", RegexOptions.Compiled | RegexOptions.Multiline); + foreach (string key in DataTypes.Keys) + { + string val; + DataTypes.TryGetValue(key, out val); + + // Replace CAST - (integer) with (int) + Script = Regex.Replace(Script, @"\(" + key + @"\)", @"(" + val + ")", RegexOptions.Compiled | RegexOptions.Multiline); + // Replace return types and function variables - integer a() and f(integer a, integer a) + Script = Regex.Replace(Script, @"(^|;|}|[\(,])(\s*)" + key + @"(\s*)", @"$1$2" + val + "$3", RegexOptions.Compiled | RegexOptions.Multiline); + } // 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); // Replace and - Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*,[^,>]*)>", @"Rotation.Parse($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); - Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*)>", @"Vector.Parse($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); + Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*,[^,>]*)>", @"new Axiom.Math.Quaternion($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); + Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*)>", @"new Axiom.Math.Vector3($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); // Replace List []'s Script = Regex.Replace(Script, @"\[([^\]]*)\]", @"List.Parse($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); @@ -239,6 +218,7 @@ namespace LSL2CS.Converter } + // Add namespace, class name and inheritance Return = "namespace SecondLife {" + Environment.NewLine; Return += "public class Script : LSL_BaseClass {" + Environment.NewLine; Return += Script; @@ -246,18 +226,6 @@ namespace LSL2CS.Converter return Return; } - //private string GetWord(char[] SA, int p) - //{ - // string ret = ""; - // for (int i = p; p < SA.Length; i++) - // { - // if (!rnw.IsMatch(SA[i].ToString())) - // break; - // ret += SA[i]; - // } - // return ret; - //} - } diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs index 03d8ba5..a065683 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs @@ -1,10 +1,21 @@ using System; using System.Collections.Generic; using System.Text; +using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler; namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL { class LSL_BaseClass { + public UInt32 State = 0; + public LSL_BuiltIn_Commands_Interface LSL_Builtins; + + public void Start(LSL_BuiltIn_Commands_Interface LSLBuiltins) + { + LSL_Builtins = LSLBuiltins; + Common.SendToLog("OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass.Start() called"); + + return; + } } } -- cgit v1.1