Add friendly error messages to both engines.
parent
ec16750a87
commit
85068dae60
|
@ -139,6 +139,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
public string functionName;
|
public string functionName;
|
||||||
public DetectParams[] llDetectParams;
|
public DetectParams[] llDetectParams;
|
||||||
public object[] param;
|
public object[] param;
|
||||||
|
public Dictionary<KeyValuePair<int,int>,KeyValuePair<int,int>>
|
||||||
|
LineMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -349,6 +351,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InstanceData id = m_ScriptEngine.m_ScriptManager.GetScript(
|
||||||
|
localID, itemID);
|
||||||
|
|
||||||
// Create a structure and add data
|
// Create a structure and add data
|
||||||
QueueItemStruct QIS = new QueueItemStruct();
|
QueueItemStruct QIS = new QueueItemStruct();
|
||||||
QIS.localID = localID;
|
QIS.localID = localID;
|
||||||
|
@ -356,6 +361,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
QIS.functionName = FunctionName;
|
QIS.functionName = FunctionName;
|
||||||
QIS.llDetectParams = qParams;
|
QIS.llDetectParams = qParams;
|
||||||
QIS.param = param;
|
QIS.param = param;
|
||||||
|
if (id != null)
|
||||||
|
QIS.LineMap = id.LineMap;
|
||||||
|
|
||||||
// Add it to queue
|
// Add it to queue
|
||||||
eventQueue.Enqueue(QIS);
|
eventQueue.Enqueue(QIS);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
@ -37,6 +38,7 @@ using OpenSim.Framework;
|
||||||
using OpenSim.Region.Environment.Scenes;
|
using OpenSim.Region.Environment.Scenes;
|
||||||
using OpenSim.Region.Environment.Scenes.Scripting;
|
using OpenSim.Region.Environment.Scenes.Scripting;
|
||||||
using OpenSim.Region.ScriptEngine.Shared;
|
using OpenSim.Region.ScriptEngine.Shared;
|
||||||
|
using OpenSim.Region.ScriptEngine.Shared.CodeTools;
|
||||||
|
|
||||||
namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
{
|
{
|
||||||
|
@ -198,10 +200,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
if (lastScriptEngine != null)
|
|
||||||
lastScriptEngine.Log.Error("[" + ScriptEngineName +
|
|
||||||
"]: Exception in EventQueueThreadLoop: " +
|
|
||||||
e.ToString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -290,32 +288,32 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
InExecution = false;
|
InExecution = false;
|
||||||
// DISPLAY ERROR INWORLD
|
string text = FormatException(e, QIS.LineMap);
|
||||||
string text = "Error executing script function \"" +
|
|
||||||
QIS.functionName + "\":\r\n";
|
|
||||||
|
|
||||||
if (e.InnerException != null)
|
// DISPLAY ERROR INWORLD
|
||||||
{
|
|
||||||
// Send inner exception
|
// if (e.InnerException != null)
|
||||||
string line = " (unknown line)";
|
// {
|
||||||
Regex rx = new Regex(@"SecondLife\.Script\..+[\s:](?<line>\d+)\.?\r?$", RegexOptions.Compiled);
|
// // Send inner exception
|
||||||
if (rx.Match(e.InnerException.ToString()).Success)
|
// string line = " (unknown line)";
|
||||||
line = " (line " + rx.Match(e.InnerException.ToString()).Result("${line}") + ")";
|
// Regex rx = new Regex(@"SecondLife\.Script\..+[\s:](?<line>\d+)\.?\r?$", RegexOptions.Compiled);
|
||||||
text += e.InnerException.Message.ToString() + line;
|
// if (rx.Match(e.InnerException.ToString()).Success)
|
||||||
}
|
// line = " (line " + rx.Match(e.InnerException.ToString()).Result("${line}") + ")";
|
||||||
else
|
// text += e.InnerException.Message.ToString() + line;
|
||||||
{
|
// }
|
||||||
text += "\r\n";
|
// else
|
||||||
// Send normal
|
// {
|
||||||
text += e.Message.ToString();
|
// text += "\r\n";
|
||||||
}
|
// // Send normal
|
||||||
if (KillCurrentScript)
|
// text += e.Message.ToString();
|
||||||
text += "\r\nScript will be deactivated!";
|
// }
|
||||||
|
// if (KillCurrentScript)
|
||||||
|
// text += "\r\nScript will be deactivated!";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (text.Length > 1500)
|
if (text.Length >= 1100)
|
||||||
text = text.Substring(0, 1500);
|
text = text.Substring(0, 1099);
|
||||||
IScriptHost m_host =
|
IScriptHost m_host =
|
||||||
m_ScriptEngine.World.GetSceneObjectPart(QIS.localID);
|
m_ScriptEngine.World.GetSceneObjectPart(QIS.localID);
|
||||||
m_ScriptEngine.World.SimChat(
|
m_ScriptEngine.World.SimChat(
|
||||||
|
@ -343,10 +341,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
QIS.localID, QIS.itemID);
|
QIS.localID, QIS.itemID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass it on so it's displayed on the console
|
|
||||||
// and in the logs (mikem 2008.06.02).
|
|
||||||
throw e.InnerException;
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -358,5 +352,45 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string FormatException(Exception e, Dictionary<KeyValuePair<int,int>,
|
||||||
|
KeyValuePair<int,int>> LineMap)
|
||||||
|
{
|
||||||
|
string message = "Runtime error:\n" + e.InnerException.StackTrace;
|
||||||
|
string[] lines = message.Split(new char[] {'\n'});
|
||||||
|
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
if (line.Contains("SecondLife.Script"))
|
||||||
|
{
|
||||||
|
int idx = line.IndexOf(':');
|
||||||
|
if (idx != -1)
|
||||||
|
{
|
||||||
|
string val = line.Substring(idx+1);
|
||||||
|
int lineNum = 0;
|
||||||
|
if (int.TryParse(val, out lineNum))
|
||||||
|
{
|
||||||
|
KeyValuePair<int, int> pos =
|
||||||
|
Compiler.FindErrorPosition(
|
||||||
|
lineNum, 0, LineMap);
|
||||||
|
|
||||||
|
int scriptLine = pos.Key;
|
||||||
|
int col = pos.Value;
|
||||||
|
if (scriptLine == 0)
|
||||||
|
scriptLine++;
|
||||||
|
if (col == 0)
|
||||||
|
col++;
|
||||||
|
message = string.Format("Runtime error:\n" +
|
||||||
|
"Line ({0}): {1}", scriptLine - 1,
|
||||||
|
e.InnerException.Message);
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
public int StartParam;
|
public int StartParam;
|
||||||
public AppDomain AppDomain;
|
public AppDomain AppDomain;
|
||||||
public Dictionary<string, IScriptApi> Apis;
|
public Dictionary<string, IScriptApi> Apis;
|
||||||
|
public Dictionary<KeyValuePair<int,int>, KeyValuePair<int,int>>
|
||||||
|
LineMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ScriptManager
|
public class ScriptManager
|
||||||
|
@ -159,6 +161,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
m_scriptEngine.m_AppDomainManager.LoadScript(
|
m_scriptEngine.m_AppDomainManager.LoadScript(
|
||||||
CompiledScriptFile, out id.AppDomain);
|
CompiledScriptFile, out id.AppDomain);
|
||||||
|
|
||||||
|
id.LineMap = LSLCompiler.LineMap();
|
||||||
id.Script = CompiledScript;
|
id.Script = CompiledScript;
|
||||||
id.Source = Script;
|
id.Source = Script;
|
||||||
id.StartParam = startParam;
|
id.StartParam = startParam;
|
||||||
|
@ -212,7 +215,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// DISPLAY ERROR INWORLD
|
// DISPLAY ERROR INWORLD
|
||||||
string text = "Error compiling script:\r\n" +
|
string text = "Error compiling script:\n" +
|
||||||
e.Message.ToString();
|
e.Message.ToString();
|
||||||
if (text.Length > 1100)
|
if (text.Length > 1100)
|
||||||
text = text.Substring(0, 1099);
|
text = text.Substring(0, 1099);
|
||||||
|
|
|
@ -33,7 +33,8 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
|
||||||
{
|
{
|
||||||
public interface ICompiler
|
public interface ICompiler
|
||||||
{
|
{
|
||||||
void Configure(IConfig configSource);
|
string PerformScriptCompile(string source, string asset);
|
||||||
void Compile(string text, string outFile, List<IScriptApi> apiList);
|
Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>
|
||||||
|
LineMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,5 +96,8 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
|
||||||
void DestroyScriptInstance();
|
void DestroyScriptInstance();
|
||||||
|
|
||||||
IScriptApi GetApi(string name);
|
IScriptApi GetApi(string name);
|
||||||
|
|
||||||
|
Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap
|
||||||
|
{ get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
ResetCounters();
|
ResetCounters();
|
||||||
Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true));
|
Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true));
|
||||||
// Obviously this needs to be in a try/except block.
|
// Obviously this needs to be in a try/except block.
|
||||||
LSL2CSCodeTransformer codeTransformer = new LSL2CSCodeTransformer(p.Parse(script));
|
LSL2CSCodeTransformer codeTransformer;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
codeTransformer = new LSL2CSCodeTransformer(p.Parse(script));
|
||||||
|
}
|
||||||
|
catch (CSToolsException e)
|
||||||
|
{
|
||||||
|
string message;
|
||||||
|
|
||||||
|
// LL start numbering lines at 0 - geeks!
|
||||||
|
//
|
||||||
|
message = String.Format("Line ({0},{1}) {2}",
|
||||||
|
e.slInfo.lineNumber - 1,
|
||||||
|
e.slInfo.charPosition - 1, e.Message);
|
||||||
|
|
||||||
|
throw new Exception(message);
|
||||||
|
}
|
||||||
|
|
||||||
m_astRoot = codeTransformer.Transform();
|
m_astRoot = codeTransformer.Transform();
|
||||||
|
|
||||||
string retstr = String.Empty;
|
string retstr = String.Empty;
|
||||||
|
|
|
@ -38,7 +38,7 @@ using OpenSim.Region.ScriptEngine.Interfaces;
|
||||||
|
|
||||||
namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
{
|
{
|
||||||
public class Compiler
|
public class Compiler : ICompiler
|
||||||
{
|
{
|
||||||
// private static readonly log4net.ILog m_log
|
// private static readonly log4net.ILog m_log
|
||||||
// = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
// = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
@ -255,18 +255,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
/// <returns>Filename to .dll assembly</returns>
|
/// <returns>Filename to .dll assembly</returns>
|
||||||
public string PerformScriptCompile(string Script, string asset)
|
public string PerformScriptCompile(string Script, string asset)
|
||||||
{
|
{
|
||||||
|
m_positionMap = null;
|
||||||
|
|
||||||
string OutFile = Path.Combine(ScriptEnginesPath, Path.Combine(
|
string OutFile = Path.Combine(ScriptEnginesPath, Path.Combine(
|
||||||
m_scriptEngine.World.RegionInfo.RegionID.ToString(),
|
m_scriptEngine.World.RegionInfo.RegionID.ToString(),
|
||||||
FilePrefix + "_compiled_" + asset + ".dll"));
|
FilePrefix + "_compiled_" + asset + ".dll"));
|
||||||
// string OutFile = Path.Combine(ScriptEnginesPath,
|
// string OutFile = Path.Combine(ScriptEnginesPath,
|
||||||
// FilePrefix + "_compiled_" + asset + ".dll");
|
// FilePrefix + "_compiled_" + asset + ".dll");
|
||||||
|
|
||||||
if (File.Exists(OutFile))
|
|
||||||
{
|
|
||||||
m_scriptEngine.Log.DebugFormat("[Compiler] Returning existing assembly for {0}", asset);
|
|
||||||
return OutFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Directory.Exists(ScriptEnginesPath))
|
if (!Directory.Exists(ScriptEnginesPath))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -327,38 +323,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
compileScript = LSL_Converter.Convert(Script);
|
compileScript = LSL_Converter.Convert(Script);
|
||||||
|
|
||||||
m_positionMap = ((CSCodeGenerator) LSL_Converter).PositionMap;
|
m_positionMap = ((CSCodeGenerator) LSL_Converter).PositionMap;
|
||||||
|
}
|
||||||
|
|
||||||
l = enumCompileType.cs;
|
// Check this late so the map is generated on sim start
|
||||||
|
//
|
||||||
|
if (File.Exists(OutFile))
|
||||||
|
{
|
||||||
|
m_scriptEngine.Log.DebugFormat("[Compiler] Returning existing assembly for {0}", asset);
|
||||||
|
return OutFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l == enumCompileType.yp)
|
if (l == enumCompileType.yp)
|
||||||
{
|
{
|
||||||
// Its YP, convert it to C#
|
// Its YP, convert it to C#
|
||||||
compileScript = YP_Converter.Convert(Script);
|
compileScript = YP_Converter.Convert(Script);
|
||||||
// We have our own processor now
|
|
||||||
//l = enumCompileType.cs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert additional assemblies here
|
|
||||||
|
|
||||||
//ADAM: Disabled for the moment until it's working right.
|
|
||||||
bool enableCommanderLSL = false;
|
|
||||||
|
|
||||||
if (enableCommanderLSL == true && ((l == enumCompileType.cs) || (l == enumCompileType.yp)))
|
|
||||||
{
|
|
||||||
foreach (KeyValuePair<string,
|
|
||||||
ICommander> com
|
|
||||||
in m_scriptEngine.World.GetCommanders())
|
|
||||||
{
|
|
||||||
compileScript = com.Value.GenerateRuntimeAPI() + compileScript;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// End of insert
|
|
||||||
|
|
||||||
switch (l)
|
switch (l)
|
||||||
{
|
{
|
||||||
case enumCompileType.cs:
|
case enumCompileType.cs:
|
||||||
|
case enumCompileType.lsl:
|
||||||
compileScript = CreateCSCompilerScript(compileScript);
|
compileScript = CreateCSCompilerScript(compileScript);
|
||||||
break;
|
break;
|
||||||
case enumCompileType.vb:
|
case enumCompileType.vb:
|
||||||
|
@ -372,10 +356,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// m_log.Debug("[ScriptEngine.DotNetEngine]: Preparing to compile the following LSL to C# translated code");
|
|
||||||
// m_log.Debug("");
|
|
||||||
// m_log.Debug(compileScript);
|
|
||||||
|
|
||||||
return CompileFromDotNetText(compileScript, l, asset);
|
return CompileFromDotNetText(compileScript, l, asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,26 +422,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
// Output assembly name
|
// Output assembly name
|
||||||
scriptCompileCounter++;
|
scriptCompileCounter++;
|
||||||
string OutFile = Path.Combine(ScriptEnginesPath, Path.Combine(
|
string OutFile = Path.Combine(ScriptEnginesPath, Path.Combine(
|
||||||
m_scriptEngine.World.RegionInfo.RegionID.ToString(),
|
m_scriptEngine.World.RegionInfo.RegionID.ToString(),
|
||||||
FilePrefix + "_compiled_" + asset + ".dll"));
|
FilePrefix + "_compiled_" + asset + ".dll"));
|
||||||
#if DEBUG
|
|
||||||
// m_scriptEngine.Log.Debug("[Compiler]: Starting compile of \"" + OutFile + "\".");
|
|
||||||
#endif
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.Delete(OutFile);
|
File.Delete(OutFile);
|
||||||
}
|
}
|
||||||
catch (Exception e) // NOTLEGIT - Should be just catching FileIOException
|
catch (Exception e) // NOTLEGIT - Should be just FileIOException
|
||||||
{
|
{
|
||||||
//m_scriptEngine.Log.Error("[Compiler]: Unable to delete old existring script-file before writing new. Compile aborted: " + e.ToString());
|
throw new Exception("Unable to delete old existing "+
|
||||||
throw new Exception("Unable to delete old existring script-file before writing new. Compile aborted: " + e.ToString());
|
"script-file before writing new. Compile aborted: " +
|
||||||
|
e.ToString());
|
||||||
}
|
}
|
||||||
//string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll");
|
|
||||||
|
|
||||||
// DEBUG - write source to disk
|
// DEBUG - write source to disk
|
||||||
if (WriteScriptSourceToDebugFile)
|
if (WriteScriptSourceToDebugFile)
|
||||||
{
|
{
|
||||||
string srcFileName = FilePrefix + "_source_" + Path.GetFileNameWithoutExtension(OutFile) + ext;
|
string srcFileName = FilePrefix + "_source_" +
|
||||||
|
Path.GetFileNameWithoutExtension(OutFile) + ext;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.WriteAllText(Path.Combine(Path.Combine(
|
File.WriteAllText(Path.Combine(Path.Combine(
|
||||||
|
@ -469,9 +447,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
m_scriptEngine.World.RegionInfo.RegionID.ToString()),
|
m_scriptEngine.World.RegionInfo.RegionID.ToString()),
|
||||||
srcFileName), Script);
|
srcFileName), Script);
|
||||||
}
|
}
|
||||||
catch (Exception ex) // NOTLEGIT - Should be just catching FileIOException
|
catch (Exception ex) //NOTLEGIT - Should be just FileIOException
|
||||||
{
|
{
|
||||||
m_scriptEngine.Log.Error("[Compiler]: Exception while trying to write script source to file \"" + srcFileName + "\": " + ex.ToString());
|
m_scriptEngine.Log.Error("[Compiler]: Exception while "+
|
||||||
|
"trying to write script source to file \"" +
|
||||||
|
srcFileName + "\": " + ex.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,22 +460,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
|
|
||||||
parameters.IncludeDebugInformation = true;
|
parameters.IncludeDebugInformation = true;
|
||||||
|
|
||||||
// Add all available assemblies
|
string rootPath =
|
||||||
// foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
|
Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
|
||||||
// {
|
|
||||||
// Console.WriteLine("Adding assembly: " + asm.Location);
|
|
||||||
// parameters.ReferencedAssemblies.Add(asm.Location);
|
|
||||||
// }
|
|
||||||
|
|
||||||
string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
|
parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
|
||||||
// string rootPathSE = Path.GetDirectoryName(GetType().Assembly.Location);
|
"OpenSim.Region.ScriptEngine.Shared.dll"));
|
||||||
//Console.WriteLine("Assembly location: " + rootPath);
|
parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
|
||||||
parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.dll"));
|
"OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll"));
|
||||||
parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll"));
|
|
||||||
|
|
||||||
if (lang == enumCompileType.yp)
|
if (lang == enumCompileType.yp)
|
||||||
{
|
{
|
||||||
parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.YieldProlog.dll"));
|
parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
|
||||||
|
"OpenSim.Region.ScriptEngine.Shared.YieldProlog.dll"));
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters.GenerateExecutable = false;
|
parameters.GenerateExecutable = false;
|
||||||
|
@ -504,24 +480,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
//parameters.WarningLevel = 1; // Should be 4?
|
//parameters.WarningLevel = 1; // Should be 4?
|
||||||
parameters.TreatWarningsAsErrors = false;
|
parameters.TreatWarningsAsErrors = false;
|
||||||
|
|
||||||
//Console.WriteLine(Script);
|
|
||||||
CompilerResults results;
|
CompilerResults results;
|
||||||
switch (lang)
|
switch (lang)
|
||||||
{
|
{
|
||||||
case enumCompileType.vb:
|
case enumCompileType.vb:
|
||||||
results = VBcodeProvider.CompileAssemblyFromSource(parameters, Script);
|
results = VBcodeProvider.CompileAssemblyFromSource(
|
||||||
|
parameters, Script);
|
||||||
break;
|
break;
|
||||||
case enumCompileType.cs:
|
case enumCompileType.cs:
|
||||||
results = CScodeProvider.CompileAssemblyFromSource(parameters, Script);
|
case enumCompileType.lsl:
|
||||||
|
results = CScodeProvider.CompileAssemblyFromSource(
|
||||||
|
parameters, Script);
|
||||||
break;
|
break;
|
||||||
case enumCompileType.js:
|
case enumCompileType.js:
|
||||||
results = JScodeProvider.CompileAssemblyFromSource(parameters, Script);
|
results = JScodeProvider.CompileAssemblyFromSource(
|
||||||
|
parameters, Script);
|
||||||
break;
|
break;
|
||||||
case enumCompileType.yp:
|
case enumCompileType.yp:
|
||||||
results = YPcodeProvider.CompileAssemblyFromSource(parameters, Script);
|
results = YPcodeProvider.CompileAssemblyFromSource(
|
||||||
|
parameters, Script);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Exception("Compiler is not able to recongnize language type \"" + lang.ToString() + "\"");
|
throw new Exception("Compiler is not able to recongnize "+
|
||||||
|
"language type \"" + lang.ToString() + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check result
|
// Check result
|
||||||
|
@ -530,11 +511,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
//
|
//
|
||||||
// WARNINGS AND ERRORS
|
// WARNINGS AND ERRORS
|
||||||
//
|
//
|
||||||
|
int display = 5;
|
||||||
if (results.Errors.Count > 0)
|
if (results.Errors.Count > 0)
|
||||||
{
|
{
|
||||||
string errtext = String.Empty;
|
string errtext = String.Empty;
|
||||||
foreach (CompilerError CompErr in results.Errors)
|
foreach (CompilerError CompErr in results.Errors)
|
||||||
{
|
{
|
||||||
|
// Show 5 errors max
|
||||||
|
//
|
||||||
|
if (display <= 0)
|
||||||
|
break;
|
||||||
|
display--;
|
||||||
|
|
||||||
string severity = "Error";
|
string severity = "Error";
|
||||||
if ( CompErr.IsWarning )
|
if ( CompErr.IsWarning )
|
||||||
{
|
{
|
||||||
|
@ -543,22 +531,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
|
|
||||||
KeyValuePair<int, int> lslPos;
|
KeyValuePair<int, int> lslPos;
|
||||||
|
|
||||||
try
|
lslPos = FindErrorPosition(CompErr.Line, CompErr.Column);
|
||||||
{
|
|
||||||
lslPos = m_positionMap[new KeyValuePair<int, int>(CompErr.Line, CompErr.Column)];
|
string text = CompErr.ErrorText;
|
||||||
}
|
|
||||||
catch (KeyNotFoundException) // we don't have this line/column mapped
|
// Use LSL type names
|
||||||
{
|
if (lang == enumCompileType.lsl)
|
||||||
m_scriptEngine.Log.Debug(String.Format("[Compiler]: Lookup of C# line {0}, column {1} failed.", CompErr.Line, CompErr.Column));
|
text = ReplaceTypes(CompErr.ErrorText);
|
||||||
lslPos = new KeyValuePair<int, int>(-CompErr.Line, -CompErr.Column);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The Second Life viewer's script editor begins
|
// The Second Life viewer's script editor begins
|
||||||
// countingn lines and columns at 0, so we subtract 1.
|
// countingn lines and columns at 0, so we subtract 1.
|
||||||
errtext += String.Format("Line {0}, column {1}, {4} Number: {2}, '{3}'\r\n", lslPos.Key - 1, lslPos.Value - 1, CompErr.ErrorNumber, CompErr.ErrorText, severity);
|
errtext += String.Format("Line ({0},{1}): {4} {2}: {3}\n",
|
||||||
|
lslPos.Key - 1, lslPos.Value - 1,
|
||||||
|
CompErr.ErrorNumber, text, severity);
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("[COMPILER MESSAGES]: " + errtext);
|
|
||||||
if (!File.Exists(OutFile))
|
if (!File.Exists(OutFile))
|
||||||
{
|
{
|
||||||
throw new Exception(errtext);
|
throw new Exception(errtext);
|
||||||
|
@ -574,8 +561,100 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
errtext += "No compile error. But not able to locate compiled file.";
|
errtext += "No compile error. But not able to locate compiled file.";
|
||||||
throw new Exception(errtext);
|
throw new Exception(errtext);
|
||||||
}
|
}
|
||||||
m_scriptEngine.Log.DebugFormat("[Compiler] Compiled new assembly for {0}", asset);
|
m_scriptEngine.Log.DebugFormat("[Compiler] Compiled new assembly "+
|
||||||
|
"for {0}", asset);
|
||||||
return OutFile;
|
return OutFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public KeyValuePair<int, int> FindErrorPosition(int line, int col)
|
||||||
|
{
|
||||||
|
return FindErrorPosition(line, col, m_positionMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class kvpSorter : IComparer<KeyValuePair<int,int>>
|
||||||
|
{
|
||||||
|
public int Compare(KeyValuePair<int,int> a,
|
||||||
|
KeyValuePair<int,int> b)
|
||||||
|
{
|
||||||
|
return a.Key.CompareTo(b.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static KeyValuePair<int, int> FindErrorPosition(int line,
|
||||||
|
int col, Dictionary<KeyValuePair<int, int>,
|
||||||
|
KeyValuePair<int, int>> positionMap)
|
||||||
|
{
|
||||||
|
if (positionMap == null || positionMap.Count == 0)
|
||||||
|
return new KeyValuePair<int, int>(line, col);
|
||||||
|
|
||||||
|
KeyValuePair<int, int> ret = new KeyValuePair<int, int>();
|
||||||
|
|
||||||
|
if (positionMap.TryGetValue(new KeyValuePair<int, int>(line, col),
|
||||||
|
out ret))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
List<KeyValuePair<int,int>> sorted =
|
||||||
|
new List<KeyValuePair<int,int>>(positionMap.Keys);
|
||||||
|
|
||||||
|
sorted.Sort(new kvpSorter());
|
||||||
|
|
||||||
|
int l = 1;
|
||||||
|
int c = 1;
|
||||||
|
|
||||||
|
foreach (KeyValuePair<int, int> cspos in sorted)
|
||||||
|
{
|
||||||
|
if (cspos.Key >= line)
|
||||||
|
{
|
||||||
|
if (cspos.Key > line)
|
||||||
|
return new KeyValuePair<int, int>(l, c);
|
||||||
|
if (cspos.Value > col)
|
||||||
|
return new KeyValuePair<int, int>(l, c);
|
||||||
|
c = cspos.Value;
|
||||||
|
if (c == 0)
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
l = cspos.Key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new KeyValuePair<int, int>(l, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
string ReplaceTypes(string message)
|
||||||
|
{
|
||||||
|
message = message.Replace(
|
||||||
|
"OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString",
|
||||||
|
"string");
|
||||||
|
|
||||||
|
message = message.Replace(
|
||||||
|
"OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger",
|
||||||
|
"integer");
|
||||||
|
|
||||||
|
message = message.Replace(
|
||||||
|
"OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat",
|
||||||
|
"float");
|
||||||
|
|
||||||
|
message = message.Replace(
|
||||||
|
"OpenSim.Region.ScriptEngine.Shared.LSL_Types.list",
|
||||||
|
"list");
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>
|
||||||
|
LineMap()
|
||||||
|
{
|
||||||
|
if (m_positionMap == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> ret =
|
||||||
|
new Dictionary<KeyValuePair<int,int>, KeyValuePair<int, int>>();
|
||||||
|
|
||||||
|
foreach (KeyValuePair<int, int> kvp in m_positionMap.Keys)
|
||||||
|
ret.Add(kvp, m_positionMap[kvp]);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||||
private int m_ControlEventsInQueue = 0;
|
private int m_ControlEventsInQueue = 0;
|
||||||
private int m_LastControlLevel = 0;
|
private int m_LastControlLevel = 0;
|
||||||
private bool m_CollisionInQueue = false;
|
private bool m_CollisionInQueue = false;
|
||||||
|
private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>
|
||||||
|
m_LineMap;
|
||||||
|
|
||||||
|
public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>
|
||||||
|
LineMap
|
||||||
|
{
|
||||||
|
get { return m_LineMap; }
|
||||||
|
set { m_LineMap = value; }
|
||||||
|
}
|
||||||
|
|
||||||
private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>();
|
private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>();
|
||||||
|
|
||||||
|
@ -628,7 +637,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// DISPLAY ERROR INWORLD
|
// DISPLAY ERROR INWORLD
|
||||||
string text = "Runtime error:\n" + e.InnerException.ToString();
|
string text = FormatException(e);
|
||||||
|
|
||||||
if (text.Length > 1000)
|
if (text.Length > 1000)
|
||||||
text = text.Substring(0, 1000);
|
text = text.Substring(0, 1000);
|
||||||
m_Engine.World.SimChat(Utils.StringToBytes(text),
|
m_Engine.World.SimChat(Utils.StringToBytes(text),
|
||||||
|
@ -812,5 +822,44 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||||
{
|
{
|
||||||
return String.Format("{0} {1} on {2}", m_ScriptName, m_ItemID, m_PrimName);
|
return String.Format("{0} {1} on {2}", m_ScriptName, m_ItemID, m_PrimName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string FormatException(Exception e)
|
||||||
|
{
|
||||||
|
string message = "Runtime error:\n" + e.InnerException.StackTrace;
|
||||||
|
string[] lines = message.Split(new char[] {'\n'});
|
||||||
|
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
if (line.Contains("SecondLife.Script"))
|
||||||
|
{
|
||||||
|
int idx = line.IndexOf(':');
|
||||||
|
if (idx != -1)
|
||||||
|
{
|
||||||
|
string val = line.Substring(idx+1);
|
||||||
|
int lineNum = 0;
|
||||||
|
if (int.TryParse(val, out lineNum))
|
||||||
|
{
|
||||||
|
KeyValuePair<int, int> pos =
|
||||||
|
Compiler.FindErrorPosition(
|
||||||
|
lineNum, 0, LineMap);
|
||||||
|
|
||||||
|
int scriptLine = pos.Key;
|
||||||
|
int col = pos.Value;
|
||||||
|
if (scriptLine == 0)
|
||||||
|
scriptLine++;
|
||||||
|
if (col == 0)
|
||||||
|
col++;
|
||||||
|
message = string.Format("Runtime error:\n" +
|
||||||
|
"Line ({0}): {1}", scriptLine - 1,
|
||||||
|
e.InnerException.Message);
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||||
private int m_MaxScriptQueue;
|
private int m_MaxScriptQueue;
|
||||||
private Scene m_Scene;
|
private Scene m_Scene;
|
||||||
private IConfig m_ScriptConfig;
|
private IConfig m_ScriptConfig;
|
||||||
private Compiler m_Compiler;
|
private ICompiler m_Compiler;
|
||||||
private int m_MinThreads;
|
private int m_MinThreads;
|
||||||
private int m_MaxThreads ;
|
private int m_MaxThreads ;
|
||||||
private int m_IdleTimeout;
|
private int m_IdleTimeout;
|
||||||
|
@ -510,7 +510,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// DISPLAY ERROR INWORLD
|
// DISPLAY ERROR INWORLD
|
||||||
string text = "Error compiling script:\r\n" + e.Message.ToString();
|
string text = "Error compiling script:\n" + e.ToString();
|
||||||
if (text.Length > 1000)
|
if (text.Length > 1000)
|
||||||
text = text.Substring(0, 1000);
|
text = text.Substring(0, 1000);
|
||||||
World.SimChat(Utils.StringToBytes(text),
|
World.SimChat(Utils.StringToBytes(text),
|
||||||
|
@ -585,6 +585,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||||
part.ParentGroup.RootPart.Name, item.Name);
|
part.ParentGroup.RootPart.Name, item.Name);
|
||||||
|
|
||||||
instance.AppDomain = appDomain;
|
instance.AppDomain = appDomain;
|
||||||
|
instance.LineMap = m_Compiler.LineMap();
|
||||||
|
|
||||||
m_Scripts[itemID] = instance;
|
m_Scripts[itemID] = instance;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue