mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Strings, due to their potentially large size, are stored outside of a routine's code section, in the data section. To access the correct string, you must read the jump index, then the real address from the jump table - and extra layer of indirection will result in more flexible data down the road, I hope. Other changes include: * Added string concat operator .. * Added TOY_STRING_MAX_LENGTH * Strings can't be created or concatenated longer than the max length * The parser will display a warning if the bucket is too small for a string at max length, but it will continue * Added TOY_BUCKET_IDEAL to correspend with max string length * The bucket now allocates an address that is 4-byte aligned * Fixed missing entries in the parser rule table * Corrected some failing TOY_BITNESS tests
29 lines
935 B
C
29 lines
935 B
C
#pragma once
|
|
|
|
#include "toy_common.h"
|
|
|
|
//NOTE: this structure has restrictions on it's usage:
|
|
// - It can only expand until it is freed
|
|
// - It cannot be copied around within RAM
|
|
// - It cannot allocate more memory than it has capacity
|
|
// If each of these rules are followed, the bucket is actually more efficient than any other option
|
|
|
|
//a custom allocator
|
|
typedef struct Toy_Bucket { //32 | 64 BITNESS
|
|
struct Toy_Bucket* next; //4 | 8
|
|
unsigned int capacity; //4 | 4
|
|
unsigned int count; //4 | 4
|
|
char data[]; //- | -
|
|
} Toy_Bucket; //12 | 16
|
|
|
|
TOY_API Toy_Bucket* Toy_allocateBucket(unsigned int capacity);
|
|
TOY_API void* Toy_partitionBucket(Toy_Bucket** bucketHandle, unsigned int amount);
|
|
TOY_API void Toy_freeBucket(Toy_Bucket** bucketHandle);
|
|
|
|
//some useful bucket sizes
|
|
#define TOY_BUCKET_SMALL 256
|
|
#define TOY_BUCKET_MEDIUM 512
|
|
#define TOY_BUCKET_LARGE 1024
|
|
|
|
#define TOY_BUCKET_IDEAL 1024
|