Use reference counting for identifiers

This commit is contained in:
2026-06-17 10:11:15 +10:00
parent 6d35acbe60
commit b4e481ed9c
16 changed files with 112 additions and 156 deletions

View File

@@ -38,6 +38,8 @@ typedef struct GroundError GroundError;
// --- Helper types ---
typedef struct GroundIdentifier GroundIdentifier;
typedef struct GroundFunctionArg GroundFunctionArg;
typedef struct GroundObjectField GroundObjectField;
@@ -113,7 +115,7 @@ struct GroundType {
struct GroundFunctionArg {
union {
char* id;
GroundIdentifier* id;
GroundType type;
} as;
};
@@ -143,7 +145,7 @@ enum GroundArgType {
struct GroundArg {
enum GroundArgType type;
union {
char* ref;
GroundIdentifier* ref;
GroundValue value;
} as;
@@ -247,6 +249,11 @@ struct GroundState {
size_t _size;
};
struct GroundIdentifier {
char* string;
size_t referenceCount;
};
//
// INTERFACE
//
@@ -277,12 +284,12 @@ struct _Ground {
struct {
GroundArg (*Value) (GroundValue value);
GroundArg (*ValueRef) (const char* ref);
GroundArg (*DirectRef) (const char* ref);
GroundArg (*LineRef) (const char* ref);
GroundArg (*LabelRef) (const char* ref);
GroundArg (*FunctionRef) (const char* ref);
GroundArg (*TypeRef) (const char* ref);
GroundArg (*ValueRef) (GroundIdentifier* ref);
GroundArg (*DirectRef) (GroundIdentifier* ref);
GroundArg (*LineRef) (GroundIdentifier* ref);
GroundArg (*LabelRef) (GroundIdentifier* ref);
GroundArg (*FunctionRef) (GroundIdentifier* ref);
GroundArg (*TypeRef) (GroundIdentifier* ref);
} Arg;
GroundList (*List) ();
@@ -298,6 +305,8 @@ struct _Ground {
GroundProgram (*Program) ();
GroundType (*Type) (enum GroundTypeType type, ...);
GroundIdentifier* (*Identifier) (const char* id);
} New;
// Frees the memory held by the specified struct
@@ -313,6 +322,8 @@ struct _Ground {
void (*Instruction) (GroundInstruction* in);
void (*Program) (GroundProgram* in);
void (*State) (GroundState* state);
void (*Identifier) (GroundIdentifier* identifier);
} Free;
// Creates a copy of the memory held by the specified struct
@@ -328,6 +339,8 @@ struct _Ground {
GroundInstruction (*Instruction) (GroundInstruction* in);
GroundProgram (*Program) (GroundProgram* in);
GroundState (*State) (GroundState* in);
GroundIdentifier* (*Identifier) (GroundIdentifier* in);
} Copy;
struct {