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

afrisby
Tedd Hansen 2007-08-12 17:37:37 +00:00
parent 7a5474ec28
commit fd63c0cd32
8 changed files with 101 additions and 121 deletions

View File

@ -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)
{

View File

@ -18,14 +18,15 @@ 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");
}
public string Convert(string Script)
{
string Return = "";
@ -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
foreach (string key in DataTypes.Keys)
{
string val;
DataTypes.TryGetValue(key, out val);
// Replace CAST - (integer) with (int)
Script = Regex.Replace(Script, @"\(integer\)", @"(int)", RegexOptions.Compiled | RegexOptions.Multiline);
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*int)eger(\s*)", @"$1$2$3", RegexOptions.Compiled | RegexOptions.Multiline);
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 <x,y,z> and <x,y,z,r>
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;
//}
}

View File

@ -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;
}
}
}

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler;
namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
{

View File

@ -30,7 +30,7 @@ using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler
{
public interface LSL_BuiltIn_Commands_Interface
{
@ -46,54 +46,54 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
UInt32 llFloor(float f);
UInt32 llCeil(float f);
UInt32 llRound(float f);
float llVecMag(LSO_Enums.Vector v);
LSO_Enums.Vector llVecNorm(LSO_Enums.Vector v);
float llVecDist(LSO_Enums.Vector a, LSO_Enums.Vector b);
LSO_Enums.Vector llRot2Euler(LSO_Enums.Rotation r);
LSO_Enums.Rotation llEuler2Rot(LSO_Enums.Vector v);
LSO_Enums.Rotation llAxes2Rot(LSO_Enums.Vector fwd, LSO_Enums.Vector left, LSO_Enums.Vector up);
LSO_Enums.Vector llRot2Fwd(LSO_Enums.Rotation r);
LSO_Enums.Vector llRot2Left(LSO_Enums.Rotation r);
LSO_Enums.Vector llRot2Up(LSO_Enums.Rotation r);
LSO_Enums.Rotation llRotBetween(LSO_Enums.Vector start, LSO_Enums.Vector end);
float llVecMag(Axiom.Math.Vector3 v);
Axiom.Math.Vector3 llVecNorm(Axiom.Math.Vector3 v);
float llVecDist(Axiom.Math.Vector3 a, Axiom.Math.Vector3 b);
Axiom.Math.Vector3 llRot2Euler(Axiom.Math.Quaternion r);
Axiom.Math.Quaternion llEuler2Rot(Axiom.Math.Vector3 v);
Axiom.Math.Quaternion llAxes2Rot(Axiom.Math.Vector3 fwd, Axiom.Math.Vector3 left, Axiom.Math.Vector3 up);
Axiom.Math.Vector3 llRot2Fwd(Axiom.Math.Quaternion r);
Axiom.Math.Vector3 llRot2Left(Axiom.Math.Quaternion r);
Axiom.Math.Vector3 llRot2Up(Axiom.Math.Quaternion r);
Axiom.Math.Quaternion llRotBetween(Axiom.Math.Vector3 start, Axiom.Math.Vector3 end);
void llWhisper(UInt16 channelID, string text);
//void llSay(UInt32 channelID, string text);
void llSay(object channelID, object text);
void llShout(UInt16 channelID, string text);
UInt32 llListen(UInt16 channelID, string name, LSO_Enums.Key ID, string msg);
UInt32 llListen(UInt16 channelID, string name, string ID, string msg);
void llListenControl(UInt32 number, UInt32 active);
void llListenRemove(UInt32 number);
void llSensor(string name, LSO_Enums.Key id, UInt32 type, float range, float arc);
void llSensorRepeat(string name, LSO_Enums.Key id, UInt32 type, float range, float arc, float rate);
void llSensor(string name, string id, UInt32 type, float range, float arc);
void llSensorRepeat(string name, string id, UInt32 type, float range, float arc, float rate);
void llSensorRemove();
string llDetectedName(UInt32 number);
LSO_Enums.Key llDetectedKey(UInt32 number);
LSO_Enums.Key llDetectedOwner(UInt32 number);
string llDetectedKey(UInt32 number);
string llDetectedOwner(UInt32 number);
UInt32 llDetectedType(UInt32 number);
LSO_Enums.Vector llDetectedPos(UInt32 number);
LSO_Enums.Vector llDetectedVel(UInt32 number);
LSO_Enums.Vector llDetectedGrab(UInt32 number);
LSO_Enums.Rotation llDetectedRot(UInt32 number);
Axiom.Math.Vector3 llDetectedPos(UInt32 number);
Axiom.Math.Vector3 llDetectedVel(UInt32 number);
Axiom.Math.Vector3 llDetectedGrab(UInt32 number);
Axiom.Math.Quaternion llDetectedRot(UInt32 number);
UInt32 llDetectedGroup(UInt32 number);
UInt32 llDetectedLinkNumber(UInt32 number);
void llDie();
float llGround(LSO_Enums.Vector offset);
float llCloud(LSO_Enums.Vector offset);
LSO_Enums.Vector llWind(LSO_Enums.Vector offset);
float llGround(Axiom.Math.Vector3 offset);
float llCloud(Axiom.Math.Vector3 offset);
Axiom.Math.Vector3 llWind(Axiom.Math.Vector3 offset);
void llSetStatus(UInt32 status, UInt32 value);
UInt32 llGetStatus(UInt32 status);
void llSetScale(LSO_Enums.Vector scale);
LSO_Enums.Vector llGetScale();
void llSetColor(LSO_Enums.Vector color, UInt32 face);
void llSetScale(Axiom.Math.Vector3 scale);
Axiom.Math.Vector3 llGetScale();
void llSetColor(Axiom.Math.Vector3 color, UInt32 face);
float llGetAlpha(UInt32 face);
void llSetAlpha(float alpha, UInt32 face);
LSO_Enums.Vector llGetColor(UInt32 face);
Axiom.Math.Vector3 llGetColor(UInt32 face);
void llSetTexture(string texture, UInt32 face);
void llScaleTexture(float u, float v, UInt32 face);
void llOffsetTexture(float u, float v, UInt32 face);
void llRotateTexture(float rotation, UInt32 face);
string llGetTexture(UInt32 face);
void llSetPos(LSO_Enums.Vector pos);
void llSetPos(Axiom.Math.Vector3 pos);
void llGetPos();
void llGetLocalPos();

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright (c) Contributors, http://www.openmetaverse.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
@ -30,7 +30,7 @@ using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler
{
public class LSL_BuiltIn_Commands_TestImplementation : LSL_BuiltIn_Commands_Interface
{
@ -52,16 +52,16 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
public UInt32 llFloor(float f) { return 0; }
public UInt32 llCeil(float f) { return 0; }
public UInt32 llRound(float f) { return 0; }
public float llVecMag(LSO_Enums.Vector v) { return 0; }
public LSO_Enums.Vector llVecNorm(LSO_Enums.Vector v) { return new LSO_Enums.Vector(); }
public float llVecDist(LSO_Enums.Vector a, LSO_Enums.Vector b) { return 0; }
public LSO_Enums.Vector llRot2Euler(LSO_Enums.Rotation r) { return new LSO_Enums.Vector(); }
public LSO_Enums.Rotation llEuler2Rot(LSO_Enums.Vector v) { return new LSO_Enums.Rotation(); }
public LSO_Enums.Rotation llAxes2Rot(LSO_Enums.Vector fwd, LSO_Enums.Vector left, LSO_Enums.Vector up) { return new LSO_Enums.Rotation(); }
public LSO_Enums.Vector llRot2Fwd(LSO_Enums.Rotation r) { return new LSO_Enums.Vector(); }
public LSO_Enums.Vector llRot2Left(LSO_Enums.Rotation r) { return new LSO_Enums.Vector(); }
public LSO_Enums.Vector llRot2Up(LSO_Enums.Rotation r) { return new LSO_Enums.Vector(); }
public LSO_Enums.Rotation llRotBetween(LSO_Enums.Vector start, LSO_Enums.Vector end) { return new LSO_Enums.Rotation(); }
public float llVecMag(Axiom.Math.Vector3 v) { return 0; }
public Axiom.Math.Vector3 llVecNorm(Axiom.Math.Vector3 v) { return new Axiom.Math.Vector3(); }
public float llVecDist(Axiom.Math.Vector3 a, Axiom.Math.Vector3 b) { return 0; }
public Axiom.Math.Vector3 llRot2Euler(Axiom.Math.Quaternion r) { return new Axiom.Math.Vector3(); }
public Axiom.Math.Quaternion llEuler2Rot(Axiom.Math.Vector3 v) { return new Axiom.Math.Quaternion(); }
public Axiom.Math.Quaternion llAxes2Rot(Axiom.Math.Vector3 fwd, Axiom.Math.Vector3 left, Axiom.Math.Vector3 up) { return new Axiom.Math.Quaternion(); }
public Axiom.Math.Vector3 llRot2Fwd(Axiom.Math.Quaternion r) { return new Axiom.Math.Vector3(); }
public Axiom.Math.Vector3 llRot2Left(Axiom.Math.Quaternion r) { return new Axiom.Math.Vector3(); }
public Axiom.Math.Vector3 llRot2Up(Axiom.Math.Quaternion r) { return new Axiom.Math.Vector3(); }
public Axiom.Math.Quaternion llRotBetween(Axiom.Math.Vector3 start, Axiom.Math.Vector3 end) { return new Axiom.Math.Quaternion(); }
public void llWhisper(UInt16 channelID, string text)
{
Common.SendToDebug("INTERNAL FUNCTION llWhisper(" + channelID + ", \"" + text + "\");");
@ -75,40 +75,40 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
Common.SendToLog("llSay Channel " + (UInt32)channelID + ", Text: \"" + (string)text + "\"");
}
public void llShout(UInt16 channelID, string text) { return; }
public UInt32 llListen(UInt16 channelID, string name, LSO_Enums.Key ID, string msg) { return 0; }
public UInt32 llListen(UInt16 channelID, string name, string ID, string msg) { return 0; }
public void llListenControl(UInt32 number, UInt32 active) { return; }
public void llListenRemove(UInt32 number) { return; }
public void llSensor(string name, LSO_Enums.Key id, UInt32 type, float range, float arc) { return; }
public void llSensorRepeat(string name, LSO_Enums.Key id, UInt32 type, float range, float arc, float rate) { return; }
public void llSensor(string name, string id, UInt32 type, float range, float arc) { return; }
public void llSensorRepeat(string name, string id, UInt32 type, float range, float arc, float rate) { return; }
public void llSensorRemove() { return; }
public string llDetectedName(UInt32 number) { return ""; }
public LSO_Enums.Key llDetectedKey(UInt32 number) { return new LSO_Enums.Key(); }
public LSO_Enums.Key llDetectedOwner(UInt32 number) { return new LSO_Enums.Key(); }
public string llDetectedKey(UInt32 number) { return ""; }
public string llDetectedOwner(UInt32 number) { return ""; }
public UInt32 llDetectedType(UInt32 number) { return 0; }
public LSO_Enums.Vector llDetectedPos(UInt32 number) { return new LSO_Enums.Vector(); }
public LSO_Enums.Vector llDetectedVel(UInt32 number) { return new LSO_Enums.Vector(); }
public LSO_Enums.Vector llDetectedGrab(UInt32 number) { return new LSO_Enums.Vector(); }
public LSO_Enums.Rotation llDetectedRot(UInt32 number) { return new LSO_Enums.Rotation(); }
public Axiom.Math.Vector3 llDetectedPos(UInt32 number) { return new Axiom.Math.Vector3(); }
public Axiom.Math.Vector3 llDetectedVel(UInt32 number) { return new Axiom.Math.Vector3(); }
public Axiom.Math.Vector3 llDetectedGrab(UInt32 number) { return new Axiom.Math.Vector3(); }
public Axiom.Math.Quaternion llDetectedRot(UInt32 number) { return new Axiom.Math.Quaternion(); }
public UInt32 llDetectedGroup(UInt32 number) { return 0; }
public UInt32 llDetectedLinkNumber(UInt32 number) { return 0; }
public void llDie() { return; }
public float llGround(LSO_Enums.Vector offset) { return 0; }
public float llCloud(LSO_Enums.Vector offset) { return 0; }
public LSO_Enums.Vector llWind(LSO_Enums.Vector offset) { return new LSO_Enums.Vector(); }
public float llGround(Axiom.Math.Vector3 offset) { return 0; }
public float llCloud(Axiom.Math.Vector3 offset) { return 0; }
public Axiom.Math.Vector3 llWind(Axiom.Math.Vector3 offset) { return new Axiom.Math.Vector3(); }
public void llSetStatus(UInt32 status, UInt32 value) { return; }
public UInt32 llGetStatus(UInt32 status) { return 0; }
public void llSetScale(LSO_Enums.Vector scale) { return; }
public LSO_Enums.Vector llGetScale() { return new LSO_Enums.Vector(); }
public void llSetColor(LSO_Enums.Vector color, UInt32 face) { return; }
public void llSetScale(Axiom.Math.Vector3 scale) { return; }
public Axiom.Math.Vector3 llGetScale() { return new Axiom.Math.Vector3(); }
public void llSetColor(Axiom.Math.Vector3 color, UInt32 face) { return; }
public float llGetAlpha(UInt32 face) { return 0; }
public void llSetAlpha(float alpha, UInt32 face) { return; }
public LSO_Enums.Vector llGetColor(UInt32 face) { return new LSO_Enums.Vector(); }
public Axiom.Math.Vector3 llGetColor(UInt32 face) { return new Axiom.Math.Vector3(); }
public void llSetTexture(string texture, UInt32 face) { return; }
public void llScaleTexture(float u, float v, UInt32 face) { return; }
public void llOffsetTexture(float u, float v, UInt32 face) { return; }
public void llRotateTexture(float rotation, UInt32 face) { return; }
public string llGetTexture(UInt32 face) { return ""; }
public void llSetPos(LSO_Enums.Vector pos) { return; }
public void llSetPos(Axiom.Math.Vector3 pos) { return; }
public void llGetPos() { }

View File

@ -137,7 +137,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
SetScript(ObjectID, ScriptID, Script);
// We need to give (untrusted) assembly a private instance of BuiltIns
// this private copy will contain Read-Only FullScriptID so that it can bring that on to the server whenever needed.
OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BuiltIn_Commands_Interface LSLB = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BuiltIn_Commands_TestImplementation(FullScriptID);
OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL_BuiltIn_Commands_Interface LSLB = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL_BuiltIn_Commands_TestImplementation(FullScriptID);
// Start the script - giving it BuiltIns
Common.SendToDebug("ScriptManager initializing script, handing over private builtin command interface");
Script.Start(LSLB);

View File

@ -951,14 +951,9 @@
<Reference name="System.Data" localCopy="false"/>
<Reference name="System.Xml" localCopy="false"/>
<Reference name="OpenSim.Region.Environment" />
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Framework.Console"/>
<Reference name="OpenSim.Framework.Data"/>
<Reference name="OpenSim.Framework.Servers"/>
<Reference name="OpenSim.Framework.UserManagement" />
<Reference name="Axiom.MathLib.dll" localCopy="false"/>
<Reference name="libsecondlife.dll"/>
<Reference name="Db4objects.Db4o.dll"/>
<Reference name="XMLRPC.dll"/>
<Reference name="OpenSim.Framework"/>
<Files>
<Match pattern="*.cs" recurse="true"/>
<Match pattern="*.lso" recurse="true"/>