mirror of
https://github.com/ZDoom/acc.git
synced 2024-11-22 12:01:40 +00:00
ac678ff7b8
- Script arrays are semantically identical to map arrays: They have fixed sizes and can be multidimensional. They can also be initialized, although this is just syntactic sugar. e.g. int init_array[2] = { 10, 20 } produces code identical to: int init_array[2]; init_array[0] = 10; init_array[1] = 20; Script arrays are also implicitly initialized to 0, just like any other variable in ACS. - Unlike map arrays, they only exist for the life of the script, and each script gets its own copy of the array. - Script arrays exists in a separate space from script variables. I did not repeat the bullshittery of map arrays here. (I still have no idea what I was thinking when I designed them that way.) - Each script and function that uses local arrays is recorded with a new chunk: SARY for scripts and FARY for functions. The first two bytes are the script/function number, and the rest of the chunk consists of four-byte integers describing the size (in ints) of each array used by that script/function. To determine how many arrays a script/function uses, take the chunk length, subtract two, and divide by four.
131 lines
2.5 KiB
C
131 lines
2.5 KiB
C
|
|
//**************************************************************************
|
|
//**
|
|
//** symbol.h
|
|
//**
|
|
//**************************************************************************
|
|
|
|
#ifndef __SYMBOL_H__
|
|
#define __SYMBOL_H__
|
|
|
|
// HEADER FILES ------------------------------------------------------------
|
|
|
|
#include "common.h"
|
|
#include "pcode.h"
|
|
|
|
// MACROS ------------------------------------------------------------------
|
|
|
|
#define MAX_ARRAY_DIMS 8
|
|
|
|
// TYPES -------------------------------------------------------------------
|
|
|
|
typedef enum
|
|
{
|
|
SY_DUMMY,
|
|
SY_LABEL,
|
|
SY_SCRIPTVAR,
|
|
SY_SCRIPTALIAS,
|
|
SY_MAPVAR,
|
|
SY_WORLDVAR,
|
|
SY_GLOBALVAR,
|
|
SY_SCRIPTARRAY,
|
|
SY_MAPARRAY,
|
|
SY_WORLDARRAY,
|
|
SY_GLOBALARRAY,
|
|
SY_SPECIAL,
|
|
SY_CONSTANT,
|
|
SY_INTERNFUNC,
|
|
SY_SCRIPTFUNC
|
|
} symbolType_t;
|
|
|
|
typedef struct
|
|
{
|
|
U_BYTE index;
|
|
} symVar_t;
|
|
|
|
typedef struct
|
|
{
|
|
U_BYTE index;
|
|
int dimensions[MAX_ARRAY_DIMS];
|
|
int ndim;
|
|
int size;
|
|
} symArray_t;
|
|
|
|
typedef struct
|
|
{
|
|
int address;
|
|
} symLabel_t;
|
|
|
|
typedef struct
|
|
{
|
|
int value;
|
|
int argCount;
|
|
} symSpecial_t;
|
|
|
|
typedef struct
|
|
{
|
|
int value;
|
|
char *strValue;
|
|
int fileDepth;
|
|
} symConstant_t;
|
|
|
|
typedef struct
|
|
{
|
|
pcd_t directCommand;
|
|
pcd_t stackCommand;
|
|
int argCount;
|
|
int optMask;
|
|
int outMask;
|
|
boolean hasReturnValue;
|
|
boolean latent;
|
|
} symInternFunc_t;
|
|
|
|
typedef struct
|
|
{
|
|
int address;
|
|
int argCount;
|
|
int varCount;
|
|
int funcNumber;
|
|
boolean hasReturnValue;
|
|
int sourceLine;
|
|
char *sourceName;
|
|
boolean predefined;
|
|
} symScriptFunc_t;
|
|
|
|
typedef struct symbolNode_s
|
|
{
|
|
struct symbolNode_s *left;
|
|
struct symbolNode_s *right;
|
|
char *name;
|
|
symbolType_t type;
|
|
boolean unused;
|
|
boolean imported;
|
|
union
|
|
{
|
|
symVar_t var;
|
|
symArray_t array;
|
|
symLabel_t label;
|
|
symSpecial_t special;
|
|
symConstant_t constant;
|
|
symInternFunc_t internFunc;
|
|
symScriptFunc_t scriptFunc;
|
|
} info;
|
|
} symbolNode_t;
|
|
|
|
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
|
|
|
void SY_Init(void);
|
|
symbolNode_t *SY_Find(char *name);
|
|
symbolNode_t *SY_FindLocal(char *name);
|
|
symbolNode_t *SY_FindGlobal(char *name);
|
|
symbolNode_t *SY_InsertLocal(char *name, symbolType_t type);
|
|
symbolNode_t *SY_InsertGlobal(char *name, symbolType_t type);
|
|
symbolNode_t *SY_InsertGlobalUnique(char *name, symbolType_t type);
|
|
void SY_FreeLocals(void);
|
|
void SY_FreeGlobals(void);
|
|
void SY_FreeConstants(int depth);
|
|
void SY_ClearShared(void);
|
|
|
|
// PUBLIC DATA DECLARATIONS ------------------------------------------------
|
|
|
|
#endif
|