add pic_load_cstr
This commit is contained in:
parent
cb288532a9
commit
74b44f4d84
|
@ -155,6 +155,7 @@ pic_list pic_parse_file(pic_state *, FILE *); /* #f for incomplete input */
|
||||||
pic_list pic_parse_cstr(pic_state *, const char *);
|
pic_list pic_parse_cstr(pic_state *, const char *);
|
||||||
|
|
||||||
pic_value pic_load(pic_state *, const char *);
|
pic_value pic_load(pic_state *, const char *);
|
||||||
|
pic_value pic_load_cstr(pic_state *, const char *);
|
||||||
|
|
||||||
pic_value pic_apply(pic_state *, struct pic_proc *, pic_value);
|
pic_value pic_apply(pic_state *, struct pic_proc *, pic_value);
|
||||||
pic_value pic_apply0(pic_state *, struct pic_proc *);
|
pic_value pic_apply0(pic_state *, struct pic_proc *);
|
||||||
|
|
28
src/load.c
28
src/load.c
|
@ -5,6 +5,34 @@
|
||||||
#include "picrin.h"
|
#include "picrin.h"
|
||||||
#include "picrin/pair.h"
|
#include "picrin/pair.h"
|
||||||
|
|
||||||
|
pic_value
|
||||||
|
pic_load_cstr(pic_state *pic, const char *src)
|
||||||
|
{
|
||||||
|
int ai;
|
||||||
|
pic_value v, exprs;
|
||||||
|
struct pic_proc *proc;
|
||||||
|
|
||||||
|
exprs = pic_parse_cstr(pic, src);
|
||||||
|
if (pic_undef_p(exprs)) {
|
||||||
|
pic_error(pic, "load: unexpected EOF");
|
||||||
|
}
|
||||||
|
|
||||||
|
pic_for_each (v, exprs) {
|
||||||
|
ai = pic_gc_arena_preserve(pic);
|
||||||
|
|
||||||
|
proc = pic_compile(pic, v);
|
||||||
|
if (proc == NULL) {
|
||||||
|
pic_error(pic, "load: compilation failure");
|
||||||
|
}
|
||||||
|
|
||||||
|
pic_apply(pic, proc, pic_nil_value());
|
||||||
|
|
||||||
|
pic_gc_arena_restore(pic, ai);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pic_none_value();
|
||||||
|
}
|
||||||
|
|
||||||
pic_value
|
pic_value
|
||||||
pic_load(pic_state *pic, const char *fn)
|
pic_load(pic_state *pic, const char *fn)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue