PageRenderTime 22ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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