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];
58 prog_section statements;
61 prog_section functions;
67 typedef prog_section_both prog_def;
68 typedef prog_section_function prog_function;
69 typedef prog_section_statement prog_statement;
73 VMERR_TEMPSTRING_ALLOC,
78 #define JUMPS_DEFAULT 1000000
81 #define VMXF_DEFAULT 0x0000 /* default flags - nothing */
82 #define VMXF_TRACE 0x0001 /* trace: print statements before executing */
83 #define VMXF_PROFILE 0x0002 /* profile: increment the profile counters */
87 typedef int (*prog_builtin)(struct qc_program_s *prog);
92 prog_function *function;
95 typedef struct qc_program_s {
98 MEM_VECTOR_MAKE(prog_statement, code);
99 MEM_VECTOR_MAKE(prog_def, defs);
100 MEM_VECTOR_MAKE(prog_def, fields);
101 MEM_VECTOR_MAKE(prog_function, functions);
102 MEM_VECTOR_MAKE(char, strings);
103 MEM_VECTOR_MAKE(qcint, globals);
104 MEM_VECTOR_MAKE(qcint, entitydata);
106 size_t tempstring_start;
107 size_t tempstring_at;
111 MEM_VECTOR_MAKE(size_t, profile);
113 MEM_VECTOR_MAKE(prog_builtin, builtins);
118 bool allowworldwrites;
120 MEM_VECTOR_MAKE(qcint, localstack);
121 MEM_VECTOR_MAKE(qc_exec_stack, stack);
124 int argc; /* current arg count for debugging */
126 MEM_VEC_FUNCTIONS(qc_program, prog_statement, code)
127 MEM_VEC_FUNCTIONS(qc_program, prog_def, defs)
128 MEM_VEC_FUNCTIONS(qc_program, prog_def, fields)
129 MEM_VEC_FUNCTIONS(qc_program, prog_function, functions)
130 MEM_VEC_FUNCTIONS(qc_program, char, strings)
131 _MEM_VEC_FUN_APPEND(qc_program, char, strings)
132 _MEM_VEC_FUN_RESIZE(qc_program, char, strings)
133 MEM_VEC_FUNCTIONS(qc_program, qcint, globals)
134 MEM_VEC_FUNCTIONS(qc_program, qcint, entitydata)
136 MEM_VEC_FUNCTIONS(qc_program, qcint, localstack)
137 _MEM_VEC_FUN_APPEND(qc_program, qcint, localstack)
138 _MEM_VEC_FUN_RESIZE(qc_program, qcint, localstack)
139 MEM_VEC_FUNCTIONS(qc_program, qc_exec_stack, stack)
141 MEM_VEC_FUNCTIONS(qc_program, size_t, profile)
142 _MEM_VEC_FUN_RESIZE(qc_program, size_t, profile)
144 qc_program* prog_load(const char *filename);
145 void prog_delete(qc_program *prog);
147 bool prog_exec(qc_program *prog, prog_function *func, size_t flags, long maxjumps);
149 char* prog_getstring(qc_program *prog, qcint str);
150 prog_def* prog_entfield(qc_program *prog, qcint off);
151 prog_def* prog_getdef(qc_program *prog, qcint off);
152 qcany* prog_getedict(qc_program *prog, qcint e);
153 qcint prog_tempstring(qc_program *prog, const char *_str);
155 #endif /* GMQCC_EXEC_HDR */