size_t i;
ast_value *out;
for (i = 0; i < vec_size(parser->imm_float); ++i) {
- if (parser->imm_float[i]->constval.vfloat == d)
+ if ((double)(parser->imm_float[i]->constval.vfloat) == d)
return parser->imm_float[i];
}
out = ast_value_new(parser_ctx(parser), "#IMMEDIATE", TYPE_FLOAT);
/* case list! */
while (parser->tok != '}') {
- ast_block *block;
+ ast_block *caseblock;
if (parser->tok != TOKEN_KEYWORD) {
ast_delete(switchnode);
parseerror(parser, "expected statements or case");
return false;
}
- block = ast_block_new(parser_ctx(parser));
- if (!block) {
+ caseblock = ast_block_new(parser_ctx(parser));
+ if (!caseblock) {
if (swcase.value) ast_unref(swcase.value);
ast_delete(switchnode);
return false;
}
- swcase.code = (ast_expression*)block;
+ swcase.code = (ast_expression*)caseblock;
vec_push(switchnode->cases, swcase);
while (true) {
ast_expression *expr;
break;
}
}
- if (!parse_statement(parser, block, &expr, true)) {
+ if (!parse_statement(parser, caseblock, &expr, true)) {
ast_delete(switchnode);
return false;
}
if (!expr)
continue;
- vec_push(block->exprs, expr);
+ vec_push(caseblock->exprs, expr);
}
}
return true;
}
+static uint16_t progdefs_crc_sum(uint16_t old, const char *str)
+{
+ return util_crc16(old, str, strlen(str));
+}
+
+static void progdefs_crc_file(const char *str)
+{
+ /* write to progdefs.h here */
+}
+
+static uint16_t progdefs_crc_both(uint16_t old, const char *str)
+{
+ old = progdefs_crc_sum(old, str);
+ progdefs_crc_file(str);
+ return old;
+}
+
+static void generate_checksum(parser_t *parser)
+{
+ uint16_t crc = 0xFFFF;
+ size_t i;
+
+ crc = progdefs_crc_both(crc, "\n/* file generated by qcc, do not modify */\n\ntypedef struct\n{");
+ crc = progdefs_crc_sum(crc, "\tint\tpad[28];\n");
+ /*
+ progdefs_crc_file("\tint\tpad;\n");
+ progdefs_crc_file("\tint\tofs_return[3];\n");
+ progdefs_crc_file("\tint\tofs_parm0[3];\n");
+ progdefs_crc_file("\tint\tofs_parm1[3];\n");
+ progdefs_crc_file("\tint\tofs_parm2[3];\n");
+ progdefs_crc_file("\tint\tofs_parm3[3];\n");
+ progdefs_crc_file("\tint\tofs_parm4[3];\n");
+ progdefs_crc_file("\tint\tofs_parm5[3];\n");
+ progdefs_crc_file("\tint\tofs_parm6[3];\n");
+ progdefs_crc_file("\tint\tofs_parm7[3];\n");
+ */
+ for (i = 0; i < parser->crc_globals; ++i) {
+ if (!ast_istype(parser->globals[i].var, ast_value))
+ continue;
+ switch (parser->globals[i].var->expression.vtype) {
+ case TYPE_FLOAT: crc = progdefs_crc_both(crc, "\tfloat\t"); break;
+ case TYPE_VECTOR: crc = progdefs_crc_both(crc, "\tvec3_t\t"); break;
+ case TYPE_STRING: crc = progdefs_crc_both(crc, "\tstring_t\t"); break;
+ case TYPE_FUNCTION: crc = progdefs_crc_both(crc, "\tfunc_t\t"); break;
+ default:
+ crc = progdefs_crc_both(crc, "\tint\t");
+ break;
+ }
+ crc = progdefs_crc_both(crc, parser->globals[i].name);
+ crc = progdefs_crc_both(crc, ";\n");
+ }
+ crc = progdefs_crc_both(crc, "} globalvars_t;\n\ntypedef struct\n{\n");
+ for (i = 0; i < parser->crc_fields; ++i) {
+ if (!ast_istype(parser->fields[i].var, ast_value))
+ continue;
+ switch (parser->fields[i].var->expression.next->expression.vtype) {
+ case TYPE_FLOAT: crc = progdefs_crc_both(crc, "\tfloat\t"); break;
+ case TYPE_VECTOR: crc = progdefs_crc_both(crc, "\tvec3_t\t"); break;
+ case TYPE_STRING: crc = progdefs_crc_both(crc, "\tstring_t\t"); break;
+ case TYPE_FUNCTION: crc = progdefs_crc_both(crc, "\tfunc_t\t"); break;
+ default:
+ crc = progdefs_crc_both(crc, "\tint\t");
+ break;
+ }
+ crc = progdefs_crc_both(crc, parser->fields[i].name);
+ crc = progdefs_crc_both(crc, ";\n");
+ }
+ crc = progdefs_crc_both(crc, "} entvars_t;\n\n");
+
+ code_crc = crc;
+}
+
static parser_t *parser;
bool parser_init()
mem_d(parser);
}
-static uint16_t progdefs_crc_sum(uint16_t old, const char *str)
-{
- return util_crc16(old, str, strlen(str));
-}
-
-static void progdefs_crc_file(const char *str)
-{
- /* write to progdefs.h here */
-}
-
-static uint16_t progdefs_crc_both(uint16_t old, const char *str)
-{
- old = progdefs_crc_sum(old, str);
- progdefs_crc_file(str);
- return old;
-}
-
-static void generate_checksum(parser_t *parser)
-{
- uint16_t crc = 0xFFFF;
- size_t i;
-
- crc = progdefs_crc_both(crc, "\n/* file generated by qcc, do not modify */\n\ntypedef struct\n{");
- crc = progdefs_crc_sum(crc, "\tint\tpad[28];\n");
- /*
- progdefs_crc_file("\tint\tpad;\n");
- progdefs_crc_file("\tint\tofs_return[3];\n");
- progdefs_crc_file("\tint\tofs_parm0[3];\n");
- progdefs_crc_file("\tint\tofs_parm1[3];\n");
- progdefs_crc_file("\tint\tofs_parm2[3];\n");
- progdefs_crc_file("\tint\tofs_parm3[3];\n");
- progdefs_crc_file("\tint\tofs_parm4[3];\n");
- progdefs_crc_file("\tint\tofs_parm5[3];\n");
- progdefs_crc_file("\tint\tofs_parm6[3];\n");
- progdefs_crc_file("\tint\tofs_parm7[3];\n");
- */
- for (i = 0; i < parser->crc_globals; ++i) {
- if (!ast_istype(parser->globals[i].var, ast_value))
- continue;
- switch (parser->globals[i].var->expression.vtype) {
- case TYPE_FLOAT: crc = progdefs_crc_both(crc, "\tfloat\t"); break;
- case TYPE_VECTOR: crc = progdefs_crc_both(crc, "\tvec3_t\t"); break;
- case TYPE_STRING: crc = progdefs_crc_both(crc, "\tstring_t\t"); break;
- case TYPE_FUNCTION: crc = progdefs_crc_both(crc, "\tfunc_t\t"); break;
- default:
- crc = progdefs_crc_both(crc, "\tint\t");
- break;
- }
- crc = progdefs_crc_both(crc, parser->globals[i].name);
- crc = progdefs_crc_both(crc, ";\n");
- }
- crc = progdefs_crc_both(crc, "} globalvars_t;\n\ntypedef struct\n{\n");
- for (i = 0; i < parser->crc_fields; ++i) {
- if (!ast_istype(parser->fields[i].var, ast_value))
- continue;
- switch (parser->fields[i].var->expression.next->expression.vtype) {
- case TYPE_FLOAT: crc = progdefs_crc_both(crc, "\tfloat\t"); break;
- case TYPE_VECTOR: crc = progdefs_crc_both(crc, "\tvec3_t\t"); break;
- case TYPE_STRING: crc = progdefs_crc_both(crc, "\tstring_t\t"); break;
- case TYPE_FUNCTION: crc = progdefs_crc_both(crc, "\tfunc_t\t"); break;
- default:
- crc = progdefs_crc_both(crc, "\tint\t");
- break;
- }
- crc = progdefs_crc_both(crc, parser->fields[i].name);
- crc = progdefs_crc_both(crc, ";\n");
- }
- crc = progdefs_crc_both(crc, "} entvars_t;\n\n");
-
- code_crc = crc;
-}
-
bool parser_finish(const char *output)
{
size_t i;