/** * @file program.h * @brief Program: a container of mnemonics, itself a mnemonic (composite pattern). * @note Program is a derivable class. */ #ifndef PROGRAM_H #define PROGRAM_H #include "mne.h" /** * @brief Forward declaration of derivable class Program. * */ typedef struct _program_t program_t; /** * @brief Program vtable is identical to base Mne vtable (no new methods). * */ typedef mne_vtable_t program_vtable_t; /** * @brief Constructs a Program with empty instruction sequence. * * @return A newly allocated Program. */ program_t* program_build_default(void); /** * @brief Destroys a Program and all its mnemonics. * * @param self The Program (can be NULL). * @note The program owns its mnemonics; they are destroyed during cleanup. */ void program_destroy(program_t *self); /** * @brief Adds a Print mnemonic to the end of the program sequence. * * @param self The Program. * @pre self != NULL. * @note Allocations are assumed to never fail. * The mnemonic is owned by the program and destroyed with it. */ void program_new_print(program_t *const self); /** * @brief Adds an Add mnemonic to the end of the program sequence. * * @param self The Program. * @pre self != NULL. * @note Allocations are assumed to never fail. * The mnemonic is owned by the program and destroyed with it. */ void program_new_add(program_t *const self); /** * @brief Adds a Sub mnemonic to the end of the program sequence. * * @param self The Program. * @pre self != NULL. * @note Allocations are assumed to never fail. * The mnemonic is owned by the program and destroyed with it. */ void program_new_sub(program_t *const self); /** * @brief Adds a Mul mnemonic to the end of the program sequence. * * @param self The Program. * @pre self != NULL. * @note Allocations are assumed to never fail. * The mnemonic is owned by the program and destroyed with it. */ void program_new_mul(program_t *const self); /** * @brief Adds a Division mnemonic to the end of the program sequence. * * @param self The Program. * @pre self != NULL. * @note Allocations are assumed to never fail. * The mnemonic is owned by the program and destroyed with it. */ void program_new_div(program_t *const self); /** * @brief Adds a Push mnemonic with the given value to the end of the sequence. * * @param self The Program. * @param value The value to push. * @pre self != NULL. * @note Allocations are assumed to never fail. * The mnemonic is owned by the program and destroyed with it. */ void program_new_push(program_t *const self, const long value); /** * @brief Empties the program sequence, destroying all mnemonics. * * @param self The Program. * @pre self != NULL. */ void program_clear(program_t *const self); /** * @brief Interprets the Program: executes each mnemonic in sequence on the stack. * * @param self The Program. * @param stack The stack. * @pre self != NULL && stack != NULL. * @note Stops at the first mnemonic that sets errno (no rollback). */ void program_interpret(const program_t *const self, stack_t *const stack); /** * @brief Allows a visitor to visit each mnemonic in the program sequence. * * @param self The Program. * @param visitor The visitor. * @pre self != NULL && visitor != NULL. */ void program_accept(const program_t *const self, visitor_t *const visitor); #endif /* PROGRAM_H */