Go to the source code of this file.
|
| static void | print_string_payload (FILE *out, const srn_string_t *s) |
| static void | write_bytes (FILE *out, const uint8_t *buf, size_t len) |
| static void | print_list (FILE *out, srn_context_t *ctx, const srn_value_t *v) |
| static void | print_seq (FILE *out, srn_context_t *ctx, const srn_value_t *v) |
| void | srn_value_print (FILE *out, srn_context_t *ctx, const srn_value_t *v) |
| | Print a value to out in its S-expression form.
|
| void | srn_value_println (FILE *out, srn_context_t *ctx, const srn_value_t *v) |
| | Same as srn_value_print followed by '
'.
|
| static void | print_quoted_string (FILE *out, const char *s) |
| static void | print_seq_body (FILE *out, srn_context_t *ctx, const seq_t *body, char open, char close) |
| void | srn_syntax_print (FILE *out, srn_context_t *ctx, const srn_syntax_t *s) |
| | Print a syntax node to out in its S-expression form.
|
| void | srn_syntax_println (FILE *out, srn_context_t *ctx, const srn_syntax_t *s) |
| | Same as srn_syntax_print followed by '
'.
|
◆ print_list()
Definition at line 66 of file print.c.
66 {
67 fputc('(', out);
69 bool first = true;
71 if (!first) {
72 fputc(' ', out);
73 }
74 first = false;
76 }
77 fputc(')', out);
78}
#define AS_LIST(value_ref)
void srn_value_print(FILE *out, srn_context_t *ctx, const srn_value_t *v)
Print a value to out in its S-expression form.
A list is a singly linked sequence of values.
◆ print_quoted_string()
| void print_quoted_string |
( |
FILE * | out, |
|
|
const char * | s ) |
|
static |
Definition at line 201 of file print.c.
201 {
202 fputc('"', out);
203 for (const char *p = s; *p != '\0'; p++) {
204 switch (*p) {
205 case '"':
206 fputs("\\\"", out);
207 break;
208 case '\\':
209 fputs("\\\\", out);
210 break;
211 case '\n':
212 fputs("\\n", out);
213 break;
214 case '\t':
215 fputs("\\t", out);
216 break;
217 case '\r':
218 fputs("\\r", out);
219 break;
220 default:
221 fputc((int)(unsigned char)*p, out);
222 break;
223 }
224 }
225 fputc('"', out);
226}
◆ print_seq()
Definition at line 80 of file print.c.
80 {
81 fputc('[', out);
83 for (
size_t i = 0; i < s->
inner.
len; i++) {
84 if (i > 0) {
85 fputc(' ', out);
86 }
88 if (r.maybe_error != nullptr) {
89 fputs("#<seq-error>", out);
90 continue;
91 }
93 }
94 fputc(']', out);
95}
#define AS_SEQ(value_ref)
seq_lookup_result_t seq_get(const seq_t *seq, size_t n)
Negative index is not supported.
size_t len
logical length.
A persistent, immutable, indexed sequence.
◆ print_seq_body()
| void print_seq_body |
( |
FILE * | out, |
|
|
srn_context_t * | ctx, |
|
|
const seq_t * | body, |
|
|
char | open, |
|
|
char | close ) |
|
static |
Definition at line 231 of file print.c.
231 {
232 fputc(open, out);
233 for (
size_t i = 0; i < body->
len; i++) {
234 if (i > 0) {
235 fputc(' ', out);
236 }
238 if (r.maybe_error != nullptr) {
239 fputs("#<seq-error>", out);
240 continue;
241 }
243 }
244 fputc(close, out);
245}
void srn_syntax_print(FILE *out, srn_context_t *ctx, const srn_syntax_t *s)
Print a syntax node to out in its S-expression form.
◆ print_string_payload()
| void print_string_payload |
( |
FILE * | out, |
|
|
const srn_string_t * | s ) |
|
static |
Definition at line 32 of file print.c.
32 {
33 fputc('"', out);
34 for (
size_t i = 0; i < s->
len; i++) {
36 switch (c) {
37 case '"':
38 fputs("\\\"", out);
39 break;
40 case '\\':
41 fputs("\\\\", out);
42 break;
43 case '\n':
44 fputs("\\n", out);
45 break;
46 case '\t':
47 fputs("\\t", out);
48 break;
49 case '\r':
50 fputs("\\r", out);
51 break;
52 default:
53 fputc((int)c, out);
54 break;
55 }
56 }
57 fputc('"', out);
58}
uint8_t buffer[]
The buffer that holds the WTF8 sequence.
size_t len
length of the WTF-8 sequence in bytes
◆ srn_syntax_print()
Print a syntax node to out in its S-expression form.
Numbers are emitted from their stored raw text (no formatting normalization). Maps print as {k v k v} because the syntax-level container is a flat seq.
Definition at line 247 of file print.c.
247 {
251
254 fputs("nil", out);
255 break;
257 fputs("true", out);
258 break;
260 fputs("false", out);
261 break;
262
265 break;
268 break;
269
272 break;
273
275 fputc(':', out);
277 break;
278
281 break;
284 break;
287 break;
288
290 fputc('\'', out);
292 break;
293
296 (void)fprintf(out,
"#<error tag=%d", (
int)e->
tag);
297 if (e->
msg !=
nullptr) {
298 (void)fprintf(out,
" %s", e->
msg);
299 }
300 fputc('>', out);
301 break;
302 }
303
304 default:
305 fputs("#<unknown>", out);
306 break;
307 }
308}
@ SError
SError should be last.
static void print_quoted_string(FILE *out, const char *s)
static void print_seq_body(FILE *out, srn_context_t *ctx, const seq_t *body, char open, char close)
A runtime error, a tag classifying the failure and a human-readable message.
union srn_syntax_t::@333325137367112222275110336355257173264057161216 as
IMPORTANT NOTE: The size of this union should never be larger than a word.
struct srn_syntax_t * quote
const char * symbol
For syntax only, we represent numbers as a strings,.
#define PANIC_IF_NULL(ptr)
◆ srn_syntax_println()
Same as srn_syntax_print followed by '
'.
Definition at line 310 of file print.c.
310 {
312 fputc('\n', out);
313}
◆ srn_value_print()
Print a value to out in its S-expression form.
Atoms round-trip with the reader; compounds without a public iterator (VMap) print as opaque placeholders for now.
Definition at line 97 of file print.c.
97 {
101
104 fputs("nil", out);
105 break;
107 fputs("true", out);
108 break;
110 fputs("false", out);
111 break;
112
114 (void)fprintf(out,
"%" PRId64,
AS_I64(v));
115 break;
116
118
119 (void)fprintf(out,
"%.17g",
AS_F64(v));
120 break;
121
124 break;
125
128
129
130 if (sym->
ns !=
nullptr) {
132 fputc('/', out);
133 }
135 break;
136 }
137
140 fputc(':', out);
142 break;
143 }
144
147 fputs("#<ns ", out);
149 fputc('>', out);
150 break;
151 }
152
155 break;
156
159 break;
160
162
164 (void)fprintf(out,
"#<map size=%zu>", m->
inner.
len);
165 break;
166 }
167
169 fputs("#<closure>", out);
170 break;
171
174 (void)fprintf(out,
"#<error tag=%d", (
int)e->
tag);
175 if (e->
msg !=
nullptr) {
176 (void)fprintf(out,
" %s", e->
msg);
177 }
178 fputc('>', out);
179 break;
180 }
181
183 fputs("#<quote>", out);
184 break;
185
186 default:
187 fputs("#<unknown>", out);
188 break;
189 }
190}
#define AS_F64(value_ref)
#define AS_SYMBOL(value_ref)
@ VError
VError should be last.
#define AS_STRING(value_ref)
#define AS_I64(value_ref)
#define AS_MAP(value_ref)
#define AS_ERROR(value_ref)
#define AS_KEYWORD(value_ref)
static void print_list(FILE *out, srn_context_t *ctx, const srn_value_t *v)
static void print_seq(FILE *out, srn_context_t *ctx, const srn_value_t *v)
static void print_string_payload(FILE *out, const srn_string_t *s)
static void write_bytes(FILE *out, const uint8_t *buf, size_t len)
size_t len
Number of key/value pairs in the map.
A persistent, immutable map.
◆ srn_value_println()
Same as srn_value_print followed by '
'.
Definition at line 192 of file print.c.
192 {
194 fputc('\n', out);
195}
◆ write_bytes()
| void write_bytes |
( |
FILE * | out, |
|
|
const uint8_t * | buf, |
|
|
size_t | len ) |
|
inlinestatic |
Definition at line 60 of file print.c.
60 {
61 if (len > 0) {
62 (void)fwrite(buf, 1, len, out);
63 }
64}