MMRScriptBinOpStr.cs 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using System.Reflection.Emit;
  31. using System.Runtime.CompilerServices;
  32. using System.Text.RegularExpressions;
  33. using OpenSim.Region.ScriptEngine.Shared;
  34. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  35. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  36. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  37. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  38. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  39. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  40. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  41. namespace OpenSim.Region.ScriptEngine.Yengine
  42. {
  43. /**
  44. * @brief This class is used to catalog the code emit routines based on a key string
  45. * The key string has the two types (eg, "integer", "rotation") and the operator (eg, "*", "!=")
  46. */
  47. public delegate void BinOpStrEmitBO(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result);
  48. public class BinOpStr
  49. {
  50. public static readonly Dictionary<string, BinOpStr> defined = DefineBinOps();
  51. public Type outtype; // type of result of computation
  52. public BinOpStrEmitBO emitBO; // how to compute result
  53. public bool rmwOK; // is the <operator>= form valid?
  54. public BinOpStr(Type outtype, BinOpStrEmitBO emitBO)
  55. {
  56. this.outtype = outtype;
  57. this.emitBO = emitBO;
  58. this.rmwOK = false;
  59. }
  60. public BinOpStr(Type outtype, BinOpStrEmitBO emitBO, bool rmwOK)
  61. {
  62. this.outtype = outtype;
  63. this.emitBO = emitBO;
  64. this.rmwOK = rmwOK;
  65. }
  66. private static TokenTypeBool tokenTypeBool = new TokenTypeBool(null);
  67. private static TokenTypeChar tokenTypeChar = new TokenTypeChar(null);
  68. private static TokenTypeFloat tokenTypeFloat = new TokenTypeFloat(null);
  69. private static TokenTypeInt tokenTypeInt = new TokenTypeInt(null);
  70. private static TokenTypeList tokenTypeList = new TokenTypeList(null);
  71. private static TokenTypeRot tokenTypeRot = new TokenTypeRot(null);
  72. private static TokenTypeStr tokenTypeStr = new TokenTypeStr(null);
  73. private static TokenTypeVec tokenTypeVec = new TokenTypeVec(null);
  74. private static MethodInfo stringAddStringMethInfo = GetBinOpsMethod("StringConcat", [typeof(string), typeof(string)]);
  75. private static MethodInfo stringCmpStringMethInfo = GetBinOpsMethod("StringCompareOrdinal", [typeof(string), typeof(string)]);
  76. private static MethodInfo infoMethListAddFloat = GetBinOpsMethod("MethListAddFloat", [typeof(LSL_List), typeof(double)]);
  77. private static MethodInfo infoMethListAddInt = GetBinOpsMethod("MethListAddInt", [typeof(LSL_List), typeof(int)]);
  78. private static MethodInfo infoMethListAddKey = GetBinOpsMethod("MethListAddKey", [typeof(LSL_List), typeof(string)]);
  79. private static MethodInfo infoMethListAddRot = GetBinOpsMethod("MethListAddRot", [typeof(LSL_List), typeof(LSL_Rotation)]);
  80. private static MethodInfo infoMethListAddStr = GetBinOpsMethod("MethListAddStr", [typeof(LSL_List), typeof(string)]);
  81. private static MethodInfo infoMethListAddVec = GetBinOpsMethod("MethListAddVec", [typeof(LSL_List), typeof(LSL_Vector)]);
  82. private static MethodInfo infoMethListAddList = GetBinOpsMethod("MethListAddList", [typeof(LSL_List), typeof(LSL_List)]);
  83. private static MethodInfo infoMethFloatAddList = GetBinOpsMethod("MethFloatAddList", [typeof(double), typeof(LSL_List)]);
  84. private static MethodInfo infoMethIntAddList = GetBinOpsMethod("MethIntAddList", [typeof(int), typeof(LSL_List)]);
  85. private static MethodInfo infoMethKeyAddList = GetBinOpsMethod("MethKeyAddList", [typeof(string), typeof(LSL_List)]);
  86. private static MethodInfo infoMethRotAddList = GetBinOpsMethod("MethRotAddList", [typeof(LSL_Rotation), typeof(LSL_List)]);
  87. private static MethodInfo infoMethStrAddList = GetBinOpsMethod("MethStrAddList", [typeof(string), typeof(LSL_List)]);
  88. private static MethodInfo infoMethVecAddList = GetBinOpsMethod("MethVecAddList", [typeof(LSL_Vector), typeof(LSL_List)]);
  89. private static MethodInfo infoMethListEqList = GetBinOpsMethod("MethListEqList", [typeof(LSL_List), typeof(LSL_List)]);
  90. private static MethodInfo infoMethListNeList = GetBinOpsMethod("MethListNeList", [typeof(LSL_List), typeof(LSL_List)]);
  91. private static MethodInfo infoMethRotEqRot = GetBinOpsMethod("MethRotEqRot", [typeof(LSL_Rotation), typeof(LSL_Rotation)]);
  92. private static MethodInfo infoMethRotNeRot = GetBinOpsMethod("MethRotNeRot", [typeof(LSL_Rotation), typeof(LSL_Rotation)]);
  93. private static MethodInfo infoMethRotAddRot = GetBinOpsMethod("MethRotAddRot", [typeof(LSL_Rotation), typeof(LSL_Rotation)]);
  94. private static MethodInfo infoMethRotSubRot = GetBinOpsMethod("MethRotSubRot", [typeof(LSL_Rotation), typeof(LSL_Rotation)]);
  95. private static MethodInfo infoMethRotMulRot = GetBinOpsMethod("MethRotMulRot", [typeof(LSL_Rotation), typeof(LSL_Rotation)]);
  96. private static MethodInfo infoMethRotDivRot = GetBinOpsMethod("MethRotDivRot", [typeof(LSL_Rotation), typeof(LSL_Rotation)]);
  97. private static MethodInfo infoMethVecEqVec = GetBinOpsMethod("MethVecEqVec", [typeof(LSL_Vector), typeof(LSL_Vector)]);
  98. private static MethodInfo infoMethVecNeVec = GetBinOpsMethod("MethVecNeVec", [typeof(LSL_Vector), typeof(LSL_Vector)]);
  99. private static MethodInfo infoMethVecAddVec = GetBinOpsMethod("MethVecAddVec", [typeof(LSL_Vector), typeof(LSL_Vector)]);
  100. private static MethodInfo infoMethVecSubVec = GetBinOpsMethod("MethVecSubVec", [typeof(LSL_Vector), typeof(LSL_Vector)]);
  101. private static MethodInfo infoMethVecMulVec = GetBinOpsMethod("MethVecMulVec", [typeof(LSL_Vector), typeof(LSL_Vector)]);
  102. private static MethodInfo infoMethVecModVec = GetBinOpsMethod("MethVecModVec", [typeof(LSL_Vector), typeof(LSL_Vector)]);
  103. private static MethodInfo infoMethVecMulFloat = GetBinOpsMethod("MethVecMulFloat", [typeof(LSL_Vector), typeof(double)]);
  104. private static MethodInfo infoMethFloatMulVec = GetBinOpsMethod("MethFloatMulVec", [typeof(double), typeof(LSL_Vector)]);
  105. private static MethodInfo infoMethVecDivFloat = GetBinOpsMethod("MethVecDivFloat", [typeof(LSL_Vector), typeof(double)]);
  106. private static MethodInfo infoMethVecMulInt = GetBinOpsMethod("MethVecMulInt", [typeof(LSL_Vector), typeof(int)]);
  107. private static MethodInfo infoMethIntMulVec = GetBinOpsMethod("MethIntMulVec", [typeof(int), typeof(LSL_Vector)]);
  108. private static MethodInfo infoMethVecDivInt = GetBinOpsMethod("MethVecDivInt", [typeof(LSL_Vector), typeof(int)]);
  109. private static MethodInfo infoMethVecMulRot = GetBinOpsMethod("MethVecMulRot", [typeof(LSL_Vector), typeof(LSL_Rotation)]);
  110. private static MethodInfo infoMethVecDivRot = GetBinOpsMethod("MethVecDivRot", [typeof(LSL_Vector), typeof(LSL_Rotation)]);
  111. private static MethodInfo infoMethDoubleDivDouble = GetBinOpsMethod("MethDoubleDivDouble", [typeof(double), typeof(double)]);
  112. private static MethodInfo infoMethLongDivLong = GetBinOpsMethod("MethLongDivLong", [typeof(long), typeof(long)]);
  113. private static MethodInfo infoMethDoubleModDouble = GetBinOpsMethod("MethDoubleModDouble", [typeof(double), typeof(double)]);
  114. private static MethodInfo infoMethLongModLong = GetBinOpsMethod("MethLongModLong", [typeof(long), typeof(long)]);
  115. private static MethodInfo GetBinOpsMethod(string name, Type[] types)
  116. {
  117. return ScriptCodeGen.GetStaticMethod(typeof(BinOpStr), name, types);
  118. }
  119. /**
  120. * @brief Create a dictionary for processing binary operators.
  121. * This tells us, for a given type, an operator and another type,
  122. * is the operation permitted, and if so, what is the type of the result?
  123. * The key is <lefttype><opcode><righttype>,
  124. * where <lefttype> and <righttype> are strings returned by (TokenType...).ToString()
  125. * and <opcode> is string returned by (TokenKw...).ToString()
  126. * The value is a BinOpStr struct giving the resultant type and a method to generate the code.
  127. */
  128. private static Dictionary<string, BinOpStr> DefineBinOps()
  129. {
  130. Dictionary<string, BinOpStr> bos = new Dictionary<string, BinOpStr>();
  131. string[] booltypes = ["bool", "char", "float", "integer", "key", "list", "string"];
  132. /*
  133. * Get the && and || all out of the way...
  134. * Simply cast their left and right operands to boolean then process.
  135. */
  136. for(int i = 0; i < booltypes.Length; i++)
  137. {
  138. for(int j = 0; j < booltypes.Length; j++)
  139. {
  140. bos.Add(booltypes[i] + "&&" + booltypes[j], new BinOpStr(typeof(bool), BinOpStrAndAnd));
  141. bos.Add(booltypes[i] + "||" + booltypes[j], new BinOpStr(typeof(bool), BinOpStrOrOr));
  142. }
  143. }
  144. /*
  145. * Pound through all the other combinations we support.
  146. */
  147. // boolean : somethingelse
  148. DefineBinOpsBoolX(bos, "bool");
  149. DefineBinOpsBoolX(bos, "char");
  150. DefineBinOpsBoolX(bos, "float");
  151. DefineBinOpsBoolX(bos, "integer");
  152. DefineBinOpsBoolX(bos, "key");
  153. DefineBinOpsBoolX(bos, "list");
  154. DefineBinOpsBoolX(bos, "string");
  155. // stuff with chars
  156. DefineBinOpsChar(bos);
  157. // somethingelse : boolean
  158. DefineBinOpsXBool(bos, "char");
  159. DefineBinOpsXBool(bos, "float");
  160. DefineBinOpsXBool(bos, "integer");
  161. DefineBinOpsXBool(bos, "key");
  162. DefineBinOpsXBool(bos, "list");
  163. DefineBinOpsXBool(bos, "string");
  164. // float : somethingelse
  165. DefineBinOpsFloatX(bos, "float");
  166. DefineBinOpsFloatX(bos, "integer");
  167. // integer : float
  168. DefineBinOpsXFloat(bos, "integer");
  169. // anything else with integers
  170. DefineBinOpsInteger(bos);
  171. // key : somethingelse
  172. DefineBinOpsKeyX(bos, "key");
  173. DefineBinOpsKeyX(bos, "string");
  174. // string : key
  175. DefineBinOpsXKey(bos, "string");
  176. // things with lists
  177. DefineBinOpsList(bos);
  178. // things with rotations
  179. DefineBinOpsRotation(bos);
  180. // things with strings
  181. DefineBinOpsString(bos);
  182. // things with vectors
  183. DefineBinOpsVector(bos);
  184. // Contrary to some beliefs, scripts do things like string+integer and integer+string
  185. bos.Add("bool+string", new BinOpStr(typeof(string), BinOpStrStrAddStr));
  186. bos.Add("char+string", new BinOpStr(typeof(string), BinOpStrStrAddStr));
  187. bos.Add("float+string", new BinOpStr(typeof(string), BinOpStrStrAddStr));
  188. bos.Add("integer+string", new BinOpStr(typeof(string), BinOpStrStrAddStr));
  189. bos.Add("string+bool", new BinOpStr(typeof(string), BinOpStrStrAddStr, true));
  190. bos.Add("string+char", new BinOpStr(typeof(string), BinOpStrStrAddStr, true));
  191. bos.Add("string+float", new BinOpStr(typeof(string), BinOpStrStrAddStr, true));
  192. bos.Add("string+integer", new BinOpStr(typeof(string), BinOpStrStrAddStr, true));
  193. // Now for our final slight-of-hand, we're going to scan through all those.
  194. // And wherever we see an 'integer' in the key, we are going to make another
  195. // entry with 'bool', as we want to accept a bool as having a value of 0 or 1.
  196. // This lets us do things like 3.5 * (x > 0).
  197. Dictionary<string, BinOpStr> bos2 = new Dictionary<string, BinOpStr>();
  198. foreach(KeyValuePair<string, BinOpStr> kvp in bos)
  199. {
  200. string key = kvp.Key;
  201. BinOpStr val = kvp.Value;
  202. bos2.Add(key, val);
  203. }
  204. Regex wordReg = new Regex("\\w+");
  205. Regex opReg = new Regex("\\W+");
  206. foreach(KeyValuePair<string, BinOpStr> kvp in bos)
  207. {
  208. string key = kvp.Key;
  209. BinOpStr val = kvp.Value;
  210. MatchCollection matches = wordReg.Matches(key);
  211. if(matches.Count != 2)
  212. continue;
  213. Match opM = opReg.Match(key);
  214. if(!opM.Success)
  215. continue;
  216. string left = matches[0].Value;
  217. string right = matches[1].Value;
  218. string op = opM.Value;
  219. string key2;
  220. if(left == "integer" && right == "integer")
  221. {
  222. key2 = "bool" + op + "bool";
  223. if(!bos2.ContainsKey(key2))
  224. bos2.Add(key2, val);
  225. key2 = "bool" + op + "integer";
  226. if(!bos2.ContainsKey(key2))
  227. bos2.Add(key2, val);
  228. key2 = "integer" + op + "bool";
  229. if(!bos2.ContainsKey(key2))
  230. bos2.Add(key2, val);
  231. }
  232. else
  233. {
  234. key2 = key.Replace("integer", "bool");
  235. if(!bos2.ContainsKey(key2))
  236. bos2.Add(key2, val);
  237. }
  238. }
  239. return bos2;
  240. }
  241. private static void DefineBinOpsBoolX(Dictionary<string, BinOpStr> bos, string x)
  242. {
  243. bos.Add("bool|" + x, new BinOpStr(typeof(int), BinOpStrBoolOrX));
  244. bos.Add("bool^" + x, new BinOpStr(typeof(int), BinOpStrBoolXorX));
  245. bos.Add("bool&" + x, new BinOpStr(typeof(int), BinOpStrBoolAndX));
  246. bos.Add("bool==" + x, new BinOpStr(typeof(bool), BinOpStrBoolEqX));
  247. bos.Add("bool!=" + x, new BinOpStr(typeof(bool), BinOpStrBoolNeX));
  248. }
  249. private static void DefineBinOpsXBool(Dictionary<string, BinOpStr> bos, string x)
  250. {
  251. bos.Add(x + "|bool", new BinOpStr(typeof(int), BinOpStrBoolOrX));
  252. bos.Add(x + "^bool", new BinOpStr(typeof(int), BinOpStrBoolXorX));
  253. bos.Add(x + "&bool", new BinOpStr(typeof(int), BinOpStrBoolAndX));
  254. bos.Add(x + "==bool", new BinOpStr(typeof(bool), BinOpStrBoolEqX));
  255. bos.Add(x + "!=bool", new BinOpStr(typeof(bool), BinOpStrBoolNeX));
  256. }
  257. private static void DefineBinOpsFloatX(Dictionary<string, BinOpStr> bos, string x)
  258. {
  259. bos.Add("float==" + x, new BinOpStr(typeof(bool), BinOpStrFloatEqX));
  260. bos.Add("float!=" + x, new BinOpStr(typeof(bool), BinOpStrFloatNeX));
  261. bos.Add("float<" + x, new BinOpStr(typeof(bool), BinOpStrFloatLtX));
  262. bos.Add("float<=" + x, new BinOpStr(typeof(bool), BinOpStrFloatLeX));
  263. bos.Add("float>" + x, new BinOpStr(typeof(bool), BinOpStrFloatGtX));
  264. bos.Add("float>=" + x, new BinOpStr(typeof(bool), BinOpStrFloatGeX));
  265. bos.Add("float+" + x, new BinOpStr(typeof(double), BinOpStrFloatAddX, true));
  266. bos.Add("float-" + x, new BinOpStr(typeof(double), BinOpStrFloatSubX, true));
  267. bos.Add("float*" + x, new BinOpStr(typeof(double), BinOpStrFloatMulX, true));
  268. bos.Add("float/" + x, new BinOpStr(typeof(double), BinOpStrFloatDivX, true));
  269. bos.Add("float%" + x, new BinOpStr(typeof(double), BinOpStrFloatModX, true));
  270. }
  271. private static void DefineBinOpsXFloat(Dictionary<string, BinOpStr> bos, string x)
  272. {
  273. bos.Add(x + "==float", new BinOpStr(typeof(bool), BinOpStrXEqFloat));
  274. bos.Add(x + "!=float", new BinOpStr(typeof(bool), BinOpStrXNeFloat));
  275. bos.Add(x + "<float", new BinOpStr(typeof(bool), BinOpStrXLtFloat));
  276. bos.Add(x + "<=float", new BinOpStr(typeof(bool), BinOpStrXLeFloat));
  277. bos.Add(x + ">float", new BinOpStr(typeof(bool), BinOpStrXGtFloat));
  278. bos.Add(x + ">=float", new BinOpStr(typeof(bool), BinOpStrXGeFloat));
  279. bos.Add(x + "+float", new BinOpStr(typeof(double), BinOpStrXAddFloat, true));
  280. bos.Add(x + "-float", new BinOpStr(typeof(double), BinOpStrXSubFloat, true));
  281. bos.Add(x + "*float", new BinOpStr(typeof(double), BinOpStrXMulFloat, true));
  282. bos.Add(x + "/float", new BinOpStr(typeof(double), BinOpStrXDivFloat, true));
  283. bos.Add(x + "%float", new BinOpStr(typeof(double), BinOpStrXModFloat, true));
  284. }
  285. private static void DefineBinOpsChar(Dictionary<string, BinOpStr> bos)
  286. {
  287. bos.Add("char==char", new BinOpStr(typeof(bool), BinOpStrCharEqChar));
  288. bos.Add("char!=char", new BinOpStr(typeof(bool), BinOpStrCharNeChar));
  289. bos.Add("char<char", new BinOpStr(typeof(bool), BinOpStrCharLtChar));
  290. bos.Add("char<=char", new BinOpStr(typeof(bool), BinOpStrCharLeChar));
  291. bos.Add("char>char", new BinOpStr(typeof(bool), BinOpStrCharGtChar));
  292. bos.Add("char>=char", new BinOpStr(typeof(bool), BinOpStrCharGeChar));
  293. bos.Add("char+integer", new BinOpStr(typeof(char), BinOpStrCharAddInt, true));
  294. bos.Add("char-integer", new BinOpStr(typeof(char), BinOpStrCharSubInt, true));
  295. bos.Add("char-char", new BinOpStr(typeof(int), BinOpStrCharSubChar));
  296. }
  297. private static void DefineBinOpsInteger(Dictionary<string, BinOpStr> bos)
  298. {
  299. bos.Add("integer==integer", new BinOpStr(typeof(bool), BinOpStrIntEqInt));
  300. bos.Add("integer!=integer", new BinOpStr(typeof(bool), BinOpStrIntNeInt));
  301. bos.Add("integer<integer", new BinOpStr(typeof(bool), BinOpStrIntLtInt));
  302. bos.Add("integer<=integer", new BinOpStr(typeof(bool), BinOpStrIntLeInt));
  303. bos.Add("integer>integer", new BinOpStr(typeof(bool), BinOpStrIntGtInt));
  304. bos.Add("integer>=integer", new BinOpStr(typeof(bool), BinOpStrIntGeInt));
  305. bos.Add("integer|integer", new BinOpStr(typeof(int), BinOpStrIntOrInt, true));
  306. bos.Add("integer^integer", new BinOpStr(typeof(int), BinOpStrIntXorInt, true));
  307. bos.Add("integer&integer", new BinOpStr(typeof(int), BinOpStrIntAndInt, true));
  308. bos.Add("integer+integer", new BinOpStr(typeof(int), BinOpStrIntAddInt, true));
  309. bos.Add("integer-integer", new BinOpStr(typeof(int), BinOpStrIntSubInt, true));
  310. bos.Add("integer*integer", new BinOpStr(typeof(int), BinOpStrIntMulInt, true));
  311. bos.Add("integer/integer", new BinOpStr(typeof(int), BinOpStrIntDivInt, true));
  312. bos.Add("integer%integer", new BinOpStr(typeof(int), BinOpStrIntModInt, true));
  313. bos.Add("integer<<integer", new BinOpStr(typeof(int), BinOpStrIntShlInt, true));
  314. bos.Add("integer>>integer", new BinOpStr(typeof(int), BinOpStrIntShrInt, true));
  315. }
  316. private static void DefineBinOpsKeyX(Dictionary<string, BinOpStr> bos, string x)
  317. {
  318. bos.Add("key==" + x, new BinOpStr(typeof(bool), BinOpStrKeyEqX));
  319. bos.Add("key!=" + x, new BinOpStr(typeof(bool), BinOpStrKeyNeX));
  320. }
  321. private static void DefineBinOpsXKey(Dictionary<string, BinOpStr> bos, string x)
  322. {
  323. bos.Add(x + "==key", new BinOpStr(typeof(bool), BinOpStrKeyEqX));
  324. bos.Add(x + "!=key", new BinOpStr(typeof(bool), BinOpStrKeyNeX));
  325. }
  326. private static void DefineBinOpsList(Dictionary<string, BinOpStr> bos)
  327. {
  328. bos.Add("list+float", new BinOpStr(typeof(LSL_List), BinOpStrListAddFloat, true));
  329. bos.Add("list+integer", new BinOpStr(typeof(LSL_List), BinOpStrListAddInt, true));
  330. bos.Add("list+key", new BinOpStr(typeof(LSL_List), BinOpStrListAddKey, true));
  331. bos.Add("list+list", new BinOpStr(typeof(LSL_List), BinOpStrListAddList, true));
  332. bos.Add("list+rotation", new BinOpStr(typeof(LSL_List), BinOpStrListAddRot, true));
  333. bos.Add("list+string", new BinOpStr(typeof(LSL_List), BinOpStrListAddStr, true));
  334. bos.Add("list+vector", new BinOpStr(typeof(LSL_List), BinOpStrListAddVec, true));
  335. bos.Add("float+list", new BinOpStr(typeof(LSL_List), BinOpStrFloatAddList));
  336. bos.Add("integer+list", new BinOpStr(typeof(LSL_List), BinOpStrIntAddList));
  337. bos.Add("key+list", new BinOpStr(typeof(LSL_List), BinOpStrKeyAddList));
  338. bos.Add("rotation+list", new BinOpStr(typeof(LSL_List), BinOpStrRotAddList));
  339. bos.Add("string+list", new BinOpStr(typeof(LSL_List), BinOpStrStrAddList));
  340. bos.Add("vector+list", new BinOpStr(typeof(LSL_List), BinOpStrVecAddList));
  341. bos.Add("list==list", new BinOpStr(typeof(bool), BinOpStrListEqList));
  342. bos.Add("list!=list", new BinOpStr(typeof(int), BinOpStrListNeList));
  343. }
  344. // all operations allowed by LSL_Rotation definition
  345. private static void DefineBinOpsRotation(Dictionary<string, BinOpStr> bos)
  346. {
  347. bos.Add("rotation==rotation", new BinOpStr(typeof(bool), BinOpStrRotEqRot));
  348. bos.Add("rotation!=rotation", new BinOpStr(typeof(bool), BinOpStrRotNeRot));
  349. bos.Add("rotation+rotation", new BinOpStr(typeof(LSL_Rotation), BinOpStrRotAddRot, true));
  350. bos.Add("rotation-rotation", new BinOpStr(typeof(LSL_Rotation), BinOpStrRotSubRot, true));
  351. bos.Add("rotation*rotation", new BinOpStr(typeof(LSL_Rotation), BinOpStrRotMulRot, true));
  352. bos.Add("rotation/rotation", new BinOpStr(typeof(LSL_Rotation), BinOpStrRotDivRot, true));
  353. }
  354. private static void DefineBinOpsString(Dictionary<string, BinOpStr> bos)
  355. {
  356. bos.Add("string==string", new BinOpStr(typeof(bool), BinOpStrStrEqStr));
  357. bos.Add("string!=string", new BinOpStr(typeof(bool), BinOpStrStrNeStr));
  358. bos.Add("string<string", new BinOpStr(typeof(bool), BinOpStrStrLtStr));
  359. bos.Add("string<=string", new BinOpStr(typeof(bool), BinOpStrStrLeStr));
  360. bos.Add("string>string", new BinOpStr(typeof(bool), BinOpStrStrGtStr));
  361. bos.Add("string>=string", new BinOpStr(typeof(bool), BinOpStrStrGeStr));
  362. bos.Add("string+string", new BinOpStr(typeof(string), BinOpStrStrAddStr, true));
  363. }
  364. // all operations allowed by LSL_Vector definition
  365. private static void DefineBinOpsVector(Dictionary<string, BinOpStr> bos)
  366. {
  367. bos.Add("vector==vector", new BinOpStr(typeof(bool), BinOpStrVecEqVec));
  368. bos.Add("vector!=vector", new BinOpStr(typeof(bool), BinOpStrVecNeVec));
  369. bos.Add("vector+vector", new BinOpStr(typeof(LSL_Vector), BinOpStrVecAddVec, true));
  370. bos.Add("vector-vector", new BinOpStr(typeof(LSL_Vector), BinOpStrVecSubVec, true));
  371. bos.Add("vector*vector", new BinOpStr(typeof(double), BinOpStrVecMulVec));
  372. bos.Add("vector%vector", new BinOpStr(typeof(LSL_Vector), BinOpStrVecModVec, true));
  373. bos.Add("vector*float", new BinOpStr(typeof(LSL_Vector), BinOpStrVecMulFloat, true));
  374. bos.Add("float*vector", new BinOpStr(typeof(LSL_Vector), BinOpStrFloatMulVec));
  375. bos.Add("vector/float", new BinOpStr(typeof(LSL_Vector), BinOpStrVecDivFloat, true));
  376. bos.Add("vector*integer", new BinOpStr(typeof(LSL_Vector), BinOpStrVecMulInt, true));
  377. bos.Add("integer*vector", new BinOpStr(typeof(LSL_Vector), BinOpStrIntMulVec));
  378. bos.Add("vector/integer", new BinOpStr(typeof(LSL_Vector), BinOpStrVecDivInt, true));
  379. bos.Add("vector*rotation", new BinOpStr(typeof(LSL_Vector), BinOpStrVecMulRot, true));
  380. bos.Add("vector/rotation", new BinOpStr(typeof(LSL_Vector), BinOpStrVecDivRot, true));
  381. }
  382. /**
  383. * @brief These methods actually emit the code to perform the arithmetic.
  384. * @param scg = what script we are compiling
  385. * @param left = left-hand operand location in memory (type as given by BinOpStr entry)
  386. * @param right = right-hand operand location in memory (type as given by BinOpStr entry)
  387. * @param result = result location in memory (type as given by BinOpStr entry)
  388. */
  389. private static void BinOpStrAndAnd(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  390. {
  391. result.PopPre(scg, errorAt);
  392. left.PushVal(scg, errorAt, tokenTypeBool);
  393. right.PushVal(scg, errorAt, tokenTypeBool);
  394. scg.ilGen.Emit(errorAt, OpCodes.And);
  395. result.PopPost(scg, errorAt, tokenTypeBool);
  396. }
  397. private static void BinOpStrOrOr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  398. {
  399. result.PopPre(scg, errorAt);
  400. left.PushVal(scg, errorAt, tokenTypeBool);
  401. right.PushVal(scg, errorAt, tokenTypeBool);
  402. scg.ilGen.Emit(errorAt, OpCodes.Or);
  403. result.PopPost(scg, errorAt, tokenTypeBool);
  404. }
  405. private static void BinOpStrBoolOrX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  406. {
  407. result.PopPre(scg, errorAt);
  408. left.PushVal(scg, errorAt, tokenTypeInt);
  409. right.PushVal(scg, errorAt, tokenTypeInt);
  410. scg.ilGen.Emit(errorAt, OpCodes.Or);
  411. result.PopPost(scg, errorAt, tokenTypeInt);
  412. }
  413. private static void BinOpStrBoolXorX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  414. {
  415. result.PopPre(scg, errorAt);
  416. left.PushVal(scg, errorAt, tokenTypeInt);
  417. right.PushVal(scg, errorAt, tokenTypeInt);
  418. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  419. result.PopPost(scg, errorAt, tokenTypeInt);
  420. }
  421. private static void BinOpStrBoolAndX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  422. {
  423. result.PopPre(scg, errorAt);
  424. left.PushVal(scg, errorAt, tokenTypeInt);
  425. right.PushVal(scg, errorAt, tokenTypeInt);
  426. scg.ilGen.Emit(errorAt, OpCodes.And);
  427. result.PopPost(scg, errorAt, tokenTypeInt);
  428. }
  429. private static void BinOpStrBoolEqX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  430. {
  431. result.PopPre(scg, errorAt);
  432. left.PushVal(scg, errorAt, tokenTypeBool);
  433. right.PushVal(scg, errorAt, tokenTypeBool);
  434. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  435. result.PopPost(scg, errorAt, tokenTypeBool);
  436. }
  437. private static void BinOpStrBoolNeX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  438. {
  439. result.PopPre(scg, errorAt);
  440. left.PushVal(scg, errorAt, tokenTypeBool);
  441. right.PushVal(scg, errorAt, tokenTypeBool);
  442. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  443. result.PopPost(scg, errorAt, tokenTypeBool);
  444. }
  445. private static void BinOpStrFloatEqX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  446. {
  447. result.PopPre(scg, errorAt);
  448. left.PushVal(scg, errorAt, tokenTypeFloat);
  449. right.PushVal(scg, errorAt, tokenTypeFloat);
  450. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  451. result.PopPost(scg, errorAt, tokenTypeBool);
  452. }
  453. private static void BinOpStrFloatNeX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  454. {
  455. result.PopPre(scg, errorAt);
  456. left.PushVal(scg, errorAt, tokenTypeFloat);
  457. right.PushVal(scg, errorAt, tokenTypeFloat);
  458. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  459. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  460. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  461. result.PopPost(scg, errorAt, tokenTypeBool);
  462. }
  463. private static void BinOpStrFloatLtX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  464. {
  465. result.PopPre(scg, errorAt);
  466. left.PushVal(scg, errorAt, tokenTypeFloat);
  467. right.PushVal(scg, errorAt, tokenTypeFloat);
  468. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  469. result.PopPost(scg, errorAt, tokenTypeBool);
  470. }
  471. private static void BinOpStrFloatLeX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  472. {
  473. result.PopPre(scg, errorAt);
  474. left.PushVal(scg, errorAt, tokenTypeFloat);
  475. right.PushVal(scg, errorAt, tokenTypeFloat);
  476. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  477. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  478. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  479. result.PopPost(scg, errorAt, tokenTypeBool);
  480. }
  481. private static void BinOpStrFloatGtX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  482. {
  483. result.PopPre(scg, errorAt);
  484. left.PushVal(scg, errorAt, tokenTypeFloat);
  485. right.PushVal(scg, errorAt, tokenTypeFloat);
  486. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  487. result.PopPost(scg, errorAt, tokenTypeBool);
  488. }
  489. private static void BinOpStrFloatGeX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  490. {
  491. result.PopPre(scg, errorAt);
  492. left.PushVal(scg, errorAt, tokenTypeFloat);
  493. right.PushVal(scg, errorAt, tokenTypeFloat);
  494. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  495. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  496. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  497. result.PopPost(scg, errorAt, tokenTypeBool);
  498. }
  499. private static void BinOpStrFloatAddX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  500. {
  501. result.PopPre(scg, errorAt);
  502. left.PushVal(scg, errorAt, tokenTypeFloat);
  503. right.PushVal(scg, errorAt, tokenTypeFloat);
  504. scg.ilGen.Emit(errorAt, OpCodes.Add);
  505. result.PopPost(scg, errorAt, tokenTypeFloat);
  506. }
  507. private static void BinOpStrFloatSubX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  508. {
  509. result.PopPre(scg, errorAt);
  510. left.PushVal(scg, errorAt, tokenTypeFloat);
  511. right.PushVal(scg, errorAt, tokenTypeFloat);
  512. scg.ilGen.Emit(errorAt, OpCodes.Sub);
  513. result.PopPost(scg, errorAt, tokenTypeFloat);
  514. }
  515. private static void BinOpStrFloatMulX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  516. {
  517. result.PopPre(scg, errorAt);
  518. left.PushVal(scg, errorAt, tokenTypeFloat);
  519. right.PushVal(scg, errorAt, tokenTypeFloat);
  520. scg.ilGen.Emit(errorAt, OpCodes.Mul);
  521. result.PopPost(scg, errorAt, tokenTypeFloat);
  522. }
  523. private static void BinOpStrFloatDivX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  524. {
  525. result.PopPre(scg, errorAt);
  526. left.PushVal(scg, errorAt, tokenTypeFloat);
  527. right.PushVal(scg, errorAt, tokenTypeFloat);
  528. //scg.ilGen.Emit(errorAt, OpCodes.Div);
  529. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethDoubleDivDouble);
  530. result.PopPost(scg, errorAt, tokenTypeFloat);
  531. }
  532. private static void BinOpStrFloatModX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  533. {
  534. result.PopPre(scg, errorAt);
  535. left.PushVal(scg, errorAt, tokenTypeFloat);
  536. right.PushVal(scg, errorAt, tokenTypeFloat);
  537. //scg.ilGen.Emit(errorAt, OpCodes.Rem);
  538. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethDoubleModDouble);
  539. result.PopPost(scg, errorAt, tokenTypeFloat);
  540. }
  541. private static void BinOpStrXEqFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  542. {
  543. result.PopPre(scg, errorAt);
  544. left.PushVal(scg, errorAt, tokenTypeFloat);
  545. right.PushVal(scg, errorAt, tokenTypeFloat);
  546. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  547. result.PopPost(scg, errorAt, tokenTypeBool);
  548. }
  549. private static void BinOpStrXNeFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  550. {
  551. result.PopPre(scg, errorAt);
  552. left.PushVal(scg, errorAt, tokenTypeFloat);
  553. right.PushVal(scg, errorAt, tokenTypeFloat);
  554. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  555. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  556. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  557. result.PopPost(scg, errorAt, tokenTypeBool);
  558. }
  559. private static void BinOpStrXLtFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  560. {
  561. result.PopPre(scg, errorAt);
  562. left.PushVal(scg, errorAt, tokenTypeFloat);
  563. right.PushVal(scg, errorAt, tokenTypeFloat);
  564. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  565. result.PopPost(scg, errorAt, tokenTypeBool);
  566. }
  567. private static void BinOpStrXLeFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  568. {
  569. result.PopPre(scg, errorAt);
  570. left.PushVal(scg, errorAt, tokenTypeFloat);
  571. right.PushVal(scg, errorAt, tokenTypeFloat);
  572. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  573. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  574. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  575. result.PopPost(scg, errorAt, tokenTypeBool);
  576. }
  577. private static void BinOpStrXGtFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  578. {
  579. result.PopPre(scg, errorAt);
  580. left.PushVal(scg, errorAt, tokenTypeFloat);
  581. right.PushVal(scg, errorAt, tokenTypeFloat);
  582. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  583. result.PopPost(scg, errorAt, tokenTypeBool);
  584. }
  585. private static void BinOpStrXGeFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  586. {
  587. result.PopPre(scg, errorAt);
  588. left.PushVal(scg, errorAt, tokenTypeFloat);
  589. right.PushVal(scg, errorAt, tokenTypeFloat);
  590. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  591. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  592. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  593. result.PopPost(scg, errorAt, tokenTypeBool);
  594. }
  595. private static void BinOpStrXAddFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  596. {
  597. result.PopPre(scg, errorAt);
  598. left.PushVal(scg, errorAt, tokenTypeFloat);
  599. right.PushVal(scg, errorAt, tokenTypeFloat);
  600. scg.ilGen.Emit(errorAt, OpCodes.Add);
  601. result.PopPost(scg, errorAt, tokenTypeFloat);
  602. }
  603. private static void BinOpStrXSubFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  604. {
  605. result.PopPre(scg, errorAt);
  606. left.PushVal(scg, errorAt, tokenTypeFloat);
  607. right.PushVal(scg, errorAt, tokenTypeFloat);
  608. scg.ilGen.Emit(errorAt, OpCodes.Sub);
  609. result.PopPost(scg, errorAt, tokenTypeFloat);
  610. }
  611. private static void BinOpStrXMulFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  612. {
  613. result.PopPre(scg, errorAt);
  614. left.PushVal(scg, errorAt, tokenTypeFloat);
  615. right.PushVal(scg, errorAt, tokenTypeFloat);
  616. scg.ilGen.Emit(errorAt, OpCodes.Mul);
  617. result.PopPost(scg, errorAt, tokenTypeFloat);
  618. }
  619. private static void BinOpStrXDivFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  620. {
  621. result.PopPre(scg, errorAt);
  622. left.PushVal(scg, errorAt, tokenTypeFloat);
  623. right.PushVal(scg, errorAt, tokenTypeFloat);
  624. //scg.ilGen.Emit(errorAt, OpCodes.Div);
  625. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethDoubleDivDouble);
  626. result.PopPost(scg, errorAt, tokenTypeFloat);
  627. }
  628. private static void BinOpStrXModFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  629. {
  630. result.PopPre(scg, errorAt);
  631. left.PushVal(scg, errorAt, tokenTypeFloat);
  632. right.PushVal(scg, errorAt, tokenTypeFloat);
  633. //scg.ilGen.Emit(errorAt, OpCodes.Rem);
  634. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethDoubleModDouble);
  635. result.PopPost(scg, errorAt, tokenTypeFloat);
  636. }
  637. private static void BinOpStrCharEqChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  638. {
  639. result.PopPre(scg, errorAt);
  640. left.PushVal(scg, errorAt, tokenTypeChar);
  641. right.PushVal(scg, errorAt, tokenTypeChar);
  642. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  643. result.PopPost(scg, errorAt, tokenTypeBool);
  644. }
  645. private static void BinOpStrCharNeChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  646. {
  647. result.PopPre(scg, errorAt);
  648. left.PushVal(scg, errorAt, tokenTypeChar);
  649. right.PushVal(scg, errorAt, tokenTypeChar);
  650. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  651. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  652. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  653. result.PopPost(scg, errorAt, tokenTypeBool);
  654. }
  655. private static void BinOpStrCharLtChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  656. {
  657. result.PopPre(scg, errorAt);
  658. left.PushVal(scg, errorAt, tokenTypeChar);
  659. right.PushVal(scg, errorAt, tokenTypeChar);
  660. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  661. result.PopPost(scg, errorAt, tokenTypeBool);
  662. }
  663. private static void BinOpStrCharLeChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  664. {
  665. result.PopPre(scg, errorAt);
  666. left.PushVal(scg, errorAt, tokenTypeChar);
  667. right.PushVal(scg, errorAt, tokenTypeChar);
  668. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  669. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  670. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  671. result.PopPost(scg, errorAt, tokenTypeBool);
  672. }
  673. private static void BinOpStrCharGtChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  674. {
  675. result.PopPre(scg, errorAt);
  676. left.PushVal(scg, errorAt, tokenTypeChar);
  677. right.PushVal(scg, errorAt, tokenTypeChar);
  678. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  679. result.PopPost(scg, errorAt, tokenTypeBool);
  680. }
  681. private static void BinOpStrCharGeChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  682. {
  683. result.PopPre(scg, errorAt);
  684. left.PushVal(scg, errorAt, tokenTypeChar);
  685. right.PushVal(scg, errorAt, tokenTypeChar);
  686. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  687. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  688. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  689. result.PopPost(scg, errorAt, tokenTypeBool);
  690. }
  691. private static void BinOpStrCharAddInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  692. {
  693. result.PopPre(scg, errorAt);
  694. left.PushVal(scg, errorAt, tokenTypeChar);
  695. right.PushVal(scg, errorAt, tokenTypeInt);
  696. scg.ilGen.Emit(errorAt, OpCodes.Add);
  697. result.PopPost(scg, errorAt, tokenTypeChar);
  698. }
  699. private static void BinOpStrCharSubInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  700. {
  701. result.PopPre(scg, errorAt);
  702. left.PushVal(scg, errorAt, tokenTypeChar);
  703. right.PushVal(scg, errorAt, tokenTypeInt);
  704. scg.ilGen.Emit(errorAt, OpCodes.Sub);
  705. result.PopPost(scg, errorAt, tokenTypeChar);
  706. }
  707. private static void BinOpStrCharSubChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  708. {
  709. result.PopPre(scg, errorAt);
  710. left.PushVal(scg, errorAt, tokenTypeChar);
  711. right.PushVal(scg, errorAt, tokenTypeChar);
  712. scg.ilGen.Emit(errorAt, OpCodes.Sub);
  713. result.PopPost(scg, errorAt, tokenTypeInt);
  714. }
  715. private static void BinOpStrIntEqInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  716. {
  717. result.PopPre(scg, errorAt);
  718. left.PushVal(scg, errorAt, tokenTypeInt);
  719. right.PushVal(scg, errorAt, tokenTypeInt);
  720. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  721. result.PopPost(scg, errorAt, tokenTypeBool);
  722. }
  723. private static void BinOpStrIntNeInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  724. {
  725. result.PopPre(scg, errorAt);
  726. left.PushVal(scg, errorAt, tokenTypeInt);
  727. right.PushVal(scg, errorAt, tokenTypeInt);
  728. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  729. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  730. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  731. result.PopPost(scg, errorAt, tokenTypeBool);
  732. }
  733. private static void BinOpStrIntLtInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  734. {
  735. result.PopPre(scg, errorAt);
  736. left.PushVal(scg, errorAt, tokenTypeInt);
  737. right.PushVal(scg, errorAt, tokenTypeInt);
  738. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  739. result.PopPost(scg, errorAt, tokenTypeBool);
  740. }
  741. private static void BinOpStrIntLeInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  742. {
  743. result.PopPre(scg, errorAt);
  744. left.PushVal(scg, errorAt, tokenTypeInt);
  745. right.PushVal(scg, errorAt, tokenTypeInt);
  746. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  747. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  748. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  749. result.PopPost(scg, errorAt, tokenTypeBool);
  750. }
  751. private static void BinOpStrIntGtInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  752. {
  753. result.PopPre(scg, errorAt);
  754. left.PushVal(scg, errorAt, tokenTypeInt);
  755. right.PushVal(scg, errorAt, tokenTypeInt);
  756. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  757. result.PopPost(scg, errorAt, tokenTypeBool);
  758. }
  759. private static void BinOpStrIntGeInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  760. {
  761. result.PopPre(scg, errorAt);
  762. left.PushVal(scg, errorAt, tokenTypeInt);
  763. right.PushVal(scg, errorAt, tokenTypeInt);
  764. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  765. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  766. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  767. result.PopPost(scg, errorAt, tokenTypeBool);
  768. }
  769. private static void BinOpStrIntOrInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  770. {
  771. result.PopPre(scg, errorAt);
  772. left.PushVal(scg, errorAt, tokenTypeInt);
  773. right.PushVal(scg, errorAt, tokenTypeInt);
  774. scg.ilGen.Emit(errorAt, OpCodes.Or);
  775. result.PopPost(scg, errorAt, tokenTypeInt);
  776. }
  777. private static void BinOpStrIntXorInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  778. {
  779. result.PopPre(scg, errorAt);
  780. left.PushVal(scg, errorAt, tokenTypeInt);
  781. right.PushVal(scg, errorAt, tokenTypeInt);
  782. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  783. result.PopPost(scg, errorAt, tokenTypeInt);
  784. }
  785. private static void BinOpStrIntAndInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  786. {
  787. result.PopPre(scg, errorAt);
  788. left.PushVal(scg, errorAt, tokenTypeInt);
  789. right.PushVal(scg, errorAt, tokenTypeInt);
  790. scg.ilGen.Emit(errorAt, OpCodes.And);
  791. result.PopPost(scg, errorAt, tokenTypeInt);
  792. }
  793. private static void BinOpStrIntAddInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  794. {
  795. result.PopPre(scg, errorAt);
  796. left.PushVal(scg, errorAt, tokenTypeInt);
  797. right.PushVal(scg, errorAt, tokenTypeInt);
  798. scg.ilGen.Emit(errorAt, OpCodes.Add);
  799. result.PopPost(scg, errorAt, tokenTypeInt);
  800. }
  801. private static void BinOpStrIntSubInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  802. {
  803. result.PopPre(scg, errorAt);
  804. left.PushVal(scg, errorAt, tokenTypeInt);
  805. right.PushVal(scg, errorAt, tokenTypeInt);
  806. scg.ilGen.Emit(errorAt, OpCodes.Sub);
  807. result.PopPost(scg, errorAt, tokenTypeInt);
  808. }
  809. private static void BinOpStrIntMulInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  810. {
  811. result.PopPre(scg, errorAt);
  812. left.PushVal(scg, errorAt, tokenTypeInt);
  813. right.PushVal(scg, errorAt, tokenTypeInt);
  814. scg.ilGen.Emit(errorAt, OpCodes.Mul);
  815. result.PopPost(scg, errorAt, tokenTypeInt);
  816. }
  817. private static void BinOpStrIntDivInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  818. {
  819. // note that we must allow 0x800000/-1 -> 0x80000000 for lslangtest1.lsl
  820. // so sign-extend the operands to 64-bit then divide and truncate result
  821. result.PopPre(scg, errorAt);
  822. left.PushVal(scg, errorAt, tokenTypeInt);
  823. scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
  824. right.PushVal(scg, errorAt, tokenTypeInt);
  825. scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
  826. //scg.ilGen.Emit(errorAt, OpCodes.Div);
  827. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethLongDivLong);
  828. scg.ilGen.Emit(errorAt, OpCodes.Conv_I4);
  829. result.PopPost(scg, errorAt, tokenTypeInt);
  830. }
  831. private static void BinOpStrIntModInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  832. {
  833. // note that we must allow 0x800000%-1 -> 0 for lslangtest1.lsl
  834. // so sign-extend the operands to 64-bit then mod and truncate result
  835. result.PopPre(scg, errorAt);
  836. left.PushVal(scg, errorAt, tokenTypeInt);
  837. scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
  838. right.PushVal(scg, errorAt, tokenTypeInt);
  839. scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
  840. //scg.ilGen.Emit(errorAt, OpCodes.Rem);
  841. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethLongModLong);
  842. scg.ilGen.Emit(errorAt, OpCodes.Conv_I4);
  843. result.PopPost(scg, errorAt, tokenTypeInt);
  844. }
  845. private static void BinOpStrIntShlInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  846. {
  847. result.PopPre(scg, errorAt);
  848. left.PushVal(scg, errorAt, tokenTypeInt);
  849. right.PushVal(scg, errorAt, tokenTypeInt);
  850. scg.ilGen.Emit(errorAt, OpCodes.Shl);
  851. result.PopPost(scg, errorAt, tokenTypeInt);
  852. }
  853. private static void BinOpStrIntShrInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  854. {
  855. result.PopPre(scg, errorAt);
  856. left.PushVal(scg, errorAt, tokenTypeInt);
  857. right.PushVal(scg, errorAt, tokenTypeInt);
  858. scg.ilGen.Emit(errorAt, OpCodes.Shr);
  859. result.PopPost(scg, errorAt, tokenTypeInt);
  860. }
  861. private static void BinOpStrKeyEqX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  862. {
  863. result.PopPre(scg, errorAt);
  864. left.PushVal(scg, errorAt, tokenTypeStr);
  865. right.PushVal(scg, errorAt, tokenTypeStr);
  866. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  867. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  868. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  869. result.PopPost(scg, errorAt, tokenTypeBool);
  870. }
  871. private static void BinOpStrKeyNeX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  872. {
  873. result.PopPre(scg, errorAt);
  874. left.PushVal(scg, errorAt, tokenTypeStr);
  875. right.PushVal(scg, errorAt, tokenTypeStr);
  876. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  877. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  878. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  879. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  880. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  881. result.PopPost(scg, errorAt, tokenTypeBool);
  882. }
  883. private static void BinOpStrListAddFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  884. {
  885. result.PopPre(scg, errorAt);
  886. left.PushVal(scg, errorAt, tokenTypeList);
  887. right.PushVal(scg, errorAt, tokenTypeFloat);
  888. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddFloat);
  889. result.PopPost(scg, errorAt, tokenTypeList);
  890. }
  891. private static void BinOpStrListAddInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  892. {
  893. result.PopPre(scg, errorAt);
  894. left.PushVal(scg, errorAt, tokenTypeList);
  895. right.PushVal(scg, errorAt, tokenTypeInt);
  896. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddInt);
  897. result.PopPost(scg, errorAt, tokenTypeList);
  898. }
  899. private static void BinOpStrListAddKey(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  900. {
  901. result.PopPre(scg, errorAt);
  902. left.PushVal(scg, errorAt, tokenTypeList);
  903. right.PushVal(scg, errorAt, tokenTypeStr);
  904. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddKey);
  905. result.PopPost(scg, errorAt, tokenTypeList);
  906. }
  907. private static void BinOpStrListAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  908. {
  909. result.PopPre(scg, errorAt);
  910. left.PushVal(scg, errorAt, tokenTypeList);
  911. right.PushVal(scg, errorAt, tokenTypeList);
  912. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddList);
  913. result.PopPost(scg, errorAt, tokenTypeList);
  914. }
  915. private static void BinOpStrListAddRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  916. {
  917. result.PopPre(scg, errorAt);
  918. left.PushVal(scg, errorAt, tokenTypeList);
  919. right.PushVal(scg, errorAt, tokenTypeRot);
  920. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddRot);
  921. result.PopPost(scg, errorAt, tokenTypeList);
  922. }
  923. private static void BinOpStrListAddStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  924. {
  925. result.PopPre(scg, errorAt);
  926. left.PushVal(scg, errorAt, tokenTypeList);
  927. right.PushVal(scg, errorAt, tokenTypeStr);
  928. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddStr);
  929. result.PopPost(scg, errorAt, tokenTypeList);
  930. }
  931. private static void BinOpStrListAddVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  932. {
  933. result.PopPre(scg, errorAt);
  934. left.PushVal(scg, errorAt, tokenTypeList);
  935. right.PushVal(scg, errorAt, tokenTypeVec);
  936. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddVec);
  937. result.PopPost(scg, errorAt, tokenTypeList);
  938. }
  939. private static void BinOpStrFloatAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  940. {
  941. result.PopPre(scg, errorAt);
  942. left.PushVal(scg, errorAt, tokenTypeFloat);
  943. right.PushVal(scg, errorAt, tokenTypeList);
  944. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethFloatAddList);
  945. result.PopPost(scg, errorAt, tokenTypeList);
  946. }
  947. private static void BinOpStrIntAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  948. {
  949. result.PopPre(scg, errorAt);
  950. left.PushVal(scg, errorAt, tokenTypeInt);
  951. right.PushVal(scg, errorAt, tokenTypeList);
  952. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethIntAddList);
  953. result.PopPost(scg, errorAt, tokenTypeList);
  954. }
  955. private static void BinOpStrKeyAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  956. {
  957. result.PopPre(scg, errorAt);
  958. left.PushVal(scg, errorAt, tokenTypeStr);
  959. right.PushVal(scg, errorAt, tokenTypeList);
  960. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethKeyAddList);
  961. result.PopPost(scg, errorAt, tokenTypeList);
  962. }
  963. private static void BinOpStrRotAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  964. {
  965. result.PopPre(scg, errorAt);
  966. left.PushVal(scg, errorAt, tokenTypeRot);
  967. right.PushVal(scg, errorAt, tokenTypeList);
  968. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotAddList);
  969. result.PopPost(scg, errorAt, tokenTypeList);
  970. }
  971. private static void BinOpStrStrAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  972. {
  973. result.PopPre(scg, errorAt);
  974. left.PushVal(scg, errorAt, tokenTypeStr);
  975. right.PushVal(scg, errorAt, tokenTypeList);
  976. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethStrAddList);
  977. result.PopPost(scg, errorAt, tokenTypeList);
  978. }
  979. private static void BinOpStrVecAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  980. {
  981. result.PopPre(scg, errorAt);
  982. left.PushVal(scg, errorAt, tokenTypeVec);
  983. right.PushVal(scg, errorAt, tokenTypeList);
  984. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecAddList);
  985. result.PopPost(scg, errorAt, tokenTypeList);
  986. }
  987. private static void BinOpStrListEqList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  988. {
  989. result.PopPre(scg, errorAt);
  990. left.PushVal(scg, errorAt, tokenTypeList);
  991. right.PushVal(scg, errorAt, tokenTypeList);
  992. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListEqList);
  993. result.PopPost(scg, errorAt, tokenTypeBool);
  994. }
  995. private static void BinOpStrListNeList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  996. {
  997. result.PopPre(scg, errorAt);
  998. left.PushVal(scg, errorAt, tokenTypeList);
  999. right.PushVal(scg, errorAt, tokenTypeList);
  1000. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListNeList);
  1001. result.PopPost(scg, errorAt, tokenTypeBool);
  1002. }
  1003. private static void BinOpStrRotEqRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1004. {
  1005. result.PopPre(scg, errorAt);
  1006. left.PushVal(scg, errorAt, tokenTypeRot);
  1007. right.PushVal(scg, errorAt, tokenTypeRot);
  1008. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotEqRot);
  1009. result.PopPost(scg, errorAt, tokenTypeBool);
  1010. }
  1011. private static void BinOpStrRotNeRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1012. {
  1013. result.PopPre(scg, errorAt);
  1014. left.PushVal(scg, errorAt, tokenTypeRot);
  1015. right.PushVal(scg, errorAt, tokenTypeRot);
  1016. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotNeRot);
  1017. result.PopPost(scg, errorAt, tokenTypeBool);
  1018. }
  1019. private static void BinOpStrRotAddRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1020. {
  1021. result.PopPre(scg, errorAt);
  1022. left.PushVal(scg, errorAt, tokenTypeRot);
  1023. right.PushVal(scg, errorAt, tokenTypeRot);
  1024. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotAddRot);
  1025. result.PopPost(scg, errorAt, tokenTypeRot);
  1026. }
  1027. private static void BinOpStrRotSubRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1028. {
  1029. result.PopPre(scg, errorAt);
  1030. left.PushVal(scg, errorAt, tokenTypeRot);
  1031. right.PushVal(scg, errorAt, tokenTypeRot);
  1032. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotSubRot);
  1033. result.PopPost(scg, errorAt, tokenTypeRot);
  1034. }
  1035. private static void BinOpStrRotMulRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1036. {
  1037. result.PopPre(scg, errorAt);
  1038. left.PushVal(scg, errorAt, tokenTypeRot);
  1039. right.PushVal(scg, errorAt, tokenTypeRot);
  1040. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotMulRot);
  1041. result.PopPost(scg, errorAt, tokenTypeRot);
  1042. }
  1043. private static void BinOpStrRotDivRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1044. {
  1045. result.PopPre(scg, errorAt);
  1046. left.PushVal(scg, errorAt, tokenTypeRot);
  1047. right.PushVal(scg, errorAt, tokenTypeRot);
  1048. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotDivRot);
  1049. result.PopPost(scg, errorAt, tokenTypeRot);
  1050. }
  1051. private static void BinOpStrStrEqStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1052. {
  1053. result.PopPre(scg, errorAt);
  1054. left.PushVal(scg, errorAt, tokenTypeStr);
  1055. right.PushVal(scg, errorAt, tokenTypeStr);
  1056. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1057. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  1058. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  1059. result.PopPost(scg, errorAt, tokenTypeBool);
  1060. }
  1061. private static void BinOpStrStrNeStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1062. {
  1063. result.PopPre(scg, errorAt);
  1064. left.PushVal(scg, errorAt, tokenTypeStr);
  1065. right.PushVal(scg, errorAt, tokenTypeStr);
  1066. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1067. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  1068. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  1069. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  1070. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  1071. result.PopPost(scg, errorAt, tokenTypeBool);
  1072. }
  1073. private static void BinOpStrStrLtStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1074. {
  1075. result.PopPre(scg, errorAt);
  1076. left.PushVal(scg, errorAt, tokenTypeStr);
  1077. right.PushVal(scg, errorAt, tokenTypeStr);
  1078. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1079. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  1080. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  1081. result.PopPost(scg, errorAt, tokenTypeBool);
  1082. }
  1083. private static void BinOpStrStrLeStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1084. {
  1085. result.PopPre(scg, errorAt);
  1086. left.PushVal(scg, errorAt, tokenTypeStr);
  1087. right.PushVal(scg, errorAt, tokenTypeStr);
  1088. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1089. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  1090. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  1091. result.PopPost(scg, errorAt, tokenTypeBool);
  1092. }
  1093. private static void BinOpStrStrGtStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1094. {
  1095. result.PopPre(scg, errorAt);
  1096. left.PushVal(scg, errorAt, tokenTypeStr);
  1097. right.PushVal(scg, errorAt, tokenTypeStr);
  1098. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1099. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  1100. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  1101. result.PopPost(scg, errorAt, tokenTypeBool);
  1102. }
  1103. private static void BinOpStrStrGeStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1104. {
  1105. result.PopPre(scg, errorAt);
  1106. left.PushVal(scg, errorAt, tokenTypeStr);
  1107. right.PushVal(scg, errorAt, tokenTypeStr);
  1108. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1109. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_M1);
  1110. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  1111. result.PopPost(scg, errorAt, tokenTypeBool);
  1112. }
  1113. // Called by many type combinations so both operands need to be cast to strings
  1114. private static void BinOpStrStrAddStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1115. {
  1116. result.PopPre(scg, errorAt);
  1117. left.PushVal(scg, errorAt, tokenTypeStr);
  1118. right.PushVal(scg, errorAt, tokenTypeStr);
  1119. scg.ilGen.Emit(errorAt, OpCodes.Call, stringAddStringMethInfo);
  1120. result.PopPost(scg, errorAt, tokenTypeStr);
  1121. }
  1122. private static void BinOpStrVecEqVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1123. {
  1124. result.PopPre(scg, errorAt);
  1125. left.PushVal(scg, errorAt, tokenTypeVec);
  1126. right.PushVal(scg, errorAt, tokenTypeVec);
  1127. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecEqVec);
  1128. result.PopPost(scg, errorAt, tokenTypeBool);
  1129. }
  1130. private static void BinOpStrVecNeVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1131. {
  1132. result.PopPre(scg, errorAt);
  1133. left.PushVal(scg, errorAt, tokenTypeVec);
  1134. right.PushVal(scg, errorAt, tokenTypeVec);
  1135. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecNeVec);
  1136. result.PopPost(scg, errorAt, tokenTypeBool);
  1137. }
  1138. private static void BinOpStrVecAddVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1139. {
  1140. result.PopPre(scg, errorAt);
  1141. left.PushVal(scg, errorAt, tokenTypeVec);
  1142. right.PushVal(scg, errorAt, tokenTypeVec);
  1143. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecAddVec);
  1144. result.PopPost(scg, errorAt, tokenTypeVec);
  1145. }
  1146. private static void BinOpStrVecSubVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1147. {
  1148. result.PopPre(scg, errorAt);
  1149. left.PushVal(scg, errorAt, tokenTypeVec);
  1150. right.PushVal(scg, errorAt, tokenTypeVec);
  1151. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecSubVec);
  1152. result.PopPost(scg, errorAt, tokenTypeVec);
  1153. }
  1154. private static void BinOpStrVecMulVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1155. {
  1156. result.PopPre(scg, errorAt);
  1157. left.PushVal(scg, errorAt, tokenTypeVec);
  1158. right.PushVal(scg, errorAt, tokenTypeVec);
  1159. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulVec);
  1160. result.PopPost(scg, errorAt, tokenTypeFloat);
  1161. }
  1162. private static void BinOpStrVecModVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1163. {
  1164. result.PopPre(scg, errorAt);
  1165. left.PushVal(scg, errorAt, tokenTypeVec);
  1166. right.PushVal(scg, errorAt, tokenTypeVec);
  1167. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecModVec);
  1168. result.PopPost(scg, errorAt, tokenTypeVec);
  1169. }
  1170. private static void BinOpStrVecMulFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1171. {
  1172. result.PopPre(scg, errorAt);
  1173. left.PushVal(scg, errorAt, tokenTypeVec);
  1174. right.PushVal(scg, errorAt, tokenTypeFloat);
  1175. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulFloat);
  1176. result.PopPost(scg, errorAt, tokenTypeVec);
  1177. }
  1178. private static void BinOpStrFloatMulVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1179. {
  1180. result.PopPre(scg, errorAt);
  1181. left.PushVal(scg, errorAt, tokenTypeFloat);
  1182. right.PushVal(scg, errorAt, tokenTypeVec);
  1183. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethFloatMulVec);
  1184. result.PopPost(scg, errorAt, tokenTypeVec);
  1185. }
  1186. private static void BinOpStrVecDivFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1187. {
  1188. result.PopPre(scg, errorAt);
  1189. left.PushVal(scg, errorAt, tokenTypeVec);
  1190. right.PushVal(scg, errorAt, tokenTypeFloat);
  1191. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecDivFloat);
  1192. result.PopPost(scg, errorAt, tokenTypeVec);
  1193. }
  1194. private static void BinOpStrVecMulInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1195. {
  1196. result.PopPre(scg, errorAt);
  1197. left.PushVal(scg, errorAt, tokenTypeVec);
  1198. right.PushVal(scg, errorAt, tokenTypeInt);
  1199. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulInt);
  1200. result.PopPost(scg, errorAt, tokenTypeVec);
  1201. }
  1202. private static void BinOpStrIntMulVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1203. {
  1204. result.PopPre(scg, errorAt);
  1205. left.PushVal(scg, errorAt, tokenTypeInt);
  1206. right.PushVal(scg, errorAt, tokenTypeVec);
  1207. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethIntMulVec);
  1208. result.PopPost(scg, errorAt, tokenTypeVec);
  1209. }
  1210. private static void BinOpStrVecDivInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1211. {
  1212. result.PopPre(scg, errorAt);
  1213. left.PushVal(scg, errorAt, tokenTypeVec);
  1214. right.PushVal(scg, errorAt, tokenTypeInt);
  1215. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecDivInt);
  1216. result.PopPost(scg, errorAt, tokenTypeVec);
  1217. }
  1218. private static void BinOpStrVecMulRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1219. {
  1220. result.PopPre(scg, errorAt);
  1221. left.PushVal(scg, errorAt, tokenTypeVec);
  1222. right.PushVal(scg, errorAt, tokenTypeRot);
  1223. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulRot);
  1224. result.PopPost(scg, errorAt, tokenTypeVec);
  1225. }
  1226. private static void BinOpStrVecDivRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1227. {
  1228. result.PopPre(scg, errorAt);
  1229. left.PushVal(scg, errorAt, tokenTypeVec);
  1230. right.PushVal(scg, errorAt, tokenTypeRot);
  1231. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecDivRot);
  1232. result.PopPost(scg, errorAt, tokenTypeVec);
  1233. }
  1234. /**
  1235. * @brief These methods are called at runtime as helpers.
  1236. * Needed to pick up functionality defined by overloaded operators of LSL_ types.
  1237. * They need to be marked public or runtime says they are inaccessible.
  1238. */
  1239. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1240. public static string StringConcat(string str1, string str2)
  1241. {
  1242. return string.Concat(str1, str2);
  1243. }
  1244. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1245. public static string StringConcat(string str1, string str2, string str3)
  1246. {
  1247. return string.Concat(str1, str2, str3);
  1248. }
  1249. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1250. public static string StringConcat(string str1, string str2, string str3, string str4)
  1251. {
  1252. return string.Concat(str1, str2, str3, str4);
  1253. }
  1254. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1255. public static int StringCompareOrdinal(string str1, string str2)
  1256. {
  1257. return string.Compare(str1, str2, StringComparison.Ordinal);
  1258. }
  1259. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1260. public static LSL_List MethListAddFloat(LSL_List left, double right)
  1261. {
  1262. return MethListAddObj(left, new LSL_Float(right));
  1263. }
  1264. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1265. public static LSL_List MethListAddInt(LSL_List left, int right)
  1266. {
  1267. return MethListAddObj(left, new LSL_Integer(right));
  1268. }
  1269. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1270. public static LSL_List MethListAddKey(LSL_List left, string right)
  1271. {
  1272. return MethListAddObj(left, new LSL_Key(right));
  1273. }
  1274. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1275. public static LSL_List MethListAddRot(LSL_List left, LSL_Rotation right)
  1276. {
  1277. return MethListAddObj(left, right);
  1278. }
  1279. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1280. public static LSL_List MethListAddStr(LSL_List left, string right)
  1281. {
  1282. return MethListAddObj(left, new LSL_String(right));
  1283. }
  1284. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1285. public static LSL_List MethListAddVec(LSL_List left, LSL_Vector right)
  1286. {
  1287. return MethListAddObj(left, right);
  1288. }
  1289. public static LSL_List MethListAddObj(LSL_List left, object right)
  1290. {
  1291. int oldlen = left.Length;
  1292. object[] newarr = new object[oldlen + 1];
  1293. Array.Copy(left.Data, newarr, oldlen);
  1294. newarr[oldlen] = right;
  1295. return new LSL_List(newarr);
  1296. }
  1297. public static LSL_List MethListAddList(LSL_List left, LSL_List right)
  1298. {
  1299. int leftlen = left.Length;
  1300. int ritelen = right.Length;
  1301. object[] newarr = new object[leftlen + ritelen];
  1302. Array.Copy(left.Data, newarr, leftlen);
  1303. Array.Copy(right.Data, 0, newarr, leftlen, ritelen);
  1304. return new LSL_List(newarr);
  1305. }
  1306. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1307. public static LSL_List MethFloatAddList(double left, LSL_List right)
  1308. {
  1309. return MethObjAddList(new LSL_Float(left), right);
  1310. }
  1311. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1312. public static LSL_List MethIntAddList(int left, LSL_List right)
  1313. {
  1314. return MethObjAddList(new LSL_Integer(left), right);
  1315. }
  1316. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1317. public static LSL_List MethKeyAddList(string left, LSL_List right)
  1318. {
  1319. return MethObjAddList(new LSL_Key(left), right);
  1320. }
  1321. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1322. public static LSL_List MethRotAddList(LSL_Rotation left, LSL_List right)
  1323. {
  1324. return MethObjAddList(left, right);
  1325. }
  1326. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1327. public static LSL_List MethStrAddList(string left, LSL_List right)
  1328. {
  1329. return MethObjAddList(new LSL_String(left), right);
  1330. }
  1331. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1332. public static LSL_List MethVecAddList(LSL_Vector left, LSL_List right)
  1333. {
  1334. return MethObjAddList(left, right);
  1335. }
  1336. public static LSL_List MethObjAddList(object left, LSL_List right)
  1337. {
  1338. int oldlen = right.Length;
  1339. object[] newarr = new object[oldlen + 1];
  1340. newarr[0] = left;
  1341. Array.Copy(right.Data, 0, newarr, 1, oldlen);
  1342. return new LSL_List(newarr);
  1343. }
  1344. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1345. public static bool MethListEqList(LSL_List left, LSL_List right)
  1346. {
  1347. return left == right;
  1348. }
  1349. // According to http://wiki.secondlife.com/wiki/LlGetListLength
  1350. // jackassed LSL allows 'somelist != []' to get the length of a list
  1351. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1352. public static int MethListNeList(LSL_List left, LSL_List right)
  1353. {
  1354. int leftlen = left.Length;
  1355. int ritelen = right.Length;
  1356. return leftlen - ritelen;
  1357. }
  1358. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1359. public static bool MethRotEqRot(LSL_Rotation left, LSL_Rotation right)
  1360. {
  1361. return left == right;
  1362. }
  1363. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1364. public static bool MethRotNeRot(LSL_Rotation left, LSL_Rotation right)
  1365. {
  1366. return left != right;
  1367. }
  1368. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1369. public static LSL_Rotation MethRotAddRot(LSL_Rotation left, LSL_Rotation right)
  1370. {
  1371. return left + right;
  1372. }
  1373. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1374. public static LSL_Rotation MethRotSubRot(LSL_Rotation left, LSL_Rotation right)
  1375. {
  1376. return left - right;
  1377. }
  1378. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1379. public static LSL_Rotation MethRotMulRot(LSL_Rotation left, LSL_Rotation right)
  1380. {
  1381. return left * right;
  1382. }
  1383. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1384. public static LSL_Rotation MethRotDivRot(LSL_Rotation left, LSL_Rotation right)
  1385. {
  1386. return left / right;
  1387. }
  1388. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1389. public static bool MethVecEqVec(LSL_Vector left, LSL_Vector right)
  1390. {
  1391. return left == right;
  1392. }
  1393. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1394. public static bool MethVecNeVec(LSL_Vector left, LSL_Vector right)
  1395. {
  1396. return left != right;
  1397. }
  1398. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1399. public static LSL_Vector MethVecAddVec(LSL_Vector left, LSL_Vector right)
  1400. {
  1401. return left + right;
  1402. }
  1403. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1404. public static LSL_Vector MethVecSubVec(LSL_Vector left, LSL_Vector right)
  1405. {
  1406. return left - right;
  1407. }
  1408. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1409. public static double MethVecMulVec(LSL_Vector left, LSL_Vector right)
  1410. {
  1411. return (double)(left * right).value;
  1412. }
  1413. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1414. public static LSL_Vector MethVecModVec(LSL_Vector left, LSL_Vector right)
  1415. {
  1416. return left % right;
  1417. }
  1418. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1419. public static LSL_Vector MethVecMulFloat(LSL_Vector left, double right)
  1420. {
  1421. return left * right;
  1422. }
  1423. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1424. public static LSL_Vector MethFloatMulVec(double left, LSL_Vector right)
  1425. {
  1426. return left * right;
  1427. }
  1428. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1429. public static LSL_Vector MethVecDivFloat(LSL_Vector left, double right)
  1430. {
  1431. return left / right;
  1432. }
  1433. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1434. public static LSL_Vector MethVecMulInt(LSL_Vector left, int right)
  1435. {
  1436. return left * right;
  1437. }
  1438. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1439. public static LSL_Vector MethIntMulVec(int left, LSL_Vector right)
  1440. {
  1441. return left * right;
  1442. }
  1443. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1444. public static LSL_Vector MethVecDivInt(LSL_Vector left, int right)
  1445. {
  1446. return left / right;
  1447. }
  1448. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1449. public static LSL_Vector MethVecMulRot(LSL_Vector left, LSL_Rotation right)
  1450. {
  1451. return left * right;
  1452. }
  1453. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1454. public static LSL_Vector MethVecDivRot(LSL_Vector left, LSL_Rotation right)
  1455. {
  1456. return left / right;
  1457. }
  1458. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1459. public static double MethDoubleDivDouble(double a, double b)
  1460. {
  1461. double r = a / b;
  1462. if (double.IsNaN(r) || double.IsInfinity(r))
  1463. throw new ScriptException("Division by Zero");
  1464. return r;
  1465. }
  1466. public static long MethLongDivLong(long a, long b)
  1467. {
  1468. try
  1469. {
  1470. return a / b;
  1471. }
  1472. catch (DivideByZeroException)
  1473. {
  1474. throw new ScriptException("Division by Zero");
  1475. }
  1476. }
  1477. public static double MethDoubleModDouble(double a, double b)
  1478. {
  1479. double r = a % b;
  1480. if (double.IsNaN(r) || double.IsInfinity(r))
  1481. throw new ScriptException("Division by Zero");
  1482. return r;
  1483. }
  1484. public static long MethLongModLong(long a, long b)
  1485. {
  1486. try
  1487. {
  1488. return a % b;
  1489. }
  1490. catch (DivideByZeroException)
  1491. {
  1492. throw new ScriptException("Division by Zero");
  1493. }
  1494. }
  1495. }
  1496. }