12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #include <stdlib.h>
- #include <string.h>
- #include "utils/Functions.h"
- void fInit(Function* f, const char* name, int line) {
- f->name = name;
- f->arguments = 0;
- f->returnType = DT_VOID;
- f->address = -1;
- f->size = 0;
- f->line = line;
- }
- bool fAddArgument(Function* f, DataType type) {
- if(f->arguments >= FUNCTION_ARGUMENTS) {
- return true;
- }
- f->size += dtGetSize(type);
- f->argumentTypes[f->arguments++] = type;
- return false;
- }
- bool fCompare(Function* a, Function* b) {
- if(a->arguments != b->arguments) {
- return false;
- }
- for(int i = 0; i < a->arguments; i++) {
- if(a->argumentTypes[i] != b->argumentTypes[i]) {
- return false;
- }
- }
- return strcmp(a->name, b->name) == 0;
- }
- void fsInit(Functions* fs) {
- fs->capacity = 16;
- fs->entries = 0;
- fs->data = malloc(sizeof(Function) * fs->capacity);
- }
- void fsDelete(Functions* fs) {
- free(fs->data);
- }
- Function* fsSearch(Functions* fs, Function* f) {
- for(int i = 0; i < fs->entries; i++) {
- if(fCompare(fs->data + i, f)) {
- return fs->data + i;
- }
- }
- return NULL;
- }
- void fsAdd(Functions* fs, Function* f) {
- if(fs->entries >= fs->capacity) {
- fs->capacity *= 2;
- fs->data = realloc(fs->data, sizeof(Function) * fs->capacity);
- }
- fs->data[fs->entries++] = *f;
- }
|