as_context.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2010 Andreas Jonsson
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any
  6. damages arising from the use of this software.
  7. Permission is granted to anyone to use this software for any
  8. purpose, including commercial applications, and to alter it and
  9. redistribute it freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you
  11. must not claim that you wrote the original software. If you use
  12. this software in a product, an acknowledgment in the product
  13. documentation would be appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and
  15. must not be misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source
  17. distribution.
  18. The original version of this library can be located at:
  19. http://www.angelcode.com/angelscript/
  20. Andreas Jonsson
  21. [email protected]
  22. */
  23. //
  24. // as_context.h
  25. //
  26. // This class handles the execution of the byte code
  27. //
  28. #ifndef AS_CONTEXT_H
  29. #define AS_CONTEXT_H
  30. #include "as_config.h"
  31. #include "as_atomic.h"
  32. #include "as_array.h"
  33. #include "as_string.h"
  34. #include "as_objecttype.h"
  35. #include "as_callfunc.h"
  36. BEGIN_AS_NAMESPACE
  37. class asCScriptFunction;
  38. class asCScriptEngine;
  39. // TODO: The context should be renamed to something that better describes it, e.g. asIVirtualMachine, asIExecuter, asIProcessor, asIScriptThread, or something like that
  40. class asCContext : public asIScriptContext
  41. {
  42. public:
  43. // From asIScriptContext
  44. int AddRef() const;
  45. int Release() const;
  46. asIScriptEngine *GetEngine() const;
  47. asEContextState GetState() const;
  48. int Prepare(int functionID);
  49. int Unprepare();
  50. int SetArgByte(asUINT arg, asBYTE value);
  51. int SetArgWord(asUINT arg, asWORD value);
  52. int SetArgDWord(asUINT arg, asDWORD value);
  53. int SetArgQWord(asUINT arg, asQWORD value);
  54. int SetArgFloat(asUINT arg, float value);
  55. int SetArgDouble(asUINT arg, double value);
  56. int SetArgAddress(asUINT arg, void *addr);
  57. int SetArgObject(asUINT arg, void *obj);
  58. void *GetAddressOfArg(asUINT arg);
  59. int SetObject(void *obj);
  60. asBYTE GetReturnByte();
  61. asWORD GetReturnWord();
  62. asDWORD GetReturnDWord();
  63. asQWORD GetReturnQWord();
  64. float GetReturnFloat();
  65. double GetReturnDouble();
  66. void *GetReturnAddress();
  67. void *GetReturnObject();
  68. void *GetAddressOfReturnValue();
  69. int Execute();
  70. int Abort();
  71. int Suspend();
  72. int SetException(const char *descr);
  73. int GetExceptionLineNumber(int *column, const char **sectionName);
  74. int GetExceptionFunction();
  75. const char *GetExceptionString();
  76. int SetLineCallback(asSFuncPtr callback, void *obj, int callConv);
  77. void ClearLineCallback();
  78. int SetExceptionCallback(asSFuncPtr callback, void *obj, int callConv);
  79. void ClearExceptionCallback();
  80. asUINT GetCallstackSize();
  81. asIScriptFunction *GetFunction(asUINT stackLevel);
  82. int GetLineNumber(asUINT stackLevel, int *column, const char **sectionName);
  83. int GetVarCount(asUINT stackLevel);
  84. const char *GetVarName(int varIndex, asUINT stackLevel);
  85. const char *GetVarDeclaration(int varIndex, asUINT stackLevel);
  86. int GetVarTypeId(int varIndex, asUINT stackLevel);
  87. void *GetAddressOfVar(int varIndex, asUINT stackLevel);
  88. int GetThisTypeId(asUINT stackLevel);
  89. void *GetThisPointer(asUINT stackLevel);
  90. void *SetUserData(void *data);
  91. void *GetUserData() const;
  92. #ifdef AS_DEPRECATED
  93. // Deprecated since 2.20.0
  94. int GetCurrentLineNumber(int *column, const char **sectionName);
  95. int GetCurrentFunction();
  96. #endif
  97. public:
  98. // Internal public functions
  99. asCContext(asCScriptEngine *engine, bool holdRef);
  100. virtual ~asCContext();
  101. //protected:
  102. friend class asCScriptEngine;
  103. void CallLineCallback();
  104. void CallExceptionCallback();
  105. int CallGeneric(int funcID, void *objectPointer);
  106. void DetachEngine();
  107. void ExecuteNext();
  108. void CleanStack();
  109. void CleanStackFrame();
  110. void CleanReturnObject();
  111. void DetermineLiveObjects(asCArray<int> &liveObjects, asUINT stackLevel);
  112. void PushCallState();
  113. void PopCallState();
  114. void CallScriptFunction(asCScriptFunction *func);
  115. void CallInterfaceMethod(asCScriptFunction *func);
  116. void SetInternalException(const char *descr);
  117. // Must be protected for multiple accesses
  118. mutable asCAtomic refCount;
  119. bool holdEngineRef;
  120. asCScriptEngine *engine;
  121. asEContextState status;
  122. bool doSuspend;
  123. bool doAbort;
  124. bool externalSuspendRequest;
  125. bool isCallingSystemFunction;
  126. asCScriptFunction *currentFunction;
  127. bool isStackMemoryNotAllocated;
  128. asCArray<size_t> callStack;
  129. asCArray<asDWORD *> stackBlocks;
  130. int stackBlockSize;
  131. int stackIndex;
  132. bool inExceptionHandler;
  133. asCString exceptionString;
  134. int exceptionFunction;
  135. int exceptionLine;
  136. int exceptionColumn;
  137. int returnValueSize;
  138. int argumentsSize;
  139. asCScriptFunction *initialFunction;
  140. // callbacks
  141. bool lineCallback;
  142. asSSystemFunctionInterface lineCallbackFunc;
  143. void *lineCallbackObj;
  144. bool exceptionCallback;
  145. asSSystemFunctionInterface exceptionCallbackFunc;
  146. void *exceptionCallbackObj;
  147. void *userData;
  148. // Registers available to JIT compiler functions
  149. asSVMRegisters regs;
  150. };
  151. END_AS_NAMESPACE
  152. #endif