mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Reworked Toy_String as a union, enabled -Wpedantic
Toy now fits into the C spec. Fixed #158 Addendum: MacOS test caught an error: error: a function declaration without a prototype is deprecated in all versions of C That took 3 attempts to fix correctly. Addendum: 'No new line at the end of file' are you shitting me?
This commit is contained in:
@@ -5,41 +5,53 @@
|
||||
#include "toy_bucket.h"
|
||||
#include "toy_value.h"
|
||||
|
||||
//rope pattern
|
||||
typedef struct Toy_String { //32 | 64 BITNESS
|
||||
enum Toy_StringType {
|
||||
TOY_STRING_NODE,
|
||||
TOY_STRING_LEAF,
|
||||
TOY_STRING_NAME,
|
||||
} type; //4 | 4
|
||||
//forward declare
|
||||
union Toy_String_t;
|
||||
|
||||
unsigned int length; //4 | 4
|
||||
unsigned int refCount; //4 | 4
|
||||
unsigned int cachedHash; //4 | 4
|
||||
//rope pattern, conforming to the C spec - see #158
|
||||
typedef enum Toy_StringType {
|
||||
TOY_STRING_NODE,
|
||||
TOY_STRING_LEAF,
|
||||
TOY_STRING_NAME,
|
||||
} Toy_StringType;
|
||||
|
||||
union {
|
||||
struct {
|
||||
struct Toy_String* left; //4 | 8
|
||||
struct Toy_String* right; //4 | 8
|
||||
} node; //8 | 16
|
||||
typedef struct Toy_StringInfo {
|
||||
Toy_StringType type;
|
||||
unsigned int length;
|
||||
unsigned int refCount;
|
||||
unsigned int cachedHash;
|
||||
} Toy_StringInfo;
|
||||
|
||||
struct {
|
||||
int _dummy; //4 | 4
|
||||
char data[]; //- | -
|
||||
} leaf; //4 | 4
|
||||
typedef struct Toy_StringNode {
|
||||
Toy_StringInfo _padding;
|
||||
union Toy_String_t* left;
|
||||
union Toy_String_t* right;
|
||||
} Toy_StringNode;
|
||||
|
||||
struct {
|
||||
Toy_ValueType type; //4 | 4
|
||||
bool constant; //1 | 1
|
||||
char data[]; //- | -
|
||||
} name; //8 | 8
|
||||
} as; //8 | 16
|
||||
} Toy_String; //24 | 32
|
||||
typedef struct Toy_StringLeaf {
|
||||
Toy_StringInfo _padding;
|
||||
char data[];
|
||||
} Toy_StringLeaf;
|
||||
|
||||
typedef struct Toy_StringName {
|
||||
Toy_StringInfo _padding;
|
||||
Toy_ValueType varType;
|
||||
bool varConstant;
|
||||
char data[];
|
||||
} Toy_StringName;
|
||||
|
||||
typedef union Toy_String_t {
|
||||
Toy_StringInfo info;
|
||||
Toy_StringNode node;
|
||||
Toy_StringLeaf leaf;
|
||||
Toy_StringName name;
|
||||
} Toy_String;
|
||||
|
||||
//
|
||||
TOY_API Toy_String* Toy_createString(Toy_Bucket** bucketHandle, const char* cstring);
|
||||
TOY_API Toy_String* Toy_createStringLength(Toy_Bucket** bucketHandle, const char* cstring, unsigned int length);
|
||||
|
||||
TOY_API Toy_String* Toy_createNameStringLength(Toy_Bucket** bucketHandle, const char* cname, unsigned int length, Toy_ValueType type, bool constant); //for variable names
|
||||
TOY_API Toy_String* Toy_createNameStringLength(Toy_Bucket** bucketHandle, const char* cname, unsigned int length, Toy_ValueType varType, bool constant); //for variable names
|
||||
|
||||
TOY_API Toy_String* Toy_copyString(Toy_String* str);
|
||||
TOY_API Toy_String* Toy_deepCopyString(Toy_Bucket** bucketHandle, Toy_String* str);
|
||||
@@ -50,8 +62,8 @@ TOY_API void Toy_freeString(Toy_String* str);
|
||||
|
||||
TOY_API unsigned int Toy_getStringLength(Toy_String* str);
|
||||
TOY_API unsigned int Toy_getStringRefCount(Toy_String* str);
|
||||
TOY_API Toy_ValueType Toy_getNameStringType(Toy_String* str);
|
||||
TOY_API Toy_ValueType Toy_getNameStringConstant(Toy_String* str);
|
||||
TOY_API Toy_ValueType Toy_getNameStringVarType(Toy_String* str);
|
||||
TOY_API Toy_ValueType Toy_getNameStringVarConstant(Toy_String* str);
|
||||
|
||||
TOY_API char* Toy_getStringRawBuffer(Toy_String* str); //allocates the buffer on the heap, needs to be freed
|
||||
|
||||
|
||||
Reference in New Issue
Block a user