[TT #592][docs] Add docs about assigning to registers in docs/debugger.pod
[parrot.git] / include / parrot / misc.h
blob0a3b780cc0526905872afe4a4bdbe83afffb9847
1 /* misc.h
2 * Copyright (C) 2001-2008, Parrot Foundation.
3 * SVN Info
4 * $Id$
5 * Overview:
6 * Miscellaneous functions, mainly the Parrot_sprintf family
7 * Data Structure and Algorithms:
8 * Uses a generalized formatting algorithm (spf_render.c) with
9 * a specialized vtable (spf_vtable.c) to handle argument extraction.
10 * History:
11 * This file used to be a simple one, with just a few function prototypes
12 * in it. When misc.c was split in three, this file took on the job of
13 * being the internal header as well.
14 * To expose the guts of Parrot_sprintf, define IN_SPF_SYSTEM before
15 * including this file.
16 * Notes:
17 * References: misc.c, spf_vtable.c, spf_render.c
20 #ifndef PARROT_MISC_H_GUARD
21 #define PARROT_MISC_H_GUARD
23 #include "parrot/parrot.h"
25 #define FLOAT_IS_ZERO(f) ((f) == 0.0)
27 #ifndef PARROT_HAS_C99_SNPRINTF
28 # define snprintf Parrot_secret_snprintf
29 #endif
31 typedef int (*reg_move_func)(PARROT_INTERP, unsigned char d, unsigned char s, void *);
33 /* HEADERIZER BEGIN: src/utils.c */
34 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
36 PARROT_EXPORT
37 INTVAL Parrot_byte_index(SHIM_INTERP,
38 ARGIN(const STRING *base),
39 ARGIN(const STRING *search),
40 UINTVAL start_offset)
41 __attribute__nonnull__(2)
42 __attribute__nonnull__(3);
44 PARROT_EXPORT
45 PARROT_WARN_UNUSED_RESULT
46 INTVAL Parrot_byte_rindex(SHIM_INTERP,
47 ARGIN(const STRING *base),
48 ARGIN(const STRING *search),
49 UINTVAL start_offset)
50 __attribute__nonnull__(2)
51 __attribute__nonnull__(3);
53 PARROT_EXPORT
54 FLOATVAL Parrot_float_rand(INTVAL how_random);
56 PARROT_EXPORT
57 INTVAL Parrot_int_rand(INTVAL how_random);
59 PARROT_EXPORT
60 INTVAL Parrot_range_rand(INTVAL from, INTVAL to, INTVAL how_random);
62 PARROT_EXPORT
63 void Parrot_register_move(PARROT_INTERP,
64 int n_regs,
65 ARGOUT(unsigned char *dest_regs),
66 ARGIN(unsigned char *src_regs),
67 unsigned char temp_reg,
68 reg_move_func mov,
69 reg_move_func mov_alt,
70 ARGIN(void *info))
71 __attribute__nonnull__(1)
72 __attribute__nonnull__(3)
73 __attribute__nonnull__(4)
74 __attribute__nonnull__(8)
75 FUNC_MODIFIES(*dest_regs);
77 PARROT_EXPORT
78 void Parrot_srand(INTVAL seed);
80 PARROT_EXPORT
81 INTVAL Parrot_uint_rand(INTVAL how_random);
83 PARROT_CONST_FUNCTION
84 FLOATVAL floatval_mod(FLOATVAL n2, FLOATVAL n3);
86 PARROT_CONST_FUNCTION
87 INTVAL intval_mod(INTVAL i2, INTVAL i3);
89 void Parrot_quicksort(PARROT_INTERP,
90 ARGMOD(void **data),
91 UINTVAL n,
92 ARGIN(PMC *cmp))
93 __attribute__nonnull__(1)
94 __attribute__nonnull__(2)
95 __attribute__nonnull__(4)
96 FUNC_MODIFIES(*data);
98 PARROT_WARN_UNUSED_RESULT
99 PARROT_CANNOT_RETURN_NULL
100 PMC* tm_to_array(PARROT_INTERP, ARGIN(const struct tm *tm))
101 __attribute__nonnull__(1)
102 __attribute__nonnull__(2);
104 #define ASSERT_ARGS_Parrot_byte_index __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
105 PARROT_ASSERT_ARG(base) \
106 , PARROT_ASSERT_ARG(search))
107 #define ASSERT_ARGS_Parrot_byte_rindex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
108 PARROT_ASSERT_ARG(base) \
109 , PARROT_ASSERT_ARG(search))
110 #define ASSERT_ARGS_Parrot_float_rand __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
111 #define ASSERT_ARGS_Parrot_int_rand __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
112 #define ASSERT_ARGS_Parrot_range_rand __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
113 #define ASSERT_ARGS_Parrot_register_move __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
114 PARROT_ASSERT_ARG(interp) \
115 , PARROT_ASSERT_ARG(dest_regs) \
116 , PARROT_ASSERT_ARG(src_regs) \
117 , PARROT_ASSERT_ARG(info))
118 #define ASSERT_ARGS_Parrot_srand __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
119 #define ASSERT_ARGS_Parrot_uint_rand __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
120 #define ASSERT_ARGS_floatval_mod __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
121 #define ASSERT_ARGS_intval_mod __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
122 #define ASSERT_ARGS_Parrot_quicksort __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
123 PARROT_ASSERT_ARG(interp) \
124 , PARROT_ASSERT_ARG(data) \
125 , PARROT_ASSERT_ARG(cmp))
126 #define ASSERT_ARGS_tm_to_array __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
127 PARROT_ASSERT_ARG(interp) \
128 , PARROT_ASSERT_ARG(tm))
129 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
130 /* HEADERIZER END: src/utils.c */
133 /* HEADERIZER BEGIN: src/misc.c */
134 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
136 PARROT_EXPORT
137 PARROT_WARN_UNUSED_RESULT
138 PARROT_CANNOT_RETURN_NULL
139 STRING * Parrot_psprintf(PARROT_INTERP,
140 ARGIN(STRING *pat),
141 ARGOUT(PMC *ary))
142 __attribute__nonnull__(1)
143 __attribute__nonnull__(2)
144 __attribute__nonnull__(3)
145 FUNC_MODIFIES(*ary);
147 PARROT_EXPORT
148 int Parrot_secret_snprintf(
149 ARGOUT(char *buffer),
150 NULLOK(const size_t len),
151 ARGIN(const char *format),
152 ...)
153 __attribute__nonnull__(1)
154 __attribute__nonnull__(3)
155 FUNC_MODIFIES(*buffer);
157 PARROT_EXPORT
158 void Parrot_snprintf(PARROT_INTERP,
159 ARGOUT(char *targ),
160 size_t len,
161 ARGIN(const char *pat),
162 ...)
163 __attribute__nonnull__(1)
164 __attribute__nonnull__(2)
165 __attribute__nonnull__(4)
166 FUNC_MODIFIES(*targ);
168 PARROT_EXPORT
169 PARROT_WARN_UNUSED_RESULT
170 PARROT_CANNOT_RETURN_NULL
171 STRING * Parrot_sprintf_c(PARROT_INTERP, ARGIN(const char *pat), ...)
172 __attribute__nonnull__(1)
173 __attribute__nonnull__(2);
175 PARROT_EXPORT
176 PARROT_WARN_UNUSED_RESULT
177 PARROT_CANNOT_RETURN_NULL
178 STRING * Parrot_sprintf_s(PARROT_INTERP, ARGIN(STRING *pat), ...)
179 __attribute__nonnull__(1)
180 __attribute__nonnull__(2);
182 PARROT_EXPORT
183 void Parrot_vsnprintf(PARROT_INTERP,
184 ARGOUT(char *targ),
185 size_t len,
186 ARGIN(const char *pat),
187 va_list args)
188 __attribute__nonnull__(1)
189 __attribute__nonnull__(2)
190 __attribute__nonnull__(4)
191 FUNC_MODIFIES(*targ);
193 PARROT_EXPORT
194 PARROT_CANNOT_RETURN_NULL
195 STRING * Parrot_vsprintf_c(PARROT_INTERP,
196 ARGIN(const char *pat),
197 va_list args)
198 __attribute__nonnull__(1)
199 __attribute__nonnull__(2);
201 PARROT_EXPORT
202 PARROT_WARN_UNUSED_RESULT
203 PARROT_CANNOT_RETURN_NULL
204 STRING * Parrot_vsprintf_s(PARROT_INTERP, ARGIN(STRING *pat), va_list args)
205 __attribute__nonnull__(1)
206 __attribute__nonnull__(2);
208 #define ASSERT_ARGS_Parrot_psprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
209 PARROT_ASSERT_ARG(interp) \
210 , PARROT_ASSERT_ARG(pat) \
211 , PARROT_ASSERT_ARG(ary))
212 #define ASSERT_ARGS_Parrot_secret_snprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
213 PARROT_ASSERT_ARG(buffer) \
214 , PARROT_ASSERT_ARG(format))
215 #define ASSERT_ARGS_Parrot_snprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
216 PARROT_ASSERT_ARG(interp) \
217 , PARROT_ASSERT_ARG(targ) \
218 , PARROT_ASSERT_ARG(pat))
219 #define ASSERT_ARGS_Parrot_sprintf_c __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
220 PARROT_ASSERT_ARG(interp) \
221 , PARROT_ASSERT_ARG(pat))
222 #define ASSERT_ARGS_Parrot_sprintf_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
223 PARROT_ASSERT_ARG(interp) \
224 , PARROT_ASSERT_ARG(pat))
225 #define ASSERT_ARGS_Parrot_vsnprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
226 PARROT_ASSERT_ARG(interp) \
227 , PARROT_ASSERT_ARG(targ) \
228 , PARROT_ASSERT_ARG(pat))
229 #define ASSERT_ARGS_Parrot_vsprintf_c __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
230 PARROT_ASSERT_ARG(interp) \
231 , PARROT_ASSERT_ARG(pat))
232 #define ASSERT_ARGS_Parrot_vsprintf_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
233 PARROT_ASSERT_ARG(interp) \
234 , PARROT_ASSERT_ARG(pat))
235 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
236 /* HEADERIZER END: src/misc.c */
239 #ifdef IN_SPF_SYSTEM
241 /* The size of all our buffers (and the maximum width of a float
242 * field).
244 # define PARROT_SPRINTF_BUFFER_SIZE 4096
246 /* The maximum floating-point precision--hopefully this and the
247 * width cap will help head off buffer overruns.
249 # define PARROT_SPRINTF_MAX_PREC 3 * PARROT_SPRINTF_BUFFER_SIZE / 4
251 # define cstr2pstr(cstr) string_make(interp, (cstr), strlen(cstr), "ascii", 0)
252 # define char2pstr(ch) string_make(interp, &(ch), 1, "ascii", 0)
254 /* SPRINTF DATA STRUCTURE AND FLAGS */
256 typedef enum {
257 SIZE_REG = 0,
258 SIZE_SHORT,
259 SIZE_LONG,
260 SIZE_HUGE,
261 SIZE_XVAL,
262 SIZE_OPCODE,
263 SIZE_PMC,
264 SIZE_PSTR
265 } spf_type_t;
267 /* SPRINTF ARGUMENT OBJECT */
269 typedef struct sprintf_obj SPRINTF_OBJ;
271 typedef STRING *(*sprintf_getchar_t) (PARROT_INTERP, INTVAL, ARGIN(SPRINTF_OBJ *));
272 typedef HUGEINTVAL(*sprintf_getint_t) (PARROT_INTERP, INTVAL, ARGIN(SPRINTF_OBJ *));
273 typedef UHUGEINTVAL(*sprintf_getuint_t) (PARROT_INTERP, INTVAL, ARGIN(SPRINTF_OBJ *));
274 typedef HUGEFLOATVAL(*sprintf_getfloat_t) (PARROT_INTERP, INTVAL, ARGIN(SPRINTF_OBJ *));
275 typedef STRING *(*sprintf_getstring_t) (PARROT_INTERP, INTVAL, ARGIN(SPRINTF_OBJ *));
276 typedef void *(*sprintf_getptr_t) (PARROT_INTERP, INTVAL, ARGIN(SPRINTF_OBJ *));
278 struct sprintf_obj {
279 void *data;
280 INTVAL index;
282 sprintf_getchar_t getchr;
283 sprintf_getint_t getint;
284 sprintf_getuint_t getuint;
285 sprintf_getfloat_t getfloat;
286 sprintf_getstring_t getstring;
287 sprintf_getptr_t getptr;
290 extern SPRINTF_OBJ pmc_core;
291 extern const SPRINTF_OBJ va_core;
293 /* HEADERIZER BEGIN: src/spf_render.c */
294 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
296 PARROT_WARN_UNUSED_RESULT
297 PARROT_CANNOT_RETURN_NULL
298 STRING * Parrot_sprintf_format(PARROT_INTERP,
299 ARGIN(STRING *pat),
300 ARGIN(SPRINTF_OBJ *obj))
301 __attribute__nonnull__(1)
302 __attribute__nonnull__(2)
303 __attribute__nonnull__(3);
305 #define ASSERT_ARGS_Parrot_sprintf_format __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
306 PARROT_ASSERT_ARG(interp) \
307 , PARROT_ASSERT_ARG(pat) \
308 , PARROT_ASSERT_ARG(obj))
309 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
310 /* HEADERIZER END: src/spf_render.c */
312 #endif /* IN_SPF_SYSTEM */
316 * generated src/revision.c
318 PARROT_EXPORT int Parrot_config_revision(void);
320 #endif /* PARROT_MISC_H_GUARD */
323 * Local variables:
324 * c-file-style: "parrot"
325 * End:
326 * vim: expandtab shiftwidth=4: