typedef char uintptr_size_is_correct[sizeof(intptr_t) == sizeof(int*)?1:-1];
typedef char intptr_size_is_correct [sizeof(uintptr_t)== sizeof(int*)?1:-1];
-/*===================================================================*/
-/*============================ lex.c ================================*/
-/*===================================================================*/
-typedef struct lex_file_t {
- FILE *file; /* file handler */
- char *name; /* name of file */
- char peek [5];
- char lastok[8192];
-
- int last; /* last token */
- int current; /* current token */
- int length; /* bytes left to parse */
- int size; /* never changes (size of file) */
- int line; /* what line are we on? */
-} lex_file;
-
-/*
- * It's important that this table never exceed 32 keywords, the ascii
- * table starts at 33 (and we don't want conflicts)
- */
-enum {
- TOKEN_DO ,
- TOKEN_ELSE ,
- TOKEN_IF ,
- TOKEN_WHILE ,
- TOKEN_BREAK ,
- TOKEN_CONTINUE ,
- TOKEN_RETURN ,
- TOKEN_GOTO ,
- TOKEN_FOR , /* extension */
- TOKEN_TYPEDEF , /* extension */
-
- /* ensure the token types are out of the */
- /* bounds of anyothers that may conflict. */
- TOKEN_FLOAT = 110,
- TOKEN_VECTOR ,
- TOKEN_STRING ,
- TOKEN_ENTITY ,
- TOKEN_VOID
-};
-
-/*
- * Lexer state constants, these are numbers for where exactly in
- * the lexing the lexer is at. Or where it decided to stop if a lexer
- * error occurs. These numbers must be > where the ascii-table ends
- * and > the last type token which is TOKEN_VOID
- */
-enum {
- LEX_COMMENT = 1128,
- LEX_CHRLIT ,
- LEX_STRLIT ,
- LEX_IDENT
-};
-
-int lex_token (lex_file *);
-void lex_reset (lex_file *);
-void lex_close (lex_file *);
-void lex_parse (lex_file *);
-lex_file *lex_include(lex_file *, const char *);
-void lex_init (const char *, lex_file **);
-
-/*===================================================================*/
-/*========================== error.c ================================*/
-/*===================================================================*/
-#define ERROR_LEX (SHRT_MAX+0)
-#define ERROR_PARSE (SHRT_MAX+1)
-#define ERROR_INTERNAL (SHRT_MAX+2)
-#define ERROR_COMPILER (SHRT_MAX+3)
-#define ERROR_PREPRO (SHRT_MAX+4)
-int error(lex_file *, int, const char *, ...);
-
-/*===================================================================*/
-/*========================== parse.c ================================*/
-/*===================================================================*/
-int parse_gen(lex_file *);
-
-/*===================================================================*/
-/*========================== typedef.c ==============================*/
-/*===================================================================*/
-typedef struct typedef_node_t {
- char *name;
-} typedef_node;
-
-void typedef_init();
-void typedef_clear();
-typedef_node *typedef_find(const char *);
-int typedef_add (lex_file *file, const char *, const char *);
-
-
/*===================================================================*/
/*=========================== util.c ================================*/
/*===================================================================*/
int util_getline (char **, size_t *, FILE *);
void util_endianswap (void *, int, int);
+size_t util_strtocmd (const char *, char *, size_t);
+size_t util_strtononcmd (const char *, char *, size_t);
+
uint32_t util_crc32(const char *, int, register const short);
#ifdef NOTRACK
while (N##_add(*++elements) != -1 && len--); \
return N##_elements; \
} \
- typedef char VECTOR_FILL(extra_semicolon_,__COUNTER__)
+ typedef char VECTOR_FILL(extra_semicolon_##N,__COUNTER__)
#define VECTOR_PROT(T,N) \
extern T* N##_data ; \
extern long N##_elements ; \
TYPE_FIELD ,
TYPE_FUNCTION ,
TYPE_POINTER ,
- /* TYPE_INTEGER , */
+ TYPE_INTEGER ,
TYPE_VARIANT ,
TYPE_COUNT
};
+extern const char *type_name[TYPE_COUNT];
+
extern size_t type_sizeof[TYPE_COUNT];
extern uint16_t type_store_instr[TYPE_COUNT];
/* could use type_store_instr + INSTR_STOREP_F - INSTR_STORE_F
VECTOR_PROT(int, code_globals );
VECTOR_PROT(char, code_chars );
+typedef float qcfloat;
+typedef int32_t qcint;
+
/*
* code_write -- writes out the compiled file
* code_init -- prepares the code file
void code_init ();
uint32_t code_genstring (const char *string);
uint32_t code_cachedstring(const char *string);
+qcint code_alloc_field (size_t qcsize);
/*===================================================================*/
/*========================= assembler.c =============================*/
{ "OR" , 0, 2 },
{ "BITAND" , 0, 6 },
{ "BITOR" , 0, 5 },
+
{ "END" , 0, 3 } /* virtual assembler instruction */
};
void asm_close(FILE *);
void asm_parse(FILE *);
/*===================================================================*/
-/*============================= main.c ==============================*/
-/*===================================================================*/
-enum {
- COMPILER_QCC, /* circa QuakeC */
- COMPILER_FTEQCC, /* fteqcc QuakeC */
- COMPILER_QCCX, /* qccx QuakeC */
- COMPILER_GMQCC /* this QuakeC */
-};
-extern bool opts_debug;
-extern bool opts_memchk;
-extern bool opts_darkplaces_stringtablebug;
-extern bool opts_omit_nullcode;
-extern int opts_compiler;
-/*===================================================================*/
/*============================= ast.c ===============================*/
/*===================================================================*/
#define MEM_VECTOR_PROTO(Towner, Tmem, mem) \
(owner)->mem##_alloc = 0; \
}
+#define MEM_VECTOR_MOVE(from, mem, to, tm) \
+{ \
+ (to)->tm = (from)->mem; \
+ (to)->tm##_count = (from)->mem##_count; \
+ (to)->tm##_alloc = (from)->mem##_alloc; \
+ (from)->mem = NULL; \
+ (from)->mem##_count = 0; \
+ (from)->mem##_alloc = 0; \
+}
+
#define MEM_VEC_FUNCTIONS(Tself, Twhat, mem) \
MEM_VEC_FUN_REMOVE(Tself, Twhat, mem) \
MEM_VEC_FUN_ADD(Tself, Twhat, mem)
* Since we may want to support that as well, let's redefine
* float and int here.
*/
-typedef float qcfloat;
-typedef int32_t qcint;
-
typedef union {
qcint _int;
qcint string;
MEM_VECTOR_MAKE(char, strings);
MEM_VECTOR_MAKE(qcint, globals);
MEM_VECTOR_MAKE(qcint, entitydata);
+ MEM_VECTOR_MAKE(bool, entitypool);
size_t tempstring_start;
size_t tempstring_at;
typedef struct {
const char *name;
longbit bit;
-} opt_flag_def;
+} opts_flag_def;
/*===================================================================*/
/* list of -f flags, like -fdarkplaces-string-table-bug */
enum {
- DP_STRING_TABLE_BUG,
- OMIT_NULLBYTES,
-
- NUM_F_FLAGS
+# define GMQCC_DEFINE_FLAG(X) X,
+# include "flags.def"
+# undef GMQCC_DEFINE_FLAG
+ COUNT_FLAGS
};
-static const opt_flag_def opt_flag_list[] = {
- { "darkplaces-string-table-bug", LONGBIT(DP_STRING_TABLE_BUG) },
- { "omit-nullbytes", LONGBIT(OMIT_NULLBYTES) }
+static const opts_flag_def opts_flag_list[] = {
+# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(X) },
+# include "flags.def"
+# undef GMQCC_DEFINE_FLAG
+ { NULL, LONGBIT(0) }
};
-static const size_t opt_flag_list_count = sizeof(opt_flag_list) / sizeof(opt_flag_list[0]);
enum {
- WARN_UNUSED_VARIABLE,
-
- NUM_W_FLAGS
+# define GMQCC_DEFINE_FLAG(X) WARN_##X,
+# include "warns.def"
+# undef GMQCC_DEFINE_FLAG
+ COUNT_WARNINGS
};
-static const opt_flag_def opt_warn_list[] = {
- /* only contains single flags, no groups like 'all' */
- { "unused-variable", LONGBIT(WARN_UNUSED_VARIABLE) }
+static const opts_flag_def opts_warn_list[] = {
+# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(WARN_##X) },
+# include "warns.def"
+# undef GMQCC_DEFINE_FLAG
+ { NULL, LONGBIT(0) }
};
-static const size_t opt_warn_list_count = sizeof(opt_warn_list) / sizeof(opt_warn_list[0]);
/* other options: */
-extern uint32_t opt_O; /* -Ox */
-extern const char *opt_output; /* -o file */
-extern int opt_standard;
-
enum {
- STD_DEF,
- STD_QCC,
- STD_FTE
+ COMPILER_QCC, /* circa QuakeC */
+ COMPILER_FTEQCC, /* fteqcc QuakeC */
+ COMPILER_QCCX, /* qccx QuakeC */
+ COMPILER_GMQCC /* this QuakeC */
};
+extern uint32_t opts_O; /* -Ox */
+extern const char *opts_output; /* -o file */
+extern int opts_standard;
+extern bool opts_debug;
+extern bool opts_memchk;
/*===================================================================*/
-#define OPT_FLAG(i) (!! (opt_flags[(i)/32] & (1<< ((i)%32))))
-extern uint32_t opt_flags[1 + (NUM_F_FLAGS / 32)];
-#define OPT_WARN(i) (!! (opt_warn[(i)/32] & (1<< ((i)%32))))
-extern uint32_t opt_warn[1 + (NUM_W_FLAGS / 32)];
+#define OPTS_FLAG(i) (!! (opts_flags[(i)/32] & (1<< ((i)%32))))
+extern uint32_t opts_flags[1 + (COUNT_FLAGS / 32)];
+#define OPTS_WARN(i) (!! (opts_warn[(i)/32] & (1<< ((i)%32))))
+extern uint32_t opts_warn[1 + (COUNT_WARNINGS / 32)];
#endif