View on GitHub

Toy

A toy programming language.

toy_literal_dictionary.h

This header defines the structure Toy_LiteralDictionary, which manages a series of Toy_Literal instances stored in a key-value hash map. The dictionary does not take ownership of given literals, instead it makes an internal copy.

The dictionary type is one of two fundemental data structures used throughout Toy - the other is the array.

Defined Functions

void Toy_initLiteralDictionary(Toy_LiteralDictionary* dictionary);

This function initializes the Toy_LiteralDictionary pointed to by dictionary.

void Toy_freeLiteralDictionary(Toy_LiteralDictionary* dictionary);

This function frees a Toy_LiteralDictionary pointed to by dictionary. Every literal within is passed to Toy_freeLiteral before its memory is released.

void Toy_setLiteralDictionary(Toy_LiteralDictionary* dictionary, Toy_Literal key, Toy_Literal value);

This function inserts the given key-value pair of literals into dictionary, creating it if it doesn’t exist, or freeing and overwriting it if key is already present. This function may also expand the memory buffer if needed.

Literal functions and opaques cannot be used as keys.

Toy_Literal Toy_getLiteralDictionary(Toy_LiteralDictionary* dictionary, Toy_Literal key);

This function returns the value of the literal within dictionary identified by key, or a null literal if it doesn’t exist.

Literal functions and opaques cannot be used as keys.

void Toy_removeLiteralDictionary(Toy_LiteralDictionary* dictionary, Toy_Literal key);

This function removes the key-value pair of literals from dictionary identified by key, if it exists.

Literal functions and opaques cannot be used as keys.

bool Toy_existsLiteralDictionary(Toy_LiteralDictionary* dictionary, Toy_Literal key);

This function returns true if the key-value pair identified by key exists within dictionary, otherwise it returns false.