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

@@ -1,8 +1,8 @@
#pragma once
#include "toy_common.h"
#include "toy_memory.h"
#include "toy_bucket.h"
#include "toy_value.h"
//each major type
@@ -55,18 +55,6 @@ typedef enum Toy_AstFlag {
//the root AST type
typedef union Toy_Ast Toy_Ast;
void Toy_private_initAstBlock(Toy_Bucket** bucket, Toy_Ast** handle);
void Toy_private_appendAstBlock(Toy_Bucket** bucket, Toy_Ast** handle, Toy_Ast* child);
void Toy_private_emitAstValue(Toy_Bucket** bucket, Toy_Ast** handle, Toy_Value value);
void Toy_private_emitAstUnary(Toy_Bucket** bucket, Toy_Ast** handle, Toy_AstFlag flag);
void Toy_private_emitAstBinary(Toy_Bucket** bucket, Toy_Ast** handle,Toy_AstFlag flag, Toy_Ast* right);
void Toy_private_emitAstGroup(Toy_Bucket** bucket, Toy_Ast** handle);
void Toy_private_emitAstPass(Toy_Bucket** bucket, Toy_Ast** handle);
void Toy_private_emitAstError(Toy_Bucket** bucket, Toy_Ast** handle);
void Toy_private_emitAstEnd(Toy_Bucket** bucket, Toy_Ast** handle);
typedef struct Toy_AstBlock {
Toy_AstType type;
Toy_Ast* child; //begin encoding the line
@@ -121,3 +109,15 @@ union Toy_Ast { //32 | 64 BITNESS
Toy_AstError error; //4 | 4
Toy_AstEnd end; //4 | 4
}; //16 | 32
void Toy_private_initAstBlock(Toy_Bucket** bucket, Toy_Ast** handle);
void Toy_private_appendAstBlock(Toy_Bucket** bucket, Toy_Ast* block, Toy_Ast* child);
void Toy_private_emitAstValue(Toy_Bucket** bucket, Toy_Ast** handle, Toy_Value value);
void Toy_private_emitAstUnary(Toy_Bucket** bucket, Toy_Ast** handle, Toy_AstFlag flag);
void Toy_private_emitAstBinary(Toy_Bucket** bucket, Toy_Ast** handle,Toy_AstFlag flag, Toy_Ast* right);
void Toy_private_emitAstGroup(Toy_Bucket** bucket, Toy_Ast** handle);
void Toy_private_emitAstPass(Toy_Bucket** bucket, Toy_Ast** handle);
void Toy_private_emitAstError(Toy_Bucket** bucket, Toy_Ast** handle);
void Toy_private_emitAstEnd(Toy_Bucket** bucket, Toy_Ast** handle);