2013-10-27 05:38:55 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-10-15 08:14:33 -04:00
|
|
|
#include "picrin.h"
|
2013-10-30 04:06:01 -04:00
|
|
|
#include "picrin/pair.h"
|
2013-10-15 08:14:33 -04:00
|
|
|
|
2013-10-30 11:29:55 -04:00
|
|
|
void pic_init_bool(pic_state *);
|
2013-10-22 23:01:06 -04:00
|
|
|
void pic_init_pair(pic_state *);
|
2013-10-15 08:14:33 -04:00
|
|
|
void pic_init_port(pic_state *);
|
2013-10-15 10:26:18 -04:00
|
|
|
void pic_init_number(pic_state *);
|
2013-10-19 23:04:15 -04:00
|
|
|
void pic_init_time(pic_state *);
|
2013-10-20 22:51:02 -04:00
|
|
|
void pic_init_system(pic_state *);
|
2013-10-22 02:16:35 -04:00
|
|
|
void pic_init_file(pic_state *);
|
2013-10-24 11:37:20 -04:00
|
|
|
void pic_init_proc(pic_state *);
|
2013-10-28 13:49:38 -04:00
|
|
|
void pic_init_symbol(pic_state *);
|
2013-11-04 20:53:33 -05:00
|
|
|
void pic_init_vector(pic_state *);
|
2013-11-04 22:58:16 -05:00
|
|
|
void pic_init_blob(pic_state *);
|
2013-11-09 00:14:25 -05:00
|
|
|
void pic_init_cont(pic_state *);
|
2013-11-14 06:41:22 -05:00
|
|
|
void pic_init_char(pic_state *);
|
2013-10-15 08:14:33 -04:00
|
|
|
|
2013-10-27 05:38:55 -04:00
|
|
|
void
|
|
|
|
pic_load_stdlib(pic_state *pic)
|
|
|
|
{
|
|
|
|
static const char *fn = "piclib/built-in.scm";
|
|
|
|
FILE *file;
|
2013-10-30 04:06:01 -04:00
|
|
|
int n, i;
|
|
|
|
pic_value v, vs;
|
2013-10-27 05:38:55 -04:00
|
|
|
struct pic_proc *proc;
|
|
|
|
|
|
|
|
file = fopen(fn, "r");
|
|
|
|
if (file == NULL) {
|
|
|
|
fputs("fatal error: could not read built-in.scm", stderr);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2013-10-30 04:06:01 -04:00
|
|
|
n = pic_parse_file(pic, file, &vs);
|
2013-11-13 03:37:05 -05:00
|
|
|
if (n < 0) {
|
2013-10-27 05:38:55 -04:00
|
|
|
fputs("fatal error: built-in.scm broken", stderr);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2013-10-30 04:06:01 -04:00
|
|
|
for (i = 0; i < n; ++i, vs = pic_cdr(pic, vs)) {
|
|
|
|
v = pic_car(pic, vs);
|
2013-10-27 05:38:55 -04:00
|
|
|
|
2013-10-30 04:06:01 -04:00
|
|
|
proc = pic_codegen(pic, v);
|
|
|
|
if (proc == NULL) {
|
|
|
|
fputs(pic->errmsg, stderr);
|
|
|
|
fputs("fatal error: built-in.scm compilation failure", stderr);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
v = pic_apply(pic, proc, pic_nil_value());
|
|
|
|
if (pic_undef_p(v)) {
|
|
|
|
fputs(pic->errmsg, stderr);
|
|
|
|
fputs("fatal error: built-in.scm evaluation failure", stderr);
|
|
|
|
abort();
|
|
|
|
}
|
2013-10-27 05:38:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
puts("successfully loaded stdlib");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-10-15 08:14:33 -04:00
|
|
|
#define DONE pic_gc_arena_restore(pic, ai);
|
|
|
|
|
|
|
|
void
|
|
|
|
pic_init_core(pic_state *pic)
|
|
|
|
{
|
|
|
|
int ai;
|
|
|
|
|
|
|
|
ai = pic_gc_arena_preserve(pic);
|
2013-10-30 11:29:55 -04:00
|
|
|
pic_init_bool(pic); DONE;
|
2013-10-22 23:01:06 -04:00
|
|
|
pic_init_pair(pic); DONE;
|
2013-10-15 08:14:33 -04:00
|
|
|
pic_init_port(pic); DONE;
|
2013-10-15 10:26:18 -04:00
|
|
|
pic_init_number(pic); DONE;
|
2013-10-19 23:04:15 -04:00
|
|
|
pic_init_time(pic); DONE;
|
2013-10-20 22:51:02 -04:00
|
|
|
pic_init_system(pic); DONE;
|
2013-10-22 02:16:35 -04:00
|
|
|
pic_init_file(pic); DONE;
|
2013-10-24 11:37:20 -04:00
|
|
|
pic_init_proc(pic); DONE;
|
2013-10-28 13:49:38 -04:00
|
|
|
pic_init_symbol(pic); DONE;
|
2013-11-04 20:53:33 -05:00
|
|
|
pic_init_vector(pic); DONE;
|
2013-11-04 22:58:16 -05:00
|
|
|
pic_init_blob(pic); DONE;
|
2013-11-09 00:14:25 -05:00
|
|
|
pic_init_cont(pic); DONE;
|
2013-11-14 06:41:22 -05:00
|
|
|
pic_init_char(pic); DONE;
|
2013-10-27 05:38:55 -04:00
|
|
|
|
|
|
|
pic_load_stdlib(pic); DONE;
|
2013-10-15 08:14:33 -04:00
|
|
|
}
|