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.
Since all the values are immutable and persistent.
◆ print_quoted_string()
| static void print_quoted_string |
( |
FILE * | out, |
|
|
const char * | s ) |
|
static |
Definition at line 195 of file print.c.
195 {
196 fputc('"', out);
197 for (const char *p = s; *p != '\0'; p++) {
198 switch (*p) {
199 case '"':
200 fputs("\\\"", out);
201 break;
202 case '\\':
203 fputs("\\\\", out);
204 break;
205 case '\n':
206 fputs("\\n", out);
207 break;
208 case '\t':
209 fputs("\\t", out);
210 break;
211 case '\r':
212 fputs("\\r", out);
213 break;
214 default:
215 fputc((int)(unsigned char)*p, out);
216 break;
217 }
218 }
219 fputc('"', out);
220}
◆ 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 srn_context_t *ctx, 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()
| static void print_seq_body |
( |
FILE * | out, |
|
|
srn_context_t * | ctx, |
|
|
const seq_t * | body, |
|
|
char | open, |
|
|
char | close ) |
|
static |
Definition at line 224 of file print.c.
225 {
226 fputc(open, out);
227 for (
size_t i = 0; i < body->
len; i++) {
228 if (i > 0) {
229 fputc(' ', out);
230 }
232 if (r.maybe_error != nullptr) {
233 fputs("#<seq-error>", out);
234 continue;
235 }
237 }
238 fputc(close, out);
239}
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()
| static 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 241 of file print.c.
241 {
245
248 fputs("nil", out);
249 break;
251 fputs("true", out);
252 break;
254 fputs("false", out);
255 break;
256
259 break;
262 break;
263
266 break;
267
269 fputc(':', out);
271 break;
272
275 break;
278 break;
281 break;
282
284 fputc('\'', out);
286 break;
287
290 (void)fprintf(out,
"#<error tag=%d", (
int)e->
tag);
291 if (e->
msg !=
nullptr) {
292 (void)fprintf(out,
" %s", e->
msg);
293 }
294 fputc('>', out);
295 break;
296 }
297
298 default:
299 fputs("#<unknown>", out);
300 break;
301 }
302}
@ 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)
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 304 of file print.c.
304 {
306 fputc('\n', out);
307}
◆ 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
129 break;
130 }
131
134 fputc(':', out);
136 break;
137 }
138
141 fputs("#<ns ", out);
143 fputc('>', out);
144 break;
145 }
146
149 break;
150
153 break;
154
156
158 (void)fprintf(out,
"#<map size=%zu>", m->
inner.
len);
159 break;
160 }
161
163 fputs("#<closure>", out);
164 break;
165
168 (void)fprintf(out,
"#<error tag=%d", (
int)e->
tag);
169 if (e->
msg !=
nullptr) {
170 (void)fprintf(out,
" %s", e->
msg);
171 }
172 fputc('>', out);
173 break;
174 }
175
177 fputs("#<quote>", out);
178 break;
179
180 default:
181 fputs("#<unknown>", out);
182 break;
183 }
184}
#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 186 of file print.c.
186 {
188 fputc('\n', out);
189}
◆ write_bytes()
| static 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}