}
#define read_data1(x, y) read_data(x, x, y)
- read_data (statements, code, prog_statement);
- read_data1(defs, prog_def);
- read_data1(fields, prog_def);
- read_data1(functions, prog_function);
+ read_data (statements, code, prog_section_statement);
+ read_data1(defs, prog_section_def);
+ read_data1(fields, prog_section_def);
+ read_data1(functions, prog_section_function);
read_data1(strings, char);
read_data1(globals, qcint);
return prog->strings + str;
}
-prog_def* prog_entfield(qc_program *prog, qcint off)
+prog_section_def* prog_entfield(qc_program *prog, qcint off)
{
size_t i;
for (i = 0; i < prog->fields_count; ++i) {
return NULL;
}
-prog_def* prog_getdef(qc_program *prog, qcint off)
+prog_section_def* prog_getdef(qc_program *prog, qcint off)
{
size_t i;
for (i = 0; i < prog->defs_count; ++i) {
static void trace_print_global(qc_program *prog, unsigned int glob, int vtype)
{
static char spaces[16+1] = " ";
- prog_def *def;
+ prog_section_def *def;
qcany *value;
int len;
}
}
-static void prog_print_statement(qc_program *prog, prog_statement *st)
+static void prog_print_statement(qc_program *prog, prog_section_statement *st)
{
if (st->opcode >= (sizeof(asm_instr)/sizeof(asm_instr[0]))) {
printf("<illegal instruction %d>\n", st->opcode);
}
}
-static qcint prog_enterfunction(qc_program *prog, prog_function *func)
+static qcint prog_enterfunction(qc_program *prog, prog_section_function *func)
{
qc_exec_stack st;
- prog_function *cur = NULL;
+ prog_section_function *cur = NULL;
if (prog->stack_count)
cur = prog->stack[prog->stack_count-1].function;
return st.stmt;
}
-bool prog_exec(qc_program *prog, prog_function *func, size_t flags, long maxjumps)
+bool prog_exec(qc_program *prog, prog_section_function *func, size_t flags, long maxjumps)
{
long jumpcount = 0;
- prog_statement *st;
+ prog_section_statement *st;
st = prog->code + prog_enterfunction(prog, func);
--st;
}
if (fnmain > 0)
{
- prog_exec(prog, &prog->functions[fnmain], VMXF_TRACE, JUMPS_DEFAULT);
+ prog_exec(prog, &prog->functions[fnmain], VMXF_TRACE, VM_JUMPS_DEFAULT);
}
else
printf("No main function found\n");
typedef char qcfloat_size_is_correct [sizeof(qcfloat) == 4 ?1:-1];
typedef char qcint_size_is_correct [sizeof(qcint) == 4 ?1:-1];
-typedef prog_section_both prog_def;
-typedef prog_section_function prog_function;
-typedef prog_section_statement prog_statement;
-
enum {
VMERR_OK,
VMERR_TEMPSTRING_ALLOC,
VMERR_END
};
-#define JUMPS_DEFAULT 1000000
+#define VM_JUMPS_DEFAULT 1000000
/* execute-flags */
#define VMXF_DEFAULT 0x0000 /* default flags - nothing */
typedef int (*prog_builtin)(struct qc_program_s *prog);
typedef struct {
- qcint stmt;
- size_t localsp;
- prog_function *function;
+ qcint stmt;
+ size_t localsp;
+ prog_section_function *function;
} qc_exec_stack;
typedef struct qc_program_s {
char *filename;
- MEM_VECTOR_MAKE(prog_statement, code);
- MEM_VECTOR_MAKE(prog_def, defs);
- MEM_VECTOR_MAKE(prog_def, fields);
- MEM_VECTOR_MAKE(prog_function, functions);
- MEM_VECTOR_MAKE(char, strings);
- MEM_VECTOR_MAKE(qcint, globals);
- MEM_VECTOR_MAKE(qcint, entitydata);
+ MEM_VECTOR_MAKE(prog_section_statement, code);
+ MEM_VECTOR_MAKE(prog_section_def, defs);
+ MEM_VECTOR_MAKE(prog_section_def, fields);
+ MEM_VECTOR_MAKE(prog_section_function, functions);
+ MEM_VECTOR_MAKE(char, strings);
+ MEM_VECTOR_MAKE(qcint, globals);
+ MEM_VECTOR_MAKE(qcint, entitydata);
size_t tempstring_start;
size_t tempstring_at;
int argc; /* current arg count for debugging */
} qc_program;
-MEM_VEC_FUNCTIONS(qc_program, prog_statement, code)
-MEM_VEC_FUNCTIONS(qc_program, prog_def, defs)
-MEM_VEC_FUNCTIONS(qc_program, prog_def, fields)
-MEM_VEC_FUNCTIONS(qc_program, prog_function, functions)
-MEM_VEC_FUNCTIONS(qc_program, char, strings)
-_MEM_VEC_FUN_APPEND(qc_program, char, strings)
-_MEM_VEC_FUN_RESIZE(qc_program, char, strings)
-MEM_VEC_FUNCTIONS(qc_program, qcint, globals)
-MEM_VEC_FUNCTIONS(qc_program, qcint, entitydata)
-
-MEM_VEC_FUNCTIONS(qc_program, qcint, localstack)
-_MEM_VEC_FUN_APPEND(qc_program, qcint, localstack)
-_MEM_VEC_FUN_RESIZE(qc_program, qcint, localstack)
+MEM_VEC_FUNCTIONS(qc_program, prog_section_statement, code)
+MEM_VEC_FUNCTIONS(qc_program, prog_section_def, defs)
+MEM_VEC_FUNCTIONS(qc_program, prog_section_def, fields)
+MEM_VEC_FUNCTIONS(qc_program, prog_section_function, functions)
+MEM_VEC_FUNCTIONS(qc_program, char, strings)
+_MEM_VEC_FUN_APPEND(qc_program, char, strings)
+_MEM_VEC_FUN_RESIZE(qc_program, char, strings)
+MEM_VEC_FUNCTIONS(qc_program, qcint, globals)
+MEM_VEC_FUNCTIONS(qc_program, qcint, entitydata)
+
+MEM_VEC_FUNCTIONS(qc_program, qcint, localstack)
+_MEM_VEC_FUN_APPEND(qc_program, qcint, localstack)
+_MEM_VEC_FUN_RESIZE(qc_program, qcint, localstack)
MEM_VEC_FUNCTIONS(qc_program, qc_exec_stack, stack)
MEM_VEC_FUNCTIONS(qc_program, size_t, profile)
qc_program* prog_load(const char *filename);
void prog_delete(qc_program *prog);
-bool prog_exec(qc_program *prog, prog_function *func, size_t flags, long maxjumps);
+bool prog_exec(qc_program *prog, prog_section_function *func, size_t flags, long maxjumps);
-char* prog_getstring(qc_program *prog, qcint str);
-prog_def* prog_entfield(qc_program *prog, qcint off);
-prog_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);
+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);
#endif /* GMQCC_EXEC_HDR */