2007-01-15 12:09:25 -08:00
/*
This file is part of Warzone 2100.
Copyright (C) 1999-2004 Eidos Interactive
Copyright (C) 2005-2007 Warzone Resurrection Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
2006-08-12 09:52:37 -07:00
%{
/*
* script.y
*
* The yacc grammar for the scipt files.
*/
#include "lib/framework/frame.h"
2006-09-23 11:38:12 -07:00
#include "lib/framework/frameresource.h"
2006-09-23 10:24:55 -07:00
#include "lib/script/interp.h"
#include "lib/script/parse.h"
#include "lib/script/script.h"
2006-08-12 09:52:37 -07:00
2006-11-16 06:30:29 -08:00
/* this will give us a more detailed error output */
#define YYERROR_VERBOSE TRUE
2007-01-02 12:12:14 -08:00
/* Script includes stack */
SDWORD scr_include_stack_ptr = 0;
char *pScrInputBuffer[MAX_SCR_INCLUDE_DEPTH];
2007-07-15 06:11:09 -07:00
/* Line counting stack */
UDWORD scrInclLine[MAX_SCR_INCLUDE_DEPTH];
2007-01-02 12:12:14 -08:00
/* Script defines stack */
SDWORD scr_num_macros = 0; /* Number of macros defined so far */
SDWORD scr_macro_stack_ptr = 0;
char *pScrMacroBuffer[MAX_SCR_MACRO_DEPTH];
2006-08-12 09:52:37 -07:00
extern int scr_lex(void);
/* Error return codes for code generation functions */
typedef enum _code_error
{
CE_OK, // No error
CE_MEMORY, // Out of memory
CE_PARSE // A parse error occured
} CODE_ERROR;
2006-08-19 06:26:11 -07:00
/* Turn off a couple of warnings that the yacc generated code gives */
2006-08-12 09:52:37 -07:00
/* Pointer to the compiled code */
static SCRIPT_CODE *psFinalProg=NULL;
/* Pointer to current block of compiled code */
static CODE_BLOCK *psCurrBlock=NULL;
/* Pointer to current block of conditional code */
static COND_BLOCK *psCondBlock=NULL;
/* Pointer to current block of object variable code */
static OBJVAR_BLOCK *psObjVarBlock=NULL;
/* Pointer to current block of compiled parameter code */
static PARAM_BLOCK *psCurrPBlock=NULL;
2007-01-02 12:12:14 -08:00
/* Any errors occured? */
static BOOL bError=FALSE;
2006-08-19 06:26:11 -07:00
//String support
//-----------------------------
char msg[MAXSTRLEN];
2006-08-25 13:38:27 -07:00
extern char STRSTACK[MAXSTACKLEN][MAXSTRLEN]; // just a simple string "stack"
2006-08-19 06:26:11 -07:00
extern UDWORD CURSTACKSTR; //Current string index
2006-08-12 09:52:37 -07:00
/* Pointer into the current code block */
2006-11-16 06:30:29 -08:00
static INTERP_VAL *ip;
2006-08-12 09:52:37 -07:00
/* Pointer to current parameter declaration block */
//static PARAM_DECL *psCurrParamDecl=NULL;
/* Pointer to current trigger subdeclaration */
static TRIGGER_DECL *psCurrTDecl=NULL;
/* Pointer to current variable subdeclaration */
static VAR_DECL *psCurrVDecl=NULL;
/* Pointer to the current variable identifier declaration */
static VAR_IDENT_DECL *psCurrVIdentDecl=NULL;
/* Pointer to the current array access block */
static ARRAY_BLOCK *psCurrArrayBlock=NULL;
/* Return code from code generation functions */
static CODE_ERROR codeRet;
/* The list of global variables */
static VAR_SYMBOL *psGlobalVars=NULL;
/* The list of global arrays */
static VAR_SYMBOL *psGlobalArrays=NULL;
/* The list of current local variables */
static VAR_SYMBOL *psLocalVars=NULL;
2006-08-19 06:26:11 -07:00
#define maxEventsLocalVars 1200
static VAR_SYMBOL *psLocalVarsB[maxEventsLocalVars]; /* local var storage */
static UDWORD numEventLocalVars[maxEventsLocalVars]; /* number of declard local vars for each event */
static VAR_SYMBOL *psLocalVarsTemp; /* temporary storage for local vars, before current event declaration is found */
EVENT_SYMBOL *psCurEvent = NULL; /* stores current event: for local var declaration */
2006-08-12 09:52:37 -07:00
/* The list of function definitions */
static FUNC_SYMBOL *psFunctions=NULL;
/* The current object variable context */
static INTERP_TYPE objVarContext = (INTERP_TYPE)0;
/* Control whether debug info is generated */
static BOOL genDebugInfo = TRUE;
/* Currently defined triggers */
static TRIGGER_SYMBOL *psTriggers;
static UDWORD numTriggers;
/* Currently defined events */
static EVENT_SYMBOL *psEvents;
static UDWORD numEvents;
/* This is true when local variables are being defined.
* (So local variables can have the same name as global ones)
*/
static BOOL localVariableDef=FALSE;
/* The identifier for the current script function being defined */
2006-11-03 13:35:50 -08:00
//static char *pCurrFuncIdent=NULL;
2006-08-12 09:52:37 -07:00
/* A temporary store for a line number - used when
* generating debugging info for functions, conditionals and loops.
*/
static UDWORD debugLine;
/* The table of user types */
TYPE_SYMBOL *asScrTypeTab;
/* The table of instinct function type definitions */
FUNC_SYMBOL *asScrInstinctTab;
/* The table of external variables and their access functions */
VAR_SYMBOL *asScrExternalTab;
/* The table of object variables and their access functions. */
VAR_SYMBOL *asScrObjectVarTab;
/* The table of constant variables */
CONST_SYMBOL *asScrConstantTab;
/* The table of callback triggers */
CALLBACK_SYMBOL *asScrCallbackTab;
2006-11-16 06:30:29 -08:00
/* Used for additional debug output */
void script_debug(const char *pFormat, ...);
2006-08-12 09:52:37 -07:00
/****************************************************************************************
*
* Code Block Macros
*
* These macros are used to allocate and free the different types of code
* block used within the compiler
*/
/* What the macro should do if it has an allocation error.
* This is different depending on whether the macro is used
* in a function, or in a rule body.
*
* This definition is used within the code generation functions
* and is then changed for use within a rule body.
*/
#define ALLOC_ERROR_ACTION return CE_MEMORY
2006-11-16 06:30:29 -08:00
/* Macro to allocate a program structure, size is in _bytes_ */
2006-08-12 09:52:37 -07:00
#define ALLOC_PROG(psProg, codeSize, pAICode, numGlobs, numArys, numTrigs, numEvnts) \
2007-04-15 03:43:05 -07:00
(psProg) = (SCRIPT_CODE *)malloc(sizeof(SCRIPT_CODE)); \
2006-08-12 09:52:37 -07:00
if ((psProg) == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
2007-04-15 03:43:05 -07:00
(psProg)->pCode = (INTERP_VAL *)malloc((codeSize) * sizeof(INTERP_VAL)); \
2006-08-12 09:52:37 -07:00
if ((psProg)->pCode == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
if (numGlobs > 0) \
{ \
2007-04-15 03:43:05 -07:00
(psProg)->pGlobals = (INTERP_TYPE *)malloc(sizeof(INTERP_TYPE) * (numGlobs)); \
2006-08-12 09:52:37 -07:00
if ((psProg)->pGlobals == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
} \
else \
{ \
(psProg)->pGlobals = NULL; \
} \
if (numArys > 0) \
{ \
2007-04-15 03:43:05 -07:00
(psProg)->psArrayInfo = (ARRAY_DATA *)malloc(sizeof(ARRAY_DATA) * (numArys)); \
2006-08-12 09:52:37 -07:00
if ((psProg)->psArrayInfo == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
} \
else \
{ \
(psProg)->psArrayInfo = NULL; \
} \
(psProg)->numArrays = (UWORD)(numArys); \
if ((numTrigs) > 0) \
{ \
2007-04-15 03:43:05 -07:00
(psProg)->pTriggerTab = malloc(sizeof(UWORD) * ((numTrigs) + 1)); \
2006-08-12 09:52:37 -07:00
if ((psProg)->pTriggerTab == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
2007-04-15 03:43:05 -07:00
(psProg)->psTriggerData = malloc(sizeof(TRIGGER_DATA) * (numTrigs)); \
2006-08-12 09:52:37 -07:00
if ((psProg)->psTriggerData == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
} \
else \
{ \
(psProg)->pTriggerTab = NULL; \
(psProg)->psTriggerData = NULL; \
} \
2007-04-15 03:43:05 -07:00
(psProg)->pEventTab = malloc(sizeof(UWORD) * ((numEvnts) + 1)); \
2006-08-12 09:52:37 -07:00
if ((psProg)->pEventTab == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
2007-04-15 03:43:05 -07:00
(psProg)->pEventLinks = malloc(sizeof(SWORD) * (numEvnts)); \
2006-08-12 09:52:37 -07:00
if ((psProg)->pEventLinks == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
(psProg)->numGlobals = (UWORD)(numGlobs); \
(psProg)->numTriggers = (UWORD)(numTriggers); \
(psProg)->numEvents = (UWORD)(numEvnts); \
2006-11-16 06:30:29 -08:00
(psProg)->size = (codeSize) * sizeof(INTERP_VAL);
2006-08-12 09:52:37 -07:00
2006-11-16 06:30:29 -08:00
/* Macro to allocate a code block, blockSize - number of INTERP_VALs we need*/
#define ALLOC_BLOCK(psBlock, num) \
2007-04-15 03:43:05 -07:00
(psBlock) = (CODE_BLOCK *)malloc(sizeof(CODE_BLOCK)); \
2006-08-12 09:52:37 -07:00
if ((psBlock) == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
2007-04-15 03:43:05 -07:00
(psBlock)->pCode = (INTERP_VAL *)malloc((num) * sizeof(INTERP_VAL)); \
2006-08-12 09:52:37 -07:00
if ((psBlock)->pCode == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2007-04-15 03:43:05 -07:00
free((psBlock)); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
2007-02-14 14:12:48 -08:00
(psBlock)->size = (num); \
(psBlock)->debugEntries = 0
2006-08-12 09:52:37 -07:00
/* Macro to free a code block */
#define FREE_BLOCK(psBlock) \
2007-04-15 03:43:05 -07:00
free((psBlock)->pCode); \
free((psBlock))
2006-08-12 09:52:37 -07:00
/* Macro to allocate a parameter block */
2006-11-16 06:30:29 -08:00
#define ALLOC_PBLOCK(psBlock, num, paramSize) \
2007-04-15 03:43:05 -07:00
(psBlock) = (PARAM_BLOCK *)malloc(sizeof(PARAM_BLOCK)); \
2006-08-12 09:52:37 -07:00
if ((psBlock) == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
2007-04-15 03:43:05 -07:00
(psBlock)->pCode = (INTERP_VAL *)malloc((num) * sizeof(INTERP_VAL)); \
2006-08-12 09:52:37 -07:00
if ((psBlock)->pCode == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2007-04-15 03:43:05 -07:00
free((psBlock)); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
2007-04-15 03:43:05 -07:00
(psBlock)->aParams = (INTERP_TYPE *)malloc(sizeof(INTERP_TYPE) * (paramSize)); \
2006-08-12 09:52:37 -07:00
if ((psBlock)->aParams == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2007-04-15 03:43:05 -07:00
free((psBlock)->pCode); \
free((psBlock)); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
2006-11-16 06:30:29 -08:00
(psBlock)->size = (num); \
2006-08-12 09:52:37 -07:00
(psBlock)->numParams = (paramSize)
/* Macro to free a parameter block */
#define FREE_PBLOCK(psBlock) \
2007-04-15 03:43:05 -07:00
free((psBlock)->pCode); \
free((psBlock)->aParams); \
free((psBlock))
2006-08-12 09:52:37 -07:00
/* Macro to allocate a parameter declaration block */
#define ALLOC_PARAMDECL(psPDecl, num) \
2007-04-15 03:43:05 -07:00
(psPDecl) = (PARAM_DECL *)malloc(sizeof(PARAM_DECL)); \
2006-08-12 09:52:37 -07:00
if ((psPDecl) == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
2007-04-15 03:43:05 -07:00
(psPDecl)->aParams = (INTERP_TYPE *)malloc(sizeof(INTERP_TYPE) * (num)); \
2006-08-12 09:52:37 -07:00
if ((psPDecl)->aParams == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
(psPDecl)->numParams = (num)
/* Macro to free a parameter declaration block */
#define FREE_PARAMDECL(psPDecl) \
2007-04-15 03:43:05 -07:00
free((psPDecl)->aParams); \
free((psPDecl))
2006-08-12 09:52:37 -07:00
/* Macro to allocate a conditional block */
2006-11-16 06:30:29 -08:00
#define ALLOC_CONDBLOCK(psCB, num, numBlocks) \
2007-04-15 03:43:05 -07:00
(psCB) = (COND_BLOCK *)malloc(sizeof(COND_BLOCK)); \
2006-08-12 09:52:37 -07:00
if ((psCB) == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
2007-04-15 03:43:05 -07:00
(psCB)->aOffsets = (UDWORD *)malloc(sizeof(SDWORD) * (num)); \
2006-08-12 09:52:37 -07:00
if ((psCB)->aOffsets == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
2007-04-15 03:43:05 -07:00
(psCB)->pCode = (INTERP_VAL *)malloc((numBlocks) * sizeof(INTERP_VAL)); \
2006-08-12 09:52:37 -07:00
if ((psCB)->pCode == NULL) \
{ \
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Out of memory"); \
2006-08-12 09:52:37 -07:00
ALLOC_ERROR_ACTION; \
} \
2006-11-16 06:30:29 -08:00
(psCB)->size = (numBlocks); \
2006-08-12 09:52:37 -07:00
(psCB)->numOffsets = (num)
/* Macro to free a conditional block */
#define FREE_CONDBLOCK(psCB) \
2007-04-15 03:43:05 -07:00
free((psCB)->aOffsets); \
free((psCB)->pCode); \
free(psCB)
2006-08-12 09:52:37 -07:00
/* Macro to free a code block */
#define FREE_USERBLOCK(psBlock) \
2007-04-15 03:43:05 -07:00
free((psBlock)->pCode); \
free((psBlock))
2006-08-12 09:52:37 -07:00
/* Macro to allocate an object variable block */
#define ALLOC_OBJVARBLOCK(psOV, blockSize, psVar) \
2007-04-15 03:43:05 -07:00
(psOV) = (OBJVAR_BLOCK *)malloc(sizeof(OBJVAR_BLOCK)); \
2006-08-12 09:52:37 -07:00
if ((psOV) == NULL) \
{ \
scr_error("Out of memory"); \
ALLOC_ERROR_ACTION; \
} \
2007-04-15 03:43:05 -07:00
(psOV)->pCode = (INTERP_VAL *)malloc((blockSize) * sizeof(INTERP_VAL)); \
2006-08-12 09:52:37 -07:00
if ((psOV)->pCode == NULL) \
{ \
scr_error("Out of memory"); \
ALLOC_ERROR_ACTION; \
} \
(psOV)->size = (blockSize); \
(psOV)->psObjVar = (psVar)
/* Macro to free an object variable block */
#define FREE_OBJVARBLOCK(psOV) \
2007-04-15 03:43:05 -07:00
free((psOV)->pCode); \
free(psOV)
2006-08-12 09:52:37 -07:00
/* Macro to allocate an array variable block */
#define ALLOC_ARRAYBLOCK(psAV, blockSize, psVar) \
2007-04-15 03:43:05 -07:00
(psAV) = (ARRAY_BLOCK *)malloc(sizeof(ARRAY_BLOCK)); \
2006-08-12 09:52:37 -07:00
if ((psAV) == NULL) \
{ \
scr_error("Out of memory"); \
ALLOC_ERROR_ACTION; \
} \
2007-04-15 03:43:05 -07:00
(psAV)->pCode = (INTERP_VAL *)malloc((blockSize) * sizeof(INTERP_VAL)); \
2006-08-12 09:52:37 -07:00
if ((psAV)->pCode == NULL) \
{ \
scr_error("Out of memory"); \
ALLOC_ERROR_ACTION; \
} \
(psAV)->size = (blockSize); \
(psAV)->dimensions = 1; \
(psAV)->psArrayVar = (psVar)
/* Macro to free an object variable block */
#define FREE_ARRAYBLOCK(psAV) \
2007-04-15 03:43:05 -07:00
free((psAV)->pCode); \
free(psAV)
2006-08-12 09:52:37 -07:00
/* Allocate a trigger subdecl */
#define ALLOC_TSUBDECL(psTSub, blockType, blockSize, blockTime) \
2007-04-15 03:43:05 -07:00
(psTSub) = malloc(sizeof(TRIGGER_DECL)); \
2006-08-12 09:52:37 -07:00
if ((psTSub) == NULL) \
{ \
scr_error("Out of memory"); \
ALLOC_ERROR_ACTION; \
} \
(psTSub)->type = (blockType); \
(psTSub)->time = (blockTime); \
if ((blockSize) > 0) \
{ \
2007-04-15 03:43:05 -07:00
(psTSub)->pCode = (INTERP_VAL *)malloc((blockSize) * sizeof(INTERP_VAL)); \
2006-08-12 09:52:37 -07:00
if ((psTSub)->pCode == NULL) \
{ \
scr_error("Out of memory"); \
ALLOC_ERROR_ACTION; \
} \
(psTSub)->size = (blockSize); \
} \
else \
{ \
(psTSub)->pCode = NULL; \
(psTSub)->size = 0; \
}
/* Free a trigger subdecl */
#define FREE_TSUBDECL(psTSub) \
if ((psTSub)->pCode) \
{ \
2007-04-15 03:43:05 -07:00
free((psTSub)->pCode); \
2006-08-12 09:52:37 -07:00
} \
2007-04-15 03:43:05 -07:00
free(psTSub)
2006-08-12 09:52:37 -07:00
/* Allocate a variable declaration block */
#define ALLOC_VARDECL(psDcl) \
2007-04-15 03:43:05 -07:00
(psDcl)=malloc(sizeof(VAR_DECL)); \
2006-08-12 09:52:37 -07:00
if ((psDcl) == NULL) \
{ \
scr_error("Out of memory"); \
ALLOC_ERROR_ACTION; \
}
/* Free a variable declaration block */
#define FREE_VARDECL(psDcl) \
2007-04-15 03:43:05 -07:00
free(psDcl)
2006-08-12 09:52:37 -07:00
/* Allocate a variable declaration block */
2007-08-14 12:24:29 -07:00
static inline CODE_ERROR do_ALLOC_VARIDENTDECL(VAR_IDENT_DECL** psDcl, const char* ident, unsigned int dim)
{
// Allocate memory
*psDcl = malloc(sizeof(VAR_IDENT_DECL));
if (*psDcl == NULL)
{
scr_error("Out of memory");
ALLOC_ERROR_ACTION;
}
// Copy over the "ident" string (if it's there)
if (ident != NULL)
{
(*psDcl)->pIdent = strdup(ident);
if ((*psDcl)->pIdent == NULL)
{
scr_error("Out of memory");
ALLOC_ERROR_ACTION;
}
}
else
{
(*psDcl)->pIdent = NULL;
}
(*psDcl)->dimensions = dim;
return CE_OK;
}
2006-08-12 09:52:37 -07:00
#define ALLOC_VARIDENTDECL(psDcl, ident, dim) \
2007-08-14 12:24:29 -07:00
{ \
CODE_ERROR err = do_ALLOC_VARIDENTDECL(&psDcl, ident, dim); \
if (err != CE_OK) \
return err; \
}
2006-08-12 09:52:37 -07:00
/* Free a variable declaration block */
#define FREE_VARIDENTDECL(psDcl) \
2007-04-15 03:43:05 -07:00
free(psDcl)
2006-08-12 09:52:37 -07:00
/****************************************************************************************
*
* Code block manipulation macros.
*
* These are used to copy chunks of code from one block to another
* or to insert opcodes or other values into a code block.
* All the macros use the ip parameter. This is a pointer into the code
* block that is incremented by the macro. This ensures that it always points
* to the next free space in the code block.
*/
2006-11-16 06:30:29 -08:00
/* Macro to store an opcode in a code block, opcode type is '-1' */
2006-08-12 09:52:37 -07:00
#define PUT_OPCODE(ip, opcode) \
2006-11-16 06:30:29 -08:00
(ip)->type = VAL_OPCODE; \
(ip)->v.ival = (opcode) << OPCODE_SHIFT; \
(ip)++
2006-08-12 09:52:37 -07:00
/* Macro to put a packed opcode in a code block */
#define PUT_PKOPCODE(ip, opcode, data) \
2006-11-16 06:30:29 -08:00
(ip)->type = VAL_PKOPCODE; \
(ip)->v.ival = ((SDWORD)(data)) & OPCODE_DATAMASK; \
(ip)->v.ival = (((SDWORD)(opcode)) << OPCODE_SHIFT) | ((ip)->v.ival); \
(ip)++
/* Special macro for floats, could be a bit tricky */
#define PUT_DATA_FLOAT(ip, data) \
ip->type = VAL_FLOAT; \
ip->v.fval = (float)(data); \
ip++
2006-08-12 09:52:37 -07:00
/* Macros to store a value in a code block */
2006-11-16 06:30:29 -08:00
#define PUT_DATA_BOOL(ip, value) \
(ip)->type = VAL_BOOL; \
(ip)->v.bval = (BOOL)(value); \
(ip)++
2006-11-26 05:45:04 -08:00
2006-11-16 06:30:29 -08:00
#define PUT_DATA_INT(ip, value) \
(ip)->type = VAL_INT; \
2006-12-06 10:57:17 -08:00
(ip)->v.ival = (SDWORD)(value); \
2006-11-16 06:30:29 -08:00
(ip)++
#define PUT_DATA_STRING(ip, value) \
(ip)->type = VAL_STRING; \
(ip)->v.sval = (char *)(value); \
(ip)++
#define PUT_OBJECT_CONST(ip, value, constType) \
(ip)->type = (constType); \
(ip)->v.oval = (value); \
(ip)++
2006-08-12 09:52:37 -07:00
#define PUT_STRING(ip, value) \
((INTERP_VAL *)(ip))->type = VAL_STRING; \
((INTERP_VAL *)(ip))->v.sval = (value); \
((INTERP_VAL *)(ip)) += 1
2006-11-16 06:30:29 -08:00
/* Macro to store an external function index in a code block */
#define PUT_FUNC_EXTERN(ip, func) \
(ip)->type = VAL_FUNC_EXTERN; \
(ip)->v.pFuncExtern = (SCRIPT_FUNC)func; \
(ip)++
/* Macro to store an internal (in-script, actually an event) function index in a code block */
#define PUT_EVENT(ip, func) \
(ip)->type = VAL_EVENT; \
(ip)->v.ival = (SDWORD)func; \
(ip)++
/* Macro to store trigger */
#define PUT_TRIGGER(ip, func) \
(ip)->type = VAL_TRIGGER; \
(ip)->v.ival = (SDWORD)func; \
(ip)++
2006-08-12 09:52:37 -07:00
/* Macro to store a function pointer in a code block */
#define PUT_VARFUNC(ip, func) \
2006-11-16 06:30:29 -08:00
(ip)->type = VAL_OBJ_GETSET; \
(ip)->v.pObjGetSet = (SCRIPT_VARFUNC)func; \
(ip)++
2006-08-12 09:52:37 -07:00
2006-11-16 06:30:29 -08:00
/* Macro to store a variable index number in a code block - NOT USED */
2006-08-12 09:52:37 -07:00
#define PUT_INDEX(ip, index) \
2006-11-16 06:30:29 -08:00
(ip)->type = -1; \
(ip)->v.ival = (SDWORD)(index); \
(ip)++
2006-08-12 09:52:37 -07:00
/* Macro to copy a code block into another code block */
2006-11-16 06:30:29 -08:00
#define PUT_BLOCK(ip, psOldBlock) \
memcpy(ip, (psOldBlock)->pCode, (psOldBlock)->size * sizeof(INTERP_VAL)); \
(ip) = (INTERP_VAL *)( (ip) + (psOldBlock)->size)
2006-08-12 09:52:37 -07:00
/***********************************************************************************
*
* Debugging information macros
*
* These macros are only used to generate debugging information for scripts.
*/
/* Macro to allocate debugging info for a CODE_BLOCK or a COND_BLOCK */
#define ALLOC_DEBUG(psBlock, num) \
if (genDebugInfo) \
{ \
2007-04-15 03:43:05 -07:00
(psBlock)->psDebug = (SCRIPT_DEBUG *)malloc(sizeof(SCRIPT_DEBUG) * (num)); \
2006-08-12 09:52:37 -07:00
if ((psBlock)->psDebug == NULL) \
{ \
scr_error("Out of memory"); \
ALLOC_ERROR_ACTION; \
} \
memset((psBlock)->psDebug, 0, sizeof(SCRIPT_DEBUG) * (num));\
(psBlock)->debugEntries = (UWORD)(num); \
} \
else \
{ \
(psBlock)->psDebug = NULL; \
(psBlock)->debugEntries = 0; \
}
/* Macro to free debugging info */
#define FREE_DEBUG(psBlock) \
if (genDebugInfo) \
2007-04-15 03:43:05 -07:00
free((psBlock)->psDebug)
2006-08-12 09:52:37 -07:00
/* Macro to copy the debugging information from one block to another */
#define PUT_DEBUG(psFinal, psBlock) \
if (genDebugInfo) \
{ \
memcpy((psFinal)->psDebug, (psBlock)->psDebug, \
sizeof(SCRIPT_DEBUG) * (psBlock)->debugEntries); \
(psFinal)->debugEntries = (psBlock)->debugEntries; \
}
/* Macro to combine the debugging information in two blocks into a third block */
static UDWORD _dbEntry;
static SCRIPT_DEBUG *_psCurr;
#define COMBINE_DEBUG(psFinal, psBlock1, psBlock2) \
if (genDebugInfo) \
{ \
memcpy((psFinal)->psDebug, (psBlock1)->psDebug, \
sizeof(SCRIPT_DEBUG) * (psBlock1)->debugEntries); \
_baseOffset = (psBlock1)->size / sizeof(UDWORD); \
for(_dbEntry = 0; _dbEntry < (psBlock2)->debugEntries; _dbEntry++) \
{ \
_psCurr = (psFinal)->psDebug + (psBlock1)->debugEntries + _dbEntry; \
_psCurr->line = (psBlock2)->psDebug[_dbEntry].line; \
_psCurr->offset = (psBlock2)->psDebug[_dbEntry].offset + _baseOffset; \
} \
(psFinal)->debugEntries = (psBlock1)->debugEntries + (psBlock2)->debugEntries; \
}
/* Macro to append some debugging information onto a block, given the instruction
offset of the debugging information already in the destination block */
#define APPEND_DEBUG(psFinal, baseOffset, psBlock) \
if (genDebugInfo) \
{ \
for(_dbEntry = 0; _dbEntry < (psBlock)->debugEntries; _dbEntry++) \
{ \
_psCurr = (psFinal)->psDebug + (psFinal)->debugEntries + _dbEntry; \
_psCurr->line = (psBlock)->psDebug[_dbEntry].line; \
_psCurr->offset = (psBlock)->psDebug[_dbEntry].offset + (baseOffset); \
} \
(psFinal)->debugEntries = (UWORD)((psFinal)->debugEntries + (psBlock)->debugEntries); \
}
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
/* Macro to store a label in the debug info */
#define DEBUG_LABEL(psBlock, offset, pString) \
if (genDebugInfo) \
{ \
2007-04-15 03:43:05 -07:00
(psBlock)->psDebug[offset].pLabel = malloc(strlen(pString)+1); \
2006-08-12 09:52:37 -07:00
if (!(psBlock)->psDebug[offset].pLabel) \
{ \
scr_error("Out of memory"); \
ALLOC_ERROR_ACTION; \
} \
strcpy((psBlock)->psDebug[offset].pLabel, pString); \
}
/***************************************************************************************
*
* Code generation functions
*
* These functions are used within rule bodies to generate code.
*/
/* Macro to deal with the errors returned by code generation functions.
* Used within the rule body.
*/
#define CHECK_CODE_ERROR(error) \
if ((error) == CE_MEMORY) \
{ \
YYABORT; \
} \
else if ((error) == CE_PARSE) \
{ \
YYERROR; \
2006-08-22 07:28:49 -07:00
}
2006-11-16 06:30:29 -08:00
void script_debug(const char *pFormat, ...)
{
char buffer[500];
va_list pArgs;
va_start(pArgs, pFormat);
(void)vsprintf(buffer, pFormat, pArgs);
2006-08-12 09:52:37 -07:00
2006-11-16 06:30:29 -08:00
debug(LOG_SCRIPT, buffer);
}
2006-08-12 09:52:37 -07:00
/* Generate the code for a function call, checking the parameter
* types match.
*/
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeFunction(FUNC_SYMBOL *psFSymbol, // The function being called
2006-08-12 09:52:37 -07:00
PARAM_BLOCK *psPBlock, // The functions parameters
BOOL expContext, // Whether the function is being
// called in an expression context
CODE_BLOCK **ppsCBlock) // The generated code block
{
2006-11-16 06:30:29 -08:00
UDWORD size, i;
INTERP_VAL *ip;
2006-08-12 09:52:37 -07:00
BOOL typeError = FALSE;
2006-11-03 13:35:50 -08:00
char aErrorString[255];
2006-11-16 06:30:29 -08:00
INTERP_TYPE type1,type2;
2006-08-12 09:52:37 -07:00
2006-08-23 05:58:48 -07:00
ASSERT( psFSymbol != NULL, "ais_CodeFunction: Invalid function symbol pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psPBlock != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeFunction: Invalid param block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( (psPBlock->size == 0) || psPBlock->pCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeFunction: Invalid parameter code pointer" );
ASSERT( ppsCBlock != NULL,
"scriptCodeFunction: Invalid generated code block pointer" );
2006-08-12 09:52:37 -07:00
/* Check the parameter types match what the function needs */
for(i=0; (i<psFSymbol->numParams) && (i<psPBlock->numParams); i++)
{
/* if (psFSymbol->aParams[i] != VAL_VOID &&
psFSymbol->aParams[i] != psPBlock->aParams[i])*/
2006-08-19 06:26:11 -07:00
//TODO: string support
2006-09-19 09:07:06 -07:00
if(psFSymbol->aParams[i] != VAL_STRING) // string - allow mixed types if string is parameter type //TODO: tweak this
2006-08-12 09:52:37 -07:00
{
2006-11-16 06:30:29 -08:00
type1 = psFSymbol->aParams[i];
type2 = psPBlock->aParams[i];
if (!interpCheckEquiv(type1, type2))
2006-08-19 06:26:11 -07:00
{
2006-11-16 06:30:29 -08:00
debug(LOG_ERROR, "scriptCodeFunction: Type mismatch for paramter %d (%d/%d)", i, psFSymbol->aParams[i], psPBlock->aParams[i]);
2006-08-19 06:26:11 -07:00
sprintf(aErrorString, "Type mismatch for paramter %d", i);
scr_error(aErrorString);
typeError = TRUE;
}
}
2006-08-21 02:34:42 -07:00
//else
//{
// debug(LOG_SCRIPT, "scriptCodeFunction: %s takes string as parameter %d (provided: %d)", psFSymbol->pIdent, i, psPBlock->aParams[i]);
//}
2006-08-12 09:52:37 -07:00
}
/* Check the number of parameters matches that expected */
if (psFSymbol->numParams != psPBlock->numParams)
{
sprintf(aErrorString, "Expected %d parameters", psFSymbol->numParams);
scr_error(aErrorString);
*ppsCBlock = NULL;
return CE_PARSE;
}
2006-11-16 06:30:29 -08:00
2006-08-12 09:52:37 -07:00
if (typeError)
{
/* Report the error here so all the */
/* type mismatches are reported */
*ppsCBlock = NULL;
return CE_PARSE;
}
2006-11-16 06:30:29 -08:00
//size = psPBlock->size + sizeof(OPCODE) + sizeof(SCRIPT_FUNC);
size = psPBlock->size + 1 + 1; //size + opcode + sizeof(SCRIPT_FUNC)
2006-11-26 05:45:04 -08:00
2006-08-12 09:52:37 -07:00
if (!expContext && (psFSymbol->type != VAL_VOID))
{
2006-11-16 06:30:29 -08:00
//size += sizeof(OPCODE);
size += 1; //+ 1 additional opcode to pop value if needed
2006-08-12 09:52:37 -07:00
}
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
ALLOC_BLOCK(*ppsCBlock, size);
ip = (*ppsCBlock)->pCode;
(*ppsCBlock)->type = psFSymbol->type;
/* Copy in the code for the parameters */
PUT_BLOCK(ip, psPBlock);
FREE_PBLOCK(psPBlock);
/* Make the function call */
if (psFSymbol->script)
{
/* function defined in this script */
// PUT_OPCODE(ip, OP_FUNC);
// PUT_SCRIPTFUNC(ip, psFSymbol);
2006-11-16 06:30:29 -08:00
ASSERT(FALSE, "wrong function type call");
2006-08-12 09:52:37 -07:00
}
else
{
/* call an instinct function */
PUT_OPCODE(ip, OP_CALL);
2006-11-16 06:30:29 -08:00
PUT_FUNC_EXTERN(ip, psFSymbol->pFunc);
2006-08-12 09:52:37 -07:00
}
if (!expContext && (psFSymbol->type != VAL_VOID))
{
/* Clear the return value from the stack */
PUT_OPCODE(ip, OP_POP);
}
return CE_OK;
}
2006-08-19 06:26:11 -07:00
/* Function call: Check the parameter types match, assumes param count matched */
2006-09-16 10:41:40 -07:00
static UDWORD checkFuncParamTypes(EVENT_SYMBOL *psFSymbol, // The function being called
2006-08-19 06:26:11 -07:00
PARAM_BLOCK *psPBlock) // The generated code block
{
2006-09-26 11:25:36 -07:00
UDWORD i;
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT,"checkFuncParamTypes");
2006-08-19 06:26:11 -07:00
/* Check the parameter types match what the function needs */
for(i=0; (i<psFSymbol->numParams) && (i<psPBlock->numParams); i++)
{
//TODO: string support
//if(psFSymbol->aParams[i] != VAL_STRING) // string - allow mixed types if string is parameter type
//{
if (!interpCheckEquiv(psFSymbol->aParams[i], psPBlock->aParams[i]))
{
debug(LOG_ERROR, "checkFuncParamTypes: Type mismatch for paramter %d ('1' based) in Function '%s' (provided type: %d, expected: %d)", (i+1), psFSymbol->pIdent, psPBlock->aParams[i], psFSymbol->aParams[i]);
2006-12-02 15:27:00 -08:00
scr_error("Parameter type mismatch");
2006-08-19 06:26:11 -07:00
return i+1;
}
//}
}
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT,"END checkFuncParamTypes");
2006-08-19 06:26:11 -07:00
return 0; //all ok
}
2006-08-22 07:28:49 -07:00
2007-02-19 06:10:44 -08:00
#ifdef UNUSED
2006-08-19 06:26:11 -07:00
/*
* function call
*/
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeCallFunction(FUNC_SYMBOL *psFSymbol, // The function being called
2006-08-19 06:26:11 -07:00
PARAM_BLOCK *psPBlock, // The functions parameters
CODE_BLOCK **ppsCBlock) // The generated code block
{
2006-11-16 06:30:29 -08:00
UDWORD size;
INTERP_VAL *ip;
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptCodeCallFunction");
2006-08-19 06:26:11 -07:00
2006-11-16 06:30:29 -08:00
ASSERT( psFSymbol != NULL, "scriptCodeCallFunction: Invalid function symbol pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psPBlock != NULL,
2006-11-16 06:30:29 -08:00
"scriptCodeCallFunction: Invalid param block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( (psPBlock->size == 0) || psPBlock->pCode != NULL,
2006-11-16 06:30:29 -08:00
"scriptCodeCallFunction: Invalid parameter code pointer" );
2006-08-23 05:58:48 -07:00
ASSERT( ppsCBlock != NULL,
2006-11-16 06:30:29 -08:00
"scriptCodeCallFunction: Invalid generated code block pointer" );
2006-08-19 06:26:11 -07:00
2006-11-16 06:30:29 -08:00
//size = psPBlock->size + sizeof(OPCODE) + sizeof(SCRIPT_FUNC);
size = psPBlock->size + 1 + 1; //size + opcode + SCRIPT_FUNC
2006-08-22 07:28:49 -07:00
2006-08-19 06:26:11 -07:00
ALLOC_BLOCK(*ppsCBlock, size);
ip = (*ppsCBlock)->pCode;
(*ppsCBlock)->type = psFSymbol->type;
/* Copy in the code for the parameters */
PUT_BLOCK(ip, psPBlock);
FREE_PBLOCK(psPBlock);
/* Make the function call */
PUT_OPCODE(ip, OP_CALL);
2006-11-16 06:30:29 -08:00
PUT_FUNC_EXTERN(ip, psFSymbol->pFunc);
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END scriptCodeCallFunction");
2006-08-19 06:26:11 -07:00
return CE_OK;
}
2007-02-19 06:10:44 -08:00
#endif
2006-08-19 06:26:11 -07:00
2006-08-12 09:52:37 -07:00
/* Generate the code for a parameter callback, checking the parameter
* types match.
*/
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeCallbackParams(
2006-08-12 09:52:37 -07:00
CALLBACK_SYMBOL *psCBSymbol, // The callback being called
PARAM_BLOCK *psPBlock, // The callbacks parameters
TRIGGER_DECL **ppsTDecl) // The generated code block
{
2006-11-16 06:30:29 -08:00
UDWORD size, i;
INTERP_VAL *ip;
2006-08-12 09:52:37 -07:00
BOOL typeError = FALSE;
2006-11-03 13:35:50 -08:00
char aErrorString[255];
2006-08-12 09:52:37 -07:00
2007-04-03 06:20:41 -07:00
ASSERT( psPBlock != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeCallbackParams: Invalid param block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( (psPBlock->size == 0) || psPBlock->pCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeCallbackParams: Invalid parameter code pointer" );
ASSERT( ppsTDecl != NULL,
"scriptCodeCallbackParams: Invalid generated code block pointer" );
ASSERT( psCBSymbol->pFunc != NULL,
"scriptCodeCallbackParams: Expected function pointer for callback symbol" );
2006-08-12 09:52:37 -07:00
/* Check the parameter types match what the function needs */
for(i=0; (i<psCBSymbol->numParams) && (i<psPBlock->numParams); i++)
{
if (!interpCheckEquiv(psCBSymbol->aParams[i], psPBlock->aParams[i]))
{
sprintf(aErrorString, "Type mismatch for paramter %d", i);
scr_error(aErrorString);
typeError = TRUE;
}
}
/* Check the number of parameters matches that expected */
if (psPBlock->numParams == 0)
{
scr_error("Expected parameters to callback");
*ppsTDecl = NULL;
return CE_PARSE;
}
else if (psCBSymbol->numParams != psPBlock->numParams)
{
sprintf(aErrorString, "Expected %d parameters", psCBSymbol->numParams);
scr_error(aErrorString);
*ppsTDecl = NULL;
return CE_PARSE;
}
if (typeError)
{
/* Return the error here so all the */
/* type mismatches are reported */
*ppsTDecl = NULL;
return CE_PARSE;
}
2006-11-16 06:30:29 -08:00
//size = psPBlock->size + sizeof(OPCODE) + sizeof(SCRIPT_FUNC);
size = psPBlock->size + 1 + 1; //size + opcode + SCRIPT_FUNC
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
ALLOC_TSUBDECL(*ppsTDecl, psCBSymbol->type, size, 0);
ip = (*ppsTDecl)->pCode;
/* Copy in the code for the parameters */
PUT_BLOCK(ip, psPBlock);
FREE_PBLOCK(psPBlock);
/* call the instinct function */
PUT_OPCODE(ip, OP_CALL);
2006-11-16 06:30:29 -08:00
PUT_FUNC_EXTERN(ip, psCBSymbol->pFunc);
2006-08-12 09:52:37 -07:00
return CE_OK;
}
/* Generate code for assigning a value to a variable */
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeAssignment(VAR_SYMBOL *psVariable, // The variable to assign to
2006-08-12 09:52:37 -07:00
CODE_BLOCK *psValue, // The code for the value to
// assign
CODE_BLOCK **ppsBlock) // Generated code
{
SDWORD size;
2006-08-23 05:58:48 -07:00
ASSERT( psVariable != NULL,
"scriptCodeAssignment: Invalid variable symbol pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psValue != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeAssignment: Invalid value code block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psValue->pCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeAssignment: Invalid value code pointer" );
ASSERT( ppsBlock != NULL,
"scriptCodeAssignment: Invalid generated code block pointer" );
2006-08-12 09:52:37 -07:00
2006-11-16 06:30:29 -08:00
//size = psValue->size + sizeof(OPCODE);
size = psValue->size + 1; //1 - for assignment opcode
2006-11-26 05:45:04 -08:00
2006-08-12 09:52:37 -07:00
if (psVariable->storage == ST_EXTERN)
{
// Check there is a set function
if (psVariable->set == NULL)
{
scr_error("No set function for external variable");
return CE_PARSE;
}
2006-11-16 06:30:29 -08:00
//size += sizeof(SCRIPT_VARFUNC);
size += 1; //1 - for set func pointer
2006-08-12 09:52:37 -07:00
}
ALLOC_BLOCK(*ppsBlock, size);
ip = (*ppsBlock)->pCode;
/* Copy in the code for the expression */
PUT_BLOCK(ip, psValue);
FREE_BLOCK(psValue);
/* Code to get the value from the stack into the variable */
switch (psVariable->storage)
{
case ST_PUBLIC:
case ST_PRIVATE:
PUT_PKOPCODE(ip, OP_POPGLOBAL, psVariable->index);
break;
2006-08-19 06:26:11 -07:00
case ST_LOCAL:
2006-08-15 11:38:51 -07:00
PUT_PKOPCODE(ip, OP_POPLOCAL, psVariable->index);
break;
2006-08-12 09:52:37 -07:00
case ST_EXTERN:
PUT_PKOPCODE(ip, OP_VARCALL, psVariable->index);
PUT_VARFUNC(ip, psVariable->set);
break;
case ST_OBJECT:
scr_error("Cannot use member variables in this context");
return CE_PARSE;
break;
default:
scr_error("Unknown storage type");
return CE_PARSE;
break;
}
return CE_OK;
}
/* Generate code for assigning a value to an object variable */
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeObjAssignment(OBJVAR_BLOCK *psVariable,// The variable to assign to
2006-08-12 09:52:37 -07:00
CODE_BLOCK *psValue, // The code for the value to
// assign
CODE_BLOCK **ppsBlock) // Generated code
{
2007-04-03 06:20:41 -07:00
ASSERT( psVariable != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjAssignment: Invalid object variable block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psVariable->pCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjAssignment: Invalid object variable code pointer" );
ASSERT( psVariable->psObjVar != NULL,
"scriptCodeObjAssignment: Invalid object variable symbol pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psValue != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjAssignment: Invalid value code block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psValue->pCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjAssignment: Invalid value code pointer" );
ASSERT( ppsBlock != NULL,
"scriptCodeObjAssignment: Invalid generated code block pointer" );
2006-11-26 05:45:04 -08:00
2006-08-12 09:52:37 -07:00
// Check there is an access function for the variable
if (psVariable->psObjVar->set == NULL)
{
scr_error("No set function for object variable");
return CE_PARSE;
}
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(*ppsBlock, psVariable->size + psValue->size + sizeof(OPCODE) + sizeof(SCRIPT_VARFUNC));
ALLOC_BLOCK(*ppsBlock, psVariable->size + psValue->size + 1 + 1); //size + size + opcode + 'sizeof(SCRIPT_VARFUNC)'
2006-11-26 05:45:04 -08:00
2006-08-12 09:52:37 -07:00
ip = (*ppsBlock)->pCode;
/* Copy in the code for the value */
PUT_BLOCK(ip, psValue);
FREE_BLOCK(psValue);
/* Copy in the code for the object */
PUT_BLOCK(ip, psVariable);
/* Code to get the value from the stack into the variable */
PUT_PKOPCODE(ip, OP_VARCALL, psVariable->psObjVar->index);
PUT_VARFUNC(ip, (psVariable->psObjVar->set));
/* Free the variable block */
FREE_OBJVARBLOCK(psVariable);
return CE_OK;
}
/* Generate code for getting a value from an object variable */
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeObjGet(OBJVAR_BLOCK *psVariable,// The variable to get from
2006-08-12 09:52:37 -07:00
CODE_BLOCK **ppsBlock) // Generated code
{
2007-04-03 06:20:41 -07:00
ASSERT( psVariable != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjAssignment: Invalid object variable block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psVariable->pCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjAssignment: Invalid object variable code pointer" );
ASSERT( psVariable->psObjVar != NULL,
"scriptCodeObjAssignment: Invalid object variable symbol pointer" );
ASSERT( ppsBlock != NULL,
"scriptCodeObjAssignment: Invalid generated code block pointer" );
2006-08-12 09:52:37 -07:00
// Check there is an access function for the variable
if (psVariable->psObjVar->get == NULL)
{
scr_error("No get function for object variable");
return CE_PARSE;
}
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(*ppsBlock, psVariable->size + sizeof(OPCODE) + sizeof(SCRIPT_VARFUNC));
ALLOC_BLOCK(*ppsBlock, psVariable->size + 1 + 1); //size + opcode + SCRIPT_VARFUNC
2006-08-12 09:52:37 -07:00
ip = (*ppsBlock)->pCode;
/* Copy in the code for the object */
PUT_BLOCK(ip, psVariable);
(*ppsBlock)->type = psVariable->psObjVar->type;
/* Code to get the value from the object onto the stack */
PUT_PKOPCODE(ip, OP_VARCALL, psVariable->psObjVar->index);
PUT_VARFUNC(ip, psVariable->psObjVar->get);
/* Free the variable block */
FREE_OBJVARBLOCK(psVariable);
return CE_OK;
}
/* Generate code for assigning a value to an array variable */
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeArrayAssignment(ARRAY_BLOCK *psVariable,// The variable to assign to
2006-08-12 09:52:37 -07:00
CODE_BLOCK *psValue, // The code for the value to
// assign
CODE_BLOCK **ppsBlock) // Generated code
{
// SDWORD elementDWords, i;
// UBYTE *pElement;
2007-04-03 06:20:41 -07:00
ASSERT( psVariable != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjAssignment: Invalid object variable block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psVariable->pCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjAssignment: Invalid object variable code pointer" );
ASSERT( psVariable->psArrayVar != NULL,
"scriptCodeObjAssignment: Invalid object variable symbol pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psValue != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjAssignment: Invalid value code block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psValue->pCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjAssignment: Invalid value code pointer" );
ASSERT( ppsBlock != NULL,
"scriptCodeObjAssignment: Invalid generated code block pointer" );
2006-08-12 09:52:37 -07:00
// Check this is an array
if (psVariable->psArrayVar->dimensions == 0)
{
scr_error("Not an array variable");
return CE_PARSE;
}
// calculate the number of DWORDs needed to store the number of elements for each dimension of the array
// elementDWords = (psVariable->psArrayVar->dimensions - 1)/4 + 1;
// ALLOC_BLOCK(*ppsBlock, psVariable->size + psValue->size + sizeof(OPCODE) + elementDWords*4);
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(*ppsBlock, psVariable->size + psValue->size + sizeof(OPCODE));
ALLOC_BLOCK(*ppsBlock, psVariable->size + psValue->size + 1); //size + size + opcode
2006-11-26 05:45:04 -08:00
2006-08-12 09:52:37 -07:00
ip = (*ppsBlock)->pCode;
/* Copy in the code for the value */
PUT_BLOCK(ip, psValue);
FREE_BLOCK(psValue);
/* Copy in the code for the array index */
PUT_BLOCK(ip, psVariable);
/* Code to get the value from the stack into the variable */
PUT_PKOPCODE(ip, OP_POPARRAYGLOBAL,
((psVariable->psArrayVar->dimensions << ARRAY_DIMENSION_SHIFT) & ARRAY_DIMENSION_MASK) |
(psVariable->psArrayVar->index & ARRAY_BASE_MASK) );
// store the size of each dimension
/* pElement = (UBYTE *)ip;
for(i=0; i<psVariable->psArrayVar->dimensions; i++)
{
*pElement = (UBYTE)psVariable->psArrayVar->elements[i];
pElement += 1;
}*/
/* Free the variable block */
FREE_ARRAYBLOCK(psVariable);
return CE_OK;
}
/* Generate code for getting a value from an array variable */
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeArrayGet(ARRAY_BLOCK *psVariable,// The variable to get from
2006-08-12 09:52:37 -07:00
CODE_BLOCK **ppsBlock) // Generated code
{
// SDWORD elementDWords, i;
// UBYTE *pElement;
2007-04-03 06:20:41 -07:00
ASSERT( psVariable != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjAssignment: Invalid object variable block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psVariable->pCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjAssignment: Invalid object variable code pointer" );
ASSERT( psVariable->psArrayVar != NULL,
"scriptCodeObjAssignment: Invalid object variable symbol pointer" );
ASSERT( ppsBlock != NULL,
"scriptCodeObjAssignment: Invalid generated code block pointer" );
2006-08-12 09:52:37 -07:00
// Check this is an array
if (psVariable->psArrayVar->dimensions == 0)
{
scr_error("Not an array variable");
return CE_PARSE;
}
// calculate the number of DWORDs needed to store the number of elements for each dimension of the array
// elementDWords = (psVariable->psArrayVar->dimensions - 1)/4 + 1;
// ALLOC_BLOCK(*ppsBlock, psVariable->size + sizeof(OPCODE) + elementDWords*4);
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(*ppsBlock, psVariable->size + sizeof(OPCODE));
ALLOC_BLOCK(*ppsBlock, psVariable->size + 1); //size + opcode
2006-08-12 09:52:37 -07:00
ip = (*ppsBlock)->pCode;
/* Copy in the code for the array index */
PUT_BLOCK(ip, psVariable);
(*ppsBlock)->type = psVariable->psArrayVar->type;
/* Code to get the value from the array onto the stack */
PUT_PKOPCODE(ip, OP_PUSHARRAYGLOBAL,
((psVariable->psArrayVar->dimensions << ARRAY_DIMENSION_SHIFT) & ARRAY_DIMENSION_MASK) |
(psVariable->psArrayVar->index & ARRAY_BASE_MASK) );
// store the size of each dimension
/* pElement = (UBYTE *)ip;
for(i=0; i<psVariable->psArrayVar->dimensions; i++)
{
*pElement = (UBYTE)psVariable->psArrayVar->elements[i];
pElement += 1;
}*/
/* Free the variable block */
FREE_ARRAYBLOCK(psVariable);
return CE_OK;
}
/* Generate the final code block for conditional statements */
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeConditional(
2006-08-12 09:52:37 -07:00
COND_BLOCK *psCondBlock, // The intermediate conditional code
CODE_BLOCK **ppsBlock) // The final conditional code
{
UDWORD i;
2007-04-03 06:20:41 -07:00
ASSERT( psCondBlock != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeConditional: Invalid conditional code block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psCondBlock->pCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeConditional: Invalid conditional code pointer" );
ASSERT( ppsBlock != NULL,
"scriptCodeConditional: Invalid generated code block pointer" );
2006-08-12 09:52:37 -07:00
/* Allocate the final block */
ALLOC_BLOCK(*ppsBlock, psCondBlock->size);
ALLOC_DEBUG(*ppsBlock, psCondBlock->debugEntries);
ip = (*ppsBlock)->pCode;
/* Copy the code over */
PUT_BLOCK(ip, psCondBlock);
/* Copy the debugging information */
PUT_DEBUG(*ppsBlock, psCondBlock);
/* Now set the offsets of jumps in the conditional to the correct value */
for(i = 0; i < psCondBlock->numOffsets; i++)
{
ip = (*ppsBlock)->pCode + psCondBlock->aOffsets[i];
2006-11-16 06:30:29 -08:00
// *ip = ((*ppsBlock)->size / sizeof(UDWORD)) - (ip - (*ppsBlock)->pCode);
ip->type = VAL_PKOPCODE;
ip->v.ival = (*ppsBlock)->size - (ip - (*ppsBlock)->pCode);
ip->v.ival = (OP_JUMP << OPCODE_SHIFT) | ( (ip->v.ival) & OPCODE_DATAMASK );
2006-08-12 09:52:37 -07:00
}
/* Free the original code */
FREE_DEBUG(psCondBlock);
FREE_CONDBLOCK(psCondBlock);
return CE_OK;
}
/* Generate code for function parameters */
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeParameter(CODE_BLOCK *psParam, // Code for the parameter
2006-08-12 09:52:37 -07:00
INTERP_TYPE type, // Parameter type
PARAM_BLOCK **ppsBlock) // Generated code
{
2007-04-03 06:20:41 -07:00
ASSERT( psParam != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeParameter: Invalid parameter code block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psParam->pCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeParameter: Invalid parameter code pointer" );
ASSERT( ppsBlock != NULL,
"scriptCodeParameter: Invalid generated code block pointer" );
2006-08-12 09:52:37 -07:00
2006-11-16 06:30:29 -08:00
RULE(" scriptCodeParameter(): type: %d", type);
2006-08-12 09:52:37 -07:00
ALLOC_PBLOCK(*ppsBlock, psParam->size, 1);
ip = (*ppsBlock)->pCode;
/* Copy in the code for the parameter */
PUT_BLOCK(ip, psParam);
FREE_BLOCK(psParam);
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
(*ppsBlock)->aParams[0] = type;
return CE_OK;
}
/* Generate code for binary operators (e.g. 2 + 2) */
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeBinaryOperator(CODE_BLOCK *psFirst, // Code for first parameter
2006-08-12 09:52:37 -07:00
CODE_BLOCK *psSecond, // Code for second parameter
OPCODE opcode, // Operator function
CODE_BLOCK **ppsBlock) // Generated code
{
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(*ppsBlock, psFirst->size + psSecond->size + sizeof(UDWORD));
ALLOC_BLOCK(*ppsBlock, psFirst->size + psSecond->size + 1); //size + size + binary opcode
2006-08-12 09:52:37 -07:00
ip = (*ppsBlock)->pCode;
/* Copy the already generated bits of code into the code block */
PUT_BLOCK(ip, psFirst);
PUT_BLOCK(ip, psSecond);
/* Now put an add operator into the code */
PUT_PKOPCODE(ip, OP_BINARYOP, opcode);
/* Free the two code blocks that have been copied */
FREE_BLOCK(psFirst);
FREE_BLOCK(psSecond);
return CE_OK;
}
2006-08-15 11:38:51 -07:00
/* check if the arguments in the function definition body match the argument types
and names from function declaration (if there was any) */
2007-03-16 09:20:16 -07:00
static BOOL checkFuncParamType(UDWORD argIndex, UDWORD argType)
2006-08-15 11:38:51 -07:00
{
VAR_SYMBOL *psCurr;
SDWORD i,j;
if(psCurEvent == NULL)
{
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "checkFuncParamType() - psCurEvent == NULL");
2006-08-15 11:38:51 -07:00
return FALSE;
}
if(argIndex < psCurEvent->numParams)
{
/* find the argument by the index */
i=psCurEvent->index;
j=0;
2007-03-16 09:20:16 -07:00
for(psCurr = psLocalVarsB[i]; psCurr != NULL; psCurr = psCurr->psNext)
2006-08-15 11:38:51 -07:00
{
if((psCurEvent->numParams - j - 1)==argIndex) /* got to the right argument */
{
if(argType != psCurr->type)
{
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Argument type with index %d in event '%s' doesn't match function declaration (%d/%d)",argIndex,psCurEvent->pIdent,argType,psCurr->type);
2006-08-15 11:38:51 -07:00
return FALSE;
}
else
{
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "arg matched ");
2006-08-15 11:38:51 -07:00
return TRUE;
}
}
j++;
}
}
else
{
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "checkFuncParamType() - argument %d has wrong argument index, event: '%s'", argIndex, psCurEvent->pIdent);
2006-08-15 11:38:51 -07:00
return FALSE;
}
2006-08-22 07:28:49 -07:00
2006-08-19 06:26:11 -07:00
return FALSE;
2006-08-15 11:38:51 -07:00
}
2006-08-12 09:52:37 -07:00
/* Generate code for accessing an object variable. The variable symbol is
* stored with the code for the object value so that this block can be used for
* both setting and retrieving an object value.
*/
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeObjectVariable(CODE_BLOCK *psObjCode, // Code for the object value
2006-08-12 09:52:37 -07:00
VAR_SYMBOL *psVar, // The object variable symbol
OBJVAR_BLOCK **ppsBlock) // Generated code
{
2007-04-03 06:20:41 -07:00
ASSERT( psObjCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjectVariable: Invalid object code block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psObjCode->pCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjectVariable: Invalid object code pointer" );
ASSERT( psVar != NULL,
"scriptCodeObjectVariable: Invalid variable symbol pointer" );
ASSERT( ppsBlock != NULL,
"scriptCodeObjectVariable: Invalid generated code block pointer" );
2006-08-12 09:52:37 -07:00
ALLOC_OBJVARBLOCK(*ppsBlock, psObjCode->size, psVar);
ip = (*ppsBlock)->pCode;
/* Copy the already generated bit of code into the code block */
PUT_BLOCK(ip, psObjCode);
FREE_BLOCK(psObjCode);
/* Check the variable is the correct type */
if (psVar->storage != ST_OBJECT)
{
scr_error("Only object variables are valid in this context");
return CE_PARSE;
}
return CE_OK;
}
/* Generate code for accessing an array variable. The variable symbol is
* stored with the code for the object value so that this block can be used for
* both setting and retrieving an array value.
*/
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeArrayVariable(ARRAY_BLOCK *psArrayCode, // Code for the array index
2006-08-12 09:52:37 -07:00
VAR_SYMBOL *psVar, // The array variable symbol
ARRAY_BLOCK **ppsBlock) // Generated code
{
2007-04-03 06:20:41 -07:00
ASSERT( psArrayCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjectVariable: Invalid object code block pointer" );
2007-04-03 06:20:41 -07:00
ASSERT( psArrayCode->pCode != NULL,
2006-08-23 05:58:48 -07:00
"scriptCodeObjectVariable: Invalid object code pointer" );
ASSERT( psVar != NULL,
"scriptCodeObjectVariable: Invalid variable symbol pointer" );
ASSERT( ppsBlock != NULL,
"scriptCodeObjectVariable: Invalid generated code block pointer" );
2006-08-12 09:52:37 -07:00
/* ALLOC_ARRAYBLOCK(*ppsBlock, psArrayCode->size, psVar);
ip = (*ppsBlock)->pCode;
// Copy the already generated bit of code into the code block
PUT_BLOCK(ip, psArrayCode);
FREE_BLOCK(psArrayCode);*/
// Check the variable is the correct type
if (psVar->dimensions != psArrayCode->dimensions)
{
scr_error("Invalid number of array dimensions for this variable");
return CE_PARSE;
}
psArrayCode->psArrayVar = psVar;
*ppsBlock = psArrayCode;
return CE_OK;
}
/* Generate code for a constant */
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeConstant(CONST_SYMBOL *psConst, // The object variable symbol
2006-08-12 09:52:37 -07:00
CODE_BLOCK **ppsBlock) // Generated code
{
2006-08-23 05:58:48 -07:00
ASSERT( psConst != NULL,
"scriptCodeConstant: Invalid constant symbol pointer" );
ASSERT( ppsBlock != NULL,
"scriptCodeConstant: Invalid generated code block pointer" );
2006-08-12 09:52:37 -07:00
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(*ppsBlock, sizeof(OPCODE) + sizeof(UDWORD));
ALLOC_BLOCK(*ppsBlock, 1 + 1); //OP_PUSH opcode + variable value
2006-08-12 09:52:37 -07:00
ip = (*ppsBlock)->pCode;
(*ppsBlock)->type = psConst->type;
/* Put the value onto the stack */
switch (psConst->type)
{
2006-11-16 06:30:29 -08:00
case VAL_FLOAT:
RULE(" scriptCodeConstant: pushing float");
PUT_PKOPCODE(ip, OP_PUSH, VAL_FLOAT);
PUT_DATA_FLOAT(ip, psConst->fval);
break;
2006-08-12 09:52:37 -07:00
case VAL_BOOL:
2006-11-16 06:30:29 -08:00
RULE(" scriptCodeConstant: pushing bool");
2006-08-12 09:52:37 -07:00
PUT_PKOPCODE(ip, OP_PUSH, VAL_BOOL);
2006-11-16 06:30:29 -08:00
PUT_DATA_BOOL(ip, psConst->bval);
2006-08-12 09:52:37 -07:00
break;
case VAL_INT:
2006-11-16 06:30:29 -08:00
RULE(" scriptCodeConstant: pushing int");
2006-08-12 09:52:37 -07:00
PUT_PKOPCODE(ip, OP_PUSH, VAL_INT);
2006-11-16 06:30:29 -08:00
PUT_DATA_INT(ip, psConst->ival);
2006-08-12 09:52:37 -07:00
break;
2006-08-19 06:26:11 -07:00
case VAL_STRING:
2006-11-16 06:30:29 -08:00
RULE(" scriptCodeConstant: pushing string");
2006-08-19 06:26:11 -07:00
PUT_PKOPCODE(ip, OP_PUSH, VAL_STRING);
2006-11-16 06:30:29 -08:00
PUT_DATA_STRING(ip, psConst->sval);
2006-08-19 06:26:11 -07:00
break;
2006-11-16 06:30:29 -08:00
default: /* Object/user constants */
RULE(" scriptCodeConstant: pushing object/ user var (type: %d)", psConst->type);
2006-08-12 09:52:37 -07:00
PUT_PKOPCODE(ip, OP_PUSH, psConst->type);
2006-11-16 06:30:29 -08:00
PUT_OBJECT_CONST(ip, psConst->oval, psConst->type); //TODO: differentiate types
2006-08-12 09:52:37 -07:00
break;
}
return CE_OK;
}
/* Generate code for getting a variables value */
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeVarGet(VAR_SYMBOL *psVariable, // The object variable symbol
2006-08-12 09:52:37 -07:00
CODE_BLOCK **ppsBlock) // Generated code
{
SDWORD size;
2006-11-16 06:30:29 -08:00
//size = sizeof(OPCODE);
size = 1; //1 - for opcode
2006-08-12 09:52:37 -07:00
if (psVariable->storage == ST_EXTERN)
{
// Check there is a set function
if (psVariable->get == NULL)
{
scr_error("No get function for external variable");
return CE_PARSE;
}
2006-11-26 05:45:04 -08:00
2006-11-16 06:30:29 -08:00
//size += sizeof(SCRIPT_VARFUNC);
size += 1;
2006-08-12 09:52:37 -07:00
}
ALLOC_BLOCK(*ppsBlock, size);
ip = (*ppsBlock)->pCode;
(*ppsBlock)->type = psVariable->type;
/* Code to get the value onto the stack */
switch (psVariable->storage)
{
case ST_PUBLIC:
case ST_PRIVATE:
PUT_PKOPCODE(ip, OP_PUSHGLOBAL, psVariable->index);
break;
2006-08-19 06:26:11 -07:00
case ST_LOCAL:
PUT_PKOPCODE(ip, OP_PUSHLOCAL, psVariable->index); //opcode + event index
2006-08-15 11:38:51 -07:00
break;
2006-08-12 09:52:37 -07:00
case ST_EXTERN:
PUT_PKOPCODE(ip, OP_VARCALL, psVariable->index);
PUT_VARFUNC(ip, psVariable->get);
break;
case ST_OBJECT:
scr_error("Cannot use member variables in this context");
return CE_PARSE;
break;
default:
scr_error("Unknown storage type");
return CE_PARSE;
break;
}
return CE_OK;
}
2006-12-06 10:57:17 -08:00
/* Code Increment/Decrement operators */
2007-01-02 12:12:14 -08:00
static CODE_ERROR scriptCodeIncDec(VAR_SYMBOL *psVariable, // The object variable symbol
2006-12-06 10:57:17 -08:00
CODE_BLOCK **ppsBlock, OPCODE op_dec_inc)
{
ALLOC_BLOCK(*ppsBlock, 1 + 1 + 1); //OP_PUSHREF opcode + variable index + inc opcode
ip = (*ppsBlock)->pCode;
(*ppsBlock)->type = psVariable->type;
/* Put variable index */
switch (psVariable->storage)
{
case ST_PRIVATE:
PUT_PKOPCODE(ip, OP_PUSHREF, psVariable->type | VAL_REF);
PUT_DATA_INT(ip, psVariable->index);
break;
case ST_LOCAL:
PUT_PKOPCODE(ip, OP_PUSHLOCALREF, psVariable->type | VAL_REF);
PUT_DATA_INT(ip, psVariable->index);
break;
default:
scr_error("Wrong variable storage type for increment/decrement operator");
break;
}
/* Put inc/dec opcode */
PUT_PKOPCODE(ip, OP_UNARYOP, op_dec_inc);
return CE_OK;
}
2006-08-12 09:52:37 -07:00
/* Generate code for getting a variables value */
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeVarRef(VAR_SYMBOL *psVariable, // The object variable symbol
2006-08-12 09:52:37 -07:00
PARAM_BLOCK **ppsBlock) // Generated code
{
SDWORD size;
2006-11-16 06:30:29 -08:00
//size = sizeof(OPCODE) + sizeof(SDWORD);
size = 1 + 1; //OP_PUSHREF opcode + variable index
2006-11-26 05:45:04 -08:00
2006-08-12 09:52:37 -07:00
ALLOC_PBLOCK(*ppsBlock, size, 1);
ip = (*ppsBlock)->pCode;
2006-08-19 06:26:11 -07:00
2006-08-12 09:52:37 -07:00
(*ppsBlock)->aParams[0] = psVariable->type | VAL_REF;
/* Code to get the value onto the stack */
switch (psVariable->storage)
{
case ST_PUBLIC:
case ST_PRIVATE:
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
PUT_PKOPCODE(ip, OP_PUSHREF, (*ppsBlock)->aParams[0]);
2006-11-16 06:30:29 -08:00
PUT_DATA_INT(ip, psVariable->index); //TODO: add new macro
2006-08-12 09:52:37 -07:00
break;
2006-08-15 11:38:51 -07:00
case ST_LOCAL:
PUT_PKOPCODE(ip, OP_PUSHLOCALREF, (*ppsBlock)->aParams[0]);
2006-11-16 06:30:29 -08:00
PUT_DATA_INT(ip, psVariable->index);
2006-08-15 11:38:51 -07:00
break;
2006-08-12 09:52:37 -07:00
case ST_EXTERN:
scr_error("Cannot use external variables in this context");
return CE_PARSE;
break;
case ST_OBJECT:
scr_error("Cannot use member variables in this context");
return CE_PARSE;
break;
default:
2006-08-19 06:26:11 -07:00
scr_error("Unknown storage type: %d", psVariable->storage);
2006-08-12 09:52:37 -07:00
return CE_PARSE;
break;
}
return CE_OK;
}
2007-02-19 06:10:44 -08:00
#ifdef UNUSED
2006-08-12 09:52:37 -07:00
/* Generate the code for a trigger and store it in the trigger list */
2006-11-03 13:35:50 -08:00
static CODE_ERROR scriptCodeTrigger(char *pIdent, CODE_BLOCK *psCode)
2006-08-12 09:52:37 -07:00
{
CODE_BLOCK *psNewBlock;
UDWORD line;
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-08-12 09:52:37 -07:00
pIdent = pIdent;
// Have to add the exit code to the end of the event
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psNewBlock, psCode->size + sizeof(OPCODE));
ALLOC_BLOCK(psNewBlock, psCode->size + 1); //size + opcode
2006-08-12 09:52:37 -07:00
ip = psNewBlock->pCode;
PUT_BLOCK(ip, psCode);
PUT_OPCODE(ip, OP_EXIT);
// Add the debug info
ALLOC_DEBUG(psNewBlock, psCode->debugEntries + 1);
PUT_DEBUG(psNewBlock, psCode);
if (genDebugInfo)
{
/* Add debugging info for the EXIT instruction */
2006-08-19 06:26:11 -07:00
scriptGetErrorData((SDWORD *)&line, &pDummy);
2006-08-12 09:52:37 -07:00
psNewBlock->psDebug[psNewBlock->debugEntries].line = line;
2006-08-22 07:28:49 -07:00
psNewBlock->psDebug[psNewBlock->debugEntries].offset =
2006-08-12 09:52:37 -07:00
ip - psNewBlock->pCode;
psNewBlock->debugEntries ++;
}
FREE_BLOCK(psCode);
// Create the trigger
/* if (!scriptAddTrigger(pIdent, psNewBlock))
{
return CE_MEMORY;
}*/
return CE_OK;
}
2007-02-19 06:10:44 -08:00
#endif
2006-08-12 09:52:37 -07:00
2007-02-19 06:10:44 -08:00
#ifdef UNUSED
2006-08-12 09:52:37 -07:00
/* Generate the code for an event and store it in the event list */
2006-09-16 10:41:40 -07:00
static CODE_ERROR scriptCodeEvent(EVENT_SYMBOL *psEvent, TRIGGER_SYMBOL *psTrig, CODE_BLOCK *psCode)
2006-08-12 09:52:37 -07:00
{
CODE_BLOCK *psNewBlock;
UDWORD line;
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-08-12 09:52:37 -07:00
// Have to add the exit code to the end of the event
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psNewBlock, psCode->size + sizeof(OPCODE));
ALLOC_BLOCK(psNewBlock, psCode->size + 1); //size + opcode
2006-08-12 09:52:37 -07:00
ip = psNewBlock->pCode;
PUT_BLOCK(ip, psCode);
PUT_OPCODE(ip, OP_EXIT);
// Add the debug info
ALLOC_DEBUG(psNewBlock, psCode->debugEntries + 1);
PUT_DEBUG(psNewBlock, psCode);
if (genDebugInfo)
{
/* Add debugging info for the EXIT instruction */
2006-08-19 06:26:11 -07:00
scriptGetErrorData((SDWORD *)&line, &pDummy);
2006-08-12 09:52:37 -07:00
psNewBlock->psDebug[psNewBlock->debugEntries].line = line;
2006-08-22 07:28:49 -07:00
psNewBlock->psDebug[psNewBlock->debugEntries].offset =
2006-08-12 09:52:37 -07:00
ip - psNewBlock->pCode;
psNewBlock->debugEntries ++;
}
FREE_BLOCK(psCode);
// Create the event
if (!scriptDefineEvent(psEvent, psNewBlock, psTrig->index))
{
return CE_MEMORY;
}
return CE_OK;
}
2007-02-19 06:10:44 -08:00
#endif
2006-08-12 09:52:37 -07:00
/* Store the types of a list of variables into a code block.
* The order of the list is reversed so that the type of the
* first variable defined is stored first.
*/
static void scriptStoreVarTypes(VAR_SYMBOL *psVar)
{
if (psVar != NULL)
{
/* Recurse down the list to get to the end of it */
scriptStoreVarTypes(psVar->psNext);
/* Now store the current variable */
PUT_INDEX(ip, psVar->type);
}
}
/* Change the error action for the ALLOC macro's to what it
* should be inside a rule body.
*
* NOTE: DO NOT USE THE ALLOC MACRO'S INSIDE ANY FUNCTIONS
* ONCE ALLOC_ERROR_ACTION IS SET TO THIS VALUE.
* ALL FUNCTIONS THAT USE THESE MACROS MUST BE PLACED
* BEFORE THIS #define.
*/
#undef ALLOC_ERROR_ACTION
#define ALLOC_ERROR_ACTION YYABORT
%}
%name-prefix="scr_"
%union {
/* Types returned by the lexer */
BOOL bval;
2006-11-16 06:30:29 -08:00
float fval;
2006-08-12 09:52:37 -07:00
SDWORD ival;
2006-11-03 13:35:50 -08:00
char *sval;
2006-08-12 09:52:37 -07:00
INTERP_TYPE tval;
STORAGE_TYPE stype;
VAR_SYMBOL *vSymbol;
CONST_SYMBOL *cSymbol;
FUNC_SYMBOL *fSymbol;
TRIGGER_SYMBOL *tSymbol;
EVENT_SYMBOL *eSymbol;
CALLBACK_SYMBOL *cbSymbol;
/* Types only returned by rules */
CODE_BLOCK *cblock;
COND_BLOCK *condBlock;
OBJVAR_BLOCK *objVarBlock;
ARRAY_BLOCK *arrayBlock;
PARAM_BLOCK *pblock;
PARAM_DECL *pdecl;
TRIGGER_DECL *tdecl;
2006-08-19 06:26:11 -07:00
UDWORD integer_val;
2006-08-12 09:52:37 -07:00
VAR_DECL *vdecl;
VAR_IDENT_DECL *videcl;
}
/* key words */
2006-08-19 06:26:11 -07:00
%token FUNCTION
2006-08-12 09:52:37 -07:00
%token TRIGGER
%token EVENT
%token WAIT
%token EVERY
%token INACTIVE
%token INITIALISE
%token LINK
%token REF
2006-08-19 06:26:11 -07:00
%token RET
2006-09-19 09:07:06 -07:00
%token _VOID
2006-08-12 09:52:37 -07:00
/* %token COND */
%token WHILE
%token IF
%token ELSE
%token EXIT
%token PAUSE
/* boolean operators */
%token BOOLEQUAL
%token NOTEQUAL
%token GREATEQUAL
%token LESSEQUAL
%token GREATER
%token LESS
%token _AND
%token _OR
%token _NOT
2006-12-02 15:27:00 -08:00
%token _INC
%token _DEC
2006-08-12 09:52:37 -07:00
%left _AND _OR
%left BOOLEQUAL NOTEQUAL GREATEQUAL LESSEQUAL GREATER LESS
%nonassoc _NOT
2006-08-19 06:26:11 -07:00
%left '-' '+' '&'
2006-08-12 09:52:37 -07:00
%left '*' '/'
2006-11-16 06:30:29 -08:00
%right TO_INT_CAST
%right TO_FLOAT_CAST
2006-08-12 09:52:37 -07:00
%nonassoc UMINUS
2006-12-02 15:27:00 -08:00
%left _INC _DEC
2006-08-12 09:52:37 -07:00
/* value tokens */
%token <bval> BOOLEAN_T
2006-11-16 06:30:29 -08:00
%token <fval> FLOAT_T
2006-08-12 09:52:37 -07:00
%token <ival> INTEGER
%token <sval> QTEXT /* Text with double quotes surrounding it */
%token <tval> TYPE /* A type specifier */
%token <stype> STORAGE /* Variable storage type */
%token <sval> IDENT /* An undefined identifier */
%token <vSymbol> VAR /* A defined variable */
%token <vSymbol> BOOL_VAR /* A defined boolean variable */
2006-11-16 06:30:29 -08:00
%token <vSymbol> NUM_VAR /* A defined numeric (int) variable */
%token <vSymbol> FLOAT_VAR /* A defined numeric (float) variable */
2006-08-12 09:52:37 -07:00
%token <vSymbol> OBJ_VAR /* A defined object pointer variable */
2006-08-19 06:26:11 -07:00
%token <vSymbol> STRING_VAR /* A defined string variable */
2006-08-12 09:52:37 -07:00
%token <vSymbol> VAR_ARRAY /* A defined variable array */
%token <vSymbol> BOOL_ARRAY /* A defined boolean variable array */
2006-11-16 06:30:29 -08:00
%token <vSymbol> NUM_ARRAY /* A defined numeric (int) variable array */
%token <vSymbol> FLOAT_ARRAY /* A defined numeric (float) variable array */
2006-08-12 09:52:37 -07:00
%token <vSymbol> OBJ_ARRAY /* A defined object pointer variable array */
%token <vSymbol> BOOL_OBJVAR /* A defined boolean object member variable */
%token <vSymbol> NUM_OBJVAR /* A defined numeric object member variable */
%token <vSymbol> USER_OBJVAR /* A defined user type object member variable */
%token <vSymbol> OBJ_OBJVAR /* A defined object pointer object member variable */
%token <cSymbol> BOOL_CONSTANT /* A defined boolean constant */
%token <cSymbol> NUM_CONSTANT /* A defined numeric constant */
%token <cSymbol> USER_CONSTANT /* A defined object pointer constant */
%token <cSymbol> OBJ_CONSTANT /* A defined object pointer constant */
2006-08-21 02:34:42 -07:00
%token <cSymbol> STRING_CONSTANT /* A defined string constant */
2006-08-12 09:52:37 -07:00
%token <fSymbol> FUNC /* A defined function */
%token <fSymbol> BOOL_FUNC /* A defined boolean function */
2006-11-16 06:30:29 -08:00
%token <fSymbol> NUM_FUNC /* A defined numeric (int) function */
%token <fSymbol> FLOAT_FUNC /* A defined numeric (float) function */
2006-08-12 09:52:37 -07:00
%token <fSymbol> USER_FUNC /* A defined user defined type function */
%token <fSymbol> OBJ_FUNC /* A defined object pointer function */
2006-08-19 06:26:11 -07:00
%token <fSymbol> STRING_FUNC /* A defined string function */
/* custom, in-script defined functions (events actually) */
%token <eSymbol> VOID_FUNC_CUST /* A defined function */
%token <eSymbol> BOOL_FUNC_CUST /* A defined boolean function */
2006-11-16 06:30:29 -08:00
%token <eSymbol> NUM_FUNC_CUST /* A defined numeric (int) function */
%token <eSymbol> FLOAT_FUNC_CUST /* A defined numeric (float) function */
2006-08-19 06:26:11 -07:00
%token <eSymbol> USER_FUNC_CUST /* A defined user defined type function */
%token <eSymbol> OBJ_FUNC_CUST /* A defined object pointer function */
%token <eSymbol> STRING_FUNC_CUST /* A defined string function */
2006-08-12 09:52:37 -07:00
%token <tSymbol> TRIG_SYM /* A defined trigger */
%token <eSymbol> EVENT_SYM /* A defined event */
%token <cbSymbol> CALLBACK_SYM /* A callback trigger */
/* rule types */
%type <cblock> expression
%type <cblock> boolexp
2006-08-19 06:26:11 -07:00
%type <cblock> stringexp
2006-11-16 06:30:29 -08:00
%type <cblock> floatexp
2006-08-19 06:26:11 -07:00
%type <cblock> return_exp
2006-08-22 07:28:49 -07:00
%type <cblock> return_statement
2006-08-12 09:52:37 -07:00
%type <cblock> objexp
%type <cblock> objexp_dot
%type <cblock> userexp
2006-12-02 15:27:00 -08:00
%type <cblock> inc_dec_exp
2006-08-12 09:52:37 -07:00
%type <objVarBlock> num_objvar
%type <objVarBlock> bool_objvar
%type <objVarBlock> user_objvar
%type <objVarBlock> obj_objvar
%type <arrayBlock> array_index
%type <arrayBlock> array_index_list
%type <arrayBlock> num_array_var
%type <arrayBlock> bool_array_var
%type <arrayBlock> user_array_var
%type <arrayBlock> obj_array_var
%type <cblock> statement_list
%type <cblock> statement
%type <cblock> assignment
%type <cblock> func_call
%type <pblock> param_list
2006-08-21 02:34:42 -07:00
/* %type <pblock> braced_param_list */ /* for jump(), to make optional braced parameter list for function calls */
2006-08-12 09:52:37 -07:00
%type <pblock> parameter
%type <pblock> var_ref
%type <cblock> conditional
%type <condBlock> cond_clause
%type <condBlock> terminal_cond
%type <condBlock> cond_clause_list
%type <cblock> loop
%type <videcl> array_sub_decl
%type <videcl> array_sub_decl_list
%type <videcl> variable_ident
%type <vdecl> variable_decl_head
%type <vdecl> variable_decl
2006-08-19 06:26:11 -07:00
%type <vdecl> var_line
2006-08-12 09:52:37 -07:00
%type <tdecl> trigger_subdecl
2006-09-19 09:07:06 -07:00
%type <integer_val> funcbody_var_def_body
%type <eSymbol> funcbody_var_def
%type <eSymbol> void_funcbody_var_def
2006-08-19 06:26:11 -07:00
/*%type <integer_val> func_decl_ret_type */ /* for function declarations and definitions */
%type <integer_val> funcvar_decl_types
2006-08-12 09:52:37 -07:00
%type <eSymbol> event_subdecl
2006-08-19 06:26:11 -07:00
%type <eSymbol> func_subdecl /* function declaration */
2006-09-19 09:07:06 -07:00
%type <eSymbol> function_def
%type <eSymbol> void_function_def
%type <eSymbol> void_func_subdecl /* void function declaration */
2006-08-19 06:26:11 -07:00
%type <eSymbol> function_declaration
2006-09-19 09:07:06 -07:00
%type <eSymbol> void_function_declaration
2006-08-12 09:52:37 -07:00
%type <eSymbol> function_type
%%
2006-08-22 07:28:49 -07:00
script: header var_list
2006-08-12 09:52:37 -07:00
{
/* stop parsing here if we are just getting */
/* the variables in the script */
/* YYACCEPT */
}
trigger_list event_list
{
2006-08-19 06:26:11 -07:00
SDWORD size, debug_i, i, dimension, arraySize, totalArraySize;
2006-08-12 09:52:37 -07:00
SDWORD numArrays;
UDWORD base;
VAR_SYMBOL *psCurr;
TRIGGER_SYMBOL *psTrig;
EVENT_SYMBOL *psEvent;
UDWORD numVars;
2006-08-15 11:38:51 -07:00
INTERP_TYPE *pCurEvLocalVars;
UDWORD j;
2006-11-03 13:35:50 -08:00
2006-11-16 06:30:29 -08:00
RULE("script: header var_list");
2006-08-12 09:52:37 -07:00
// Calculate the code size
size = 0;
2006-08-19 06:26:11 -07:00
debug_i = 0;
2006-08-12 09:52:37 -07:00
for(psTrig = psTriggers; psTrig; psTrig = psTrig->psNext)
{
// Add the trigger code size
size += psTrig->size;
2006-08-19 06:26:11 -07:00
debug_i += psTrig->debugEntries;
2006-08-12 09:52:37 -07:00
}
2006-08-19 06:26:11 -07:00
2006-08-12 09:52:37 -07:00
for(psEvent = psEvents; psEvent; psEvent = psEvent->psNext)
{
// Add the trigger code size
size += psEvent->size;
2006-08-19 06:26:11 -07:00
debug_i += psEvent->debugEntries;
2006-08-12 09:52:37 -07:00
}
// Allocate the program
numVars = psGlobalVars ? psGlobalVars->index+1 : 0;
numArrays = psGlobalArrays ? psGlobalArrays->index+1 : 0;
totalArraySize = 0;
for(psCurr=psGlobalArrays; psCurr; psCurr=psCurr->psNext)
{
arraySize = 1;
for(dimension = 0; dimension < psCurr->dimensions; dimension += 1)
{
arraySize *= psCurr->elements[dimension];
}
totalArraySize += arraySize;
}
ALLOC_PROG(psFinalProg, size, psCurrBlock->pCode,
numVars, numArrays, numTriggers, numEvents);
2006-08-15 11:38:51 -07:00
2006-08-19 06:26:11 -07:00
//store local vars
2006-08-15 11:38:51 -07:00
//allocate array for holding an array of local vars for each event
2007-04-15 03:43:05 -07:00
psFinalProg->ppsLocalVars = (INTERP_TYPE **)malloc(sizeof(INTERP_TYPE*) * numEvents);
2007-03-13 13:49:03 -07:00
psFinalProg->ppsLocalVarVal = NULL;
2007-04-15 03:43:05 -07:00
psFinalProg->numLocalVars = (UDWORD *)malloc(sizeof(UDWORD) * numEvents); //how many local vars each event has
psFinalProg->numParams = (UDWORD *)malloc(sizeof(UDWORD) * numEvents); //how many arguments each event has
2006-08-15 11:38:51 -07:00
i=0;
for(psEvent = psEvents; psEvent; psEvent = psEvent->psNext)
{
psEvent->numLocalVars = numEventLocalVars[i];
psFinalProg->numLocalVars[i] = numEventLocalVars[i]; //remember how many local vars this event has
psFinalProg->numParams[i] = psEvent->numParams; //remember how many parameters this event has
if(numEventLocalVars[i] > 0)
{
2007-04-15 03:43:05 -07:00
pCurEvLocalVars = (INTERP_TYPE*)malloc(sizeof(INTERP_TYPE) * numEventLocalVars[i]);
2006-08-22 07:28:49 -07:00
2006-08-15 11:38:51 -07:00
j=0;
for(psCurr =psLocalVarsB[i]; psCurr != NULL; psCurr = psCurr->psNext)
{
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "remembering loc var ");
//debug(LOG_SCRIPT, "%d - %d \n",i,j);
2006-08-15 11:38:51 -07:00
pCurEvLocalVars[numEventLocalVars[i] - j - 1] = psCurr->type; //save type, order is reversed
j++;
}
}
else
{
pCurEvLocalVars = NULL; //this event has no local vars
}
psFinalProg->ppsLocalVars[i] = pCurEvLocalVars;
i++;
}
2006-08-19 06:26:11 -07:00
ALLOC_DEBUG(psFinalProg, debug_i);
2006-08-12 09:52:37 -07:00
psFinalProg->debugEntries = 0;
ip = psFinalProg->pCode;
// Add the trigger code
i=0;
for(psTrig = psTriggers; psTrig; psTrig = psTrig->psNext)
{
// Store the trigger offset
psFinalProg->pTriggerTab[i] = (UWORD)(ip - psFinalProg->pCode);
if (psTrig->pCode != NULL)
{
// Store the label
DEBUG_LABEL(psFinalProg, psFinalProg->debugEntries,
psTrig->pIdent);
// Store debug info
APPEND_DEBUG(psFinalProg, ip - psFinalProg->pCode, psTrig);
// Store the code
PUT_BLOCK(ip, psTrig);
psFinalProg->psTriggerData[i].code = TRUE;
}
else
{
psFinalProg->psTriggerData[i].code = FALSE;
}
// Store the data
psFinalProg->psTriggerData[i].type = (UWORD)psTrig->type;
psFinalProg->psTriggerData[i].time = psTrig->time;
i = i+1;
}
// Note the end of the final trigger
psFinalProg->pTriggerTab[i] = (UWORD)(ip - psFinalProg->pCode);
// Add the event code
i=0;
for(psEvent = psEvents; psEvent; psEvent = psEvent->psNext)
{
// Check the event was declared and has a code body
if (psEvent->pCode == NULL)
{
scr_error("Event %s declared without being defined",
psEvent->pIdent);
YYABORT;
}
// Store the event offset
psFinalProg->pEventTab[i] = (UWORD)(ip - psFinalProg->pCode);
// Store the trigger link
psFinalProg->pEventLinks[i] = (SWORD)(psEvent->trigger);
// Store the label
DEBUG_LABEL(psFinalProg, psFinalProg->debugEntries,
psEvent->pIdent);
// Store debug info
APPEND_DEBUG(psFinalProg, ip - psFinalProg->pCode, psEvent);
// Store the code
PUT_BLOCK(ip, psEvent);
i = i+1;
}
// Note the end of the final event
psFinalProg->pEventTab[i] = (UWORD)(ip - psFinalProg->pCode);
// Allocate debug info for the variables if necessary
if (genDebugInfo)
{
if (numVars > 0)
{
2007-04-15 03:43:05 -07:00
psFinalProg->psVarDebug = malloc(sizeof(VAR_DEBUG) * numVars);
2006-08-12 09:52:37 -07:00
if (psFinalProg->psVarDebug == NULL)
{
scr_error("Out of memory");
YYABORT;
}
}
else
{
psFinalProg->psVarDebug = NULL;
}
if (numArrays > 0)
{
2007-04-15 03:43:05 -07:00
psFinalProg->psArrayDebug = malloc(sizeof(ARRAY_DEBUG) * numArrays);
2006-08-12 09:52:37 -07:00
if (psFinalProg->psArrayDebug == NULL)
{
scr_error("Out of memory");
YYABORT;
}
}
else
{
psFinalProg->psArrayDebug = NULL;
}
}
else
{
psFinalProg->psVarDebug = NULL;
psFinalProg->psArrayDebug = NULL;
}
/* Now set the types for the global variables */
for(psCurr = psGlobalVars; psCurr != NULL; psCurr = psCurr->psNext)
{
i = psCurr->index;
psFinalProg->pGlobals[i] = psCurr->type;
if (genDebugInfo)
{
psFinalProg->psVarDebug[i].pIdent =
2007-04-15 03:43:05 -07:00
malloc(strlen(psCurr->pIdent) + 1);
2006-08-12 09:52:37 -07:00
if (psFinalProg->psVarDebug[i].pIdent == NULL)
{
scr_error("Out of memory");
YYABORT;
}
strcpy(psFinalProg->psVarDebug[i].pIdent, psCurr->pIdent);
psFinalProg->psVarDebug[i].storage = psCurr->storage;
}
}
/* Now store the array info */
psFinalProg->arraySize = totalArraySize;
for(psCurr = psGlobalArrays; psCurr != NULL; psCurr = psCurr->psNext)
{
i = psCurr->index;
psFinalProg->psArrayInfo[i].type = (UBYTE)psCurr->type;
psFinalProg->psArrayInfo[i].dimensions = (UBYTE)psCurr->dimensions;
for(dimension=0; dimension < psCurr->dimensions; dimension += 1)
{
psFinalProg->psArrayInfo[i].elements[dimension] = (UBYTE)psCurr->elements[dimension];
}
if (genDebugInfo)
{
psFinalProg->psArrayDebug[i].pIdent =
2007-04-15 03:43:05 -07:00
malloc(strlen(psCurr->pIdent) + 1);
2006-08-12 09:52:37 -07:00
if (psFinalProg->psArrayDebug[i].pIdent == NULL)
{
scr_error("Out of memory");
YYABORT;
}
strcpy(psFinalProg->psArrayDebug[i].pIdent, psCurr->pIdent);
psFinalProg->psArrayDebug[i].storage = psCurr->storage;
}
}
// calculate the base index of each array
base = psFinalProg->numGlobals;
for(i=0; i<numArrays; i++)
{
psFinalProg->psArrayInfo[i].base = base;
arraySize = 1;
for(dimension = 0; dimension < psFinalProg->psArrayInfo[i].dimensions; dimension += 1)
{
arraySize *= psFinalProg->psArrayInfo[i].elements[dimension];
}
base += arraySize;
}
2006-08-26 14:45:21 -07:00
2006-11-16 06:30:29 -08:00
RULE("END script: header var_list");
}
2006-08-12 09:52:37 -07:00
;
/**************************************************************************************
*
* Header declarations
*/
2006-08-19 06:26:11 -07:00
header: /* NULL token */
2006-08-12 09:52:37 -07:00
| header_decl
| header header_decl
;
header_decl: LINK TYPE ';'
{
// if (!scriptAddVariable("owner", $2, ST_PUBLIC, 0))
// {
// Out of memory - error already given
// YYABORT;
// }
}
;
2006-11-03 13:35:50 -08:00
2006-08-19 06:26:11 -07:00
var_list: /* NULL token */
2006-09-19 09:07:06 -07:00
{
2006-11-16 06:30:29 -08:00
RULE("var_list: NULL");
2006-09-19 09:07:06 -07:00
}
2006-08-15 11:38:51 -07:00
| var_line
2006-08-12 09:52:37 -07:00
{
2006-11-16 06:30:29 -08:00
RULE("var_list: var_line");
2006-08-12 09:52:37 -07:00
FREE_VARDECL($1);
}
2006-08-15 11:38:51 -07:00
| var_list var_line
2006-08-12 09:52:37 -07:00
{
FREE_VARDECL($2);
}
;
2006-09-19 09:07:06 -07:00
/**************************************************************************************
*
* Variable and function declarations
*/
2006-08-15 11:38:51 -07:00
var_line: variable_decl ';'
{
/* remember that local var declaration is over */
localVariableDef = FALSE;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "localVariableDef = FALSE 0");
2006-08-15 11:38:51 -07:00
$$ = $1;
}
;
2006-08-19 06:26:11 -07:00
2006-08-12 09:52:37 -07:00
variable_decl_head: STORAGE TYPE
{
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "variable_decl_head: STORAGE TYPE");
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
ALLOC_VARDECL(psCurrVDecl);
psCurrVDecl->storage = $1;
psCurrVDecl->type = $2;
2006-08-16 04:23:43 -07:00
2006-08-19 06:26:11 -07:00
/* allow local vars to have the same names as global vars (don't check global vars) */
if($1 == ST_LOCAL)
2006-08-16 04:23:43 -07:00
{
2006-08-19 06:26:11 -07:00
localVariableDef = TRUE;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "localVariableDef = TRUE 0");
2006-08-15 11:38:51 -07:00
}
2006-08-12 09:52:37 -07:00
$$ = psCurrVDecl;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END variable_decl_head: STORAGE TYPE (TYPE=%d)", $2);
2006-08-12 09:52:37 -07:00
}
| STORAGE TRIGGER
{
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
ALLOC_VARDECL(psCurrVDecl);
psCurrVDecl->storage = $1;
psCurrVDecl->type = VAL_TRIGGER;
$$ = psCurrVDecl;
}
| STORAGE EVENT
{
ALLOC_VARDECL(psCurrVDecl);
psCurrVDecl->storage = $1;
psCurrVDecl->type = VAL_EVENT;
$$ = psCurrVDecl;
}
;
array_sub_decl: '[' INTEGER ']'
{
if ($2 <= 0 || $2 >= VAR_MAX_ELEMENTS)
{
scr_error("Invalid array size %d", $2);
YYABORT;
}
ALLOC_VARIDENTDECL(psCurrVIdentDecl, NULL, 1);
psCurrVIdentDecl->elements[0] = $2;
$$ = psCurrVIdentDecl;
}
;
array_sub_decl_list: array_sub_decl
{
$$ = $1;
}
|
array_sub_decl_list '[' INTEGER ']'
{
if ($1->dimensions >= VAR_MAX_DIMENSIONS)
{
scr_error("Too many dimensions for array");
YYABORT;
}
if ($3 <= 0 || $3 >= VAR_MAX_ELEMENTS)
{
scr_error("Invalid array size %d", $3);
YYABORT;
}
$1->elements[$1->dimensions] = $3;
$1->dimensions += 1;
$$ = $1;
}
;
variable_ident: IDENT
{
ALLOC_VARIDENTDECL(psCurrVIdentDecl, $1, 0);
$$ = psCurrVIdentDecl;
}
|
IDENT array_sub_decl_list
{
2007-04-15 03:43:05 -07:00
$2->pIdent = malloc(strlen($1)+1);
2006-08-12 09:52:37 -07:00
if ($2->pIdent == NULL)
{
scr_error("Out of memory");
YYABORT;
}
strcpy($2->pIdent, $1);
$$ = $2;
}
;
variable_decl: variable_decl_head variable_ident
{
if (!scriptAddVariable($1, $2))
{
/* Out of memory - error already given */
YYABORT;
}
FREE_VARIDENTDECL($2);
/* return the variable type */
$$ = $1;
}
| variable_decl ',' variable_ident
{
if (!scriptAddVariable($1, $3))
{
/* Out of memory - error already given */
YYABORT;
}
FREE_VARIDENTDECL($3);
/* return the variable type */
$$ = $1;
}
;
/**************************************************************************************
*
* Trigger declarations
*/
2006-08-19 06:26:11 -07:00
trigger_list: /* NULL token */
2006-08-12 09:52:37 -07:00
| trigger_decl
| trigger_list trigger_decl
;
trigger_subdecl: boolexp ',' INTEGER
{
ALLOC_TSUBDECL(psCurrTDecl, TR_CODE, $1->size, $3);
ip = psCurrTDecl->pCode;
PUT_BLOCK(ip, $1);
FREE_BLOCK($1);
$$ = psCurrTDecl;
}
| WAIT ',' INTEGER
{
ALLOC_TSUBDECL(psCurrTDecl, TR_WAIT, 0, $3);
$$ = psCurrTDecl;
}
| EVERY ',' INTEGER
{
ALLOC_TSUBDECL(psCurrTDecl, TR_EVERY, 0, $3);
$$ = psCurrTDecl;
}
| INITIALISE
{
ALLOC_TSUBDECL(psCurrTDecl, TR_INIT, 0, 0);
$$ = psCurrTDecl;
}
| CALLBACK_SYM
{
if ($1->numParams != 0)
{
scr_error("Expected parameters for callback trigger");
YYABORT;
}
ALLOC_TSUBDECL(psCurrTDecl, $1->type, 0, 0);
$$ = psCurrTDecl;
}
| CALLBACK_SYM ',' param_list
{
2006-11-16 06:30:29 -08:00
RULE("trigger_subdecl: CALLBACK_SYM ',' param_list");
2006-08-12 09:52:37 -07:00
codeRet = scriptCodeCallbackParams($1, $3, &psCurrTDecl);
CHECK_CODE_ERROR(codeRet);
$$ = psCurrTDecl;
}
;
trigger_decl: TRIGGER IDENT '(' trigger_subdecl ')' ';'
{
SDWORD line;
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-08-12 09:52:37 -07:00
2006-08-19 06:26:11 -07:00
scriptGetErrorData(&line, &pDummy);
2006-08-12 09:52:37 -07:00
if (!scriptAddTrigger($2, $4, (UDWORD)line))
{
YYABORT;
}
FREE_TSUBDECL($4);
}
;
/**************************************************************************************
*
* Event declarations
*/
event_list: event_decl
| event_list event_decl
;
event_subdecl: EVENT IDENT
{
EVENT_SYMBOL *psEvent;
2006-11-16 06:30:29 -08:00
RULE("event_subdecl: EVENT IDENT");
2006-08-19 06:26:11 -07:00
if (!scriptDeclareEvent($2, &psEvent,0))
2006-08-12 09:52:37 -07:00
{
YYABORT;
}
psCurEvent = psEvent;
$$ = psEvent;
2006-08-19 06:26:11 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END event_subdecl: EVENT IDENT");
2006-08-12 09:52:37 -07:00
}
| EVENT EVENT_SYM
2007-01-02 12:12:14 -08:00
{
2006-11-16 06:30:29 -08:00
2007-01-02 12:12:14 -08:00
RULE("EVENT EVENT_SYM");
2006-11-16 06:30:29 -08:00
2007-01-02 12:12:14 -08:00
psCurEvent = $2;
$$ = $2;
2006-08-22 07:28:49 -07:00
2007-01-02 12:12:14 -08:00
//debug(LOG_SCRIPT, "END EVENT EVENT_SYM");
}
2006-08-12 09:52:37 -07:00
;
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
function_def: FUNCTION TYPE function_type
{
2006-11-16 06:30:29 -08:00
RULE("function_def: FUNCTION TYPE function_type");
2006-09-19 09:07:06 -07:00
psCurEvent = $3;
/* check if this event was declared as function before */
if(!$3->bFunction)
{
debug(LOG_ERROR, "'%s' was declared as event before and can't be redefined to function", $3->pIdent);
scr_error("Wrong event definition");
YYABORT;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
$$ = $3;
}
;
2006-11-03 13:35:50 -08:00
2006-08-19 06:26:11 -07:00
function_type: VOID_FUNC_CUST
2007-01-02 12:12:14 -08:00
| BOOL_FUNC_CUST
| NUM_FUNC_CUST
| USER_FUNC_CUST
| OBJ_FUNC_CUST
| STRING_FUNC_CUST
| FLOAT_FUNC_CUST
;
2006-11-03 13:35:50 -08:00
2006-08-19 06:26:11 -07:00
/* function declaration rules */
2006-09-19 09:07:06 -07:00
func_subdecl: FUNCTION TYPE IDENT
2007-01-02 12:12:14 -08:00
{
2006-08-19 06:26:11 -07:00
EVENT_SYMBOL *psEvent;
2006-11-16 06:30:29 -08:00
RULE("func_subdecl: FUNCTION TYPE IDENT");
2006-08-19 06:26:11 -07:00
/* allow local vars to have the same names as global vars (don't check global vars) */
localVariableDef = TRUE;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "localVariableDef = TRUE 1");
2006-08-19 06:26:11 -07:00
if (!scriptDeclareEvent($3, &psEvent,0))
2006-08-12 09:52:37 -07:00
{
YYABORT;
}
2006-08-19 06:26:11 -07:00
psEvent->retType = $2;
psCurEvent = psEvent;
psCurEvent->bFunction = TRUE;
2006-08-12 09:52:37 -07:00
2006-08-19 06:26:11 -07:00
$$ = psEvent;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END func_subdecl:FUNCTION TYPE IDENT. ");
2007-01-02 12:12:14 -08:00
}
2006-09-19 09:07:06 -07:00
;
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
/* void function declaration rules */
2007-01-02 12:12:14 -08:00
void_func_subdecl: FUNCTION _VOID IDENT /* declaration of a function */
2006-09-19 09:07:06 -07:00
{
EVENT_SYMBOL *psEvent;
2006-11-16 06:30:29 -08:00
RULE("void_func_subdecl: FUNCTION _VOID IDENT");
2006-09-19 09:07:06 -07:00
/* allow local vars to have the same names as global vars (don't check global vars) */
localVariableDef = TRUE;
//debug(LOG_SCRIPT, "localVariableDef = TRUE 1");
if (!scriptDeclareEvent($3, &psEvent,0))
{
YYABORT;
}
psEvent->retType = VAL_VOID;
psCurEvent = psEvent;
psCurEvent->bFunction = TRUE;
$$ = psEvent;
//debug(LOG_SCRIPT, "END func_subdecl:FUNCTION TYPE IDENT. ");
}
;
2006-11-03 13:35:50 -08:00
2007-01-02 12:12:14 -08:00
void_function_def: FUNCTION _VOID function_type /* definition of a function that was declated before */
2006-08-19 06:26:11 -07:00
{
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "func_subdecl:FUNCTION EVENT_SYM ");
psCurEvent = $3;
2006-08-19 06:26:11 -07:00
/* check if this event was declared as function before */
if(!$3->bFunction)
{
debug(LOG_ERROR, "'%s' was declared as event before and can't be redefined to function", $3->pIdent);
scr_error("Wrong event definition");
YYABORT;
}
/* psCurEvent->bFunction = TRUE; */
/* psEvent->retType = $2; */
$$ = $3;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "func_subdecl:FUNCTION EVENT_SYM. ");
2006-08-19 06:26:11 -07:00
}
2006-09-19 09:07:06 -07:00
;
2006-11-03 13:35:50 -08:00
2006-08-19 06:26:11 -07:00
2006-11-16 06:30:29 -08:00
funcvar_decl_types: TYPE NUM_VAR
2007-01-02 12:12:14 -08:00
{
$$=$1;
}
| TYPE FLOAT_VAR
{
$$=$1;
}
| TYPE BOOL_VAR
{
$$=$1;
}
| TYPE STRING_VAR
{
$$=$1;
}
| TYPE OBJ_VAR
{
$$=$1;
}
| TYPE OBJ_OBJVAR
{
$$=$1;
}
| TYPE OBJ_ARRAY
{
$$=$1;
}
| TYPE VAR /* STRUCTURESTAT, RESEARCHSTAT etc */
{
$$=$1;
}
;
2006-08-19 06:26:11 -07:00
2006-09-19 09:07:06 -07:00
funcbody_var_def_body: funcvar_decl_types
2006-08-19 06:26:11 -07:00
{
if(!checkFuncParamType(0, $1))
{
scr_error("Wrong event argument definition in '%s'", psCurEvent->pIdent);
YYABORT;
}
2006-09-19 09:07:06 -07:00
//debug(LOG_SCRIPT, "funcbody_var_def_body=%d \n", $1);
2006-08-19 06:26:11 -07:00
$$=1;
}
2006-09-19 09:07:06 -07:00
| funcbody_var_def_body ',' funcvar_decl_types
2006-08-19 06:26:11 -07:00
{
if(!checkFuncParamType($1, $3))
{
scr_error("Wrong event argument definition");
YYABORT;
}
2006-09-19 09:07:06 -07:00
//debug(LOG_SCRIPT, "funcbody_var_def_body2=%d \n", $3);
2006-08-19 06:26:11 -07:00
$$=$1+1;
}
;
2006-09-19 09:07:06 -07:00
/* function was declared before */
funcbody_var_def: function_def '(' funcbody_var_def_body ')'
{
2006-11-16 06:30:29 -08:00
RULE("funcbody_var_def: '(' funcvar_decl_types ')'");
2006-09-19 09:07:06 -07:00
/* remember that local var declaration is over */
localVariableDef = FALSE;
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
if(psCurEvent == NULL)
{
scr_error("psCurEvent == NULL");
YYABORT;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
if(!psCurEvent->bDeclared)
{
debug(LOG_ERROR, "Event %s's definition doesn't match with declaration.", psCurEvent->pIdent);
scr_error("Wrong event definition:\n event %s's definition doesn't match with declaration", psCurEvent->pIdent);
YYABORT;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
/* check if number of parameter in body defenition match number of params in the declaration */
if($3 != psCurEvent->numParams)
{
scr_error("Wrong number of arguments in function definition (or declaration-definition argument type/names mismatch) \n in event: '%s'", psCurEvent->pIdent);
YYABORT;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
$$ = $1;
}
| function_def '(' ')'
{
2006-11-16 06:30:29 -08:00
RULE( "funcbody_var_def: funcbody_var_def_body '(' ')'");
2006-09-19 09:07:06 -07:00
/* remember that local var declaration is over */
localVariableDef = FALSE;
if(psCurEvent == NULL)
{
scr_error("psCurEvent == NULL");
YYABORT;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
if(!psCurEvent->bDeclared)
{
debug(LOG_ERROR, "Event %s's definition doesn't match with declaration.", psCurEvent->pIdent);
scr_error("Wrong event definition:\n event %s's definition doesn't match with declaration", psCurEvent->pIdent);
YYABORT;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
/* check if number of parameter in body defenition match number of params in the declaration */
if(0 != psCurEvent->numParams)
{
scr_error("Wrong number of arguments in function definition (or declaration-definition argument type/names mismatch) \n in event: '%s'", psCurEvent->pIdent);
YYABORT;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
$$ = $1;
}
;
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
/* void function was declared before */
void_funcbody_var_def: void_function_def '(' funcbody_var_def_body ')'
{
2006-11-16 06:30:29 -08:00
RULE( "funcbody_var_def: '(' funcvar_decl_types ')'");
2006-09-19 09:07:06 -07:00
/* remember that local var declaration is over */
localVariableDef = FALSE;
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
if(psCurEvent == NULL)
{
scr_error("psCurEvent == NULL");
YYABORT;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
if(!psCurEvent->bDeclared)
{
debug(LOG_ERROR, "Event %s's definition doesn't match with declaration.", psCurEvent->pIdent);
scr_error("Wrong event definition:\n event %s's definition doesn't match with declaration", psCurEvent->pIdent);
YYABORT;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
/* check if number of parameter in body defenition match number of params in the declaration */
if($3 != psCurEvent->numParams)
{
scr_error("Wrong number of arguments in function definition (or declaration-definition argument type/names mismatch) \n in event: '%s'", psCurEvent->pIdent);
YYABORT;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
$$ = $1;
}
| void_function_def '(' ')'
{
2006-11-16 06:30:29 -08:00
RULE( "funcbody_var_def: funcbody_var_def_body '(' ')'");
2006-09-19 09:07:06 -07:00
/* remember that local var declaration is over */
localVariableDef = FALSE;
if(psCurEvent == NULL)
{
scr_error("psCurEvent == NULL");
YYABORT;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
if(!psCurEvent->bDeclared)
{
debug(LOG_ERROR, "Event %s's definition doesn't match with declaration.", psCurEvent->pIdent);
scr_error("Wrong event definition:\n event %s's definition doesn't match with declaration", psCurEvent->pIdent);
YYABORT;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
/* check if number of parameter in body defenition match number of params in the declaration */
if(0 != psCurEvent->numParams)
{
scr_error("Wrong number of arguments in function definition (or declaration-definition argument type/names mismatch) \n in event: '%s'", psCurEvent->pIdent);
YYABORT;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
$$ = $1;
}
;
2006-08-19 06:26:11 -07:00
/* event declaration with parameters, like: event myEvent(int Arg1, string Arg2); */
argument_decl_head: TYPE variable_ident
{
2006-11-16 06:30:29 -08:00
RULE( "argument_decl_head: TYPE variable_ident");
2006-08-19 06:26:11 -07:00
/* handle type part */
ALLOC_VARDECL(psCurrVDecl);
psCurrVDecl->storage =ST_LOCAL; /* can only be local */
psCurrVDecl->type = $1;
/* handle ident part */
if (!scriptAddVariable(psCurrVDecl, $2))
{
YYABORT;
}
FREE_VARIDENTDECL($2);
FREE_VARDECL(psCurrVDecl);
/* return the variable type */
/* $$ = psCurrVDecl; */ /* not needed? */
if(psCurEvent == NULL)
debug(LOG_ERROR, "argument_decl_head 0: - psCurEvent == NULL");
psCurEvent->numParams = psCurEvent->numParams + 1; /* remember a parameter was declared */
2006-08-22 07:28:49 -07:00
2006-08-19 06:26:11 -07:00
/* remember parameter type */
psCurEvent->aParams[0] = $1;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "argument_decl_head 0. ");
2006-08-19 06:26:11 -07:00
}
| argument_decl_head ',' TYPE variable_ident
{
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "argument_decl_head 1 ");
2006-08-19 06:26:11 -07:00
/* handle type part */
ALLOC_VARDECL(psCurrVDecl);
psCurrVDecl->storage =ST_LOCAL; /* can only be local */
psCurrVDecl->type = $3;
2006-08-22 07:28:49 -07:00
2006-08-19 06:26:11 -07:00
/* remember parameter type */
psCurEvent->aParams[psCurEvent->numParams] = $3;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "argument_decl_head 10 ");
2006-08-19 06:26:11 -07:00
/* handle ident part */
if (!scriptAddVariable(psCurrVDecl, $4))
{
YYABORT;
}
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "argument_decl_head 11 ");
2006-08-19 06:26:11 -07:00
FREE_VARIDENTDECL($4);
FREE_VARDECL(psCurrVDecl);
/* return the variable type */
/* $$ = psCurrVDecl; */ /* not needed? */
if(psCurEvent == NULL)
debug(LOG_ERROR, "argument_decl_head 0: - psCurEvent == NULL");
psCurEvent->numParams = psCurEvent->numParams + 1; /* remember a parameter was declared */
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "argument_decl_head 1. ");
2006-08-19 06:26:11 -07:00
}
;
argument_decl: '(' ')'
| '(' argument_decl_head ')'
{
/* remember that local var declaration is over */
localVariableDef = FALSE;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "localVariableDef = FALSE 1");
2006-08-19 06:26:11 -07:00
}
;
function_declaration: func_subdecl '(' argument_decl_head ')' /* function was not declared before */
{
2006-11-16 06:30:29 -08:00
RULE( "function_declaration: func_subdecl '(' argument_decl_head ')'");
2006-08-19 06:26:11 -07:00
/* remember that local var declaration is over */
localVariableDef = FALSE;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "localVariableDef = FALSE 2");
2006-08-19 06:26:11 -07:00
if(psCurEvent->bDeclared) /* can only occur if different (new) var names are used in the event definition that don't match with declaration*/
{
scr_error("Wrong event definition: \nEvent %s's definition doesn't match with declaration", psCurEvent->pIdent);
YYABORT;
}
$$ = $1;
}
| func_subdecl '(' ')'
{
2006-11-16 06:30:29 -08:00
RULE( "function_declaration: func_subdecl '(' ')'");
2006-09-19 09:07:06 -07:00
/* remember that local var declaration is over */
localVariableDef = FALSE;
//debug(LOG_SCRIPT, "localVariableDef = FALSE 3");
if($1->numParams > 0 && psCurEvent->bDeclared) /* can only occur if no parameters or different (new) var names are used in the event definition that don't match with declaration */
{
scr_error("Wrong event definition: \nEvent %s's definition doesn't match with declaration", psCurEvent->pIdent);
YYABORT;
}
$$ = $1;
}
;
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
void_function_declaration: void_func_subdecl '(' argument_decl_head ')' /* function was not declared before */
{
/* remember that local var declaration is over */
localVariableDef = FALSE;
//debug(LOG_SCRIPT, "localVariableDef = FALSE 2");
if(psCurEvent->bDeclared) /* can only occur if different (new) var names are used in the event definition that don't match with declaration*/
{
scr_error("Wrong event definition: \nEvent %s's definition doesn't match with declaration", psCurEvent->pIdent);
YYABORT;
}
$$ = $1;
}
| void_func_subdecl '(' ')'
{
2006-11-26 05:45:04 -08:00
2006-11-16 06:30:29 -08:00
RULE( "void_function_declaration: void_func_subdecl '(' ')'");
2006-11-26 05:45:04 -08:00
2006-08-19 06:26:11 -07:00
/* remember that local var declaration is over */
localVariableDef = FALSE;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "localVariableDef = FALSE 3");
2006-08-19 06:26:11 -07:00
if($1->numParams > 0 && psCurEvent->bDeclared) /* can only occur if no parameters or different (new) var names are used in the event definition that don't match with declaration */
{
scr_error("Wrong event definition: \nEvent %s's definition doesn't match with declaration", psCurEvent->pIdent);
YYABORT;
}
2006-09-19 09:07:06 -07:00
$$ = $1;
}
;
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
return_statement_void: RET ';'
;
2006-11-03 13:35:50 -08:00
2007-01-02 12:12:14 -08:00
return_statement: return_statement_void
2006-09-19 09:07:06 -07:00
{
2006-11-16 06:30:29 -08:00
RULE( "return_statement: return_statement_void");
2006-09-19 09:07:06 -07:00
if(psCurEvent == NULL) /* no events declared or defined yet */
{
scr_error("return statement outside of function");
YYABORT;
}
if(!psCurEvent->bFunction)
{
scr_error("return statement inside of an event '%s'", psCurEvent->pIdent);
YYABORT;
}
if(psCurEvent->retType != VAL_VOID)
{
scr_error("wrong return statement syntax for a non-void function '%s'", psCurEvent->pIdent);
YYABORT;
}
/* Allocate code block for exit instruction */
2006-11-16 06:30:29 -08:00
ALLOC_BLOCK(psCurrBlock, 1); //1 for opcode
2006-09-19 09:07:06 -07:00
ip = psCurrBlock->pCode;
PUT_OPCODE(ip, OP_EXIT);
psCurrBlock->type = VAL_VOID; /* make return statement of type VOID manually */
$$ = psCurrBlock;
}
| RET return_exp ';'
{
2006-11-16 06:30:29 -08:00
RULE( "return_statement: RET return_exp ';'");
2006-09-19 09:07:06 -07:00
if(psCurEvent == NULL) /* no events declared or defined yet */
{
debug(LOG_ERROR, "return statement outside of function");
YYABORT;
}
if(!psCurEvent->bFunction)
{
debug(LOG_ERROR, "return statement inside of an event '%s'", psCurEvent->pIdent);
YYABORT;
}
if(psCurEvent->retType != $2->type)
{
if(!interpCheckEquiv(psCurEvent->retType, $2->type))
{
debug(LOG_ERROR, "return type mismatch");
debug(LOG_ERROR, "wrong return statement syntax for function '%s' (%d - %d)", psCurEvent->pIdent, psCurEvent->retType, $2->type);
YYABORT;
}
}
/* Allocate code block for exit instruction */
2006-11-16 06:30:29 -08:00
ALLOC_BLOCK(psCurrBlock, $2->size + 1); //+1 for OPCODE
2006-09-19 09:07:06 -07:00
ip = psCurrBlock->pCode;
PUT_BLOCK(ip, $2);
PUT_OPCODE(ip, OP_EXIT);
/* store the type of the exp */
psCurrBlock->type = $2->type;
$$ = psCurrBlock;
//debug(LOG_SCRIPT, "END RET return_exp ';'");
}
;
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
statement_list: /* NULL token */
{
2006-11-16 06:30:29 -08:00
RULE( "statement_list: NULL");
2006-09-19 09:07:06 -07:00
// Allocate a dummy code block
ALLOC_BLOCK(psCurrBlock, 1);
psCurrBlock->size = 0;
$$ = psCurrBlock;
}
| statement
{
2006-11-16 06:30:29 -08:00
RULE("statement_list: statement");
2006-09-19 09:07:06 -07:00
$$ = $1;
}
| statement_list statement
{
2006-11-16 06:30:29 -08:00
RULE("statement_list: statement_list statement");
2006-09-19 09:07:06 -07:00
ALLOC_BLOCK(psCurrBlock, $1->size + $2->size);
2006-11-26 05:45:04 -08:00
2006-09-19 09:07:06 -07:00
ALLOC_DEBUG(psCurrBlock, $1->debugEntries +
$2->debugEntries);
ip = psCurrBlock->pCode;
/* Copy the two code blocks */
PUT_BLOCK(ip, $1);
PUT_BLOCK(ip, $2);
PUT_DEBUG(psCurrBlock, $1);
2006-11-16 06:30:29 -08:00
APPEND_DEBUG(psCurrBlock, $1->size / sizeof(INTERP_VAL), $2);
2006-11-26 05:45:04 -08:00
2006-11-16 06:30:29 -08:00
ASSERT($1 != NULL, "$1 == NULL");
ASSERT($1->psDebug != NULL, "psDebug == NULL");
2006-11-26 05:45:04 -08:00
2006-09-19 09:07:06 -07:00
FREE_DEBUG($1);
FREE_DEBUG($2);
FREE_BLOCK($1);
FREE_BLOCK($2);
2006-08-19 06:26:11 -07:00
2006-09-19 09:07:06 -07:00
/* Return the code block */
$$ = psCurrBlock;
}
;
2006-08-19 06:26:11 -07:00
event_decl: event_subdecl ';'
{
2006-11-16 06:30:29 -08:00
RULE( "event_decl: event_subdecl ';'");
2006-11-26 05:45:04 -08:00
2006-08-19 06:26:11 -07:00
psCurEvent->bDeclared = TRUE;
}
| func_subdecl argument_decl ';' /* event (function) declaration can now include parameter declaration (optional) */
{
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "localVariableDef = FALSE new ");
2006-08-19 06:26:11 -07:00
localVariableDef = FALSE;
psCurEvent->bDeclared = TRUE;
}
2006-09-19 09:07:06 -07:00
| void_func_subdecl argument_decl ';' /* event (function) declaration can now include parameter declaration (optional) */
{
2006-11-16 06:30:29 -08:00
RULE( "event_decl: void_func_subdecl argument_decl ';'");
2006-11-26 05:45:04 -08:00
2006-09-19 09:07:06 -07:00
//debug(LOG_SCRIPT, "localVariableDef = FALSE new ");
localVariableDef = FALSE;
psCurEvent->bDeclared = TRUE;
}
2006-08-19 06:26:11 -07:00
| event_subdecl '(' TRIG_SYM ')' '{' var_list statement_list '}' /* 16.08.05 - local vars support */
{
2006-11-16 06:30:29 -08:00
RULE( "event_decl: event_subdecl '(' TRIG_SYM ')'");
2006-11-26 05:45:04 -08:00
2006-08-19 06:26:11 -07:00
/* make sure this event is not declared as function */
if(psCurEvent->bFunction)
{
debug(LOG_ERROR, "Event '%s' is declared as function and can't have a trigger assigned", psCurEvent->pIdent);
scr_error("Wrong event definition");
YYABORT;
}
2006-08-21 02:34:42 -07:00
/* pop required number of paramerets passed to this event (if any) */
2006-08-19 06:26:11 -07:00
/* popArguments($1, $7, &psCurrBlock); */
/* if (!scriptDefineEvent($1, $6, $3->index)) */
if (!scriptDefineEvent($1, $7, $3->index))
{
YYABORT;
}
2006-08-21 02:34:42 -07:00
/* end of event */
2006-08-19 06:26:11 -07:00
psCurEvent = NULL;
FREE_DEBUG($7);
FREE_BLOCK($7);
2006-11-26 05:45:04 -08:00
2006-11-16 06:30:29 -08:00
RULE( "END event_decl: event_subdecl '(' TRIG_SYM ')'");
2006-11-26 05:45:04 -08:00
2006-08-19 06:26:11 -07:00
}
| event_subdecl '(' trigger_subdecl ')'
{
2006-08-12 09:52:37 -07:00
// Get the line for the implicit trigger declaration
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-11-26 05:45:04 -08:00
2006-11-16 06:30:29 -08:00
RULE( "event_decl:event_subdecl '(' trigger_subdecl ')' ");
2006-11-26 05:45:04 -08:00
2006-08-19 06:26:11 -07:00
/* make sure this event is not declared as function */
if(psCurEvent->bFunction)
{
debug(LOG_ERROR, "Event '%s' is declared as function and can't have a trigger assigned", psCurEvent->pIdent);
scr_error("Wrong event definition");
YYABORT;
}
scriptGetErrorData((SDWORD *)&debugLine, &pDummy);
2006-08-12 09:52:37 -07:00
}
2006-08-21 02:34:42 -07:00
'{' var_list statement_list '}' /* local vars support */
2006-08-12 09:52:37 -07:00
{
2006-11-16 06:30:29 -08:00
RULE("event_decl: '{' var_list statement_list '}'");
2006-08-12 09:52:37 -07:00
// Create a trigger for this event
if (!scriptAddTrigger("", $3, debugLine))
{
YYABORT;
}
FREE_TSUBDECL($3);
2006-08-19 06:26:11 -07:00
/* if (!scriptDefineEvent($1, $7, numTriggers - 1)) */
2006-08-16 04:23:43 -07:00
if (!scriptDefineEvent($1, $8, numTriggers - 1))
2006-08-12 09:52:37 -07:00
{
YYABORT;
}
2006-08-19 06:26:11 -07:00
/* end of event */
2006-08-12 09:52:37 -07:00
psCurEvent = NULL;
2006-08-16 04:23:43 -07:00
FREE_DEBUG($8);
2006-11-16 06:30:29 -08:00
FREE_BLOCK($8);
2006-08-19 06:26:11 -07:00
2006-11-16 06:30:29 -08:00
RULE( "END event_decl:event_subdecl '(' trigger_subdecl ')' .");
2006-08-12 09:52:37 -07:00
}
2006-08-19 06:26:11 -07:00
/* local vars */
2006-08-16 04:23:43 -07:00
| event_subdecl '(' INACTIVE ')' '{' var_list statement_list '}'
2006-08-12 09:52:37 -07:00
{
2006-11-16 06:30:29 -08:00
RULE( "event_subdecl '(' INACTIVE ')' '{' var_list statement_list '}'");
2006-11-26 05:45:04 -08:00
2006-08-19 06:26:11 -07:00
/* make sure this event is not declared as function */
if(psCurEvent->bFunction)
2006-08-12 09:52:37 -07:00
{
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Event '%s' is declared as function and can't have a trigger assigned", psCurEvent->pIdent);
scr_error("Wrong event definition");
2006-08-12 09:52:37 -07:00
YYABORT;
}
2006-08-19 06:26:11 -07:00
if (!scriptDefineEvent($1, $7, -1))
{
YYABORT;
}
2006-08-22 07:28:49 -07:00
2006-08-19 06:26:11 -07:00
/* end of event */
2006-08-12 09:52:37 -07:00
psCurEvent = NULL;
2006-08-16 04:23:43 -07:00
FREE_DEBUG($7);
FREE_BLOCK($7);
2006-08-19 06:26:11 -07:00
2006-11-16 06:30:29 -08:00
RULE( "END event_subdecl '(' INACTIVE ')' '{' var_list statement_list '}'");
2006-08-12 09:52:37 -07:00
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
/* VOID function that was NOT declared before */
| void_function_declaration '{' var_list statement_list '}'
2006-08-19 06:26:11 -07:00
{
2006-11-16 06:30:29 -08:00
RULE( "void_function_declaration '{' var_list statement_list '}'");
2006-11-26 05:45:04 -08:00
2006-08-19 06:26:11 -07:00
/* stays the same if no params (just gets copied) */
2006-11-16 06:30:29 -08:00
ALLOC_BLOCK(psCurrBlock, $4->size + 1 + $1->numParams); /* statement_list + opcode + numParams */
2006-08-19 06:26:11 -07:00
ip = psCurrBlock->pCode;
2006-08-22 07:28:49 -07:00
2006-08-19 06:26:11 -07:00
/* pop required number of paramerets passed to this event (if any) */
popArguments(&ip, $1->numParams);
2006-08-22 07:28:49 -07:00
2006-08-19 06:26:11 -07:00
/* Copy the two code blocks */
PUT_BLOCK(ip, $4);
PUT_OPCODE(ip, OP_EXIT); /* must exit after return */
2006-08-21 02:34:42 -07:00
2006-08-19 06:26:11 -07:00
ALLOC_DEBUG(psCurrBlock, $4->debugEntries);
PUT_DEBUG(psCurrBlock, $4);
2006-08-21 02:34:42 -07:00
2006-08-19 06:26:11 -07:00
if (!scriptDefineEvent($1, psCurrBlock, -1))
{
YYABORT;
}
2006-08-21 02:34:42 -07:00
2006-08-19 06:26:11 -07:00
FREE_DEBUG($4);
FREE_BLOCK($4);
2006-08-21 02:34:42 -07:00
/* end of event */
2006-08-19 06:26:11 -07:00
psCurEvent = NULL;
2006-08-21 02:34:42 -07:00
2006-08-19 06:26:11 -07:00
/* free block since code was copied in scriptDefineEvent() */
FREE_DEBUG(psCurrBlock);
FREE_BLOCK(psCurrBlock);
2006-11-26 05:45:04 -08:00
2006-11-16 06:30:29 -08:00
RULE( "END void_function_declaration '{' var_list statement_list '}'");
2006-08-19 06:26:11 -07:00
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
/* void function that was declared before */
| void_funcbody_var_def '{' var_list statement_list '}'
2006-08-12 09:52:37 -07:00
{
2006-11-26 05:45:04 -08:00
2006-11-16 06:30:29 -08:00
RULE( "void_funcbody_var_def '{' var_list statement_list '}'");
2006-11-26 05:45:04 -08:00
2006-08-12 09:52:37 -07:00
/* stays the same if no params (just gets copied) */
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, $4->size + sizeof(OPCODE) + (sizeof(OPCODE) * $1->numParams));
ALLOC_BLOCK(psCurrBlock, $4->size + 1 + $1->numParams); /* statements + opcode + numparams */
2006-08-12 09:52:37 -07:00
ip = psCurrBlock->pCode;
2006-08-19 06:26:11 -07:00
2006-08-21 02:34:42 -07:00
/* pop required number of paramerets passed to this event (if any) */
2006-08-19 06:26:11 -07:00
popArguments(&ip, $1->numParams);
2006-08-21 02:34:42 -07:00
2006-08-12 09:52:37 -07:00
/* Copy the old (main) code and free it */
2006-09-19 09:07:06 -07:00
PUT_BLOCK(ip, $4);
2006-08-12 09:52:37 -07:00
PUT_OPCODE(ip, OP_EXIT); /* must exit after return */
2006-08-21 02:34:42 -07:00
2006-08-12 09:52:37 -07:00
/* copy debug info */
2006-09-19 09:07:06 -07:00
ALLOC_DEBUG(psCurrBlock, $4->debugEntries);
PUT_DEBUG(psCurrBlock, $4);
2006-08-12 09:52:37 -07:00
if (!scriptDefineEvent($1, psCurrBlock, -1))
{
YYABORT;
}
2006-08-21 02:34:42 -07:00
2006-09-19 09:07:06 -07:00
FREE_DEBUG($4);
FREE_BLOCK($4);
2007-02-14 14:12:48 -08:00
FREE_BLOCK(psCurrBlock);
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
/* end of event */
psCurEvent = NULL;
2006-11-16 06:30:29 -08:00
RULE( "END void_func_subdecl '(' funcbody_var_def_body ')' '{' var_list statement_list '}'");
2006-08-12 09:52:37 -07:00
}
2006-08-19 06:26:11 -07:00
2006-09-19 09:07:06 -07:00
/* function that was NOT declared before (atleast must look like this)!!! */
| function_declaration '{' var_list statement_list return_statement '}'
2006-08-19 06:26:11 -07:00
{
2006-11-16 06:30:29 -08:00
RULE( "function_declaration '{' var_list statement_list return_statement '}'");
2006-09-19 09:07:06 -07:00
/* stays the same if no params (just gets copied) */
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, $4->size + $5->size + sizeof(OPCODE) + (sizeof(OPCODE) * $1->numParams)); /* statement_list + expression + EXIT + numParams */
ALLOC_BLOCK(psCurrBlock, $4->size + $5->size + 1 + $1->numParams); /* statement_list + return_expr + EXIT opcode + numParams */
2006-09-19 09:07:06 -07:00
ip = psCurrBlock->pCode;
2006-08-19 06:26:11 -07:00
2006-09-19 09:07:06 -07:00
/* pop required number of paramerets passed to this event (if any) */
popArguments(&ip, $1->numParams);
2006-08-19 06:26:11 -07:00
2006-09-19 09:07:06 -07:00
/* Copy the two code blocks */
PUT_BLOCK(ip, $4);
2006-08-19 06:26:11 -07:00
2006-09-19 09:07:06 -07:00
PUT_BLOCK(ip, $5);
2006-08-19 06:26:11 -07:00
2006-09-19 09:07:06 -07:00
PUT_OPCODE(ip, OP_EXIT); /* must exit after return */
2006-08-22 07:28:49 -07:00
2006-09-19 09:07:06 -07:00
ALLOC_DEBUG(psCurrBlock, $4->debugEntries);
2006-08-21 02:34:42 -07:00
2006-09-19 09:07:06 -07:00
PUT_DEBUG(psCurrBlock, $4);
if (!scriptDefineEvent($1, psCurrBlock, -1))
2006-08-19 06:26:11 -07:00
{
YYABORT;
}
2006-08-21 02:34:42 -07:00
2006-09-19 09:07:06 -07:00
FREE_DEBUG($4);
FREE_BLOCK($4);
FREE_BLOCK($5);
2006-08-21 02:34:42 -07:00
2006-09-19 09:07:06 -07:00
/* end of event */
psCurEvent = NULL;
2006-08-21 02:34:42 -07:00
2006-09-19 09:07:06 -07:00
/* free block since code was copied in scriptDefineEvent() */
FREE_DEBUG(psCurrBlock);
FREE_BLOCK(psCurrBlock);
2006-11-26 05:45:04 -08:00
2006-11-16 06:30:29 -08:00
RULE( "END function_declaration '{' var_list statement_list return_statement '}'");
2006-09-19 09:07:06 -07:00
}
2006-08-21 02:34:42 -07:00
2006-09-19 09:07:06 -07:00
/* function that WAS declared before */
2007-02-14 14:12:48 -08:00
| funcbody_var_def '{' var_list statement_list return_statement '}'
2006-09-19 09:07:06 -07:00
{
2006-11-16 06:30:29 -08:00
RULE( "func_subdecl '(' funcbody_var_def_body ')' '{' var_list statement_list return_statement '}'");
2006-11-26 05:45:04 -08:00
2006-09-19 09:07:06 -07:00
/* stays the same if no params (just gets copied) */
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, $4->size + $5->size + sizeof(OPCODE) + (sizeof(OPCODE) * $1->numParams));
ALLOC_BLOCK(psCurrBlock, $4->size + $5->size + 1 + $1->numParams); /* statements + return expr + opcode + numParams */
2006-09-19 09:07:06 -07:00
ip = psCurrBlock->pCode;
2006-08-12 09:52:37 -07:00
2006-09-19 09:07:06 -07:00
/* pop required number of paramerets passed to this event (if any) */
popArguments(&ip, $1->numParams);
2006-08-12 09:52:37 -07:00
2006-09-19 09:07:06 -07:00
/* Copy the old (main) code and free it */
PUT_BLOCK(ip, $4);
PUT_BLOCK(ip, $5);
PUT_OPCODE(ip, OP_EXIT); /* must exit after return */
2006-08-12 09:52:37 -07:00
2006-09-19 09:07:06 -07:00
/* copy debug info */
ALLOC_DEBUG(psCurrBlock, $4->debugEntries);
PUT_DEBUG(psCurrBlock, $4);
2007-02-14 14:12:48 -08:00
RULE( "debug entries %d", $4->debugEntries);
2006-09-19 09:07:06 -07:00
if (!scriptDefineEvent($1, psCurrBlock, -1))
2006-08-12 09:52:37 -07:00
{
2006-09-19 09:07:06 -07:00
YYABORT;
2006-08-12 09:52:37 -07:00
}
2006-09-19 09:07:06 -07:00
FREE_DEBUG($4);
FREE_BLOCK($4);
FREE_BLOCK($5);
2007-02-14 14:12:48 -08:00
FREE_BLOCK(psCurrBlock);
2006-08-12 09:52:37 -07:00
2006-09-19 09:07:06 -07:00
/* end of event */
psCurEvent = NULL;
2006-08-12 09:52:37 -07:00
2006-11-16 06:30:29 -08:00
RULE( "END func_subdecl '(' funcbody_var_def_body ')' '{' var_list statement_list return_statement '}'");
2007-02-14 14:12:48 -08:00
}
/* function that WAS declared before with a single return statement */
| funcbody_var_def '{' var_list return_statement '}'
{
RULE( "funcbody_var_def '{' var_list return_statement '}'");
/* stays the same if no params (just gets copied) */
ALLOC_BLOCK(psCurrBlock, $4->size + 1 + $1->numParams); /* return expr + opcode + numParams */
ip = psCurrBlock->pCode;
/* pop required number of paramerets passed to this event (if any) */
popArguments(&ip, $1->numParams);
/* Copy the old (main) code and free it */
PUT_BLOCK(ip, $4);
PUT_OPCODE(ip, OP_EXIT); /* must exit after return */
if (!scriptDefineEvent($1, psCurrBlock, -1))
{
YYABORT;
}
FREE_BLOCK($4);
FREE_BLOCK(psCurrBlock);
psCurEvent = NULL;
RULE( "END funcbody_var_def '{' var_list return_statement '}'");
}
/* function with a single return statement that was NOT declared before */
| function_declaration '{' var_list return_statement '}'
{
RULE( "function_declaration '{' var_list statement_list return_statement '}'");
/* stays the same if no params (just gets copied) */
ALLOC_BLOCK(psCurrBlock, $4->size + 1 + $1->numParams); /* return_expr + EXIT opcode + numParams */
ip = psCurrBlock->pCode;
/* pop required number of paramerets passed to this event (if any) */
popArguments(&ip, $1->numParams);
/* Copy code block */
PUT_BLOCK(ip, $4);
PUT_OPCODE(ip, OP_EXIT); /* must exit after return */
if (!scriptDefineEvent($1, psCurrBlock, -1))
{
YYABORT;
}
FREE_BLOCK($4);
psCurEvent = NULL;
FREE_BLOCK(psCurrBlock);
2006-11-26 05:45:04 -08:00
2007-02-14 14:12:48 -08:00
RULE( "END function_declaration '{' var_list statement_list return_statement '}'");
2006-09-19 09:07:06 -07:00
}
;
2006-08-19 06:26:11 -07:00
2006-09-19 09:07:06 -07:00
/**************************************************************************************
*
* Statements
*/
2006-08-19 06:26:11 -07:00
2006-08-12 09:52:37 -07:00
statement: assignment ';'
{
UDWORD line;
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-08-12 09:52:37 -07:00
2006-12-02 15:27:00 -08:00
RULE("statement: assignment");
/* Put in debugging info */
if (genDebugInfo)
{
ALLOC_DEBUG($1, 1);
$1->psDebug[0].offset = 0;
scriptGetErrorData((SDWORD *)&line, &pDummy);
$1->psDebug[0].line = line;
}
$$ = $1;
}
| inc_dec_exp ';'
{
UDWORD line;
char *pDummy;
RULE("statement: inc_dec_exp");
2006-08-12 09:52:37 -07:00
/* Put in debugging info */
if (genDebugInfo)
{
ALLOC_DEBUG($1, 1);
$1->psDebug[0].offset = 0;
2006-08-19 06:26:11 -07:00
scriptGetErrorData((SDWORD *)&line, &pDummy);
2006-08-12 09:52:37 -07:00
$1->psDebug[0].line = line;
}
$$ = $1;
}
| func_call ';'
{
UDWORD line;
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-08-12 09:52:37 -07:00
2006-11-16 06:30:29 -08:00
RULE("statement: func_call ';'");
2006-08-12 09:52:37 -07:00
/* Put in debugging info */
if (genDebugInfo)
{
ALLOC_DEBUG($1, 1);
$1->psDebug[0].offset = 0;
2006-08-19 06:26:11 -07:00
scriptGetErrorData((SDWORD *)&line, &pDummy);
2006-08-12 09:52:37 -07:00
$1->psDebug[0].line = line;
}
$$ = $1;
}
2006-08-19 06:26:11 -07:00
| VOID_FUNC_CUST '(' param_list ')' ';'
2006-08-12 09:52:37 -07:00
{
2006-08-19 06:26:11 -07:00
UDWORD line,paramNumber;
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-08-12 09:52:37 -07:00
2006-11-16 06:30:29 -08:00
RULE( "statement: VOID_FUNC_CUST '(' param_list ')' ';'");
2006-08-19 06:26:11 -07:00
/* allow to call EVENTs to reuse the code only if no actual parameters are specified in function call, like "myEvent();" */
if(!$1->bFunction && $3->numParams > 0)
{
scr_error("Can't pass any parameters in an event call:\nEvent: '%s'", $1->pIdent);
return CE_PARSE;
}
if($3->numParams != $1->numParams)
{
scr_error("Wrong number of arguments for function call: '%s'. Expected %d parameters instead of %d.", $1->pIdent, $1->numParams, $3->numParams);
return CE_PARSE;
}
2006-08-22 07:28:49 -07:00
2006-08-19 06:26:11 -07:00
/* check if right parameters were passed */
paramNumber = checkFuncParamTypes($1, $3);
if(paramNumber > 0)
{
debug(LOG_ERROR, "Parameter mismatch in function call: '%s'. Mismatch in parameter %d.", $1->pIdent, paramNumber);
YYABORT;
}
2006-08-12 09:52:37 -07:00
/* Allocate the code block */
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, $3->size + sizeof(OPCODE) + sizeof(UDWORD)); //Params + Opcode + event index
ALLOC_BLOCK(psCurrBlock, $3->size + 1 + 1); //paramList + opcode + event index
2006-08-12 09:52:37 -07:00
ALLOC_DEBUG(psCurrBlock, 1);
ip = psCurrBlock->pCode;
2006-08-19 06:26:11 -07:00
if($3->numParams > 0) /* if any parameters declared */
{
/* Copy in the code for the parameters */
PUT_BLOCK(ip, $3); //PUT_BLOCK(ip, psPBlock);
FREE_PBLOCK($3); //FREE_PBLOCK(psPBlock);
}
2006-08-12 09:52:37 -07:00
/* Store the instruction */
PUT_OPCODE(ip, OP_FUNC);
2006-11-16 06:30:29 -08:00
PUT_EVENT(ip,$1->index); //Put event index
2006-08-12 09:52:37 -07:00
/* Add the debugging information */
if (genDebugInfo)
{
psCurrBlock->psDebug[0].offset = 0;
scriptGetErrorData((SDWORD *)&line, &pDummy);
psCurrBlock->psDebug[0].line = line;
}
$$ = psCurrBlock;
}
2006-08-19 06:26:11 -07:00
| EVENT_SYM '(' param_list ')' ';' /* event as a void function to reuse the code */
{
UDWORD line;
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-08-19 06:26:11 -07:00
2006-11-16 06:30:29 -08:00
RULE( "statement: EVENT_SYM '(' param_list ')' ';'");
2006-08-19 06:26:11 -07:00
/* allow to call EVENTs to reuse the code only if no actual parameters are specified in function call, like "myEvent();" */
if(!$1->bFunction && $3->numParams > 0)
{
scr_error("Can't pass any parameters in an event call:\nEvent: '%s'", $1->pIdent);
return CE_PARSE;
}
if($3->numParams != $1->numParams)
{
scr_error("Wrong number of arguments for function call: '%s'. Expected %d parameters instead of %d.", $1->pIdent, $1->numParams, $3->numParams);
return CE_PARSE;
}
/* Allocate the code block */
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, $3->size + sizeof(OPCODE) + sizeof(UDWORD)); //Params + Opcode + event index
ALLOC_BLOCK(psCurrBlock, $3->size + 1 + 1); //Params + Opcode + event index
2006-08-19 06:26:11 -07:00
ALLOC_DEBUG(psCurrBlock, 1);
ip = psCurrBlock->pCode;
if($3->numParams > 0) /* if any parameters declared */
{
/* Copy in the code for the parameters */
PUT_BLOCK(ip, $3); //PUT_BLOCK(ip, psPBlock);
FREE_PBLOCK($3); //FREE_PBLOCK(psPBlock);
}
/* Store the instruction */
PUT_OPCODE(ip, OP_FUNC);
2006-11-16 06:30:29 -08:00
PUT_EVENT(ip,$1->index); //Put event index as VAL_EVENT
2006-08-12 09:52:37 -07:00
2006-08-19 06:26:11 -07:00
/* Add the debugging information */
if (genDebugInfo)
{
psCurrBlock->psDebug[0].offset = 0;
scriptGetErrorData((SDWORD *)&line, &pDummy);
psCurrBlock->psDebug[0].line = line;
}
2006-08-12 09:52:37 -07:00
2006-08-19 06:26:11 -07:00
$$ = psCurrBlock;
}
2006-08-12 09:52:37 -07:00
| conditional
{
$$ = $1;
}
| loop
{
$$ = $1;
}
| EXIT ';'
{
UDWORD line;
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-08-12 09:52:37 -07:00
/* Allocate the code block */
2006-11-16 06:30:29 -08:00
ALLOC_BLOCK(psCurrBlock, 1); //1 - Exit opcode
2006-08-12 09:52:37 -07:00
ALLOC_DEBUG(psCurrBlock, 1);
ip = psCurrBlock->pCode;
/* Store the instruction */
PUT_OPCODE(ip, OP_EXIT);
/* Add the debugging information */
if (genDebugInfo)
{
psCurrBlock->psDebug[0].offset = 0;
2006-08-19 06:26:11 -07:00
scriptGetErrorData((SDWORD *)&line, &pDummy);
2006-08-12 09:52:37 -07:00
psCurrBlock->psDebug[0].line = line;
}
$$ = psCurrBlock;
}
2006-08-15 11:38:51 -07:00
| return_statement
{
UDWORD line;
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-11-16 06:30:29 -08:00
RULE( "statement: return_statement");
2006-11-26 05:45:04 -08:00
2006-08-15 11:38:51 -07:00
if(psCurEvent == NULL)
{
2006-08-19 06:26:11 -07:00
scr_error("'return' outside of function body");
2006-08-15 11:38:51 -07:00
YYABORT;
}
if(!psCurEvent->bFunction)
{
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "'return' can only be used in functions, not in events, event: '%s'", psCurEvent->pIdent);
scr_error("'return' in event");
2006-08-15 11:38:51 -07:00
YYABORT;
}
if($1->type != psCurEvent->retType)
{
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "'return' type doesn't match with function return type, function: '%s' (%d / %d)", psCurEvent->pIdent, $1->type, psCurEvent->retType);
scr_error("'return' type mismatch 0");
2006-08-15 11:38:51 -07:00
YYABORT;
}
2006-11-16 06:30:29 -08:00
ALLOC_BLOCK(psCurrBlock, $1->size + 1); //return statement + EXIT opcode
2006-08-15 11:38:51 -07:00
ALLOC_DEBUG(psCurrBlock, 1);
ip = psCurrBlock->pCode;
PUT_BLOCK(ip, $1);
PUT_OPCODE(ip, OP_EXIT);
FREE_BLOCK($1);
if (genDebugInfo)
{
psCurrBlock->psDebug[0].offset = 0;
scriptGetErrorData((SDWORD *)&line, &pDummy);
psCurrBlock->psDebug[0].line = line;
}
$$ = psCurrBlock;
}
2006-08-12 09:52:37 -07:00
| PAUSE '(' INTEGER ')' ';'
{
UDWORD line;
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-08-12 09:52:37 -07:00
// can only have a positive pause
if ($3 < 0)
{
scr_error("Invalid pause time");
YYABORT;
}
/* Allocate the code block */
2006-11-16 06:30:29 -08:00
ALLOC_BLOCK(psCurrBlock, 1); //1 - for OP_PAUSE
2006-08-12 09:52:37 -07:00
ALLOC_DEBUG(psCurrBlock, 1);
ip = psCurrBlock->pCode;
/* Store the instruction */
PUT_PKOPCODE(ip, OP_PAUSE, $3);
/* Add the debugging information */
if (genDebugInfo)
{
psCurrBlock->psDebug[0].offset = 0;
2006-08-19 06:26:11 -07:00
scriptGetErrorData((SDWORD *)&line, &pDummy);
2006-08-12 09:52:37 -07:00
psCurrBlock->psDebug[0].line = line;
}
$$ = psCurrBlock;
}
;
2006-08-19 06:26:11 -07:00
/* function return type */
return_exp: expression
{
2006-11-16 06:30:29 -08:00
RULE("return_exp: expression");
2006-08-19 06:26:11 -07:00
/* Just pass the code up the tree */
$1->type = VAL_INT;
$$ = $1;
}
2006-11-16 06:30:29 -08:00
| floatexp
{
RULE("return_exp: floatexp");
/* Just pass the code up the tree */
$1->type = VAL_FLOAT;
$$ = $1;
}
2006-08-19 06:26:11 -07:00
| stringexp
{
2006-11-16 06:30:29 -08:00
RULE( "return_exp: stringexp");
2006-08-19 06:26:11 -07:00
/* Just pass the code up the tree */
$1->type = VAL_STRING;
$$ = $1;
}
| boolexp
{
2006-11-16 06:30:29 -08:00
RULE( "return_exp: boolexp");
2006-08-19 06:26:11 -07:00
/* Just pass the code up the tree */
$1->type = VAL_BOOL;
$$ = $1;
}
| objexp /* example: "group", "feature", "structure.health", "droid.numkills" */
{
2006-11-16 06:30:29 -08:00
RULE( "return_exp: objexp");
2006-08-19 06:26:11 -07:00
/* Just pass the code up the tree */
/* $1->type = */
$$ = $1;
}
;
2006-08-12 09:52:37 -07:00
/* Variable assignment statements, eg:
* foo = 4 + bar ;
*/
assignment: NUM_VAR '=' expression
{
2006-11-16 06:30:29 -08:00
RULE( "assignment: NUM_VAR '=' expression");
codeRet = scriptCodeAssignment($1, $3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
2006-08-12 09:52:37 -07:00
/* Return the code block */
$$ = psCurrBlock;
}
| BOOL_VAR '=' boolexp
{
2006-11-16 06:30:29 -08:00
RULE( "assignment: BOOL_VAR '=' boolexp");
codeRet = scriptCodeAssignment($1, $3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| FLOAT_VAR '=' floatexp
{
RULE( "assignment: FLOAT_VAR '=' floatexp");
2006-08-12 09:52:37 -07:00
codeRet = scriptCodeAssignment($1, $3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-08-19 06:26:11 -07:00
| STRING_VAR '=' stringexp
{
2006-11-16 06:30:29 -08:00
RULE("assignment: STRING_VAR '=' stringexp");
2006-08-19 06:26:11 -07:00
codeRet = scriptCodeAssignment($1, $3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-08-12 09:52:37 -07:00
| OBJ_VAR '=' objexp
{
2006-11-16 06:30:29 -08:00
RULE("assignment: OBJ_VAR '=' objexp");
2006-08-12 09:52:37 -07:00
if (!interpCheckEquiv($1->type, $3->type))
{
2006-08-19 06:26:11 -07:00
scr_error("User type mismatch for assignment (%d - %d) 4", $1->type, $3->type);
2006-08-12 09:52:37 -07:00
YYABORT;
}
codeRet = scriptCodeAssignment($1, $3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| VAR '=' userexp
{
2006-11-16 06:30:29 -08:00
RULE( "assignment: VAR '=' userexp");
2006-08-12 09:52:37 -07:00
if (!interpCheckEquiv($1->type, $3->type))
{
2006-08-19 06:26:11 -07:00
scr_error("User type mismatch for assignment (%d - %d) 3", $1->type, $3->type);
2006-08-12 09:52:37 -07:00
YYABORT;
}
codeRet = scriptCodeAssignment($1, (CODE_BLOCK *)$3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| num_objvar '=' expression
{
2006-11-16 06:30:29 -08:00
RULE( "assignment: num_objvar '=' expression");
2006-08-12 09:52:37 -07:00
codeRet = scriptCodeObjAssignment($1, $3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| bool_objvar '=' boolexp
{
2006-11-16 06:30:29 -08:00
RULE( "assignment: bool_objvar '=' boolexp");
2006-08-12 09:52:37 -07:00
codeRet = scriptCodeObjAssignment($1, $3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| user_objvar '=' userexp
{
2006-11-16 06:30:29 -08:00
RULE( "assignment: user_objvar '=' userexp");
2006-08-12 09:52:37 -07:00
if (!interpCheckEquiv($1->psObjVar->type,$3->type))
{
2006-08-19 06:26:11 -07:00
scr_error("User type mismatch for assignment (%d - %d) 2", $1->psObjVar->type, $3->type);
2006-08-12 09:52:37 -07:00
YYABORT;
}
codeRet = scriptCodeObjAssignment($1, (CODE_BLOCK *)$3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| obj_objvar '=' objexp
{
2006-11-16 06:30:29 -08:00
RULE( "assignment: obj_objvar '=' objexp");
2006-08-12 09:52:37 -07:00
if (!interpCheckEquiv($1->psObjVar->type, $3->type))
{
2006-08-19 06:26:11 -07:00
scr_error("User type mismatch for assignment (%d - %d) 1", $1->psObjVar->type, $3->type);
2006-08-12 09:52:37 -07:00
YYABORT;
}
codeRet = scriptCodeObjAssignment($1, $3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| num_array_var '=' expression
{
2006-11-16 06:30:29 -08:00
RULE( "assignment: num_array_var '=' expression");
2006-08-12 09:52:37 -07:00
codeRet = scriptCodeArrayAssignment($1, $3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| bool_array_var '=' boolexp
{
2006-11-16 06:30:29 -08:00
RULE( "assignment: bool_array_var '=' boolexp");
2006-08-12 09:52:37 -07:00
codeRet = scriptCodeArrayAssignment($1, $3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| user_array_var '=' userexp
{
2006-11-16 06:30:29 -08:00
RULE( "assignment: user_array_var '=' userexp");
2006-08-12 09:52:37 -07:00
if (!interpCheckEquiv($1->psArrayVar->type,$3->type))
{
2006-08-19 06:26:11 -07:00
scr_error("User type mismatch for assignment (%d - %d) 0", $1->psArrayVar->type, $3->type);
2006-08-12 09:52:37 -07:00
YYABORT;
}
codeRet = scriptCodeArrayAssignment($1, (CODE_BLOCK *)$3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| obj_array_var '=' objexp
{
2006-11-16 06:30:29 -08:00
RULE( "assignment: obj_array_var '=' objexp");
2006-08-12 09:52:37 -07:00
if (!interpCheckEquiv($1->psArrayVar->type, $3->type))
{
scr_error("User type mismatch for assignment");
YYABORT;
}
codeRet = scriptCodeArrayAssignment($1, $3, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
;
/* Function calls, eg:
* DisplayGlobals() ;
*
* If the function returns a value in a statement context
* code is generated to remove that value from the stack.
*/
func_call: NUM_FUNC '(' param_list ')'
{
2006-11-16 06:30:29 -08:00
RULE( "func_call: NUM_FUNC '(' param_list ')'");
2006-08-12 09:52:37 -07:00
/* Generate the code for the function call */
codeRet = scriptCodeFunction($1, $3, FALSE, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| BOOL_FUNC '(' param_list ')'
{
2006-11-16 06:30:29 -08:00
RULE( "func_call: BOOL_FUNC '(' param_list ')'");
2006-08-12 09:52:37 -07:00
/* Generate the code for the function call */
codeRet = scriptCodeFunction($1, $3, FALSE, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| USER_FUNC '(' param_list ')'
{
2006-11-16 06:30:29 -08:00
RULE( "func_call: USER_FUNC '(' param_list ')'");
2006-08-12 09:52:37 -07:00
/* Generate the code for the function call */
codeRet = scriptCodeFunction($1, $3, FALSE, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| OBJ_FUNC '(' param_list ')'
{
2006-11-16 06:30:29 -08:00
RULE( "func_call: OBJ_FUNC '(' param_list ')'");
2006-08-12 09:52:37 -07:00
/* Generate the code for the function call */
codeRet = scriptCodeFunction($1, $3, FALSE, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| FUNC '(' param_list ')'
{
2006-11-16 06:30:29 -08:00
RULE("func_call: FUNC '(' param_list ')'");
2006-11-26 05:45:04 -08:00
2006-09-19 09:07:06 -07:00
/* Generate the code for the function call */
codeRet = scriptCodeFunction($1, $3, FALSE, &psCurrBlock);
2006-11-26 05:45:04 -08:00
2006-09-19 09:07:06 -07:00
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| STRING_FUNC '(' param_list ')'
{
2006-11-16 06:30:29 -08:00
RULE( "func_call: STRING_FUNC '(' param_list ')'");
2006-11-17 09:07:03 -08:00
/* Generate the code for the function call */
codeRet = scriptCodeFunction($1, $3, FALSE, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| FLOAT_FUNC '(' param_list ')'
{
RULE( "func_call: FLOAT_FUNC '(' param_list ')'");
2006-09-19 09:07:06 -07:00
2006-08-12 09:52:37 -07:00
/* Generate the code for the function call */
codeRet = scriptCodeFunction($1, $3, FALSE, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
;
2006-08-19 06:26:11 -07:00
2006-08-12 09:52:37 -07:00
/*
* Parse parameter lists eg:
* 5, foo, (bar + 4.2) / 3, foobar and barfoo
*
* These rules return PARAM_BLOCKS which contain the type of each
* parameter as well as the code for the parameter.
*/
2006-08-19 06:26:11 -07:00
param_list: /* NULL token */
2006-08-12 09:52:37 -07:00
{
/* create a dummy pblock containing nothing */
2006-11-16 06:30:29 -08:00
//ALLOC_PBLOCK(psCurrPBlock, sizeof(UDWORD), 1);
ALLOC_PBLOCK(psCurrPBlock, 1, 1); //1 is enough
2006-08-12 09:52:37 -07:00
psCurrPBlock->size = 0;
psCurrPBlock->numParams = 0;
$$ = psCurrPBlock;
}
| parameter
{
2006-11-16 06:30:29 -08:00
RULE("param_list: parameter");
2006-08-12 09:52:37 -07:00
$$ = $1;
}
| param_list ',' parameter
{
2006-11-16 06:30:29 -08:00
RULE("param_list: param_list ',' parameter");
2006-08-22 07:28:49 -07:00
2006-11-16 06:30:29 -08:00
ALLOC_PBLOCK(psCurrPBlock, $1->size + $3->size, $1->numParams + $3->numParams);
2006-08-12 09:52:37 -07:00
ip = psCurrPBlock->pCode;
/* Copy in the code for the parameters */
PUT_BLOCK(ip, $1);
PUT_BLOCK(ip, $3);
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
/* Copy the parameter types */
memcpy(psCurrPBlock->aParams, $1->aParams,
$1->numParams * sizeof(INTERP_TYPE));
memcpy(psCurrPBlock->aParams + $1->numParams,
$3->aParams,
$3->numParams * sizeof(INTERP_TYPE));
/* Free the old pblocks */
FREE_PBLOCK($1);
FREE_PBLOCK($3);
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
/* return the pblock */
$$ = psCurrPBlock;
}
;
parameter: expression
{
2006-11-16 06:30:29 -08:00
RULE("parameter: expression");
2006-08-12 09:52:37 -07:00
/* Generate the code for the parameter */
codeRet = scriptCodeParameter($1, VAL_INT, &psCurrPBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrPBlock;
}
| boolexp
{
2006-11-16 06:30:29 -08:00
RULE("parameter: boolexp (boolexp size: %d)", $1->size);
2006-08-12 09:52:37 -07:00
/* Generate the code for the parameter */
codeRet = scriptCodeParameter($1, VAL_BOOL, &psCurrPBlock);
CHECK_CODE_ERROR(codeRet);
2006-11-16 06:30:29 -08:00
/* Return the code block */
$$ = psCurrPBlock;
}
| floatexp
{
RULE("parameter: floatexp");
/* Generate the code for the parameter */
codeRet = scriptCodeParameter($1, VAL_FLOAT, &psCurrPBlock);
CHECK_CODE_ERROR(codeRet);
2006-08-19 06:26:11 -07:00
/* Return the code block */
$$ = psCurrPBlock;
}
| stringexp
{
2006-11-16 06:30:29 -08:00
RULE("parameter: stringexp");
2006-08-19 06:26:11 -07:00
/* Generate the code for the parameter */
codeRet = scriptCodeParameter($1, VAL_STRING, &psCurrPBlock);
CHECK_CODE_ERROR(codeRet);
2006-08-12 09:52:37 -07:00
/* Return the code block */
$$ = psCurrPBlock;
}
| userexp
{
2006-11-16 06:30:29 -08:00
RULE("parameter: userexp");
2006-08-12 09:52:37 -07:00
/* Generate the code for the parameter */
codeRet = scriptCodeParameter((CODE_BLOCK *)$1, $1->type, &psCurrPBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrPBlock;
}
| objexp
{
2006-11-16 06:30:29 -08:00
RULE( "parameter: objexp");
2006-08-12 09:52:37 -07:00
/* Generate the code for the parameter */
codeRet = scriptCodeParameter($1, $1->type, &psCurrPBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrPBlock;
}
| var_ref
{
/* just pass the variable reference up the tree */
$$ = $1;
}
;
var_ref: REF NUM_VAR
{
codeRet = scriptCodeVarRef($2, &psCurrPBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrPBlock;
}
2006-11-16 06:30:29 -08:00
| REF FLOAT_VAR
{
codeRet = scriptCodeVarRef($2, &psCurrPBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrPBlock;
}
2006-08-12 09:52:37 -07:00
| REF BOOL_VAR
{
codeRet = scriptCodeVarRef($2, &psCurrPBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrPBlock;
}
2006-08-19 06:26:11 -07:00
| REF STRING_VAR
{
codeRet = scriptCodeVarRef($2, &psCurrPBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrPBlock;
}
2006-08-12 09:52:37 -07:00
| REF VAR
{
codeRet = scriptCodeVarRef($2, &psCurrPBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrPBlock;
}
| REF OBJ_VAR
{
codeRet = scriptCodeVarRef($2, &psCurrPBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrPBlock;
}
;
/*
* Conditional statements, can be :
*
*/
conditional: cond_clause_list
{
2006-11-16 06:30:29 -08:00
RULE( "conditional: cond_clause_list");
2006-08-12 09:52:37 -07:00
codeRet = scriptCodeConditional($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
$$ = psCurrBlock;
}
| cond_clause_list ELSE terminal_cond
{
2006-11-16 06:30:29 -08:00
RULE( "conditional: cond_clause_list ELSE terminal_cond");
ALLOC_CONDBLOCK(psCondBlock, $1->numOffsets + $3->numOffsets, $1->size + $3->size);
2006-08-12 09:52:37 -07:00
ALLOC_DEBUG(psCondBlock, $1->debugEntries + $3->debugEntries);
ip = psCondBlock->pCode;
/* Store the two blocks of code */
PUT_BLOCK(ip, $1);
PUT_BLOCK(ip, $3);
/* Copy over the offset information */
/* (There isn't any in the terminal_cond) */
memcpy(psCondBlock->aOffsets, $1->aOffsets,
$1->numOffsets * sizeof(SDWORD));
psCondBlock->numOffsets = $1->numOffsets;
/* Put in the debugging information */
PUT_DEBUG(psCondBlock, $1);
2006-11-16 06:30:29 -08:00
APPEND_DEBUG(psCondBlock, $1->size, $3);
2006-08-12 09:52:37 -07:00
/* Free the code blocks */
FREE_DEBUG($1);
FREE_DEBUG($3);
FREE_CONDBLOCK($1);
FREE_CONDBLOCK($3);
/* Do the final processing of the conditional */
codeRet = scriptCodeConditional(psCondBlock, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
$$ = psCurrBlock;
}
;
cond_clause_list: cond_clause
{
2006-11-16 06:30:29 -08:00
RULE( "cond_clause_list: cond_clause");
2006-08-12 09:52:37 -07:00
$$ = $1;
}
| cond_clause_list ELSE cond_clause
{
2006-11-16 06:30:29 -08:00
RULE( "cond_clause_list: cond_clause_list ELSE cond_clause");
2006-08-12 09:52:37 -07:00
ALLOC_CONDBLOCK(psCondBlock,
$1->numOffsets + $3->numOffsets,
$1->size + $3->size);
ALLOC_DEBUG(psCondBlock, $1->debugEntries + $3->debugEntries);
ip = psCondBlock->pCode;
/* Store the two blocks of code */
PUT_BLOCK(ip, $1);
PUT_BLOCK(ip, $3);
/* Copy over the offset information */
memcpy(psCondBlock->aOffsets, $1->aOffsets,
$1->numOffsets * sizeof(SDWORD));
psCondBlock->aOffsets[$1->numOffsets] =
2006-11-16 06:30:29 -08:00
$3->aOffsets[0] + $1->size;
2006-08-12 09:52:37 -07:00
psCondBlock->numOffsets = $1->numOffsets + 1;
/* Put in the debugging information */
PUT_DEBUG(psCondBlock, $1);
2006-11-16 06:30:29 -08:00
APPEND_DEBUG(psCondBlock, $1->size, $3);
2006-08-12 09:52:37 -07:00
/* Free the code blocks */
FREE_DEBUG($1);
FREE_DEBUG($3);
FREE_CONDBLOCK($1);
FREE_CONDBLOCK($3);
$$ = psCondBlock;
}
;
terminal_cond: '{' statement_list '}'
{
2006-11-16 06:30:29 -08:00
RULE( "terminal_cond: '{' statement_list '}'");
2006-08-12 09:52:37 -07:00
/* Allocate the block */
ALLOC_CONDBLOCK(psCondBlock, 1, $2->size);
ALLOC_DEBUG(psCondBlock, $2->debugEntries);
ip = psCondBlock->pCode;
/* Put in the debugging information */
PUT_DEBUG(psCondBlock, $2);
/* Store the statements */
PUT_BLOCK(ip, $2);
FREE_DEBUG($2);
FREE_BLOCK($2);
$$ = psCondBlock;
}
;
cond_clause: IF '(' boolexp ')'
{
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-11-16 06:30:29 -08:00
RULE( "cond_clause: IF '(' boolexp ')' '{' statement_list '}'");
2006-08-12 09:52:37 -07:00
/* Get the line number for the end of the boolean expression */
/* and store it in debugLine. */
2006-08-19 06:26:11 -07:00
scriptGetErrorData((SDWORD *)&debugLine, &pDummy);
2006-08-12 09:52:37 -07:00
}
2007-01-02 12:12:14 -08:00
'{' statement_list '}'
2006-08-12 09:52:37 -07:00
{
/* Allocate the block */
2006-10-08 01:06:46 -07:00
ALLOC_CONDBLOCK(psCondBlock, 1, //1 offset
2006-08-22 07:28:49 -07:00
$3->size + $7->size +
2006-11-16 06:30:29 -08:00
1 + 1); //size + size + OP_JUMPFALSE + OP_JUMP
2006-11-26 05:45:04 -08:00
2006-08-12 09:52:37 -07:00
ALLOC_DEBUG(psCondBlock, $7->debugEntries + 1);
ip = psCondBlock->pCode;
/* Store the boolean expression code */
PUT_BLOCK(ip, $3);
FREE_BLOCK($3);
/* Put in the jump to the end of the block if the */
/* condition is false */
2006-11-16 06:30:29 -08:00
PUT_PKOPCODE(ip, OP_JUMPFALSE, $7->size + 2);
2006-08-12 09:52:37 -07:00
/* Put in the debugging information */
if (genDebugInfo)
{
psCondBlock->debugEntries = 1;
psCondBlock->psDebug->line = debugLine;
psCondBlock->psDebug->offset = 0;
APPEND_DEBUG(psCondBlock, ip - psCondBlock->pCode, $7);
}
/* Store the statements */
PUT_BLOCK(ip, $7);
FREE_DEBUG($7);
FREE_BLOCK($7);
/* Store the location that has to be filled in */
2006-11-16 06:30:29 -08:00
//TODO: don't want to store pointers as ints
psCondBlock->aOffsets[0] = (UDWORD)(ip - psCondBlock->pCode);
2006-08-12 09:52:37 -07:00
/* Put in a jump to skip the rest of the conditional */
/* The correct offset will be set once the whole */
/* conditional has been parsed */
2006-10-08 01:06:46 -07:00
/* The jump should be to the instruction after the */
/* entire conditonal block */
PUT_PKOPCODE(ip, OP_JUMP, 0);
$$ = psCondBlock;
}
2006-11-03 13:35:50 -08:00
/* 'Monoblock' */
2007-01-02 12:12:14 -08:00
| IF '(' boolexp ')'
2006-10-08 01:06:46 -07:00
{
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-11-16 06:30:29 -08:00
RULE( "cond_clause: IF '(' boolexp ')' statement");
2006-10-08 01:06:46 -07:00
/* Get the line number for the end of the boolean expression */
/* and store it in debugLine. */
scriptGetErrorData((SDWORD *)&debugLine, &pDummy);
}
statement
{
/* Allocate the block */
ALLOC_CONDBLOCK(psCondBlock, 1,
$3->size + $6->size +
2006-11-16 06:30:29 -08:00
1 + 1); //size + size + opcode + opcode
2006-11-26 05:45:04 -08:00
2006-10-08 01:06:46 -07:00
ALLOC_DEBUG(psCondBlock, $6->debugEntries + 1);
ip = psCondBlock->pCode;
2006-11-03 13:35:50 -08:00
2006-10-08 01:06:46 -07:00
/* Store the boolean expression code */
PUT_BLOCK(ip, $3);
FREE_BLOCK($3);
/* Put in the jump to the end of the block if the */
/* condition is false */
2006-11-16 06:30:29 -08:00
PUT_PKOPCODE(ip, OP_JUMPFALSE, $6->size + 2);
2006-10-08 01:06:46 -07:00
/* Put in the debugging information */
if (genDebugInfo)
{
psCondBlock->debugEntries = 1;
psCondBlock->psDebug->line = debugLine;
psCondBlock->psDebug->offset = 0;
APPEND_DEBUG(psCondBlock, ip - psCondBlock->pCode, $6);
}
/* Store the statements */
PUT_BLOCK(ip, $6);
FREE_DEBUG($6);
FREE_BLOCK($6);
/* Store the location that has to be filled in */
2006-11-16 06:30:29 -08:00
psCondBlock->aOffsets[0] = (UDWORD)(ip - psCondBlock->pCode);
2006-10-08 01:06:46 -07:00
/* Put in a jump to skip the rest of the conditional */
/* The correct offset will be set once the whole */
/* conditional has been parsed */
2006-08-12 09:52:37 -07:00
/* The jump should be to the instruction after the */
/* entire conditonal block */
PUT_PKOPCODE(ip, OP_JUMP, 0);
$$ = psCondBlock;
}
;
/*
* while loops, e.g.
*
* while (i < 5)
* {
* ....
* i = i + 1;
* }
*/
2007-01-02 12:12:14 -08:00
loop: WHILE '(' boolexp ')'
2006-08-12 09:52:37 -07:00
{
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-08-12 09:52:37 -07:00
/* Get the line number for the end of the boolean expression */
/* and store it in debugLine. */
2006-08-19 06:26:11 -07:00
scriptGetErrorData((SDWORD *)&debugLine, &pDummy);
2006-08-12 09:52:37 -07:00
}
'{' statement_list '}'
{
2006-11-16 06:30:29 -08:00
RULE("loop: WHILE '(' boolexp ')'");
2006-08-12 09:52:37 -07:00
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, $3->size + $7->size + sizeof(OPCODE) * 2);
ALLOC_BLOCK(psCurrBlock, $3->size + $7->size + 1 + 1); //size + size + opcode + opcode
2006-11-26 05:45:04 -08:00
2006-08-12 09:52:37 -07:00
ALLOC_DEBUG(psCurrBlock, $7->debugEntries + 1);
ip = psCurrBlock->pCode;
/* Copy in the loop expression */
PUT_BLOCK(ip, $3);
FREE_BLOCK($3);
/* Now a conditional jump out of the loop if the */
/* expression is false. */
2006-11-16 06:30:29 -08:00
PUT_PKOPCODE(ip, OP_JUMPFALSE, $7->size + 2);
2006-08-12 09:52:37 -07:00
/* Now put in the debugging information */
if (genDebugInfo)
{
psCurrBlock->debugEntries = 1;
psCurrBlock->psDebug->line = debugLine;
psCurrBlock->psDebug->offset = 0;
APPEND_DEBUG(psCurrBlock, ip - psCurrBlock->pCode, $7);
}
/* Copy in the body of the loop */
PUT_BLOCK(ip, $7);
FREE_DEBUG($7);
FREE_BLOCK($7);
/* Put in a jump back to the start of the loop expression */
2006-11-16 06:30:29 -08:00
PUT_PKOPCODE(ip, OP_JUMP, (SWORD)( -(SWORD)(psCurrBlock->size) + 1));
2006-08-12 09:52:37 -07:00
$$ = psCurrBlock;
}
;
2006-12-02 15:27:00 -08:00
/* Increment/Decrement expressions */
inc_dec_exp: NUM_VAR _INC
{
RULE("expression: NUM_VAR++");
2006-12-06 10:57:17 -08:00
scriptCodeIncDec($1, &psCurrBlock, OP_INC);
2006-12-02 15:27:00 -08:00
/* Return the code block */
$$ = psCurrBlock;
}
| NUM_VAR _DEC
{
RULE("expression: NUM_VAR--");
2006-12-06 10:57:17 -08:00
scriptCodeIncDec($1, &psCurrBlock, OP_DEC);
2006-12-02 15:27:00 -08:00
/* Return the code block */
$$ = psCurrBlock;
}
;
2006-08-19 06:26:11 -07:00
2006-08-12 09:52:37 -07:00
/**************************************************************************************
*
* Mathematical expressions
*/
expression: expression '+' expression
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_ADD, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| expression '-' expression
{
2006-08-19 06:26:11 -07:00
codeRet = scriptCodeBinaryOperator($1, $3, OP_SUB, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| expression '*' expression
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_MUL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| expression '/' expression
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_DIV, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| '-' expression %prec UMINUS
{
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, $2->size + sizeof(OPCODE));
ALLOC_BLOCK(psCurrBlock, $2->size + 1); //size + unary minus opcode
2006-08-19 06:26:11 -07:00
ip = psCurrBlock->pCode;
/* Copy the already generated bits of code into the code block */
PUT_BLOCK(ip, $2);
/* Now put a negation operator into the code */
PUT_PKOPCODE(ip, OP_UNARYOP, OP_NEG);
/* Free the two code blocks that have been copied */
FREE_BLOCK($2);
/* Return the code block */
$$ = psCurrBlock;
}
| '(' expression ')'
{
/* Just pass the code up the tree */
$$ = $2;
}
2006-11-16 06:30:29 -08:00
| TO_INT_CAST floatexp
{
RULE("expression: (int) floatexp");
/* perform cast */
$2->type = VAL_INT;
//ALLOC_BLOCK(psCurrBlock, $4->size + sizeof(OPCODE));
ALLOC_BLOCK(psCurrBlock, $2->size + 1); //size + opcode
ip = psCurrBlock->pCode;
PUT_BLOCK(ip, $2);
PUT_OPCODE(ip, OP_TO_INT);
$$ = psCurrBlock;
}
2006-08-19 06:26:11 -07:00
| NUM_FUNC '(' param_list ')'
{
2006-11-16 06:30:29 -08:00
RULE( "expression: NUM_FUNC '(' param_list ')'");
2006-08-19 06:26:11 -07:00
/* Generate the code for the function call */
codeRet = scriptCodeFunction($1, $3, TRUE, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| NUM_FUNC_CUST '(' param_list ')'
{
2006-12-02 15:27:00 -08:00
UDWORD line,paramNumber;
char *pDummy;
2006-08-19 06:26:11 -07:00
2006-11-16 06:30:29 -08:00
RULE( "expression: NUM_FUNC_CUST '(' param_list ')'");
2006-12-02 15:27:00 -08:00
/* if($4->numParams != $3->numParams) */
if($3->numParams != $1->numParams)
{
debug(LOG_ERROR, "Wrong number of arguments for function call: '%s'. Expected %d parameters instead of %d.", $1->pIdent, $1->numParams, $3->numParams);
scr_error("Wrong number of arguments in function call");
return CE_PARSE;
}
2006-08-19 06:26:11 -07:00
2006-12-02 15:27:00 -08:00
if(!$1->bFunction)
{
debug(LOG_ERROR, "'%s' is not a function", $1->pIdent);
scr_error("Can't call an event");
return CE_PARSE;
}
2006-08-19 06:26:11 -07:00
2006-12-02 15:27:00 -08:00
/* make sure function has a return type */
if($1->retType != VAL_INT)
{
debug(LOG_ERROR, "'%s' does not return an integer value", $1->pIdent);
scr_error("assignment type conflict");
return CE_PARSE;
}
2006-08-22 07:28:49 -07:00
2006-12-02 15:27:00 -08:00
/* check if right parameters were passed */
paramNumber = checkFuncParamTypes($1, $3);
if(paramNumber > 0)
{
debug(LOG_ERROR, "Parameter mismatch in function call: '%s'. Mismatch in parameter %d.", $1->pIdent, paramNumber);
YYABORT;
}
2006-08-19 06:26:11 -07:00
2006-12-02 15:27:00 -08:00
/* Allocate the code block */
//ALLOC_BLOCK(psCurrBlock, $3->size + sizeof(OPCODE) + sizeof(UDWORD)); //Params + Opcode + event index
ALLOC_BLOCK(psCurrBlock, $3->size + 1 + 1); //Params + Opcode + event index
2006-11-26 05:45:04 -08:00
2006-12-02 15:27:00 -08:00
ALLOC_DEBUG(psCurrBlock, 1);
ip = psCurrBlock->pCode;
2006-08-19 06:26:11 -07:00
2006-12-02 15:27:00 -08:00
if($3->numParams > 0) /* if any parameters declared */
{
/* Copy in the code for the parameters */
PUT_BLOCK(ip, $3); //PUT_BLOCK(ip, psPBlock);
FREE_PBLOCK($3); //FREE_PBLOCK(psPBlock);
}
2006-08-19 06:26:11 -07:00
2006-12-02 15:27:00 -08:00
/* Store the instruction */
PUT_OPCODE(ip, OP_FUNC);
PUT_EVENT(ip,$1->index); //Put event index
2006-08-19 06:26:11 -07:00
2006-12-02 15:27:00 -08:00
/* Add the debugging information */
if (genDebugInfo)
{
psCurrBlock->psDebug[0].offset = 0;
scriptGetErrorData((SDWORD *)&line, &pDummy);
psCurrBlock->psDebug[0].line = line;
}
2006-08-19 06:26:11 -07:00
2006-12-02 15:27:00 -08:00
$$ = psCurrBlock;
2006-08-19 06:26:11 -07:00
}
| NUM_VAR
{
2006-11-16 06:30:29 -08:00
RULE("expression: NUM_VAR");
2006-08-19 06:26:11 -07:00
codeRet = scriptCodeVarGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| NUM_CONSTANT
{
2006-11-16 06:30:29 -08:00
RULE("expression: NUM_CONSTANT");
2006-08-19 06:26:11 -07:00
codeRet = scriptCodeConstant($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| num_objvar
{
2006-11-16 06:30:29 -08:00
RULE( "expression: num_objvar");
RULE( "type=%d", $1->psObjVar->type);
2006-08-19 06:26:11 -07:00
codeRet = scriptCodeObjGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| num_array_var
{
codeRet = scriptCodeArrayGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| INTEGER
{
2006-11-16 06:30:29 -08:00
RULE("expression: INTEGER");
//ALLOC_BLOCK(psCurrBlock, sizeof(OPCODE) + sizeof(UDWORD));
ALLOC_BLOCK(psCurrBlock, 1 + 1); //opcode + integer value
2006-08-19 06:26:11 -07:00
ip = psCurrBlock->pCode;
/* Code to store the value on the stack */
PUT_PKOPCODE(ip, OP_PUSH, VAL_INT);
2006-11-16 06:30:29 -08:00
PUT_DATA_INT(ip, $1);
/* Return the code block */
$$ = psCurrBlock;
}
;
floatexp: floatexp '+' floatexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_ADD, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| floatexp '-' floatexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_SUB, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| floatexp '*' floatexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_MUL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| floatexp '/' floatexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_DIV, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| TO_FLOAT_CAST expression
{
RULE("floatexp: (float) expression");
/* perform cast */
$2->type = VAL_FLOAT;
//ALLOC_BLOCK(psCurrBlock, $4->size + sizeof(OPCODE));
ALLOC_BLOCK(psCurrBlock, $2->size + 1); //size + opcode
ip = psCurrBlock->pCode;
PUT_BLOCK(ip, $2);
PUT_OPCODE(ip, OP_TO_FLOAT);
$$ = psCurrBlock;
}
| '-' floatexp %prec UMINUS
{
//ALLOC_BLOCK(psCurrBlock, $2->size + sizeof(OPCODE));
ALLOC_BLOCK(psCurrBlock, $2->size + 1); //size + opcode
ip = psCurrBlock->pCode;
/* Copy the already generated bits of code into the code block */
PUT_BLOCK(ip, $2);
/* Now put a negation operator into the code */
PUT_PKOPCODE(ip, OP_UNARYOP, OP_NEG);
/* Free the two code blocks that have been copied */
FREE_BLOCK($2);
/* Return the code block */
$$ = psCurrBlock;
}
| '(' floatexp ')'
{
/* Just pass the code up the tree */
$$ = $2;
}
2006-11-17 09:07:03 -08:00
| FLOAT_FUNC '(' param_list ')'
{
RULE("floatexp: FLOAT_FUNC '(' param_list ')'");
/* Generate the code for the function call */
codeRet = scriptCodeFunction($1, $3, TRUE, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| FLOAT_FUNC_CUST '(' param_list ')'
{
UDWORD line,paramNumber;
char *pDummy;
RULE("floatexp: FLOAT_FUNC_CUST '(' param_list ')'");
if($3->numParams != $1->numParams)
{
debug(LOG_ERROR, "Wrong number of arguments for function call: '%s'. Expected %d parameters instead of %d.", $1->pIdent, $1->numParams, $3->numParams);
scr_error("Wrong number of arguments in function call");
return CE_PARSE;
}
if(!$1->bFunction)
{
debug(LOG_ERROR, "'%s' is not a function", $1->pIdent);
scr_error("Can't call an event");
return CE_PARSE;
}
/* make sure function has a return type */
if($1->retType != VAL_FLOAT)
{
debug(LOG_ERROR, "'%s' does not return a float value", $1->pIdent);
scr_error("assignment type conflict");
return CE_PARSE;
}
/* check if right parameters were passed */
paramNumber = checkFuncParamTypes($1, $3);
if(paramNumber > 0)
{
debug(LOG_ERROR, "Parameter mismatch in function call: '%s'. Mismatch in parameter %d.", $1->pIdent, paramNumber);
YYABORT;
}
/* Allocate the code block */
//ALLOC_BLOCK(psCurrBlock, $3->size + sizeof(OPCODE) + sizeof(UDWORD)); //Params + Opcode + event index
ALLOC_BLOCK(psCurrBlock, $3->size + 1 + 1); //Params + Opcode + event index
ALLOC_DEBUG(psCurrBlock, 1);
ip = psCurrBlock->pCode;
if($3->numParams > 0) /* if any parameters declared */
{
/* Copy in the code for the parameters */
PUT_BLOCK(ip, $3);
FREE_PBLOCK($3);
}
/* Store the instruction */
PUT_OPCODE(ip, OP_FUNC);
PUT_EVENT(ip,$1->index); //Put event/function index
/* Add the debugging information */
if (genDebugInfo)
{
psCurrBlock->psDebug[0].offset = 0;
scriptGetErrorData((SDWORD *)&line, &pDummy);
psCurrBlock->psDebug[0].line = line;
}
$$ = psCurrBlock;
}
2006-11-16 06:30:29 -08:00
| FLOAT_VAR
{
RULE( "floatexp: FLOAT_VAR");
codeRet = scriptCodeVarGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| FLOAT_T
{
RULE( "floatexp: FLOAT_T");
//ALLOC_BLOCK(psCurrBlock, sizeof(OPCODE) + sizeof(float));
ALLOC_BLOCK(psCurrBlock, 1 + 1); //opcode + float
ip = psCurrBlock->pCode;
/* Code to store the value on the stack */
PUT_PKOPCODE(ip, OP_PUSH, VAL_FLOAT);
PUT_DATA_FLOAT(ip, $1);
2006-11-26 05:45:04 -08:00
2006-11-16 06:30:29 -08:00
debug(LOG_WZ, "putting float '%f'", $1);
2006-08-12 09:52:37 -07:00
/* Return the code block */
$$ = psCurrBlock;
}
2006-08-19 06:26:11 -07:00
;
2006-08-22 07:28:49 -07:00
2006-08-19 06:26:11 -07:00
/***************************************************************************************
2006-08-22 07:28:49 -07:00
*
2006-08-19 06:26:11 -07:00
* String expressions
*/
stringexp:
2006-11-16 06:30:29 -08:00
stringexp '&' stringexp
2006-08-12 09:52:37 -07:00
{
2006-11-16 06:30:29 -08:00
RULE("stringexp: stringexp '&' stringexp");
2006-08-22 07:28:49 -07:00
2006-11-16 06:30:29 -08:00
codeRet = scriptCodeBinaryOperator($1, $3, OP_CONC, &psCurrBlock);
2006-08-12 09:52:37 -07:00
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END stringexp: stringexp '&' stringexp");
2006-08-12 09:52:37 -07:00
}
2006-11-16 06:30:29 -08:00
| stringexp '&' expression
2006-08-12 09:52:37 -07:00
{
2006-11-17 09:07:03 -08:00
RULE( "stringexp: stringexp '&' expression");
2006-11-16 06:30:29 -08:00
codeRet = scriptCodeBinaryOperator($1, $3, OP_CONC, &psCurrBlock);
2006-08-12 09:52:37 -07:00
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-11-16 06:30:29 -08:00
| expression '&' stringexp
2006-08-12 09:52:37 -07:00
{
2006-11-17 09:07:03 -08:00
RULE( "stringexp: expression '&' stringexp");
2006-11-16 06:30:29 -08:00
codeRet = scriptCodeBinaryOperator($1, $3, OP_CONC, &psCurrBlock);
2006-08-19 06:26:11 -07:00
CHECK_CODE_ERROR(codeRet);
2006-08-12 09:52:37 -07:00
/* Return the code block */
$$ = psCurrBlock;
}
2006-10-24 06:05:40 -07:00
| stringexp '&' boolexp
{
2006-11-17 09:07:03 -08:00
RULE( "stringexp: stringexp '&' boolexp");
2006-11-16 06:30:29 -08:00
codeRet = scriptCodeBinaryOperator($1, $3, OP_CONC, &psCurrBlock);
2006-10-24 06:05:40 -07:00
CHECK_CODE_ERROR(codeRet);
2006-08-22 07:28:49 -07:00
2006-10-24 06:05:40 -07:00
/* Return the code block */
$$ = psCurrBlock;
}
| boolexp '&' stringexp
{
2006-11-17 09:07:03 -08:00
RULE( "stringexp: boolexp '&' stringexp");
codeRet = scriptCodeBinaryOperator($1, $3, OP_CONC, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| stringexp '&' floatexp
{
RULE( "stringexp: stringexp '&' floatexp");
codeRet = scriptCodeBinaryOperator($1, $3, OP_CONC, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| floatexp '&' stringexp
{
RULE( "stringexp: floatexp '&' stringexp");
2006-11-16 06:30:29 -08:00
codeRet = scriptCodeBinaryOperator($1, $3, OP_CONC, &psCurrBlock);
2006-10-24 06:05:40 -07:00
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-08-19 06:26:11 -07:00
| '(' stringexp ')'
2006-08-12 09:52:37 -07:00
{
/* Just pass the code up the tree */
$$ = $2;
}
2006-11-03 13:35:50 -08:00
2006-09-19 09:07:06 -07:00
| STRING_FUNC '(' param_list ')'
{
2006-11-16 06:30:29 -08:00
RULE("stringexp: STRING_FUNC '(' param_list ')'");
2006-09-19 09:07:06 -07:00
/* Generate the code for the function call */
codeRet = scriptCodeFunction($1, $3, TRUE, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
2006-08-19 06:26:11 -07:00
2006-09-19 09:07:06 -07:00
/* Return the code block */
$$ = psCurrBlock;
}
2006-08-19 06:26:11 -07:00
| STRING_FUNC_CUST '(' param_list ')'
2006-08-12 09:52:37 -07:00
{
2006-08-19 06:26:11 -07:00
UDWORD line;
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-08-12 09:52:37 -07:00
2006-11-16 06:30:29 -08:00
RULE("stringexp: STRING_FUNC_CUST '(' param_list ')'");
2006-08-19 06:26:11 -07:00
if($3->numParams != $1->numParams)
{
debug(LOG_ERROR, "Wrong number of arguments for function call: '%s'. Expected %d parameters instead of %d.", $1->pIdent, $1->numParams, $3->numParams);
scr_error("Wrong number of arguments in function call");
return CE_PARSE;
}
if(!$1->bFunction)
{
debug(LOG_ERROR, "'%s' is not a function", $1->pIdent);
2006-11-17 09:07:03 -08:00
scr_error("Can't call an event");
2006-08-19 06:26:11 -07:00
return CE_PARSE;
}
/* make sure function has a return type */
if($1->retType != VAL_STRING)
{
debug(LOG_ERROR, "'%s' does not return a string value", $1->pIdent);
scr_error("assignment type conflict");
return CE_PARSE;
}
/* Allocate the code block */
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, $3->size + sizeof(OPCODE) + sizeof(UDWORD)); //Params + Opcode + event index
ALLOC_BLOCK(psCurrBlock, $3->size + 1 + 1); //Params + Opcode + event index
2006-08-19 06:26:11 -07:00
ALLOC_DEBUG(psCurrBlock, 1);
ip = psCurrBlock->pCode;
if($3->numParams > 0) /* if any parameters declared */
{
/* Copy in the code for the parameters */
2006-11-16 06:30:29 -08:00
PUT_BLOCK(ip, $3);
FREE_PBLOCK($3);
2006-08-19 06:26:11 -07:00
}
/* Store the instruction */
PUT_OPCODE(ip, OP_FUNC);
2006-11-16 06:30:29 -08:00
PUT_EVENT(ip,$1->index); //Put event index
2006-08-19 06:26:11 -07:00
/* Add the debugging information */
if (genDebugInfo)
{
psCurrBlock->psDebug[0].offset = 0;
scriptGetErrorData((SDWORD *)&line, &pDummy);
psCurrBlock->psDebug[0].line = line;
}
$$ = psCurrBlock;
2006-08-12 09:52:37 -07:00
}
2006-08-19 06:26:11 -07:00
| STRING_VAR
2006-08-12 09:52:37 -07:00
{
2006-11-16 06:30:29 -08:00
RULE("stringexpr: STRING_VAR");
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
codeRet = scriptCodeVarGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-08-19 06:26:11 -07:00
| QTEXT
2006-08-12 09:52:37 -07:00
{
2006-11-16 06:30:29 -08:00
RULE("QTEXT: '%s'", yyvsp[0].sval);
//ALLOC_BLOCK(psCurrBlock, sizeof(OPCODE) + sizeof(UDWORD));
ALLOC_BLOCK(psCurrBlock, 1 + 1); //opcode + string pointer
2006-08-22 07:28:49 -07:00
2006-08-19 06:26:11 -07:00
ip = psCurrBlock->pCode;
2006-08-12 09:52:37 -07:00
2006-08-19 06:26:11 -07:00
/* Code to store the value on the stack */
PUT_PKOPCODE(ip, OP_PUSH, VAL_STRING);
2006-11-16 06:30:29 -08:00
PUT_DATA_STRING(ip, STRSTACK[CURSTACKSTR]);
2006-08-12 09:52:37 -07:00
/* Return the code block */
$$ = psCurrBlock;
2006-08-19 06:26:11 -07:00
/* Manage string stack */
2007-06-04 09:49:58 -07:00
strncpy(STRSTACK[CURSTACKSTR], yyvsp[0].sval, sizeof(STRSTACK[CURSTACKSTR]));
// Terminate the string with a NUL character
STRSTACK[CURSTACKSTR][sizeof(STRSTACK[CURSTACKSTR]) - 1] = '\0';
2006-08-19 06:26:11 -07:00
CURSTACKSTR = CURSTACKSTR + 1; /* Increment 'pointer' to the top of the string stack */
2006-08-22 07:28:49 -07:00
2007-01-02 12:12:14 -08:00
if(CURSTACKSTR >= MAXSTACKLEN)
{
scr_error("Can't store more than %d strings", MAXSTACKLEN);
}
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END QTEXT found");
2006-08-12 09:52:37 -07:00
}
2006-10-24 06:05:40 -07:00
| expression
2006-08-12 09:52:37 -07:00
{
2006-11-17 09:07:03 -08:00
RULE( "stringexp: expression");
2006-10-24 06:05:40 -07:00
/* Just pass the code up the tree */
$$ = $1;
2006-11-17 09:07:03 -08:00
}
2006-08-12 09:52:37 -07:00
;
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
/***************************************************************************************
*
* Boolean expressions
*/
boolexp: boolexp _AND boolexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_AND, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| boolexp _OR boolexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_OR, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| boolexp BOOLEQUAL boolexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_EQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| boolexp NOTEQUAL boolexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_NOTEQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| _NOT boolexp
{
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, $2->size + sizeof(OPCODE));
ALLOC_BLOCK(psCurrBlock, $2->size + 1); //size + opcode
2006-08-12 09:52:37 -07:00
ip = psCurrBlock->pCode;
/* Copy the already generated bits of code into the code block */
PUT_BLOCK(ip, $2);
/* Now put a negation operator into the code */
PUT_PKOPCODE(ip, OP_UNARYOP, OP_NOT);
/* Free the two code blocks that have been copied */
FREE_BLOCK($2);
/* Return the code block */
$$ = psCurrBlock;
}
| '(' boolexp ')'
{
/* Just pass the code up the tree */
$$ = $2;
}
| BOOL_FUNC '(' param_list ')'
{
2006-11-16 06:30:29 -08:00
RULE("boolexp: BOOL_FUNC '(' param_list ')'");
2006-08-12 09:52:37 -07:00
/* Generate the code for the function call */
codeRet = scriptCodeFunction($1, $3, TRUE, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-08-19 06:26:11 -07:00
| BOOL_FUNC_CUST '(' param_list ')'
{
UDWORD line,paramNumber;
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-08-19 06:26:11 -07:00
2006-11-16 06:30:29 -08:00
RULE("boolexp: BOOL_FUNC_CUST '(' param_list ')'");
2006-08-19 06:26:11 -07:00
if($3->numParams != $1->numParams)
{
debug(LOG_ERROR, "Wrong number of arguments for function call: '%s'. Expected %d parameters instead of %d.", $1->pIdent, $1->numParams, $3->numParams);
scr_error("Wrong number of arguments in function call");
return CE_PARSE;
}
if(!$1->bFunction)
{
debug(LOG_ERROR, "'%s' is not a function", $1->pIdent);
2006-11-17 09:07:03 -08:00
scr_error("Can't call an event");
2006-08-19 06:26:11 -07:00
return CE_PARSE;
}
/* make sure function has a return type */
if($1->retType != VAL_BOOL)
{
debug(LOG_ERROR, "'%s' does not return a boolean value", $1->pIdent);
scr_error("assignment type conflict");
return CE_PARSE;
}
2006-08-22 07:28:49 -07:00
2006-08-19 06:26:11 -07:00
/* check if right parameters were passed */
paramNumber = checkFuncParamTypes($1, $3);
if(paramNumber > 0)
{
debug(LOG_ERROR, "Parameter mismatch in function call: '%s'. Mismatch in parameter %d.", $1->pIdent, paramNumber);
YYABORT;
}
/* Allocate the code block */
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, $3->size + sizeof(OPCODE) + sizeof(UDWORD)); //Params + Opcode + event index
ALLOC_BLOCK(psCurrBlock, $3->size + 1 + 1); //Params + Opcode + event index
2006-08-19 06:26:11 -07:00
ALLOC_DEBUG(psCurrBlock, 1);
ip = psCurrBlock->pCode;
if($3->numParams > 0) /* if any parameters declared */
{
/* Copy in the code for the parameters */
2006-11-16 06:30:29 -08:00
PUT_BLOCK(ip, $3);
FREE_PBLOCK($3);
2006-08-19 06:26:11 -07:00
}
/* Store the instruction */
PUT_OPCODE(ip, OP_FUNC);
2006-11-16 06:30:29 -08:00
PUT_EVENT(ip,$1->index); //Put event/function index
2006-08-19 06:26:11 -07:00
/* Add the debugging information */
if (genDebugInfo)
{
psCurrBlock->psDebug[0].offset = 0;
scriptGetErrorData((SDWORD *)&line, &pDummy);
psCurrBlock->psDebug[0].line = line;
}
$$ = psCurrBlock;
}
2006-08-12 09:52:37 -07:00
| BOOL_VAR
{
2006-11-16 06:30:29 -08:00
RULE("boolexp: BOOL_VAR");
2006-08-12 09:52:37 -07:00
codeRet = scriptCodeVarGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| BOOL_CONSTANT
{
2006-11-16 06:30:29 -08:00
RULE("boolexp: BOOL_CONSTANT");
2006-08-12 09:52:37 -07:00
codeRet = scriptCodeConstant($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| bool_objvar
{
codeRet = scriptCodeObjGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| bool_array_var
{
codeRet = scriptCodeArrayGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| BOOLEAN_T
{
2006-11-16 06:30:29 -08:00
RULE("boolexp: BOOLEAN_T");
//ALLOC_BLOCK(psCurrBlock, sizeof(OPCODE) + sizeof(UDWORD));
ALLOC_BLOCK(psCurrBlock, 1 + 1); //opcode + value
2006-08-12 09:52:37 -07:00
ip = psCurrBlock->pCode;
/* Code to store the value on the stack */
PUT_PKOPCODE(ip, OP_PUSH, VAL_BOOL);
2006-11-16 06:30:29 -08:00
PUT_DATA_BOOL(ip, $1);
2006-08-12 09:52:37 -07:00
/* Return the code block */
$$ = psCurrBlock;
}
| expression BOOLEQUAL expression
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_EQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-12-02 15:27:00 -08:00
| floatexp BOOLEQUAL floatexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_EQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-12-16 06:59:50 -08:00
| stringexp BOOLEQUAL stringexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_EQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-08-12 09:52:37 -07:00
| userexp BOOLEQUAL userexp
{
if (!interpCheckEquiv($1->type,$3->type))
{
scr_error("Type mismatch for equality");
YYABORT;
}
codeRet = scriptCodeBinaryOperator($1, $3, OP_EQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| objexp BOOLEQUAL objexp
{
if (!interpCheckEquiv($1->type,$3->type))
{
scr_error("Type mismatch for equality");
YYABORT;
}
codeRet = scriptCodeBinaryOperator($1, $3, OP_EQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| expression NOTEQUAL expression
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_NOTEQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-12-02 15:27:00 -08:00
| floatexp NOTEQUAL floatexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_NOTEQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
2006-12-16 06:59:50 -08:00
}
| stringexp NOTEQUAL stringexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_NOTEQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
2006-12-02 15:27:00 -08:00
}
2006-08-12 09:52:37 -07:00
| userexp NOTEQUAL userexp
{
if (!interpCheckEquiv($1->type,$3->type))
{
scr_error("Type mismatch for inequality");
YYABORT;
}
codeRet = scriptCodeBinaryOperator($1, $3, OP_NOTEQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| objexp NOTEQUAL objexp
{
if (!interpCheckEquiv($1->type,$3->type))
{
scr_error("Type mismatch for inequality");
YYABORT;
}
codeRet = scriptCodeBinaryOperator($1, $3, OP_NOTEQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| expression LESSEQUAL expression
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_LESSEQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-12-02 15:27:00 -08:00
| floatexp LESSEQUAL floatexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_LESSEQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-08-12 09:52:37 -07:00
| expression GREATEQUAL expression
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_GREATEREQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-12-02 15:27:00 -08:00
| floatexp GREATEQUAL floatexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_GREATEREQUAL, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-08-12 09:52:37 -07:00
| expression GREATER expression
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_GREATER, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-12-02 15:27:00 -08:00
| floatexp GREATER floatexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_GREATER, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-08-12 09:52:37 -07:00
| expression LESS expression
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_LESS, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-12-02 15:27:00 -08:00
| floatexp LESS floatexp
{
codeRet = scriptCodeBinaryOperator($1, $3, OP_LESS, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-08-12 09:52:37 -07:00
;
/*************************************************************************************
*
* User variable expressions
*/
userexp: VAR
{
codeRet = scriptCodeVarGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| USER_CONSTANT
{
2006-11-16 06:30:29 -08:00
RULE("userexp: USER_CONSTANT");
2006-08-12 09:52:37 -07:00
codeRet = scriptCodeConstant($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| user_objvar
{
codeRet = scriptCodeObjGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| user_array_var
{
codeRet = scriptCodeArrayGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| USER_FUNC '(' param_list ')'
{
/* Generate the code for the function call */
codeRet = scriptCodeFunction($1, $3, TRUE, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| TRIG_SYM
{
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, sizeof(OPCODE) + sizeof(UDWORD));
ALLOC_BLOCK(psCurrBlock, 1 + 1); //opcode + trigger index
2006-08-12 09:52:37 -07:00
ip = psCurrBlock->pCode;
/* Code to store the value on the stack */
2006-11-16 06:30:29 -08:00
PUT_PKOPCODE(ip, OP_PUSH, VAL_TRIGGER); //TODO: don't need to put VAL_TRIGGER here, since stored in ip->type now
PUT_TRIGGER(ip, $1->index);
2006-08-12 09:52:37 -07:00
psCurrBlock->type = VAL_TRIGGER;
/* Return the code block */
$$ = psCurrBlock;
}
| INACTIVE
{
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, sizeof(OPCODE) + sizeof(UDWORD));
ALLOC_BLOCK(psCurrBlock, 1 + 1); //opcode + '-1' for 'inactive'
2006-08-12 09:52:37 -07:00
ip = psCurrBlock->pCode;
/* Code to store the value on the stack */
PUT_PKOPCODE(ip, OP_PUSH, VAL_TRIGGER);
2006-11-16 06:30:29 -08:00
PUT_TRIGGER(ip, -1);
2006-08-12 09:52:37 -07:00
psCurrBlock->type = VAL_TRIGGER;
/* Return the code block */
$$ = psCurrBlock;
}
| EVENT_SYM
{
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, sizeof(OPCODE) + sizeof(UDWORD));
ALLOC_BLOCK(psCurrBlock, 1 + 1); //opcode + event index
2006-08-12 09:52:37 -07:00
ip = psCurrBlock->pCode;
/* Code to store the value on the stack */
PUT_PKOPCODE(ip, OP_PUSH, VAL_EVENT);
2006-11-16 06:30:29 -08:00
PUT_EVENT(ip, $1->index);
2006-08-12 09:52:37 -07:00
psCurrBlock->type = VAL_EVENT;
/* Return the code block */
$$ = psCurrBlock;
}
;
/*************************************************************************************
*
* Object expressions.
*/
objexp: OBJ_VAR
{
codeRet = scriptCodeVarGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| OBJ_CONSTANT
{
2006-11-16 06:30:29 -08:00
RULE("objexp: OBJ_CONSTANT");
2006-08-12 09:52:37 -07:00
codeRet = scriptCodeConstant($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| OBJ_FUNC '(' param_list ')'
{
/* Generate the code for the function call */
codeRet = scriptCodeFunction($1, $3, TRUE, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
2006-08-19 06:26:11 -07:00
| OBJ_FUNC_CUST '(' param_list ')'
{
UDWORD line,paramNumber;
2006-11-03 13:35:50 -08:00
char *pDummy;
2006-08-19 06:26:11 -07:00
if($3->numParams != $1->numParams)
{
debug(LOG_ERROR, "Wrong number of arguments for function call: '%s'. Expected %d parameters instead of %d.", $1->pIdent, $1->numParams, $3->numParams);
scr_error("Wrong number of arguments in function call");
return CE_PARSE;
}
if(!$1->bFunction)
{
debug(LOG_ERROR, "'%s' is not a function", $1->pIdent);
2006-11-17 09:07:03 -08:00
scr_error("Can't call an event");
2006-08-19 06:26:11 -07:00
return CE_PARSE;
}
/* make sure function has a return type */
/* if($1->retType != OBJ_VAR) */
if(asScrTypeTab[$1->retType - VAL_USERTYPESTART].accessType != AT_OBJECT)
{
scr_error("'%s' does not return an object value (%d )", $1->pIdent, $1->retType);
return CE_PARSE;
}
2006-08-22 07:28:49 -07:00
2006-08-19 06:26:11 -07:00
/* check if right parameters were passed */
paramNumber = checkFuncParamTypes($1, $3);
if(paramNumber > 0)
{
debug(LOG_ERROR, "Parameter mismatch in function call: '%s'. Mismatch in parameter %d.", $1->pIdent, paramNumber);
YYABORT;
}
/* Allocate the code block */
2006-11-16 06:30:29 -08:00
//ALLOC_BLOCK(psCurrBlock, $3->size + sizeof(OPCODE) + sizeof(UDWORD)); //Params + Opcode + event index
ALLOC_BLOCK(psCurrBlock, $3->size + 1 + 1); //Params + Opcode + event index
2006-08-19 06:26:11 -07:00
ALLOC_DEBUG(psCurrBlock, 1);
ip = psCurrBlock->pCode;
if($3->numParams > 0) /* if any parameters declared */
{
/* Copy in the code for the parameters */
2006-11-16 06:30:29 -08:00
PUT_BLOCK(ip, $3);
FREE_PBLOCK($3);
2006-08-19 06:26:11 -07:00
}
/* Store the instruction */
PUT_OPCODE(ip, OP_FUNC);
2006-11-16 06:30:29 -08:00
PUT_EVENT(ip,$1->index); //Put event index
2006-08-19 06:26:11 -07:00
/* Add the debugging information */
if (genDebugInfo)
{
psCurrBlock->psDebug[0].offset = 0;
scriptGetErrorData((SDWORD *)&line, &pDummy);
psCurrBlock->psDebug[0].line = line;
}
/* remember objexp type for further stuff, like myVar = objFunc(); to be able to check type equivalency */
psCurrBlock->type = $1->retType;
$$ = psCurrBlock;
}
2006-08-12 09:52:37 -07:00
| obj_objvar
{
codeRet = scriptCodeObjGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
| obj_array_var
{
codeRet = scriptCodeArrayGet($1, &psCurrBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrBlock;
}
;
/*
* Seperate rule for the dot after an object so the lookup context
* for object variables can be set
*/
objexp_dot: objexp '.'
{
2006-11-16 06:30:29 -08:00
RULE( "objexp_dot: objexp '.', type=%d", $1->type);
2006-08-12 09:52:37 -07:00
// Store the object type for the variable lookup
objVarContext = $1->type;
}
;
/*
* Object member variable references.
*/
num_objvar: objexp_dot NUM_OBJVAR
{
2006-11-16 06:30:29 -08:00
RULE( "num_objvar: objexp_dot NUM_OBJVAR");
2006-08-12 09:52:37 -07:00
codeRet = scriptCodeObjectVariable($1, $2, &psObjVarBlock);
CHECK_CODE_ERROR(codeRet);
// reset the object type
objVarContext = 0;
/* Return the code block */
$$ = psObjVarBlock;
}
;
bool_objvar: objexp_dot BOOL_OBJVAR
{
codeRet = scriptCodeObjectVariable($1, $2, &psObjVarBlock);
CHECK_CODE_ERROR(codeRet);
// reset the object type
objVarContext = 0;
/* Return the code block */
$$ = psObjVarBlock;
}
;
user_objvar: objexp_dot USER_OBJVAR
{
codeRet = scriptCodeObjectVariable($1, $2, &psObjVarBlock);
CHECK_CODE_ERROR(codeRet);
// reset the object type
objVarContext = 0;
/* Return the code block */
$$ = psObjVarBlock;
}
;
obj_objvar: objexp_dot OBJ_OBJVAR
{
codeRet = scriptCodeObjectVariable($1, $2, &psObjVarBlock);
CHECK_CODE_ERROR(codeRet);
// reset the object type
objVarContext = 0;
/* Return the code block */
$$ = psObjVarBlock;
}
;
/*****************************************************************************************************
*
* Array expressions
*
*/
array_index: '[' expression ']'
{
ALLOC_ARRAYBLOCK(psCurrArrayBlock, $2->size, NULL);
ip = psCurrArrayBlock->pCode;
/* Copy the index expression code into the code block */
PUT_BLOCK(ip, $2);
FREE_BLOCK($2);
$$ = psCurrArrayBlock;
}
;
array_index_list: array_index
{
$$ = $1;
}
|
array_index_list '[' expression ']'
{
2006-11-16 06:30:29 -08:00
//ALLOC_ARRAYBLOCK(psCurrArrayBlock, $1->size + $3->size, NULL);
2006-08-12 09:52:37 -07:00
ALLOC_ARRAYBLOCK(psCurrArrayBlock, $1->size + $3->size, NULL);
2006-11-16 06:30:29 -08:00
2006-08-12 09:52:37 -07:00
ip = psCurrArrayBlock->pCode;
/* Copy the index expression code into the code block */
psCurrArrayBlock->dimensions = $1->dimensions + 1;
PUT_BLOCK(ip, $1);
PUT_BLOCK(ip, $3);
FREE_ARRAYBLOCK($1);
FREE_ARRAYBLOCK($3);
$$ = psCurrArrayBlock;
}
;
num_array_var: NUM_ARRAY array_index_list
{
codeRet = scriptCodeArrayVariable($2, $1, &psCurrArrayBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrArrayBlock;
}
;
bool_array_var: BOOL_ARRAY array_index_list
{
codeRet = scriptCodeArrayVariable($2, $1, &psCurrArrayBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrArrayBlock;
}
;
obj_array_var: OBJ_ARRAY array_index_list
{
codeRet = scriptCodeArrayVariable($2, $1, &psCurrArrayBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrArrayBlock;
}
;
user_array_var: VAR_ARRAY array_index_list
{
codeRet = scriptCodeArrayVariable($2, $1, &psCurrArrayBlock);
CHECK_CODE_ERROR(codeRet);
/* Return the code block */
$$ = psCurrArrayBlock;
}
;
%%
// Reset all the symbol tables
static void scriptResetTables(void)
{
VAR_SYMBOL *psCurr, *psNext;
TRIGGER_SYMBOL *psTCurr, *psTNext;
EVENT_SYMBOL *psECurr, *psENext;
FUNC_SYMBOL *psFCurr, *psFNext;
2006-08-15 11:38:51 -07:00
2006-08-19 06:26:11 -07:00
SDWORD i;
2006-08-15 11:38:51 -07:00
2006-08-19 06:26:11 -07:00
/* start with global vars definition */
2006-08-15 11:38:51 -07:00
localVariableDef = FALSE;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "localVariableDef = FALSE 4");
2006-08-12 09:52:37 -07:00
/* Reset the global variable symbol table */
for(psCurr = psGlobalVars; psCurr != NULL; psCurr = psNext)
{
psNext = psCurr->psNext;
2007-04-15 03:43:05 -07:00
free(psCurr->pIdent);
free(psCurr);
2006-08-12 09:52:37 -07:00
}
psGlobalVars = NULL;
2006-08-21 02:34:42 -07:00
/* Reset the global variable symbol table */
2006-08-12 09:52:37 -07:00
psCurEvent = NULL;
2006-08-15 11:38:51 -07:00
for(i=0; i<maxEventsLocalVars; i++)
{
numEventLocalVars[i] = 0;
for(psCurr = psLocalVarsB[i]; psCurr != NULL; psCurr = psNext)
{
psNext = psCurr->psNext;
2007-04-15 03:43:05 -07:00
free(psCurr->pIdent);
free(psCurr);
2006-08-15 11:38:51 -07:00
}
psLocalVarsB[i] = NULL;
}
2006-08-21 02:34:42 -07:00
/* Reset the temp local variable symbol table */
2006-08-15 11:38:51 -07:00
for(psCurr = psLocalVarsTemp; psCurr != NULL; psCurr = psNext)
{
psNext = psCurr->psNext;
2007-04-15 03:43:05 -07:00
free(psCurr->pIdent);
free(psCurr);
2006-08-15 11:38:51 -07:00
}
psLocalVarsTemp = NULL;
2006-08-19 06:26:11 -07:00
2006-08-12 09:52:37 -07:00
/* Reset the global array symbol table */
for(psCurr = psGlobalArrays; psCurr != NULL; psCurr = psNext)
{
psNext = psCurr->psNext;
2007-04-15 03:43:05 -07:00
free(psCurr->pIdent);
free(psCurr);
2006-08-12 09:52:37 -07:00
}
psGlobalArrays = NULL;
// Reset the trigger table
for(psTCurr = psTriggers; psTCurr; psTCurr = psTNext)
{
psTNext = psTCurr->psNext;
if (psTCurr->psDebug)
{
2007-04-15 03:43:05 -07:00
free(psTCurr->psDebug);
2006-08-12 09:52:37 -07:00
}
if (psTCurr->pCode)
{
2007-04-15 03:43:05 -07:00
free(psTCurr->pCode);
2006-08-12 09:52:37 -07:00
}
2007-04-15 03:43:05 -07:00
free(psTCurr->pIdent);
free(psTCurr);
2006-08-12 09:52:37 -07:00
}
psTriggers = NULL;
numTriggers = 0;
// Reset the event table
for(psECurr = psEvents; psECurr; psECurr = psENext)
{
psENext = psECurr->psNext;
if (psECurr->psDebug)
{
2007-04-15 03:43:05 -07:00
free(psECurr->psDebug);
2006-08-12 09:52:37 -07:00
}
2007-04-15 03:43:05 -07:00
free(psECurr->pIdent);
free(psECurr->pCode);
free(psECurr);
2006-08-12 09:52:37 -07:00
}
psEvents = NULL;
numEvents = 0;
/* Reset the function symbol table */
for(psFCurr = psFunctions; psFCurr != NULL; psFCurr = psFNext)
{
psFNext = psFCurr->psNext;
FREE_DEBUG(psFCurr);
2007-04-15 03:43:05 -07:00
free(psFCurr->pIdent);
free(psFCurr->pCode);
free(psFCurr);
2006-08-12 09:52:37 -07:00
}
psFunctions = NULL;
}
/* Compile a script program */
2006-11-26 05:45:04 -08:00
BOOL scriptCompile(const char *pData, UDWORD fileSize,
2006-08-12 09:52:37 -07:00
SCRIPT_CODE **ppsProg, SCR_DEBUGTYPE debugType)
{
2007-01-02 12:12:14 -08:00
UDWORD i;
/* Reset include stack */
scr_include_stack_ptr = 0;
/* Initialize include input buffers */
for(i=0;i<MAX_SCR_INCLUDE_DEPTH;i++)
{
pScrInputBuffer[i] = NULL;
2007-07-15 06:11:09 -07:00
scrInclLine[i] = 0;
2007-01-02 12:12:14 -08:00
}
/* Set the initial input buffer */
pScrInputBuffer[0] = (char *)pData;
/* Reset number of macros */
scr_num_macros = 0;
/* Reset macro stack */
scr_macro_stack_ptr = 0;
/* Initialize macro input buffers */
for(i=0;i<MAX_SCR_MACRO_DEPTH;i++)
{
pScrMacroBuffer[i] = NULL;
}
/* Feed flex with initial input buffer */
scriptSetInputBuffer(pScrInputBuffer[0], fileSize);
2006-08-12 09:52:37 -07:00
scriptResetTables();
psFinalProg = NULL;
if (debugType == SCR_DEBUGINFO)
{
genDebugInfo = TRUE;
}
else
{
genDebugInfo = FALSE;
}
2007-01-02 12:12:14 -08:00
if (scr_parse() != 0 || bError)
2006-08-12 09:52:37 -07:00
{
return FALSE;
}
scriptResetTables();
*ppsProg = psFinalProg;
return TRUE;
}
/* A simple error reporting routine */
2006-09-13 02:09:05 -07:00
void scr_error(const char *pMessage, ...)
2006-08-12 09:52:37 -07:00
{
int line;
char *text;
va_list args;
2006-11-03 13:35:50 -08:00
char aBuff[1024];
2006-08-12 09:52:37 -07:00
va_start(args, pMessage);
vsprintf(aBuff, pMessage, args);
va_end(args);
scriptGetErrorData(&line, &text);
2007-01-02 12:12:14 -08:00
bError = TRUE;
2006-08-12 09:52:37 -07:00
#ifdef DEBUG
2006-08-22 07:28:49 -07:00
debug( LOG_ERROR, "script parse error:\n%s at %s:%d\nToken: %d, Text: '%s'\n",
aBuff, GetLastResourceFilename(), line, scr_char, text );
2006-08-23 05:58:48 -07:00
ASSERT( FALSE, "script parse error:\n%s at %s:%d\nToken: %d, Text: '%s'\n",
aBuff, GetLastResourceFilename(), line, scr_char, text );
2006-08-12 09:52:37 -07:00
#else
2006-08-19 06:26:11 -07:00
//DBERROR(("script parse error:\n%s at line %d\nToken: %d, Text: '%s'\n",
// pMessage, line, scr_char, text));
2006-08-22 07:28:49 -07:00
debug( LOG_ERROR, "script parse error:\n'%s' at %s:%d\nToken: %d, Text: '%s'\n",
aBuff, GetLastResourceFilename(), line, scr_char, text );
abort();
2006-08-12 09:52:37 -07:00
#endif
}
/* Look up a type symbol */
2006-11-26 05:45:04 -08:00
BOOL scriptLookUpType(const char *pIdent, INTERP_TYPE *pType)
2006-08-12 09:52:37 -07:00
{
UDWORD i;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpType");
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
if (asScrTypeTab)
{
for(i=0; asScrTypeTab[i].typeID != 0; i++)
{
if (strcmp(asScrTypeTab[i].pIdent, pIdent) == 0)
{
*pType = asScrTypeTab[i].typeID;
return TRUE;
}
}
}
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END scriptLookUpType");
2006-08-15 11:38:51 -07:00
2006-08-12 09:52:37 -07:00
return FALSE;
}
/* Reset the local variable symbol table at the end of a function */
void scriptClearLocalVariables(void)
{
VAR_SYMBOL *psCurr, *psNext;
for(psCurr = psLocalVars; psCurr != NULL; psCurr = psNext)
{
psNext = psCurr->psNext;
2007-04-15 03:43:05 -07:00
free(psCurr->pIdent);
free(psCurr);
2006-08-12 09:52:37 -07:00
}
2006-08-19 06:26:11 -07:00
}
2006-11-16 06:30:29 -08:00
/* pop passed arguments (if any) */
BOOL popArguments(INTERP_VAL **ip_temp, SDWORD numParams)
2006-08-19 06:26:11 -07:00
{
SDWORD i;
/* code to pop passed params right before the main code begins */
for(i = numParams-1; i >= 0 ; i--)
{
2006-11-16 06:30:29 -08:00
PUT_PKOPCODE(*ip_temp, OP_POPLOCAL, i); //pop parameters into first i local params
2006-08-19 06:26:11 -07:00
}
2006-08-15 11:38:51 -07:00
2006-08-19 06:26:11 -07:00
return TRUE;
2006-08-12 09:52:37 -07:00
}
2006-08-19 06:26:11 -07:00
2006-08-12 09:52:37 -07:00
/* Add a new variable symbol.
* If localVariableDef is true a local variable symbol is defined,
* otherwise a global variable symbol is defined.
*/
BOOL scriptAddVariable(VAR_DECL *psStorage, VAR_IDENT_DECL *psVarIdent)
{
VAR_SYMBOL *psNew;
2006-11-16 06:30:29 -08:00
SDWORD i;
2006-11-03 13:35:50 -08:00
2006-08-12 09:52:37 -07:00
/* Allocate the memory for the symbol structure */
2007-04-15 03:43:05 -07:00
psNew = (VAR_SYMBOL *)malloc(sizeof(VAR_SYMBOL));
2006-08-12 09:52:37 -07:00
if (psNew == NULL)
{
scr_error("Out of memory");
return FALSE;
}
2006-08-15 11:38:51 -07:00
2007-04-15 03:43:05 -07:00
psNew->pIdent = psVarIdent->pIdent; //(char *)malloc(strlen(pIdent) + 1);
2006-08-12 09:52:37 -07:00
/* if (psNew->pIdent == NULL)
{
scr_error("Out of memory");
return FALSE;
}*/
/* Intialise the symbol structure */
// strcpy(psNew->pIdent, pIdent);
2006-08-15 11:38:51 -07:00
2006-08-12 09:52:37 -07:00
psNew->type = psStorage->type;
psNew->storage = psStorage->storage;
psNew->dimensions = psVarIdent->dimensions;
2006-08-15 11:38:51 -07:00
2006-08-19 06:26:11 -07:00
2006-08-12 09:52:37 -07:00
for(i=0; i<psNew->dimensions; i++)
{
psNew->elements[i] = psVarIdent->elements[i];
}
if (psNew->dimensions == 0)
{
2006-08-15 11:38:51 -07:00
if(psStorage->storage != ST_LOCAL) //if not a local var
2006-08-12 09:52:37 -07:00
{
2006-08-15 11:38:51 -07:00
if (psGlobalVars == NULL)
{
psNew->index = 0;
}
else
{
psNew->index = psGlobalVars->index + 1;
}
/* Add the symbol to the list */
psNew->psNext = psGlobalVars;
psGlobalVars = psNew;
2006-08-12 09:52:37 -07:00
}
2006-08-19 06:26:11 -07:00
else //local var
2006-08-12 09:52:37 -07:00
{
2006-08-15 11:38:51 -07:00
if(psCurEvent == NULL)
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "Can't declare local variables before defining an event");
2006-08-12 09:52:37 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "local variable declared for event %d, type=%d \n", psCurEvent->index, psNew->type);
//debug(LOG_SCRIPT, "%s \n", psNew->pIdent);
2006-08-15 11:38:51 -07:00
if (psLocalVarsB[psCurEvent->index] == NULL)
{
psNew->index = 0;
}
else
{
psNew->index = psLocalVarsB[psCurEvent->index]->index + 1;
}
numEventLocalVars[psCurEvent->index] = numEventLocalVars[psCurEvent->index] + 1;
psNew->psNext = psLocalVarsB[psCurEvent->index];
psLocalVarsB[psCurEvent->index] = psNew;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "local variable declared. ");
2006-08-15 11:38:51 -07:00
}
2006-08-12 09:52:37 -07:00
}
else
{
if (psGlobalArrays == NULL)
{
psNew->index = 0;
}
else
{
psNew->index = psGlobalArrays->index + 1;
}
psNew->psNext = psGlobalArrays;
psGlobalArrays = psNew;
}
2006-08-15 11:38:51 -07:00
2006-08-12 09:52:37 -07:00
return TRUE;
}
/* Look up a variable symbol */
2006-11-26 05:45:04 -08:00
BOOL scriptLookUpVariable(const char *pIdent, VAR_SYMBOL **ppsSym)
2006-08-12 09:52:37 -07:00
{
VAR_SYMBOL *psCurr;
2006-08-15 11:38:51 -07:00
UDWORD i;
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpVariable");
2006-08-12 09:52:37 -07:00
/* See if the symbol is an object variable */
if (asScrObjectVarTab && objVarContext != 0)
{
for(psCurr = asScrObjectVarTab; psCurr->pIdent != NULL; psCurr++)
{
if (interpCheckEquiv(psCurr->objType, objVarContext) &&
strcmp(psCurr->pIdent, pIdent) == 0)
{
*ppsSym = psCurr;
return TRUE;
}
}
}
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
/* See if the symbol is an external variable */
if (asScrExternalTab)
{
for(psCurr = asScrExternalTab; psCurr->pIdent != NULL; psCurr++)
{
if (strcmp(psCurr->pIdent, pIdent) == 0)
{
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpVariable: extern");
2006-08-12 09:52:37 -07:00
*ppsSym = psCurr;
return TRUE;
}
}
}
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
/* See if the symbol is in the local variable list */
for(psCurr = psLocalVars; psCurr != NULL; psCurr = psCurr->psNext)
{
if (strcmp(psCurr->pIdent, pIdent) == 0)
{
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpVariable: local");
2006-08-12 09:52:37 -07:00
*ppsSym = psCurr;
return TRUE;
}
}
2006-08-22 07:28:49 -07:00
2006-08-19 06:26:11 -07:00
/* check local vars if we are inside of an event */
2006-08-15 11:38:51 -07:00
if(psCurEvent != NULL)
{
if(psCurEvent->index >= maxEventsLocalVars)
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "psCurEvent->index (%d) >= maxEventsLocalVars", psCurEvent->index);
2006-08-15 11:38:51 -07:00
i = psCurEvent->index;
if(psLocalVarsB[i] != NULL) //any vars stored for this event
{
2006-08-19 06:26:11 -07:00
int line;
char *text;
2006-08-15 11:38:51 -07:00
2006-08-19 06:26:11 -07:00
//debug(LOG_SCRIPT, "now checking event %s; index = %d\n", psCurEvent->pIdent, psCurEvent->index);
2006-08-15 11:38:51 -07:00
scriptGetErrorData(&line, &text);
2006-11-16 06:30:29 -08:00
for(psCurr = psLocalVarsB[i]; psCurr != NULL; psCurr = psCurr->psNext)
2006-08-15 11:38:51 -07:00
{
2006-08-19 06:26:11 -07:00
2006-08-15 11:38:51 -07:00
if(psCurr->pIdent == NULL)
2006-08-19 06:26:11 -07:00
{
2006-08-15 11:38:51 -07:00
debug(LOG_ERROR, "psCurr->pIdent == NULL");
2006-08-19 06:26:11 -07:00
debug(LOG_ERROR, "psCurr->index = %d", psCurr->index);
}
2006-08-15 11:38:51 -07:00
2006-08-19 06:26:11 -07:00
//debug(LOG_SCRIPT, "start comparing, num local vars=%d, at line %d\n", numEventLocalVars[i], line);
//debug(LOG_SCRIPT, "current var=%s\n", psCurr->pIdent);
//debug(LOG_SCRIPT, "passed string=%s\n", pIdent);
2006-08-15 11:38:51 -07:00
2006-08-19 06:26:11 -07:00
//debug(LOG_SCRIPT, "comparing %s with %s \n", psCurr->pIdent, pIdent);
2006-08-15 11:38:51 -07:00
if (strcmp(psCurr->pIdent, pIdent) == 0)
{
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpVariable - local var found, type=%d\n", psCurr->type);
2006-08-15 11:38:51 -07:00
*ppsSym = psCurr;
return TRUE;
}
}
}
}
2006-08-22 07:28:49 -07:00
2006-08-12 09:52:37 -07:00
/* See if the symbol is in the global variable list.
* This is not checked for when local variables are being defined.
* This allows local variables to have the same name as global ones.
*/
if (!localVariableDef)
{
for(psCurr = psGlobalVars; psCurr != NULL; psCurr = psCurr->psNext)
{
if (strcmp(psCurr->pIdent, pIdent) == 0)
{
*ppsSym = psCurr;
return TRUE;
}
}
for(psCurr = psGlobalArrays; psCurr != NULL; psCurr = psCurr->psNext)
{
if (strcmp(psCurr->pIdent, pIdent) == 0)
{
*ppsSym = psCurr;
return TRUE;
}
}
}
/* Failed to find the variable */
*ppsSym = NULL;
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END scriptLookUpVariable");
2006-08-12 09:52:37 -07:00
return FALSE;
}
/* Add a new trigger symbol */
2006-11-03 13:35:50 -08:00
BOOL scriptAddTrigger(const char *pIdent, TRIGGER_DECL *psDecl, UDWORD line)
2006-08-12 09:52:37 -07:00
{
TRIGGER_SYMBOL *psTrigger, *psCurr, *psPrev;
// Allocate the trigger
2007-04-15 03:43:05 -07:00
psTrigger = malloc(sizeof(TRIGGER_SYMBOL));
2006-08-12 09:52:37 -07:00
if (!psTrigger)
{
scr_error("Out of memory");
return FALSE;
}
2007-04-15 03:43:05 -07:00
psTrigger->pIdent = malloc(strlen(pIdent) + 1);
2006-08-12 09:52:37 -07:00
if (!psTrigger->pIdent)
{
scr_error("Out of memory");
return FALSE;
}
strcpy(psTrigger->pIdent, pIdent);
if (psDecl->size > 0)
{
2007-04-15 03:43:05 -07:00
psTrigger->pCode = (INTERP_VAL *)malloc(psDecl->size * sizeof(INTERP_VAL));
2006-08-12 09:52:37 -07:00
if (!psTrigger->pCode)
{
scr_error("Out of memory");
return FALSE;
}
2006-11-16 06:30:29 -08:00
memcpy(psTrigger->pCode, psDecl->pCode, psDecl->size * sizeof(INTERP_VAL));
2006-08-12 09:52:37 -07:00
}
else
{
psTrigger->pCode = NULL;
}
psTrigger->size = psDecl->size;
psTrigger->type = psDecl->type;
psTrigger->time = psDecl->time;
psTrigger->index = numTriggers++;
psTrigger->psNext = NULL;
// Add debug info
if (genDebugInfo)
{
2007-04-15 03:43:05 -07:00
psTrigger->psDebug = malloc(sizeof(SCRIPT_DEBUG));
2006-08-12 09:52:37 -07:00
psTrigger->psDebug[0].offset = 0;
psTrigger->psDebug[0].line = line;
psTrigger->debugEntries = 1;
}
else
{
psTrigger->debugEntries = 0;
psTrigger->psDebug = NULL;
}
// Store the trigger
psPrev = NULL;
for(psCurr = psTriggers; psCurr; psCurr = psCurr->psNext)
{
psPrev = psCurr;
}
if (psPrev)
{
psPrev->psNext = psTrigger;
}
else
{
psTriggers = psTrigger;
}
return TRUE;
}
/* Lookup a trigger symbol */
2006-11-26 05:45:04 -08:00
BOOL scriptLookUpTrigger(const char *pIdent, TRIGGER_SYMBOL **ppsTrigger)
2006-08-12 09:52:37 -07:00
{
TRIGGER_SYMBOL *psCurr;
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpTrigger");
2006-08-15 11:38:51 -07:00
2006-08-12 09:52:37 -07:00
for(psCurr = psTriggers; psCurr; psCurr=psCurr->psNext)
{
if (strcmp(pIdent, psCurr->pIdent) == 0)
{
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpTrigger: found");
2006-08-12 09:52:37 -07:00
*ppsTrigger = psCurr;
return TRUE;
}
}
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END scriptLookUpTrigger");
2006-08-15 11:38:51 -07:00
2006-08-12 09:52:37 -07:00
return FALSE;
}
/* Lookup a callback trigger symbol */
2006-11-26 05:45:04 -08:00
BOOL scriptLookUpCallback(const char *pIdent, CALLBACK_SYMBOL **ppsCallback)
2006-08-12 09:52:37 -07:00
{
CALLBACK_SYMBOL *psCurr;
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpCallback");
2006-08-15 11:38:51 -07:00
2006-08-12 09:52:37 -07:00
if (!asScrCallbackTab)
{
return FALSE;
}
for(psCurr = asScrCallbackTab; psCurr->type != 0; psCurr += 1)
{
if (strcmp(pIdent, psCurr->pIdent) == 0)
{
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpCallback: found");
2006-08-12 09:52:37 -07:00
*ppsCallback = psCurr;
return TRUE;
}
}
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END scriptLookUpCallback: found");
2006-08-12 09:52:37 -07:00
return FALSE;
}
/* Add a new event symbol */
2006-11-26 05:45:04 -08:00
BOOL scriptDeclareEvent(const char *pIdent, EVENT_SYMBOL **ppsEvent, SDWORD numArgs)
2006-08-12 09:52:37 -07:00
{
EVENT_SYMBOL *psEvent, *psCurr, *psPrev;
// Allocate the event
2007-04-15 03:43:05 -07:00
psEvent = malloc(sizeof(EVENT_SYMBOL));
2006-08-12 09:52:37 -07:00
if (!psEvent)
{
scr_error("Out of memory");
return FALSE;
}
2007-04-15 03:43:05 -07:00
psEvent->pIdent = malloc(strlen(pIdent) + 1);
2006-08-12 09:52:37 -07:00
if (!psEvent->pIdent)
{
scr_error("Out of memory");
return FALSE;
}
strcpy(psEvent->pIdent, pIdent);
psEvent->pCode = NULL;
psEvent->size = 0;
psEvent->psDebug = NULL;
psEvent->debugEntries = 0;
psEvent->index = numEvents++;
psEvent->psNext = NULL;
2006-08-21 02:34:42 -07:00
/* remember how many params this event has */
2006-08-12 09:52:37 -07:00
psEvent->numParams = numArgs;
psEvent->bFunction = FALSE;
psEvent->bDeclared = FALSE;
psEvent->retType = VAL_VOID; /* functions can return a value */
// Add the event to the list
psPrev = NULL;
for(psCurr = psEvents; psCurr; psCurr = psCurr->psNext)
{
psPrev = psCurr;
}
if (psPrev)
{
psPrev->psNext = psEvent;
}
else
{
psEvents = psEvent;
}
*ppsEvent = psEvent;
return TRUE;
}
// Add the code to a defined event
BOOL scriptDefineEvent(EVENT_SYMBOL *psEvent, CODE_BLOCK *psCode, SDWORD trigger)
{
2007-02-14 14:12:48 -08:00
ASSERT(psCode != NULL, "scriptDefineEvent: psCode == NULL");
ASSERT(psCode->size > 0,
"Event '%s' is empty, please add at least 1 statement", psEvent->pIdent);
2006-08-15 11:38:51 -07:00
2006-08-21 02:34:42 -07:00
// events with arguments can't have a trigger assigned
2007-02-14 14:12:48 -08:00
ASSERT(!(psEvent->numParams > 0 && trigger >= 0),
"Events with parameters can't have a trigger assigned, event: '%s' ", psEvent->pIdent);
2006-08-15 11:38:51 -07:00
2006-08-12 09:52:37 -07:00
// Store the event code
2007-04-15 03:43:05 -07:00
psEvent->pCode = (INTERP_VAL *)malloc(psCode->size * sizeof(INTERP_VAL));
2006-08-12 09:52:37 -07:00
if (!psEvent->pCode)
{
scr_error("Out of memory");
return FALSE;
}
2006-08-19 06:26:11 -07:00
2006-11-16 06:30:29 -08:00
memcpy(psEvent->pCode, psCode->pCode, psCode->size * sizeof(INTERP_VAL));
2006-08-12 09:52:37 -07:00
psEvent->size = psCode->size;
psEvent->trigger = trigger;
// Add debug info
2007-02-14 14:12:48 -08:00
if (genDebugInfo && (psCode->debugEntries > 0))
2006-08-12 09:52:37 -07:00
{
2007-04-15 03:43:05 -07:00
psEvent->psDebug = malloc(sizeof(SCRIPT_DEBUG) * psCode->debugEntries);
2006-08-19 06:26:11 -07:00
2006-08-12 09:52:37 -07:00
if (!psEvent->psDebug)
{
scr_error("Out of memory");
return FALSE;
}
2006-08-19 06:26:11 -07:00
2006-08-12 09:52:37 -07:00
memcpy(psEvent->psDebug, psCode->psDebug,
sizeof(SCRIPT_DEBUG) * psCode->debugEntries);
psEvent->debugEntries = psCode->debugEntries;
}
else
{
psEvent->debugEntries = 0;
psEvent->psDebug = NULL;
}
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "before define event");
2006-08-19 06:26:11 -07:00
2006-08-21 02:34:42 -07:00
/* store local vars */
2006-08-19 06:26:11 -07:00
if(psEvent->index >= maxEventsLocalVars)
debug(LOG_ERROR, "scriptDefineEvent - psEvent->index >= maxEventsLocalVars");
2006-08-15 11:38:51 -07:00
2006-08-12 09:52:37 -07:00
return TRUE;
}
/* Lookup an event symbol */
2006-11-26 05:45:04 -08:00
BOOL scriptLookUpEvent(const char *pIdent, EVENT_SYMBOL **ppsEvent)
2006-08-12 09:52:37 -07:00
{
EVENT_SYMBOL *psCurr;
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpEvent");
2006-08-15 11:38:51 -07:00
2006-08-12 09:52:37 -07:00
for(psCurr = psEvents; psCurr; psCurr=psCurr->psNext)
{
if (strcmp(pIdent, psCurr->pIdent) == 0)
{
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpEvent:found");
2006-08-12 09:52:37 -07:00
*ppsEvent = psCurr;
return TRUE;
}
}
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END scriptLookUpEvent");
2006-08-12 09:52:37 -07:00
return FALSE;
}
/* Look up a constant variable symbol */
2006-11-26 05:45:04 -08:00
BOOL scriptLookUpConstant(const char *pIdent, CONST_SYMBOL **ppsSym)
2006-08-12 09:52:37 -07:00
{
CONST_SYMBOL *psCurr;
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpConstant");
2006-08-15 11:38:51 -07:00
2006-08-12 09:52:37 -07:00
/* Scan the Constant list */
if (asScrConstantTab)
{
for(psCurr = asScrConstantTab; psCurr->type != VAL_VOID; psCurr++)
{
if (strcmp(psCurr->pIdent, pIdent) == 0)
{
*ppsSym = psCurr;
return TRUE;
}
}
}
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END scriptLookUpConstant");
2006-08-15 11:38:51 -07:00
2006-08-12 09:52:37 -07:00
return FALSE;
}
/* Look up a function symbol */
2006-11-26 05:45:04 -08:00
BOOL scriptLookUpFunction(const char *pIdent, FUNC_SYMBOL **ppsSym)
2006-08-12 09:52:37 -07:00
{
UDWORD i;
FUNC_SYMBOL *psCurr;
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpFunction");
2006-08-15 11:38:51 -07:00
2006-08-12 09:52:37 -07:00
/* See if the function is defined as an instinct function */
if (asScrInstinctTab)
{
for(i = 0; asScrInstinctTab[i].pFunc != NULL; i++)
{
if (strcmp(asScrInstinctTab[i].pIdent, pIdent) == 0)
{
*ppsSym = asScrInstinctTab + i;
return TRUE;
}
}
}
/* See if the function is defined as a script function */
for(psCurr = psFunctions; psCurr != NULL; psCurr = psCurr->psNext)
{
if (strcmp(psCurr->pIdent, pIdent) == 0)
{
*ppsSym = psCurr;
return TRUE;
}
}
/* Failed to find the indentifier */
*ppsSym = NULL;
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END scriptLookUpFunction");
2006-08-12 09:52:37 -07:00
return FALSE;
}
/* Look up a function symbol defined in script */
2006-11-26 05:45:04 -08:00
BOOL scriptLookUpCustomFunction(const char *pIdent, EVENT_SYMBOL **ppsSym)
2006-08-12 09:52:37 -07:00
{
EVENT_SYMBOL *psCurr;
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpCustomFunction");
2006-08-15 11:38:51 -07:00
2006-08-12 09:52:37 -07:00
/* See if the function is defined as a script function */
for(psCurr = psEvents; psCurr; psCurr = psCurr->psNext)
{
if(psCurr->bFunction) /* event defined as function */
{
if (strcmp(psCurr->pIdent, pIdent) == 0)
{
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "scriptLookUpCustomFunction: %s is a custom function", pIdent);
2006-08-12 09:52:37 -07:00
*ppsSym = psCurr;
return TRUE;
}
}
}
/* Failed to find the indentifier */
*ppsSym = NULL;
2006-08-22 07:28:49 -07:00
2006-08-21 02:34:42 -07:00
//debug(LOG_SCRIPT, "END scriptLookUpCustomFunction");
2006-08-12 09:52:37 -07:00
return FALSE;
}
/* Set the type table */
void scriptSetTypeTab(TYPE_SYMBOL *psTypeTab)
{
#ifdef DEBUG
SDWORD i;
INTERP_TYPE type;
for(i=0, type=VAL_USERTYPESTART; psTypeTab[i].typeID != 0; i++)
{
2006-08-23 05:58:48 -07:00
ASSERT( psTypeTab[i].typeID == type,
"scriptSetTypeTab: ID's must be >= VAL_USERTYPESTART and sequential" );
2006-09-03 13:32:01 -07:00
type = type + 1;
2006-08-12 09:52:37 -07:00
}
#endif
asScrTypeTab = psTypeTab;
}
/* Set the function table */
void scriptSetFuncTab(FUNC_SYMBOL *psFuncTab)
{
asScrInstinctTab = psFuncTab;
}
/* Set the object variable table */
void scriptSetObjectTab(VAR_SYMBOL *psObjTab)
{
asScrObjectVarTab = psObjTab;
}
/* Set the external variable table */
void scriptSetExternalTab(VAR_SYMBOL *psExtTab)
{
asScrExternalTab = psExtTab;
}
/* Set the constant table */
void scriptSetConstTab(CONST_SYMBOL *psConstTab)
{
asScrConstantTab = psConstTab;
}
/* Set the callback table */
void scriptSetCallbackTab(CALLBACK_SYMBOL *psCallTab)
{
#ifdef DEBUG
SDWORD i;
TRIGGER_TYPE type;
for(i=0, type=TR_CALLBACKSTART; psCallTab[i].type != 0; i++)
{
2006-08-23 05:58:48 -07:00
ASSERT( psCallTab[i].type == type,
"scriptSetCallbackTab: ID's must be >= VAL_CALLBACKSTART and sequential" );
2006-09-03 13:32:01 -07:00
type = type + 1;
2006-08-12 09:52:37 -07:00
}
#endif
asScrCallbackTab = psCallTab;
}