Use reference counting for identifiers
This commit is contained in:
@@ -12,7 +12,7 @@ static inline void doLabels(GroundProgram* program, GroundState* state) {
|
||||
if (instruction->args.len > 0) {
|
||||
GroundArg* arg = &instruction->args.at[0];
|
||||
GroundLabel* label = NULL;
|
||||
HASH_FIND_STR(state->labels, arg->as.ref, label);
|
||||
HASH_FIND_STR(state->labels, arg->as.ref->string, label);
|
||||
|
||||
if (label == NULL) {
|
||||
label = malloc(sizeof(GroundLabel));
|
||||
@@ -21,7 +21,7 @@ static inline void doLabels(GroundProgram* program, GroundState* state) {
|
||||
Ground.Flags.error = true;
|
||||
return;
|
||||
}
|
||||
strncpy(label->name, arg->as.ref, 2047);
|
||||
strncpy(label->name, arg->as.ref->string, 2047);
|
||||
label->name[2047] = '\0';
|
||||
label->lineNum = i;
|
||||
HASH_ADD_STR(state->labels, name, label);
|
||||
@@ -34,10 +34,10 @@ static inline void doLabels(GroundProgram* program, GroundState* state) {
|
||||
GroundInstruction* instruction = &program->at[i];
|
||||
if (instruction->type == GroundInstruction_JUMP) {
|
||||
GroundArg* arg = &instruction->args.at[0];
|
||||
size_t* line = Ground.State.findLabel(state, arg->as.ref);
|
||||
size_t* line = Ground.State.findLabel(state, arg->as.ref->string);
|
||||
if (line == NULL) {
|
||||
char buf[2048];
|
||||
snprintf(buf, 2047, "couldn't find label '%s' (instruction JUMP at %zu) in Ground.Internal.Run()", arg->as.ref, i);
|
||||
snprintf(buf, 2047, "couldn't find label '%s' (instruction JUMP at %zu) in Ground.Internal.Run()", arg->as.ref->string, i);
|
||||
Ground.Log.Error(buf);
|
||||
Ground.Flags.error = true;
|
||||
return;
|
||||
@@ -47,10 +47,10 @@ static inline void doLabels(GroundProgram* program, GroundState* state) {
|
||||
|
||||
} else if (instruction->type == GroundInstruction_IF) {
|
||||
GroundArg* arg = &instruction->args.at[1];
|
||||
size_t* line = Ground.State.findLabel(state, arg->as.ref);
|
||||
size_t* line = Ground.State.findLabel(state, arg->as.ref->string);
|
||||
if (line == NULL) {
|
||||
char buf[2048];
|
||||
snprintf(buf, 2047, "couldn't find label '%s' (instruction IF at %zu) in Ground.Internal.Run()", arg->as.ref, i);
|
||||
snprintf(buf, 2047, "couldn't find label '%s' (instruction IF at %zu) in Ground.Internal.Run()", arg->as.ref->string, i);
|
||||
Ground.Log.Error(buf);
|
||||
Ground.Flags.error = true;
|
||||
return;
|
||||
@@ -60,10 +60,10 @@ static inline void doLabels(GroundProgram* program, GroundState* state) {
|
||||
|
||||
} else if (instruction->type == GroundInstruction_CATCH) {
|
||||
GroundArg* arg = &instruction->args.at[1];
|
||||
size_t* line = Ground.State.findLabel(state, arg->as.ref);
|
||||
size_t* line = Ground.State.findLabel(state, arg->as.ref->string);
|
||||
if (line == NULL) {
|
||||
char buf[2048];
|
||||
snprintf(buf, 2047, "couldn't find label '%s' (instruction CATCH at %zu) in Ground.Internal.Run()", arg->as.ref, i);
|
||||
snprintf(buf, 2047, "couldn't find label '%s' (instruction CATCH at %zu) in Ground.Internal.Run()", arg->as.ref->string, i);
|
||||
Ground.Log.Error(buf);
|
||||
Ground.Flags.error = true;
|
||||
return;
|
||||
@@ -92,7 +92,7 @@ static inline size_t doOffsets(GroundProgram* program, GroundState* state) {
|
||||
) continue;
|
||||
|
||||
GroundVariable* item = NULL;
|
||||
HASH_FIND_STR(state->variables, arg->as.ref, item);
|
||||
HASH_FIND_STR(state->variables, arg->as.ref->string, item);
|
||||
|
||||
if (item == NULL) {
|
||||
item = malloc(sizeof(GroundVariable));
|
||||
@@ -102,7 +102,7 @@ static inline size_t doOffsets(GroundProgram* program, GroundState* state) {
|
||||
return 0;
|
||||
}
|
||||
item->value = Ground.New.Value.Int(0);
|
||||
strncpy(item->name, arg->as.ref, 2047);
|
||||
strncpy(item->name, arg->as.ref->string, 2047);
|
||||
item->_offset = size++;
|
||||
HASH_ADD_STR(state->variables, name, item);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user