1
0

MMRScriptBinOpStr.cs 78 KB

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