-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathjo_clojure_io.h
680 lines (628 loc) · 23.3 KB
/
jo_clojure_io.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
#pragma once
#include "jo_stdcpp.h"
// for popen and pclose
#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#define popen _popen
#define pclose _pclose
#define opendir _opendir
#define closedir _closedir
#else
#include <unistd.h>
#include <dirent.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <sys/wait.h>
#endif
// This functionality deviates from clojure's IO library, cause in my personal opinion,
// clojure's IO library is not great. I assume because Rich was trying to be purist.
// However, IMO, side-effects are side-effects and you can't avoid them with files.
// Might as well embrace them in this case.
// TODO: should directory scans be lazy? would make sense for read-dir-all and the like
//
// (file-seq dir)
// A tree seq on java.io.Files
static node_idx_t native_io_file_seq(env_ptr_t env, list_ptr_t args) {
return NIL_NODE;
}
static node_idx_t native_io_slurp(env_ptr_t env, list_ptr_t args) {
jo_string path = get_node_string(args->first_value());
jo_string url_server = http_url_server(path);
if(!url_server.empty()) {
return http_get(path);
}
char *c = (char*)jo_slurp_file(path.c_str());
node_idx_t ret = new_node_string(c?c:"");
free(c);
return ret;
}
static node_idx_t native_io_spit(env_ptr_t env, list_ptr_t args) {
// TODO: HTTP/HTTPS!
jo_string path = get_node_string(args->first_value());
jo_string contents_str = get_node_string(args->second_value());
return new_node_bool(jo_spit_file(path.c_str(), contents_str.c_str()) == 0);
}
// (file opts arg)(file opts parent child)(file opts parent child & more)
// Returns a java.io.File, passing each arg to as-file. Multiple-arg
// versions treat the first argument as parent and subsequent args as
// children relative to the parent.
static node_idx_t native_io_open_file(env_ptr_t env, list_ptr_t args) {
if(args->size() < 2) {
return NIL_NODE;
}
list_t::iterator it(args);
jo_string opts = get_node_string(*it++);
jo_string str;
for(; it; it++) {
node_t *n = get_node(*it);
#ifdef _WIN32
if(str.empty()) {
str += n->as_string(env).replace("/", "\\");
} else {
str += "\\" + n->as_string(env).replace("/", "\\");
}
#else
if(str.empty()) {
str += n->as_string(env).replace("\\", "/");
} else {
str += "/" + n->as_string(env).replace("\\", "/");
}
#endif
}
FILE *fp = fopen(str.c_str(), opts.c_str());
if(!fp) {
return NIL_NODE;
}
return new_node_file(fp);
}
// (io/close-file file)
// Closes the file and frees the node.
static node_idx_t native_io_close_file(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE) {
return NIL_NODE;
}
if(n->t_file) {
fclose(n->t_file);
n->t_file = 0;
}
return NIL_NODE;
}
// (io/read-line file)
// Reads a line from the file.
static node_idx_t native_io_read_line(env_ptr_t env, list_ptr_t args) {
char buf[1024]; // TODO: not sure I like this fixed size, but its better to have a limit than no limit... right?
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
if(!fgets(buf, 1024, n->t_file)) {
return NIL_NODE;
}
return new_node_string(buf);
}
// (io/write-line file str)
// Writes a line to the file.
static node_idx_t native_io_write_line(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
jo_string str = get_node_string(args->second_value());
str += "\n";
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
fputs(str.c_str(), n->t_file);
return NIL_NODE;
}
// (io/flush file)
// Flushes the file.
static node_idx_t native_io_flush(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
fflush(n->t_file);
return NIL_NODE;
}
// (io/seek file pos)
// Seeks to the specified position in the file.
static node_idx_t native_io_seek(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
long long pos = get_node_int(args->second_value());
fseek(n->t_file, pos, SEEK_SET);
return NIL_NODE;
}
// (io/tell file)
// Returns the current position in the file.
static node_idx_t native_io_tell(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
return new_node_int(ftell(n->t_file));
}
// (io/size file)
// Returns the size of the file.
static node_idx_t native_io_size(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
long pos = ftell(n->t_file);
fseek(n->t_file, 0, SEEK_END);
long size = ftell(n->t_file);
fseek(n->t_file, pos, SEEK_SET);
return new_node_int(size);
}
// (io/eof file)
// Returns true if the file is at the end.
static node_idx_t native_io_eof(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
return new_node_bool(feof(n->t_file));
}
// (io/file-exists? file)
// Returns true if the file exists.
static node_idx_t native_io_file_exists(env_ptr_t env, list_ptr_t args) {
return new_node_bool(jo_file_exists(get_node_string(args->first_value()).c_str()));
}
// (io/file-readable? file)
// Returns true if the file is readable.
static node_idx_t native_io_file_readable(env_ptr_t env, list_ptr_t args) {
return new_node_bool(jo_file_readable(get_node_string(args->first_value()).c_str()));
}
// (io/file-writable? file)
// Returns true if the file is writable.
static node_idx_t native_io_file_writable(env_ptr_t env, list_ptr_t args) {
return new_node_bool(jo_file_writable(get_node_string(args->first_value()).c_str()));
}
// (io/file-executable? file)
// Returns true if the file is executable.
static node_idx_t native_io_file_executable(env_ptr_t env, list_ptr_t args) {
return new_node_bool(jo_file_executable(get_node_string(args->first_value()).c_str()));
}
// (io/delete-file f & [silently])
// Delete file f. If silently is nil or false, raise an exception on failure,
// else return the value of silently.
static node_idx_t native_io_delete_file(env_ptr_t env, list_ptr_t args) {
jo_string path = get_node_string(args->first_value());
#ifdef _WIN32
if(!DeleteFileA(path.c_str())) {
#else
if(unlink(path.c_str())) {
#endif
if(!get_node_bool(args->second_value())) {
warnf("Failed to delete file %s", path.c_str());
}
}
return args->second_value();
}
// (copy input output)
// Copies input to output.
static node_idx_t native_io_copy(env_ptr_t env, list_ptr_t args) {
jo_string input = get_node_string(args->first_value());
jo_string output = get_node_string(args->second_value());
return new_node_bool(jo_file_copy(input.c_str(), output.c_str()) == 0);
}
// (io/proc-open cmd opts)
// Opens a pipe to cmd.
static node_idx_t native_io_open_proc(env_ptr_t env, list_ptr_t args) {
jo_string cmd = get_node_string(args->first_value());
jo_string opts = get_node_string(args->second_value());
#if 0 //def __linux__ // not working correctly =/
int fds[2];
pid_t pid;
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0)
return NIL_NODE;
switch(pid=vfork()) {
case -1: /* Error */
close(fds[0]);
close(fds[1]);
return NIL_NODE;
case 0: /* child */
close(fds[0]);
dup2(fds[1], 0);
dup2(fds[1], 1);
close(fds[1]);
execl("/bin/sh", "sh", "-c", cmd.c_str(), NULL);
_exit(127);
}
/* parent */
close(fds[1]);
return new_node_file(fdopen(fds[0], "r+"));
#else
FILE *fp = popen(cmd.c_str(), opts.c_str());
if(!fp) {
warnf("popen execution failed for '%s' with opts '%s'\n", cmd.c_str(), opts.c_str());
return NIL_NODE;
}
return new_node_file(fp);
#endif
}
// (io/proc-close file)
// Closes the file and frees the node.
static node_idx_t native_io_close_proc(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE) {
return NIL_NODE;
}
if(n->t_file) {
pclose(n->t_file);
n->t_file = 0;
}
return NIL_NODE;
}
static node_idx_t native_io_write_str(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
jo_string str = get_node_string(args->second_value());
fputs(str.c_str(), n->t_file);
return NIL_NODE;
}
static node_idx_t native_io_write_int(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
long long i = get_node_int(args->second_value());
fwrite(&i, sizeof(int), 1, n->t_file);
return NIL_NODE;
}
static node_idx_t native_io_write_float(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
float f = get_node_float(args->second_value());
fwrite(&f, sizeof(float), 1, n->t_file);
return NIL_NODE;
}
static node_idx_t native_io_write_short(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
long long s = get_node_int(args->second_value());
fwrite(&s, sizeof(short), 1, n->t_file);
return NIL_NODE;
}
static node_idx_t native_io_write_byte(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
long long b = get_node_int(args->second_value());
fwrite(&b, sizeof(char), 1, n->t_file);
return NIL_NODE;
}
static node_idx_t native_io_write_array(env_ptr_t env, list_ptr_t args) {
list_t::iterator it(args);
node_t *n = get_node(*it++);
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
jo_clojure_array_ptr_t A = get_node(*it++)->t_object.cast<jo_clojure_array_t>();
A->write(n->t_file);
return NIL_NODE;
}
static node_idx_t native_io_read_int(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
int i;
fread(&i, sizeof(int), 1, n->t_file);
return new_node_int(i);
}
static node_idx_t native_io_read_float(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
float f;
fread(&f, sizeof(float), 1, n->t_file);
return new_node_float(f);
}
static node_idx_t native_io_read_short(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
short s;
fread(&s, sizeof(short), 1, n->t_file);
return new_node_int(s);
}
static node_idx_t native_io_read_byte(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
char b;
fread(&b, sizeof(char), 1, n->t_file);
return new_node_int(b);
}
// (io/read-str file terminator)
// Reads a string from the file.
static node_idx_t native_io_read_str(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_FILE || !n->t_file) {
return NIL_NODE;
}
char buf[1024];
int term = '\n';
if(args->size() == 2) {
term = get_node_int(args->second_value());
}
long long i = 0;
while(1) {
int c = fgetc(n->t_file);
if(c == EOF || c == term) {
break;
}
buf[i] = c;
i++;
}
buf[i] = 0;
return new_node_string(buf);
}
static node_idx_t native_io_open_dir(env_ptr_t env, list_ptr_t args) {
jo_string str = get_node_string(args->first_value());
#ifdef _WIN32
HANDLE h = FindFirstFileA(str.c_str(), NULL);
if(h == INVALID_HANDLE_VALUE) {
return NIL_NODE;
}
return new_node_dir(h);
#else
DIR *dir = opendir(str.c_str());
if(!dir) {
return NIL_NODE;
}
return new_node_dir(dir);
#endif
}
static node_idx_t native_io_close_dir(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_DIR || !n->t_dir) {
return NIL_NODE;
}
if(n->t_dir != 0) {
#ifdef _WIN32
FindClose(n->t_dir);
#else
closedir((DIR*)n->t_dir);
#endif
n->t_dir = NULL;
}
return NIL_NODE;
}
// (io/read-dir dir)
// Reads a directory entry from the directory.
static node_idx_t native_io_read_dir(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_DIR || !n->t_dir) {
return NIL_NODE;
}
#ifdef _WIN32
WIN32_FIND_DATAA fd;
if(!FindNextFileA(n->t_dir, &fd)) {
return NIL_NODE;
}
return new_node_string(fd.cFileName);
#else
struct dirent *ent = readdir((DIR*)n->t_dir);
if(!ent) {
return NIL_NODE;
}
return new_node_string(ent->d_name);
#endif
}
// (io/read-dir-all dir)
// Reads all directory entries from the directory.
static node_idx_t native_io_read_dir_all(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_DIR || !n->t_dir) {
return NIL_NODE;
}
list_ptr_t list = new_list();
while(1) {
#ifdef _WIN32
WIN32_FIND_DATAA fd;
if(!FindNextFileA(n->t_dir, &fd)) {
break;
}
list->push_back_inplace(new_node_string(fd.cFileName));
#else
struct dirent *ent = readdir((DIR*)n->t_dir);
if(!ent) {
break;
}
list->push_back_inplace(new_node_string(ent->d_name));
#endif
}
return new_node_list(list);
}
// (io/read-dir-files dir)
// Reads all files from the directory.
static node_idx_t native_io_read_dir_files(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_DIR || !n->t_dir) {
return NIL_NODE;
}
list_ptr_t list = new_list();
while(1) {
#ifdef _WIN32
WIN32_FIND_DATAA fd;
if(!FindNextFileA(n->t_dir, &fd)) {
break;
}
if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
continue;
}
list->push_back_inplace(new_node_string(fd.cFileName));
#else
struct dirent *ent = readdir((DIR*)n->t_dir);
if(!ent) {
break;
}
if(ent->d_type == DT_REG) {
list->push_back_inplace(new_node_string(ent->d_name));
}
#endif
}
return new_node_list(list);
}
// (io/read-dir-dirs dir)
// Reads all directories from the directory.
static node_idx_t native_io_read_dir_dirs(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_DIR || !n->t_dir) {
return NIL_NODE;
}
list_ptr_t list = new_list();
while(1) {
#ifdef _WIN32
WIN32_FIND_DATAA fd;
if(!FindNextFileA(n->t_dir, &fd)) {
break;
}
if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
list->push_back_inplace(new_node_string(fd.cFileName));
}
#else
struct dirent *ent = readdir((DIR*)n->t_dir);
if(!ent) {
break;
}
if(ent->d_type == DT_DIR) {
list->push_back_inplace(new_node_string(ent->d_name));
}
#endif
}
return new_node_list(list);
}
// (io/rewind-dir dir)
// Rewinds the directory.
static node_idx_t native_io_rewind_dir(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_DIR || !n->t_dir) {
return NIL_NODE;
}
#ifdef _WIN32
FindClose(n->t_dir);
#else
rewinddir((DIR*)n->t_dir);
#endif
return NIL_NODE;
}
// (io/tell-dir dir)
// Returns the current position in the directory.
static node_idx_t native_io_tell_dir(env_ptr_t env, list_ptr_t args) {
node_t *n = get_node(args->first_value());
if(n->type != NODE_DIR || !n->t_dir) {
return NIL_NODE;
}
#ifdef _WIN32
return ZERO_NODE;
#else
return new_node_int(telldir((DIR*)n->t_dir));
#endif
}
// (line-seq rdr)
// Returns the lines of text from rdr as a lazy sequence of strings.
// rdr must implement java.io.BufferedReader.
static node_idx_t native_io_line_seq(env_ptr_t env, list_ptr_t args) {
node_idx_t rdr_idx = args->first_value();
if(get_node_type(rdr_idx) != NODE_FILE) {
warnf("line-seq: rdr must be a file\n");
return NIL_NODE;
}
return new_node_lazy_list(env, new_node_list(list_va(env->get("line-seq-next"), rdr_idx)));
}
static node_idx_t native_io_line_seq_next(env_ptr_t env, list_ptr_t args) {
node_idx_t rdr_idx = args->first_value();
node_t *rdr = get_node(rdr_idx);
if(feof(rdr->t_file)) {
return NIL_NODE;
}
node_idx_t line = native_io_read_line(env, args);
if(line == NIL_NODE) {
return NIL_NODE;
}
return new_node_list(list_va(line, env->get("line-seq-next"), rdr_idx));
}
static node_idx_t native_io_file_to_array(env_ptr_t env, list_ptr_t args) {
node_idx_t file_idx = args->first_value();
if(get_node_type(file_idx) != NODE_FILE) {
warnf("file->array: file must be a file\n");
return NIL_NODE;
}
node_t *file = get_node(file_idx);
if(!file->t_file) {
warnf("file->array: file is closed\n");
return NIL_NODE;
}
fseek(file->t_file, 0, SEEK_END);
long long size = jo_ftell64(file->t_file);
fseek(file->t_file, 0, SEEK_SET);
unsigned char *buf = (unsigned char*)malloc(size);
fread(buf, 1, size, file->t_file);
return new_node_array(new_array(buf, size));
}
void jo_clojure_io_init(env_ptr_t env) {
env->set("file-seq", new_node_native_function("file-seq", &native_io_file_seq, false, NODE_FLAG_PRERESOLVE));
env->set("line-seq", new_node_native_function("line-seq", &native_io_line_seq, false, NODE_FLAG_PRERESOLVE));
env->set("line-seq-next", new_node_native_function("line-seq-next", &native_io_line_seq_next, true, NODE_FLAG_PRERESOLVE));
env->set("slurp", new_node_native_function("slurp", &native_io_slurp, false, NODE_FLAG_PRERESOLVE));
env->set("spit", new_node_native_function("spit", &native_io_spit, false, NODE_FLAG_PRERESOLVE));
env->set("io/open-dir", new_node_native_function("io/open-dir", &native_io_open_dir, false, NODE_FLAG_PRERESOLVE));
env->set("io/close-dir", new_node_native_function("io/close-dir", &native_io_close_dir, false, NODE_FLAG_PRERESOLVE));
env->set("io/read-dir", new_node_native_function("io/read-dir", &native_io_read_dir, false, NODE_FLAG_PRERESOLVE));
env->set("io/read-dir-all", new_node_native_function("io/read-dir-all", &native_io_read_dir_all, false, NODE_FLAG_PRERESOLVE));
env->set("io/read-dir-files", new_node_native_function("io/read-dir-files", &native_io_read_dir_files, false, NODE_FLAG_PRERESOLVE));
env->set("io/read-dir-dirs", new_node_native_function("io/read-dir-dirs", &native_io_read_dir_dirs, false, NODE_FLAG_PRERESOLVE));
env->set("io/rewind-dir", new_node_native_function("io/rewind-dir", &native_io_rewind_dir, false, NODE_FLAG_PRERESOLVE));
env->set("io/tell-dir", new_node_native_function("io/tell-dir", &native_io_tell_dir, false, NODE_FLAG_PRERESOLVE));
env->set("io/open-proc", new_node_native_function("io/open-proc", &native_io_open_proc, false, NODE_FLAG_PRERESOLVE));
env->set("io/close-proc", new_node_native_function("io/close-proc", &native_io_close_proc, false, NODE_FLAG_PRERESOLVE));
env->set("io/open-file", new_node_native_function("io/open-file", &native_io_open_file, false, NODE_FLAG_PRERESOLVE));
env->set("io/close-file", new_node_native_function("io/close-file", &native_io_close_file, false, NODE_FLAG_PRERESOLVE));
env->set("io/read-line", new_node_native_function("io/read-line", &native_io_read_line, false, NODE_FLAG_PRERESOLVE));
env->set("io/read-str", new_node_native_function("io/read-str", &native_io_read_str, false, NODE_FLAG_PRERESOLVE));
env->set("io/read-int", new_node_native_function("io/read-int", &native_io_read_int, false, NODE_FLAG_PRERESOLVE));
env->set("io/read-float", new_node_native_function("io/read-float", &native_io_read_float, false, NODE_FLAG_PRERESOLVE));
env->set("io/read-short", new_node_native_function("io/read-short", &native_io_read_short, false, NODE_FLAG_PRERESOLVE));
env->set("io/read-byte", new_node_native_function("io/read-byte", &native_io_read_byte, false, NODE_FLAG_PRERESOLVE));
env->set("io/write-line", new_node_native_function("io/write-line", &native_io_write_line, false, NODE_FLAG_PRERESOLVE));
env->set("io/write-str", new_node_native_function("io/write-str", &native_io_write_str, false, NODE_FLAG_PRERESOLVE));
env->set("io/write-int", new_node_native_function("io/write-int", &native_io_write_int, false, NODE_FLAG_PRERESOLVE));
env->set("io/write-float", new_node_native_function("io/write-float", &native_io_write_float, false, NODE_FLAG_PRERESOLVE));
env->set("io/write-short", new_node_native_function("io/write-short", &native_io_write_short, false, NODE_FLAG_PRERESOLVE));
env->set("io/write-byte", new_node_native_function("io/write-byte", &native_io_write_byte, false, NODE_FLAG_PRERESOLVE));
env->set("io/write-array", new_node_native_function("io/write-array", &native_io_write_array, false, NODE_FLAG_PRERESOLVE));
env->set("io/flush", new_node_native_function("io/flush", &native_io_flush, false, NODE_FLAG_PRERESOLVE));
env->set("io/seek", new_node_native_function("io/seek", &native_io_seek, false, NODE_FLAG_PRERESOLVE));
env->set("io/tell", new_node_native_function("io/tell", &native_io_tell, false, NODE_FLAG_PRERESOLVE));
env->set("io/size", new_node_native_function("io/size", &native_io_size, false, NODE_FLAG_PRERESOLVE));
env->set("io/eof?", new_node_native_function("io/eof?", &native_io_eof, false, NODE_FLAG_PRERESOLVE));
env->set("io/file-exists?", new_node_native_function("io/file-exists?", &native_io_file_exists, false, NODE_FLAG_PRERESOLVE));
env->set("io/file-readable?", new_node_native_function("io/file-readable?", &native_io_file_readable, false, NODE_FLAG_PRERESOLVE));
env->set("io/file-writable?", new_node_native_function("io/file-writable?", &native_io_file_writable, false, NODE_FLAG_PRERESOLVE));
env->set("io/file-executable?", new_node_native_function("io/file-executable?", &native_io_file_executable, false, NODE_FLAG_PRERESOLVE));
env->set("io/delete-file", new_node_native_function("io/delete-file", &native_io_delete_file, false, NODE_FLAG_PRERESOLVE));
env->set("io/copy", new_node_native_function("io/copy", &native_io_copy, false, NODE_FLAG_PRERESOLVE));
env->set("io/file-to-array", new_node_native_function("io/file-to-array", &native_io_file_to_array, false, NODE_FLAG_PRERESOLVE));
env->set("*in*", new_node_file(stdin, NODE_FLAG_PRERESOLVE));
env->set("*out*", new_node_file(stdout, NODE_FLAG_PRERESOLVE));
env->set("*err*", new_node_file(stderr, NODE_FLAG_PRERESOLVE));
}