Interpreter.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 Thread _mThread;
  13. public Interpreter(Thread parentThread)
  14. {
  15. _mThread = parentThread;
  16. }
  17. public bool Excute()
  18. {
  19. bool run = true;
  20. byte currentOpCode = GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC++];
  21. // Console.WriteLine("opCode is: " + currentOpCode);
  22. bool handled = false;
  23. handled = this.IsLogicOpCode(currentOpCode);
  24. if (!handled)
  25. {
  26. handled = this.IsMethodOpCode(currentOpCode);
  27. }
  28. if (!handled)
  29. {
  30. if (currentOpCode == 172)
  31. {
  32. if (this._mThread.stack.StackFrames.Count > 1)
  33. {
  34. Console.WriteLine("returning int from function");
  35. int retPC1 = this._mThread.currentFrame.ReturnPC;
  36. BaseType bas1 = this._mThread.currentFrame.OpStack.Pop();
  37. this._mThread.stack.StackFrames.Pop();
  38. this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
  39. this._mThread.PC = retPC1;
  40. if (bas1 is Int)
  41. {
  42. this._mThread.currentFrame.OpStack.Push((Int)bas1);
  43. }
  44. }
  45. else
  46. {
  47. // Console.WriteLine("No parent function so ending program");
  48. run = false;
  49. }
  50. handled = true;
  51. }
  52. if (currentOpCode == 174)
  53. {
  54. if (this._mThread.stack.StackFrames.Count > 1)
  55. {
  56. Console.WriteLine("returning float from function");
  57. int retPC1 = this._mThread.currentFrame.ReturnPC;
  58. BaseType bas1 = this._mThread.currentFrame.OpStack.Pop();
  59. this._mThread.stack.StackFrames.Pop();
  60. this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
  61. this._mThread.PC = retPC1;
  62. if (bas1 is Float)
  63. {
  64. this._mThread.currentFrame.OpStack.Push((Float)bas1);
  65. }
  66. }
  67. else
  68. {
  69. // Console.WriteLine("No parent function so ending program");
  70. run = false;
  71. }
  72. handled = true;
  73. }
  74. if (currentOpCode == 177)
  75. {
  76. if (this._mThread.stack.StackFrames.Count > 1)
  77. {
  78. Console.WriteLine("returning from function");
  79. int retPC = this._mThread.currentFrame.ReturnPC;
  80. this._mThread.stack.StackFrames.Pop();
  81. this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
  82. this._mThread.PC = retPC;
  83. }
  84. else
  85. {
  86. // Console.WriteLine("No parent function so ending program");
  87. run = false;
  88. }
  89. handled = true;
  90. }
  91. }
  92. if (!handled)
  93. {
  94. Console.WriteLine("opcode " + currentOpCode + " not been handled ");
  95. }
  96. return run;
  97. }
  98. }
  99. }
  100. }