The execution stack.
More...
#include <CBotStack.h>
|
void | Reset () |
| Reset the stack for execution resume - resets the error and timer. More...
|
|
void | SetProgram (CBotProgram *p) |
| Set program this stack level is in. Additionally marks this block as function block. Note: for public functions different stack levels might be in different programs. More...
|
|
CBotProgram * | GetProgram (bool bFirst=false) |
| Get program we are currently in. More...
|
|
void | SetUserPtr (void *user) |
| Set user pointer for external calls. More...
|
|
void * | GetUserPtr () |
| Get user pointer for external calls. More...
|
|
BlockVisibilityType | GetBlock () |
| Get the block type this stack represents - instruction, code block or function. More...
|
|
void | GetRunPos (std::string &functionName, int &start, int &end) |
| Get current position in the program. More...
|
|
CBotVar * | GetStackVars (std::string &functionName, int level) |
| Get local variables at the given stack level. More...
|
|
bool | IsCallFinished () |
|
|
static void | SetTimer (int n) |
| Set the maximum number of "timer ticks" (parts of instructions) to execute. More...
|
|
static int | GetTimer () |
| Get the current configured maximum number of "timer ticks" (parts of instructions) to execute. More...
|
|
|
bool | SaveState (FILE *pf) |
|
bool | RestoreState (FILE *pf, CBotStack *&pStack) |
|
Block type this stack represents. This determines local variable visibility (you can only see up to top FUNCTION stack)
Enumerator |
---|
INSTRUCTION |
Instruction (default)
|
BLOCK |
Code block between { ... }.
|
FUNCTION |
Function - variable visibility limit.
|
CBotStack * CBot::CBotStack::AllocateStack |
( |
| ) |
|
|
static |
Allocate the stack.
- Returns
- pointer to created stack
void CBot::CBotStack::Delete |
( |
| ) |
|
Remove the current stack.
bool CBot::CBotStack::StackOver |
( |
| ) |
|
Check for stack overflow and set error status as needed.
- Returns
- true on stack overflow
CBotError CBot::CBotStack::GetError |
( |
int & |
start, |
|
|
int & |
end |
|
) |
| |
|
inline |
Get last error.
- Parameters
-
[out] | start | Starting position in code of the error |
[out] | end | Ending position in code of the error |
- Returns
- Error number
bool CBot::CBotStack::IsOk |
( |
| ) |
|
|
inline |
Check if there was an error.
- Returns
- false if an error occurred
- See also
- GetError()
Set execution error unless it's already set unless you are trying to reset it.
- Parameters
-
n | Error to set |
token | Token to take error position from |
- See also
- ResetError() to force set error
void CBot::CBotStack::SetPosError |
( |
CBotToken * |
token | ) |
|
Set error position to position of given token.
- Parameters
-
token | Token to take error position from |
void CBot::CBotStack::ResetError |
( |
CBotError |
n, |
|
|
int |
start, |
|
|
int |
end |
|
) |
| |
Set execution error even if it is already set.
- See also
- SetError() to set error only if it is not set already
void CBot::CBotStack::SetBreak |
( |
int |
val, |
|
|
const std::string & |
name |
|
) |
| |
- Todo:
- Document
WARNING! Changes error to -val ...
void CBot::CBotStack::Reset |
( |
| ) |
|
Reset the stack for execution resume - resets the error and timer.
void CBot::CBotStack::AddVar |
( |
CBotVar * |
var | ) |
|
Adds a local variable.
- Parameters
-
Fetch a variable by its token.
- Parameters
-
pToken | Token upon which search is performed |
bUpdate | true to automatically call update function for classes, see CBotClass::SetUpdateFunc() |
- Returns
- Found variable, nullptr if not found
Fetch a variable by its token.
- Parameters
-
pToken | Token upon which search is performed |
bUpdate | true to automatically call update function for classes, see CBotClass::SetUpdateFunc() |
- Returns
- Found variable, nullptr if not found
CBotVar * CBot::CBotStack::FindVar |
( |
const std::string & |
name | ) |
|
Fetch variable by its name.
- Parameters
-
name | Name of variable to find |
- Returns
- Found variable, nullptr if not found
CBotVar * CBot::CBotStack::FindVar |
( |
long |
ident, |
|
|
bool |
bUpdate |
|
) |
| |
Fetch a variable on the stack according to its unique identifier.
This is faster than comparing names
- Parameters
-
ident | Unique identifier of a variable |
bUpdate | true to automatically call update function for classes, see CBotClass::SetUpdateFunc() |
- Returns
- Found variable, nullptr if not found
Find variable by its token and returns a copy of it.
- Parameters
-
pToken | Token upon which search is performed |
bUpdate | true to automatically call update function for classes, see CBotClass::SetUpdateFunc() |
- Returns
- Found variable, nullptr if not found
Creates or gets the primary child stack.
If the stack already exists, it is returned. Otherwise, a new stack is created.
- Todo:
- Document params
- Returns
- New stack element
Creates or gets the secondary child stack.
- Todo:
- What is it used for?
If the stack already exists, it is returned. Otherwise, a new stack is created.
- See also
- AddStack()
- Returns
- New stack element
Adds special EOX stack marker.
- Todo:
- What is this thing? Used by external calls
- Todo:
- Document params & return
Restore CBotInstr pointer after loading stack from file.
- Todo:
- Check what this does exactly
Restores CBotExternalCall in the EOX marker after loading stack from file.
- Todo:
- Check what this does exactly
bool CBot::CBotStack::Return |
( |
CBotStack * |
pFils | ) |
|
Return to this point - copy the result from given stack, and destroy all child stacks from here.
- Todo:
- Better description
- Parameters
-
pFils | Stack to copy result from |
- Returns
- IsOk()
bool CBot::CBotStack::ReturnKeep |
( |
CBotStack * |
pFils | ) |
|
Like Return() but doesn't destroy the stacks.
- Parameters
-
pFils | Stack to copy result from |
- Returns
- IsOk()
bool CBot::CBotStack::BreakReturn |
( |
CBotStack * |
pfils, |
|
|
const std::string & |
name = "" |
|
) |
| |
- Todo:
- Document
in case of eventual break
bool CBot::CBotStack::IfContinue |
( |
int |
state, |
|
|
const std::string & |
name |
|
) |
| |
- Todo:
- Document
or "continue"
bool CBot::CBotStack::SetState |
( |
int |
n, |
|
|
int |
lim = -10 |
|
) |
| |
Set execution state.
- Parameters
-
n | New state |
lim | Required amount of "ticks" on the timer required to allow to continue execution. By default allows a little overflow (up to 10 ticks) |
- Returns
- false if timer requests interruption (timer <= limit)
int CBot::CBotStack::GetState |
( |
| ) |
|
|
inline |
Return current execution state.
Used when resuming execution
- Returns
- Execution state set before interruption by SetState() and IncState()
bool CBot::CBotStack::IncState |
( |
int |
lim = -10 | ) |
|
Increase the execution state by one.
- Parameters
-
lim | Required amount of "ticks" on the timer required to allow to continue execution. By default allows a little overflow (up to 10 ticks) |
- Returns
- false if timer requests interruption (timer <= limit)
bool CBot::CBotStack::IfStep |
( |
| ) |
|
Check if we are in step by step execution mode.
- Returns
- true if step by step, false otherwise
bool CBot::CBotStack::Execute |
( |
| ) |
|
Resumes execution of interrupted external call.
- Returns
- true if external call finished, false if interrupted again
void CBot::CBotStack::SetVar |
( |
CBotVar * |
var | ) |
|
Set the result variable.
- Todo:
- CBotStack takes over the ownership - use std::unique_ptr here
- Parameters
-
var | Result variable to set |
void CBot::CBotStack::SetCopyVar |
( |
CBotVar * |
var | ) |
|
Set the result variable to copy of given variable.
- Parameters
-
var | Variable to copy as result |
CBotVar * CBot::CBotStack::GetVar |
( |
| ) |
|
bool CBot::CBotStack::GetRetVar |
( |
bool |
bRet | ) |
|
- Todo:
- Document
Copies the result value from static m_retvar (m_var at a moment of SetBreak(3)) to this stack result
long CBot::CBotStack::GetVal |
( |
| ) |
|
Set program this stack level is in. Additionally marks this block as function block. Note: for public functions different stack levels might be in different programs.
- Todo:
- Refactor this two-in-one thing
- Parameters
-
CBotProgram * CBot::CBotStack::GetProgram |
( |
bool |
bFirst = false | ) |
|
Get program we are currently in.
- Parameters
-
bFirst | if true, get the main CBotProgram instance (the one that has the main function) |
void CBot::CBotStack::SetUserPtr |
( |
void * |
user | ) |
|
void * CBot::CBotStack::GetUserPtr |
( |
| ) |
|
Get user pointer for external calls.
- Returns
- User pointer for external execution calls
- See also
- SetUserPtr()
Get the block type this stack represents - instruction, code block or function.
- See also
- BlockVisibilityType enum
Execute a function call, either external or user-defined.
- Parameters
-
[in,out] | nIdent | Unique function identifier, if not found will be updated |
| token | Function name token |
| ppVar | Array of function arguments |
| rettype | Expected return type |
void CBot::CBotStack::RestoreCall |
( |
long & |
nIdent, |
|
|
CBotToken * |
token, |
|
|
CBotVar ** |
ppVar |
|
) |
| |
Restore a function call after the program state has been restored from a file.
- Parameters
-
[in,out] | nIdent | Unique function identifier, if not found will be updated |
| token | Function name token |
| ppVar | Array of function arguments |
void CBot::CBotStack::SetTimer |
( |
int |
n | ) |
|
|
static |
Set the maximum number of "timer ticks" (parts of instructions) to execute.
This setting gets applied on next call to Reset()
- Todo:
- Full documentation of the timer
int CBot::CBotStack::GetTimer |
( |
| ) |
|
|
static |
Get the current configured maximum number of "timer ticks" (parts of instructions) to execute.
void CBot::CBotStack::GetRunPos |
( |
std::string & |
functionName, |
|
|
int & |
start, |
|
|
int & |
end |
|
) |
| |
Get current position in the program.
- Parameters
-
[out] | functionName | Current function name, nullptr if not found |
[out] | start | Start position of currently executed token |
[out] | end | End position of currently executed token |
CBotVar * CBot::CBotStack::GetStackVars |
( |
std::string & |
functionName, |
|
|
int |
level |
|
) |
| |
Get local variables at the given stack level.
- Parameters
-
[out] | functionName | Name of instruction being executed at this level |
| level | 0 for current level, -1, -2, -3 etc. for next levels |
The documentation for this class was generated from the following files:
- /build/colobot-4LMcse/colobot-0.1.8/src/CBot/CBotStack.h
- /build/colobot-4LMcse/colobot-0.1.8/src/CBot/CBotStack.cpp