Sheep
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
sheepcpp.h
Go to the documentation of this file.
1 #ifndef SHEEP_SHEEPCPP_H
2 #define SHEEP_SHEEPCPP_H
3 
4 #include "sheepCommon.h"
5 
8 namespace Sheep
10 {
12  enum class SymbolType
13  {
15  Void = 0,
16 
18  Int = 1,
19 
21  Float = 2,
22 
24  String = 3
25  };
26 
29  {
31  V100 = 0,
32 
34  V200
35  };
36 
37  class IScript;
38  class IVirtualMachine;
39 
41  {
43  Prepared,
44 
46  Executing,
47 
49  Suspended,
50 
52  Finished
53  };
54 
60  {
61  public:
65  virtual void Release() = 0;
66 
70  virtual int Execute() = 0;
71 
75  virtual int Suspend() = 0;
76 
78  virtual ExecutionContextState GetState() = 0;
79 
82 
84  virtual int GetNumVariables() = 0;
85 
87  virtual const char* GetVariableName(int index) = 0;
88 
90  virtual SymbolType GetVariableType(int index) = 0;
91 
97  virtual int SetVariableInt(int index, int value) = 0;
98 
104  virtual int SetVariableFloat(int index, float value) = 0;
105 
111  virtual int SetVariableString(int index, const char* value) = 0;
112 
118  virtual int GetVariableInt(int index, int* result) = 0;
119 
125  virtual int GetVariableFloat(int index, float* result) = 0;
126 
132  virtual int GetVariableString(int index, const char** result) = 0;
133 
138  virtual int PopIntFromStack(int* result) = 0;
139 
144  virtual int PopFloatFromStack(float* result) = 0;
145 
150  virtual int PopStringFromStack(const char** result) = 0;
151 
155  virtual int PushIntOntoStack(int value) = 0;
156 
160  virtual int PushFloatOntoStack(float value) = 0;
161  };
162 
163  typedef void (SHP_CALLBACK *ImportCallback)(IExecutionContext* context);
164  typedef void (SHP_CALLBACK* EndWaitCallback)(IVirtualMachine* vm, IExecutionContext* context);
165 
168  {
169  public:
175  virtual void Release() = 0;
176 
179 
182  virtual void SetTag(void* tag) = 0;
184  virtual void* GetTag() = 0;
185 
193  virtual int SetEndWaitCallback(EndWaitCallback callback) = 0;
194 
202  virtual int SetImportCallback(const char* importName, ImportCallback callback) = 0;
203 
214  virtual int PrepareScriptForExecution(IScript* script, const char* function, IExecutionContext** context) = 0;
215  };
216 
219  {
220  protected:
221  virtual ~IDisassembly() {}
222 
223  public:
225  virtual void Release() = 0;
226 
230  virtual const char* GetDisassemblyText() = 0;
231  };
232 
234  {
235  protected:
236  virtual ~ICompiledScriptOutput() {}
237 
238  public:
240  virtual void Release() = 0;
241 
243  virtual int GetSize() = 0;
244 
246  virtual const char* GetData() = 0;
247  };
248 
250  enum class ScriptStatus
251  {
253  Success,
254 
256  Error,
257 
259  Invalid
260  };
261 
263  class IScript
264  {
265  protected:
266  virtual ~IScript() {}
267 
268  public:
273  virtual void Release() = 0;
274 
277 
279  virtual ScriptStatus GetStatus() = 0;
280 
282  virtual int GetNumMessages() = 0;
283 
285  virtual const char* GetMessage(int index) = 0;
286 
288  virtual int GetMessageLineNumber(int index) = 0;
289 
292  virtual IDisassembly* GenerateDisassembly() = 0;
293 
297  };
298 
300  class ICompiler
301  {
302  protected:
303  virtual ~ICompiler() {}
304 
305  public:
311  virtual void Release() = 0;
312 
315 
322  virtual int DefineImportFunction(const char* name, SymbolType returnType, SymbolType parameters[], int numParameters) = 0;
323 
331  virtual IScript* CompileScript(const char* script) = 0;
332  };
333 }
334 
335 
336 extern "C"
337 {
343  SHP_DECLSPEC Sheep::ICompiler* SHP_APIENTRY CreateSheepCompiler(Sheep::SheepLanguageVersion version);
344 
351 
360  SHP_DECLSPEC int SHP_APIENTRY CreateScriptFromBytecode(const char* bytecode, int length, Sheep::IScript** result);
361 }
362 
363 #endif // SHEEP_SHEEPCPP_H
virtual void Release()=0
virtual int PushIntOntoStack(int value)=0
virtual void Release()=0
virtual SheepLanguageVersion GetLanguageVersion()=0
Gets the language version with which this script was created.
virtual ICompiledScriptOutput * GenerateCompiledOutput()=0
virtual void Release()=0
The context has finished execution.
virtual int SetImportCallback(const char *importName, ImportCallback callback)=0
virtual int PrepareScriptForExecution(IScript *script, const char *function, IExecutionContext **context)=0
virtual int GetNumMessages()=0
Gets the number of messages that were generated during compilation.
Represents a Sheep Virtual Machine which executes compiled Sheep scripts.
Definition: sheepcpp.h:167
SHP_DECLSPEC Sheep::IVirtualMachine *SHP_APIENTRY CreateSheepVirtualMachine(Sheep::SheepLanguageVersion version)
Interface to a Compiler object that compiles sheep scripts.
Definition: sheepcpp.h:300
SheepLanguageVersion
Represents a specific version of Sheep.
Definition: sheepcpp.h:28
The context has been prepared for execution and is ready to execute.
virtual void Release()=0
Releases the compiled script output object.
virtual int GetMessageLineNumber(int index)=0
Gets the line number for which the particular message was generated.
SHP_DECLSPEC int SHP_APIENTRY CreateScriptFromBytecode(const char *bytecode, int length, Sheep::IScript **result)
virtual int PushFloatOntoStack(float value)=0
Definition: sheepcpp.h:233
virtual int GetSize()=0
Returns the size (in bytes) of the compiled output.
virtual int PopFloatFromStack(float *result)=0
virtual SymbolType GetVariableType(int index)=0
Gets the type of variable at the specified index.
virtual int GetNumVariables()=0
Gets the number of global variables within the script associated with the Context.
virtual IVirtualMachine * GetParentVirtualMachine()=0
Gets the parent Sheep::IVirtualMachine that owns this context.
virtual int SetVariableInt(int index, int value)=0
virtual SheepLanguageVersion GetLanguageVersion()=0
Gets the language version with which this virtual machine was created.
virtual int SetVariableString(int index, const char *value)=0
The script was successfully compiled and is ready to run.
virtual void SetTag(void *tag)=0
virtual int GetVariableString(int index, const char **result)=0
32-bit floating point symbol type
virtual int PopStringFromStack(const char **result)=0
"Void" symbol type
The context has been suspended and is ready to resume.
ScriptStatus
Represents the status of an IScript object.
Definition: sheepcpp.h:250
virtual int DefineImportFunction(const char *name, SymbolType returnType, SymbolType parameters[], int numParameters)=0
virtual const char * GetMessage(int index)=0
Gets the message text of the particular message generated during compilation.
Vanilla version of Sheep with no enhancements (Gabriel Knight 3-level features only) ...
virtual void Release()=0
Releases the disassembly.
The context is currently executing.
There was an error compiling the script.
Variable length string variable type.
Represents a disassembly of an IScript object.
Definition: sheepcpp.h:218
SHP_DECLSPEC Sheep::ICompiler *SHP_APIENTRY CreateSheepCompiler(Sheep::SheepLanguageVersion version)
virtual IDisassembly * GenerateDisassembly()=0
virtual int Suspend()=0
Definition: sheepcpp.h:59
virtual const char * GetVariableName(int index)=0
Gets the name of the given variable, or null if the index is invalid.
virtual int GetVariableInt(int index, int *result)=0
Interface to a Script object.
Definition: sheepcpp.h:263
virtual int SetVariableFloat(int index, float value)=0
virtual ScriptStatus GetStatus()=0
Gets the status of the script.
virtual void Release()=0
SymbolType
Represents a Sheep symbol type.
Definition: sheepcpp.h:12
virtual int PopIntFromStack(int *result)=0
virtual ExecutionContextState GetState()=0
Gets the current state of the context.
virtual int Execute()=0
virtual void * GetTag()=0
Gets the tag that was set earlier, or null if no tag has been set.
virtual int SetEndWaitCallback(EndWaitCallback callback)=0
virtual IScript * CompileScript(const char *script)=0
ExecutionContextState
Definition: sheepcpp.h:40
virtual const char * GetData()=0
Returns the raw compiled output data.
virtual const char * GetDisassemblyText()=0
32-bit integer symbol type
virtual int GetVariableFloat(int index, float *result)=0
The script is not valid and cannot run.
virtual SheepLanguageVersion GetLanguageVersion()=0
Gets the language version with which this compiler was created.