InterpreterLogic.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 26:
  93. if (this._mThread.currentFrame.LocalVariables[0] != null)
  94. {
  95. if (this._mThread.currentFrame.LocalVariables[0] is Int)
  96. {
  97. Int newInt = new Int();
  98. newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[0]).mValue;
  99. this._mThread.currentFrame.OpStack.Push(newInt);
  100. }
  101. }
  102. result = true;
  103. break;
  104. case 27:
  105. if (this._mThread.currentFrame.LocalVariables[1] != null)
  106. {
  107. if (this._mThread.currentFrame.LocalVariables[1] is Int)
  108. {
  109. Int newInt = new Int();
  110. newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[1]).mValue;
  111. this._mThread.currentFrame.OpStack.Push(newInt);
  112. }
  113. }
  114. result = true;
  115. break;
  116. case 34:
  117. if (this._mThread.currentFrame.LocalVariables[0] != null)
  118. {
  119. if (this._mThread.currentFrame.LocalVariables[0] is Float)
  120. {
  121. Float newfloat = new Float();
  122. newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[0]).mValue;
  123. this._mThread.currentFrame.OpStack.Push(newfloat);
  124. }
  125. }
  126. result = true;
  127. break;
  128. case 35:
  129. if (this._mThread.currentFrame.LocalVariables[1] != null)
  130. {
  131. if (this._mThread.currentFrame.LocalVariables[1] is Float)
  132. {
  133. Float newfloat = new Float();
  134. newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[1]).mValue;
  135. this._mThread.currentFrame.OpStack.Push(newfloat);
  136. }
  137. }
  138. result = true;
  139. break;
  140. case 59:
  141. BaseType baset = this._mThread.currentFrame.OpStack.Pop();
  142. if (baset is Int)
  143. {
  144. this._mThread.currentFrame.LocalVariables[0] = (Int)baset;
  145. }
  146. result = true;
  147. break;
  148. case 60:
  149. baset = this._mThread.currentFrame.OpStack.Pop();
  150. if (baset is Int)
  151. {
  152. this._mThread.currentFrame.LocalVariables[1] = (Int)baset;
  153. }
  154. result = true;
  155. break;
  156. case 67:
  157. baset = this._mThread.currentFrame.OpStack.Pop();
  158. if (baset is Float)
  159. {
  160. this._mThread.currentFrame.LocalVariables[0] = (Float)baset;
  161. }
  162. result = true;
  163. break;
  164. case 68:
  165. baset = this._mThread.currentFrame.OpStack.Pop();
  166. if (baset is Float)
  167. {
  168. this._mThread.currentFrame.LocalVariables[1] = (Float)baset;
  169. }
  170. result = true;
  171. break;
  172. case 87:
  173. this._mThread.currentFrame.OpStack.Pop();
  174. result = true;
  175. break;
  176. case 98:
  177. BaseType bf2 = this._mThread.currentFrame.OpStack.Pop();
  178. BaseType bf1 = this._mThread.currentFrame.OpStack.Pop();
  179. if (bf1 is Float && bf2 is Float)
  180. {
  181. Float nflt = new Float();
  182. nflt.mValue = ((Float)bf1).mValue + ((Float)bf2).mValue;
  183. this._mThread.currentFrame.OpStack.Push(nflt);
  184. }
  185. result = true;
  186. break;
  187. case 104: //check the order of the two values off the stack is correct
  188. BaseType bs2 = this._mThread.currentFrame.OpStack.Pop();
  189. BaseType bs1 = this._mThread.currentFrame.OpStack.Pop();
  190. if (bs1 is Int && bs2 is Int)
  191. {
  192. Int nInt = new Int();
  193. nInt.mValue = ((Int)bs1).mValue * ((Int)bs2).mValue;
  194. this._mThread.currentFrame.OpStack.Push(nInt);
  195. }
  196. result = true;
  197. break;
  198. case 132:
  199. if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] != null)
  200. {
  201. if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] is Int)
  202. {
  203. ((Int)this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]]).mValue += (sbyte) GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1];
  204. }
  205. }
  206. this._mThread.PC += 2;
  207. result = true;
  208. break;
  209. case 139:
  210. BaseType conv1 = this._mThread.currentFrame.OpStack.Pop();
  211. if (conv1 is Float)
  212. {
  213. Int newconv = new Int();
  214. newconv.mValue = (int)((Float)conv1).mValue;
  215. this._mThread.currentFrame.OpStack.Push(newconv);
  216. }
  217. result = true;
  218. break;
  219. case 162:
  220. short compareoffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
  221. BaseType bc2 = this._mThread.currentFrame.OpStack.Pop();
  222. BaseType bc1 = this._mThread.currentFrame.OpStack.Pop();
  223. if (bc1 is Int && bc2 is Int)
  224. {
  225. Console.WriteLine("comparing " + ((Int)bc1).mValue + " and " + ((Int)bc2).mValue);
  226. if (((Int)bc1).mValue >= ((Int)bc2).mValue)
  227. {
  228. Console.WriteLine("branch compare true , offset is " +compareoffset);
  229. Console.WriteLine("current PC is " + this._mThread.PC);
  230. this._mThread.PC += -1 + compareoffset;
  231. Console.WriteLine("new PC is " + this._mThread.PC);
  232. }
  233. else
  234. {
  235. Console.WriteLine("branch compare false");
  236. this._mThread.PC += 2;
  237. }
  238. }
  239. else
  240. {
  241. this._mThread.PC += 2;
  242. }
  243. result = true;
  244. break;
  245. case 164:
  246. short compareloffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
  247. BaseType bcl2 = this._mThread.currentFrame.OpStack.Pop();
  248. BaseType bcl1 = this._mThread.currentFrame.OpStack.Pop();
  249. if (bcl1 is Int && bcl2 is Int)
  250. {
  251. Console.WriteLine("comparing " + ((Int)bcl1).mValue + " and " + ((Int)bcl2).mValue);
  252. if (((Int)bcl1).mValue <= ((Int)bcl2).mValue)
  253. {
  254. Console.WriteLine("branch compare true , offset is " + compareloffset);
  255. Console.WriteLine("current PC is " + this._mThread.PC);
  256. this._mThread.PC += -1 + compareloffset;
  257. Console.WriteLine("new PC is " + this._mThread.PC);
  258. }
  259. else
  260. {
  261. Console.WriteLine("branch compare false");
  262. this._mThread.PC += 2;
  263. }
  264. }
  265. else
  266. {
  267. this._mThread.PC += 2;
  268. }
  269. result = true;
  270. break;
  271. case 167:
  272. short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]);
  273. this._mThread.PC += -1 + offset;
  274. result = true;
  275. break;
  276. }
  277. return result;
  278. }
  279. }
  280. }
  281. }