Reworked generic structures, read more

The following structures are now more independant:

- Toy_Array
- Toy_Stack
- Toy_Bucket
- Toy_String

I reworked a lot of the memory allocation, so now there are more direct
calls to malloc() or realloc(), rather than relying on the macros from
toy_memory.h.

I've also split toy_memory into proper array and bucket files, because
it makes more sense this way, rather than having them both jammed into
one file. This means the eventual hashtable structure can also stand on
its own.

Toy_Array is a new wrapper around raw array pointers, and all of the
structures have their metadata embedded into their allocated memory now,
using variable length array members.

A lot of 'capacity' and 'count' variables were changed to 'size_t'
types, but this doesn't seem to be a problem anywhere.

If the workflow fails, then I'll leave it for tonight - I'm too tired,
and I don't want to overdo myself.
This commit is contained in:
2024-10-01 20:24:52 +10:00
parent 53b0fc158c
commit 7b453bc35f
34 changed files with 566 additions and 576 deletions

View File

@@ -6,24 +6,24 @@
//internal structure that holds the individual parts of a compiled routine
typedef struct Toy_Routine {
unsigned char* param; //c-string params in sequence (could be moved below the jump table?)
int paramCapacity;
int paramCount;
size_t paramCapacity;
size_t paramCount;
unsigned char* code; //the instruction set
int codeCapacity;
int codeCount;
size_t codeCapacity;
size_t codeCount;
int* jumps; //each 'jump' is the starting address of an element within 'data'
int jumpsCapacity;
int jumpsCount;
size_t* jumps; //each 'jump' is the starting address of an element within 'data'
size_t jumpsCapacity;
size_t jumpsCount;
unsigned char* data; //{type,val} tuples of data
int dataCapacity;
int dataCount;
size_t dataCapacity;
size_t dataCount;
unsigned char* subs; //subroutines, recursively
int subsCapacity;
int subsCount;
size_t subsCapacity;
size_t subsCount;
} Toy_Routine;
TOY_API void* Toy_compileRoutine(Toy_Ast* ast);