#include #include #include "FunctionMap.h" void fmInit(FunctionMap* fm) { fm->capacity = 16; fm->entries = 0; fm->data = malloc(sizeof(Function) * fm->capacity); } void fmDelete(FunctionMap* fm) { free(fm->data); } int fmSearchAddress(FunctionMap* fm, const char* name, int arguments) { for(int i = 0; i < fm->entries; i++) { if(fm->data[i].arguments == arguments && strcmp(fm->data[i].name, name) == 0) { return fm->data[i].address; } } return -1; } bool fmAdd(FunctionMap* fm, const char* name, int arguments, int address) { if(fmSearchAddress(fm, name, arguments) != -1) { return false; } if(fm->entries >= fm->capacity) { fm->capacity *= 2; fm->data = realloc(fm->data, sizeof(Function) * fm->capacity); } int index = fm->entries++; fm->data[index].name = name; fm->data[index].arguments = arguments; fm->data[index].address = address; return true; }