Skip to content

Commit 017aaa5

Browse files
committed
Refactor terminology
"stack" -> "scopes"
1 parent 8d86fea commit 017aaa5

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

jim.h

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#ifndef JIM_H_
22
#define JIM_H_
33

4-
#ifndef JIM_STACK_CAPACITY
5-
#define JIM_STACK_CAPACITY 128
6-
#endif // JIM_STACK_CAPACITY
4+
#ifndef JIM_SCOPES_CAPACITY
5+
#define JIM_SCOPES_CAPACITY 128
6+
#endif // JIM_SCOPES_CAPACITY
77

88
typedef void* Jim_Sink;
99
typedef size_t (*Jim_Write)(const void *ptr, size_t size, size_t nmemb, Jim_Sink sink);
1010

1111
typedef enum {
1212
JIM_OK = 0,
1313
JIM_WRITE_ERROR,
14-
JIM_STACK_OVERFLOW,
15-
JIM_STACK_UNDERFLOW,
14+
JIM_SCOPES_OVERFLOW,
15+
JIM_SCOPES_UNDERFLOW,
1616
JIM_OUT_OF_SCOPE_KEY,
1717
JIM_DOUBLE_KEY
1818
} Jim_Error;
@@ -34,8 +34,8 @@ typedef struct {
3434
Jim_Sink sink;
3535
Jim_Write write;
3636
Jim_Error error;
37-
Jim_Scope stack[JIM_STACK_CAPACITY];
38-
size_t stack_size;
37+
Jim_Scope scopes[JIM_SCOPES_CAPACITY];
38+
size_t scopes_size;
3939
} Jim;
4040

4141
void jim_null(Jim *jim);
@@ -67,36 +67,36 @@ static size_t jim_strlen(const char *s)
6767
return count;
6868
}
6969

70-
static void jim_stack_push(Jim *jim, Jim_Scope_Kind kind)
70+
static void jim_scope_push(Jim *jim, Jim_Scope_Kind kind)
7171
{
7272
if (jim->error == JIM_OK) {
73-
if (jim->stack_size < JIM_STACK_CAPACITY) {
74-
jim->stack[jim->stack_size].kind = kind;
75-
jim->stack[jim->stack_size].tail = 0;
76-
jim->stack[jim->stack_size].key = 0;
77-
jim->stack_size += 1;
73+
if (jim->scopes_size < JIM_SCOPES_CAPACITY) {
74+
jim->scopes[jim->scopes_size].kind = kind;
75+
jim->scopes[jim->scopes_size].tail = 0;
76+
jim->scopes[jim->scopes_size].key = 0;
77+
jim->scopes_size += 1;
7878
} else {
79-
jim->error = JIM_STACK_OVERFLOW;
79+
jim->error = JIM_SCOPES_OVERFLOW;
8080
}
8181
}
8282
}
8383

84-
static void jim_stack_pop(Jim *jim)
84+
static void jim_scope_pop(Jim *jim)
8585
{
8686
if (jim->error == JIM_OK) {
87-
if (jim->stack_size > 0) {
88-
jim->stack_size--;
87+
if (jim->scopes_size > 0) {
88+
jim->scopes_size--;
8989
} else {
90-
jim->error = JIM_STACK_UNDERFLOW;
90+
jim->error = JIM_SCOPES_UNDERFLOW;
9191
}
9292
}
9393
}
9494

95-
static Jim_Scope *jim_stack_top(Jim *jim)
95+
static Jim_Scope *jim_current_scope(Jim *jim)
9696
{
9797
if (jim->error == JIM_OK) {
98-
if (jim->stack_size > 0) {
99-
return &jim->stack[jim->stack_size - 1];
98+
if (jim->scopes_size > 0) {
99+
return &jim->scopes[jim->scopes_size - 1];
100100
}
101101
}
102102

@@ -135,7 +135,7 @@ static int jim_get_utf8_char_len(unsigned char ch)
135135
void jim_element_begin(Jim *jim)
136136
{
137137
if (jim->error == JIM_OK) {
138-
Jim_Scope *scope = jim_stack_top(jim);
138+
Jim_Scope *scope = jim_current_scope(jim);
139139
if (scope && scope->tail && !scope->key) {
140140
jim_write_cstr(jim, ",");
141141
}
@@ -145,7 +145,7 @@ void jim_element_begin(Jim *jim)
145145
void jim_element_end(Jim *jim)
146146
{
147147
if (jim->error == JIM_OK) {
148-
Jim_Scope *scope = jim_stack_top(jim);
148+
Jim_Scope *scope = jim_current_scope(jim);
149149
if (scope) {
150150
scope->tail = 1;
151151
scope->key = 0;
@@ -161,10 +161,10 @@ const char *jim_error_string(Jim_Error error)
161161
return "There is no error. The developer of this software just had a case of \"Task failed successfully\" https://i.imgur.com/Bdb3rkq.jpg - Please contact the developer and tell them that they are very lazy for not checking errors properly.";
162162
case JIM_WRITE_ERROR:
163163
return "Write error";
164-
case JIM_STACK_OVERFLOW:
165-
return "Stack Overflow";
166-
case JIM_STACK_UNDERFLOW:
167-
return "Stack Underflow";
164+
case JIM_SCOPES_OVERFLOW:
165+
return "Stack of Scopes Overflow";
166+
case JIM_SCOPES_UNDERFLOW:
167+
return "Stack of Scopes Underflow";
168168
case JIM_OUT_OF_SCOPE_KEY:
169169
return "Out of Scope key";
170170
case JIM_DOUBLE_KEY:
@@ -316,7 +316,7 @@ void jim_array_begin(Jim *jim)
316316
if (jim->error == JIM_OK) {
317317
jim_element_begin(jim);
318318
jim_write_cstr(jim, "[");
319-
jim_stack_push(jim, JIM_ARRAY_SCOPE);
319+
jim_scope_push(jim, JIM_ARRAY_SCOPE);
320320
}
321321
}
322322

@@ -325,7 +325,7 @@ void jim_array_end(Jim *jim)
325325
{
326326
if (jim->error == JIM_OK) {
327327
jim_write_cstr(jim, "]");
328-
jim_stack_pop(jim);
328+
jim_scope_pop(jim);
329329
jim_element_end(jim);
330330
}
331331
}
@@ -335,15 +335,15 @@ void jim_object_begin(Jim *jim)
335335
if (jim->error == JIM_OK) {
336336
jim_element_begin(jim);
337337
jim_write_cstr(jim, "{");
338-
jim_stack_push(jim, JIM_OBJECT_SCOPE);
338+
jim_scope_push(jim, JIM_OBJECT_SCOPE);
339339
}
340340
}
341341

342342
void jim_member_key(Jim *jim, const char *str, const unsigned int *size)
343343
{
344344
if (jim->error == JIM_OK) {
345345
jim_element_begin(jim);
346-
Jim_Scope *scope = jim_stack_top(jim);
346+
Jim_Scope *scope = jim_current_scope(jim);
347347
if (scope && scope->kind == JIM_OBJECT_SCOPE) {
348348
if (!scope->key) {
349349
jim_string_no_element(jim, str, size);
@@ -362,7 +362,7 @@ void jim_object_end(Jim *jim)
362362
{
363363
if (jim->error == JIM_OK) {
364364
jim_write_cstr(jim, "}");
365-
jim_stack_pop(jim);
365+
jim_scope_pop(jim);
366366
jim_element_end(jim);
367367
}
368368
}

0 commit comments

Comments
 (0)