}
/* Initialize main ast node aprts */
-static void ast_node_init(ast_node *self, lex_ctx ctx, int nodetype)
+static void ast_node_init(ast_node *self, lex_ctx_t ctx, int nodetype)
{
self->context = ctx;
self->destroy = &_ast_node_destroy;
}
}
-static ast_expression* ast_shallow_type(lex_ctx ctx, int vtype)
+static ast_expression* ast_shallow_type(lex_ctx_t ctx, int vtype)
{
ast_instantiate(ast_expression, ctx, ast_expression_delete_full);
ast_expression_init(self, NULL);
return self;
}
-ast_expression* ast_type_copy(lex_ctx ctx, const ast_expression *ex)
+ast_expression* ast_type_copy(lex_ctx_t ctx, const ast_expression *ex)
{
size_t i;
const ast_expression *fromex;
}
static bool ast_value_codegen(ast_value *self, ast_function *func, bool lvalue, ir_value **out);
-ast_value* ast_value_new(lex_ctx ctx, const char *name, int t)
+ast_value* ast_value_new(lex_ctx_t ctx, const char *name, int t)
{
ast_instantiate(ast_value, ctx, ast_value_delete);
ast_expression_init((ast_expression*)self,
return !!self->name;
}
-ast_binary* ast_binary_new(lex_ctx ctx, int op,
+ast_binary* ast_binary_new(lex_ctx_t ctx, int op,
ast_expression* left, ast_expression* right)
{
ast_instantiate(ast_binary, ctx, ast_binary_delete);
mem_d(self);
}
-ast_binstore* ast_binstore_new(lex_ctx ctx, int storop, int op,
+ast_binstore* ast_binstore_new(lex_ctx_t ctx, int storop, int op,
ast_expression* left, ast_expression* right)
{
ast_instantiate(ast_binstore, ctx, ast_binstore_delete);
mem_d(self);
}
-ast_unary* ast_unary_new(lex_ctx ctx, int op,
+ast_unary* ast_unary_new(lex_ctx_t ctx, int op,
ast_expression *expr)
{
ast_instantiate(ast_unary, ctx, ast_unary_delete);
mem_d(self);
}
-ast_return* ast_return_new(lex_ctx ctx, ast_expression *expr)
+ast_return* ast_return_new(lex_ctx_t ctx, ast_expression *expr)
{
ast_instantiate(ast_return, ctx, ast_return_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_return_codegen);
mem_d(self);
}
-ast_entfield* ast_entfield_new(lex_ctx ctx, ast_expression *entity, ast_expression *field)
+ast_entfield* ast_entfield_new(lex_ctx_t ctx, ast_expression *entity, ast_expression *field)
{
if (field->vtype != TYPE_FIELD) {
compile_error(ctx, "ast_entfield_new with expression not of type field");
return ast_entfield_new_force(ctx, entity, field, field->next);
}
-ast_entfield* ast_entfield_new_force(lex_ctx ctx, ast_expression *entity, ast_expression *field, const ast_expression *outtype)
+ast_entfield* ast_entfield_new_force(lex_ctx_t ctx, ast_expression *entity, ast_expression *field, const ast_expression *outtype)
{
ast_instantiate(ast_entfield, ctx, ast_entfield_delete);
mem_d(self);
}
-ast_member* ast_member_new(lex_ctx ctx, ast_expression *owner, unsigned int field, const char *name)
+ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int field, const char *name)
{
ast_instantiate(ast_member, ctx, ast_member_delete);
if (field >= 3) {
return !!self->name;
}
-ast_array_index* ast_array_index_new(lex_ctx ctx, ast_expression *array, ast_expression *index)
+ast_array_index* ast_array_index_new(lex_ctx_t ctx, ast_expression *array, ast_expression *index)
{
ast_expression *outtype;
ast_instantiate(ast_array_index, ctx, ast_array_index_delete);
mem_d(self);
}
-ast_argpipe* ast_argpipe_new(lex_ctx ctx, ast_expression *index)
+ast_argpipe* ast_argpipe_new(lex_ctx_t ctx, ast_expression *index)
{
ast_instantiate(ast_argpipe, ctx, ast_argpipe_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_argpipe_codegen);
mem_d(self);
}
-ast_ifthen* ast_ifthen_new(lex_ctx ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse)
+ast_ifthen* ast_ifthen_new(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse)
{
ast_instantiate(ast_ifthen, ctx, ast_ifthen_delete);
if (!ontrue && !onfalse) {
mem_d(self);
}
-ast_ternary* ast_ternary_new(lex_ctx ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse)
+ast_ternary* ast_ternary_new(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse)
{
ast_expression *exprtype = ontrue;
ast_instantiate(ast_ternary, ctx, ast_ternary_delete);
mem_d(self);
}
-ast_loop* ast_loop_new(lex_ctx ctx,
+ast_loop* ast_loop_new(lex_ctx_t ctx,
ast_expression *initexpr,
ast_expression *precond, bool pre_not,
ast_expression *postcond, bool post_not,
mem_d(self);
}
-ast_breakcont* ast_breakcont_new(lex_ctx ctx, bool iscont, unsigned int levels)
+ast_breakcont* ast_breakcont_new(lex_ctx_t ctx, bool iscont, unsigned int levels)
{
ast_instantiate(ast_breakcont, ctx, ast_breakcont_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_breakcont_codegen);
mem_d(self);
}
-ast_switch* ast_switch_new(lex_ctx ctx, ast_expression *op)
+ast_switch* ast_switch_new(lex_ctx_t ctx, ast_expression *op)
{
ast_instantiate(ast_switch, ctx, ast_switch_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_switch_codegen);
mem_d(self);
}
-ast_label* ast_label_new(lex_ctx ctx, const char *name, bool undefined)
+ast_label* ast_label_new(lex_ctx_t ctx, const char *name, bool undefined)
{
ast_instantiate(ast_label, ctx, ast_label_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_label_codegen);
vec_push(self->gotos, g);
}
-ast_goto* ast_goto_new(lex_ctx ctx, const char *name)
+ast_goto* ast_goto_new(lex_ctx_t ctx, const char *name)
{
ast_instantiate(ast_goto, ctx, ast_goto_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_goto_codegen);
self->target = label;
}
-ast_call* ast_call_new(lex_ctx ctx,
+ast_call* ast_call_new(lex_ctx_t ctx,
ast_expression *funcexpr)
{
ast_instantiate(ast_call, ctx, ast_call_delete);
return retval;
}
-ast_store* ast_store_new(lex_ctx ctx, int op,
+ast_store* ast_store_new(lex_ctx_t ctx, int op,
ast_expression *dest, ast_expression *source)
{
ast_instantiate(ast_store, ctx, ast_store_delete);
mem_d(self);
}
-ast_block* ast_block_new(lex_ctx ctx)
+ast_block* ast_block_new(lex_ctx_t ctx)
{
ast_instantiate(ast_block, ctx, ast_block_delete);
ast_expression_init((ast_expression*)self,
ast_type_adopt(self, from);
}
-ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype)
+ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype)
{
ast_instantiate(ast_function, ctx, ast_function_delete);
typedef void ast_node_delete(ast_node*);
struct ast_node_common
{
- lex_ctx context;
+ lex_ctx_t context;
/* I don't feel comfortable using keywords like 'delete' as names... */
ast_node_delete *destroy;
int nodetype;
typedef union {
double vfloat;
int vint;
- vector vvec;
+ vec3_t vvec;
const char *vstring;
int ventity;
ast_function *vfunc;
ast_value *getter;
};
-ast_value* ast_value_new(lex_ctx ctx, const char *name, int qctype);
+ast_value* ast_value_new(lex_ctx_t ctx, const char *name, int qctype);
ast_value* ast_value_copy(const ast_value *self);
/* This will NOT delete an underlying ast_function */
void ast_value_delete(ast_value*);
void ast_value_params_add(ast_value*, ast_value*);
bool ast_compare_type(ast_expression *a, ast_expression *b);
-ast_expression* ast_type_copy(lex_ctx ctx, const ast_expression *ex);
+ast_expression* ast_type_copy(lex_ctx_t ctx, const ast_expression *ex);
#define ast_type_adopt(a, b) ast_type_adopt_impl((ast_expression*)(a), (ast_expression*)(b))
void ast_type_adopt_impl(ast_expression *self, const ast_expression *other);
void ast_type_to_string(ast_expression *e, char *buf, size_t bufsize);
ast_binary_ref refs;
};
-ast_binary* ast_binary_new(lex_ctx ctx,
+ast_binary* ast_binary_new(lex_ctx_t ctx,
int op,
ast_expression *left,
ast_expression *right);
/* for &~= which uses the destination in a binary in source we can use this */
bool keep_dest;
};
-ast_binstore* ast_binstore_new(lex_ctx ctx,
+ast_binstore* ast_binstore_new(lex_ctx_t ctx,
int storeop,
int op,
ast_expression *left,
int op;
ast_expression *operand;
};
-ast_unary* ast_unary_new(lex_ctx ctx,
+ast_unary* ast_unary_new(lex_ctx_t ctx,
int op,
ast_expression *expr);
ast_expression expression;
ast_expression *operand;
};
-ast_return* ast_return_new(lex_ctx ctx,
+ast_return* ast_return_new(lex_ctx_t ctx,
ast_expression *expr);
/* Entity-field
/* As can the field, it just must result in a value of TYPE_FIELD */
ast_expression *field;
};
-ast_entfield* ast_entfield_new(lex_ctx ctx, ast_expression *entity, ast_expression *field);
-ast_entfield* ast_entfield_new_force(lex_ctx ctx, ast_expression *entity, ast_expression *field, const ast_expression *outtype);
+ast_entfield* ast_entfield_new(lex_ctx_t ctx, ast_expression *entity, ast_expression *field);
+ast_entfield* ast_entfield_new_force(lex_ctx_t ctx, ast_expression *entity, ast_expression *field, const ast_expression *outtype);
/* Member access:
*
const char *name;
bool rvalue;
};
-ast_member* ast_member_new(lex_ctx ctx, ast_expression *owner, unsigned int field, const char *name);
+ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int field, const char *name);
void ast_member_delete(ast_member*);
bool ast_member_set_name(ast_member*, const char *name);
ast_expression *array;
ast_expression *index;
};
-ast_array_index* ast_array_index_new(lex_ctx ctx, ast_expression *array, ast_expression *index);
+ast_array_index* ast_array_index_new(lex_ctx_t ctx, ast_expression *array, ast_expression *index);
/* Vararg pipe node:
*
ast_expression expression;
ast_expression *index;
};
-ast_argpipe* ast_argpipe_new(lex_ctx ctx, ast_expression *index);
+ast_argpipe* ast_argpipe_new(lex_ctx_t ctx, ast_expression *index);
/* Store
*
ast_expression *dest;
ast_expression *source;
};
-ast_store* ast_store_new(lex_ctx ctx, int op,
+ast_store* ast_store_new(lex_ctx_t ctx, int op,
ast_expression *d, ast_expression *s);
/* If
ast_expression *on_true;
ast_expression *on_false;
};
-ast_ifthen* ast_ifthen_new(lex_ctx ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse);
+ast_ifthen* ast_ifthen_new(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse);
/* Ternary expressions...
*
ast_expression *on_true;
ast_expression *on_false;
};
-ast_ternary* ast_ternary_new(lex_ctx ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse);
+ast_ternary* ast_ternary_new(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse);
/* A general loop node
*
bool pre_not;
bool post_not;
};
-ast_loop* ast_loop_new(lex_ctx ctx,
+ast_loop* ast_loop_new(lex_ctx_t ctx,
ast_expression *initexpr,
ast_expression *precond, bool pre_not,
ast_expression *postcond, bool post_not,
bool is_continue;
unsigned int levels;
};
-ast_breakcont* ast_breakcont_new(lex_ctx ctx, bool iscont, unsigned int levels);
+ast_breakcont* ast_breakcont_new(lex_ctx_t ctx, bool iscont, unsigned int levels);
/* Switch Statements
*
ast_switch_case *cases;
};
-ast_switch* ast_switch_new(lex_ctx ctx, ast_expression *op);
+ast_switch* ast_switch_new(lex_ctx_t ctx, ast_expression *op);
/* Label nodes
*
bool undefined;
};
-ast_label* ast_label_new(lex_ctx ctx, const char *name, bool undefined);
+ast_label* ast_label_new(lex_ctx_t ctx, const char *name, bool undefined);
/* GOTO nodes
*
ir_block *irblock_from;
};
-ast_goto* ast_goto_new(lex_ctx ctx, const char *name);
+ast_goto* ast_goto_new(lex_ctx_t ctx, const char *name);
void ast_goto_set_label(ast_goto*, ast_label*);
/* CALL node
ast_expression* *params;
ast_expression *va_count;
};
-ast_call* ast_call_new(lex_ctx ctx,
+ast_call* ast_call_new(lex_ctx_t ctx,
ast_expression *funcexpr);
bool ast_call_check_types(ast_call*, ast_expression *this_func_va_type);
ast_expression* *exprs;
ast_expression* *collect;
};
-ast_block* ast_block_new(lex_ctx ctx);
+ast_block* ast_block_new(lex_ctx_t ctx);
void ast_block_delete(ast_block*);
void ast_block_set_type(ast_block*, ast_expression *from);
void ast_block_collect(ast_block*, ast_expression*);
ast_value *fixedparams;
ast_value *return_value;
};
-ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype);
+ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype);
/* This will NOT delete the underlying ast_value */
void ast_function_delete(ast_function*);
/* For "optimized" builds this can just keep returning "foo"...
/*
* We could use the old method of casting to uintptr_t then to void*
- * or qcint; however, it's incredibly unsafe for two reasons.
+ * or qcint_t; however, it's incredibly unsafe for two reasons.
* 1) The compilers aliasing optimization can legally make it unstable
* (it's undefined behaviour).
*
*/
typedef union {
void *enter;
- qcint leave;
+ qcint_t leave;
} code_hash_entry_t;
/* Some sanity macros */
#define CODE_HASH_ENTER(ENTRY) ((ENTRY).enter)
#define CODE_HASH_LEAVE(ENTRY) ((ENTRY).leave)
-void code_push_statement(code_t *code, prog_section_statement *stmt, int linenum)
+void code_push_statement(code_t *code, prog_section_statement_t *stmt, int linenum)
{
vec_push(code->statements, *stmt);
vec_push(code->linenums, linenum);
}
code_t *code_init() {
- static prog_section_function empty_function = {0,0,0,0,0,0,0,{0,0,0,0,0,0,0,0}};
- static prog_section_statement empty_statement = {0,{0},{0},{0}};
- static prog_section_def empty_def = {0, 0, 0};
+ static prog_section_function_t empty_function = {0,0,0,0,0,0,0,{0,0,0,0,0,0,0,0}};
+ static prog_section_statement_t empty_statement = {0,{0},{0},{0}};
+ static prog_section_def_t empty_def = {0, 0, 0};
code_t *code = (code_t*)mem_a(sizeof(code_t));
int i = 0;
return CODE_HASH_LEAVE(existing);
}
-qcint code_alloc_field (code_t *code, size_t qcsize)
+qcint_t code_alloc_field (code_t *code, size_t qcsize)
{
- qcint pos = (qcint)code->entfields;
+ qcint_t pos = (qcint_t)code->entfields;
code->entfields += qcsize;
return pos;
}
-static void code_create_header(code_t *code, prog_header *code_header) {
- code_header->statements.offset = sizeof(prog_header);
+static void code_create_header(code_t *code, prog_header_t *code_header) {
+ code_header->statements.offset = sizeof(prog_header_t);
code_header->statements.length = vec_size(code->statements);
- code_header->defs.offset = code_header->statements.offset + (sizeof(prog_section_statement) * vec_size(code->statements));
+ code_header->defs.offset = code_header->statements.offset + (sizeof(prog_section_statement_t) * vec_size(code->statements));
code_header->defs.length = vec_size(code->defs);
- code_header->fields.offset = code_header->defs.offset + (sizeof(prog_section_def) * vec_size(code->defs));
+ code_header->fields.offset = code_header->defs.offset + (sizeof(prog_section_def_t) * vec_size(code->defs));
code_header->fields.length = vec_size(code->fields);
- code_header->functions.offset = code_header->fields.offset + (sizeof(prog_section_field) * vec_size(code->fields));
+ code_header->functions.offset = code_header->fields.offset + (sizeof(prog_section_field_t) * vec_size(code->fields));
code_header->functions.length = vec_size(code->functions);
- code_header->globals.offset = code_header->functions.offset + (sizeof(prog_section_function) * vec_size(code->functions));
+ code_header->globals.offset = code_header->functions.offset + (sizeof(prog_section_function_t) * vec_size(code->functions));
code_header->globals.length = vec_size(code->globals);
- code_header->strings.offset = code_header->globals.offset + (sizeof(int32_t) * vec_size(code->globals));
+ code_header->strings.offset = code_header->globals.offset + (sizeof(int32_t) * vec_size(code->globals));
code_header->strings.length = vec_size(code->chars);
code_header->version = 6;
code_header->skip = 0;
* These are not part of the header but we ensure LE format here to save on duplicated
* code.
*/
- util_endianswap(code->statements, vec_size(code->statements), sizeof(prog_section_statement));
- util_endianswap(code->defs, vec_size(code->defs), sizeof(prog_section_def));
- util_endianswap(code->fields, vec_size(code->fields), sizeof(prog_section_field));
- util_endianswap(code->functions, vec_size(code->functions), sizeof(prog_section_function));
+ util_endianswap(code->statements, vec_size(code->statements), sizeof(prog_section_statement_t));
+ util_endianswap(code->defs, vec_size(code->defs), sizeof(prog_section_def_t));
+ util_endianswap(code->fields, vec_size(code->fields), sizeof(prog_section_field_t));
+ util_endianswap(code->functions, vec_size(code->functions), sizeof(prog_section_function_t));
util_endianswap(code->globals, vec_size(code->globals), sizeof(int32_t));
}
* we're going to add.
*/
bool code_write_memory(code_t *code, uint8_t **datmem, size_t *sizedat, uint8_t **lnomem, size_t *sizelno) {
- prog_header code_header;
- uint32_t offset = 0;
+ prog_header_t code_header;
+ uint32_t offset = 0;
if (!datmem)
return false;
}
/* Write out the dat */
- *sizedat += sizeof(prog_header);
- *sizedat += sizeof(prog_section_statement) * vec_size(code->statements);
- *sizedat += sizeof(prog_section_def) * vec_size(code->defs);
- *sizedat += sizeof(prog_section_field) * vec_size(code->fields);
- *sizedat += sizeof(prog_section_function) * vec_size(code->functions);
- *sizedat += sizeof(int32_t) * vec_size(code->globals);
- *sizedat += 1 * vec_size(code->chars);
+ *sizedat += sizeof(prog_header_t);
+ *sizedat += sizeof(prog_section_statement_t) * vec_size(code->statements);
+ *sizedat += sizeof(prog_section_def_t) * vec_size(code->defs);
+ *sizedat += sizeof(prog_section_field_t) * vec_size(code->fields);
+ *sizedat += sizeof(prog_section_function_t) * vec_size(code->functions);
+ *sizedat += sizeof(int32_t) * vec_size(code->globals);
+ *sizedat += 1 * vec_size(code->chars);
*datmem = (uint8_t*)mem_a(*sizedat);
- WRITE_CHUNK(datmem, &code_header, sizeof(prog_header));
- WRITE_CHUNK(datmem, code->statements, sizeof(prog_section_statement) * vec_size(code->statements));
- WRITE_CHUNK(datmem, code->defs, sizeof(prog_section_def) * vec_size(code->defs));
- WRITE_CHUNK(datmem, code->fields, sizeof(prog_section_field) * vec_size(code->fields));
- WRITE_CHUNK(datmem, code->functions, sizeof(prog_section_function) * vec_size(code->functions));
- WRITE_CHUNK(datmem, code->globals, sizeof(int32_t) * vec_size(code->globals));
- WRITE_CHUNK(datmem, code->chars, 1 * vec_size(code->chars));
+ WRITE_CHUNK(datmem, &code_header, sizeof(prog_header_t));
+ WRITE_CHUNK(datmem, code->statements, sizeof(prog_section_statement_t) * vec_size(code->statements));
+ WRITE_CHUNK(datmem, code->defs, sizeof(prog_section_def_t) * vec_size(code->defs));
+ WRITE_CHUNK(datmem, code->fields, sizeof(prog_section_field_t) * vec_size(code->fields));
+ WRITE_CHUNK(datmem, code->functions, sizeof(prog_section_function_t) * vec_size(code->functions));
+ WRITE_CHUNK(datmem, code->globals, sizeof(int32_t) * vec_size(code->globals));
+ WRITE_CHUNK(datmem, code->chars, 1 * vec_size(code->chars));
#undef WRITE_CHUNK
}
bool code_write(code_t *code, const char *filename, const char *lnofile) {
- prog_header code_header;
- FILE *fp = NULL;
- size_t it = 2;
+ prog_header_t code_header;
+ FILE *fp = NULL;
+ size_t it = 2;
code_create_header(code, &code_header);
if (!fp)
return false;
- if (1 != fs_file_write(&code_header, sizeof(prog_header) , 1 , fp) ||
- vec_size(code->statements) != fs_file_write(code->statements, sizeof(prog_section_statement), vec_size(code->statements), fp) ||
- vec_size(code->defs) != fs_file_write(code->defs, sizeof(prog_section_def) , vec_size(code->defs) , fp) ||
- vec_size(code->fields) != fs_file_write(code->fields, sizeof(prog_section_field) , vec_size(code->fields) , fp) ||
- vec_size(code->functions) != fs_file_write(code->functions, sizeof(prog_section_function) , vec_size(code->functions) , fp) ||
- vec_size(code->globals) != fs_file_write(code->globals, sizeof(int32_t) , vec_size(code->globals) , fp) ||
- vec_size(code->chars) != fs_file_write(code->chars, 1 , vec_size(code->chars) , fp))
+ if (1 != fs_file_write(&code_header, sizeof(prog_header_t) , 1 , fp) ||
+ vec_size(code->statements) != fs_file_write(code->statements, sizeof(prog_section_statement_t), vec_size(code->statements), fp) ||
+ vec_size(code->defs) != fs_file_write(code->defs, sizeof(prog_section_def_t) , vec_size(code->defs) , fp) ||
+ vec_size(code->fields) != fs_file_write(code->fields, sizeof(prog_section_field_t) , vec_size(code->fields) , fp) ||
+ vec_size(code->functions) != fs_file_write(code->functions, sizeof(prog_section_function_t) , vec_size(code->functions) , fp) ||
+ vec_size(code->globals) != fs_file_write(code->globals, sizeof(int32_t) , vec_size(code->globals) , fp) ||
+ vec_size(code->chars) != fs_file_write(code->chars, 1 , vec_size(code->chars) , fp))
{
fs_file_close(fp);
return false;
va_end (va);
}
-void con_cvprintmsg(void *ctx, int lvl, const char *msgtype, const char *msg, va_list ap) {
- con_vprintmsg(lvl, ((lex_ctx*)ctx)->file, ((lex_ctx*)ctx)->line, ((lex_ctx*)ctx)->column, msgtype, msg, ap);
+void con_cvprintmsg(lex_ctx_t ctx, int lvl, const char *msgtype, const char *msg, va_list ap) {
+ con_vprintmsg(lvl, ctx.file, ctx.line, ctx.column, msgtype, msg, ap);
}
-void con_cprintmsg (void *ctx, int lvl, const char *msgtype, const char *msg, ...) {
+void con_cprintmsg(lex_ctx_t ctx, int lvl, const char *msgtype, const char *msg, ...) {
va_list va;
va_start(va, msg);
con_cvprintmsg(ctx, lvl, msgtype, msg, va);
}
/* General error interface */
-size_t compile_errors = 0;
+size_t compile_errors = 0;
size_t compile_warnings = 0;
-
-size_t compile_Werrors = 0;
-static lex_ctx first_werror;
+size_t compile_Werrors = 0;
+static lex_ctx_t first_werror;
void compile_show_werrors()
{
- con_cprintmsg((void*)&first_werror, LVL_ERROR, "first warning", "was here");
+ con_cprintmsg(first_werror, LVL_ERROR, "first warning", "was here");
}
-void vcompile_error(lex_ctx ctx, const char *msg, va_list ap)
+void vcompile_error(lex_ctx_t ctx, const char *msg, va_list ap)
{
++compile_errors;
- con_cvprintmsg((void*)&ctx, LVL_ERROR, "error", msg, ap);
+ con_cvprintmsg(ctx, LVL_ERROR, "error", msg, ap);
}
-void compile_error(lex_ctx ctx, const char *msg, ...)
+void compile_error(lex_ctx_t ctx, const char *msg, ...)
{
va_list ap;
va_start(ap, msg);
va_end(ap);
}
-bool GMQCC_WARN vcompile_warning(lex_ctx ctx, int warntype, const char *fmt, va_list ap)
+bool GMQCC_WARN vcompile_warning(lex_ctx_t ctx, int warntype, const char *fmt, va_list ap)
{
const char *msgtype = "warning";
int lvl = LVL_WARNING;
return OPTS_WERROR(warntype) && OPTS_FLAG(BAIL_ON_WERROR);
}
-bool GMQCC_WARN compile_warning(lex_ctx ctx, int warntype, const char *fmt, ...)
+bool GMQCC_WARN compile_warning(lex_ctx_t ctx, int warntype, const char *fmt, ...)
{
bool r;
va_list ap;
printf(": %s\n", util_strerror(err));
}
-static void qcvmerror(qc_program *prog, const char *fmt, ...)
+static void qcvmerror(qc_program_t *prog, const char *fmt, ...)
{
va_list ap;
putchar('\n');
}
-qc_program* prog_load(const char *filename, bool skipversion)
+qc_program_t* prog_load(const char *filename, bool skipversion)
{
- qc_program *prog;
- prog_header header;
+ qc_program_t *prog;
+ prog_header_t header;
FILE *file = fs_file_open(filename, "rb");
if (!file)
return NULL;
}
- prog = (qc_program*)mem_a(sizeof(qc_program));
+ prog = (qc_program_t*)mem_a(sizeof(qc_program_t));
if (!prog) {
fs_file_close(file);
fprintf(stderr, "failed to allocate program data\n");
return NULL;
}
-void prog_delete(qc_program *prog)
+void prog_delete(qc_program_t *prog)
{
if (prog->filename) mem_d(prog->filename);
vec_free(prog->code);
* VM code
*/
-const char* prog_getstring(qc_program *prog, qcint str) {
+const char* prog_getstring(qc_program_t *prog, qcint_t str) {
/* cast for return required for C++ */
- if (str < 0 || str >= (qcint)vec_size(prog->strings))
+ if (str < 0 || str >= (qcint_t)vec_size(prog->strings))
return "<<<invalid string>>>";
return prog->strings + str;
}
-prog_section_def* prog_entfield(qc_program *prog, qcint off) {
+prog_section_def_t* prog_entfield(qc_program_t *prog, qcint_t off) {
size_t i;
for (i = 0; i < vec_size(prog->fields); ++i) {
if (prog->fields[i].offset == off)
return NULL;
}
-prog_section_def* prog_getdef(qc_program *prog, qcint off)
+prog_section_def_t* prog_getdef(qc_program_t *prog, qcint_t off)
{
size_t i;
for (i = 0; i < vec_size(prog->defs); ++i) {
return NULL;
}
-qcany* prog_getedict(qc_program *prog, qcint e) {
- if (e >= (qcint)vec_size(prog->entitypool)) {
+qcany_t* prog_getedict(qc_program_t *prog, qcint_t e) {
+ if (e >= (qcint_t)vec_size(prog->entitypool)) {
prog->vmerror++;
fprintf(stderr, "Accessing out of bounds edict %i\n", (int)e);
e = 0;
}
- return (qcany*)(prog->entitydata + (prog->entityfields * e));
+ return (qcany_t*)(prog->entitydata + (prog->entityfields * e));
}
-qcint prog_spawn_entity(qc_program *prog) {
+qcint_t prog_spawn_entity(qc_program_t *prog) {
char *data;
- qcint e;
- for (e = 0; e < (qcint)vec_size(prog->entitypool); ++e) {
+ qcint_t e;
+ for (e = 0; e < (qcint_t)vec_size(prog->entitypool); ++e) {
if (!prog->entitypool[e]) {
data = (char*)(prog->entitydata + (prog->entityfields * e));
- memset(data, 0, prog->entityfields * sizeof(qcint));
+ memset(data, 0, prog->entityfields * sizeof(qcint_t));
return e;
}
}
vec_push(prog->entitypool, true);
prog->entities++;
data = (char*)vec_add(prog->entitydata, prog->entityfields);
- memset(data, 0, prog->entityfields * sizeof(qcint));
+ memset(data, 0, prog->entityfields * sizeof(qcint_t));
return e;
}
-void prog_free_entity(qc_program *prog, qcint e) {
+void prog_free_entity(qc_program_t *prog, qcint_t e) {
if (!e) {
prog->vmerror++;
fprintf(stderr, "Trying to free world entity\n");
return;
}
- if (e >= (qcint)vec_size(prog->entitypool)) {
+ if (e >= (qcint_t)vec_size(prog->entitypool)) {
prog->vmerror++;
fprintf(stderr, "Trying to free out of bounds entity\n");
return;
prog->entitypool[e] = false;
}
-qcint prog_tempstring(qc_program *prog, const char *str) {
+qcint_t prog_tempstring(qc_program_t *prog, const char *str) {
size_t len = strlen(str);
size_t at = prog->tempstring_at;
return len;
}
-static void trace_print_global(qc_program *prog, unsigned int glob, int vtype) {
+static void trace_print_global(qc_program_t *prog, unsigned int glob, int vtype) {
static char spaces[28+1] = " ";
- prog_section_def *def;
- qcany *value;
+ prog_section_def_t *def;
+ qcany_t *value;
int len;
if (!glob) {
}
def = prog_getdef(prog, glob);
- value = (qcany*)(&prog->globals[glob]);
+ value = (qcany_t*)(&prog->globals[glob]);
len = printf("[@%u] ", glob);
if (def) {
}
}
-static void prog_print_statement(qc_program *prog, prog_section_statement *st) {
+static void prog_print_statement(qc_program_t *prog, prog_section_statement_t *st) {
if (st->opcode >= VINSTR_END) {
printf("<illegal instruction %d>\n", st->opcode);
return;
}
}
-static qcint prog_enterfunction(qc_program *prog, prog_section_function *func) {
- qc_exec_stack st;
+static qcint_t prog_enterfunction(qc_program_t *prog, prog_section_function_t *func) {
+ qc_exec_stack_t st;
size_t parampos;
int32_t p;
#ifdef QCVM_BACKUP_STRATEGY_CALLER_VARS
if (vec_size(prog->stack))
{
- prog_section_function *cur;
+ prog_section_function_t *cur;
cur = prog->stack[vec_size(prog->stack)-1].function;
if (cur)
{
- qcint *globals = prog->globals + cur->firstlocal;
+ qcint_t *globals = prog->globals + cur->firstlocal;
vec_append(prog->localstack, cur->locals, globals);
}
}
#else
{
- qcint *globals = prog->globals + func->firstlocal;
+ qcint_t *globals = prog->globals + func->firstlocal;
vec_append(prog->localstack, func->locals, globals);
}
#endif
return func->entry;
}
-static qcint prog_leavefunction(qc_program *prog) {
- prog_section_function *prev = NULL;
+static qcint_t prog_leavefunction(qc_program_t *prog) {
+ prog_section_function_t *prev = NULL;
size_t oldsp;
- qc_exec_stack st = vec_last(prog->stack);
+ qc_exec_stack_t st = vec_last(prog->stack);
if (prog->xflags & VMXF_TRACE) {
if (vec_size(prog->function_stack))
oldsp = prog->stack[vec_size(prog->stack)-1].localsp;
#endif
if (prev) {
- qcint *globals = prog->globals + prev->firstlocal;
+ qcint_t *globals = prog->globals + prev->firstlocal;
memcpy(globals, prog->localstack + oldsp, prev->locals * sizeof(prog->localstack[0]));
/* vec_remove(prog->localstack, oldsp, vec_size(prog->localstack)-oldsp); */
vec_shrinkto(prog->localstack, oldsp);
return st.stmt - 1; /* offset the ++st */
}
-bool prog_exec(qc_program *prog, prog_section_function *func, size_t flags, long maxjumps) {
+bool prog_exec(qc_program_t *prog, prog_section_function_t *func, size_t flags, long maxjumps) {
long jumpcount = 0;
size_t oldxflags = prog->xflags;
- prog_section_statement *st;
+ prog_section_statement_t *st;
prog->vmerror = 0;
prog->xflags = flags;
} \
} while (0)
-#define GetGlobal(idx) ((qcany*)(prog->globals + (idx)))
+#define GetGlobal(idx) ((qcany_t*)(prog->globals + (idx)))
#define GetArg(num) GetGlobal(OFS_PARM0 + 3*(num))
#define Return(any) *(GetGlobal(OFS_RETURN)) = (any)
-static int qc_print(qc_program *prog) {
+static int qc_print(qc_program_t *prog) {
size_t i;
const char *laststr = NULL;
for (i = 0; i < (size_t)prog->argc; ++i) {
- qcany *str = (qcany*)(prog->globals + OFS_PARM0 + 3*i);
+ qcany_t *str = (qcany_t*)(prog->globals + OFS_PARM0 + 3*i);
laststr = prog_getstring(prog, str->string);
printf("%s", laststr);
}
return 0;
}
-static int qc_error(qc_program *prog) {
+static int qc_error(qc_program_t *prog) {
fprintf(stderr, "*** VM raised an error:\n");
qc_print(prog);
prog->vmerror++;
return -1;
}
-static int qc_ftos(qc_program *prog) {
+static int qc_ftos(qc_program_t *prog) {
char buffer[512];
- qcany *num;
- qcany str;
+ qcany_t *num;
+ qcany_t str;
CheckArgs(1);
num = GetArg(0);
util_snprintf(buffer, sizeof(buffer), "%g", num->_float);
return 0;
}
-static int qc_stof(qc_program *prog) {
- qcany *str;
- qcany num;
+static int qc_stof(qc_program_t *prog) {
+ qcany_t *str;
+ qcany_t num;
CheckArgs(1);
str = GetArg(0);
num._float = (float)strtod(prog_getstring(prog, str->string), NULL);
return 0;
}
-static int qc_vtos(qc_program *prog) {
+static int qc_vtos(qc_program_t *prog) {
char buffer[512];
- qcany *num;
- qcany str;
+ qcany_t *num;
+ qcany_t str;
CheckArgs(1);
num = GetArg(0);
util_snprintf(buffer, sizeof(buffer), "'%g %g %g'", num->vector[0], num->vector[1], num->vector[2]);
return 0;
}
-static int qc_etos(qc_program *prog) {
+static int qc_etos(qc_program_t *prog) {
char buffer[512];
- qcany *num;
- qcany str;
+ qcany_t *num;
+ qcany_t str;
CheckArgs(1);
num = GetArg(0);
util_snprintf(buffer, sizeof(buffer), "%i", num->_int);
return 0;
}
-static int qc_spawn(qc_program *prog) {
- qcany ent;
+static int qc_spawn(qc_program_t *prog) {
+ qcany_t ent;
CheckArgs(0);
ent.edict = prog_spawn_entity(prog);
Return(ent);
return (ent.edict ? 0 : -1);
}
-static int qc_kill(qc_program *prog) {
- qcany *ent;
+static int qc_kill(qc_program_t *prog) {
+ qcany_t *ent;
CheckArgs(1);
ent = GetArg(0);
prog_free_entity(prog, ent->edict);
return 0;
}
-static int qc_sqrt(qc_program *prog) {
- qcany *num, out;
+static int qc_sqrt(qc_program_t *prog) {
+ qcany_t *num, out;
CheckArgs(1);
num = GetArg(0);
out._float = sqrt(num->_float);
return 0;
}
-static int qc_vlen(qc_program *prog) {
- qcany *vec, len;
+static int qc_vlen(qc_program_t *prog) {
+ qcany_t *vec, len;
CheckArgs(1);
vec = GetArg(0);
len._float = sqrt(vec->vector[0] * vec->vector[0] +
return 0;
}
-static int qc_normalize(qc_program *prog) {
+static int qc_normalize(qc_program_t *prog) {
double len;
- qcany *vec;
- qcany out;
+ qcany_t *vec;
+ qcany_t out;
CheckArgs(1);
vec = GetArg(0);
len = sqrt(vec->vector[0] * vec->vector[0] +
return 0;
}
-static int qc_strcat(qc_program *prog) {
+static int qc_strcat(qc_program_t *prog) {
char *buffer;
size_t len1, len2;
- qcany *str1, *str2;
- qcany out;
+ qcany_t *str1, *str2;
+ qcany_t out;
const char *cstr1;
const char *cstr2;
return 0;
}
-static int qc_strcmp(qc_program *prog) {
- qcany *str1, *str2;
- qcany out;
+static int qc_strcmp(qc_program_t *prog) {
+ qcany_t *str1, *str2;
+ qcany_t out;
const char *cstr1;
const char *cstr2;
return 0;
}
-static int qc_floor(qc_program *prog) {
- qcany *num, out;
+static int qc_floor(qc_program_t *prog) {
+ qcany_t *num, out;
CheckArgs(1);
num = GetArg(0);
out._float = floor(num->_float);
return 0;
}
-static prog_builtin qc_builtins[] = {
+static prog_builtin_t qc_builtins[] = {
NULL,
&qc_print, /* 1 */
&qc_ftos, /* 2 */
" -string <s> pass a string parameter to main() \n");
}
-static void prog_main_setparams(qc_program *prog) {
+static void prog_main_setparams(qc_program_t *prog) {
size_t i;
- qcany *arg;
+ qcany_t *arg;
for (i = 0; i < vec_size(main_params); ++i) {
arg = GetGlobal(OFS_PARM0 + 3*i);
*dest = '\0';
}
-void prog_disasm_function(qc_program *prog, size_t id);
+void prog_disasm_function(qc_program_t *prog, size_t id);
int main(int argc, char **argv) {
size_t i;
- qcint fnmain = -1;
- qc_program *prog;
+ qcint_t fnmain = -1;
+ qc_program_t *prog;
size_t xflags = VMXF_DEFAULT;
bool opts_printfields = false;
bool opts_printdefs = false;
if (opts_v) {
switch (prog->defs[i].type & DEF_TYPEMASK) {
case TYPE_FLOAT:
- printf(" [init: %g]", ((qcany*)(prog->globals + prog->defs[i].offset))->_float);
+ printf(" [init: %g]", ((qcany_t*)(prog->globals + prog->defs[i].offset))->_float);
break;
case TYPE_INTEGER:
- printf(" [init: %i]", (int)( ((qcany*)(prog->globals + prog->defs[i].offset))->_int ));
+ printf(" [init: %i]", (int)( ((qcany_t*)(prog->globals + prog->defs[i].offset))->_int ));
break;
case TYPE_ENTITY:
case TYPE_FUNCTION:
case TYPE_FIELD:
case TYPE_POINTER:
- printf(" [init: %u]", (unsigned)( ((qcany*)(prog->globals + prog->defs[i].offset))->_int ));
+ printf(" [init: %u]", (unsigned)( ((qcany_t*)(prog->globals + prog->defs[i].offset))->_int ));
break;
case TYPE_STRING:
- getstring = prog_getstring(prog, ((qcany*)(prog->globals + prog->defs[i].offset))->string);
+ getstring = prog_getstring(prog, ((qcany_t*)(prog->globals + prog->defs[i].offset))->string);
escape = (char*)mem_a(strlen(getstring) * 2 + 1); /* will be enough */
escapestring(escape, getstring);
printf(" [init: `%s`]", escape);
printf(") builtin %i\n", (int)-start);
else {
size_t funsize = 0;
- prog_section_statement *st = prog->code + start;
+ prog_section_statement_t *st = prog->code + start;
for (;st->opcode != INSTR_DONE; ++st)
++funsize;
printf(") - %lu instructions", (unsigned long)funsize);
for (i = 1; i < vec_size(prog->functions); ++i) {
const char *name = prog_getstring(prog, prog->functions[i].name);
if (!strcmp(name, "main"))
- fnmain = (qcint)i;
+ fnmain = (qcint_t)i;
}
if (fnmain > 0)
{
return 0;
}
-void prog_disasm_function(qc_program *prog, size_t id) {
- prog_section_function *fdef = prog->functions + id;
- prog_section_statement *st;
+void prog_disasm_function(qc_program_t *prog, size_t id) {
+ prog_section_function_t *fdef = prog->functions + id;
+ prog_section_statement_t *st;
if (fdef->entry < 0) {
printf("FUNCTION \"%s\" = builtin #%i\n", prog_getstring(prog, fdef->name), (int)-fdef->entry);
* sort of isn't, which makes it nicer looking.
*/
-#define OPA ( (qcany*) (prog->globals + st->o1.u1) )
-#define OPB ( (qcany*) (prog->globals + st->o2.u1) )
-#define OPC ( (qcany*) (prog->globals + st->o3.u1) )
+#define OPA ( (qcany_t*) (prog->globals + st->o1.u1) )
+#define OPB ( (qcany_t*) (prog->globals + st->o2.u1) )
+#define OPC ( (qcany_t*) (prog->globals + st->o3.u1) )
-#define GLOBAL(x) ( (qcany*) (prog->globals + (x)) )
+#define GLOBAL(x) ( (qcany_t*) (prog->globals + (x)) )
/* to be consistent with current darkplaces behaviour */
#if !defined(FLOAT_IS_TRUE_FOR_INT)
#endif
while (1) {
- prog_section_function *newf;
- qcany *ed;
- qcany *ptr;
+ prog_section_function_t *newf;
+ qcany_t *ed;
+ qcany_t *ptr;
++st;
break;
case INSTR_MUL_FV:
{
- qcfloat f = OPA->_float;
+ qcfloat_t f = OPA->_float;
OPC->vector[0] = f * OPB->vector[0];
OPC->vector[1] = f * OPB->vector[1];
OPC->vector[2] = f * OPB->vector[2];
}
case INSTR_MUL_VF:
{
- qcfloat f = OPB->_float;
+ qcfloat_t f = OPB->_float;
OPC->vector[0] = f * OPA->vector[0];
OPC->vector[1] = f * OPA->vector[1];
OPC->vector[2] = f * OPA->vector[2];
goto cleanup;
}
ed = prog_getedict(prog, OPA->edict);
- OPC->_int = ((qcany*)( ((qcint*)ed) + OPB->_int ))->_int;
+ OPC->_int = ((qcany_t*)( ((qcint_t*)ed) + OPB->_int ))->_int;
break;
case INSTR_LOAD_V:
if (OPA->edict < 0 || OPA->edict >= prog->entities) {
qcvmerror(prog, "progs `%s` attempted to read an out of bounds entity", prog->filename);
goto cleanup;
}
- if (OPB->_int < 0 || OPB->_int + 3 > (qcint)prog->entityfields)
+ if (OPB->_int < 0 || OPB->_int + 3 > (qcint_t)prog->entityfields)
{
qcvmerror(prog, "prog `%s` attempted to read an invalid field from entity (%i)",
prog->filename,
goto cleanup;
}
ed = prog_getedict(prog, OPA->edict);
- ptr = (qcany*)( ((qcint*)ed) + OPB->_int );
+ ptr = (qcany_t*)( ((qcint_t*)ed) + OPB->_int );
OPC->ivector[0] = ptr->ivector[0];
OPC->ivector[1] = ptr->ivector[1];
OPC->ivector[2] = ptr->ivector[2];
}
ed = prog_getedict(prog, OPA->edict);
- OPC->_int = ((qcint*)ed) - prog->entitydata + OPB->_int;
+ OPC->_int = ((qcint_t*)ed) - prog->entitydata + OPB->_int;
break;
case INSTR_STORE_F:
case INSTR_STOREP_ENT:
case INSTR_STOREP_FLD:
case INSTR_STOREP_FNC:
- if (OPB->_int < 0 || OPB->_int >= (qcint)vec_size(prog->entitydata)) {
+ if (OPB->_int < 0 || OPB->_int >= (qcint_t)vec_size(prog->entitydata)) {
qcvmerror(prog, "`%s` attempted to write to an out of bounds edict (%i)", prog->filename, OPB->_int);
goto cleanup;
}
- if (OPB->_int < (qcint)prog->entityfields && !prog->allowworldwrites)
+ if (OPB->_int < (qcint_t)prog->entityfields && !prog->allowworldwrites)
qcvmerror(prog, "`%s` tried to assign to world.%s (field %i)\n",
prog->filename,
prog_getstring(prog, prog_entfield(prog, OPB->_int)->name),
OPB->_int);
- ptr = (qcany*)(prog->entitydata + OPB->_int);
+ ptr = (qcany_t*)(prog->entitydata + OPB->_int);
ptr->_int = OPA->_int;
break;
case INSTR_STOREP_V:
- if (OPB->_int < 0 || OPB->_int + 2 >= (qcint)vec_size(prog->entitydata)) {
+ if (OPB->_int < 0 || OPB->_int + 2 >= (qcint_t)vec_size(prog->entitydata)) {
qcvmerror(prog, "`%s` attempted to write to an out of bounds edict (%i)", prog->filename, OPB->_int);
goto cleanup;
}
- if (OPB->_int < (qcint)prog->entityfields && !prog->allowworldwrites)
+ if (OPB->_int < (qcint_t)prog->entityfields && !prog->allowworldwrites)
qcvmerror(prog, "`%s` tried to assign to world.%s (field %i)\n",
prog->filename,
prog_getstring(prog, prog_entfield(prog, OPB->_int)->name),
OPB->_int);
- ptr = (qcany*)(prog->entitydata + OPB->_int);
+ ptr = (qcany_t*)(prog->entitydata + OPB->_int);
ptr->ivector[0] = OPA->ivector[0];
ptr->ivector[1] = OPA->ivector[1];
ptr->ivector[2] = OPA->ivector[2];
if (!OPA->function)
qcvmerror(prog, "NULL function in `%s`", prog->filename);
- if(!OPA->function || OPA->function >= (qcint)vec_size(prog->functions))
+ if(!OPA->function || OPA->function >= (qcint_t)vec_size(prog->functions))
{
qcvmerror(prog, "CALL outside the program in `%s`", prog->filename);
goto cleanup;
if (newf->entry < 0)
{
/* negative statements are built in functions */
- qcint builtinnumber = -newf->entry;
- if (builtinnumber < (qcint)prog->builtins_count && prog->builtins[builtinnumber])
+ qcint_t builtinnumber = -newf->entry;
+ if (builtinnumber < (qcint_t)prog->builtins_count && prog->builtins[builtinnumber])
prog->builtins[builtinnumber](prog);
else
qcvmerror(prog, "No such builtin #%i in %s! Try updating your gmqcc sources",
char *value;
/* a copy from the lexer */
union {
- vector v;
+ vec3_t v;
int i;
double f;
int t; /* type */
} pptoken;
typedef struct {
- lex_ctx ctx;
+ lex_ctx_t ctx;
char *name;
char **params;
#define ftepp_tokval(f) ((f)->lex->tok.value)
#define ftepp_ctx(f) ((f)->lex->tok.ctx)
-static void ftepp_errorat(ftepp_t *ftepp, lex_ctx ctx, const char *fmt, ...)
+static void ftepp_errorat(ftepp_t *ftepp, lex_ctx_t ctx, const char *fmt, ...)
{
va_list ap;
ftepp->errors++;
va_start(ap, fmt);
- con_cvprintmsg((void*)&ctx, LVL_ERROR, "error", fmt, ap);
+ con_cvprintmsg(ctx, LVL_ERROR, "error", fmt, ap);
va_end(ap);
}
ftepp->errors++;
va_start(ap, fmt);
- con_cvprintmsg((void*)&ftepp->lex->tok.ctx, LVL_ERROR, "error", fmt, ap);
+ con_cvprintmsg(ftepp->lex->tok.ctx, LVL_ERROR, "error", fmt, ap);
va_end(ap);
}
mem_d(self);
}
-static ppmacro *ppmacro_new(lex_ctx ctx, const char *name)
+static ppmacro *ppmacro_new(lex_ctx_t ctx, const char *name)
{
ppmacro *macro = (ppmacro*)mem_a(sizeof(ppmacro));
}
vec_push(message, '\0');
if (ftepp->output_on)
- con_cprintmsg(&ftepp->lex->tok.ctx, LVL_MSG, "message", message);
+ con_cprintmsg(ftepp->lex->tok.ctx, LVL_MSG, "message", message);
vec_free(message);
return;
}
return;
unescape (ftepp_tokval(ftepp), ftepp_tokval(ftepp));
- con_cprintmsg(&ftepp->lex->tok.ctx, LVL_MSG, "message", ftepp_tokval(ftepp));
+ con_cprintmsg(ftepp->lex->tok.ctx, LVL_MSG, "message", ftepp_tokval(ftepp));
}
/**
{
lex_file *old_lexer = ftepp->lex;
lex_file *inlex;
- lex_ctx ctx;
+ lex_ctx_t ctx;
char lineno[128];
char *filename;
char *old_includename;
ppcondition cond;
ppcondition *pc;
- lex_ctx ctx = ftepp_ctx(ftepp);
+ lex_ctx_t ctx = ftepp_ctx(ftepp);
if (!ftepp_skipspace(ftepp))
return false;
void ftepp_add_define(ftepp_t *ftepp, const char *source, const char *name)
{
ppmacro *macro;
- lex_ctx ctx = { "__builtin__", 0, 0 };
+ lex_ctx_t ctx = { "__builtin__", 0, 0 };
ctx.file = source;
macro = ppmacro_new(ctx, name);
/*vec_push(ftepp->macros, macro);*/
#define vec_upload(X,Y,S) ((void)(memcpy(vec_add((X), (S) * sizeof(*(Y))), (Y), (S) * sizeof(*(Y)))))
#define vec_remove(A,I,N) ((void)(memmove((A)+(I),(A)+((I)+(N)),sizeof(*(A))*(vec_meta(A)->used-(I)-(N))),vec_meta(A)->used-=(N)))
-typedef struct trie_s {
- void *value;
- struct trie_s *entries;
+typedef struct correct_trie_s {
+ void *value;
+ struct correct_trie_s *entries;
} correct_trie_t;
correct_trie_t* correct_trie_new(void);
-typedef struct hash_table_t {
+typedef struct hash_table_s {
size_t size;
struct hash_node_t **table;
} hash_table_t, *ht;
typedef struct {
uint32_t offset; /* Offset in file of where data begins */
uint32_t length; /* Length of section (how many of) */
-} prog_section;
+} prog_section_t;
typedef struct {
- uint32_t version; /* Program version (6) */
- uint16_t crc16;
- uint16_t skip;
-
- prog_section statements; /* prog_section_statement */
- prog_section defs; /* prog_section_def */
- prog_section fields; /* prog_section_field */
- prog_section functions; /* prog_section_function */
- prog_section strings;
- prog_section globals;
- uint32_t entfield; /* Number of entity fields */
-} prog_header;
+ uint32_t version; /* Program version (6) */
+ uint16_t crc16;
+ uint16_t skip;
+
+ prog_section_t statements; /* prog_section_statement */
+ prog_section_t defs; /* prog_section_def */
+ prog_section_t fields; /* prog_section_field */
+ prog_section_t functions; /* prog_section_function */
+ prog_section_t strings;
+ prog_section_t globals;
+ uint32_t entfield; /* Number of entity fields */
+} prog_header_t;
/*
* Each paramater incerements by 3 since vector types hold
* But this one is more sane to work with, and the
* type sizes are guranteed.
*/
-} prog_section_statement;
+} prog_section_statement_t;
typedef struct {
/*
uint16_t type;
uint16_t offset;
uint32_t name;
-} prog_section_both;
+} prog_section_both_t;
-typedef prog_section_both prog_section_def;
-typedef prog_section_both prog_section_field;
+typedef prog_section_both_t prog_section_def_t;
+typedef prog_section_both_t prog_section_field_t;
/* this is ORed to the type */
#define DEF_SAVEGLOBAL (1<<15)
uint32_t file; /* file of the source file */
int32_t nargs; /* number of arguments */
uint8_t argsize[8]; /* size of arguments (keep 8 always?) */
-} prog_section_function;
+} prog_section_function_t;
/*
* Instructions
/* TODO: elide */
extern const char *util_instr_str[VINSTR_END];
-/* uhh? */
-typedef float qcfloat;
-typedef int32_t qcint;
+/* TOO: _t */
+typedef float qcfloat_t;
+typedef int32_t qcint_t;
typedef struct {
- prog_section_statement *statements;
- int *linenums;
- prog_section_def *defs;
- prog_section_field *fields;
- prog_section_function *functions;
- int *globals;
- char *chars;
- uint16_t crc;
- uint32_t entfields;
- ht string_cache;
- qcint string_cached_empty;
+ prog_section_statement_t *statements;
+ int *linenums;
+ 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;
} code_t;
/*
code_t *code_init (void);
void code_cleanup (code_t *);
uint32_t code_genstring (code_t *, const char *string);
-qcint code_alloc_field (code_t *, size_t qcsize);
-void code_push_statement(code_t *, prog_section_statement *stmt, int linenum);
+qcint_t code_alloc_field (code_t *, size_t qcsize);
+void code_push_statement(code_t *, prog_section_statement_t *stmt, int linenum);
void code_pop_statement (code_t *);
/*
const char *file;
size_t line;
size_t column;
-} lex_ctx;
+} lex_ctx_t;
/*===================================================================*/
/*============================ con.c ================================*/
void con_vprintmsg (int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, va_list ap);
void con_printmsg (int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, ...);
-void con_cvprintmsg(void *ctx, int lvl, const char *msgtype, const char *msg, va_list ap);
-void con_cprintmsg (void *ctx, int lvl, const char *msgtype, const char *msg, ...);
+void con_cvprintmsg(lex_ctx_t ctx, int lvl, const char *msgtype, const char *msg, va_list ap);
+void con_cprintmsg (lex_ctx_t ctx, int lvl, const char *msgtype, const char *msg, ...);
void con_close (void);
void con_init (void);
extern size_t compile_Werrors;
extern size_t compile_warnings;
-void /********/ compile_error (lex_ctx ctx, /*LVL_ERROR*/ const char *msg, ...);
-void /********/ vcompile_error (lex_ctx ctx, /*LVL_ERROR*/ const char *msg, va_list ap);
-bool GMQCC_WARN compile_warning (lex_ctx ctx, int warntype, const char *fmt, ...);
-bool GMQCC_WARN vcompile_warning(lex_ctx ctx, int warntype, const char *fmt, va_list ap);
+void /********/ compile_error (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, ...);
+void /********/ vcompile_error (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, va_list ap);
+bool GMQCC_WARN compile_warning (lex_ctx_t ctx, int warntype, const char *fmt, ...);
+bool GMQCC_WARN vcompile_warning(lex_ctx_t ctx, int warntype, const char *fmt, va_list ap);
void compile_show_werrors(void);
/*===================================================================*/
};
typedef struct {
- qcfloat x, y, z;
-} vector;
+ qcfloat_t x, y, z;
+} vec3_t;
-vector vec3_add (vector, vector);
-vector vec3_sub (vector, vector);
-qcfloat vec3_mulvv(vector, vector);
-vector vec3_mulvf(vector, float);
+vec3_t vec3_add (vec3_t, vec3_t);
+vec3_t vec3_sub (vec3_t, vec3_t);
+qcfloat_t vec3_mulvv(vec3_t, vec3_t);
+vec3_t vec3_mulvf(vec3_t, float);
/*===================================================================*/
/*============================= exec.c ==============================*/
* float and int here.
*/
typedef union {
- qcint _int;
- qcint string;
- qcint function;
- qcint edict;
- qcfloat _float;
- qcfloat vector[3];
- qcint ivector[3];
-} qcany;
-
-typedef char qcfloat_size_is_correct [sizeof(qcfloat) == 4 ?1:-1];
-typedef char qcint_size_is_correct [sizeof(qcint) == 4 ?1:-1];
+ qcint_t _int;
+ qcint_t string;
+ qcint_t function;
+ qcint_t edict;
+ qcfloat_t _float;
+ qcfloat_t vector[3];
+ qcint_t ivector[3];
+} qcany_t;
+
+typedef char qcfloat_t_size_is_correct [sizeof(qcfloat_t) == 4 ?1:-1];
+typedef char qcint_t_size_is_correct [sizeof(qcint_t) == 4 ?1:-1];
enum {
VMERR_OK,
VMERR_TEMPSTRING_ALLOC,
-
VMERR_END
};
#define VMXF_PROFILE 0x0002 /* profile: increment the profile counters */
struct qc_program_s;
-
-typedef int (*prog_builtin)(struct qc_program_s *prog);
+typedef int (*prog_builtin_t)(struct qc_program_s *prog);
typedef struct {
- qcint stmt;
- size_t localsp;
- prog_section_function *function;
-} qc_exec_stack;
+ qcint_t stmt;
+ size_t localsp;
+ prog_section_function_t *function;
+} qc_exec_stack_t;
typedef struct qc_program_s {
- char *filename;
-
- prog_section_statement *code;
- prog_section_def *defs;
- prog_section_def *fields;
- prog_section_function *functions;
- char *strings;
- qcint *globals;
- qcint *entitydata;
- bool *entitypool;
-
- const char* *function_stack;
+ 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;
uint16_t crc16;
size_t tempstring_start;
size_t tempstring_at;
- qcint vmerror;
+ qcint_t vmerror;
size_t *profile;
- prog_builtin *builtins;
- size_t builtins_count;
+ prog_builtin_t *builtins;
+ size_t builtins_count;
/* size_t ip; */
- qcint entities;
+ qcint_t entities;
size_t entityfields;
bool allowworldwrites;
- qcint *localstack;
- qc_exec_stack *stack;
+ qcint_t *localstack;
+ qc_exec_stack_t *stack;
size_t statement;
size_t xflags;
int argc; /* current arg count for debugging */
-} qc_program;
-
-qc_program* prog_load(const char *filename, bool ignoreversion);
-void prog_delete(qc_program *prog);
-
-bool prog_exec(qc_program *prog, prog_section_function *func, size_t flags, long maxjumps);
+} qc_program_t;
-const char* prog_getstring (qc_program *prog, qcint str);
-prog_section_def* prog_entfield (qc_program *prog, qcint off);
-prog_section_def* prog_getdef (qc_program *prog, qcint off);
-qcany* prog_getedict (qc_program *prog, qcint e);
-qcint prog_tempstring(qc_program *prog, const char *_str);
+qc_program_t* prog_load (const char *filename, bool ignoreversion);
+void prog_delete (qc_program_t *prog);
+bool prog_exec (qc_program_t *prog, prog_section_function_t *func, size_t flags, long maxjumps);
+const char* prog_getstring (qc_program_t *prog, qcint_t str);
+prog_section_def_t* prog_entfield (qc_program_t *prog, qcint_t off);
+prog_section_def_t* prog_getdef (qc_program_t *prog, qcint_t off);
+qcany_t* prog_getedict (qc_program_t *prog, qcint_t e);
+qcint_t prog_tempstring(qc_program_t *prog, const char *_str);
/*===================================================================*/
typedef struct {
const char *name;
longbit bit;
-} opts_flag_def;
+} opts_flag_def_t;
bool opts_setflag (const char *, bool);
bool opts_setwarn (const char *, bool);
OPTION_COUNT
};
-extern const opts_flag_def opts_flag_list[COUNT_FLAGS+1];
-extern const opts_flag_def opts_warn_list[COUNT_WARNINGS+1];
-extern const opts_flag_def opts_opt_list[COUNT_OPTIMIZATIONS+1];
-extern const unsigned int opts_opt_oflag[COUNT_OPTIMIZATIONS+1];
-extern unsigned int opts_optimizationcount[COUNT_OPTIMIZATIONS];
+extern const opts_flag_def_t opts_flag_list[COUNT_FLAGS+1];
+extern const opts_flag_def_t opts_warn_list[COUNT_WARNINGS+1];
+extern const opts_flag_def_t opts_opt_list[COUNT_OPTIMIZATIONS+1];
+extern const unsigned int opts_opt_oflag[COUNT_OPTIMIZATIONS+1];
+extern unsigned int opts_optimizationcount[COUNT_OPTIMIZATIONS];
/* other options: */
typedef enum {
static void ir_function_delete(ir_function*);
static void ir_function_dump(ir_function*, char *ind, int (*oprintf)(const char*,...));
-static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx, const char *label,
+static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx_t, const char *label,
int op, ir_value *a, ir_value *b, int outype);
static void ir_block_delete(ir_block*);
static ir_block* ir_block_new(struct ir_function_s *owner, const char *label);
-static bool GMQCC_WARN ir_block_create_store(ir_block*, lex_ctx, ir_value *target, ir_value *what);
+static bool GMQCC_WARN ir_block_create_store(ir_block*, lex_ctx_t, ir_value *target, ir_value *what);
static bool ir_block_set_label(ir_block*, const char *label);
static void ir_block_dump(ir_block*, char *ind, int (*oprintf)(const char*,...));
static void ir_instr_dump(ir_instr* in, char *ind, int (*oprintf)(const char*,...));
/* error functions */
-static void irerror(lex_ctx ctx, const char *msg, ...)
+static void irerror(lex_ctx_t ctx, const char *msg, ...)
{
va_list ap;
va_start(ap, msg);
- con_cvprintmsg((void*)&ctx, LVL_ERROR, "internal error", msg, ap);
+ con_cvprintmsg(ctx, LVL_ERROR, "internal error", msg, ap);
va_end(ap);
}
-static bool irwarning(lex_ctx ctx, int warntype, const char *fmt, ...)
+static bool irwarning(lex_ctx_t ctx, int warntype, const char *fmt, ...)
{
bool r;
va_list ap;
vec_push(self->values, v);
}
-ir_block* ir_function_create_block(lex_ctx ctx, ir_function *self, const char *label)
+ir_block* ir_function_create_block(lex_ctx_t ctx, ir_function *self, const char *label)
{
ir_block* bn = ir_block_new(self, label);
bn->context = ctx;
*IR Instructions
*/
-static ir_instr* ir_instr_new(lex_ctx ctx, ir_block* owner, int op)
+static ir_instr* ir_instr_new(lex_ctx_t ctx, ir_block* owner, int op)
{
ir_instr *self;
self = (ir_instr*)mem_a(sizeof(*self));
return true;
}
-bool ir_value_set_vector(ir_value *self, vector v)
+bool ir_value_set_vector(ir_value *self, vec3_t v)
{
if (self->vtype != TYPE_VECTOR)
return false;
return false;
}
-bool ir_block_create_store_op(ir_block *self, lex_ctx ctx, int op, ir_value *target, ir_value *what)
+bool ir_block_create_store_op(ir_block *self, lex_ctx_t ctx, int op, ir_value *target, ir_value *what)
{
ir_instr *in;
if (!ir_check_unreachable(self))
return true;
}
-static bool ir_block_create_store(ir_block *self, lex_ctx ctx, ir_value *target, ir_value *what)
+static bool ir_block_create_store(ir_block *self, lex_ctx_t ctx, ir_value *target, ir_value *what)
{
int op = 0;
int vtype;
return ir_block_create_store_op(self, ctx, op, target, what);
}
-bool ir_block_create_storep(ir_block *self, lex_ctx ctx, ir_value *target, ir_value *what)
+bool ir_block_create_storep(ir_block *self, lex_ctx_t ctx, ir_value *target, ir_value *what)
{
int op = 0;
int vtype;
return ir_block_create_store_op(self, ctx, op, target, what);
}
-bool ir_block_create_return(ir_block *self, lex_ctx ctx, ir_value *v)
+bool ir_block_create_return(ir_block *self, lex_ctx_t ctx, ir_value *v)
{
ir_instr *in;
if (!ir_check_unreachable(self))
return true;
}
-bool ir_block_create_if(ir_block *self, lex_ctx ctx, ir_value *v,
+bool ir_block_create_if(ir_block *self, lex_ctx_t ctx, ir_value *v,
ir_block *ontrue, ir_block *onfalse)
{
ir_instr *in;
return true;
}
-bool ir_block_create_jump(ir_block *self, lex_ctx ctx, ir_block *to)
+bool ir_block_create_jump(ir_block *self, lex_ctx_t ctx, ir_block *to)
{
ir_instr *in;
if (!ir_check_unreachable(self))
return true;
}
-bool ir_block_create_goto(ir_block *self, lex_ctx ctx, ir_block *to)
+bool ir_block_create_goto(ir_block *self, lex_ctx_t ctx, ir_block *to)
{
self->owner->flags |= IR_FLAG_HAS_GOTO;
return ir_block_create_jump(self, ctx, to);
}
-ir_instr* ir_block_create_phi(ir_block *self, lex_ctx ctx, const char *label, int ot)
+ir_instr* ir_block_create_phi(ir_block *self, lex_ctx_t ctx, const char *label, int ot)
{
ir_value *out;
ir_instr *in;
}
/* call related code */
-ir_instr* ir_block_create_call(ir_block *self, lex_ctx ctx, const char *label, ir_value *func, bool noreturn)
+ir_instr* ir_block_create_call(ir_block *self, lex_ctx_t ctx, const char *label, ir_value *func, bool noreturn)
{
ir_value *out;
ir_instr *in;
/* binary op related code */
-ir_value* ir_block_create_binop(ir_block *self, lex_ctx ctx,
+ir_value* ir_block_create_binop(ir_block *self, lex_ctx_t ctx,
const char *label, int opcode,
ir_value *left, ir_value *right)
{
return ir_block_create_general_instr(self, ctx, label, opcode, left, right, ot);
}
-ir_value* ir_block_create_unary(ir_block *self, lex_ctx ctx,
+ir_value* ir_block_create_unary(ir_block *self, lex_ctx_t ctx,
const char *label, int opcode,
ir_value *operand)
{
return ir_block_create_general_instr(self, ctx, label, opcode, operand, NULL, ot);
}
-static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx ctx, const char *label,
+static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx_t ctx, const char *label,
int op, ir_value *a, ir_value *b, int outype)
{
ir_instr *instr;
return NULL;
}
-ir_value* ir_block_create_fieldaddress(ir_block *self, lex_ctx ctx, const char *label, ir_value *ent, ir_value *field)
+ir_value* ir_block_create_fieldaddress(ir_block *self, lex_ctx_t ctx, const char *label, ir_value *ent, ir_value *field)
{
ir_value *v;
return v;
}
-ir_value* ir_block_create_load_from_ent(ir_block *self, lex_ctx ctx, const char *label, ir_value *ent, ir_value *field, int outype)
+ir_value* ir_block_create_load_from_ent(ir_block *self, lex_ctx_t ctx, const char *label, ir_value *ent, ir_value *field, int outype)
{
int op;
if (ent->vtype != TYPE_ENTITY)
static bool gen_blocks_recursive(code_t *code, ir_function *func, ir_block *block)
{
- prog_section_statement stmt;
+ prog_section_statement_t stmt;
ir_instr *instr;
ir_block *target;
ir_block *ontrue;
static bool gen_function_code(code_t *code, ir_function *self)
{
ir_block *block;
- prog_section_statement stmt, *retst;
+ prog_section_statement_t stmt, *retst;
/* Starting from entry point, we generate blocks "as they come"
* for now. Dead blocks will not be translated obviously.
return true;
}
-static qcint ir_builder_filestring(ir_builder *ir, const char *filename)
+static qcint_t ir_builder_filestring(ir_builder *ir, const char *filename)
{
/* NOTE: filename pointers are copied, we never strdup them,
* thus we can use pointer-comparison to find the string.
*/
size_t i;
- qcint str;
+ qcint_t str;
for (i = 0; i < vec_size(ir->filenames); ++i) {
if (ir->filenames[i] == filename)
static bool gen_global_function(ir_builder *ir, ir_value *global)
{
- prog_section_function fun;
- ir_function *irfun;
+ prog_section_function_t fun;
+ ir_function *irfun;
size_t i;
static void ir_gen_extparam(ir_builder *ir)
{
- prog_section_def def;
- ir_value *global;
+ prog_section_def_t def;
+ ir_value *global;
if (vec_size(ir->extparam_protos) < vec_size(ir->extparams)+1)
global = ir_gen_extparam_proto(ir);
ir_builder *ir = self->owner;
ir_value *ep;
- prog_section_statement stmt;
+ prog_section_statement_t stmt;
numparams = vec_size(self->params);
if (!numparams)
ir_builder *ir = self->owner;
ir_value *ep;
- prog_section_statement stmt;
+ prog_section_statement_t stmt;
numparams = vec_size(self->params);
if (!numparams)
static bool gen_function_locals(ir_builder *ir, ir_value *global)
{
- prog_section_function *def;
- ir_function *irfun;
- size_t i;
- uint32_t firstlocal, firstglobal;
+ prog_section_function_t *def;
+ ir_function *irfun;
+ size_t i;
+ uint32_t firstlocal, firstglobal;
irfun = global->constval.vfunc;
def = ir->code->functions + irfun->code_function_def;
static bool gen_global_function_code(ir_builder *ir, ir_value *global)
{
- prog_section_function *fundef;
- ir_function *irfun;
+ prog_section_function_t *fundef;
+ ir_function *irfun;
(void)ir;
return true;
}
-static void gen_vector_defs(code_t *code, prog_section_def def, const char *name)
+static void gen_vector_defs(code_t *code, prog_section_def_t def, const char *name)
{
char *component;
size_t len, i;
mem_d(component);
}
-static void gen_vector_fields(code_t *code, prog_section_field fld, const char *name)
+static void gen_vector_fields(code_t *code, prog_section_field_t fld, const char *name)
{
char *component;
size_t len, i;
static bool ir_builder_gen_global(ir_builder *self, ir_value *global, bool islocal)
{
- size_t i;
- int32_t *iptr;
- prog_section_def def;
- bool pushdef = opts.optimizeoff;
+ size_t i;
+ int32_t *iptr;
+ prog_section_def_t def;
+ bool pushdef = opts.optimizeoff;
def.type = global->vtype;
def.offset = vec_size(self->code->globals);
static bool ir_builder_gen_field(ir_builder *self, ir_value *field)
{
- prog_section_def def;
- prog_section_field fld;
+ prog_section_def_t def;
+ prog_section_field_t fld;
(void)self;
bool ir_builder_generate(ir_builder *self, const char *filename)
{
- prog_section_statement stmt;
+ prog_section_statement_t stmt;
size_t i;
char *lnofile = NULL;
char *name;
int vtype;
int store;
- lex_ctx context;
+ lex_ctx_t context;
/* even the IR knows the subtype of a field */
int fieldtype;
/* and the output type of a function */
union {
float vfloat;
int vint;
- vector vvec;
+ vec3_t vvec;
int32_t ivec[3];
char *vstring;
struct ir_value_s *vpointer;
bool GMQCC_WARN ir_value_set_float(ir_value*, float f);
bool GMQCC_WARN ir_value_set_func(ir_value*, int f);
bool GMQCC_WARN ir_value_set_string(ir_value*, const char *s);
-bool GMQCC_WARN ir_value_set_vector(ir_value*, vector v);
+bool GMQCC_WARN ir_value_set_vector(ir_value*, vec3_t v);
bool GMQCC_WARN ir_value_set_field(ir_value*, ir_value *fld);
bool ir_value_lives(ir_value*, size_t);
void ir_value_dump_life(const ir_value *self, int (*oprintf)(const char*,...));
typedef struct ir_instr_s
{
int opcode;
- lex_ctx context;
+ lex_ctx_t context;
ir_value* (_ops[3]);
struct ir_block_s* (bops[2]);
typedef struct ir_block_s
{
char *label;
- lex_ctx context;
+ lex_ctx_t context;
bool final; /* once a jump is added we're done */
ir_instr **instr;
size_t code_start;
} ir_block;
-ir_value* ir_block_create_binop(ir_block*, lex_ctx, const char *label, int op, ir_value *left, ir_value *right);
-ir_value* ir_block_create_unary(ir_block*, lex_ctx, const char *label, int op, ir_value *operand);
-bool GMQCC_WARN ir_block_create_store_op(ir_block*, lex_ctx, int op, ir_value *target, ir_value *what);
-bool GMQCC_WARN ir_block_create_storep(ir_block*, lex_ctx, ir_value *target, ir_value *what);
-ir_value* ir_block_create_load_from_ent(ir_block*, lex_ctx, const char *label, ir_value *ent, ir_value *field, int outype);
-ir_value* ir_block_create_fieldaddress(ir_block*, lex_ctx, const char *label, ir_value *entity, ir_value *field);
+ir_value* ir_block_create_binop(ir_block*, lex_ctx_t, const char *label, int op, ir_value *left, ir_value *right);
+ir_value* ir_block_create_unary(ir_block*, lex_ctx_t, const char *label, int op, ir_value *operand);
+bool GMQCC_WARN ir_block_create_store_op(ir_block*, lex_ctx_t, int op, ir_value *target, ir_value *what);
+bool GMQCC_WARN ir_block_create_storep(ir_block*, lex_ctx_t, ir_value *target, ir_value *what);
+ir_value* ir_block_create_load_from_ent(ir_block*, lex_ctx_t, const char *label, ir_value *ent, ir_value *field, int outype);
+ir_value* ir_block_create_fieldaddress(ir_block*, lex_ctx_t, const char *label, ir_value *entity, ir_value *field);
/* This is to create an instruction of the form
* <outtype>%label := opcode a, b
*/
-ir_instr* ir_block_create_phi(ir_block*, lex_ctx, const char *label, int vtype);
+ir_instr* ir_block_create_phi(ir_block*, lex_ctx_t, const char *label, int vtype);
ir_value* ir_phi_value(ir_instr*);
void ir_phi_add(ir_instr*, ir_block *b, ir_value *v);
-ir_instr* ir_block_create_call(ir_block*, lex_ctx, const char *label, ir_value *func, bool noreturn);
+ir_instr* ir_block_create_call(ir_block*, lex_ctx_t, const char *label, ir_value *func, bool noreturn);
ir_value* ir_call_value(ir_instr*);
void ir_call_param(ir_instr*, ir_value*);
-bool GMQCC_WARN ir_block_create_return(ir_block*, lex_ctx, ir_value *opt_value);
+bool GMQCC_WARN ir_block_create_return(ir_block*, lex_ctx_t, ir_value *opt_value);
-bool GMQCC_WARN ir_block_create_if(ir_block*, lex_ctx, ir_value *cond,
+bool GMQCC_WARN ir_block_create_if(ir_block*, lex_ctx_t, ir_value *cond,
ir_block *ontrue, ir_block *onfalse);
/* A 'goto' is an actual 'goto' coded in QC, whereas
* a 'jump' is a virtual construct which simply names the
* A goto usually becomes an OP_GOTO in the resulting code,
* whereas a 'jump' usually doesn't add any actual instruction.
*/
-bool GMQCC_WARN ir_block_create_jump(ir_block*, lex_ctx, ir_block *to);
-bool GMQCC_WARN ir_block_create_goto(ir_block*, lex_ctx, ir_block *to);
+bool GMQCC_WARN ir_block_create_jump(ir_block*, lex_ctx_t, ir_block *to);
+bool GMQCC_WARN ir_block_create_goto(ir_block*, lex_ctx_t, ir_block *to);
/* function */
typedef struct ir_function_s
ir_block* first;
ir_block* last;
- lex_ctx context;
+ lex_ctx_t context;
/* for prototypes - first we generate all the
* globals, and we remember teh function-defs
*
* remember the ID:
*/
- qcint code_function_def;
+ qcint_t code_function_def;
/* for temp allocation */
size_t run_id;
ir_value* ir_function_create_local(ir_function *self, const char *name, int vtype, bool param);
bool GMQCC_WARN ir_function_finalize(ir_function*);
-ir_block* ir_function_create_block(lex_ctx ctx, ir_function*, const char *label);
+ir_block* ir_function_create_block(lex_ctx_t ctx, ir_function*, const char *label);
/* builder */
#define IR_HT_SIZE 1024
uint32_t first_common_globaltemp;
const char **filenames;
- qcint *filestrings;
+ qcint_t *filestrings;
/* we cache the #IMMEDIATE string here */
- qcint str_immediate;
+ qcint_t str_immediate;
/* there should just be this one nil */
ir_value *nil;
ir_value *reserved_va_count;
* for some reason :P
*/
typedef int static_assert_is_32bit_float [(sizeof(int32_t) == 4)?1:-1];
-typedef int static_assert_is_32bit_integer[(sizeof(qcfloat) == 4)?1:-1];
+typedef int static_assert_is_32bit_integer[(sizeof(qcfloat_t) == 4)?1:-1];
#endif
static bool lexwarn(lex_file *lex, int warntype, const char *fmt, ...)
{
- bool r;
- lex_ctx ctx;
- va_list ap;
+ bool r;
+ lex_ctx_t ctx;
+ va_list ap;
ctx.file = lex->name;
ctx.line = lex->sline;
char *value;
union {
- vector v;
+ vec3_t v;
int i;
double f;
int t; /* type */
struct token_s *prev;
#endif
- lex_ctx ctx;
+ lex_ctx_t ctx;
};
#if 0
0
};
-const opts_flag_def opts_opt_list[COUNT_OPTIMIZATIONS+1] = {
+const opts_flag_def_t opts_opt_list[COUNT_OPTIMIZATIONS+1] = {
# define GMQCC_TYPE_OPTIMIZATIONS
# define GMQCC_DEFINE_FLAG(NAME, MIN_O) { #NAME, LONGBIT(OPTIM_##NAME) },
# include "opts.def"
{ NULL, LONGBIT(0) }
};
-const opts_flag_def opts_warn_list[COUNT_WARNINGS+1] = {
+const opts_flag_def_t opts_warn_list[COUNT_WARNINGS+1] = {
# define GMQCC_TYPE_WARNS
# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(WARN_##X) },
# include "opts.def"
{ NULL, LONGBIT(0) }
};
-const opts_flag_def opts_flag_list[COUNT_FLAGS+1] = {
+const opts_flag_def_t opts_flag_list[COUNT_FLAGS+1] = {
# define GMQCC_TYPE_FLAGS
# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(X) },
# include "opts.def"
OPTS_OPTION_U16(OPTION_MEMDUMPCOLS) = 16;
}
-static bool opts_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def *list, size_t listsize) {
+static bool opts_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def_t *list, size_t listsize) {
size_t i;
for (i = 0; i < listsize; ++i) {
size_t *_blocklocals;
ast_value **_typedefs;
size_t *_blocktypedefs;
- lex_ctx *_block_ctx;
+ lex_ctx_t *_block_ctx;
/* we store the '=' operator info */
const oper_info *assign_op;
* some maths used for constant folding
*/
-vector vec3_add(vector a, vector b)
+vec3_t vec3_add(vec3_t a, vec3_t b)
{
- vector out;
+ vec3_t out;
out.x = a.x + b.x;
out.y = a.y + b.y;
out.z = a.z + b.z;
return out;
}
-vector vec3_sub(vector a, vector b)
+vec3_t vec3_sub(vec3_t a, vec3_t b)
{
- vector out;
+ vec3_t out;
out.x = a.x - b.x;
out.y = a.y - b.y;
out.z = a.z - b.z;
return out;
}
-qcfloat vec3_mulvv(vector a, vector b)
+qcfloat_t vec3_mulvv(vec3_t a, vec3_t b)
{
return (a.x * b.x + a.y * b.y + a.z * b.z);
}
-vector vec3_mulvf(vector a, float b)
+vec3_t vec3_mulvf(vec3_t a, float b)
{
- vector out;
+ vec3_t out;
out.x = a.x * b;
out.y = a.y * b;
out.z = a.z * b;
{
size_t i;
ast_value *out;
- lex_ctx ctx;
+ lex_ctx_t ctx;
for (i = 0; i < vec_size(parser->imm_float); ++i) {
const double compare = parser->imm_float[i]->constval.vfloat;
if (memcmp((const void*)&compare, (const void *)&d, sizeof(double)) == 0)
return out;
}
-static ast_value* parser_const_vector(parser_t *parser, vector v)
+static ast_value* parser_const_vector(parser_t *parser, vec3_t v)
{
size_t i;
ast_value *out;
static ast_value* parser_const_vector_f(parser_t *parser, float x, float y, float z)
{
- vector v;
+ vec3_t v;
v.x = x;
v.y = y;
v.z = z;
size_t off;
ast_expression *out;
ast_block *block; /* for commas and function calls */
- lex_ctx ctx;
+ lex_ctx_t ctx;
} sy_elem;
enum {
unsigned int *paren;
} shunt;
-static sy_elem syexp(lex_ctx ctx, ast_expression *v) {
+static sy_elem syexp(lex_ctx_t ctx, ast_expression *v) {
sy_elem e;
e.etype = 0;
e.off = 0;
return e;
}
-static sy_elem syblock(lex_ctx ctx, ast_block *v) {
+static sy_elem syblock(lex_ctx_t ctx, ast_block *v) {
sy_elem e;
e.etype = 0;
e.off = 0;
return e;
}
-static sy_elem syop(lex_ctx ctx, const oper_info *op) {
+static sy_elem syop(lex_ctx_t ctx, const oper_info *op) {
sy_elem e;
e.etype = 1 + (op - operators);
e.off = 0;
return e;
}
-static sy_elem syparen(lex_ctx ctx, size_t off) {
+static sy_elem syparen(lex_ctx_t ctx, size_t off) {
sy_elem e;
e.etype = 0;
e.off = off;
ast_expression *sub;
ast_expression *entity;
- lex_ctx ctx = ast_ctx(*out);
+ lex_ctx_t ctx = ast_ctx(*out);
if (!ast_istype(*out, ast_array_index))
return false;
return true;
}
-static bool immediate_is_true(lex_ctx ctx, ast_value *v)
+static bool immediate_is_true(lex_ctx_t ctx, ast_value *v)
{
switch (v->expression.vtype) {
case TYPE_FLOAT:
static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
{
const oper_info *op;
- lex_ctx ctx;
+ lex_ctx_t ctx;
ast_expression *out = NULL;
ast_expression *exprs[3];
ast_block *blocks[3];
ast_value *asvalue[3];
ast_binstore *asbinstore;
size_t i, assignop, addop, subop;
- qcint generated_op = 0;
+ qcint_t generated_op = 0;
char ty1[1024];
char ty2[1024];
if (CanConstFold(exprs[0], exprs[1]))
out = (ast_expression*)parser_const_float(parser, vec3_mulvv(ConstV(0), ConstV(1)));
else if (OPTS_OPTIMIZATION(OPTIM_VECTOR_COMPONENTS) && CanConstFold1(exprs[0])) {
- vector vec = ConstV(0);
+ vec3_t vec = ConstV(0);
if (!vec.y && !vec.z) { /* 'n 0 0' * v */
++opts_optimizationcount[OPTIM_VECTOR_COMPONENTS];
out = (ast_expression*)ast_member_new(ctx, exprs[1], 0, NULL);
out = (ast_expression*)ast_binary_new(ctx, INSTR_MUL_V, exprs[0], exprs[1]);
}
else if (OPTS_OPTIMIZATION(OPTIM_VECTOR_COMPONENTS) && CanConstFold1(exprs[1])) {
- vector vec = ConstV(1);
+ vec3_t vec = ConstV(1);
if (!vec.y && !vec.z) { /* v * 'n 0 0' */
++opts_optimizationcount[OPTIM_VECTOR_COMPONENTS];
out = (ast_expression*)ast_member_new(ctx, exprs[0], 0, NULL);
}
if (CanConstFold(exprs[0], exprs[1])) {
out = (ast_expression*)parser_const_float(parser,
- (float)(((qcint)ConstF(0)) % ((qcint)ConstF(1))));
+ (float)(((qcint_t)ConstF(0)) % ((qcint_t)ConstF(1))));
} else {
/* generate a call to __builtin_mod */
ast_expression *mod = intrin_func(parser, "mod");
}
if (CanConstFold(exprs[0], exprs[1]))
out = (ast_expression*)parser_const_float(parser,
- (op->id == opid1('|') ? (float)( ((qcint)ConstF(0)) | ((qcint)ConstF(1)) ) :
- (float)( ((qcint)ConstF(0)) & ((qcint)ConstF(1)) ) ));
+ (op->id == opid1('|') ? (float)( ((qcint_t)ConstF(0)) | ((qcint_t)ConstF(1)) ) :
+ (float)( ((qcint_t)ConstF(0)) & ((qcint_t)ConstF(1)) ) ));
else
out = (ast_expression*)ast_binary_new(ctx,
(op->id == opid1('|') ? INSTR_BITOR : INSTR_BITAND),
*/
if (exprs[0]->vtype == TYPE_FLOAT) {
if(CanConstFold(exprs[0], exprs[1])) {
- out = (ast_expression*)parser_const_float(parser, (float)((qcint)(ConstF(0)) ^ ((qcint)(ConstF(1)))));
+ out = (ast_expression*)parser_const_float(parser, (float)((qcint_t)(ConstF(0)) ^ ((qcint_t)(ConstF(1)))));
} else {
ast_binary *expr = ast_binary_new(
ctx,
if (CanConstFold(exprs[0], exprs[1])) {
out = (ast_expression*)parser_const_vector_f(
parser,
- (float)(((qcint)(ConstV(0).x)) ^ ((qcint)(ConstV(1).x))),
- (float)(((qcint)(ConstV(0).y)) ^ ((qcint)(ConstV(1).y))),
- (float)(((qcint)(ConstV(0).z)) ^ ((qcint)(ConstV(1).z)))
+ (float)(((qcint_t)(ConstV(0).x)) ^ ((qcint_t)(ConstV(1).x))),
+ (float)(((qcint_t)(ConstV(0).y)) ^ ((qcint_t)(ConstV(1).y))),
+ (float)(((qcint_t)(ConstV(0).z)) ^ ((qcint_t)(ConstV(1).z)))
);
} else {
compile_error(ast_ctx(exprs[0]), "Not Yet Implemented: bit-xor for vector against vector");
if (CanConstFold(exprs[0], exprs[1])) {
out = (ast_expression*)parser_const_vector_f(
parser,
- (float)(((qcint)(ConstV(0).x)) ^ ((qcint)(ConstF(1)))),
- (float)(((qcint)(ConstV(0).y)) ^ ((qcint)(ConstF(1)))),
- (float)(((qcint)(ConstV(0).z)) ^ ((qcint)(ConstF(1))))
+ (float)(((qcint_t)(ConstV(0).x)) ^ ((qcint_t)(ConstF(1)))),
+ (float)(((qcint_t)(ConstV(0).y)) ^ ((qcint_t)(ConstF(1)))),
+ (float)(((qcint_t)(ConstV(0).z)) ^ ((qcint_t)(ConstF(1))))
);
} else {
compile_error(ast_ctx(exprs[0]), "Not Yet Implemented: bit-xor for vector against float");
}
if(CanConstFold1(exprs[0]))
- out = (ast_expression*)parser_const_float(parser, ~(qcint)ConstF(0));
+ out = (ast_expression*)parser_const_float(parser, ~(qcint_t)ConstF(0));
else
out = (ast_expression*)
ast_binary_new(ctx, INSTR_SUB_F, (ast_expression*)parser_const_float_neg1(parser), exprs[0]);
ast_expression *idx, *out;
ast_value *typevar;
ast_value *funtype = parser->function->vtype;
- lex_ctx ctx = parser_ctx(parser);
+ lex_ctx_t ctx = parser_ctx(parser);
if (!parser->function->varargs) {
parseerror(parser, "function has no variable argument list");
ast_expression *cond, *ontrue = NULL, *onfalse = NULL;
bool ifnot = false;
- lex_ctx ctx = parser_ctx(parser);
+ lex_ctx_t ctx = parser_ctx(parser);
(void)block; /* not touching */
bool ifnot = false;
- lex_ctx ctx = parser_ctx(parser);
+ lex_ctx_t ctx = parser_ctx(parser);
(void)block; /* not touching */
bool ifnot = false;
- lex_ctx ctx = parser_ctx(parser);
+ lex_ctx_t ctx = parser_ctx(parser);
(void)block; /* not touching */
bool ifnot = false;
- lex_ctx ctx = parser_ctx(parser);
+ lex_ctx_t ctx = parser_ctx(parser);
parser_enterblock(parser);
/* parse the incrementor */
if (parser->tok != ')') {
- lex_ctx condctx = parser_ctx(parser);
+ lex_ctx_t condctx = parser_ctx(parser);
increment = parse_expression_leave(parser, false, false, false);
if (!increment)
goto onerr;
ast_value *retval = parser->function->return_value;
ast_value *expected = parser->function->vtype;
- lex_ctx ctx = parser_ctx(parser);
+ lex_ctx_t ctx = parser_ctx(parser);
(void)block; /* not touching */
{
size_t i;
unsigned int levels = 0;
- lex_ctx ctx = parser_ctx(parser);
+ lex_ctx_t ctx = parser_ctx(parser);
const char **loops = (is_continue ? parser->continues : parser->breaks);
(void)block; /* not touching */
bool noref, is_static;
uint32_t qflags = 0;
- lex_ctx ctx = parser_ctx(parser);
+ lex_ctx_t ctx = parser_ctx(parser);
(void)block; /* not touching */
(void)opval;
}
else
{
- lex_ctx ctx = parser_ctx(parser);
+ lex_ctx_t ctx = parser_ctx(parser);
ast_expression *exp = parse_expression(parser, false, false);
if (!exp)
return false;
{
bool flag = false;
bool reverse = false;
- qcfloat num = 0;
+ qcfloat_t num = 0;
ast_value **values = NULL;
ast_value *var = NULL;
ast_value *asvalue;
}
if (has_frame_think) {
- lex_ctx ctx;
+ lex_ctx_t ctx;
ast_expression *self_frame;
ast_expression *self_nextthink;
ast_expression *self_think;
ast_ifthen *ifthen;
ast_binary *cmp;
- lex_ctx ctx = ast_ctx(array);
+ lex_ctx_t ctx = ast_ctx(array);
if (!left || !right) {
if (left) ast_delete(left);
static ast_expression *array_setter_node(parser_t *parser, ast_value *array, ast_value *index, ast_value *value, size_t from, size_t afterend)
{
- lex_ctx ctx = ast_ctx(array);
+ lex_ctx_t ctx = ast_ctx(array);
if (from+1 == afterend) {
/* set this value */
size_t from,
size_t afterend)
{
- lex_ctx ctx = ast_ctx(array);
+ lex_ctx_t ctx = ast_ctx(array);
if (from+1 == afterend) {
/* set this value */
static ast_expression *array_getter_node(parser_t *parser, ast_value *array, ast_value *index, size_t from, size_t afterend)
{
- lex_ctx ctx = ast_ctx(array);
+ lex_ctx_t ctx = ast_ctx(array);
if (from+1 == afterend) {
ast_return *ret;
static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_value *cached_typedef);
static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
{
- lex_ctx ctx;
+ lex_ctx_t ctx;
size_t i;
ast_value **params;
ast_value *param;
{
ast_expression *cexp;
ast_value *cval, *tmp;
- lex_ctx ctx;
+ lex_ctx_t ctx;
ctx = parser_ctx(parser);
static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_value *cached_typedef)
{
ast_value *var, *tmp;
- lex_ctx ctx;
+ lex_ctx_t ctx;
const char *name = NULL;
bool isfield = false;
parser_t *parser_create()
{
parser_t *parser;
- lex_ctx empty_ctx;
+ lex_ctx_t empty_ctx;
size_t i;
parser = (parser_t*)mem_a(sizeof(parser_t));