char* prog_getstring(qc_program *prog, qcint str)
{
- if (str < 0 || str >= vec_size(prog->strings))
+ if (str < 0 || str >= (qcint)vec_size(prog->strings))
return "<<<invalid string>>>";
return prog->strings + str;
}
qcany* prog_getedict(qc_program *prog, qcint e)
{
- if (e >= vec_size(prog->entitypool)) {
+ if (e >= (qcint)vec_size(prog->entitypool)) {
prog->vmerror++;
printf("Accessing out of bounds edict %i\n", (int)e);
e = 0;
printf("Trying to free world entity\n");
return;
}
- if (e >= vec_size(prog->entitypool)) {
+ if (e >= (qcint)vec_size(prog->entitypool)) {
prog->vmerror++;
printf("Trying to free out of bounds entity\n");
return;
return at;
}
-static int print_escaped_string(const char *str, size_t maxlen)
+static size_t print_escaped_string(const char *str, size_t maxlen)
{
- int len = 2;
+ size_t len = 2;
putchar('"');
--maxlen; /* because we're lazy and have escape sequences */
while (*str) {
break;
}
done:
- if (len < sizeof(spaces)-1) {
+ if (len < (int)sizeof(spaces)-1) {
spaces[sizeof(spaces)-1-len] = 0;
printf(spaces);
spaces[sizeof(spaces)-1-len] = ' ';
static qcint prog_enterfunction(qc_program *prog, prog_section_function *func)
{
qc_exec_stack st;
- size_t p, parampos;
+ size_t parampos;
+ int32_t p;
/* back up locals */
st.localsp = vec_size(prog->localstack);
#if defined(QCVM_EXECUTOR)
#include <math.h>
+opts_cmd_t opts;
+
const char *type_name[TYPE_COUNT] = {
"void",
"string",
"variant"
};
-bool opts_debug = false;
-bool opts_memchk = false;
-
typedef struct {
int vtype;
const char *value;
{
size_t i;
const char *laststr = NULL;
- for (i = 0; i < prog->argc; ++i) {
+ for (i = 0; i < (size_t)prog->argc; ++i) {
qcany *str = (qcany*)(prog->globals + OFS_PARM0 + 3*i);
printf("%s", (laststr = prog_getstring(prog, str->string)));
}
return 0;
}
+static int qc_stof(qc_program *prog)
+{
+ qcany *str;
+ qcany num;
+ CheckArgs(1);
+ str = GetArg(0);
+ num._float = strtof(prog_getstring(prog, str->string), NULL);
+ Return(num);
+ return 0;
+}
+
static int qc_vtos(qc_program *prog)
{
char buffer[512];
qcany *vec, len;
CheckArgs(1);
vec = GetArg(0);
- len._float = sqrt(vec->vector[0] * vec->vector[0] +
+ len._float = sqrt(vec->vector[0] * vec->vector[0] +
vec->vector[1] * vec->vector[1] +
vec->vector[2] * vec->vector[2]);
Return(len);
&qc_vtos, /* 5 */
&qc_error, /* 6 */
&qc_vlen, /* 7 */
- &qc_etos /* 8 */
+ &qc_etos, /* 8 */
+ &qc_stof /* 9 */
};
static size_t qc_builtins_count = sizeof(qc_builtins) / sizeof(qc_builtins[0]);
size_t xflags = VMXF_DEFAULT;
bool opts_printfields = false;
bool opts_printdefs = false;
+ bool opts_printfuns = false;
bool opts_disasm = false;
bool opts_info = false;
++argv;
opts_printdefs = true;
}
+ else if (!strcmp(argv[1], "-printfuns")) {
+ --argc;
+ ++argv;
+ opts_printfuns = true;
+ }
else if (!strcmp(argv[1], "-printfields")) {
--argc;
++argv;
prog->builtins_count = qc_builtins_count;
if (opts_info) {
- printf("Program's system-checksum = 0x%04x\n", (int)prog->crc16);
- printf("Entity field space: %i\n", (int)prog->entityfields);
+ printf("Program's system-checksum = 0x%04x\n", (unsigned int)prog->crc16);
+ printf("Entity field space: %u\n", (unsigned int)prog->entityfields);
+ printf("Globals: %u\n", (unsigned int)vec_size(prog->globals));
}
for (i = 1; i < vec_size(prog->functions); ++i) {
}
if (opts_printdefs) {
for (i = 0; i < vec_size(prog->defs); ++i) {
- printf("Global: %8s %-16s at %u\n",
+ printf("Global: %8s %-16s at %u%s\n",
type_name[prog->defs[i].type & DEF_TYPEMASK],
prog_getstring(prog, prog->defs[i].name),
- (unsigned int)prog->defs[i].offset);
+ (unsigned int)prog->defs[i].offset,
+ ((prog->defs[i].type & DEF_SAVEGLOBAL) ? " [SAVE]" : ""));
}
}
else if (opts_printfields) {
for (i = 0; i < vec_size(prog->fields); ++i) {
- printf("Field: %8s %-16s at %u\n",
+ printf("Field: %8s %-16s at %u%s\n",
type_name[prog->fields[i].type],
prog_getstring(prog, prog->fields[i].name),
- (unsigned int)prog->fields[i].offset);
+ (unsigned int)prog->fields[i].offset,
+ ((prog->fields[i].type & DEF_SAVEGLOBAL) ? " [SAVE]" : ""));
+ }
+ }
+ else if (opts_printfuns) {
+ for (i = 0; i < vec_size(prog->functions); ++i) {
+ int32_t a;
+ printf("Function: %-16s taking %i parameters:(",
+ prog_getstring(prog, prog->functions[i].name),
+ (unsigned int)prog->functions[i].nargs);
+ for (a = 0; a < prog->functions[i].nargs; ++a) {
+ printf(" %i", prog->functions[i].argsize[a]);
+ }
+ printf(") locals: %i + %i\n",
+ prog->functions[i].firstlocal,
+ prog->functions[i].locals);
}
}
else
printf("FUNCTION \"%s\"\n", prog_getstring(prog, fdef->name));
st = prog->code + fdef->entry;
- while (st->opcode != AINSTR_END) {
+ while (st->opcode != INSTR_DONE) {
prog_print_statement(prog, st);
++st;
}
qcvmerror(prog, "progs `%s` attempted to read an out of bounds entity", prog->filename);
goto cleanup;
}
- if (OPB->_int < 0 || OPB->_int + 3 > prog->entityfields)
+ if (OPB->_int < 0 || OPB->_int + 3 > (qcint)prog->entityfields)
{
qcvmerror(prog, "prog `%s` attempted to read an invalid field from entity (%i)",
prog->filename,
case INSTR_STOREP_ENT:
case INSTR_STOREP_FLD:
case INSTR_STOREP_FNC:
- if (OPB->_int < 0 || OPB->_int >= vec_size(prog->entitydata)) {
+ if (OPB->_int < 0 || OPB->_int >= (qcint)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 < prog->entityfields && !prog->allowworldwrites)
+ if (OPB->_int < (qcint)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),
ptr->_int = OPA->_int;
break;
case INSTR_STOREP_V:
- if (OPB->_int < 0 || OPB->_int + 2 >= vec_size(prog->entitydata)) {
+ if (OPB->_int < 0 || OPB->_int + 2 >= (qcint)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 < prog->entityfields && !prog->allowworldwrites)
+ if (OPB->_int < (qcint)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),
if (!OPA->function)
qcvmerror(prog, "NULL function in `%s`", prog->filename);
- if(!OPA->function || OPA->function >= (unsigned int)vec_size(prog->functions))
+ if(!OPA->function || OPA->function >= (qcint)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 */
- int builtinnumber = -newf->entry;
- if (builtinnumber < prog->builtins_count && prog->builtins[builtinnumber])
+ qcint builtinnumber = -newf->entry;
+ if (builtinnumber < (qcint)prog->builtins_count && prog->builtins[builtinnumber])
prog->builtins[builtinnumber](prog);
else
qcvmerror(prog, "No such builtin #%i in %s! Try updating your gmqcc sources",