X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=gmqcc.h;h=88cf7ff21831336c15f1d6d87515af82176fb6f6;hb=49f4fedecfcdbc15879bcfe1f26562acd47d5ac2;hp=14a9b7c64caf37244512a0a91416cfcecbf85947;hpb=878195bdec6877c9376f6da55ebf5a3a23a3cc69;p=xonotic%2Fgmqcc.git diff --git a/gmqcc.h b/gmqcc.h index 14a9b7c..88cf7ff 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -1,5 +1,10 @@ #ifndef GMQCC_HDR #define GMQCC_HDR +#include +#include +#include +#include +using std::move; #include #include #include @@ -226,7 +231,7 @@ void _util_vec_delete(void *vec); /* exposed interface */ #define vec_meta(A) ((vector_t*)(((char *)(A)) - sizeof(vector_t))) -#define vec_free(A) ((void)((A) ? (_util_vec_delete((void *)(A)), (A) = NULL) : 0)) +#define vec_free(A) ((void)((A) ? (_util_vec_delete((void *)(A)), (A) = nullptr) : 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)]) @@ -258,7 +263,7 @@ int util_getline(char **, size_t *, FILE *); /* code.c */ /* Note: if you change the order, fix type_sizeof in ir.c */ -enum { +enum qc_type { TYPE_VOID , TYPE_STRING , TYPE_FLOAT , @@ -486,29 +491,33 @@ enum { /* 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); +void util_swap_header(prog_header_t &code_header); +void util_swap_statements(std::vector &statements); +void util_swap_defs_fields(std::vector §ion); +void util_swap_functions(std::vector &functions); +void util_swap_globals(std::vector &globals); -typedef float qcfloat_t; -typedef int32_t qcint_t; +typedef float qcfloat_t; +typedef int32_t qcint_t; typedef uint32_t qcuint_t; struct code_t { - prog_section_statement_t *statements; - int *linenums; - int *columnnums; - prog_section_def_t *defs; - prog_section_field_t *fields; - prog_section_function_t *functions; - int *globals; - char *chars; - uint16_t crc; - uint32_t entfields; - ht string_cache; - qcint_t string_cached_empty; + void* operator new(std::size_t); + void operator delete(void*); + code_t(); + ~code_t(); + std::vector statements; + std::vector linenums; + std::vector columnnums; + std::vector defs; + std::vector fields; + std::vector functions; + std::vector globals; + std::vector chars; + uint16_t crc = 0; + uint32_t entfields = 0; + ht string_cache; + qcint_t string_cached_empty = 0; }; /* @@ -517,8 +526,8 @@ struct code_t { */ struct lex_ctx_t { const char *file; - size_t line; - size_t column; + size_t line; + size_t column; }; /* @@ -588,7 +597,7 @@ void compile_show_werrors(void); /* ir.c */ /* TODO: cleanup */ -enum store_types { +enum store_type { store_global, store_local, /* local, assignable for now, should get promoted later */ store_param, /* parameters, they are locals with a fixed position */ @@ -645,17 +654,17 @@ struct qc_exec_stack_t { }; struct qc_program_t { - 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; - - const char* *function_stack; + char *filename; + std::vector code; + std::vector defs; + std::vector fields; + std::vector functions; + std::vector strings; + std::vector globals; + qcint_t *entitydata; + bool *entitypool; + + const char* *function_stack; uint16_t crc16;