parrotcode: Some utility functions | |
Contents | C |
src/utils.c - Some utility functions
Prototypes are in src/misc.h.
Opcode helper functions that don't really fit elsewhere.
PARROT_CONST_FUNCTION INTVAL intval_mod(INTVAL i2, INTVAL i3)
x mod y = x - y * floor(x / y)
PARROT_CONST_FUNCTION FLOATVAL floatval_mod(FLOATVAL n2, FLOATVAL n3)
n2 mod n3
.lcc
compiler.Based on the rand48()
family of functions.
static void next_rand(_rand_buf X)
X
.static FLOATVAL _erand48(_rand_buf buf)
double
in the interval [0.0, 1.0)
.static FLOATVAL _drand48(void)
double
in the interval [0.0, 1.0)
.static long _jrand48(_rand_buf buf)
long
in the interval [-2^31, 2^31)
.static long _nrand48(_rand_buf buf)
long
in the interval [0, 2^31)
.static long _lrand48(void)
long
in the interval [0, 2^31)
.static long _mrand48(void)
long
in the interval [-2^31, 2^31)
.static void _srand48(long seed)
seed
. The low order 16 bits are set to the arbitrary value 0x330e.PARROT_API FLOATVAL Parrot_float_rand(INTVAL how_random)
FLOATVAL
in the interval [0.0, 1.0)
.how_random
is ignored.PARROT_API INTVAL Parrot_uint_rand(INTVAL how_random)
INTVAL
in the interval [0, 2^31)
.how_random
is ignored.PARROT_API INTVAL Parrot_int_rand(INTVAL how_random)
INTVAL
in the interval [-2^31, 2^31)
.how_random
is ignored.PARROT_API INTVAL Parrot_range_rand(INTVAL from, INTVAL to, INTVAL how_random)
INTVAL
in the range [from, to]
.how_random
is ignored.PARROT_API void Parrot_srand(INTVAL seed)
Seeds the random number generator with seed
.PARROT_API PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL void *Parrot_make_la(PARROT_INTERP, NOTNULL(PMC *array))
long
s with one more element than the number of elements in *array
. The elements are then copied from *array
to the new array, and the last (extra) element is set to 0.src/nci.c
.PARROT_API void Parrot_destroy_la(NULLOK(long *array))
Parrot_make_la()
.PARROT_API PARROT_MALLOC PARROT_CANNOT_RETURN_NULL void *Parrot_make_cpa(PARROT_INTERP, NOTNULL(PMC *array))
char *
s with one more element than the number of elements in *array
. The elements are then copied from *array
to the new array, and the last (extra) element is set to 0.Parrot_destroy_cpa()
.PARROT_API void Parrot_destroy_cpa(NOTNULL(char **array))
Parrot_make_cpa()
.PARROT_API PARROT_CANNOT_RETURN_NULL PMC *tm_to_array(PARROT_INTERP, NOTNULL(const struct tm *tm))
PARROT_API INTVAL Parrot_byte_index(SHIM_INTERP, NOTNULL(const STRING *base), NOTNULL(const STRING *search), UINTVAL start_offset)
PARROT_API PARROT_WARN_UNUSED_RESULT INTVAL Parrot_byte_rindex(SHIM_INTERP, NOTNULL(const STRING *base), NOTNULL(const STRING *search), UINTVAL start_offset)
static void rec_climb_back_and_mark(int node_index, NOTNULL(parrot_prm_context *c))
node_index ... the index of a destination (i.e. with a pred.) register
c ... the graph and all the needed params : the context
static void process_cycle_without_exit(int node_index, NOTNULL(parrot_prm_context *c))
node_index ... the index of a destination (i.e. with a pred.) register
c ... the graph and all the needed params : the context
static void move_reg(int from, int dest, NOTNULL(parrot_prm_context *c))
PARROT_API void Parrot_register_move(PARROT_INTERP, int n_regs, NOTNULL(unsigned char *dest_regs), NOTNULL(unsigned char *src_regs), unsigned char temp_reg, reg_move_func mov, reg_move_func mov_alt, NOTNULL(void *info))
n_regs
from the given register list src_regs
to dest_regs
. n_regs ... amount of registers to move
dest_regs ... list of register numbers 0..255
src_regs ... list of register numbers 0..255
temp_reg ... a register number not in one of these lists
mov ... a register move function to be called to move one register
mov_alt ... a register move function to be called to move one register
which triese fetching from an alternate src (or NULLfunc):
(void) (mov)(interp, dest, src, info);
moved = (mov_alt)(interp, dest, src, info);
dest_regs
might be the same as src_regs
, which makes this a bit non-trivial, because if the destination is already clobbered, using it later as source doesn"t work. E.g. 0 <- 1
1 <- 0 # register 0 already clobbered
2 <- 0
0 <- 1
3 <- 2 # register 2 already clobbered - reorder moves
a) rearrange the order of moves (not possible in the first case)
and/or if that failed:
b) if an alternate move function is available, it may fetch the
source from a different (non-clobbered) location - call it.
if the function returns 0 also use c)
c) if no alternate move function is available, use the temp reg
Initial version by leo 2003.09.09.
|