Interpreter.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. this._mThread.stack.StackFrames.Pop();
  49. run = false;
  50. }
  51. handled = true;
  52. }
  53. if (currentOpCode == 174)
  54. {
  55. if (this._mThread.stack.StackFrames.Count > 1)
  56. {
  57. Console.WriteLine("returning float from function");
  58. int retPC1 = this._mThread.currentFrame.ReturnPC;
  59. BaseType bas1 = this._mThread.currentFrame.OpStack.Pop();
  60. this._mThread.stack.StackFrames.Pop();
  61. this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
  62. this._mThread.PC = retPC1;
  63. if (bas1 is Float)
  64. {
  65. this._mThread.currentFrame.OpStack.Push((Float)bas1);
  66. }
  67. }
  68. else
  69. {
  70. // Console.WriteLine("No parent function so ending program");
  71. this._mThread.stack.StackFrames.Pop();
  72. run = false;
  73. }
  74. handled = true;
  75. }
  76. if (currentOpCode == 177)
  77. {
  78. if (this._mThread.stack.StackFrames.Count > 1)
  79. {
  80. Console.WriteLine("returning from function");
  81. int retPC = this._mThread.currentFrame.ReturnPC;
  82. this._mThread.stack.StackFrames.Pop();
  83. this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
  84. this._mThread.PC = retPC;
  85. }
  86. else
  87. {
  88. // Console.WriteLine("No parent function so ending program");
  89. this._mThread.stack.StackFrames.Pop();
  90. run = false;
  91. }
  92. handled = true;
  93. }
  94. }
  95. if (!handled)
  96. {
  97. Console.WriteLine("opcode " + currentOpCode + " not been handled ");
  98. }
  99. return run;
  100. }
  101. }
  102. }
  103. }