/xbmc/visualizations/Vortex/angelscript/angelscript/source/as_context.h

http://github.com/xbmc/xbmc · C++ Header · 210 lines · 120 code · 46 blank · 44 comment · 0 complexity · b30aaa9e879d8830d01687ffef73d423 MD5 · raw file

  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2009 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. andreas@angelcode.com
  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();
  45. int Release();
  46. asIScriptEngine *GetEngine();
  47. asEContextState GetState();
  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 GetCurrentLineNumber(int *column);
  73. int GetCurrentFunction();
  74. int SetException(const char *descr);
  75. int GetExceptionLineNumber(int *column);
  76. int GetExceptionFunction();
  77. const char *GetExceptionString();
  78. int SetLineCallback(asSFuncPtr callback, void *obj, int callConv);
  79. void ClearLineCallback();
  80. int SetExceptionCallback(asSFuncPtr callback, void *obj, int callConv);
  81. void ClearExceptionCallback();
  82. int GetCallstackSize();
  83. int GetCallstackFunction(int index);
  84. int GetCallstackLineNumber(int index, int *column);
  85. int GetVarCount(int stackLevel);
  86. const char *GetVarName(int varIndex, int stackLevel);
  87. const char *GetVarDeclaration(int varIndex, int stackLevel);
  88. int GetVarTypeId(int varIndex, int stackLevel);
  89. void *GetAddressOfVar(int varIndex, int stackLevel);
  90. int GetThisTypeId(int stackLevel);
  91. void *GetThisPointer(int stackLevel);
  92. void *SetUserData(void *data);
  93. void *GetUserData();
  94. public:
  95. // Internal public functions
  96. asCContext(asCScriptEngine *engine, bool holdRef);
  97. virtual ~asCContext();
  98. #ifdef AS_DEPRECATED
  99. // Deprecated since 2009-12-08, 2.18.0
  100. int SetExecuteStringFunction(asCScriptFunction *func);
  101. #endif
  102. //protected:
  103. friend class asCScriptEngine;
  104. void CallLineCallback();
  105. void CallExceptionCallback();
  106. int CallGeneric(int funcID, void *objectPointer);
  107. void DetachEngine();
  108. void ExecuteNext();
  109. void CleanStack();
  110. void CleanStackFrame();
  111. void CleanReturnObject();
  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. 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. #ifdef AS_DEPRECATED
  140. // Deprecated since 2009-12-08, 2.18.0
  141. // String function
  142. asCScriptFunction *stringFunction;
  143. #endif
  144. asCScriptFunction *initialFunction;
  145. // callbacks
  146. bool lineCallback;
  147. asSSystemFunctionInterface lineCallbackFunc;
  148. void *lineCallbackObj;
  149. bool exceptionCallback;
  150. asSSystemFunctionInterface exceptionCallbackFunc;
  151. void *exceptionCallbackObj;
  152. void *userData;
  153. // Registers available to JIT compiler functions
  154. asSVMRegisters regs;
  155. };
  156. END_AS_NAMESPACE
  157. #endif