Interpreter.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 System;
  28. using OpenSim.Region.ExtensionsScriptModule.JVMEngine.Types;
  29. using OpenSim.Region.ExtensionsScriptModule.JVMEngine.Types.PrimitiveTypes;
  30. namespace OpenSim.Region.ExtensionsScriptModule.JVMEngine.JVM
  31. {
  32. partial class Thread
  33. {
  34. private partial class Interpreter
  35. {
  36. private Thread m_thread;
  37. public Interpreter(Thread parentThread)
  38. {
  39. m_thread = parentThread;
  40. }
  41. public bool Excute()
  42. {
  43. bool run = true;
  44. byte currentOpCode = GlobalMemory.MethodArea.MethodBuffer[m_thread.PC++];
  45. // Console.WriteLine("opCode is: " + currentOpCode);
  46. bool handled = false;
  47. handled = IsLogicOpCode(currentOpCode);
  48. if (!handled)
  49. {
  50. handled = IsMethodOpCode(currentOpCode);
  51. }
  52. if (!handled)
  53. {
  54. if (currentOpCode == 172)
  55. {
  56. if (m_thread.stack.StackFrames.Count > 1)
  57. {
  58. Console.WriteLine("returning int from function");
  59. int retPC1 = m_thread.m_currentFrame.ReturnPC;
  60. BaseType bas1 = m_thread.m_currentFrame.OpStack.Pop();
  61. m_thread.stack.StackFrames.Pop();
  62. m_thread.m_currentFrame = m_thread.stack.StackFrames.Peek();
  63. m_thread.PC = retPC1;
  64. if (bas1 is Int)
  65. {
  66. m_thread.m_currentFrame.OpStack.Push((Int) bas1);
  67. }
  68. }
  69. else
  70. {
  71. // Console.WriteLine("No parent function so ending program");
  72. m_thread.stack.StackFrames.Pop();
  73. run = false;
  74. }
  75. handled = true;
  76. }
  77. if (currentOpCode == 174)
  78. {
  79. if (m_thread.stack.StackFrames.Count > 1)
  80. {
  81. Console.WriteLine("returning float from function");
  82. int retPC1 = m_thread.m_currentFrame.ReturnPC;
  83. BaseType bas1 = m_thread.m_currentFrame.OpStack.Pop();
  84. m_thread.stack.StackFrames.Pop();
  85. m_thread.m_currentFrame = m_thread.stack.StackFrames.Peek();
  86. m_thread.PC = retPC1;
  87. if (bas1 is Float)
  88. {
  89. m_thread.m_currentFrame.OpStack.Push((Float) bas1);
  90. }
  91. }
  92. else
  93. {
  94. // Console.WriteLine("No parent function so ending program");
  95. m_thread.stack.StackFrames.Pop();
  96. run = false;
  97. }
  98. handled = true;
  99. }
  100. if (currentOpCode == 177)
  101. {
  102. if (m_thread.stack.StackFrames.Count > 1)
  103. {
  104. Console.WriteLine("returning from function");
  105. int retPC = m_thread.m_currentFrame.ReturnPC;
  106. m_thread.stack.StackFrames.Pop();
  107. m_thread.m_currentFrame = m_thread.stack.StackFrames.Peek();
  108. m_thread.PC = retPC;
  109. }
  110. else
  111. {
  112. // Console.WriteLine("No parent function so ending program");
  113. m_thread.stack.StackFrames.Pop();
  114. run = false;
  115. }
  116. handled = true;
  117. }
  118. }
  119. if (!handled)
  120. {
  121. Console.WriteLine("opcode " + currentOpCode + " not been handled ");
  122. }
  123. return run;
  124. }
  125. }
  126. }
  127. }