Skip to content

Commit

Permalink
-Change: Remove debug information in script.c when building in Release
Browse files Browse the repository at this point in the history
  • Loading branch information
miniupnp committed Dec 29, 2016
1 parent 74cef77 commit 91f7f72
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/script/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,18 @@ static void Script_Error(const char *error, ...)
* @param value The value to push.
* @note Use SCRIPT_PUSH(position) to use; do not use this function directly.
*/
#ifdef _DEBUG
void Script_Stack_Push(ScriptEngine *script, uint16 value, const char *filename, int lineno)
#else
void Script_Stack_Push(ScriptEngine *script, uint16 value)
#endif
{
if (script->stackPointer == 0) {
#ifdef _DEBUG
Script_Error("Stack Overflow at %s:%d", filename, lineno);
#else
Script_Error("Stack Overflow");
#endif
script->script = NULL;
return;
}
Expand All @@ -192,10 +200,18 @@ void Script_Stack_Push(ScriptEngine *script, uint16 value, const char *filename,
* @return The value that was on the stack.
* @note Use SCRIPT_POP(position) to use; do not use this function directly.
*/
#ifdef _DEBUG
uint16 Script_Stack_Pop(ScriptEngine *script, const char *filename, int lineno)
#else
uint16 Script_Stack_Pop(ScriptEngine *script)
#endif
{
if (script->stackPointer >= 15) {
#ifdef _DEBUG
Script_Error("Stack Overflow at %s:%d", filename, lineno);
#else
Script_Error("Stack Overflow");
#endif
script->script = NULL;
return 0;
}
Expand All @@ -209,12 +225,20 @@ uint16 Script_Stack_Pop(ScriptEngine *script, const char *filename, int lineno)
* @return The value that was on the stack.
* @note Use SCRIPT_PEEK(position) to use; do not use this function directly.
*/
#ifdef _DEBUG
uint16 Script_Stack_Peek(ScriptEngine *script, int position, const char *filename, int lineno)
#else
uint16 Script_Stack_Peek(ScriptEngine *script, int position)
#endif
{
assert(position > 0);

if (script->stackPointer >= 16 - position) {
#ifdef _DEBUG
Script_Error("Stack Overflow at %s:%d", filename, lineno);
#else
Script_Error("Stack Overflow");
#endif
script->script = NULL;
return 0;
}
Expand Down Expand Up @@ -360,7 +384,11 @@ bool Script_Run(ScriptEngine *script)

case SCRIPT_PUSH_LOCAL_VARIABLE: {
if (script->framePointer - parameter - 2 >= 15) {
#ifdef _DEBUG
Script_Error("Stack Overflow at %s:%d", __FILE__, __LINE__);
#else
Script_Error("Stack Overflow");
#endif
script->script = NULL;
return false;
}
Expand All @@ -371,7 +399,11 @@ bool Script_Run(ScriptEngine *script)

case SCRIPT_PUSH_PARAMETER: {
if (script->framePointer + parameter - 1 >= 15) {
#ifdef _DEBUG
Script_Error("Stack Overflow at %s:%d", __FILE__, __LINE__);
#else
Script_Error("Stack Overflow");
#endif
script->script = NULL;
return false;
}
Expand Down Expand Up @@ -405,7 +437,11 @@ bool Script_Run(ScriptEngine *script)

case SCRIPT_POP_LOCAL_VARIABLE: {
if (script->framePointer - parameter - 2 >= 15) {
#ifdef _DEBUG
Script_Error("Stack Overflow at %s:%d", __FILE__, __LINE__);
#else
Script_Error("Stack Overflow");
#endif
script->script = NULL;
return false;
}
Expand All @@ -416,7 +452,11 @@ bool Script_Run(ScriptEngine *script)

case SCRIPT_POP_PARAMETER: {
if (script->framePointer + parameter - 1 >= 15) {
#ifdef _DEBUG
Script_Error("Stack Overflow at %s:%d", __FILE__, __LINE__);
#else
Script_Error("Stack Overflow");
#endif
script->script = NULL;
return false;
}
Expand Down
12 changes: 12 additions & 0 deletions src/script/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ typedef struct ScriptInfo {
uint16 isAllocated; /*!< Memory has been allocated on load. */
} ScriptInfo;

#ifdef _DEBUG
#define STACK_PUSH(value) Script_Stack_Push(script, value, __FILE__, __LINE__)
#define STACK_POP() Script_Stack_Pop(script, __FILE__, __LINE__)
#define STACK_PEEK(position) Script_Stack_Peek(script, position, __FILE__, __LINE__)
#else
#define STACK_PUSH(value) Script_Stack_Push(script, value)
#define STACK_POP() Script_Stack_Pop(script)
#define STACK_PEEK(position) Script_Stack_Peek(script, position)
#endif

extern struct Object *g_scriptCurrentObject;
extern struct Structure *g_scriptCurrentStructure;
Expand All @@ -89,9 +95,15 @@ extern void Script_LoadAsSubroutine(ScriptEngine *script, uint8 typeID);
extern void Script_ClearInfo(ScriptInfo *scriptInfo);
extern uint16 Script_LoadFromFile(const char *filename, ScriptInfo *scriptInfo, const ScriptFunction *functions, uint8 *data);

#ifdef _DEBUG
extern void Script_Stack_Push(ScriptEngine *script, uint16 value, const char *filename, int lineno);
extern uint16 Script_Stack_Pop(ScriptEngine *script, const char *filename, int lineno);
extern uint16 Script_Stack_Peek(ScriptEngine *script, int position, const char *filename, int lineno);
#else
extern void Script_Stack_Push(ScriptEngine *script, uint16 value);
extern uint16 Script_Stack_Pop(ScriptEngine *script);
extern uint16 Script_Stack_Peek(ScriptEngine *script, int position);
#endif

/* General Script Functions */
extern uint16 Script_General_Delay(ScriptEngine *script);
Expand Down

0 comments on commit 91f7f72

Please sign in to comment.