1
0

InterpreterLogic.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using OpenSim.Scripting.EmbeddedJVM.Types;
  5. using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
  6. namespace OpenSim.Scripting.EmbeddedJVM
  7. {
  8. partial class Thread
  9. {
  10. private partial class Interpreter
  11. {
  12. private bool IsLogicOpCode(byte opcode)
  13. {
  14. bool result = false;
  15. switch (opcode)
  16. {
  17. case 2:
  18. Int m_int= new Int();
  19. m_int.mValue = -1;
  20. this._mThread.currentFrame.OpStack.Push(m_int);
  21. result = true;
  22. break;
  23. case 3:
  24. m_int= new Int();
  25. m_int.mValue = 0;
  26. this._mThread.currentFrame.OpStack.Push(m_int);
  27. result = true;
  28. break;
  29. case 4:
  30. m_int = new Int();
  31. m_int.mValue = 1;
  32. this._mThread.currentFrame.OpStack.Push(m_int);
  33. result = true;
  34. break;
  35. case 5:
  36. m_int = new Int();
  37. m_int.mValue = 2;
  38. this._mThread.currentFrame.OpStack.Push(m_int);
  39. result = true;
  40. break;
  41. case 6:
  42. m_int = new Int();
  43. m_int.mValue = 3;
  44. this._mThread.currentFrame.OpStack.Push(m_int);
  45. break;
  46. case 7:
  47. m_int = new Int();
  48. m_int.mValue = 4;
  49. this._mThread.currentFrame.OpStack.Push(m_int);
  50. result = true;
  51. break;
  52. case 8:
  53. m_int = new Int();
  54. m_int.mValue = 5;
  55. this._mThread.currentFrame.OpStack.Push(m_int);
  56. result = true;
  57. break;
  58. case 11:
  59. Float m_float = new Float();
  60. m_float.mValue = 0.0f;
  61. this._mThread.currentFrame.OpStack.Push(m_float);
  62. result = true;
  63. break;
  64. case 12:
  65. m_float = new Float();
  66. m_float.mValue = 1.0f;
  67. this._mThread.currentFrame.OpStack.Push(m_float);
  68. result = true;
  69. break;
  70. case 13:
  71. m_float = new Float();
  72. m_float.mValue = 2.0f;
  73. this._mThread.currentFrame.OpStack.Push(m_float);
  74. result = true;
  75. break;
  76. case 16:
  77. int pushvalue = (int)GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC];
  78. Int pushInt = new Int();
  79. pushInt.mValue = pushvalue;
  80. this._mThread.currentFrame.OpStack.Push(pushInt);
  81. this._mThread.PC++;
  82. result = true;
  83. break;
  84. case 17:
  85. short pushvalue2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
  86. Int pushInt2 = new Int();
  87. pushInt2.mValue = pushvalue2;
  88. this._mThread.currentFrame.OpStack.Push(pushInt2);
  89. this._mThread.PC += 2;
  90. result = true;
  91. break;
  92. case 23:
  93. short findex1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]));
  94. Float fload = new Float();
  95. if (this._mThread.currentFrame.LocalVariables[findex1] != null)
  96. {
  97. if (this._mThread.currentFrame.LocalVariables[findex1] is Float)
  98. {
  99. fload.mValue = ((Float)this._mThread.currentFrame.LocalVariables[findex1]).mValue;
  100. this._mThread.currentFrame.OpStack.Push(fload);
  101. }
  102. }
  103. this._mThread.PC++;
  104. result = true;
  105. break;
  106. case 26:
  107. if (this._mThread.currentFrame.LocalVariables[0] != null)
  108. {
  109. if (this._mThread.currentFrame.LocalVariables[0] is Int)
  110. {
  111. Int newInt = new Int();
  112. newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[0]).mValue;
  113. this._mThread.currentFrame.OpStack.Push(newInt);
  114. }
  115. }
  116. result = true;
  117. break;
  118. case 27:
  119. if (this._mThread.currentFrame.LocalVariables[1] != null)
  120. {
  121. if (this._mThread.currentFrame.LocalVariables[1] is Int)
  122. {
  123. Int newInt = new Int();
  124. newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[1]).mValue;
  125. this._mThread.currentFrame.OpStack.Push(newInt);
  126. }
  127. }
  128. result = true;
  129. break;
  130. case 34:
  131. if (this._mThread.currentFrame.LocalVariables[0] != null)
  132. {
  133. if (this._mThread.currentFrame.LocalVariables[0] is Float)
  134. {
  135. Float newfloat = new Float();
  136. newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[0]).mValue;
  137. this._mThread.currentFrame.OpStack.Push(newfloat);
  138. }
  139. }
  140. result = true;
  141. break;
  142. case 35:
  143. if (this._mThread.currentFrame.LocalVariables[1] != null)
  144. {
  145. if (this._mThread.currentFrame.LocalVariables[1] is Float)
  146. {
  147. Float newfloat = new Float();
  148. newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[1]).mValue;
  149. this._mThread.currentFrame.OpStack.Push(newfloat);
  150. }
  151. }
  152. result = true;
  153. break;
  154. case 36:
  155. if (this._mThread.currentFrame.LocalVariables[2] != null)
  156. {
  157. if (this._mThread.currentFrame.LocalVariables[2] is Float)
  158. {
  159. Float newfloat = new Float();
  160. newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[2]).mValue;
  161. this._mThread.currentFrame.OpStack.Push(newfloat);
  162. }
  163. }
  164. result = true;
  165. break;
  166. case 37:
  167. if (this._mThread.currentFrame.LocalVariables[3] != null)
  168. {
  169. if (this._mThread.currentFrame.LocalVariables[3] is Float)
  170. {
  171. Float newfloat = new Float();
  172. newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[3]).mValue;
  173. this._mThread.currentFrame.OpStack.Push(newfloat);
  174. }
  175. }
  176. result = true;
  177. break;
  178. case 56:
  179. short findex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] ));
  180. BaseType fstor = this._mThread.currentFrame.OpStack.Pop();
  181. if (fstor is Float)
  182. {
  183. this._mThread.currentFrame.LocalVariables[findex] = (Float)fstor;
  184. }
  185. this._mThread.PC++;
  186. result = true;
  187. break;
  188. case 59:
  189. BaseType baset = this._mThread.currentFrame.OpStack.Pop();
  190. if (baset is Int)
  191. {
  192. this._mThread.currentFrame.LocalVariables[0] = (Int)baset;
  193. }
  194. result = true;
  195. break;
  196. case 60:
  197. baset = this._mThread.currentFrame.OpStack.Pop();
  198. if (baset is Int)
  199. {
  200. this._mThread.currentFrame.LocalVariables[1] = (Int)baset;
  201. }
  202. result = true;
  203. break;
  204. case 67:
  205. baset = this._mThread.currentFrame.OpStack.Pop();
  206. if (baset is Float)
  207. {
  208. this._mThread.currentFrame.LocalVariables[0] = (Float)baset;
  209. }
  210. result = true;
  211. break;
  212. case 68:
  213. baset = this._mThread.currentFrame.OpStack.Pop();
  214. if (baset is Float)
  215. {
  216. this._mThread.currentFrame.LocalVariables[1] = (Float)baset;
  217. }
  218. result = true;
  219. break;
  220. case 69:
  221. baset = this._mThread.currentFrame.OpStack.Pop();
  222. if (baset is Float)
  223. {
  224. this._mThread.currentFrame.LocalVariables[2] = (Float)baset;
  225. }
  226. result = true;
  227. break;
  228. case 70:
  229. baset = this._mThread.currentFrame.OpStack.Pop();
  230. if (baset is Float)
  231. {
  232. this._mThread.currentFrame.LocalVariables[3] = (Float)baset;
  233. }
  234. result = true;
  235. break;
  236. case 87:
  237. this._mThread.currentFrame.OpStack.Pop();
  238. result = true;
  239. break;
  240. case 98:
  241. BaseType bf2 = this._mThread.currentFrame.OpStack.Pop();
  242. BaseType bf1 = this._mThread.currentFrame.OpStack.Pop();
  243. if (bf1 is Float && bf2 is Float)
  244. {
  245. Float nflt = new Float();
  246. nflt.mValue = ((Float)bf1).mValue + ((Float)bf2).mValue;
  247. this._mThread.currentFrame.OpStack.Push(nflt);
  248. }
  249. result = true;
  250. break;
  251. case 102:
  252. BaseType bsf2 = this._mThread.currentFrame.OpStack.Pop();
  253. BaseType bsf1 = this._mThread.currentFrame.OpStack.Pop();
  254. if (bsf1 is Float && bsf2 is Float)
  255. {
  256. Float resf = new Float();
  257. resf.mValue = ((Float)bsf1).mValue - ((Float)bsf2).mValue;
  258. this._mThread.currentFrame.OpStack.Push(resf);
  259. }
  260. result = true;
  261. break;
  262. case 104: //check the order of the two values off the stack is correct
  263. BaseType bs2 = this._mThread.currentFrame.OpStack.Pop();
  264. BaseType bs1 = this._mThread.currentFrame.OpStack.Pop();
  265. if (bs1 is Int && bs2 is Int)
  266. {
  267. Int nInt = new Int();
  268. nInt.mValue = ((Int)bs1).mValue * ((Int)bs2).mValue;
  269. this._mThread.currentFrame.OpStack.Push(nInt);
  270. }
  271. result = true;
  272. break;
  273. case 132:
  274. if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] != null)
  275. {
  276. if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] is Int)
  277. {
  278. ((Int)this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]]).mValue += (sbyte) GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1];
  279. }
  280. }
  281. this._mThread.PC += 2;
  282. result = true;
  283. break;
  284. case 139:
  285. BaseType conv1 = this._mThread.currentFrame.OpStack.Pop();
  286. if (conv1 is Float)
  287. {
  288. Int newconv = new Int();
  289. newconv.mValue = (int)((Float)conv1).mValue;
  290. this._mThread.currentFrame.OpStack.Push(newconv);
  291. }
  292. result = true;
  293. break;
  294. case 149:
  295. BaseType flcom2 = this._mThread.currentFrame.OpStack.Pop();
  296. BaseType flcom1 = this._mThread.currentFrame.OpStack.Pop();
  297. if (flcom1 is Float && flcom2 is Float)
  298. {
  299. Int compres = new Int();
  300. if (((Float)flcom1).mValue < ((Float)flcom2).mValue)
  301. {
  302. compres.mValue = -1;
  303. }
  304. else if (((Float)flcom1).mValue > ((Float)flcom2).mValue)
  305. {
  306. compres.mValue = 1;
  307. }
  308. else
  309. {
  310. compres.mValue = 0;
  311. }
  312. this._mThread.currentFrame.OpStack.Push(compres);
  313. }
  314. result = true;
  315. break;
  316. case 158:
  317. short compareoffset1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
  318. BaseType comp1 = this._mThread.currentFrame.OpStack.Pop();
  319. if (comp1 is Int)
  320. {
  321. if (((Int)comp1).mValue <= 0)
  322. {
  323. this._mThread.PC += -1 + compareoffset1;
  324. }
  325. else
  326. {
  327. this._mThread.PC += 2;
  328. }
  329. }
  330. else
  331. {
  332. this._mThread.PC += 2;
  333. }
  334. result = true;
  335. break;
  336. case 162:
  337. short compareoffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
  338. BaseType bc2 = this._mThread.currentFrame.OpStack.Pop();
  339. BaseType bc1 = this._mThread.currentFrame.OpStack.Pop();
  340. if (bc1 is Int && bc2 is Int)
  341. {
  342. //Console.WriteLine("comparing " + ((Int)bc1).mValue + " and " + ((Int)bc2).mValue);
  343. if (((Int)bc1).mValue >= ((Int)bc2).mValue)
  344. {
  345. // Console.WriteLine("branch compare true , offset is " +compareoffset);
  346. // Console.WriteLine("current PC is " + this._mThread.PC);
  347. this._mThread.PC += -1 + compareoffset;
  348. //Console.WriteLine("new PC is " + this._mThread.PC);
  349. }
  350. else
  351. {
  352. //Console.WriteLine("branch compare false");
  353. this._mThread.PC += 2;
  354. }
  355. }
  356. else
  357. {
  358. this._mThread.PC += 2;
  359. }
  360. result = true;
  361. break;
  362. case 164:
  363. short compareloffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
  364. BaseType bcl2 = this._mThread.currentFrame.OpStack.Pop();
  365. BaseType bcl1 = this._mThread.currentFrame.OpStack.Pop();
  366. if (bcl1 is Int && bcl2 is Int)
  367. {
  368. //Console.WriteLine("comparing " + ((Int)bcl1).mValue + " and " + ((Int)bcl2).mValue);
  369. if (((Int)bcl1).mValue <= ((Int)bcl2).mValue)
  370. {
  371. // Console.WriteLine("branch compare true , offset is " + compareloffset);
  372. // Console.WriteLine("current PC is " + this._mThread.PC);
  373. this._mThread.PC += -1 + compareloffset;
  374. // Console.WriteLine("new PC is " + this._mThread.PC);
  375. }
  376. else
  377. {
  378. //Console.WriteLine("branch compare false");
  379. this._mThread.PC += 2;
  380. }
  381. }
  382. else
  383. {
  384. this._mThread.PC += 2;
  385. }
  386. result = true;
  387. break;
  388. case 167:
  389. short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]);
  390. this._mThread.PC += -1 + offset;
  391. result = true;
  392. break;
  393. }
  394. return result;
  395. }
  396. }
  397. }
  398. }