aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs50
1 files changed, 47 insertions, 3 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
index 2edcee0..841ed26 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
@@ -55,7 +55,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
55 lsl = 0, 55 lsl = 0,
56 cs = 1, 56 cs = 1,
57 vb = 2, 57 vb = 2,
58 js = 3 58 js = 3,
59 yp = 4
59 } 60 }
60 61
61 /// <summary> 62 /// <summary>
@@ -75,6 +76,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
75 private static CSharpCodeProvider CScodeProvider = new CSharpCodeProvider(); 76 private static CSharpCodeProvider CScodeProvider = new CSharpCodeProvider();
76 private static VBCodeProvider VBcodeProvider = new VBCodeProvider(); 77 private static VBCodeProvider VBcodeProvider = new VBCodeProvider();
77 private static JScriptCodeProvider JScodeProvider = new JScriptCodeProvider(); 78 private static JScriptCodeProvider JScodeProvider = new JScriptCodeProvider();
79 private static CSharpCodeProvider YPcodeProvider = new CSharpCodeProvider(); // YP is translated into CSharp
80 private static YP2CSConverter YP_Converter = new YP2CSConverter();
78 81
79 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
80 private static UInt64 scriptCompileCounter = 0; // And a counter 83 private static UInt64 scriptCompileCounter = 0; // And a counter
@@ -112,9 +115,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
112 LanguageMapping.Add(enumCompileType.vb.ToString(), enumCompileType.vb); 115 LanguageMapping.Add(enumCompileType.vb.ToString(), enumCompileType.vb);
113 LanguageMapping.Add(enumCompileType.lsl.ToString(), enumCompileType.lsl); 116 LanguageMapping.Add(enumCompileType.lsl.ToString(), enumCompileType.lsl);
114 LanguageMapping.Add(enumCompileType.js.ToString(), enumCompileType.js); 117 LanguageMapping.Add(enumCompileType.js.ToString(), enumCompileType.js);
118 LanguageMapping.Add(enumCompileType.yp.ToString(), enumCompileType.yp);
115 119
116 // Allowed compilers 120 // Allowed compilers
117 string allowComp = m_scriptEngine.Config.GetString("AllowedCompilers", "lsl,cs,vb,js"); 121 string allowComp = m_scriptEngine.Config.GetString("AllowedCompilers", "lsl,cs,vb,js,yp");
118 AllowedCompilers.Clear(); 122 AllowedCompilers.Clear();
119 123
120#if DEBUG 124#if DEBUG
@@ -303,6 +307,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
303 if (Script.StartsWith("//js", true, CultureInfo.InvariantCulture)) 307 if (Script.StartsWith("//js", true, CultureInfo.InvariantCulture))
304 l = enumCompileType.js; 308 l = enumCompileType.js;
305 309
310 if (Script.StartsWith("//yp", true, CultureInfo.InvariantCulture))
311 l = enumCompileType.yp;
312
306 if (!AllowedCompilers.ContainsKey(l.ToString())) 313 if (!AllowedCompilers.ContainsKey(l.ToString()))
307 { 314 {
308 // Not allowed to compile to this language! 315 // Not allowed to compile to this language!
@@ -320,12 +327,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
320 l = enumCompileType.cs; 327 l = enumCompileType.cs;
321 } 328 }
322 329
330 if (l == enumCompileType.yp)
331 {
332 // Its YP, convert it to C#
333 compileScript = YP_Converter.Convert(Script);
334 // We have our own processor now
335 //l = enumCompileType.cs;
336 }
337
323 // Insert additional assemblies here 338 // Insert additional assemblies here
324 339
325 //ADAM: Disabled for the moment until it's working right. 340 //ADAM: Disabled for the moment until it's working right.
326 bool enableCommanderLSL = false; 341 bool enableCommanderLSL = false;
327 342
328 if (enableCommanderLSL == true && l == enumCompileType.cs) 343 if (enableCommanderLSL == true && ((l == enumCompileType.cs) || (l == enumCompileType.yp)))
329 { 344 {
330 foreach (KeyValuePair<string, 345 foreach (KeyValuePair<string,
331 ICommander> com 346 ICommander> com
@@ -348,6 +363,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
348 case enumCompileType.js: 363 case enumCompileType.js:
349 compileScript = CreateJSCompilerScript(compileScript); 364 compileScript = CreateJSCompilerScript(compileScript);
350 break; 365 break;
366 case enumCompileType.yp:
367 compileScript = CreateYPCompilerScript(compileScript);
368 break;
351 } 369 }
352 370
353// m_log.Debug("[ScriptEngine.DotNetEngine]: Preparing to compile the following LSL to C# translated code"); 371// m_log.Debug("[ScriptEngine.DotNetEngine]: Preparing to compile the following LSL to C# translated code");
@@ -380,6 +398,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
380 return compileScript; 398 return compileScript;
381 } 399 }
382 400
401 private static string CreateYPCompilerScript(string compileScript)
402 {
403
404
405 compileScript = String.Empty +
406 "using OpenSim.Region.ScriptEngine.Shared.YieldProlog; " +
407 "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" +
408 String.Empty + "namespace SecondLife { " +
409 String.Empty + "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" +
410 //@"public Script() { } " +
411 @"static OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP YP=null; " +
412 @"public Script() { YP= new OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP(); } " +
413
414 compileScript +
415 "} }\r\n";
416 return compileScript;
417 }
418
383 private static string CreateVBCompilerScript(string compileScript) 419 private static string CreateVBCompilerScript(string compileScript)
384 { 420 {
385 compileScript = String.Empty + 421 compileScript = String.Empty +
@@ -455,6 +491,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
455 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.dll")); 491 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.dll"));
456 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll")); 492 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll"));
457 493
494 if (lang == enumCompileType.yp)
495 {
496 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.YieldProlog.dll"));
497 }
498
458 parameters.GenerateExecutable = false; 499 parameters.GenerateExecutable = false;
459 parameters.OutputAssembly = OutFile; 500 parameters.OutputAssembly = OutFile;
460 parameters.IncludeDebugInformation = CompileWithDebugInformation; 501 parameters.IncludeDebugInformation = CompileWithDebugInformation;
@@ -474,6 +515,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
474 case enumCompileType.js: 515 case enumCompileType.js:
475 results = JScodeProvider.CompileAssemblyFromSource(parameters, Script); 516 results = JScodeProvider.CompileAssemblyFromSource(parameters, Script);
476 break; 517 break;
518 case enumCompileType.yp:
519 results = YPcodeProvider.CompileAssemblyFromSource(parameters, Script);
520 break;
477 default: 521 default:
478 throw new Exception("Compiler is not able to recongnize language type \"" + lang.ToString() + "\""); 522 throw new Exception("Compiler is not able to recongnize language type \"" + lang.ToString() + "\"");
479 } 523 }