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.
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)
- Constructor for a lexer structure.
Initializes all fields,
creates a Parrot interpreter structure.
static bucket *new_bucket(void)
- Constructor for a bucket object.
static void store_string(lexer_state *const lexer, char *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 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.
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()
.
Call the destructor on the Parrot Interpreter,
and free lexer
itself.
|
|