Interpreter.Logic.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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 OpenSim 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.ExtensionsScriptModule.JVMEngine.Types;
  28. using OpenSim.Region.ExtensionsScriptModule.JVMEngine.Types.PrimitiveTypes;
  29. namespace OpenSim.Region.ExtensionsScriptModule.JVMEngine.JVM
  30. {
  31. partial class Thread
  32. {
  33. private partial class Interpreter
  34. {
  35. private bool IsLogicOpCode(byte opcode)
  36. {
  37. bool result = false;
  38. switch (opcode)
  39. {
  40. case (byte) (byte) OpCode.iconst_m1:
  41. Int m_int = new Int();
  42. m_int.mValue = -1;
  43. m_thread.m_currentFrame.OpStack.Push(m_int);
  44. result = true;
  45. break;
  46. case (byte) (byte) OpCode.iconst_0:
  47. m_int = new Int();
  48. m_int.mValue = 0;
  49. m_thread.m_currentFrame.OpStack.Push(m_int);
  50. result = true;
  51. break;
  52. case (byte) (byte) OpCode.iconst_1:
  53. m_int = new Int();
  54. m_int.mValue = 1;
  55. m_thread.m_currentFrame.OpStack.Push(m_int);
  56. result = true;
  57. break;
  58. case (byte) (byte) OpCode.iconst_2:
  59. m_int = new Int();
  60. m_int.mValue = 2;
  61. m_thread.m_currentFrame.OpStack.Push(m_int);
  62. result = true;
  63. break;
  64. case (byte) (byte) OpCode.iconst_3:
  65. m_int = new Int();
  66. m_int.mValue = 3;
  67. m_thread.m_currentFrame.OpStack.Push(m_int);
  68. break;
  69. case (byte) (byte) OpCode.iconst_4:
  70. m_int = new Int();
  71. m_int.mValue = 4;
  72. m_thread.m_currentFrame.OpStack.Push(m_int);
  73. result = true;
  74. break;
  75. case (byte) OpCode.iconst_5:
  76. m_int = new Int();
  77. m_int.mValue = 5;
  78. m_thread.m_currentFrame.OpStack.Push(m_int);
  79. result = true;
  80. break;
  81. case (byte) OpCode.fconst_0:
  82. Float m_float = new Float();
  83. m_float.mValue = 0.0f;
  84. m_thread.m_currentFrame.OpStack.Push(m_float);
  85. result = true;
  86. break;
  87. case (byte) OpCode.fconst_1:
  88. m_float = new Float();
  89. m_float.mValue = 1.0f;
  90. m_thread.m_currentFrame.OpStack.Push(m_float);
  91. result = true;
  92. break;
  93. case (byte) OpCode.fconst_2:
  94. m_float = new Float();
  95. m_float.mValue = 2.0f;
  96. m_thread.m_currentFrame.OpStack.Push(m_float);
  97. result = true;
  98. break;
  99. case (byte) OpCode.bipush: //is this right? this should be pushing a byte onto stack not int?
  100. int pushvalue = (int) GlobalMemory.MethodArea.MethodBuffer[m_thread.PC];
  101. Int pushInt = new Int();
  102. pushInt.mValue = pushvalue;
  103. m_thread.m_currentFrame.OpStack.Push(pushInt);
  104. m_thread.PC++;
  105. result = true;
  106. break;
  107. case (byte) OpCode.sipush:
  108. short pushvalue2 =
  109. (short)
  110. ((GlobalMemory.MethodArea.MethodBuffer[m_thread.PC] << 8) +
  111. GlobalMemory.MethodArea.MethodBuffer[m_thread.PC + 1]);
  112. Int pushInt2 = new Int();
  113. pushInt2.mValue = pushvalue2;
  114. m_thread.m_currentFrame.OpStack.Push(pushInt2);
  115. m_thread.PC += 2;
  116. result = true;
  117. break;
  118. case (byte) OpCode.fload:
  119. short findex1 = (short) ((GlobalMemory.MethodArea.MethodBuffer[m_thread.PC]));
  120. Float fload = new Float();
  121. if (m_thread.m_currentFrame.LocalVariables[findex1] != null)
  122. {
  123. if (m_thread.m_currentFrame.LocalVariables[findex1] is Float)
  124. {
  125. fload.mValue = ((Float) m_thread.m_currentFrame.LocalVariables[findex1]).mValue;
  126. m_thread.m_currentFrame.OpStack.Push(fload);
  127. }
  128. }
  129. m_thread.PC++;
  130. result = true;
  131. break;
  132. case (byte) OpCode.iload_0:
  133. if (m_thread.m_currentFrame.LocalVariables[0] != null)
  134. {
  135. if (m_thread.m_currentFrame.LocalVariables[0] is Int)
  136. {
  137. Int newInt = new Int();
  138. newInt.mValue = ((Int) m_thread.m_currentFrame.LocalVariables[0]).mValue;
  139. m_thread.m_currentFrame.OpStack.Push(newInt);
  140. }
  141. }
  142. result = true;
  143. break;
  144. case (byte) OpCode.iload_1:
  145. if (m_thread.m_currentFrame.LocalVariables[1] != null)
  146. {
  147. if (m_thread.m_currentFrame.LocalVariables[1] is Int)
  148. {
  149. Int newInt = new Int();
  150. newInt.mValue = ((Int) m_thread.m_currentFrame.LocalVariables[1]).mValue;
  151. m_thread.m_currentFrame.OpStack.Push(newInt);
  152. }
  153. }
  154. result = true;
  155. break;
  156. case (byte) OpCode.fload_0:
  157. if (m_thread.m_currentFrame.LocalVariables[0] != null)
  158. {
  159. if (m_thread.m_currentFrame.LocalVariables[0] is Float)
  160. {
  161. Float newfloat = new Float();
  162. newfloat.mValue = ((Float) m_thread.m_currentFrame.LocalVariables[0]).mValue;
  163. m_thread.m_currentFrame.OpStack.Push(newfloat);
  164. }
  165. }
  166. result = true;
  167. break;
  168. case (byte) OpCode.fload_1:
  169. if (m_thread.m_currentFrame.LocalVariables[1] != null)
  170. {
  171. if (m_thread.m_currentFrame.LocalVariables[1] is Float)
  172. {
  173. Float newfloat = new Float();
  174. newfloat.mValue = ((Float) m_thread.m_currentFrame.LocalVariables[1]).mValue;
  175. m_thread.m_currentFrame.OpStack.Push(newfloat);
  176. }
  177. }
  178. result = true;
  179. break;
  180. case (byte) OpCode.fload_2:
  181. if (m_thread.m_currentFrame.LocalVariables[2] != null)
  182. {
  183. if (m_thread.m_currentFrame.LocalVariables[2] is Float)
  184. {
  185. Float newfloat = new Float();
  186. newfloat.mValue = ((Float) m_thread.m_currentFrame.LocalVariables[2]).mValue;
  187. m_thread.m_currentFrame.OpStack.Push(newfloat);
  188. }
  189. }
  190. result = true;
  191. break;
  192. case (byte) OpCode.fload_3:
  193. if (m_thread.m_currentFrame.LocalVariables[3] != null)
  194. {
  195. if (m_thread.m_currentFrame.LocalVariables[3] is Float)
  196. {
  197. Float newfloat = new Float();
  198. newfloat.mValue = ((Float) m_thread.m_currentFrame.LocalVariables[3]).mValue;
  199. m_thread.m_currentFrame.OpStack.Push(newfloat);
  200. }
  201. }
  202. result = true;
  203. break;
  204. case (byte) OpCode.istore:
  205. short findex3 = (short) ((GlobalMemory.MethodArea.MethodBuffer[m_thread.PC]));
  206. BaseType istor = m_thread.m_currentFrame.OpStack.Pop();
  207. if (istor is Int)
  208. {
  209. m_thread.m_currentFrame.LocalVariables[findex3] = (Int) istor;
  210. }
  211. m_thread.PC++;
  212. result = true;
  213. break;
  214. case (byte) OpCode.fstore:
  215. short findex = (short) ((GlobalMemory.MethodArea.MethodBuffer[m_thread.PC]));
  216. BaseType fstor = m_thread.m_currentFrame.OpStack.Pop();
  217. if (fstor is Float)
  218. {
  219. m_thread.m_currentFrame.LocalVariables[findex] = (Float) fstor;
  220. }
  221. m_thread.PC++;
  222. result = true;
  223. break;
  224. case (byte) OpCode.istore_0:
  225. BaseType baset = m_thread.m_currentFrame.OpStack.Pop();
  226. if (baset is Int)
  227. {
  228. m_thread.m_currentFrame.LocalVariables[0] = (Int) baset;
  229. }
  230. result = true;
  231. break;
  232. case (byte) OpCode.istore_1:
  233. baset = m_thread.m_currentFrame.OpStack.Pop();
  234. if (baset is Int)
  235. {
  236. m_thread.m_currentFrame.LocalVariables[1] = (Int) baset;
  237. }
  238. result = true;
  239. break;
  240. case (byte) OpCode.fstore_0:
  241. baset = m_thread.m_currentFrame.OpStack.Pop();
  242. if (baset is Float)
  243. {
  244. m_thread.m_currentFrame.LocalVariables[0] = (Float) baset;
  245. }
  246. result = true;
  247. break;
  248. case (byte) OpCode.fstore_1:
  249. baset = m_thread.m_currentFrame.OpStack.Pop();
  250. if (baset is Float)
  251. {
  252. m_thread.m_currentFrame.LocalVariables[1] = (Float) baset;
  253. }
  254. result = true;
  255. break;
  256. case (byte) OpCode.fstore_2:
  257. baset = m_thread.m_currentFrame.OpStack.Pop();
  258. if (baset is Float)
  259. {
  260. m_thread.m_currentFrame.LocalVariables[2] = (Float) baset;
  261. }
  262. result = true;
  263. break;
  264. case (byte) OpCode.fstore_3:
  265. baset = m_thread.m_currentFrame.OpStack.Pop();
  266. if (baset is Float)
  267. {
  268. m_thread.m_currentFrame.LocalVariables[3] = (Float) baset;
  269. }
  270. result = true;
  271. break;
  272. case (byte) OpCode.pop:
  273. m_thread.m_currentFrame.OpStack.Pop();
  274. result = true;
  275. break;
  276. case (byte) OpCode.fadd:
  277. BaseType bf2 = m_thread.m_currentFrame.OpStack.Pop();
  278. BaseType bf1 = m_thread.m_currentFrame.OpStack.Pop();
  279. if (bf1 is Float && bf2 is Float)
  280. {
  281. Float nflt = new Float();
  282. nflt.mValue = ((Float) bf1).mValue + ((Float) bf2).mValue;
  283. m_thread.m_currentFrame.OpStack.Push(nflt);
  284. }
  285. result = true;
  286. break;
  287. case (byte) OpCode.fsub:
  288. BaseType bsf2 = m_thread.m_currentFrame.OpStack.Pop();
  289. BaseType bsf1 = m_thread.m_currentFrame.OpStack.Pop();
  290. if (bsf1 is Float && bsf2 is Float)
  291. {
  292. Float resf = new Float();
  293. resf.mValue = ((Float) bsf1).mValue - ((Float) bsf2).mValue;
  294. m_thread.m_currentFrame.OpStack.Push(resf);
  295. }
  296. result = true;
  297. break;
  298. case (byte) OpCode.imul: //check the order of the two values off the stack is correct
  299. BaseType bs2 = m_thread.m_currentFrame.OpStack.Pop();
  300. BaseType bs1 = m_thread.m_currentFrame.OpStack.Pop();
  301. if (bs1 is Int && bs2 is Int)
  302. {
  303. Int nInt = new Int();
  304. nInt.mValue = ((Int) bs1).mValue*((Int) bs2).mValue;
  305. m_thread.m_currentFrame.OpStack.Push(nInt);
  306. }
  307. result = true;
  308. break;
  309. case (byte) OpCode.iinc:
  310. if (m_thread.m_currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[m_thread.PC]] !=
  311. null)
  312. {
  313. if (
  314. m_thread.m_currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[m_thread.PC]
  315. ] is Int)
  316. {
  317. ((Int)
  318. m_thread.m_currentFrame.LocalVariables[
  319. GlobalMemory.MethodArea.MethodBuffer[m_thread.PC]]).mValue +=
  320. (sbyte) GlobalMemory.MethodArea.MethodBuffer[m_thread.PC + 1];
  321. }
  322. }
  323. m_thread.PC += 2;
  324. result = true;
  325. break;
  326. case (byte) OpCode.f2i:
  327. BaseType conv1 = m_thread.m_currentFrame.OpStack.Pop();
  328. if (conv1 is Float)
  329. {
  330. Int newconv = new Int();
  331. newconv.mValue = (int) ((Float) conv1).mValue;
  332. m_thread.m_currentFrame.OpStack.Push(newconv);
  333. }
  334. result = true;
  335. break;
  336. case (byte) OpCode.fcmpl:
  337. BaseType flcom2 = m_thread.m_currentFrame.OpStack.Pop();
  338. BaseType flcom1 = m_thread.m_currentFrame.OpStack.Pop();
  339. if (flcom1 is Float && flcom2 is Float)
  340. {
  341. Int compres = new Int();
  342. if (((Float) flcom1).mValue < ((Float) flcom2).mValue)
  343. {
  344. compres.mValue = -1;
  345. }
  346. else if (((Float) flcom1).mValue > ((Float) flcom2).mValue)
  347. {
  348. compres.mValue = 1;
  349. }
  350. else
  351. {
  352. compres.mValue = 0;
  353. }
  354. m_thread.m_currentFrame.OpStack.Push(compres);
  355. }
  356. result = true;
  357. break;
  358. case (byte) OpCode.fcmpg:
  359. flcom2 = m_thread.m_currentFrame.OpStack.Pop();
  360. flcom1 = m_thread.m_currentFrame.OpStack.Pop();
  361. if (flcom1 is Float && flcom2 is Float)
  362. {
  363. Int compres = new Int();
  364. if (((Float) flcom1).mValue < ((Float) flcom2).mValue)
  365. {
  366. compres.mValue = -1;
  367. }
  368. else if (((Float) flcom1).mValue > ((Float) flcom2).mValue)
  369. {
  370. compres.mValue = 1;
  371. }
  372. else
  373. {
  374. compres.mValue = 0;
  375. }
  376. m_thread.m_currentFrame.OpStack.Push(compres);
  377. }
  378. result = true;
  379. break;
  380. case (byte) OpCode.ifge:
  381. short compareoffset2 =
  382. (short)
  383. ((GlobalMemory.MethodArea.MethodBuffer[m_thread.PC] << 8) +
  384. GlobalMemory.MethodArea.MethodBuffer[m_thread.PC + 1]);
  385. BaseType compe1 = m_thread.m_currentFrame.OpStack.Pop();
  386. if (compe1 is Int)
  387. {
  388. if (((Int) compe1).mValue >= 0)
  389. {
  390. m_thread.PC += -1 + compareoffset2;
  391. }
  392. else
  393. {
  394. m_thread.PC += 2;
  395. }
  396. }
  397. else
  398. {
  399. m_thread.PC += 2;
  400. }
  401. result = true;
  402. break;
  403. case (byte) OpCode.ifle:
  404. short compareoffset1 =
  405. (short)
  406. ((GlobalMemory.MethodArea.MethodBuffer[m_thread.PC] << 8) +
  407. GlobalMemory.MethodArea.MethodBuffer[m_thread.PC + 1]);
  408. BaseType comp1 = m_thread.m_currentFrame.OpStack.Pop();
  409. if (comp1 is Int)
  410. {
  411. if (((Int) comp1).mValue <= 0)
  412. {
  413. m_thread.PC += -1 + compareoffset1;
  414. }
  415. else
  416. {
  417. m_thread.PC += 2;
  418. }
  419. }
  420. else
  421. {
  422. m_thread.PC += 2;
  423. }
  424. result = true;
  425. break;
  426. case (byte) OpCode.if_icmpge:
  427. short compareoffset =
  428. (short)
  429. ((GlobalMemory.MethodArea.MethodBuffer[m_thread.PC] << 8) +
  430. GlobalMemory.MethodArea.MethodBuffer[m_thread.PC + 1]);
  431. BaseType bc2 = m_thread.m_currentFrame.OpStack.Pop();
  432. BaseType bc1 = m_thread.m_currentFrame.OpStack.Pop();
  433. if (bc1 is Int && bc2 is Int)
  434. {
  435. //Console.WriteLine("comparing " + ((Int)bc1).mValue + " and " + ((Int)bc2).mValue);
  436. if (((Int) bc1).mValue >= ((Int) bc2).mValue)
  437. {
  438. // Console.WriteLine("branch compare true , offset is " +compareoffset);
  439. // Console.WriteLine("current PC is " + this._mThread.PC);
  440. m_thread.PC += -1 + compareoffset;
  441. //Console.WriteLine("new PC is " + this._mThread.PC);
  442. }
  443. else
  444. {
  445. //Console.WriteLine("branch compare false");
  446. m_thread.PC += 2;
  447. }
  448. }
  449. else
  450. {
  451. m_thread.PC += 2;
  452. }
  453. result = true;
  454. break;
  455. case (byte) OpCode.if_icmple:
  456. short compareloffset =
  457. (short)
  458. ((GlobalMemory.MethodArea.MethodBuffer[m_thread.PC] << 8) +
  459. GlobalMemory.MethodArea.MethodBuffer[m_thread.PC + 1]);
  460. BaseType bcl2 = m_thread.m_currentFrame.OpStack.Pop();
  461. BaseType bcl1 = m_thread.m_currentFrame.OpStack.Pop();
  462. if (bcl1 is Int && bcl2 is Int)
  463. {
  464. //Console.WriteLine("comparing " + ((Int)bcl1).mValue + " and " + ((Int)bcl2).mValue);
  465. if (((Int) bcl1).mValue <= ((Int) bcl2).mValue)
  466. {
  467. // Console.WriteLine("branch compare true , offset is " + compareloffset);
  468. // Console.WriteLine("current PC is " + this._mThread.PC);
  469. m_thread.PC += -1 + compareloffset;
  470. // Console.WriteLine("new PC is " + this._mThread.PC);
  471. }
  472. else
  473. {
  474. //Console.WriteLine("branch compare false");
  475. m_thread.PC += 2;
  476. }
  477. }
  478. else
  479. {
  480. m_thread.PC += 2;
  481. }
  482. result = true;
  483. break;
  484. case (byte) OpCode._goto:
  485. short offset =
  486. (short)
  487. ((GlobalMemory.MethodArea.MethodBuffer[m_thread.PC] << 8) +
  488. GlobalMemory.MethodArea.MethodBuffer[m_thread.PC + 1]);
  489. m_thread.PC += -1 + offset;
  490. result = true;
  491. break;
  492. case (byte) OpCode.getstatic:
  493. short fieldrefIndex =
  494. (short)
  495. ((GlobalMemory.MethodArea.MethodBuffer[m_thread.PC] << 8) +
  496. GlobalMemory.MethodArea.MethodBuffer[m_thread.PC + 1]);
  497. if (m_thread.currentClass.m_constantsPool[fieldrefIndex - 1] is ClassRecord.PoolFieldRef)
  498. {
  499. if (
  500. ((ClassRecord.PoolFieldRef) m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).
  501. mClass.Name.Value == m_thread.currentClass.MClass.Name.Value)
  502. {
  503. //from this class
  504. if (
  505. m_thread.currentClass.StaticFields.ContainsKey(
  506. ((ClassRecord.PoolFieldRef)
  507. m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value))
  508. {
  509. if (
  510. m_thread.currentClass.StaticFields[
  511. ((ClassRecord.PoolFieldRef)
  512. m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.
  513. Value] is Float)
  514. {
  515. Float retFloat = new Float();
  516. retFloat.mValue =
  517. ((Float)
  518. m_thread.currentClass.StaticFields[
  519. ((ClassRecord.PoolFieldRef)
  520. m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.
  521. Name.Value]).mValue;
  522. m_thread.m_currentFrame.OpStack.Push(retFloat);
  523. }
  524. else if (
  525. m_thread.currentClass.StaticFields[
  526. ((ClassRecord.PoolFieldRef)
  527. m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.
  528. Name.Value] is Int)
  529. {
  530. Int retInt = new Int();
  531. retInt.mValue =
  532. ((Int)
  533. m_thread.currentClass.StaticFields[
  534. ((ClassRecord.PoolFieldRef)
  535. m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).
  536. mNameType.Name.Value]).mValue;
  537. // Console.WriteLine("getting static field, " + retInt.mValue);
  538. m_thread.m_currentFrame.OpStack.Push(retInt);
  539. }
  540. }
  541. }
  542. else
  543. {
  544. //get from a different class
  545. }
  546. }
  547. m_thread.PC += 2;
  548. result = true;
  549. break;
  550. case (byte) OpCode.putstatic:
  551. fieldrefIndex =
  552. (short)
  553. ((GlobalMemory.MethodArea.MethodBuffer[m_thread.PC] << 8) +
  554. GlobalMemory.MethodArea.MethodBuffer[m_thread.PC + 1]);
  555. BaseType addstatic = m_thread.m_currentFrame.OpStack.Pop();
  556. if (m_thread.currentClass.m_constantsPool[fieldrefIndex - 1] is ClassRecord.PoolFieldRef)
  557. {
  558. if (
  559. ((ClassRecord.PoolFieldRef) m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).
  560. mClass.Name.Value == m_thread.currentClass.MClass.Name.Value)
  561. {
  562. // this class
  563. if (
  564. m_thread.currentClass.StaticFields.ContainsKey(
  565. ((ClassRecord.PoolFieldRef)
  566. m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value))
  567. {
  568. if (addstatic is Float)
  569. {
  570. if (
  571. m_thread.currentClass.StaticFields[
  572. ((ClassRecord.PoolFieldRef)
  573. m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.
  574. Name.Value] is Float)
  575. {
  576. Float newf = new Float();
  577. newf.mValue = ((Float) addstatic).mValue;
  578. m_thread.currentClass.StaticFields[
  579. ((ClassRecord.PoolFieldRef)
  580. m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.
  581. Name.Value] = newf;
  582. }
  583. }
  584. else if (addstatic is Int)
  585. {
  586. if (
  587. m_thread.currentClass.StaticFields[
  588. ((ClassRecord.PoolFieldRef)
  589. m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.
  590. Name.Value] is Int)
  591. {
  592. //Console.WriteLine("setting static field to " + ((Int)addstatic).mValue);
  593. Int newi = new Int();
  594. newi.mValue = ((Int) addstatic).mValue;
  595. m_thread.currentClass.StaticFields[
  596. ((ClassRecord.PoolFieldRef)
  597. m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.
  598. Name.Value] = newi;
  599. }
  600. }
  601. }
  602. }
  603. else
  604. {
  605. // a different class
  606. }
  607. }
  608. m_thread.PC += 2;
  609. result = true;
  610. break;
  611. }
  612. return result;
  613. }
  614. }
  615. }
  616. }