mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Wrote value, chunk, memory sections, tested value
chunk and memory remain untested for now
This commit is contained in:
24
source/toy_chunk.c
Normal file
24
source/toy_chunk.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "toy_chunk.h"
|
||||
|
||||
#include "toy_memory.h"
|
||||
|
||||
void Toy_initChunk(Toy_Chunk* chunk) {
|
||||
chunk->count = 0;
|
||||
chunk->capacity = 0;
|
||||
chunk->code = NULL;
|
||||
}
|
||||
|
||||
void Toy_pushChunk(Toy_Chunk* chunk, uint8_t byte) {
|
||||
if (chunk->count +1 > chunk->capacity) {
|
||||
int oldCapacity = chunk->capacity;
|
||||
chunk->capacity = TOY_GROW_CAPACITY(oldCapacity);
|
||||
chunk->code = TOY_GROW_ARRAY(uint8_t, chunk->code, oldCapacity, chunk->capacity);
|
||||
}
|
||||
|
||||
chunk->code[chunk->count++] = byte;
|
||||
}
|
||||
|
||||
void Toy_freeChunk(Toy_Chunk* chunk) {
|
||||
TOY_FREE_ARRAY(uint8_t, chunk->code, chunk->capacity);
|
||||
Toy_initChunk(chunk);
|
||||
}
|
||||
Reference in New Issue
Block a user