stop using yengine math inlines, this have cast issues, just use lsl api, plus cosmetics

This commit is contained in:
UbitUmarov
2020-09-25 02:38:00 +01:00
parent c919b07642
commit a2534dc378
4 changed files with 79 additions and 73 deletions

View File

@@ -185,32 +185,32 @@ namespace OpenSim.Region.ScriptEngine.Yengine
{
cv = new CompValuChar(new TokenTypeChar(null), (char)value);
}
if(value is double)
else if (value is double)
{
cv = new CompValuFloat(new TokenTypeFloat(null), (double)(double)value);
}
if(value is float)
else if (value is float)
{
cv = new CompValuFloat(new TokenTypeFloat(null), (double)(float)value);
}
if(value is int)
else if (value is int)
{
cv = new CompValuInteger(new TokenTypeInt(null), (int)value);
}
if(value is string)
else if (value is string)
{
cv = new CompValuString(new TokenTypeStr(null), (string)value);
}
if(value is LSL_Float)
else if (value is LSL_Float)
{
cv = new CompValuFloat(new TokenTypeFloat(null), (double)((LSL_Float)value).value);
}
if(value is LSL_Integer)
else if (value is LSL_Integer)
{
cv = new CompValuInteger(new TokenTypeInt(null), ((LSL_Integer)value).value);
}
if(value is LSL_Rotation)
else if (value is LSL_Rotation)
{
LSL_Rotation r = (LSL_Rotation)value;
CompValu x = new CompValuFloat(new TokenTypeFloat(null), r.x);
@@ -219,11 +219,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine
CompValu s = new CompValuFloat(new TokenTypeFloat(null), r.s);
cv = new CompValuRot(new TokenTypeRot(null), x, y, z, s);
}
if(value is LSL_String)
else if (value is LSL_String)
{
cv = new CompValuString(new TokenTypeStr(null), (string)(LSL_String)value);
}
if(value is LSL_Vector)
else if (value is LSL_Vector)
{
LSL_Vector v = (LSL_Vector)value;
CompValu x = new CompValuFloat(new TokenTypeFloat(null), v.x);
@@ -232,7 +232,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
cv = new CompValuVec(new TokenTypeVec(null), x, y, z);
}
if(value is OpenMetaverse.Quaternion)
else if (value is OpenMetaverse.Quaternion)
{
OpenMetaverse.Quaternion r = (OpenMetaverse.Quaternion)value;
CompValu x = new CompValuFloat(new TokenTypeFloat(null), r.X);
@@ -241,11 +241,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine
CompValu s = new CompValuFloat(new TokenTypeFloat(null), r.W);
cv = new CompValuRot(new TokenTypeRot(null), x, y, z, s);
}
if(value is OpenMetaverse.UUID)
else if (value is OpenMetaverse.UUID)
{
cv = new CompValuString(new TokenTypeKey(null), value.ToString());
}
if(value is OpenMetaverse.Vector3)
else if (value is OpenMetaverse.Vector3)
{
OpenMetaverse.Vector3 v = (OpenMetaverse.Vector3)value;
CompValu x = new CompValuFloat(new TokenTypeFloat(null), v.X);

View File

@@ -50,7 +50,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
public abstract void CodeGen(ScriptCodeGen scg, Token errorAt, CompValuTemp result, CompValu[] args);
private static string[] noCheckRuns;
private static HashSet<string> noCheckRuns;
private static string[] keyReturns;
protected bool isTaggedCallsCheckRun;
@@ -64,7 +64,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
* For those listed in noCheckRun, we just generate the call (simple computations).
* For all others, we generate the call then a call to CheckRun().
*/
noCheckRuns = new string[] {
noCheckRuns = new HashSet<string>() {
"llBase64ToString",
"llCSV2List",
"llDeleteSubList",
@@ -100,7 +100,18 @@ namespace OpenSim.Region.ScriptEngine.Yengine
"llStringToBase64",
"llStringTrim",
"llSubStringIndex",
"llUnescapeURL"
"llUnescapeURL",
"osGetSitActiveRange",
"osIsNotValidNumber",
"osSlerp",
"osApproxEquals",
"osVecDistSquare",
"osVecMagSquare",
"osRound",
"osGetLinkNumber",
"osMax",
"osMin",
"osIsUUID"
};
/*
@@ -144,21 +155,21 @@ namespace OpenSim.Region.ScriptEngine.Yengine
/*
* Mono generates an FPU instruction for many math calls.
*/
new TokenDeclInline_LLAbs(ifd);
new TokenDeclInline_Math(ifd, "llAcos(float)", "Acos", oneDoub);
new TokenDeclInline_Math(ifd, "llAsin(float)", "Asin", oneDoub);
new TokenDeclInline_Math(ifd, "llAtan2(float,float)", "Atan2", twoDoubs);
new TokenDeclInline_Math(ifd, "llCos(float)", "Cos", oneDoub);
new TokenDeclInline_Math(ifd, "llFabs(float)", "Abs", oneDoub);
new TokenDeclInline_Math(ifd, "llLog(float)", "Log", oneDoub);
new TokenDeclInline_Math(ifd, "llLog10(float)", "Log10", oneDoub);
new TokenDeclInline_Math(ifd, "llPow(float,float)", "Pow", twoDoubs);
new TokenDeclInline_LLRound(ifd);
new TokenDeclInline_Math(ifd, "llSin(float)", "Sin", oneDoub);
new TokenDeclInline_Math(ifd, "llSqrt(float)", "Sqrt", oneDoub);
new TokenDeclInline_Math(ifd, "llTan(float)", "Tan", oneDoub);
/* just use lsl api alos this have cast issues
new TokenDeclInline_LLAbs(ifd);
new TokenDeclInline_Math(ifd, "llAcos(float)", "Acos", oneDoub);
new TokenDeclInline_Math(ifd, "llAsin(float)", "Asin", oneDoub);
new TokenDeclInline_Math(ifd, "llAtan2(float,float)", "Atan2", twoDoubs);
new TokenDeclInline_Math(ifd, "llCos(float)", "Cos", oneDoub);
new TokenDeclInline_Math(ifd, "llFabs(float)", "Abs", oneDoub);
new TokenDeclInline_Math(ifd, "llLog(float)", "Log", oneDoub);
new TokenDeclInline_Math(ifd, "llLog10(float)", "Log10", oneDoub);
new TokenDeclInline_Math(ifd, "llPow(float,float)", "Pow", twoDoubs);
new TokenDeclInline_LLRound(ifd);
new TokenDeclInline_Math(ifd, "llSin(float)", "Sin", oneDoub);
new TokenDeclInline_Math(ifd, "llSqrt(float)", "Sqrt", oneDoub);
new TokenDeclInline_Math(ifd, "llTan(float)", "Tan", oneDoub);
*/
/*
* Something weird about the code generation for these calls, so they all have their own handwritten code generators.
*/
@@ -218,14 +229,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
* Otherwise, assume we will call CheckRun()
*/
bool dcr = !key.StartsWith("xmr");
foreach(string ncr in noCheckRuns)
{
if(ncr == key)
{
dcr = false;
break;
}
}
if(dcr && noCheckRuns.Contains(key))
dcr = false;
/*
* Add function to dictionary.
@@ -293,14 +298,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine
MethodInfo methInfo)
: base(null, null, null)
{
TokenType retType = TokenType.FromSysType(null, methInfo.ReturnType);
this.isTaggedCallsCheckRun = IsTaggedCallsCheckRun(methInfo);
this.name = new TokenName(null, methInfo.Name);
this.retType = GetRetType(methInfo, retType);
this.argDecl = GetArgDecl(methInfo.GetParameters());
this.triviality = (doCheckRun || this.isTaggedCallsCheckRun) ? Triviality.complex : Triviality.trivial;
this.location = new CompValuInline(this);
isTaggedCallsCheckRun = IsTaggedCallsCheckRun(methInfo);
name = new TokenName(null, methInfo.Name);
retType = GetRetType(methInfo, TokenType.FromSysType(null, methInfo.ReturnType));
argDecl = GetArgDecl(methInfo.GetParameters());
triviality = (doCheckRun || isTaggedCallsCheckRun) ? Triviality.complex : Triviality.trivial;
location = new CompValuInline(this);
if(ifd == null)
ifd = inlineFunctions;

View File

@@ -2594,33 +2594,35 @@ public abstract class TokenType: Token
public static TokenType FromLSLType(Token original, string typ)
{
if(typ == "list")
return new TokenTypeList(original);
if(typ == "rotation")
return new TokenTypeRot(original);
if(typ == "vector")
return new TokenTypeVec(original);
if(typ == "float")
return new TokenTypeFloat(original);
if(typ == "integer")
return new TokenTypeInt(original);
if(typ == "key")
return new TokenTypeKey(original);
if(typ == "string")
return new TokenTypeStr(original);
if(typ == "object")
return new TokenTypeObject(original);
if(typ == "array")
return new TokenTypeArray(original);
if(typ == "bool")
return new TokenTypeBool(original);
if(typ == "void")
return new TokenTypeVoid(original);
if(typ == "char")
return new TokenTypeChar(original);
if(typ == "exception")
return new TokenTypeExc(original);
switch(typ)
{
case "list":
return new TokenTypeList(original);
case "rotation":
return new TokenTypeRot(original);
case "vector":
return new TokenTypeVec(original);
case "float":
return new TokenTypeFloat(original);
case "integer":
return new TokenTypeInt(original);
case "key":
return new TokenTypeKey(original);
case "string":
return new TokenTypeStr(original);
case "object":
return new TokenTypeObject(original);
case "array":
return new TokenTypeArray(original);
case "bool":
return new TokenTypeBool(original);
case "void":
return new TokenTypeVoid(original);
case "char":
return new TokenTypeChar(original);
case "exception":
return new TokenTypeExc(original);
}
throw new Exception("unknown type " + typ);
}

View File

@@ -638,6 +638,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
callNo = sf.callNo;
stackFrames = sf.nextSF;
sf.nextSF = null;
return sf.objArray;
}