static allocated_mem_ptrs *new_mem_ptrs_block(void)

Create a new allocated_mem_ptrs block; all pointers to allocated memory within pirc are stored in such blocks. One block has space for a number of pointers; if the block is full, a new block must be created and linked into the list of blocks.

static void register_ptr(lexer_state *lexer, void *ptr)

Store the pointer ptr in a datastructure; whenever release_resources() is invoked, ptr will be freed through mem_sys_free().

void *pir_mem_allocate_zeroed(lexer_state *const lexer, size_t numbytes)

Memory allocation function for all PIR internal functions. Memory is allocated through Parrot's allocation functions, but the pointer to the allocated memory is stored in a data structure; this way, freeing all memory can be done by just iterating over these pointers and freeing them.

Memory allocated through this function is all set to zero.

void *pir_mem_allocate(NOTNULL(lexer_state *const lexer), size_t numbytes)

See pir_mem_allocate_zeroed(). Memory is not guaranteed to be zeroed. (It might, it might not, depending on what your system finds appropriate. Don't count on it anyway.)

void init_hashtable(lexer_state *const lexer, hashtable *const table, unsigned size)

Initialize the hashtable table with space for size buckets.

lexer_state *new_lexer(char *const filename, int flags)

Constructor for a lexer structure. Initializes all fields, creates a Parrot interpreter structure.

bucket *new_bucket(lexer_state *const lexer)

Constructor for a bucket object.

static void store_string(lexer_state *const lexer, char const *const str)

Store the string str in a hashtable; whenever this string is needed, a pointer to the same physical string is returned, preventing allocating different buffers for the same string. This is especially useful for ops, as most ops in a typical program will be used many times.

static char const *find_string(lexer_state *const lexer, char const *const str)

Find the string str in the lexer's string hashtable. If the string was found, then a pointer to that buffer is returned. So, whenever for instance the string "print" is used, the string will only be stored in memory once, and a pointer to that buffer will be returned.

char *dupstrn(lexer_state *const lexer, char const *const source, size_t slen)

See dupstr, except that this version takes the number of characters to be copied. Easy for copying a string except the quotes, for instance.

XXX maybe make this a runtime (commandline) option? Might be slightly slower. XXX Otherwise maybe a build option using #defines.

char *dupstr(lexer_state *const lexer, char const *const source)

The C89 standard does not define a strdup() in the C library, so define our own strdup. Function names beginning with "str" are reserved, so make it dupstr, as that is what it does: duplicate a string.

void release_resources(lexer_state *lexer)

Release all resources pointed to by lexer. Free all memory that was allocated through pir_mem_allocate_zeroed(). Free lexer itself.

void pirwarning(lexer_state *const lexer, int lineno, char const *const message, ...)

Emit a warning message to stderr. The line number (passed in lineno) is reported, together with the message. The message can be formatted, meaning it can contain printf's placeholders. message and all variable arguments are passed to vfprintf().


parrot