MMRScriptBinOpStr.cs 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569
  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) });
  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.Call, stringCmpStringMethInfo);
  861. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  862. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  863. result.PopPost(scg, errorAt, tokenTypeBool);
  864. }
  865. private static void BinOpStrKeyNeX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  866. {
  867. result.PopPre(scg, errorAt);
  868. left.PushVal(scg, errorAt, tokenTypeStr);
  869. right.PushVal(scg, errorAt, tokenTypeStr);
  870. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  871. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  872. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  873. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  874. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  875. result.PopPost(scg, errorAt, tokenTypeBool);
  876. }
  877. private static void BinOpStrListAddFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  878. {
  879. result.PopPre(scg, errorAt);
  880. left.PushVal(scg, errorAt, tokenTypeList);
  881. right.PushVal(scg, errorAt, tokenTypeFloat);
  882. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddFloat);
  883. result.PopPost(scg, errorAt, tokenTypeList);
  884. }
  885. private static void BinOpStrListAddInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  886. {
  887. result.PopPre(scg, errorAt);
  888. left.PushVal(scg, errorAt, tokenTypeList);
  889. right.PushVal(scg, errorAt, tokenTypeInt);
  890. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddInt);
  891. result.PopPost(scg, errorAt, tokenTypeList);
  892. }
  893. private static void BinOpStrListAddKey(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  894. {
  895. result.PopPre(scg, errorAt);
  896. left.PushVal(scg, errorAt, tokenTypeList);
  897. right.PushVal(scg, errorAt, tokenTypeStr);
  898. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddKey);
  899. result.PopPost(scg, errorAt, tokenTypeList);
  900. }
  901. private static void BinOpStrListAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  902. {
  903. result.PopPre(scg, errorAt);
  904. left.PushVal(scg, errorAt, tokenTypeList);
  905. right.PushVal(scg, errorAt, tokenTypeList);
  906. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddList);
  907. result.PopPost(scg, errorAt, tokenTypeList);
  908. }
  909. private static void BinOpStrListAddRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  910. {
  911. result.PopPre(scg, errorAt);
  912. left.PushVal(scg, errorAt, tokenTypeList);
  913. right.PushVal(scg, errorAt, tokenTypeRot);
  914. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddRot);
  915. result.PopPost(scg, errorAt, tokenTypeList);
  916. }
  917. private static void BinOpStrListAddStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  918. {
  919. result.PopPre(scg, errorAt);
  920. left.PushVal(scg, errorAt, tokenTypeList);
  921. right.PushVal(scg, errorAt, tokenTypeStr);
  922. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddStr);
  923. result.PopPost(scg, errorAt, tokenTypeList);
  924. }
  925. private static void BinOpStrListAddVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  926. {
  927. result.PopPre(scg, errorAt);
  928. left.PushVal(scg, errorAt, tokenTypeList);
  929. right.PushVal(scg, errorAt, tokenTypeVec);
  930. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddVec);
  931. result.PopPost(scg, errorAt, tokenTypeList);
  932. }
  933. private static void BinOpStrFloatAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  934. {
  935. result.PopPre(scg, errorAt);
  936. left.PushVal(scg, errorAt, tokenTypeFloat);
  937. right.PushVal(scg, errorAt, tokenTypeList);
  938. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethFloatAddList);
  939. result.PopPost(scg, errorAt, tokenTypeList);
  940. }
  941. private static void BinOpStrIntAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  942. {
  943. result.PopPre(scg, errorAt);
  944. left.PushVal(scg, errorAt, tokenTypeInt);
  945. right.PushVal(scg, errorAt, tokenTypeList);
  946. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethIntAddList);
  947. result.PopPost(scg, errorAt, tokenTypeList);
  948. }
  949. private static void BinOpStrKeyAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  950. {
  951. result.PopPre(scg, errorAt);
  952. left.PushVal(scg, errorAt, tokenTypeStr);
  953. right.PushVal(scg, errorAt, tokenTypeList);
  954. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethKeyAddList);
  955. result.PopPost(scg, errorAt, tokenTypeList);
  956. }
  957. private static void BinOpStrRotAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  958. {
  959. result.PopPre(scg, errorAt);
  960. left.PushVal(scg, errorAt, tokenTypeRot);
  961. right.PushVal(scg, errorAt, tokenTypeList);
  962. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotAddList);
  963. result.PopPost(scg, errorAt, tokenTypeList);
  964. }
  965. private static void BinOpStrStrAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  966. {
  967. result.PopPre(scg, errorAt);
  968. left.PushVal(scg, errorAt, tokenTypeStr);
  969. right.PushVal(scg, errorAt, tokenTypeList);
  970. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethStrAddList);
  971. result.PopPost(scg, errorAt, tokenTypeList);
  972. }
  973. private static void BinOpStrVecAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  974. {
  975. result.PopPre(scg, errorAt);
  976. left.PushVal(scg, errorAt, tokenTypeVec);
  977. right.PushVal(scg, errorAt, tokenTypeList);
  978. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecAddList);
  979. result.PopPost(scg, errorAt, tokenTypeList);
  980. }
  981. private static void BinOpStrListEqList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  982. {
  983. result.PopPre(scg, errorAt);
  984. left.PushVal(scg, errorAt, tokenTypeList);
  985. right.PushVal(scg, errorAt, tokenTypeList);
  986. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListEqList);
  987. result.PopPost(scg, errorAt, tokenTypeBool);
  988. }
  989. private static void BinOpStrListNeList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  990. {
  991. result.PopPre(scg, errorAt);
  992. left.PushVal(scg, errorAt, tokenTypeList);
  993. right.PushVal(scg, errorAt, tokenTypeList);
  994. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListNeList);
  995. result.PopPost(scg, errorAt, tokenTypeBool);
  996. }
  997. private static void BinOpStrRotEqRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  998. {
  999. result.PopPre(scg, errorAt);
  1000. left.PushVal(scg, errorAt, tokenTypeRot);
  1001. right.PushVal(scg, errorAt, tokenTypeRot);
  1002. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotEqRot);
  1003. result.PopPost(scg, errorAt, tokenTypeBool);
  1004. }
  1005. private static void BinOpStrRotNeRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1006. {
  1007. result.PopPre(scg, errorAt);
  1008. left.PushVal(scg, errorAt, tokenTypeRot);
  1009. right.PushVal(scg, errorAt, tokenTypeRot);
  1010. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotNeRot);
  1011. result.PopPost(scg, errorAt, tokenTypeBool);
  1012. }
  1013. private static void BinOpStrRotAddRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1014. {
  1015. result.PopPre(scg, errorAt);
  1016. left.PushVal(scg, errorAt, tokenTypeRot);
  1017. right.PushVal(scg, errorAt, tokenTypeRot);
  1018. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotAddRot);
  1019. result.PopPost(scg, errorAt, tokenTypeRot);
  1020. }
  1021. private static void BinOpStrRotSubRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1022. {
  1023. result.PopPre(scg, errorAt);
  1024. left.PushVal(scg, errorAt, tokenTypeRot);
  1025. right.PushVal(scg, errorAt, tokenTypeRot);
  1026. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotSubRot);
  1027. result.PopPost(scg, errorAt, tokenTypeRot);
  1028. }
  1029. private static void BinOpStrRotMulRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1030. {
  1031. result.PopPre(scg, errorAt);
  1032. left.PushVal(scg, errorAt, tokenTypeRot);
  1033. right.PushVal(scg, errorAt, tokenTypeRot);
  1034. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotMulRot);
  1035. result.PopPost(scg, errorAt, tokenTypeRot);
  1036. }
  1037. private static void BinOpStrRotDivRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1038. {
  1039. result.PopPre(scg, errorAt);
  1040. left.PushVal(scg, errorAt, tokenTypeRot);
  1041. right.PushVal(scg, errorAt, tokenTypeRot);
  1042. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotDivRot);
  1043. result.PopPost(scg, errorAt, tokenTypeRot);
  1044. }
  1045. private static void BinOpStrStrEqStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1046. {
  1047. result.PopPre(scg, errorAt);
  1048. left.PushVal(scg, errorAt, tokenTypeStr);
  1049. right.PushVal(scg, errorAt, tokenTypeStr);
  1050. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1051. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  1052. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  1053. result.PopPost(scg, errorAt, tokenTypeBool);
  1054. }
  1055. private static void BinOpStrStrNeStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1056. {
  1057. result.PopPre(scg, errorAt);
  1058. left.PushVal(scg, errorAt, tokenTypeStr);
  1059. right.PushVal(scg, errorAt, tokenTypeStr);
  1060. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1061. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  1062. scg.ilGen.Emit(errorAt, OpCodes.Ceq);
  1063. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  1064. scg.ilGen.Emit(errorAt, OpCodes.Xor);
  1065. result.PopPost(scg, errorAt, tokenTypeBool);
  1066. }
  1067. private static void BinOpStrStrLtStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1068. {
  1069. result.PopPre(scg, errorAt);
  1070. left.PushVal(scg, errorAt, tokenTypeStr);
  1071. right.PushVal(scg, errorAt, tokenTypeStr);
  1072. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1073. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  1074. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  1075. result.PopPost(scg, errorAt, tokenTypeBool);
  1076. }
  1077. private static void BinOpStrStrLeStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1078. {
  1079. result.PopPre(scg, errorAt);
  1080. left.PushVal(scg, errorAt, tokenTypeStr);
  1081. right.PushVal(scg, errorAt, tokenTypeStr);
  1082. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1083. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
  1084. scg.ilGen.Emit(errorAt, OpCodes.Clt);
  1085. result.PopPost(scg, errorAt, tokenTypeBool);
  1086. }
  1087. private static void BinOpStrStrGtStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1088. {
  1089. result.PopPre(scg, errorAt);
  1090. left.PushVal(scg, errorAt, tokenTypeStr);
  1091. right.PushVal(scg, errorAt, tokenTypeStr);
  1092. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1093. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
  1094. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  1095. result.PopPost(scg, errorAt, tokenTypeBool);
  1096. }
  1097. private static void BinOpStrStrGeStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1098. {
  1099. result.PopPre(scg, errorAt);
  1100. left.PushVal(scg, errorAt, tokenTypeStr);
  1101. right.PushVal(scg, errorAt, tokenTypeStr);
  1102. scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
  1103. scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_M1);
  1104. scg.ilGen.Emit(errorAt, OpCodes.Cgt);
  1105. result.PopPost(scg, errorAt, tokenTypeBool);
  1106. }
  1107. // Called by many type combinations so both operands need to be cast to strings
  1108. private static void BinOpStrStrAddStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1109. {
  1110. result.PopPre(scg, errorAt);
  1111. left.PushVal(scg, errorAt, tokenTypeStr);
  1112. right.PushVal(scg, errorAt, tokenTypeStr);
  1113. scg.ilGen.Emit(errorAt, OpCodes.Call, stringAddStringMethInfo);
  1114. result.PopPost(scg, errorAt, tokenTypeStr);
  1115. }
  1116. private static void BinOpStrVecEqVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1117. {
  1118. result.PopPre(scg, errorAt);
  1119. left.PushVal(scg, errorAt, tokenTypeVec);
  1120. right.PushVal(scg, errorAt, tokenTypeVec);
  1121. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecEqVec);
  1122. result.PopPost(scg, errorAt, tokenTypeBool);
  1123. }
  1124. private static void BinOpStrVecNeVec(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, infoMethVecNeVec);
  1130. result.PopPost(scg, errorAt, tokenTypeBool);
  1131. }
  1132. private static void BinOpStrVecAddVec(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, infoMethVecAddVec);
  1138. result.PopPost(scg, errorAt, tokenTypeVec);
  1139. }
  1140. private static void BinOpStrVecSubVec(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, infoMethVecSubVec);
  1146. result.PopPost(scg, errorAt, tokenTypeVec);
  1147. }
  1148. private static void BinOpStrVecMulVec(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, infoMethVecMulVec);
  1154. result.PopPost(scg, errorAt, tokenTypeFloat);
  1155. }
  1156. private static void BinOpStrVecModVec(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, infoMethVecModVec);
  1162. result.PopPost(scg, errorAt, tokenTypeVec);
  1163. }
  1164. private static void BinOpStrVecMulFloat(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, tokenTypeFloat);
  1169. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulFloat);
  1170. result.PopPost(scg, errorAt, tokenTypeVec);
  1171. }
  1172. private static void BinOpStrFloatMulVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1173. {
  1174. result.PopPre(scg, errorAt);
  1175. left.PushVal(scg, errorAt, tokenTypeFloat);
  1176. right.PushVal(scg, errorAt, tokenTypeVec);
  1177. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethFloatMulVec);
  1178. result.PopPost(scg, errorAt, tokenTypeVec);
  1179. }
  1180. private static void BinOpStrVecDivFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1181. {
  1182. result.PopPre(scg, errorAt);
  1183. left.PushVal(scg, errorAt, tokenTypeVec);
  1184. right.PushVal(scg, errorAt, tokenTypeFloat);
  1185. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecDivFloat);
  1186. result.PopPost(scg, errorAt, tokenTypeVec);
  1187. }
  1188. private static void BinOpStrVecMulInt(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, tokenTypeInt);
  1193. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulInt);
  1194. result.PopPost(scg, errorAt, tokenTypeVec);
  1195. }
  1196. private static void BinOpStrIntMulVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1197. {
  1198. result.PopPre(scg, errorAt);
  1199. left.PushVal(scg, errorAt, tokenTypeInt);
  1200. right.PushVal(scg, errorAt, tokenTypeVec);
  1201. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethIntMulVec);
  1202. result.PopPost(scg, errorAt, tokenTypeVec);
  1203. }
  1204. private static void BinOpStrVecDivInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
  1205. {
  1206. result.PopPre(scg, errorAt);
  1207. left.PushVal(scg, errorAt, tokenTypeVec);
  1208. right.PushVal(scg, errorAt, tokenTypeInt);
  1209. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecDivInt);
  1210. result.PopPost(scg, errorAt, tokenTypeVec);
  1211. }
  1212. private static void BinOpStrVecMulRot(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, tokenTypeRot);
  1217. scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulRot);
  1218. result.PopPost(scg, errorAt, tokenTypeVec);
  1219. }
  1220. private static void BinOpStrVecDivRot(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, infoMethVecDivRot);
  1226. result.PopPost(scg, errorAt, tokenTypeVec);
  1227. }
  1228. /**
  1229. * @brief These methods are called at runtime as helpers.
  1230. * Needed to pick up functionality defined by overloaded operators of LSL_ types.
  1231. * They need to be marked public or runtime says they are inaccessible.
  1232. */
  1233. public static LSL_List MethListAddFloat(LSL_List left, double right)
  1234. {
  1235. return MethListAddObj(left, new LSL_Float(right));
  1236. }
  1237. public static LSL_List MethListAddInt(LSL_List left, int right)
  1238. {
  1239. return MethListAddObj(left, new LSL_Integer(right));
  1240. }
  1241. public static LSL_List MethListAddKey(LSL_List left, string right)
  1242. {
  1243. return MethListAddObj(left, new LSL_Key(right));
  1244. }
  1245. public static LSL_List MethListAddRot(LSL_List left, LSL_Rotation right)
  1246. {
  1247. return MethListAddObj(left, right);
  1248. }
  1249. public static LSL_List MethListAddStr(LSL_List left, string right)
  1250. {
  1251. return MethListAddObj(left, new LSL_String(right));
  1252. }
  1253. public static LSL_List MethListAddVec(LSL_List left, LSL_Vector right)
  1254. {
  1255. return MethListAddObj(left, right);
  1256. }
  1257. public static LSL_List MethListAddObj(LSL_List left, object right)
  1258. {
  1259. int oldlen = left.Length;
  1260. object[] newarr = new object[oldlen + 1];
  1261. Array.Copy(left.Data, newarr, oldlen);
  1262. newarr[oldlen] = right;
  1263. return new LSL_List(newarr);
  1264. }
  1265. public static LSL_List MethListAddList(LSL_List left, LSL_List right)
  1266. {
  1267. int leftlen = left.Length;
  1268. int ritelen = right.Length;
  1269. object[] newarr = new object[leftlen + ritelen];
  1270. Array.Copy(left.Data, newarr, leftlen);
  1271. Array.Copy(right.Data, 0, newarr, leftlen, ritelen);
  1272. return new LSL_List(newarr);
  1273. }
  1274. public static LSL_List MethFloatAddList(double left, LSL_List right)
  1275. {
  1276. return MethObjAddList(new LSL_Float(left), right);
  1277. }
  1278. public static LSL_List MethIntAddList(int left, LSL_List right)
  1279. {
  1280. return MethObjAddList(new LSL_Integer(left), right);
  1281. }
  1282. public static LSL_List MethKeyAddList(string left, LSL_List right)
  1283. {
  1284. return MethObjAddList(new LSL_Key(left), right);
  1285. }
  1286. public static LSL_List MethRotAddList(LSL_Rotation left, LSL_List right)
  1287. {
  1288. return MethObjAddList(left, right);
  1289. }
  1290. public static LSL_List MethStrAddList(string left, LSL_List right)
  1291. {
  1292. return MethObjAddList(new LSL_String(left), right);
  1293. }
  1294. public static LSL_List MethVecAddList(LSL_Vector left, LSL_List right)
  1295. {
  1296. return MethObjAddList(left, right);
  1297. }
  1298. public static LSL_List MethObjAddList(object left, LSL_List right)
  1299. {
  1300. int oldlen = right.Length;
  1301. object[] newarr = new object[oldlen + 1];
  1302. newarr[0] = left;
  1303. Array.Copy(right.Data, 0, newarr, 1, oldlen);
  1304. return new LSL_List(newarr);
  1305. }
  1306. public static bool MethListEqList(LSL_List left, LSL_List right)
  1307. {
  1308. return left == right;
  1309. }
  1310. // According to http://wiki.secondlife.com/wiki/LlGetListLength
  1311. // jackassed LSL allows 'somelist != []' to get the length of a list
  1312. public static int MethListNeList(LSL_List left, LSL_List right)
  1313. {
  1314. int leftlen = left.Length;
  1315. int ritelen = right.Length;
  1316. return leftlen - ritelen;
  1317. }
  1318. public static bool MethRotEqRot(LSL_Rotation left, LSL_Rotation right)
  1319. {
  1320. return left == right;
  1321. }
  1322. public static bool MethRotNeRot(LSL_Rotation left, LSL_Rotation right)
  1323. {
  1324. return left != right;
  1325. }
  1326. public static LSL_Rotation MethRotAddRot(LSL_Rotation left, LSL_Rotation right)
  1327. {
  1328. return left + right;
  1329. }
  1330. public static LSL_Rotation MethRotSubRot(LSL_Rotation left, LSL_Rotation right)
  1331. {
  1332. return left - right;
  1333. }
  1334. public static LSL_Rotation MethRotMulRot(LSL_Rotation left, LSL_Rotation right)
  1335. {
  1336. return left * right;
  1337. }
  1338. public static LSL_Rotation MethRotDivRot(LSL_Rotation left, LSL_Rotation right)
  1339. {
  1340. return left / right;
  1341. }
  1342. public static bool MethVecEqVec(LSL_Vector left, LSL_Vector right)
  1343. {
  1344. return left == right;
  1345. }
  1346. public static bool MethVecNeVec(LSL_Vector left, LSL_Vector right)
  1347. {
  1348. return left != right;
  1349. }
  1350. public static LSL_Vector MethVecAddVec(LSL_Vector left, LSL_Vector right)
  1351. {
  1352. return left + right;
  1353. }
  1354. public static LSL_Vector MethVecSubVec(LSL_Vector left, LSL_Vector right)
  1355. {
  1356. return left - right;
  1357. }
  1358. public static double MethVecMulVec(LSL_Vector left, LSL_Vector right)
  1359. {
  1360. return (double)(left * right).value;
  1361. }
  1362. public static LSL_Vector MethVecModVec(LSL_Vector left, LSL_Vector right)
  1363. {
  1364. return left % right;
  1365. }
  1366. public static LSL_Vector MethVecMulFloat(LSL_Vector left, double right)
  1367. {
  1368. return left * right;
  1369. }
  1370. public static LSL_Vector MethFloatMulVec(double left, LSL_Vector right)
  1371. {
  1372. return left * right;
  1373. }
  1374. public static LSL_Vector MethVecDivFloat(LSL_Vector left, double right)
  1375. {
  1376. return left / right;
  1377. }
  1378. public static LSL_Vector MethVecMulInt(LSL_Vector left, int right)
  1379. {
  1380. return left * right;
  1381. }
  1382. public static LSL_Vector MethIntMulVec(int left, LSL_Vector right)
  1383. {
  1384. return left * right;
  1385. }
  1386. public static LSL_Vector MethVecDivInt(LSL_Vector left, int right)
  1387. {
  1388. return left / right;
  1389. }
  1390. public static LSL_Vector MethVecMulRot(LSL_Vector left, LSL_Rotation right)
  1391. {
  1392. return left * right;
  1393. }
  1394. public static LSL_Vector MethVecDivRot(LSL_Vector left, LSL_Rotation right)
  1395. {
  1396. return left / right;
  1397. }
  1398. }
  1399. }