aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs226
1 files changed, 113 insertions, 113 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
index a488b91..b63a6ce 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
@@ -1,113 +1,113 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Text; 3using System.Text;
4using System.IO; 4using System.IO;
5using Microsoft.CSharp; 5using Microsoft.CSharp;
6using System.CodeDom.Compiler; 6using System.CodeDom.Compiler;
7using System.Reflection; 7using System.Reflection;
8 8
9namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL 9namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
10{ 10{
11 11
12 public class Compiler 12 public class Compiler
13 { 13 {
14 private LSL2CSConverter LSL_Converter = new LSL2CSConverter(); 14 private LSL2CSConverter LSL_Converter = new LSL2CSConverter();
15 private CSharpCodeProvider codeProvider = new CSharpCodeProvider(); 15 private CSharpCodeProvider codeProvider = new CSharpCodeProvider();
16 private static UInt64 scriptCompileCounter = 0; 16 private static UInt64 scriptCompileCounter = 0;
17 //private ICodeCompiler icc = codeProvider.CreateCompiler(); 17 //private ICodeCompiler icc = codeProvider.CreateCompiler();
18 public string CompileFromFile(string LSOFileName) 18 public string CompileFromFile(string LSOFileName)
19 { 19 {
20 switch (System.IO.Path.GetExtension(LSOFileName).ToLower()) 20 switch (System.IO.Path.GetExtension(LSOFileName).ToLower())
21 { 21 {
22 case ".txt": 22 case ".txt":
23 case ".lsl": 23 case ".lsl":
24 Common.SendToDebug("Source code is LSL, converting to CS"); 24 Common.SendToDebug("Source code is LSL, converting to CS");
25 return CompileFromLSLText(File.ReadAllText(LSOFileName)); 25 return CompileFromLSLText(File.ReadAllText(LSOFileName));
26 case ".cs": 26 case ".cs":
27 Common.SendToDebug("Source code is CS"); 27 Common.SendToDebug("Source code is CS");
28 return CompileFromCSText(File.ReadAllText(LSOFileName)); 28 return CompileFromCSText(File.ReadAllText(LSOFileName));
29 default: 29 default:
30 throw new Exception("Unknown script type."); 30 throw new Exception("Unknown script type.");
31 } 31 }
32 } 32 }
33 /// <summary> 33 /// <summary>
34 /// Converts script from LSL to CS and calls CompileFromCSText 34 /// Converts script from LSL to CS and calls CompileFromCSText
35 /// </summary> 35 /// </summary>
36 /// <param name="Script">LSL script</param> 36 /// <param name="Script">LSL script</param>
37 /// <returns>Filename to .dll assembly</returns> 37 /// <returns>Filename to .dll assembly</returns>
38 public string CompileFromLSLText(string Script) 38 public string CompileFromLSLText(string Script)
39 { 39 {
40 return CompileFromCSText(LSL_Converter.Convert(Script)); 40 return CompileFromCSText(LSL_Converter.Convert(Script));
41 } 41 }
42 /// <summary> 42 /// <summary>
43 /// Compile CS script to .Net assembly (.dll) 43 /// Compile CS script to .Net assembly (.dll)
44 /// </summary> 44 /// </summary>
45 /// <param name="Script">CS script</param> 45 /// <param name="Script">CS script</param>
46 /// <returns>Filename to .dll assembly</returns> 46 /// <returns>Filename to .dll assembly</returns>
47 public string CompileFromCSText(string Script) 47 public string CompileFromCSText(string Script)
48 { 48 {
49 49
50 50
51 // Output assembly name 51 // Output assembly name
52 scriptCompileCounter++; 52 scriptCompileCounter++;
53 string OutFile = Path.Combine("ScriptEngines", "Script_" + scriptCompileCounter + ".dll"); 53 string OutFile = Path.Combine("ScriptEngines", "Script_" + scriptCompileCounter + ".dll");
54 try 54 try
55 { 55 {
56 System.IO.File.Delete(OutFile); 56 System.IO.File.Delete(OutFile);
57 } 57 }
58 catch (Exception e) 58 catch (Exception e)
59 { 59 {
60 Console.WriteLine("Exception attempting to delete old compiled script: " + e.ToString()); 60 Console.WriteLine("Exception attempting to delete old compiled script: " + e.ToString());
61 } 61 }
62 //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll"); 62 //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll");
63 63
64 // DEBUG - write source to disk 64 // DEBUG - write source to disk
65 try 65 try
66 { 66 {
67 File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(OutFile) + ".cs"), Script); 67 File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(OutFile) + ".cs"), Script);
68 } 68 }
69 catch { } 69 catch { }
70 70
71 // Do actual compile 71 // Do actual compile
72 System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters(); 72 System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
73 parameters.IncludeDebugInformation = true; 73 parameters.IncludeDebugInformation = true;
74 // Add all available assemblies 74 // Add all available assemblies
75 foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) 75 foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
76 { 76 {
77 //Console.WriteLine("Adding assembly: " + asm.Location); 77 //Console.WriteLine("Adding assembly: " + asm.Location);
78 //parameters.ReferencedAssemblies.Add(asm.Location); 78 //parameters.ReferencedAssemblies.Add(asm.Location);
79 } 79 }
80 80
81 string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); 81 string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
82 string rootPathSE = Path.GetDirectoryName(this.GetType().Assembly.Location); 82 string rootPathSE = Path.GetDirectoryName(this.GetType().Assembly.Location);
83 //Console.WriteLine("Assembly location: " + rootPath); 83 //Console.WriteLine("Assembly location: " + rootPath);
84 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Common.dll")); 84 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Common.dll"));
85 parameters.ReferencedAssemblies.Add(Path.Combine(rootPathSE, "OpenSim.Region.ScriptEngine.DotNetEngine.dll")); 85 parameters.ReferencedAssemblies.Add(Path.Combine(rootPathSE, "OpenSim.Region.ScriptEngine.DotNetEngine.dll"));
86 86
87 //parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment"); 87 //parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment");
88 parameters.GenerateExecutable = false; 88 parameters.GenerateExecutable = false;
89 parameters.OutputAssembly = OutFile; 89 parameters.OutputAssembly = OutFile;
90 parameters.IncludeDebugInformation = false; 90 parameters.IncludeDebugInformation = false;
91 CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, Script); 91 CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, Script);
92 92
93 // Go through errors 93 // Go through errors
94 // TODO: Return errors to user somehow 94 // TODO: Return errors to user somehow
95 if (results.Errors.Count > 0) 95 if (results.Errors.Count > 0)
96 { 96 {
97 97
98 string errtext = ""; 98 string errtext = "";
99 foreach (CompilerError CompErr in results.Errors) 99 foreach (CompilerError CompErr in results.Errors)
100 { 100 {
101 errtext += "Line number " + (CompErr.Line - 1) + 101 errtext += "Line number " + (CompErr.Line - 1) +
102 ", Error Number: " + CompErr.ErrorNumber + 102 ", Error Number: " + CompErr.ErrorNumber +
103 ", '" + CompErr.ErrorText + "'\r\n"; 103 ", '" + CompErr.ErrorText + "'\r\n";
104 } 104 }
105 throw new Exception(errtext); 105 throw new Exception(errtext);
106 } 106 }
107 107
108 108
109 return OutFile; 109 return OutFile;
110 } 110 }
111 111
112 } 112 }
113} 113}