5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is furnished to do
10 * so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #ifndef GMQCC_EXEC_HDR
25 #define GMQCC_EXEC_HDR
27 /* darkplaces has (or will have) a 64 bit prog loader
28 * where the 32 bit qc program is autoconverted on load.
29 * Since we may want to support that as well, let's redefine
32 typedef float qcfloat;
33 typedef int32_t qcint;
45 typedef char qcfloat_size_is_correct [sizeof(qcfloat) == 4 ?1:-1];
46 typedef char qcint_size_is_correct [sizeof(qcint) == 4 ?1:-1];
50 VMERR_TEMPSTRING_ALLOC,
55 #define VM_JUMPS_DEFAULT 1000000
58 #define VMXF_DEFAULT 0x0000 /* default flags - nothing */
59 #define VMXF_TRACE 0x0001 /* trace: print statements before executing */
60 #define VMXF_PROFILE 0x0002 /* profile: increment the profile counters */
64 typedef int (*prog_builtin)(struct qc_program_s *prog);
69 prog_section_function *function;
72 typedef struct qc_program_s {
75 MEM_VECTOR_MAKE(prog_section_statement, code);
76 MEM_VECTOR_MAKE(prog_section_def, defs);
77 MEM_VECTOR_MAKE(prog_section_def, fields);
78 MEM_VECTOR_MAKE(prog_section_function, functions);
79 MEM_VECTOR_MAKE(char, strings);
80 MEM_VECTOR_MAKE(qcint, globals);
81 MEM_VECTOR_MAKE(qcint, entitydata);
83 size_t tempstring_start;
88 MEM_VECTOR_MAKE(size_t, profile);
90 MEM_VECTOR_MAKE(prog_builtin, builtins);
95 bool allowworldwrites;
97 MEM_VECTOR_MAKE(qcint, localstack);
98 MEM_VECTOR_MAKE(qc_exec_stack, stack);
101 int argc; /* current arg count for debugging */
103 MEM_VEC_FUNCTIONS(qc_program, prog_section_statement, code)
104 MEM_VEC_FUNCTIONS(qc_program, prog_section_def, defs)
105 MEM_VEC_FUNCTIONS(qc_program, prog_section_def, fields)
106 MEM_VEC_FUNCTIONS(qc_program, prog_section_function, functions)
107 MEM_VEC_FUNCTIONS(qc_program, char, strings)
108 _MEM_VEC_FUN_APPEND(qc_program, char, strings)
109 _MEM_VEC_FUN_RESIZE(qc_program, char, strings)
110 MEM_VEC_FUNCTIONS(qc_program, qcint, globals)
111 MEM_VEC_FUNCTIONS(qc_program, qcint, entitydata)
113 MEM_VEC_FUNCTIONS(qc_program, qcint, localstack)
114 _MEM_VEC_FUN_APPEND(qc_program, qcint, localstack)
115 _MEM_VEC_FUN_RESIZE(qc_program, qcint, localstack)
116 MEM_VEC_FUNCTIONS(qc_program, qc_exec_stack, stack)
118 MEM_VEC_FUNCTIONS(qc_program, size_t, profile)
119 _MEM_VEC_FUN_RESIZE(qc_program, size_t, profile)
121 qc_program* prog_load(const char *filename);
122 void prog_delete(qc_program *prog);
124 bool prog_exec(qc_program *prog, prog_section_function *func, size_t flags, long maxjumps);
126 char* prog_getstring (qc_program *prog, qcint str);
127 prog_section_def* prog_entfield (qc_program *prog, qcint off);
128 prog_section_def* prog_getdef (qc_program *prog, qcint off);
129 qcany* prog_getedict (qc_program *prog, qcint e);
130 qcint prog_tempstring(qc_program *prog, const char *_str);
132 #endif /* GMQCC_EXEC_HDR */