/* stat.c */
void stat_info (void);
char *stat_mem_strdup (const char *, size_t, const char *, bool);
+void stat_mem_deallocate(void *, size_t, const char *);
void *stat_mem_reallocate(void *, size_t, size_t, const char *, const char *);
-void stat_mem_deallocate(void *);
void *stat_mem_allocate (size_t, size_t, const char *, const char *);
#define mem_a(SIZE) stat_mem_allocate ((SIZE), __LINE__, __FILE__, #SIZE)
-#define mem_d(PTRN) stat_mem_deallocate((void*)(PTRN))
+#define mem_d(PTRN) stat_mem_deallocate((void*)(PTRN), __LINE__, __FILE__)
#define mem_r(PTRN, SIZE) stat_mem_reallocate((void*)(PTRN), (SIZE), __LINE__, __FILE__, #SIZE)
#define mem_af(SIZE, FILE, LINE) stat_mem_allocate ((SIZE), (LINE), (FILE), #SIZE)
#define util_isprint(a) (((unsigned)(a)-0x20) < 0x5F)
#define util_isspace(a) (((a) >= 9 && (a) <= 13) || (a) == ' ')
-bool util_strupper (const char *);
-bool util_strdigit (const char *);
-void util_endianswap (void *, size_t, unsigned int);
+bool util_strupper(const char *);
+bool util_strdigit(const char *);
+
+void util_endianswap(void *, size_t, unsigned int);
size_t util_strtocmd (const char *, char *, size_t);
size_t util_strtononcmd (const char *, char *, size_t);
/* hidden interface */
void _util_vec_grow(void **a, size_t i, size_t s);
+void _util_vec_delete(void *vec, size_t line, const char *file);
+
#define GMQCC_VEC_WILLGROW(X,Y) ( \
((!(X) || vec_meta(X)->used + Y >= vec_meta(X)->allocated)) ? \
(void)_util_vec_grow(((void**)&(X)), (Y), sizeof(*(X))) : \
)
/* exposed interface */
-#define vec_meta(A) (((vector_t*)((void*)A)) - 1)
-#define vec_free(A) ((void)((A) ? (mem_d((void*)vec_meta(A)), (A) = NULL) : 0))
+#define vec_meta(A) ((vector_t*)(((char *)(A)) - (sizeof(vector_t) + 4)))
+#define vec_free(A) ((void)((A) ? (_util_vec_delete((void *)(A), __LINE__, __FILE__), (A) = NULL) : 0))
#define vec_push(A,V) (GMQCC_VEC_WILLGROW((A),1), (A)[vec_meta(A)->used++] = (V))
#define vec_size(A) ((A) ? vec_meta(A)->used : 0)
#define vec_add(A,N) (GMQCC_VEC_WILLGROW((A),(N)), vec_meta(A)->used += (N), &(A)[vec_meta(A)->used-(N)])
/* TODO: elide */
extern const char *util_instr_str[VINSTR_END];
+void util_swap_header (prog_header_t *code_header);
+void util_swap_statements (prog_section_statement_t *statements);
+void util_swap_defs_fields(prog_section_both_t *section);
+void util_swap_functions (prog_section_function_t *functions);
+void util_swap_globals (int32_t *globals);
typedef float qcfloat_t;
typedef int32_t qcint_t;
} qc_exec_stack_t;
typedef struct qc_program_s {
- char *filename;
+ char *filename;
prog_section_statement_t *code;
prog_section_def_t *defs;
prog_section_def_t *fields;
prog_section_function_t *functions;
- char *strings;
- qcint_t *globals;
- qcint_t *entitydata;
- bool *entitypool;
+ char *strings;
+ qcint_t *globals;
+ qcint_t *entitydata;
+ bool *entitypool;
- const char* *function_stack;
+ const char* *function_stack;
uint16_t crc16;
size_t xflags;
int argc; /* current arg count for debugging */
+
+ /* cached fields */
+ struct {
+ qcint_t frame;
+ qcint_t nextthink;
+ qcint_t think;
+ } cached_fields;
+
+ struct {
+ qcint_t self;
+ qcint_t time;
+ } cached_globals;
+
+ bool supports_state; /* is INSTR_STATE supported? */
} qc_program_t;
qc_program_t* prog_load (const char *filename, bool ignoreversion);
extern opts_cmd_t opts;
-#define OPTS_GENERIC(f,i) (!! (((f)[(i)/32]) & (1<< (unsigned)((i)%32))))
+#define OPTS_GENERIC(f,i) (!! (((f)[(i)/32]) & (1U << (unsigned)((i)%32))))
#define OPTS_FLAG(i) OPTS_GENERIC(opts.flags, (i))
#define OPTS_WARN(i) OPTS_GENERIC(opts.warn, (i))