as_context.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2011 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. class asCContext : public asIScriptContext
  40. {
  41. public:
  42. // From asIScriptContext
  43. int AddRef() const;
  44. int Release() const;
  45. asIScriptEngine *GetEngine() const;
  46. asEContextState GetState() const;
  47. int Prepare(asIScriptFunction *func);
  48. // TODO: interface: deprecate this
  49. int Prepare(int functionId);
  50. int Unprepare();
  51. int SetArgByte(asUINT arg, asBYTE value);
  52. int SetArgWord(asUINT arg, asWORD value);
  53. int SetArgDWord(asUINT arg, asDWORD value);
  54. int SetArgQWord(asUINT arg, asQWORD value);
  55. int SetArgFloat(asUINT arg, float value);
  56. int SetArgDouble(asUINT arg, double value);
  57. int SetArgAddress(asUINT arg, void *addr);
  58. int SetArgObject(asUINT arg, void *obj);
  59. void *GetAddressOfArg(asUINT arg);
  60. int SetObject(void *obj);
  61. asBYTE GetReturnByte();
  62. asWORD GetReturnWord();
  63. asDWORD GetReturnDWord();
  64. asQWORD GetReturnQWord();
  65. float GetReturnFloat();
  66. double GetReturnDouble();
  67. void *GetReturnAddress();
  68. void *GetReturnObject();
  69. void *GetAddressOfReturnValue();
  70. int Execute();
  71. int Abort();
  72. int Suspend();
  73. int SetException(const char *descr);
  74. int GetExceptionLineNumber(int *column, const char **sectionName);
  75. int GetExceptionFunction();
  76. const char *GetExceptionString();
  77. int SetLineCallback(asSFuncPtr callback, void *obj, int callConv);
  78. void ClearLineCallback();
  79. int SetExceptionCallback(asSFuncPtr callback, void *obj, int callConv);
  80. void ClearExceptionCallback();
  81. asUINT GetCallstackSize();
  82. asIScriptFunction *GetFunction(asUINT stackLevel);
  83. int GetLineNumber(asUINT stackLevel, int *column, const char **sectionName);
  84. int GetVarCount(asUINT stackLevel);
  85. const char *GetVarName(asUINT varIndex, asUINT stackLevel);
  86. const char *GetVarDeclaration(asUINT varIndex, asUINT stackLevel);
  87. int GetVarTypeId(asUINT varIndex, asUINT stackLevel);
  88. void *GetAddressOfVar(asUINT varIndex, asUINT stackLevel);
  89. bool IsVarInScope(asUINT varIndex, asUINT stackLevel);
  90. int GetThisTypeId(asUINT stackLevel);
  91. void *GetThisPointer(asUINT stackLevel);
  92. void *SetUserData(void *data);
  93. void *GetUserData() const;
  94. public:
  95. // Internal public functions
  96. asCContext(asCScriptEngine *engine, bool holdRef);
  97. virtual ~asCContext();
  98. //protected:
  99. friend class asCScriptEngine;
  100. void CallLineCallback();
  101. void CallExceptionCallback();
  102. int CallGeneric(int funcID, void *objectPointer);
  103. void DetachEngine();
  104. void ExecuteNext();
  105. void CleanStack();
  106. void CleanStackFrame();
  107. void CleanReturnObject();
  108. void DetermineLiveObjects(asCArray<int> &liveObjects, asUINT stackLevel);
  109. void PushCallState();
  110. void PopCallState();
  111. void CallScriptFunction(asCScriptFunction *func);
  112. void CallInterfaceMethod(asCScriptFunction *func);
  113. void SetInternalException(const char *descr);
  114. // Must be protected for multiple accesses
  115. mutable asCAtomic refCount;
  116. bool holdEngineRef;
  117. asCScriptEngine *engine;
  118. asEContextState status;
  119. bool doSuspend;
  120. bool doAbort;
  121. bool externalSuspendRequest;
  122. bool isCallingSystemFunction;
  123. asCScriptFunction *currentFunction;
  124. bool isStackMemoryNotAllocated;
  125. asCArray<size_t> callStack;
  126. asCArray<asDWORD *> stackBlocks;
  127. int stackBlockSize;
  128. int stackIndex;
  129. bool inExceptionHandler;
  130. asCString exceptionString;
  131. int exceptionFunction;
  132. int exceptionLine;
  133. int exceptionColumn;
  134. int returnValueSize;
  135. int argumentsSize;
  136. asCScriptFunction *initialFunction;
  137. // callbacks
  138. bool lineCallback;
  139. asSSystemFunctionInterface lineCallbackFunc;
  140. void *lineCallbackObj;
  141. bool exceptionCallback;
  142. asSSystemFunctionInterface exceptionCallbackFunc;
  143. void *exceptionCallbackObj;
  144. void *userData;
  145. // Registers available to JIT compiler functions
  146. asSVMRegisters regs;
  147. };
  148. END_AS_NAMESPACE
  149. #endif