commit 3adcde1
uint
·
2026-10-24 18:29:16 +0000 UTC
parent 3c21d58
Rename expl_type->expression_type
M
expl.c
+26,
-18
1@@ -10,6 +10,14 @@
2 #define pos(p) ((p)->pos)
3 #define peek(p) ((p)->src[(p)->pos + 1])
4
5+typedef enum {
6+ EXPRESSION_TYPE_ATOM,
7+ EXPRESSION_TYPE_STRING,
8+ EXPRESSION_TYPE_LIST,
9+
10+ EXPRESSION_TYPE_COUNT
11+} expression_type;
12+
13 typedef struct environment environment;
14 typedef struct function function;
15 typedef struct parser parser;
16@@ -34,7 +42,7 @@ struct function {
17
18 struct expression {
19 char* value;
20- expl_type type;
21+ expression_type type;
22 expression* child;
23 expression* next;
24 };
25@@ -50,7 +58,7 @@ static expression* parse_expression(parser* p);
26 static expression* list(parser* p);
27 static expl_value* lookup(environment* env, const char* name);
28 expression* parse(const char* source);
29-static expression* value(parser* p, expl_type type);
30+static expression* value(parser* p, expression_type type);
31
32 static expl_value eval(expression* n, environment** env);
33 static expl_value eval_call(expression* args, environment** env);
34@@ -62,7 +70,7 @@ static void skip_space(parser* p);
35 static char* _strndup(const char* src, size_t len);
36 static void unescape(char* src);
37
38-static expression* new_node(expl_type type);
39+static expression* new_node(expression_type type);
40 static void free_node(expression* node);
41 static void free_environment(environment* env);
42
43@@ -92,7 +100,7 @@ parse_expression(parser* p)
44 skip_space(p);
45 switch (p->src[p->pos]) {
46 case '"':
47- return value(p, EXPL_TYPE_STRING);
48+ return value(p, EXPRESSION_TYPE_STRING);
49 case '(':
50 return list(p);
51 case ')':
52@@ -100,7 +108,7 @@ parse_expression(parser* p)
53 p->err = EXPL_ERR_UNEXPECTED_TOKEN;
54 return NULL;
55 default:
56- return value(p, EXPL_TYPE_ATOM);
57+ return value(p, EXPRESSION_TYPE_ATOM);
58 }
59 }
60
61@@ -112,7 +120,7 @@ list(parser* p)
62
63 advance(p);
64
65- node = new_node(EXPL_TYPE_LIST);
66+ node = new_node(EXPRESSION_TYPE_LIST);
67 if (!node) {
68 p->err = EXPL_ERR_OUT_OF_MEMORY;
69 return NULL;
70@@ -181,17 +189,17 @@ parse(const char* source)
71 }
72
73 static expression*
74-value(parser* p, expl_type type)
75+value(parser* p, expression_type type)
76 {
77 expression* node = NULL;
78 size_t start = 0;
79
80- if (type == EXPL_TYPE_STRING)
81+ if (type == EXPRESSION_TYPE_STRING)
82 advance(p);
83
84 start = p->pos;
85
86- if (type == EXPL_TYPE_STRING) {
87+ if (type == EXPRESSION_TYPE_STRING) {
88 while (!current_char(p, '"') && !current_char(p, '\0')) {
89 if (current_char(p, '\\') && p->src[p->pos + 1])
90 advance(p);
91@@ -210,7 +218,7 @@ value(parser* p, expl_type type)
92 advance(p);
93 }
94
95- if (start == p->pos && type == EXPL_TYPE_ATOM) {
96+ if (start == p->pos && type == EXPRESSION_TYPE_ATOM) {
97 p->err = EXPL_ERR_EXPECTED_ATOM;
98 return NULL;
99 }
100@@ -228,7 +236,7 @@ value(parser* p, expl_type type)
101 return NULL;
102 }
103
104- if (type == EXPL_TYPE_STRING) {
105+ if (type == EXPRESSION_TYPE_STRING) {
106 unescape(node->value);
107 advance(p);
108 }
109@@ -247,12 +255,12 @@ eval(expression* n, environment** env)
110 return result;
111
112 switch (n->type) {
113- case EXPL_TYPE_STRING:
114+ case EXPRESSION_TYPE_STRING:
115 result.type = EXPL_VALUE_STRING;
116 result.as.string = n->value;
117 return result;
118
119- case EXPL_TYPE_ATOM:
120+ case EXPRESSION_TYPE_ATOM:
121 result.as.number = strtod(n->value, &end);
122 if (end != n->value && !*end) {
123 result.type = EXPL_VALUE_NUMBER;
124@@ -264,7 +272,7 @@ eval(expression* n, environment** env)
125 return *v;
126 return result;
127
128- case EXPL_TYPE_LIST:
129+ case EXPRESSION_TYPE_LIST:
130 return eval_call(n, env);
131
132 default:
133@@ -283,7 +291,7 @@ eval_call(expression* n, environment** env)
134 int argc = 0;
135 int i = 0;
136
137- if (!n->child || n->child->type != EXPL_TYPE_ATOM)
138+ if (!n->child || n->child->type != EXPRESSION_TYPE_ATOM)
139 return result;
140
141 /* defined function */
142@@ -327,9 +335,9 @@ eval_fn(expression* args, environment** env)
143 function* f = NULL;
144
145 name = args;
146- if (!name || name->type != EXPL_TYPE_ATOM ||
147+ if (!name || name->type != EXPRESSION_TYPE_ATOM ||
148 !name->next || !name->next->next ||
149- name->next->type != EXPL_TYPE_LIST)
150+ name->next->type != EXPRESSION_TYPE_LIST)
151 return result;
152
153 f = malloc(sizeof(*f));
154@@ -466,7 +474,7 @@ unescape(char* src)
155 }
156
157 static expression*
158-new_node(expl_type type)
159+new_node(expression_type type)
160 {
161 expression* node = malloc(sizeof(*node));
162 if (!node)
M
expl.h
+0,
-8
1@@ -1,14 +1,6 @@
2 #ifndef EXPL_H
3 #define EXPL_H
4
5-typedef enum {
6- EXPL_TYPE_ATOM,
7- EXPL_TYPE_STRING,
8- EXPL_TYPE_LIST,
9-
10- EXPL_TYPE_COUNT
11-} expl_type;
12-
13 typedef enum {
14 EXPL_VALUE_NIL,
15 EXPL_VALUE_NUMBER,