Initial commit

This commit is contained in:
ktkk 2026-01-13 19:52:23 +00:00
commit b2edca2cb4
25 changed files with 3590 additions and 0 deletions

29
memory.h Normal file
View file

@ -0,0 +1,29 @@
#ifndef clox_memory_h
#define clox_memory_h
#include "common.h"
#include "object.h"
#define ALLOCATE(type, count) \
(type*)reallocate(nullptr, 0, sizeof(type) * (count))
#define FREE(type, pointer) \
reallocate(pointer, sizeof(type), 0)
#define GROW_CAPACITY(capacity) \
((capacity) < 8 ? 8 : (capacity) * 2)
#define GROW_ARRAY(type, pointer, oldCount, newCount) \
(type*)reallocate(pointer, sizeof(type) * (oldCount), sizeof(type) * (newCount))
#define FREE_ARRAY(type, pointer, oldCount) \
reallocate(pointer, sizeof(type) * (oldCount), 0)
void* reallocate(void* pointer, size_t oldSize, size_t newSize);
void markObject(Obj* object);
void markValue(Value value);
void collectGarbage();
void freeObjects();
#endif // clox_memory_h