MMRScriptBinOpStr.cs 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577
  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 OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  28. using OpenSim.Region.ScriptEngine.Yengine;
  29. using System;
  30. using System.Collections.Generic;
  31. using System.IO;
  32. using System.Reflection;
  33. using System.Reflection.Emit;
  34. using System.Text;
  35. using System.Text.RegularExpressions;
  36. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  37. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  38. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  39. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  40. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  41. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  42. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  43. namespace OpenSim.Region.ScriptEngine.Yengine
  44. {
  45. /**
  46. * @brief This class is used to catalog the code emit routines based on a key string
  47. * The key string has the two types (eg, "integer", "rotation") and the operator (eg, "*", "!=")
  48. */
  49. public delegate void BinOpStrEmitBO(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result);
  50. public class BinOpStr
  51. {
  52. public static readonly Dictionary<string, BinOpStr> defined = DefineBinOps();
  53. public Type outtype; // type of result of computation
  54. public BinOpStrEmitBO emitBO; // how to compute result
  55. public bool rmwOK; // is the <operator>= form valid?
  56. public BinOpStr(Type outtype, BinOpStrEmitBO emitBO)
  57. {
  58. this.outtype = outtype;
  59. this.emitBO = emitBO;
  60. this.rmwOK = false;
  61. }
  62. public BinOpStr(Type outtype, BinOpStrEmitBO emitBO, bool rmwOK)
  63. {
  64. this.outtype = outtype;
  65. this.emitBO = emitBO;
  66. this.rmwOK = rmwOK;
  67. }
  68. private static TokenTypeBool tokenTypeBool = new TokenTypeBool(null);
  69. private static TokenTypeChar tokenTypeChar = new TokenTypeChar(null);
  70. private static TokenTypeFloat tokenTypeFloat = new TokenTypeFloat(null);
  71. private static TokenTypeInt tokenTypeInt = new TokenTypeInt(null);
  72. private static TokenTypeList tokenTypeList = new TokenTypeList(null);
  73. private static TokenTypeRot tokenTypeRot = new TokenTypeRot(null);
  74. private static TokenTypeStr tokenTypeStr = new TokenTypeStr(null);
  75. private static TokenTypeVec tokenTypeVec = new TokenTypeVec(null);
  76. private static MethodInfo stringAddStringMethInfo = ScriptCodeGen.GetStaticMethod(typeof(string), "Concat", new Type[] { typeof(string), typeof(string) });
  77. private static MethodInfo stringCmpStringMethInfo = ScriptCodeGen.GetStaticMethod(typeof(string), "Compare", new Type[] { typeof(string), typeof(string), typeof(StringComparison) });
  78. private static MethodInfo infoMethListAddFloat = GetBinOpsMethod("MethListAddFloat", new Type[] { typeof(LSL_List), typeof(double) });
  79. private static MethodInfo infoMethListAddInt = GetBinOpsMethod("MethListAddInt", new Type[] { typeof(LSL_List), typeof(int) });
  80. private static MethodInfo infoMethListAddKey = GetBinOpsMethod("MethListAddKey", new Type[] { typeof(LSL_List), typeof(string) });
  81. private static MethodInfo infoMethListAddRot = GetBinOpsMethod("MethListAddRot", new Type[] { typeof(LSL_List), typeof(LSL_Rotation) });
  82. private static MethodInfo infoMethListAddStr = GetBinOpsMethod("MethListAddStr", new Type[] { typeof(LSL_List), typeof(string) });
  83. private static MethodInfo infoMethListAddVec = GetBinOpsMethod("MethListAddVec", new Type[] { typeof(LSL_List), typeof(LSL_Vector) });
  84. private static MethodInfo infoMethListAddList = GetBinOpsMethod("MethListAddList", new Type[] { typeof(LSL_List), typeof(LSL_List) });
  85. private static MethodInfo infoMethFloatAddList = GetBinOpsMethod("MethFloatAddList", new Type[] { typeof(double), typeof(LSL_List) });
  86. private static MethodInfo infoMethIntAddList = GetBinOpsMethod("MethIntAddList", new Type[] { typeof(int), typeof(LSL_List) });
  87. private static MethodInfo infoMethKeyAddList = GetBinOpsMethod("MethKeyAddList", new Type[] { typeof(string), typeof(LSL_List) });
  88. private static MethodInfo infoMethRotAddList = GetBinOpsMethod("MethRotAddList", new Type[] { typeof(LSL_Rotation), typeof(LSL_List) });
  89. private static MethodInfo infoMethStrAddList = GetBinOpsMethod("MethStrAddList", new Type[] { typeof(string), typeof(LSL_List) });
  90. private static MethodInfo infoMethVecAddList = GetBinOpsMethod("MethVecAddList", new Type[] { typeof(LSL_Vector), typeof(LSL_List) });
  91. private static MethodInfo infoMethListEqList = GetBinOpsMethod("MethListEqList", new Type[] { typeof(LSL_List), typeof(LSL_List) });
  92. private static MethodInfo infoMethListNeList = GetBinOpsMethod("MethListNeList", new Type[] { typeof(LSL_List), typeof(LSL_List) });
  93. private static MethodInfo infoMethRotEqRot = GetBinOpsMethod("MethRotEqRot", new Type[] { typeof(LSL_Rotation), typeof(LSL_Rotation) });
  94. private static MethodInfo infoMethRotNeRot = GetBinOpsMethod("MethRotNeRot", new Type[] { typeof(LSL_Rotation), typeof(LSL_Rotation) });
  95. private static MethodInfo infoMethRotAddRot = GetBinOpsMethod("MethRotAddRot", new Type[] { typeof(LSL_Rotation), typeof(LSL_Rotation) });
  96. private static MethodInfo infoMethRotSubRot = GetBinOpsMethod("MethRotSubRot", new Type[] { typeof(LSL_Rotation), typeof(LSL_Rotation) });
  97. private static MethodInfo infoMethRotMulRot = GetBinOpsMethod("MethRotMulRot", new Type[] { typeof(LSL_Rotation), typeof(LSL_Rotation) });
  98. private static MethodInfo infoMethRotDivRot = GetBinOpsMethod("MethRotDivRot", new Type[] { typeof(LSL_Rotation), typeof(LSL_Rotation) });
  99. private static MethodInfo infoMethVecEqVec = GetBinOpsMethod("MethVecEqVec", new Type[] { typeof(LSL_Vector), typeof(LSL_Vector) });
  100. private static MethodInfo infoMethVecNeVec = GetBinOpsMethod("MethVecNeVec", new Type[] { typeof(LSL_Vector), typeof(LSL_Vector) });
  101. private static MethodInfo infoMethVecAddVec = GetBinOpsMethod("MethVecAddVec", new Type[] { typeof(LSL_Vector), typeof(LSL_Vector) });
  102. private static MethodInfo infoMethVecSubVec = GetBinOpsMethod("MethVecSubVec", new Type[] { typeof(LSL_Vector), typeof(LSL_Vector) });
  103. private static MethodInfo infoMethVecMulVec = GetBinOpsMethod("MethVecMulVec", new Type[] { typeof(LSL_Vector), typeof(LSL_Vector) });
  104. private static MethodInfo infoMethVecModVec = GetBinOpsMethod("MethVecModVec", new Type[] { typeof(LSL_Vector), typeof(LSL_Vector) });
  105. private static MethodInfo infoMethVecMulFloat = GetBinOpsMethod("MethVecMulFloat", new Type[] { typeof(LSL_Vector), typeof(double) });
  106. private static MethodInfo infoMethFloatMulVec = GetBinOpsMethod("MethFloatMulVec", new Type[] { typeof(double), typeof(LSL_Vector) });
  107. private static MethodInfo infoMethVecDivFloat = GetBinOpsMethod("MethVecDivFloat", new Type[] { typeof(LSL_Vector), typeof(double) });
  108. private static MethodInfo infoMethVecMulInt = GetBinOpsMethod("MethVecMulInt", new Type[] { typeof(LSL_Vector), typeof(int) });
  109. private static MethodInfo infoMethIntMulVec = GetBinOpsMethod("MethIntMulVec", new Type[] { typeof(int), typeof(LSL_Vector) });
  110. private static MethodInfo infoMethVecDivInt = GetBinOpsMethod("MethVecDivInt", new Type[] { typeof(LSL_Vector), typeof(int) });
  111. private static MethodInfo infoMethVecMulRot = GetBinOpsMethod("MethVecMulRot", new Type[] { typeof(LSL_Vector), typeof(LSL_Rotation) });
  112. private static MethodInfo infoMethVecDivRot = GetBinOpsMethod("MethVecDivRot", new Type[] { typeof(LSL_Vector), typeof(LSL_Rotation) });
  113. private static MethodInfo GetBinOpsMethod(string name, Type[] types)
  114. {
  115. return ScriptCodeGen.GetStaticMethod(typeof(BinOpStr), name, types);
  116. }
  117. /**
  118. * @brief Create a dictionary for processing binary operators.
  119. * This tells us, for a given type, an operator and another type,
  120. * is the operation permitted, and if so, what is the type of the result?
  121. * The key is <lefttype><opcode><righttype>,
  122. * where <lefttype> and <righttype> are strings returned by (TokenType...).ToString()
  123. * and <opcode> is string returned by (TokenKw...).ToString()
  124. * The value is a BinOpStr struct giving the resultant type and a method to generate the code.
  125. */
  126. private static Dictionary<string, BinOpStr> DefineBinOps()
  127. {
  128. Dictionary<string, BinOpStr> bos = new Dictionary<string, BinOpStr>();
  129. string[] booltypes = new string[] { "bool", "char", "float", "integer", "key", "list", "string" };
  130. /*
  131. * Get the && and || all out of the way...
  132. * Simply cast their left and right operands to boolean then process.
  133. */
  134. for(int i = 0; i < booltypes.Length; i++)
  135. {
  136. for(int j = 0; j < booltypes.Length; j++)
  137. {
  138. bos.Add(booltypes[i] + "&&" + booltypes[j],
  139. new BinOpStr(typeof(bool), BinOpStrAndAnd));
  140. bos.Add(booltypes[i] + "||" + booltypes[j],
  141. 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. result.PopPost(scg, errorAt, tokenTypeFloat);
  530. }
  531. private static void BinOpStrFloatModX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  532. {
  533. result.PopPre(scg, errorAt);
  534. left.PushVal(scg, errorAt, tokenTypeFloat);
  535. right.PushVal(scg, errorAt, tokenTypeFloat);
  536. scg.ilGen.Emit(errorAt, OpCodes.Rem);
  537. result.PopPost(scg, errorAt, tokenTypeFloat);
  538. }
  539. private static void BinOpStrXEqFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  540. {
  541. result.PopPre(scg, errorAt);
  542. left.PushVal(scg, errorAt, tokenTypeFloat);
  543. right.PushVal(scg, errorAt, tokenTypeFloat);
  544. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  545. result.PopPost(scg, errorAt, tokenTypeBool);
  546. }
  547. private static void BinOpStrXNeFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  548. {
  549. result.PopPre(scg, errorAt);
  550. left.PushVal(scg, errorAt, tokenTypeFloat);
  551. right.PushVal(scg, errorAt, tokenTypeFloat);
  552. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  553. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  554. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  555. result.PopPost(scg, errorAt, tokenTypeBool);
  556. }
  557. private static void BinOpStrXLtFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  558. {
  559. result.PopPre(scg, errorAt);
  560. left.PushVal(scg, errorAt, tokenTypeFloat);
  561. right.PushVal(scg, errorAt, tokenTypeFloat);
  562. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  563. result.PopPost(scg, errorAt, tokenTypeBool);
  564. }
  565. private static void BinOpStrXLeFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  566. {
  567. result.PopPre(scg, errorAt);
  568. left.PushVal(scg, errorAt, tokenTypeFloat);
  569. right.PushVal(scg, errorAt, tokenTypeFloat);
  570. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  571. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  572. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  573. result.PopPost(scg, errorAt, tokenTypeBool);
  574. }
  575. private static void BinOpStrXGtFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  576. {
  577. result.PopPre(scg, errorAt);
  578. left.PushVal(scg, errorAt, tokenTypeFloat);
  579. right.PushVal(scg, errorAt, tokenTypeFloat);
  580. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  581. result.PopPost(scg, errorAt, tokenTypeBool);
  582. }
  583. private static void BinOpStrXGeFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  584. {
  585. result.PopPre(scg, errorAt);
  586. left.PushVal(scg, errorAt, tokenTypeFloat);
  587. right.PushVal(scg, errorAt, tokenTypeFloat);
  588. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  589. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  590. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  591. result.PopPost(scg, errorAt, tokenTypeBool);
  592. }
  593. private static void BinOpStrXAddFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  594. {
  595. result.PopPre(scg, errorAt);
  596. left.PushVal(scg, errorAt, tokenTypeFloat);
  597. right.PushVal(scg, errorAt, tokenTypeFloat);
  598. scg.ilGen.Emit(errorAt, OpCodes.Add);
  599. result.PopPost(scg, errorAt, tokenTypeFloat);
  600. }
  601. private static void BinOpStrXSubFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  602. {
  603. result.PopPre(scg, errorAt);
  604. left.PushVal(scg, errorAt, tokenTypeFloat);
  605. right.PushVal(scg, errorAt, tokenTypeFloat);
  606. scg.ilGen.Emit(errorAt, OpCodes.Sub);
  607. result.PopPost(scg, errorAt, tokenTypeFloat);
  608. }
  609. private static void BinOpStrXMulFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  610. {
  611. result.PopPre(scg, errorAt);
  612. left.PushVal(scg, errorAt, tokenTypeFloat);
  613. right.PushVal(scg, errorAt, tokenTypeFloat);
  614. scg.ilGen.Emit(errorAt, OpCodes.Mul);
  615. result.PopPost(scg, errorAt, tokenTypeFloat);
  616. }
  617. private static void BinOpStrXDivFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  618. {
  619. result.PopPre(scg, errorAt);
  620. left.PushVal(scg, errorAt, tokenTypeFloat);
  621. right.PushVal(scg, errorAt, tokenTypeFloat);
  622. scg.ilGen.Emit(errorAt, OpCodes.Div);
  623. result.PopPost(scg, errorAt, tokenTypeFloat);
  624. }
  625. private static void BinOpStrXModFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  626. {
  627. result.PopPre(scg, errorAt);
  628. left.PushVal(scg, errorAt, tokenTypeFloat);
  629. right.PushVal(scg, errorAt, tokenTypeFloat);
  630. scg.ilGen.Emit(errorAt, OpCodes.Rem);
  631. result.PopPost(scg, errorAt, tokenTypeFloat);
  632. }
  633. private static void BinOpStrCharEqChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  634. {
  635. result.PopPre(scg, errorAt);
  636. left.PushVal(scg, errorAt, tokenTypeChar);
  637. right.PushVal(scg, errorAt, tokenTypeChar);
  638. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  639. result.PopPost(scg, errorAt, tokenTypeBool);
  640. }
  641. private static void BinOpStrCharNeChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  642. {
  643. result.PopPre(scg, errorAt);
  644. left.PushVal(scg, errorAt, tokenTypeChar);
  645. right.PushVal(scg, errorAt, tokenTypeChar);
  646. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  647. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  648. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  649. result.PopPost(scg, errorAt, tokenTypeBool);
  650. }
  651. private static void BinOpStrCharLtChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  652. {
  653. result.PopPre(scg, errorAt);
  654. left.PushVal(scg, errorAt, tokenTypeChar);
  655. right.PushVal(scg, errorAt, tokenTypeChar);
  656. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  657. result.PopPost(scg, errorAt, tokenTypeBool);
  658. }
  659. private static void BinOpStrCharLeChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  660. {
  661. result.PopPre(scg, errorAt);
  662. left.PushVal(scg, errorAt, tokenTypeChar);
  663. right.PushVal(scg, errorAt, tokenTypeChar);
  664. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  665. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  666. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  667. result.PopPost(scg, errorAt, tokenTypeBool);
  668. }
  669. private static void BinOpStrCharGtChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  670. {
  671. result.PopPre(scg, errorAt);
  672. left.PushVal(scg, errorAt, tokenTypeChar);
  673. right.PushVal(scg, errorAt, tokenTypeChar);
  674. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  675. result.PopPost(scg, errorAt, tokenTypeBool);
  676. }
  677. private static void BinOpStrCharGeChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  678. {
  679. result.PopPre(scg, errorAt);
  680. left.PushVal(scg, errorAt, tokenTypeChar);
  681. right.PushVal(scg, errorAt, tokenTypeChar);
  682. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  683. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  684. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  685. result.PopPost(scg, errorAt, tokenTypeBool);
  686. }
  687. private static void BinOpStrCharAddInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  688. {
  689. result.PopPre(scg, errorAt);
  690. left.PushVal(scg, errorAt, tokenTypeChar);
  691. right.PushVal(scg, errorAt, tokenTypeInt);
  692. scg.ilGen.Emit(errorAt, OpCodes.Add);
  693. result.PopPost(scg, errorAt, tokenTypeChar);
  694. }
  695. private static void BinOpStrCharSubInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  696. {
  697. result.PopPre(scg, errorAt);
  698. left.PushVal(scg, errorAt, tokenTypeChar);
  699. right.PushVal(scg, errorAt, tokenTypeInt);
  700. scg.ilGen.Emit(errorAt, OpCodes.Sub);
  701. result.PopPost(scg, errorAt, tokenTypeChar);
  702. }
  703. private static void BinOpStrCharSubChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  704. {
  705. result.PopPre(scg, errorAt);
  706. left.PushVal(scg, errorAt, tokenTypeChar);
  707. right.PushVal(scg, errorAt, tokenTypeChar);
  708. scg.ilGen.Emit(errorAt, OpCodes.Sub);
  709. result.PopPost(scg, errorAt, tokenTypeInt);
  710. }
  711. private static void BinOpStrIntEqInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  712. {
  713. result.PopPre(scg, errorAt);
  714. left.PushVal(scg, errorAt, tokenTypeInt);
  715. right.PushVal(scg, errorAt, tokenTypeInt);
  716. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  717. result.PopPost(scg, errorAt, tokenTypeBool);
  718. }
  719. private static void BinOpStrIntNeInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  720. {
  721. result.PopPre(scg, errorAt);
  722. left.PushVal(scg, errorAt, tokenTypeInt);
  723. right.PushVal(scg, errorAt, tokenTypeInt);
  724. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  725. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  726. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  727. result.PopPost(scg, errorAt, tokenTypeBool);
  728. }
  729. private static void BinOpStrIntLtInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  730. {
  731. result.PopPre(scg, errorAt);
  732. left.PushVal(scg, errorAt, tokenTypeInt);
  733. right.PushVal(scg, errorAt, tokenTypeInt);
  734. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  735. result.PopPost(scg, errorAt, tokenTypeBool);
  736. }
  737. private static void BinOpStrIntLeInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  738. {
  739. result.PopPre(scg, errorAt);
  740. left.PushVal(scg, errorAt, tokenTypeInt);
  741. right.PushVal(scg, errorAt, tokenTypeInt);
  742. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  743. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  744. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  745. result.PopPost(scg, errorAt, tokenTypeBool);
  746. }
  747. private static void BinOpStrIntGtInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  748. {
  749. result.PopPre(scg, errorAt);
  750. left.PushVal(scg, errorAt, tokenTypeInt);
  751. right.PushVal(scg, errorAt, tokenTypeInt);
  752. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  753. result.PopPost(scg, errorAt, tokenTypeBool);
  754. }
  755. private static void BinOpStrIntGeInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  756. {
  757. result.PopPre(scg, errorAt);
  758. left.PushVal(scg, errorAt, tokenTypeInt);
  759. right.PushVal(scg, errorAt, tokenTypeInt);
  760. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  761. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  762. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  763. result.PopPost(scg, errorAt, tokenTypeBool);
  764. }
  765. private static void BinOpStrIntOrInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  766. {
  767. result.PopPre(scg, errorAt);
  768. left.PushVal(scg, errorAt, tokenTypeInt);
  769. right.PushVal(scg, errorAt, tokenTypeInt);
  770. scg.ilGen.Emit(errorAt, OpCodes.Or);
  771. result.PopPost(scg, errorAt, tokenTypeInt);
  772. }
  773. private static void BinOpStrIntXorInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  774. {
  775. result.PopPre(scg, errorAt);
  776. left.PushVal(scg, errorAt, tokenTypeInt);
  777. right.PushVal(scg, errorAt, tokenTypeInt);
  778. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  779. result.PopPost(scg, errorAt, tokenTypeInt);
  780. }
  781. private static void BinOpStrIntAndInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  782. {
  783. result.PopPre(scg, errorAt);
  784. left.PushVal(scg, errorAt, tokenTypeInt);
  785. right.PushVal(scg, errorAt, tokenTypeInt);
  786. scg.ilGen.Emit(errorAt, OpCodes.And);
  787. result.PopPost(scg, errorAt, tokenTypeInt);
  788. }
  789. private static void BinOpStrIntAddInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  790. {
  791. result.PopPre(scg, errorAt);
  792. left.PushVal(scg, errorAt, tokenTypeInt);
  793. right.PushVal(scg, errorAt, tokenTypeInt);
  794. scg.ilGen.Emit(errorAt, OpCodes.Add);
  795. result.PopPost(scg, errorAt, tokenTypeInt);
  796. }
  797. private static void BinOpStrIntSubInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  798. {
  799. result.PopPre(scg, errorAt);
  800. left.PushVal(scg, errorAt, tokenTypeInt);
  801. right.PushVal(scg, errorAt, tokenTypeInt);
  802. scg.ilGen.Emit(errorAt, OpCodes.Sub);
  803. result.PopPost(scg, errorAt, tokenTypeInt);
  804. }
  805. private static void BinOpStrIntMulInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  806. {
  807. result.PopPre(scg, errorAt);
  808. left.PushVal(scg, errorAt, tokenTypeInt);
  809. right.PushVal(scg, errorAt, tokenTypeInt);
  810. scg.ilGen.Emit(errorAt, OpCodes.Mul);
  811. result.PopPost(scg, errorAt, tokenTypeInt);
  812. }
  813. private static void BinOpStrIntDivInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  814. {
  815. // note that we must allow 0x800000/-1 -> 0x80000000 for lslangtest1.lsl
  816. // so sign-extend the operands to 64-bit then divide and truncate result
  817. result.PopPre(scg, errorAt);
  818. left.PushVal(scg, errorAt, tokenTypeInt);
  819. scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
  820. right.PushVal(scg, errorAt, tokenTypeInt);
  821. scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
  822. scg.ilGen.Emit(errorAt, OpCodes.Div);
  823. scg.ilGen.Emit(errorAt, OpCodes.Conv_I4);
  824. result.PopPost(scg, errorAt, tokenTypeInt);
  825. }
  826. private static void BinOpStrIntModInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  827. {
  828. // note that we must allow 0x800000%-1 -> 0 for lslangtest1.lsl
  829. // so sign-extend the operands to 64-bit then mod and truncate result
  830. result.PopPre(scg, errorAt);
  831. left.PushVal(scg, errorAt, tokenTypeInt);
  832. scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
  833. right.PushVal(scg, errorAt, tokenTypeInt);
  834. scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
  835. scg.ilGen.Emit(errorAt, OpCodes.Rem);
  836. scg.ilGen.Emit(errorAt, OpCodes.Conv_I4);
  837. result.PopPost(scg, errorAt, tokenTypeInt);
  838. }
  839. private static void BinOpStrIntShlInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  840. {
  841. result.PopPre(scg, errorAt);
  842. left.PushVal(scg, errorAt, tokenTypeInt);
  843. right.PushVal(scg, errorAt, tokenTypeInt);
  844. scg.ilGen.Emit(errorAt, OpCodes.Shl);
  845. result.PopPost(scg, errorAt, tokenTypeInt);
  846. }
  847. private static void BinOpStrIntShrInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  848. {
  849. result.PopPre(scg, errorAt);
  850. left.PushVal(scg, errorAt, tokenTypeInt);
  851. right.PushVal(scg, errorAt, tokenTypeInt);
  852. scg.ilGen.Emit(errorAt, OpCodes.Shr);
  853. result.PopPost(scg, errorAt, tokenTypeInt);
  854. }
  855. private static void BinOpStrKeyEqX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  856. {
  857. result.PopPre(scg, errorAt);
  858. left.PushVal(scg, errorAt, tokenTypeStr);
  859. right.PushVal(scg, errorAt, tokenTypeStr);
  860. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
  861. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  862. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  863. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  864. result.PopPost(scg, errorAt, tokenTypeBool);
  865. }
  866. private static void BinOpStrKeyNeX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  867. {
  868. result.PopPre(scg, errorAt);
  869. left.PushVal(scg, errorAt, tokenTypeStr);
  870. right.PushVal(scg, errorAt, tokenTypeStr);
  871. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
  872. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  873. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  874. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  875. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  876. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  877. result.PopPost(scg, errorAt, tokenTypeBool);
  878. }
  879. private static void BinOpStrListAddFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  880. {
  881. result.PopPre(scg, errorAt);
  882. left.PushVal(scg, errorAt, tokenTypeList);
  883. right.PushVal(scg, errorAt, tokenTypeFloat);
  884. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddFloat);
  885. result.PopPost(scg, errorAt, tokenTypeList);
  886. }
  887. private static void BinOpStrListAddInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  888. {
  889. result.PopPre(scg, errorAt);
  890. left.PushVal(scg, errorAt, tokenTypeList);
  891. right.PushVal(scg, errorAt, tokenTypeInt);
  892. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddInt);
  893. result.PopPost(scg, errorAt, tokenTypeList);
  894. }
  895. private static void BinOpStrListAddKey(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  896. {
  897. result.PopPre(scg, errorAt);
  898. left.PushVal(scg, errorAt, tokenTypeList);
  899. right.PushVal(scg, errorAt, tokenTypeStr);
  900. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddKey);
  901. result.PopPost(scg, errorAt, tokenTypeList);
  902. }
  903. private static void BinOpStrListAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  904. {
  905. result.PopPre(scg, errorAt);
  906. left.PushVal(scg, errorAt, tokenTypeList);
  907. right.PushVal(scg, errorAt, tokenTypeList);
  908. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddList);
  909. result.PopPost(scg, errorAt, tokenTypeList);
  910. }
  911. private static void BinOpStrListAddRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  912. {
  913. result.PopPre(scg, errorAt);
  914. left.PushVal(scg, errorAt, tokenTypeList);
  915. right.PushVal(scg, errorAt, tokenTypeRot);
  916. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddRot);
  917. result.PopPost(scg, errorAt, tokenTypeList);
  918. }
  919. private static void BinOpStrListAddStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  920. {
  921. result.PopPre(scg, errorAt);
  922. left.PushVal(scg, errorAt, tokenTypeList);
  923. right.PushVal(scg, errorAt, tokenTypeStr);
  924. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddStr);
  925. result.PopPost(scg, errorAt, tokenTypeList);
  926. }
  927. private static void BinOpStrListAddVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  928. {
  929. result.PopPre(scg, errorAt);
  930. left.PushVal(scg, errorAt, tokenTypeList);
  931. right.PushVal(scg, errorAt, tokenTypeVec);
  932. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddVec);
  933. result.PopPost(scg, errorAt, tokenTypeList);
  934. }
  935. private static void BinOpStrFloatAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  936. {
  937. result.PopPre(scg, errorAt);
  938. left.PushVal(scg, errorAt, tokenTypeFloat);
  939. right.PushVal(scg, errorAt, tokenTypeList);
  940. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethFloatAddList);
  941. result.PopPost(scg, errorAt, tokenTypeList);
  942. }
  943. private static void BinOpStrIntAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  944. {
  945. result.PopPre(scg, errorAt);
  946. left.PushVal(scg, errorAt, tokenTypeInt);
  947. right.PushVal(scg, errorAt, tokenTypeList);
  948. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethIntAddList);
  949. result.PopPost(scg, errorAt, tokenTypeList);
  950. }
  951. private static void BinOpStrKeyAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  952. {
  953. result.PopPre(scg, errorAt);
  954. left.PushVal(scg, errorAt, tokenTypeStr);
  955. right.PushVal(scg, errorAt, tokenTypeList);
  956. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethKeyAddList);
  957. result.PopPost(scg, errorAt, tokenTypeList);
  958. }
  959. private static void BinOpStrRotAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  960. {
  961. result.PopPre(scg, errorAt);
  962. left.PushVal(scg, errorAt, tokenTypeRot);
  963. right.PushVal(scg, errorAt, tokenTypeList);
  964. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotAddList);
  965. result.PopPost(scg, errorAt, tokenTypeList);
  966. }
  967. private static void BinOpStrStrAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  968. {
  969. result.PopPre(scg, errorAt);
  970. left.PushVal(scg, errorAt, tokenTypeStr);
  971. right.PushVal(scg, errorAt, tokenTypeList);
  972. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethStrAddList);
  973. result.PopPost(scg, errorAt, tokenTypeList);
  974. }
  975. private static void BinOpStrVecAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  976. {
  977. result.PopPre(scg, errorAt);
  978. left.PushVal(scg, errorAt, tokenTypeVec);
  979. right.PushVal(scg, errorAt, tokenTypeList);
  980. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecAddList);
  981. result.PopPost(scg, errorAt, tokenTypeList);
  982. }
  983. private static void BinOpStrListEqList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  984. {
  985. result.PopPre(scg, errorAt);
  986. left.PushVal(scg, errorAt, tokenTypeList);
  987. right.PushVal(scg, errorAt, tokenTypeList);
  988. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListEqList);
  989. result.PopPost(scg, errorAt, tokenTypeBool);
  990. }
  991. private static void BinOpStrListNeList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  992. {
  993. result.PopPre(scg, errorAt);
  994. left.PushVal(scg, errorAt, tokenTypeList);
  995. right.PushVal(scg, errorAt, tokenTypeList);
  996. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListNeList);
  997. result.PopPost(scg, errorAt, tokenTypeBool);
  998. }
  999. private static void BinOpStrRotEqRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1000. {
  1001. result.PopPre(scg, errorAt);
  1002. left.PushVal(scg, errorAt, tokenTypeRot);
  1003. right.PushVal(scg, errorAt, tokenTypeRot);
  1004. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotEqRot);
  1005. result.PopPost(scg, errorAt, tokenTypeBool);
  1006. }
  1007. private static void BinOpStrRotNeRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1008. {
  1009. result.PopPre(scg, errorAt);
  1010. left.PushVal(scg, errorAt, tokenTypeRot);
  1011. right.PushVal(scg, errorAt, tokenTypeRot);
  1012. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotNeRot);
  1013. result.PopPost(scg, errorAt, tokenTypeBool);
  1014. }
  1015. private static void BinOpStrRotAddRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1016. {
  1017. result.PopPre(scg, errorAt);
  1018. left.PushVal(scg, errorAt, tokenTypeRot);
  1019. right.PushVal(scg, errorAt, tokenTypeRot);
  1020. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotAddRot);
  1021. result.PopPost(scg, errorAt, tokenTypeRot);
  1022. }
  1023. private static void BinOpStrRotSubRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1024. {
  1025. result.PopPre(scg, errorAt);
  1026. left.PushVal(scg, errorAt, tokenTypeRot);
  1027. right.PushVal(scg, errorAt, tokenTypeRot);
  1028. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotSubRot);
  1029. result.PopPost(scg, errorAt, tokenTypeRot);
  1030. }
  1031. private static void BinOpStrRotMulRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1032. {
  1033. result.PopPre(scg, errorAt);
  1034. left.PushVal(scg, errorAt, tokenTypeRot);
  1035. right.PushVal(scg, errorAt, tokenTypeRot);
  1036. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotMulRot);
  1037. result.PopPost(scg, errorAt, tokenTypeRot);
  1038. }
  1039. private static void BinOpStrRotDivRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1040. {
  1041. result.PopPre(scg, errorAt);
  1042. left.PushVal(scg, errorAt, tokenTypeRot);
  1043. right.PushVal(scg, errorAt, tokenTypeRot);
  1044. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotDivRot);
  1045. result.PopPost(scg, errorAt, tokenTypeRot);
  1046. }
  1047. private static void BinOpStrStrEqStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1048. {
  1049. result.PopPre(scg, errorAt);
  1050. left.PushVal(scg, errorAt, tokenTypeStr);
  1051. right.PushVal(scg, errorAt, tokenTypeStr);
  1052. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
  1053. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1054. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  1055. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  1056. result.PopPost(scg, errorAt, tokenTypeBool);
  1057. }
  1058. private static void BinOpStrStrNeStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1059. {
  1060. result.PopPre(scg, errorAt);
  1061. left.PushVal(scg, errorAt, tokenTypeStr);
  1062. right.PushVal(scg, errorAt, tokenTypeStr);
  1063. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
  1064. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1065. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  1066. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  1067. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  1068. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  1069. result.PopPost(scg, errorAt, tokenTypeBool);
  1070. }
  1071. private static void BinOpStrStrLtStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1072. {
  1073. result.PopPre(scg, errorAt);
  1074. left.PushVal(scg, errorAt, tokenTypeStr);
  1075. right.PushVal(scg, errorAt, tokenTypeStr);
  1076. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
  1077. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1078. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  1079. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  1080. result.PopPost(scg, errorAt, tokenTypeBool);
  1081. }
  1082. private static void BinOpStrStrLeStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1083. {
  1084. result.PopPre(scg, errorAt);
  1085. left.PushVal(scg, errorAt, tokenTypeStr);
  1086. right.PushVal(scg, errorAt, tokenTypeStr);
  1087. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
  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.Ldc_I4, (int)StringComparison.Ordinal);
  1099. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1100. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  1101. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  1102. result.PopPost(scg, errorAt, tokenTypeBool);
  1103. }
  1104. private static void BinOpStrStrGeStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1105. {
  1106. result.PopPre(scg, errorAt);
  1107. left.PushVal(scg, errorAt, tokenTypeStr);
  1108. right.PushVal(scg, errorAt, tokenTypeStr);
  1109. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
  1110. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1111. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_M1);
  1112. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  1113. result.PopPost(scg, errorAt, tokenTypeBool);
  1114. }
  1115. // Called by many type combinations so both operands need to be cast to strings
  1116. private static void BinOpStrStrAddStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1117. {
  1118. result.PopPre(scg, errorAt);
  1119. left.PushVal(scg, errorAt, tokenTypeStr);
  1120. right.PushVal(scg, errorAt, tokenTypeStr);
  1121. scg.ilGen.Emit(errorAt, OpCodes.Call, stringAddStringMethInfo);
  1122. result.PopPost(scg, errorAt, tokenTypeStr);
  1123. }
  1124. private static void BinOpStrVecEqVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1125. {
  1126. result.PopPre(scg, errorAt);
  1127. left.PushVal(scg, errorAt, tokenTypeVec);
  1128. right.PushVal(scg, errorAt, tokenTypeVec);
  1129. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecEqVec);
  1130. result.PopPost(scg, errorAt, tokenTypeBool);
  1131. }
  1132. private static void BinOpStrVecNeVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1133. {
  1134. result.PopPre(scg, errorAt);
  1135. left.PushVal(scg, errorAt, tokenTypeVec);
  1136. right.PushVal(scg, errorAt, tokenTypeVec);
  1137. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecNeVec);
  1138. result.PopPost(scg, errorAt, tokenTypeBool);
  1139. }
  1140. private static void BinOpStrVecAddVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1141. {
  1142. result.PopPre(scg, errorAt);
  1143. left.PushVal(scg, errorAt, tokenTypeVec);
  1144. right.PushVal(scg, errorAt, tokenTypeVec);
  1145. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecAddVec);
  1146. result.PopPost(scg, errorAt, tokenTypeVec);
  1147. }
  1148. private static void BinOpStrVecSubVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1149. {
  1150. result.PopPre(scg, errorAt);
  1151. left.PushVal(scg, errorAt, tokenTypeVec);
  1152. right.PushVal(scg, errorAt, tokenTypeVec);
  1153. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecSubVec);
  1154. result.PopPost(scg, errorAt, tokenTypeVec);
  1155. }
  1156. private static void BinOpStrVecMulVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1157. {
  1158. result.PopPre(scg, errorAt);
  1159. left.PushVal(scg, errorAt, tokenTypeVec);
  1160. right.PushVal(scg, errorAt, tokenTypeVec);
  1161. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulVec);
  1162. result.PopPost(scg, errorAt, tokenTypeFloat);
  1163. }
  1164. private static void BinOpStrVecModVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1165. {
  1166. result.PopPre(scg, errorAt);
  1167. left.PushVal(scg, errorAt, tokenTypeVec);
  1168. right.PushVal(scg, errorAt, tokenTypeVec);
  1169. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecModVec);
  1170. result.PopPost(scg, errorAt, tokenTypeVec);
  1171. }
  1172. private static void BinOpStrVecMulFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1173. {
  1174. result.PopPre(scg, errorAt);
  1175. left.PushVal(scg, errorAt, tokenTypeVec);
  1176. right.PushVal(scg, errorAt, tokenTypeFloat);
  1177. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulFloat);
  1178. result.PopPost(scg, errorAt, tokenTypeVec);
  1179. }
  1180. private static void BinOpStrFloatMulVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1181. {
  1182. result.PopPre(scg, errorAt);
  1183. left.PushVal(scg, errorAt, tokenTypeFloat);
  1184. right.PushVal(scg, errorAt, tokenTypeVec);
  1185. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethFloatMulVec);
  1186. result.PopPost(scg, errorAt, tokenTypeVec);
  1187. }
  1188. private static void BinOpStrVecDivFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1189. {
  1190. result.PopPre(scg, errorAt);
  1191. left.PushVal(scg, errorAt, tokenTypeVec);
  1192. right.PushVal(scg, errorAt, tokenTypeFloat);
  1193. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecDivFloat);
  1194. result.PopPost(scg, errorAt, tokenTypeVec);
  1195. }
  1196. private static void BinOpStrVecMulInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1197. {
  1198. result.PopPre(scg, errorAt);
  1199. left.PushVal(scg, errorAt, tokenTypeVec);
  1200. right.PushVal(scg, errorAt, tokenTypeInt);
  1201. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulInt);
  1202. result.PopPost(scg, errorAt, tokenTypeVec);
  1203. }
  1204. private static void BinOpStrIntMulVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1205. {
  1206. result.PopPre(scg, errorAt);
  1207. left.PushVal(scg, errorAt, tokenTypeInt);
  1208. right.PushVal(scg, errorAt, tokenTypeVec);
  1209. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethIntMulVec);
  1210. result.PopPost(scg, errorAt, tokenTypeVec);
  1211. }
  1212. private static void BinOpStrVecDivInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1213. {
  1214. result.PopPre(scg, errorAt);
  1215. left.PushVal(scg, errorAt, tokenTypeVec);
  1216. right.PushVal(scg, errorAt, tokenTypeInt);
  1217. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecDivInt);
  1218. result.PopPost(scg, errorAt, tokenTypeVec);
  1219. }
  1220. private static void BinOpStrVecMulRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1221. {
  1222. result.PopPre(scg, errorAt);
  1223. left.PushVal(scg, errorAt, tokenTypeVec);
  1224. right.PushVal(scg, errorAt, tokenTypeRot);
  1225. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulRot);
  1226. result.PopPost(scg, errorAt, tokenTypeVec);
  1227. }
  1228. private static void BinOpStrVecDivRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1229. {
  1230. result.PopPre(scg, errorAt);
  1231. left.PushVal(scg, errorAt, tokenTypeVec);
  1232. right.PushVal(scg, errorAt, tokenTypeRot);
  1233. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecDivRot);
  1234. result.PopPost(scg, errorAt, tokenTypeVec);
  1235. }
  1236. /**
  1237. * @brief These methods are called at runtime as helpers.
  1238. * Needed to pick up functionality defined by overloaded operators of LSL_ types.
  1239. * They need to be marked public or runtime says they are inaccessible.
  1240. */
  1241. public static LSL_List MethListAddFloat(LSL_List left, double right)
  1242. {
  1243. return MethListAddObj(left, new LSL_Float(right));
  1244. }
  1245. public static LSL_List MethListAddInt(LSL_List left, int right)
  1246. {
  1247. return MethListAddObj(left, new LSL_Integer(right));
  1248. }
  1249. public static LSL_List MethListAddKey(LSL_List left, string right)
  1250. {
  1251. return MethListAddObj(left, new LSL_Key(right));
  1252. }
  1253. public static LSL_List MethListAddRot(LSL_List left, LSL_Rotation right)
  1254. {
  1255. return MethListAddObj(left, right);
  1256. }
  1257. public static LSL_List MethListAddStr(LSL_List left, string right)
  1258. {
  1259. return MethListAddObj(left, new LSL_String(right));
  1260. }
  1261. public static LSL_List MethListAddVec(LSL_List left, LSL_Vector right)
  1262. {
  1263. return MethListAddObj(left, right);
  1264. }
  1265. public static LSL_List MethListAddObj(LSL_List left, object right)
  1266. {
  1267. int oldlen = left.Length;
  1268. object[] newarr = new object[oldlen + 1];
  1269. Array.Copy(left.Data, newarr, oldlen);
  1270. newarr[oldlen] = right;
  1271. return new LSL_List(newarr);
  1272. }
  1273. public static LSL_List MethListAddList(LSL_List left, LSL_List right)
  1274. {
  1275. int leftlen = left.Length;
  1276. int ritelen = right.Length;
  1277. object[] newarr = new object[leftlen + ritelen];
  1278. Array.Copy(left.Data, newarr, leftlen);
  1279. Array.Copy(right.Data, 0, newarr, leftlen, ritelen);
  1280. return new LSL_List(newarr);
  1281. }
  1282. public static LSL_List MethFloatAddList(double left, LSL_List right)
  1283. {
  1284. return MethObjAddList(new LSL_Float(left), right);
  1285. }
  1286. public static LSL_List MethIntAddList(int left, LSL_List right)
  1287. {
  1288. return MethObjAddList(new LSL_Integer(left), right);
  1289. }
  1290. public static LSL_List MethKeyAddList(string left, LSL_List right)
  1291. {
  1292. return MethObjAddList(new LSL_Key(left), right);
  1293. }
  1294. public static LSL_List MethRotAddList(LSL_Rotation left, LSL_List right)
  1295. {
  1296. return MethObjAddList(left, right);
  1297. }
  1298. public static LSL_List MethStrAddList(string left, LSL_List right)
  1299. {
  1300. return MethObjAddList(new LSL_String(left), right);
  1301. }
  1302. public static LSL_List MethVecAddList(LSL_Vector left, LSL_List right)
  1303. {
  1304. return MethObjAddList(left, right);
  1305. }
  1306. public static LSL_List MethObjAddList(object left, LSL_List right)
  1307. {
  1308. int oldlen = right.Length;
  1309. object[] newarr = new object[oldlen + 1];
  1310. newarr[0] = left;
  1311. Array.Copy(right.Data, 0, newarr, 1, oldlen);
  1312. return new LSL_List(newarr);
  1313. }
  1314. public static bool MethListEqList(LSL_List left, LSL_List right)
  1315. {
  1316. return left == right;
  1317. }
  1318. // According to http://wiki.secondlife.com/wiki/LlGetListLength
  1319. // jackassed LSL allows 'somelist != []' to get the length of a list
  1320. public static int MethListNeList(LSL_List left, LSL_List right)
  1321. {
  1322. int leftlen = left.Length;
  1323. int ritelen = right.Length;
  1324. return leftlen - ritelen;
  1325. }
  1326. public static bool MethRotEqRot(LSL_Rotation left, LSL_Rotation right)
  1327. {
  1328. return left == right;
  1329. }
  1330. public static bool MethRotNeRot(LSL_Rotation left, LSL_Rotation right)
  1331. {
  1332. return left != right;
  1333. }
  1334. public static LSL_Rotation MethRotAddRot(LSL_Rotation left, LSL_Rotation right)
  1335. {
  1336. return left + right;
  1337. }
  1338. public static LSL_Rotation MethRotSubRot(LSL_Rotation left, LSL_Rotation right)
  1339. {
  1340. return left - right;
  1341. }
  1342. public static LSL_Rotation MethRotMulRot(LSL_Rotation left, LSL_Rotation right)
  1343. {
  1344. return left * right;
  1345. }
  1346. public static LSL_Rotation MethRotDivRot(LSL_Rotation left, LSL_Rotation right)
  1347. {
  1348. return left / right;
  1349. }
  1350. public static bool MethVecEqVec(LSL_Vector left, LSL_Vector right)
  1351. {
  1352. return left == right;
  1353. }
  1354. public static bool MethVecNeVec(LSL_Vector left, LSL_Vector right)
  1355. {
  1356. return left != right;
  1357. }
  1358. public static LSL_Vector MethVecAddVec(LSL_Vector left, LSL_Vector right)
  1359. {
  1360. return left + right;
  1361. }
  1362. public static LSL_Vector MethVecSubVec(LSL_Vector left, LSL_Vector right)
  1363. {
  1364. return left - right;
  1365. }
  1366. public static double MethVecMulVec(LSL_Vector left, LSL_Vector right)
  1367. {
  1368. return (double)(left * right).value;
  1369. }
  1370. public static LSL_Vector MethVecModVec(LSL_Vector left, LSL_Vector right)
  1371. {
  1372. return left % right;
  1373. }
  1374. public static LSL_Vector MethVecMulFloat(LSL_Vector left, double right)
  1375. {
  1376. return left * right;
  1377. }
  1378. public static LSL_Vector MethFloatMulVec(double left, LSL_Vector right)
  1379. {
  1380. return left * right;
  1381. }
  1382. public static LSL_Vector MethVecDivFloat(LSL_Vector left, double right)
  1383. {
  1384. return left / right;
  1385. }
  1386. public static LSL_Vector MethVecMulInt(LSL_Vector left, int right)
  1387. {
  1388. return left * right;
  1389. }
  1390. public static LSL_Vector MethIntMulVec(int left, LSL_Vector right)
  1391. {
  1392. return left * right;
  1393. }
  1394. public static LSL_Vector MethVecDivInt(LSL_Vector left, int right)
  1395. {
  1396. return left / right;
  1397. }
  1398. public static LSL_Vector MethVecMulRot(LSL_Vector left, LSL_Rotation right)
  1399. {
  1400. return left * right;
  1401. }
  1402. public static LSL_Vector MethVecDivRot(LSL_Vector left, LSL_Rotation right)
  1403. {
  1404. return left / right;
  1405. }
  1406. }
  1407. }